diff --git a/runtime/jcl/common/java_lang_invoke_MethodHandleNatives.cpp b/runtime/jcl/common/java_lang_invoke_MethodHandleNatives.cpp index a7137c4c201..09d0c71062b 100644 --- a/runtime/jcl/common/java_lang_invoke_MethodHandleNatives.cpp +++ b/runtime/jcl/common/java_lang_invoke_MethodHandleNatives.cpp @@ -881,13 +881,52 @@ Java_java_lang_invoke_MethodHandleNatives_resolve(JNIEnv *env, jclass clazz, job vmindex = (jlong)(UDATA)methodID; target = (jlong)(UDATA)method; + J9ROMMethod *romMethod = J9_ROM_METHOD_FROM_RAM_METHOD(methodID->method); + J9UTF8 *methodName = J9ROMMETHOD_NAME(romMethod); + U_32 methodModifiers = romMethod->modifiers; new_clazz = J9VM_J9CLASS_TO_HEAPCLASS(J9_CLASS_FROM_METHOD(method)); + new_flags = methodModifiers & CFR_METHOD_ACCESS_MASK; - J9ROMMethod *romMethod = J9_ROM_METHOD_FROM_RAM_METHOD(methodID->method); - new_flags = flags | (romMethod->modifiers & CFR_METHOD_ACCESS_MASK); - if (J9_ARE_ANY_BITS_SET(romMethod->modifiers, J9AccMethodCallerSensitive)) { + if (J9_ARE_ANY_BITS_SET(methodModifiers, J9AccMethodCallerSensitive)) { new_flags |= MN_CALLER_SENSITIVE; } + + if (J9_ARE_ALL_BITS_SET(flags, MN_IS_METHOD)) { + new_flags |= MN_IS_METHOD; + if (MH_REF_INVOKEINTERFACE == ref_kind) { + Assert_JCL_true(J9_ARE_NO_BITS_SET(methodModifiers, J9AccStatic)); + if (J9_ARE_ALL_BITS_SET(methodID->vTableIndex, J9_JNI_MID_INTERFACE)) { + new_flags |= MH_REF_INVOKEINTERFACE << MN_REFERENCE_KIND_SHIFT; + } else if (!J9ROMMETHOD_HAS_VTABLE(romMethod)) { + new_flags |= MH_REF_INVOKESPECIAL << MN_REFERENCE_KIND_SHIFT; + } else { + new_flags |= MH_REF_INVOKEVIRTUAL << MN_REFERENCE_KIND_SHIFT; + } + } else if (MH_REF_INVOKESPECIAL == ref_kind) { + Assert_JCL_true(J9_ARE_NO_BITS_SET(methodModifiers, J9AccStatic)); + new_flags |= MH_REF_INVOKESPECIAL << MN_REFERENCE_KIND_SHIFT; + } else if (MH_REF_INVOKESTATIC == ref_kind) { + Assert_JCL_true(J9_ARE_ALL_BITS_SET(methodModifiers, J9AccStatic)); + new_flags |= MH_REF_INVOKESTATIC << MN_REFERENCE_KIND_SHIFT; + } else if (MH_REF_INVOKEVIRTUAL == ref_kind) { + Assert_JCL_true(J9_ARE_NO_BITS_SET(methodModifiers, J9AccStatic)); + if (!J9ROMMETHOD_HAS_VTABLE(romMethod)) { + new_flags |= MH_REF_INVOKESPECIAL << MN_REFERENCE_KIND_SHIFT; + } else { + if (J9_ARE_ALL_BITS_SET(methodID->vTableIndex, J9_JNI_MID_INTERFACE)) { + new_clazz = J9VM_J9CLASS_TO_HEAPCLASS(resolvedClass); + } + new_flags |= MH_REF_INVOKEVIRTUAL << MN_REFERENCE_KIND_SHIFT; + } + } else { + Assert_JCL_unreachable(); + } + } else if (J9_ARE_NO_BITS_SET(methodModifiers, J9AccStatic) && ('<' == (char)*J9UTF8_DATA(methodName))) { + new_flags |= MN_IS_CONSTRUCTOR; + new_flags |= MH_REF_INVOKESPECIAL << MN_REFERENCE_KIND_SHIFT; + } else { + Assert_JCL_unreachable(); + } } } if (J9_ARE_ANY_BITS_SET(flags, MN_IS_FIELD)) { J9Class *declaringClass;