@@ -965,7 +965,7 @@ static intptr_t get_next_hash(Thread* current, oop obj) {
965965 return value;
966966}
967967
968- static intptr_t install_hash_code (Thread* current, oop obj) {
968+ static intptr_t install_hash_code (Thread* current, oop obj, intptr_t * requested_value = nullptr ) {
969969 assert (UseObjectMonitorTable && LockingMode == LM_LIGHTWEIGHT, " must be" );
970970
971971 markWord mark = obj->mark_acquire ();
@@ -975,7 +975,7 @@ static intptr_t install_hash_code(Thread* current, oop obj) {
975975 return hash;
976976 }
977977
978- hash = get_next_hash (current, obj);
978+ hash = requested_value != nullptr ? *requested_value : get_next_hash (current, obj);
979979 const markWord old_mark = mark;
980980 const markWord new_mark = old_mark.copy_set_hash (hash);
981981
@@ -986,11 +986,14 @@ static intptr_t install_hash_code(Thread* current, oop obj) {
986986 }
987987}
988988
989- intptr_t ObjectSynchronizer::FastHashCode (Thread* current, oop obj) {
989+ intptr_t ObjectSynchronizer::FastHashCode (Thread* current, oop obj, intptr_t * requested_value) {
990+ assert (requested_value == nullptr ||
991+ (*requested_value != markWord::no_hash && *requested_value >> markWord::hash_bits == 0 ),
992+ " invalid identity hash: %ld" , *requested_value);
990993 if (UseObjectMonitorTable) {
991994 // Since the monitor isn't in the object header, the hash can simply be
992995 // installed in the object header.
993- return install_hash_code (current, obj);
996+ return install_hash_code (current, obj, requested_value );
994997 }
995998
996999 while (true ) {
@@ -1007,7 +1010,7 @@ intptr_t ObjectSynchronizer::FastHashCode(Thread* current, oop obj) {
10071010 if (hash != 0 ) { // if it has a hash, just return it
10081011 return hash;
10091012 }
1010- hash = get_next_hash (current, obj); // get a new hash
1013+ hash = requested_value != nullptr ? *requested_value : get_next_hash (current, obj); // get a new hash
10111014 temp = mark.copy_set_hash (hash); // merge the hash into header
10121015 // try to install the hash
10131016 test = obj->cas_set_mark (temp, mark);
@@ -1082,7 +1085,7 @@ intptr_t ObjectSynchronizer::FastHashCode(Thread* current, oop obj) {
10821085 assert (mark.is_neutral (), " invariant: header=" INTPTR_FORMAT, mark.value ());
10831086 hash = mark.hash ();
10841087 if (hash == 0 ) { // if it does not have a hash
1085- hash = get_next_hash (current, obj); // get a new hash
1088+ hash = requested_value != nullptr ? *requested_value : get_next_hash (current, obj); // get a new hash
10861089 temp = mark.copy_set_hash (hash) ; // merge the hash into header
10871090 assert (temp.is_neutral (), " invariant: header=" INTPTR_FORMAT, temp.value ());
10881091 uintptr_t v = Atomic::cmpxchg (monitor->metadata_addr (), mark.value (), temp.value ());
0 commit comments