458 current->set_current_pending_monitor_is_from_java(true);
459 }
460
461 // NOTE: must use heavy weight monitor to handle jni monitor exit
462 void ObjectSynchronizer::jni_exit(oop obj, TRAPS) {
463 JavaThread* current = THREAD;
464
465 ObjectMonitor* monitor;
466 monitor = LightweightSynchronizer::inflate_locked_or_imse(obj, inflate_cause_jni_exit, CHECK);
467 // If this thread has locked the object, exit the monitor. We
468 // intentionally do not use CHECK on check_owner because we must exit the
469 // monitor even if an exception was already pending.
470 if (monitor->check_owner(THREAD)) {
471 monitor->exit(current);
472 }
473 }
474
475 // -----------------------------------------------------------------------------
476 // Internal VM locks on java objects
477 // standard constructor, allows locking failures
478 ObjectLocker::ObjectLocker(Handle obj, JavaThread* thread) : _npm(thread) {
479 _thread = thread;
480 _thread->check_for_valid_safepoint_state();
481 _obj = obj;
482
483 if (_obj() != nullptr) {
484 ObjectSynchronizer::enter(_obj, &_lock, _thread);
485 }
486 }
487
488 ObjectLocker::~ObjectLocker() {
489 if (_obj() != nullptr) {
490 ObjectSynchronizer::exit(_obj(), &_lock, _thread);
491 }
492 }
493
494
495 // -----------------------------------------------------------------------------
496 // Wait/Notify/NotifyAll
497 // NOTE: must use heavy weight monitor to handle wait()
498
499 int ObjectSynchronizer::wait(Handle obj, jlong millis, TRAPS) {
500 JavaThread* current = THREAD;
501 if (millis < 0) {
502 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "timeout value is negative");
503 }
504
505 ObjectMonitor* monitor;
506 monitor = LightweightSynchronizer::inflate_locked_or_imse(obj(), inflate_cause_wait, CHECK_0);
507
508 DTRACE_MONITOR_WAIT_PROBE(monitor, obj(), current, millis);
509 monitor->wait(millis, true, THREAD); // Not CHECK as we need following code
510
511 // This dummy call is in place to get around dtrace bug 6254741. Once
512 // that's fixed we can uncomment the following line, remove the call
513 // and change this function back into a "void" func.
514 // DTRACE_MONITOR_PROBE(waited, monitor, obj(), THREAD);
515 int ret_code = dtrace_waited_probe(monitor, obj, THREAD);
516 return ret_code;
517 }
518
519 void ObjectSynchronizer::waitUninterruptibly(Handle obj, jlong millis, TRAPS) {
520 if (millis < 0) {
521 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "timeout value is negative");
522 }
523
524 ObjectMonitor* monitor;
525 monitor = LightweightSynchronizer::inflate_locked_or_imse(obj(), inflate_cause_wait, CHECK);
526 monitor->wait(millis, false, THREAD);
527 }
528
529
530 void ObjectSynchronizer::notify(Handle obj, TRAPS) {
531 JavaThread* current = THREAD;
532
533 markWord mark = obj->mark();
534 if ((mark.is_fast_locked() && current->lock_stack().contains(obj()))) {
535 // Not inflated so there can't be any waiters to notify.
536 return;
537 }
538 ObjectMonitor* monitor = LightweightSynchronizer::inflate_locked_or_imse(obj(), inflate_cause_notify, CHECK);
539 monitor->notify(CHECK);
540 }
541
542 // NOTE: see comment of notify()
|
458 current->set_current_pending_monitor_is_from_java(true);
459 }
460
461 // NOTE: must use heavy weight monitor to handle jni monitor exit
462 void ObjectSynchronizer::jni_exit(oop obj, TRAPS) {
463 JavaThread* current = THREAD;
464
465 ObjectMonitor* monitor;
466 monitor = LightweightSynchronizer::inflate_locked_or_imse(obj, inflate_cause_jni_exit, CHECK);
467 // If this thread has locked the object, exit the monitor. We
468 // intentionally do not use CHECK on check_owner because we must exit the
469 // monitor even if an exception was already pending.
470 if (monitor->check_owner(THREAD)) {
471 monitor->exit(current);
472 }
473 }
474
475 // -----------------------------------------------------------------------------
476 // Internal VM locks on java objects
477 // standard constructor, allows locking failures
478 ObjectLocker::ObjectLocker(Handle obj, TRAPS) : _thread(THREAD), _obj(obj),
479 _npm(_thread, _thread->at_preemptable_init() /* ignore_mark */), _skip_exit(false) {
480 assert(!_thread->preempting(), "");
481
482 _thread->check_for_valid_safepoint_state();
483
484 if (_obj() != nullptr) {
485 ObjectSynchronizer::enter(_obj, &_lock, _thread);
486
487 if (_thread->preempting()) {
488 // If preemption was cancelled we acquired the monitor after freezing
489 // the frames. Redoing the vm call laterĀ in thaw will require us to
490 // release it since the call should look like the original one. We
491 // do it in ~ObjectLocker to reduce the window of time we hold the
492 // monitor since we can't do anything useful with it now, and would
493 // otherwise just force other vthreads to preempt in case they try
494 // to acquire this monitor.
495 _skip_exit = !_thread->preemption_cancelled();
496 ObjectSynchronizer::read_monitor(_thread, _obj())->set_object_strong();
497 _thread->set_pending_preempted_exception();
498
499 }
500 }
501 }
502
503 ObjectLocker::~ObjectLocker() {
504 if (_obj() != nullptr && !_skip_exit) {
505 ObjectSynchronizer::exit(_obj(), &_lock, _thread);
506 }
507 }
508
509 void ObjectLocker::wait_uninterruptibly(TRAPS) {
510 ObjectSynchronizer::waitUninterruptibly(_obj, 0, _thread);
511 if (_thread->preempting()) {
512 _skip_exit = true;
513 ObjectSynchronizer::read_monitor(_thread, _obj())->set_object_strong();
514 _thread->set_pending_preempted_exception();
515 }
516 }
517
518 // -----------------------------------------------------------------------------
519 // Wait/Notify/NotifyAll
520 // NOTE: must use heavy weight monitor to handle wait()
521
522 int ObjectSynchronizer::wait(Handle obj, jlong millis, TRAPS) {
523 JavaThread* current = THREAD;
524 if (millis < 0) {
525 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "timeout value is negative");
526 }
527
528 ObjectMonitor* monitor;
529 monitor = LightweightSynchronizer::inflate_locked_or_imse(obj(), inflate_cause_wait, CHECK_0);
530
531 DTRACE_MONITOR_WAIT_PROBE(monitor, obj(), current, millis);
532 monitor->wait(millis, true, THREAD); // Not CHECK as we need following code
533
534 // This dummy call is in place to get around dtrace bug 6254741. Once
535 // that's fixed we can uncomment the following line, remove the call
536 // and change this function back into a "void" func.
537 // DTRACE_MONITOR_PROBE(waited, monitor, obj(), THREAD);
538 int ret_code = dtrace_waited_probe(monitor, obj, THREAD);
539 return ret_code;
540 }
541
542 void ObjectSynchronizer::waitUninterruptibly(Handle obj, jlong millis, TRAPS) {
543 assert(millis >= 0, "timeout value is negative");
544
545 ObjectMonitor* monitor;
546 monitor = LightweightSynchronizer::inflate_locked_or_imse(obj(), inflate_cause_wait, CHECK);
547 monitor->wait(millis, false, THREAD);
548 }
549
550
551 void ObjectSynchronizer::notify(Handle obj, TRAPS) {
552 JavaThread* current = THREAD;
553
554 markWord mark = obj->mark();
555 if ((mark.is_fast_locked() && current->lock_stack().contains(obj()))) {
556 // Not inflated so there can't be any waiters to notify.
557 return;
558 }
559 ObjectMonitor* monitor = LightweightSynchronizer::inflate_locked_or_imse(obj(), inflate_cause_notify, CHECK);
560 monitor->notify(CHECK);
561 }
562
563 // NOTE: see comment of notify()
|