From c7c6a136522b4c67b3ca24b3407ace6bda74653f Mon Sep 17 00:00:00 2001 From: Theresa Mammarella Date: Fri, 22 Nov 2024 13:39:00 -0500 Subject: [PATCH] Don't assume lockword of class is at index 0 With valuetypes it's possible for the lockword not to be the first field. Signed-off-by: Theresa Mammarella --- .../common/java_lang_invoke_MethodHandleNatives.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/runtime/jcl/common/java_lang_invoke_MethodHandleNatives.cpp b/runtime/jcl/common/java_lang_invoke_MethodHandleNatives.cpp index 1ae5769d6fe..1b942333b4d 100644 --- a/runtime/jcl/common/java_lang_invoke_MethodHandleNatives.cpp +++ b/runtime/jcl/common/java_lang_invoke_MethodHandleNatives.cpp @@ -1368,8 +1368,15 @@ Java_java_lang_invoke_MethodHandleNatives_resolve( target = (jlong)offset; } } - - if ((0 != target) && ((0 != vmindex) || J9_ARE_ANY_BITS_SET(flags, MN_IS_METHOD | MN_IS_CONSTRUCTOR))) { + if ( +#if defined(J9VM_OPT_VALHALLA_VALUE_TYPES) + /* In project Valhalla fields may start at offset 0. */ + (NULL != new_clazz) +#else /* defined(J9VM_OPT_VALHALLA_VALUE_TYPES) */ + (0 != target) +#endif /* defined(J9VM_OPT_VALHALLA_VALUE_TYPES) */ + && ((0 != vmindex) || J9_ARE_ANY_BITS_SET(flags, MN_IS_METHOD | MN_IS_CONSTRUCTOR)) + ) { /* Refetch reference after GC point */ membernameObject = J9_JNI_UNWRAP_REFERENCE(self); if (addMemberNameToClass(currentThread, membernameObject, new_clazz)) {