664 // The initial monitor is ours for the taking. |
664 // The initial monitor is ours for the taking. |
665 // Monitor not filled in frame manager any longer as this caused race condition with biased locking. |
665 // Monitor not filled in frame manager any longer as this caused race condition with biased locking. |
666 BasicObjectLock* mon = &istate->monitor_base()[-1]; |
666 BasicObjectLock* mon = &istate->monitor_base()[-1]; |
667 mon->set_obj(rcvr); |
667 mon->set_obj(rcvr); |
668 bool success = false; |
668 bool success = false; |
669 uintptr_t epoch_mask_in_place = (uintptr_t)markWord::epoch_mask_in_place; |
669 uintptr_t epoch_mask_in_place = markWord::epoch_mask_in_place; |
670 markWord mark = rcvr->mark(); |
670 markWord mark = rcvr->mark(); |
671 intptr_t hash = (intptr_t) markWord::no_hash; |
671 intptr_t hash = (intptr_t) markWord::no_hash; |
672 // Implies UseBiasedLocking. |
672 // Implies UseBiasedLocking. |
673 if (mark.has_bias_pattern()) { |
673 if (mark.has_bias_pattern()) { |
674 uintptr_t thread_ident; |
674 uintptr_t thread_ident; |
675 uintptr_t anticipated_bias_locking_value; |
675 uintptr_t anticipated_bias_locking_value; |
676 thread_ident = (uintptr_t)istate->thread(); |
676 thread_ident = (uintptr_t)istate->thread(); |
677 anticipated_bias_locking_value = |
677 anticipated_bias_locking_value = |
678 (((uintptr_t)rcvr->klass()->prototype_header().value() | thread_ident) ^ mark.value()) & |
678 ((rcvr->klass()->prototype_header().value() | thread_ident) ^ mark.value()) & |
679 ~((uintptr_t) markWord::age_mask_in_place); |
679 ~(markWord::age_mask_in_place); |
680 |
680 |
681 if (anticipated_bias_locking_value == 0) { |
681 if (anticipated_bias_locking_value == 0) { |
682 // Already biased towards this thread, nothing to do. |
682 // Already biased towards this thread, nothing to do. |
683 if (PrintBiasedLockingStatistics) { |
683 if (PrintBiasedLockingStatistics) { |
684 (* BiasedLocking::biased_lock_entry_count_addr())++; |
684 (* BiasedLocking::biased_lock_entry_count_addr())++; |
709 } |
709 } |
710 success = true; |
710 success = true; |
711 } else { |
711 } else { |
712 // Try to bias towards thread in case object is anonymously biased. |
712 // Try to bias towards thread in case object is anonymously biased. |
713 markWord header(mark.value() & |
713 markWord header(mark.value() & |
714 ((uintptr_t)markWord::biased_lock_mask_in_place | |
714 (markWord::biased_lock_mask_in_place | |
715 (uintptr_t)markWord::age_mask_in_place | epoch_mask_in_place)); |
715 markWord::age_mask_in_place | epoch_mask_in_place)); |
716 if (hash != markWord::no_hash) { |
716 if (hash != markWord::no_hash) { |
717 header = header.copy_set_hash(hash); |
717 header = header.copy_set_hash(hash); |
718 } |
718 } |
719 markWord new_header(header.value() | thread_ident); |
719 markWord new_header(header.value() | thread_ident); |
720 // Debugging hint. |
720 // Debugging hint. |
849 // find a free monitor |
849 // find a free monitor |
850 BasicObjectLock* entry = (BasicObjectLock*) istate->stack_base(); |
850 BasicObjectLock* entry = (BasicObjectLock*) istate->stack_base(); |
851 assert(entry->obj() == NULL, "Frame manager didn't allocate the monitor"); |
851 assert(entry->obj() == NULL, "Frame manager didn't allocate the monitor"); |
852 entry->set_obj(lockee); |
852 entry->set_obj(lockee); |
853 bool success = false; |
853 bool success = false; |
854 uintptr_t epoch_mask_in_place = (uintptr_t)markWord::epoch_mask_in_place; |
854 uintptr_t epoch_mask_in_place = markWord::epoch_mask_in_place; |
855 |
855 |
856 markWord mark = lockee->mark(); |
856 markWord mark = lockee->mark(); |
857 intptr_t hash = (intptr_t) markWord::no_hash; |
857 intptr_t hash = (intptr_t) markWord::no_hash; |
858 // implies UseBiasedLocking |
858 // implies UseBiasedLocking |
859 if (mark.has_bias_pattern()) { |
859 if (mark.has_bias_pattern()) { |
860 uintptr_t thread_ident; |
860 uintptr_t thread_ident; |
861 uintptr_t anticipated_bias_locking_value; |
861 uintptr_t anticipated_bias_locking_value; |
862 thread_ident = (uintptr_t)istate->thread(); |
862 thread_ident = (uintptr_t)istate->thread(); |
863 anticipated_bias_locking_value = |
863 anticipated_bias_locking_value = |
864 (((uintptr_t)lockee->klass()->prototype_header().value() | thread_ident) ^ mark.value()) & |
864 ((lockee->klass()->prototype_header().value() | thread_ident) ^ mark.value()) & |
865 ~((uintptr_t) markWord::age_mask_in_place); |
865 ~(markWord::age_mask_in_place); |
866 |
866 |
867 if (anticipated_bias_locking_value == 0) { |
867 if (anticipated_bias_locking_value == 0) { |
868 // already biased towards this thread, nothing to do |
868 // already biased towards this thread, nothing to do |
869 if (PrintBiasedLockingStatistics) { |
869 if (PrintBiasedLockingStatistics) { |
870 (* BiasedLocking::biased_lock_entry_count_addr())++; |
870 (* BiasedLocking::biased_lock_entry_count_addr())++; |
895 CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception); |
895 CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception); |
896 } |
896 } |
897 success = true; |
897 success = true; |
898 } else { |
898 } else { |
899 // try to bias towards thread in case object is anonymously biased |
899 // try to bias towards thread in case object is anonymously biased |
900 markWord header(mark.value() & ((uintptr_t)markWord::biased_lock_mask_in_place | |
900 markWord header(mark.value() & (markWord::biased_lock_mask_in_place | |
901 (uintptr_t)markWord::age_mask_in_place | epoch_mask_in_place)); |
901 markWord::age_mask_in_place | epoch_mask_in_place)); |
902 if (hash != markWord::no_hash) { |
902 if (hash != markWord::no_hash) { |
903 header = header.copy_set_hash(hash); |
903 header = header.copy_set_hash(hash); |
904 } |
904 } |
905 markWord new_header(header.value() | thread_ident); |
905 markWord new_header(header.value() | thread_ident); |
906 // debugging hint |
906 // debugging hint |
1789 most_recent++; |
1789 most_recent++; |
1790 } |
1790 } |
1791 if (entry != NULL) { |
1791 if (entry != NULL) { |
1792 entry->set_obj(lockee); |
1792 entry->set_obj(lockee); |
1793 int success = false; |
1793 int success = false; |
1794 uintptr_t epoch_mask_in_place = (uintptr_t)markWord::epoch_mask_in_place; |
1794 uintptr_t epoch_mask_in_place = markWord::epoch_mask_in_place; |
1795 |
1795 |
1796 markWord mark = lockee->mark(); |
1796 markWord mark = lockee->mark(); |
1797 intptr_t hash = (intptr_t) markWord::no_hash; |
1797 intptr_t hash = (intptr_t) markWord::no_hash; |
1798 // implies UseBiasedLocking |
1798 // implies UseBiasedLocking |
1799 if (mark.has_bias_pattern()) { |
1799 if (mark.has_bias_pattern()) { |
1800 uintptr_t thread_ident; |
1800 uintptr_t thread_ident; |
1801 uintptr_t anticipated_bias_locking_value; |
1801 uintptr_t anticipated_bias_locking_value; |
1802 thread_ident = (uintptr_t)istate->thread(); |
1802 thread_ident = (uintptr_t)istate->thread(); |
1803 anticipated_bias_locking_value = |
1803 anticipated_bias_locking_value = |
1804 (((uintptr_t)lockee->klass()->prototype_header().value() | thread_ident) ^ mark.value()) & |
1804 ((lockee->klass()->prototype_header().value() | thread_ident) ^ mark.value()) & |
1805 ~((uintptr_t) markWord::age_mask_in_place); |
1805 ~(markWord::age_mask_in_place); |
1806 |
1806 |
1807 if (anticipated_bias_locking_value == 0) { |
1807 if (anticipated_bias_locking_value == 0) { |
1808 // already biased towards this thread, nothing to do |
1808 // already biased towards this thread, nothing to do |
1809 if (PrintBiasedLockingStatistics) { |
1809 if (PrintBiasedLockingStatistics) { |
1810 (* BiasedLocking::biased_lock_entry_count_addr())++; |
1810 (* BiasedLocking::biased_lock_entry_count_addr())++; |
1837 } |
1837 } |
1838 success = true; |
1838 success = true; |
1839 } |
1839 } |
1840 else { |
1840 else { |
1841 // try to bias towards thread in case object is anonymously biased |
1841 // try to bias towards thread in case object is anonymously biased |
1842 markWord header(mark.value() & ((uintptr_t)markWord::biased_lock_mask_in_place | |
1842 markWord header(mark.value() & (markWord::biased_lock_mask_in_place | |
1843 (uintptr_t)markWord::age_mask_in_place | |
1843 markWord::age_mask_in_place | |
1844 epoch_mask_in_place)); |
1844 epoch_mask_in_place)); |
1845 if (hash != markWord::no_hash) { |
1845 if (hash != markWord::no_hash) { |
1846 header = header.copy_set_hash(hash); |
1846 header = header.copy_set_hash(hash); |
1847 } |
1847 } |
1848 markWord new_header(header.value() | thread_ident); |
1848 markWord new_header(header.value() | thread_ident); |