298 // removed from the system.
299 //
300 // Note: If the _in_use_list max exceeds the ceiling, then
301 // monitors_used_above_threshold() will use the in_use_list max instead
302 // of the thread count derived ceiling because we have used more
303 // ObjectMonitors than the estimated average.
304 //
305 // Note: If deflate_idle_monitors() has NoAsyncDeflationProgressMax
306 // no-progress async monitor deflation cycles in a row, then the ceiling
307 // is adjusted upwards by monitors_used_above_threshold().
308 //
309 // Start the ceiling with the estimate for one thread in initialize()
310 // which is called after cmd line options are processed.
311 static size_t _in_use_list_ceiling = 0;
312 bool volatile ObjectSynchronizer::_is_async_deflation_requested = false;
313 bool volatile ObjectSynchronizer::_is_final_audit = false;
314 jlong ObjectSynchronizer::_last_async_deflation_time_ns = 0;
315 static uintx _no_progress_cnt = 0;
316 static bool _no_progress_skip_increment = false;
317
318 // =====================> Quick functions
319
320 // The quick_* forms are special fast-path variants used to improve
321 // performance. In the simplest case, a "quick_*" implementation could
322 // simply return false, in which case the caller will perform the necessary
323 // state transitions and call the slow-path form.
324 // The fast-path is designed to handle frequently arising cases in an efficient
325 // manner and is just a degenerate "optimistic" variant of the slow-path.
326 // returns true -- to indicate the call was satisfied.
327 // returns false -- to indicate the call needs the services of the slow-path.
328 // A no-loitering ordinance is in effect for code in the quick_* family
329 // operators: safepoints or indefinite blocking (blocking that might span a
330 // safepoint) are forbidden. Generally the thread_state() is _in_Java upon
331 // entry.
332 //
333 // Consider: An interesting optimization is to have the JIT recognize the
334 // following common idiom:
335 // synchronized (someobj) { .... ; notify(); }
336 // That is, we find a notify() or notifyAll() call that immediately precedes
337 // the monitorexit operation. In that case the JIT could fuse the operations
338 // into a single notifyAndExit() runtime primitive.
339
340 bool ObjectSynchronizer::quick_notify(oopDesc* obj, JavaThread* current, bool all) {
341 assert(current->thread_state() == _thread_in_Java, "invariant");
342 NoSafepointVerifier nsv;
343 if (obj == nullptr) return false; // slow-path for invalid obj
344 const markWord mark = obj->mark();
345
346 if (mark.is_fast_locked() && current->lock_stack().contains(cast_to_oop(obj))) {
347 // Degenerate notify
348 // fast-locked by caller so by definition the implied waitset is empty.
349 return true;
350 }
351
352 if (mark.has_monitor()) {
353 ObjectMonitor* const mon = read_monitor(obj, mark);
354 if (mon == nullptr) {
355 // Racing with inflation/deflation go slow path
356 return false;
357 }
358 assert(mon->object() == oop(obj), "invariant");
359 if (!mon->has_owner(current)) return false; // slow-path for IMS exception
360
361 if (mon->first_waiter() != nullptr) {
362 // We have one or more waiters. Since this is an inflated monitor
363 // that we own, we quickly notify them here and now, avoiding the slow-path.
411 } else {
412 vblog.info("Cannot find the last Java frame");
413 }
414
415 EventSyncOnValueBasedClass event;
416 if (event.should_commit()) {
417 event.set_valueBasedClass(obj->klass());
418 event.commit();
419 }
420 }
421
422 if (bcp_was_adjusted) {
423 last_frame.interpreter_frame_set_bcp(last_frame.interpreter_frame_bcp() + 1);
424 }
425 }
426
427 // -----------------------------------------------------------------------------
428 // JNI locks on java objects
429 // NOTE: must use heavy weight monitor to handle jni monitor enter
430 void ObjectSynchronizer::jni_enter(Handle obj, JavaThread* current) {
431 // Top native frames in the stack will not be seen if we attempt
432 // preemption, since we start walking from the last Java anchor.
433 NoPreemptMark npm(current);
434
435 if (obj->klass()->is_value_based()) {
436 handle_sync_on_value_based_class(obj, current);
437 }
438
439 // the current locking is from JNI instead of Java code
440 current->set_current_pending_monitor_is_from_java(false);
441 // An async deflation can race after the inflate() call and before
442 // enter() can make the ObjectMonitor busy. enter() returns false if
443 // we have lost the race to async deflation and we simply try again.
444 while (true) {
445 BasicLock lock;
446 if (ObjectSynchronizer::inflate_and_enter(obj(), &lock, inflate_cause_jni_enter, current, current) != nullptr) {
447 break;
448 }
449 }
450 current->set_current_pending_monitor_is_from_java(true);
451 }
452
453 // NOTE: must use heavy weight monitor to handle jni monitor exit
454 void ObjectSynchronizer::jni_exit(oop obj, TRAPS) {
455 JavaThread* current = THREAD;
456
457 ObjectMonitor* monitor;
458 monitor = ObjectSynchronizer::inflate_locked_or_imse(obj, inflate_cause_jni_exit, CHECK);
459 // If this thread has locked the object, exit the monitor. We
460 // intentionally do not use CHECK on check_owner because we must exit the
461 // monitor even if an exception was already pending.
462 if (monitor->check_owner(THREAD)) {
463 monitor->exit(current);
464 }
465 }
466
467 // -----------------------------------------------------------------------------
468 // Internal VM locks on java objects
469 // standard constructor, allows locking failures
470 ObjectLocker::ObjectLocker(Handle obj, TRAPS) : _thread(THREAD), _obj(obj),
471 _npm(_thread, _thread->at_preemptable_init() /* ignore_mark */), _skip_exit(false) {
472 assert(!_thread->preempting(), "");
473
474 _thread->check_for_valid_safepoint_state();
475
496 if (_obj() != nullptr && !_skip_exit) {
497 ObjectSynchronizer::exit(_obj(), &_lock, _thread);
498 }
499 }
500
501 void ObjectLocker::wait_uninterruptibly(TRAPS) {
502 ObjectSynchronizer::waitUninterruptibly(_obj, 0, _thread);
503 if (_thread->preempting()) {
504 _skip_exit = true;
505 ObjectSynchronizer::read_monitor(_obj())->set_object_strong();
506 _thread->set_pending_preempted_exception();
507 }
508 }
509
510 // -----------------------------------------------------------------------------
511 // Wait/Notify/NotifyAll
512 // NOTE: must use heavy weight monitor to handle wait()
513
514 int ObjectSynchronizer::wait(Handle obj, jlong millis, TRAPS) {
515 JavaThread* current = THREAD;
516 if (millis < 0) {
517 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "timeout value is negative");
518 }
519
520 ObjectMonitor* monitor;
521 monitor = ObjectSynchronizer::inflate_locked_or_imse(obj(), inflate_cause_wait, CHECK_0);
522
523 DTRACE_MONITOR_WAIT_PROBE(monitor, obj(), current, millis);
524 monitor->wait(millis, true, THREAD); // Not CHECK as we need following code
525
526 // This dummy call is in place to get around dtrace bug 6254741. Once
527 // that's fixed we can uncomment the following line, remove the call
528 // and change this function back into a "void" func.
529 // DTRACE_MONITOR_PROBE(waited, monitor, obj(), THREAD);
530 int ret_code = dtrace_waited_probe(monitor, obj, THREAD);
531 return ret_code;
532 }
533
534 void ObjectSynchronizer::waitUninterruptibly(Handle obj, jlong millis, TRAPS) {
535 assert(millis >= 0, "timeout value is negative");
536
537 ObjectMonitor* monitor;
538 monitor = ObjectSynchronizer::inflate_locked_or_imse(obj(), inflate_cause_wait, CHECK);
539 monitor->wait(millis, false, THREAD);
540 }
541
542
543 void ObjectSynchronizer::notify(Handle obj, TRAPS) {
544 JavaThread* current = THREAD;
545
546 markWord mark = obj->mark();
547 if ((mark.is_fast_locked() && current->lock_stack().contains(obj()))) {
548 // Not inflated so there can't be any waiters to notify.
549 return;
550 }
551 ObjectMonitor* monitor = ObjectSynchronizer::inflate_locked_or_imse(obj(), inflate_cause_notify, CHECK);
552 monitor->notify(CHECK);
553 }
554
555 // NOTE: see comment of notify()
556 void ObjectSynchronizer::notifyall(Handle obj, TRAPS) {
557 JavaThread* current = THREAD;
558
559 markWord mark = obj->mark();
560 if ((mark.is_fast_locked() && current->lock_stack().contains(obj()))) {
561 // Not inflated so there can't be any waiters to notify.
562 return;
563 }
564
565 ObjectMonitor* monitor = ObjectSynchronizer::inflate_locked_or_imse(obj(), inflate_cause_notify, CHECK);
566 monitor->notifyAll(CHECK);
567 }
568
569 // -----------------------------------------------------------------------------
570 // Hash Code handling
571
572 struct SharedGlobals {
573 char _pad_prefix[OM_CACHE_LINE_SIZE];
574 // This is a highly shared mostly-read variable.
575 // To avoid false-sharing it needs to be the sole occupant of a cache line.
576 volatile int stw_random;
577 DEFINE_PAD_MINUS_SIZE(1, OM_CACHE_LINE_SIZE, sizeof(volatile int));
623 // This is probably the best overall implementation -- we'll
624 // likely make this the default in future releases.
625 unsigned t = current->_hashStateX;
626 t ^= (t << 11);
627 current->_hashStateX = current->_hashStateY;
628 current->_hashStateY = current->_hashStateZ;
629 current->_hashStateZ = current->_hashStateW;
630 unsigned v = current->_hashStateW;
631 v = (v ^ (v >> 19)) ^ (t ^ (t >> 8));
632 current->_hashStateW = v;
633 value = v;
634 }
635
636 value &= markWord::hash_mask;
637 if (value == 0) value = 0xBAD;
638 assert(value != markWord::no_hash, "invariant");
639 return value;
640 }
641
642 intptr_t ObjectSynchronizer::FastHashCode(Thread* current, oop obj) {
643 while (true) {
644 ObjectMonitor* monitor = nullptr;
645 markWord temp, test;
646 intptr_t hash;
647 markWord mark = obj->mark_acquire();
648 // If UseObjectMonitorTable is set the hash can simply be installed in the
649 // object header, since the monitor isn't in the object header.
650 if (UseObjectMonitorTable || !mark.has_monitor()) {
651 hash = mark.hash();
652 if (hash != 0) { // if it has a hash, just return it
653 return hash;
654 }
655 hash = get_next_hash(current, obj); // get a new hash
656 temp = mark.copy_set_hash(hash); // merge the hash into header
657 // try to install the hash
658 test = obj->cas_set_mark(temp, mark);
659 if (test == mark) { // if the hash was installed, return it
660 return hash;
661 }
662 // CAS failed, retry
721 hash = test.hash();
722 assert(test.is_neutral(), "invariant: header=" INTPTR_FORMAT, test.value());
723 assert(hash != 0, "should only have lost the race to a thread that set a non-zero hash");
724 }
725 if (monitor->is_being_async_deflated() && !UseObjectMonitorTable) {
726 // If we detect that async deflation has occurred, then we
727 // attempt to restore the header/dmw to the object's header
728 // so that we only retry once if the deflater thread happens
729 // to be slow.
730 monitor->install_displaced_markword_in_object(obj);
731 continue;
732 }
733 }
734 // We finally get the hash.
735 return hash;
736 }
737 }
738
739 bool ObjectSynchronizer::current_thread_holds_lock(JavaThread* current,
740 Handle h_obj) {
741 assert(current == JavaThread::current(), "Can only be called on current thread");
742 oop obj = h_obj();
743
744 markWord mark = obj->mark_acquire();
745
746 if (mark.is_fast_locked()) {
747 // fast-locking case, see if lock is in current's lock stack
748 return current->lock_stack().contains(h_obj());
749 }
750
751 while (mark.has_monitor()) {
752 ObjectMonitor* monitor = read_monitor(obj, mark);
753 if (monitor != nullptr) {
754 return monitor->is_entered(current) != 0;
755 }
756 // Racing with inflation/deflation, retry
757 mark = obj->mark_acquire();
758
759 if (mark.is_fast_locked()) {
760 // Some other thread fast_locked, current could not have held the lock
|
298 // removed from the system.
299 //
300 // Note: If the _in_use_list max exceeds the ceiling, then
301 // monitors_used_above_threshold() will use the in_use_list max instead
302 // of the thread count derived ceiling because we have used more
303 // ObjectMonitors than the estimated average.
304 //
305 // Note: If deflate_idle_monitors() has NoAsyncDeflationProgressMax
306 // no-progress async monitor deflation cycles in a row, then the ceiling
307 // is adjusted upwards by monitors_used_above_threshold().
308 //
309 // Start the ceiling with the estimate for one thread in initialize()
310 // which is called after cmd line options are processed.
311 static size_t _in_use_list_ceiling = 0;
312 bool volatile ObjectSynchronizer::_is_async_deflation_requested = false;
313 bool volatile ObjectSynchronizer::_is_final_audit = false;
314 jlong ObjectSynchronizer::_last_async_deflation_time_ns = 0;
315 static uintx _no_progress_cnt = 0;
316 static bool _no_progress_skip_increment = false;
317
318 // These checks are required for wait, notify and exit to avoid inflating the monitor to
319 // find out this inline type object cannot be locked.
320 #define CHECK_THROW_NOSYNC_IMSE(obj) \
321 if ((obj)->mark().is_inline_type()) { \
322 /*
323 * A value object can never be synchronized upon. The error message we use
324 * here is (accurate and) consistent with the one we use for identity objects
325 * when the current thread isn't the owner of the monitor.
326 */ \
327 THROW_MSG(vmSymbols::java_lang_IllegalMonitorStateException(), "current thread is not owner"); \
328 }
329
330 #define CHECK_THROW_NOSYNC_IMSE_0(obj) \
331 if ((obj)->mark().is_inline_type()) { \
332 /*
333 * A value object can never be synchronized upon. The error message we use
334 * here is (accurate and) consistent with the one we use for identity objects
335 * when the current thread isn't the owner of the monitor.
336 */ \
337 THROW_MSG_0(vmSymbols::java_lang_IllegalMonitorStateException(), "current thread is not owner"); \
338 }
339
340 // =====================> Quick functions
341
342 // The quick_* forms are special fast-path variants used to improve
343 // performance. In the simplest case, a "quick_*" implementation could
344 // simply return false, in which case the caller will perform the necessary
345 // state transitions and call the slow-path form.
346 // The fast-path is designed to handle frequently arising cases in an efficient
347 // manner and is just a degenerate "optimistic" variant of the slow-path.
348 // returns true -- to indicate the call was satisfied.
349 // returns false -- to indicate the call needs the services of the slow-path.
350 // A no-loitering ordinance is in effect for code in the quick_* family
351 // operators: safepoints or indefinite blocking (blocking that might span a
352 // safepoint) are forbidden. Generally the thread_state() is _in_Java upon
353 // entry.
354 //
355 // Consider: An interesting optimization is to have the JIT recognize the
356 // following common idiom:
357 // synchronized (someobj) { .... ; notify(); }
358 // That is, we find a notify() or notifyAll() call that immediately precedes
359 // the monitorexit operation. In that case the JIT could fuse the operations
360 // into a single notifyAndExit() runtime primitive.
361
362 bool ObjectSynchronizer::quick_notify(oopDesc* obj, JavaThread* current, bool all) {
363 assert(current->thread_state() == _thread_in_Java, "invariant");
364 NoSafepointVerifier nsv;
365 if (obj == nullptr) return false; // slow-path for invalid obj
366 assert(!obj->klass()->is_inline_klass(), "monitor op on inline type");
367 const markWord mark = obj->mark();
368
369 if (mark.is_fast_locked() && current->lock_stack().contains(cast_to_oop(obj))) {
370 // Degenerate notify
371 // fast-locked by caller so by definition the implied waitset is empty.
372 return true;
373 }
374
375 if (mark.has_monitor()) {
376 ObjectMonitor* const mon = read_monitor(obj, mark);
377 if (mon == nullptr) {
378 // Racing with inflation/deflation go slow path
379 return false;
380 }
381 assert(mon->object() == oop(obj), "invariant");
382 if (!mon->has_owner(current)) return false; // slow-path for IMS exception
383
384 if (mon->first_waiter() != nullptr) {
385 // We have one or more waiters. Since this is an inflated monitor
386 // that we own, we quickly notify them here and now, avoiding the slow-path.
434 } else {
435 vblog.info("Cannot find the last Java frame");
436 }
437
438 EventSyncOnValueBasedClass event;
439 if (event.should_commit()) {
440 event.set_valueBasedClass(obj->klass());
441 event.commit();
442 }
443 }
444
445 if (bcp_was_adjusted) {
446 last_frame.interpreter_frame_set_bcp(last_frame.interpreter_frame_bcp() + 1);
447 }
448 }
449
450 // -----------------------------------------------------------------------------
451 // JNI locks on java objects
452 // NOTE: must use heavy weight monitor to handle jni monitor enter
453 void ObjectSynchronizer::jni_enter(Handle obj, JavaThread* current) {
454 JavaThread* THREAD = current;
455 // Top native frames in the stack will not be seen if we attempt
456 // preemption, since we start walking from the last Java anchor.
457 NoPreemptMark npm(current);
458
459 if (obj->klass()->is_value_based()) {
460 handle_sync_on_value_based_class(obj, current);
461 }
462
463 if (obj->klass()->is_inline_klass()) {
464 ResourceMark rm(THREAD);
465 stringStream ss;
466 ss.print("Cannot synchronize on an instance of value class %s",
467 obj->klass()->external_name());
468 THROW_MSG(vmSymbols::java_lang_IdentityException(), ss.as_string());
469 }
470
471 // the current locking is from JNI instead of Java code
472 current->set_current_pending_monitor_is_from_java(false);
473 // An async deflation can race after the inflate() call and before
474 // enter() can make the ObjectMonitor busy. enter() returns false if
475 // we have lost the race to async deflation and we simply try again.
476 while (true) {
477 BasicLock lock;
478 if (ObjectSynchronizer::inflate_and_enter(obj(), &lock, inflate_cause_jni_enter, current, current) != nullptr) {
479 break;
480 }
481 }
482 current->set_current_pending_monitor_is_from_java(true);
483 }
484
485 // NOTE: must use heavy weight monitor to handle jni monitor exit
486 void ObjectSynchronizer::jni_exit(oop obj, TRAPS) {
487 JavaThread* current = THREAD;
488 CHECK_THROW_NOSYNC_IMSE(obj);
489
490 ObjectMonitor* monitor;
491 monitor = ObjectSynchronizer::inflate_locked_or_imse(obj, inflate_cause_jni_exit, CHECK);
492 // If this thread has locked the object, exit the monitor. We
493 // intentionally do not use CHECK on check_owner because we must exit the
494 // monitor even if an exception was already pending.
495 if (monitor->check_owner(THREAD)) {
496 monitor->exit(current);
497 }
498 }
499
500 // -----------------------------------------------------------------------------
501 // Internal VM locks on java objects
502 // standard constructor, allows locking failures
503 ObjectLocker::ObjectLocker(Handle obj, TRAPS) : _thread(THREAD), _obj(obj),
504 _npm(_thread, _thread->at_preemptable_init() /* ignore_mark */), _skip_exit(false) {
505 assert(!_thread->preempting(), "");
506
507 _thread->check_for_valid_safepoint_state();
508
529 if (_obj() != nullptr && !_skip_exit) {
530 ObjectSynchronizer::exit(_obj(), &_lock, _thread);
531 }
532 }
533
534 void ObjectLocker::wait_uninterruptibly(TRAPS) {
535 ObjectSynchronizer::waitUninterruptibly(_obj, 0, _thread);
536 if (_thread->preempting()) {
537 _skip_exit = true;
538 ObjectSynchronizer::read_monitor(_obj())->set_object_strong();
539 _thread->set_pending_preempted_exception();
540 }
541 }
542
543 // -----------------------------------------------------------------------------
544 // Wait/Notify/NotifyAll
545 // NOTE: must use heavy weight monitor to handle wait()
546
547 int ObjectSynchronizer::wait(Handle obj, jlong millis, TRAPS) {
548 JavaThread* current = THREAD;
549 CHECK_THROW_NOSYNC_IMSE_0(obj);
550 if (millis < 0) {
551 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "timeout value is negative");
552 }
553
554 ObjectMonitor* monitor;
555 monitor = ObjectSynchronizer::inflate_locked_or_imse(obj(), inflate_cause_wait, CHECK_0);
556
557 DTRACE_MONITOR_WAIT_PROBE(monitor, obj(), current, millis);
558 monitor->wait(millis, true, THREAD); // Not CHECK as we need following code
559
560 // This dummy call is in place to get around dtrace bug 6254741. Once
561 // that's fixed we can uncomment the following line, remove the call
562 // and change this function back into a "void" func.
563 // DTRACE_MONITOR_PROBE(waited, monitor, obj(), THREAD);
564 int ret_code = dtrace_waited_probe(monitor, obj, THREAD);
565 return ret_code;
566 }
567
568 void ObjectSynchronizer::waitUninterruptibly(Handle obj, jlong millis, TRAPS) {
569 assert(millis >= 0, "timeout value is negative");
570
571 ObjectMonitor* monitor;
572 monitor = ObjectSynchronizer::inflate_locked_or_imse(obj(), inflate_cause_wait, CHECK);
573 monitor->wait(millis, false, THREAD);
574 }
575
576
577 void ObjectSynchronizer::notify(Handle obj, TRAPS) {
578 JavaThread* current = THREAD;
579 CHECK_THROW_NOSYNC_IMSE(obj);
580
581 markWord mark = obj->mark();
582 if ((mark.is_fast_locked() && current->lock_stack().contains(obj()))) {
583 // Not inflated so there can't be any waiters to notify.
584 return;
585 }
586 ObjectMonitor* monitor = ObjectSynchronizer::inflate_locked_or_imse(obj(), inflate_cause_notify, CHECK);
587 monitor->notify(CHECK);
588 }
589
590 // NOTE: see comment of notify()
591 void ObjectSynchronizer::notifyall(Handle obj, TRAPS) {
592 JavaThread* current = THREAD;
593 CHECK_THROW_NOSYNC_IMSE(obj);
594
595 markWord mark = obj->mark();
596 if ((mark.is_fast_locked() && current->lock_stack().contains(obj()))) {
597 // Not inflated so there can't be any waiters to notify.
598 return;
599 }
600
601 ObjectMonitor* monitor = ObjectSynchronizer::inflate_locked_or_imse(obj(), inflate_cause_notify, CHECK);
602 monitor->notifyAll(CHECK);
603 }
604
605 // -----------------------------------------------------------------------------
606 // Hash Code handling
607
608 struct SharedGlobals {
609 char _pad_prefix[OM_CACHE_LINE_SIZE];
610 // This is a highly shared mostly-read variable.
611 // To avoid false-sharing it needs to be the sole occupant of a cache line.
612 volatile int stw_random;
613 DEFINE_PAD_MINUS_SIZE(1, OM_CACHE_LINE_SIZE, sizeof(volatile int));
659 // This is probably the best overall implementation -- we'll
660 // likely make this the default in future releases.
661 unsigned t = current->_hashStateX;
662 t ^= (t << 11);
663 current->_hashStateX = current->_hashStateY;
664 current->_hashStateY = current->_hashStateZ;
665 current->_hashStateZ = current->_hashStateW;
666 unsigned v = current->_hashStateW;
667 v = (v ^ (v >> 19)) ^ (t ^ (t >> 8));
668 current->_hashStateW = v;
669 value = v;
670 }
671
672 value &= markWord::hash_mask;
673 if (value == 0) value = 0xBAD;
674 assert(value != markWord::no_hash, "invariant");
675 return value;
676 }
677
678 intptr_t ObjectSynchronizer::FastHashCode(Thread* current, oop obj) {
679 // VM should be calling bootstrap method.
680 assert(!obj->klass()->is_inline_klass(), "FastHashCode should not be called for inline classes");
681
682 while (true) {
683 ObjectMonitor* monitor = nullptr;
684 markWord temp, test;
685 intptr_t hash;
686 markWord mark = obj->mark_acquire();
687 // If UseObjectMonitorTable is set the hash can simply be installed in the
688 // object header, since the monitor isn't in the object header.
689 if (UseObjectMonitorTable || !mark.has_monitor()) {
690 hash = mark.hash();
691 if (hash != 0) { // if it has a hash, just return it
692 return hash;
693 }
694 hash = get_next_hash(current, obj); // get a new hash
695 temp = mark.copy_set_hash(hash); // merge the hash into header
696 // try to install the hash
697 test = obj->cas_set_mark(temp, mark);
698 if (test == mark) { // if the hash was installed, return it
699 return hash;
700 }
701 // CAS failed, retry
760 hash = test.hash();
761 assert(test.is_neutral(), "invariant: header=" INTPTR_FORMAT, test.value());
762 assert(hash != 0, "should only have lost the race to a thread that set a non-zero hash");
763 }
764 if (monitor->is_being_async_deflated() && !UseObjectMonitorTable) {
765 // If we detect that async deflation has occurred, then we
766 // attempt to restore the header/dmw to the object's header
767 // so that we only retry once if the deflater thread happens
768 // to be slow.
769 monitor->install_displaced_markword_in_object(obj);
770 continue;
771 }
772 }
773 // We finally get the hash.
774 return hash;
775 }
776 }
777
778 bool ObjectSynchronizer::current_thread_holds_lock(JavaThread* current,
779 Handle h_obj) {
780 if (h_obj->mark().is_inline_type()) {
781 return false;
782 }
783 assert(current == JavaThread::current(), "Can only be called on current thread");
784 oop obj = h_obj();
785
786 markWord mark = obj->mark_acquire();
787
788 if (mark.is_fast_locked()) {
789 // fast-locking case, see if lock is in current's lock stack
790 return current->lock_stack().contains(h_obj());
791 }
792
793 while (mark.has_monitor()) {
794 ObjectMonitor* monitor = read_monitor(obj, mark);
795 if (monitor != nullptr) {
796 return monitor->is_entered(current) != 0;
797 }
798 // Racing with inflation/deflation, retry
799 mark = obj->mark_acquire();
800
801 if (mark.is_fast_locked()) {
802 // Some other thread fast_locked, current could not have held the lock
|