From 4fe9b2b96df0b8f79924f26f06d2867d20617d7d Mon Sep 17 00:00:00 2001 From: Theresa Mammarella Date: Fri, 29 Nov 2024 11:21:05 -0500 Subject: [PATCH] Copy local signature from MethodHandleNatives.resolve Signed-off-by: Theresa Mammarella --- runtime/bcverify/clconstraints.c | 15 +++++++-------- runtime/jcl/common/java_dyn_methodhandle.c | 6 +++--- .../java_lang_invoke_MethodHandleNatives.cpp | 3 ++- runtime/jcl/common/java_lang_invoke_VarHandle.c | 1 + runtime/oti/bcverify_api.h | 4 ++-- runtime/oti/j9consts.h | 1 + runtime/oti/j9nonbuilder.h | 2 +- runtime/vm/createramclass.cpp | 4 ++-- runtime/vm/lookupmethod.c | 9 ++++++++- runtime/vm/resolvesupport.cpp | 4 ++-- 10 files changed, 29 insertions(+), 20 deletions(-) diff --git a/runtime/bcverify/clconstraints.c b/runtime/bcverify/clconstraints.c index d5daa835fc0..ac5d35263c1 100644 --- a/runtime/bcverify/clconstraints.c +++ b/runtime/bcverify/clconstraints.c @@ -71,7 +71,7 @@ validateArgs (J9VMThread* vmThread, J9ClassLoader* loader1, J9ClassLoader* loade * return 0 if no class loading constraints have been violated, or non-zero if they have been. */ UDATA -j9bcv_checkClassLoadingConstraintsForSignature (J9VMThread* vmThread, J9ClassLoader* loader1, J9ClassLoader* loader2, J9UTF8* sig1, J9UTF8* sig2) +j9bcv_checkClassLoadingConstraintsForSignature (J9VMThread* vmThread, J9ClassLoader* loader1, J9ClassLoader* loader2, J9UTF8* sig1, J9UTF8* sig2, UDATA copySig1) { U_32 index = 0, endIndex; U_32 length = J9UTF8_LENGTH(sig1); @@ -101,8 +101,7 @@ j9bcv_checkClassLoadingConstraintsForSignature (J9VMThread* vmThread, J9ClassLoa while (J9UTF8_DATA(sig1)[endIndex] != ';') { endIndex++; } - - rc = j9bcv_checkClassLoadingConstraintForName (vmThread, loader1, loader2, &J9UTF8_DATA(sig1)[index], &J9UTF8_DATA(sig2)[index], endIndex - index, FALSE); + rc = j9bcv_checkClassLoadingConstraintForName (vmThread, loader1, loader2, &J9UTF8_DATA(sig1)[index], &J9UTF8_DATA(sig2)[index], endIndex - index, copySig1, FALSE); if (rc) { break; } @@ -120,7 +119,7 @@ j9bcv_checkClassLoadingConstraintsForSignature (J9VMThread* vmThread, J9ClassLoa /* NOTE: the current thread must own the class table mutex */ UDATA -j9bcv_checkClassLoadingConstraintForName (J9VMThread* vmThread, J9ClassLoader* loader1, J9ClassLoader* loader2, U_8* name1, U_8* name2, UDATA length, UDATA copyUTFs) +j9bcv_checkClassLoadingConstraintForName (J9VMThread* vmThread, J9ClassLoader* loader1, J9ClassLoader* loader2, U_8* name1, U_8* name2, UDATA length, UDATA copyUTF1, UDATA copyUTF2) { J9Class *class1; J9Class *class2; @@ -140,7 +139,7 @@ j9bcv_checkClassLoadingConstraintForName (J9VMThread* vmThread, J9ClassLoader* l return 1; } } else if (class1 == NULL && class2 != NULL) { - const1 = registerClassLoadingConstraint (vmThread, loader1, name1, length, copyUTFs); + const1 = registerClassLoadingConstraint (vmThread, loader1, name1, length, copyUTF1); if (const1 == NULL) return 1; if (const1->clazz != NULL) { if (const1->clazz != class2) { @@ -151,7 +150,7 @@ j9bcv_checkClassLoadingConstraintForName (J9VMThread* vmThread, J9ClassLoader* l const1->clazz = class2; } } else if (class2 == NULL && class1 != NULL) { - const2 = registerClassLoadingConstraint (vmThread, loader2, name2, length, copyUTFs); + const2 = registerClassLoadingConstraint (vmThread, loader2, name2, length, copyUTF2); if (const2->clazz != NULL) { if (const2->clazz != class1) { return 1; @@ -164,11 +163,11 @@ j9bcv_checkClassLoadingConstraintForName (J9VMThread* vmThread, J9ClassLoader* l J9ClassLoadingConstraint *tempNext; J9ClassLoadingConstraint *tempPrevious; - const1 = registerClassLoadingConstraint (vmThread, loader1, name1, length, copyUTFs); + const1 = registerClassLoadingConstraint (vmThread, loader1, name1, length, copyUTF1); if (const1 == NULL) { return 1; } - const2 = registerClassLoadingConstraint (vmThread, loader2, name2, length, copyUTFs); + const2 = registerClassLoadingConstraint (vmThread, loader2, name2, length, copyUTF2); if (const2 == NULL) { return 1; } diff --git a/runtime/jcl/common/java_dyn_methodhandle.c b/runtime/jcl/common/java_dyn_methodhandle.c index 342d5207e14..9e1216ff301 100644 --- a/runtime/jcl/common/java_dyn_methodhandle.c +++ b/runtime/jcl/common/java_dyn_methodhandle.c @@ -375,7 +375,7 @@ accessCheckFieldSignature(J9VMThread *currentThread, J9Class* lookupClass, UDATA U_32 sigLength = J9UTF8_LENGTH(lookupSig) - sigOffset - 1; omrthread_monitor_enter(vm->classTableMutex); - if(verifyData->checkClassLoadingConstraintForNameFunction(currentThread, targetClassloader, ramClass->classLoader, &lookupSigData[sigOffset], &lookupSigData[sigOffset], sigLength, TRUE) != 0) { + if(verifyData->checkClassLoadingConstraintForNameFunction(currentThread, targetClassloader, ramClass->classLoader, &lookupSigData[sigOffset], &lookupSigData[sigOffset], sigLength, TRUE, TRUE) != 0) { result = FALSE; } omrthread_monitor_exit(vm->classTableMutex); @@ -445,7 +445,7 @@ accessCheckMethodSignature(J9VMThread *currentThread, J9Method *method, j9object /* Check if we really need to check this classloader constraint */ if (argumentRamClass->classLoader != targetClassloader) { - if(verifyData->checkClassLoadingConstraintForNameFunction(currentThread, targetClassloader, argumentRamClass->classLoader, &J9UTF8_DATA(targetSig)[index], &lookupSigData[index], endIndex - index, TRUE) != 0) { + if(verifyData->checkClassLoadingConstraintForNameFunction(currentThread, targetClassloader, argumentRamClass->classLoader, &J9UTF8_DATA(targetSig)[index], &lookupSigData[index], endIndex - index, TRUE, TRUE) != 0) { result = FALSE; goto releaseMutexAndReturn; } @@ -477,7 +477,7 @@ accessCheckMethodSignature(J9VMThread *currentThread, J9Method *method, j9object endIndex++; } - if(verifyData->checkClassLoadingConstraintForNameFunction(currentThread, targetClassloader, returnRamClass->classLoader, &J9UTF8_DATA(targetSig)[index], &lookupSigData[index], endIndex - index, TRUE) != 0) { + if(verifyData->checkClassLoadingConstraintForNameFunction(currentThread, targetClassloader, returnRamClass->classLoader, &J9UTF8_DATA(targetSig)[index], &lookupSigData[index], endIndex - index, TRUE, TRUE) != 0) { result = FALSE; goto releaseMutexAndReturn; } diff --git a/runtime/jcl/common/java_lang_invoke_MethodHandleNatives.cpp b/runtime/jcl/common/java_lang_invoke_MethodHandleNatives.cpp index 1b942333b4d..fe4e8c04668 100644 --- a/runtime/jcl/common/java_lang_invoke_MethodHandleNatives.cpp +++ b/runtime/jcl/common/java_lang_invoke_MethodHandleNatives.cpp @@ -1115,7 +1115,7 @@ Java_java_lang_invoke_MethodHandleNatives_resolve( Trc_JCL_java_lang_invoke_MethodHandleNatives_resolve_NAS(env, J9UTF8_LENGTH(name), J9UTF8_DATA(name), J9UTF8_LENGTH(signature), J9UTF8_DATA(signature)); if (J9_ARE_ANY_BITS_SET(flags, MN_IS_METHOD | MN_IS_CONSTRUCTOR)) { - UDATA lookupOptions = 0; + UDATA lookupOptions = J9_LOOK_LOCAL_NAS; #if JAVA_SPEC_VERSION >= 11 if (JNI_TRUE == speculativeResolve) { @@ -1323,6 +1323,7 @@ Java_java_lang_invoke_MethodHandleNatives_resolve( J9UTF8_DATA(signature) + sigOffset, J9UTF8_DATA(signature) + sigOffset, J9UTF8_LENGTH(signature) - sigOffset - 1, /* -1 to remove the trailing ;*/ + true, true); omrthread_monitor_exit(vm->classTableMutex); if (0 != clConstraintResult) { diff --git a/runtime/jcl/common/java_lang_invoke_VarHandle.c b/runtime/jcl/common/java_lang_invoke_VarHandle.c index 0655b08d67b..340d1736dd4 100644 --- a/runtime/jcl/common/java_lang_invoke_VarHandle.c +++ b/runtime/jcl/common/java_lang_invoke_VarHandle.c @@ -64,6 +64,7 @@ accessCheckFieldType(J9VMThread *currentThread, J9Class* lookupClass, J9Class* t &lookupSigData[1], &lookupSigData[1], J9UTF8_LENGTH(lookupSig) - 2, + TRUE, TRUE) != 0) { result = FALSE; } diff --git a/runtime/oti/bcverify_api.h b/runtime/oti/bcverify_api.h index 7dc772c226c..7d2ffb6b07c 100644 --- a/runtime/oti/bcverify_api.h +++ b/runtime/oti/bcverify_api.h @@ -163,7 +163,7 @@ bcvIsInitOrClinit (J9CfrConstantPoolInfo * info); * @return UDATA */ UDATA -j9bcv_checkClassLoadingConstraintsForSignature (J9VMThread* vmThread, J9ClassLoader* loader1, J9ClassLoader* loader2, J9UTF8* sig1, J9UTF8* sig2); +j9bcv_checkClassLoadingConstraintsForSignature (J9VMThread* vmThread, J9ClassLoader* loader1, J9ClassLoader* loader2, J9UTF8* sig1, J9UTF8* sig2, UDATA copySig1); /** * @brief @@ -176,7 +176,7 @@ j9bcv_checkClassLoadingConstraintsForSignature (J9VMThread* vmThread, J9ClassLoa * @return UDATA */ UDATA -j9bcv_checkClassLoadingConstraintForName (J9VMThread* vmThread, J9ClassLoader* loader1, J9ClassLoader* loader2, U_8* name1, U_8* name2, UDATA length, UDATA copyUTFs); +j9bcv_checkClassLoadingConstraintForName (J9VMThread* vmThread, J9ClassLoader* loader1, J9ClassLoader* loader2, U_8* name1, U_8* name2, UDATA length, UDATA copyUTF1, UDATA copyUTF2); /** * @brief diff --git a/runtime/oti/j9consts.h b/runtime/oti/j9consts.h index 9715affa6b9..fa357684a0e 100644 --- a/runtime/oti/j9consts.h +++ b/runtime/oti/j9consts.h @@ -618,6 +618,7 @@ extern "C" { #define J9_LOOK_NO_JAVA 0x80000 #define J9_LOOK_NO_NESTMATES 0x100000 #define J9_LOOK_NO_MODULE_CHECKS 0x200000 +#define J9_LOOK_LOCAL_NAS 0x400000 #define J9_STR_NONE 0x0 #define J9_STR_XLAT 0x1 diff --git a/runtime/oti/j9nonbuilder.h b/runtime/oti/j9nonbuilder.h index 5c562bbec62..9f57b2c6b62 100644 --- a/runtime/oti/j9nonbuilder.h +++ b/runtime/oti/j9nonbuilder.h @@ -2007,7 +2007,7 @@ typedef struct J9TranslationBufferSet { typedef struct J9BytecodeVerificationData { IDATA ( *verifyBytecodesFunction)(struct J9PortLibrary *portLib, struct J9Class *ramClass, struct J9ROMClass *romClass, struct J9BytecodeVerificationData *verifyData) ; - UDATA ( *checkClassLoadingConstraintForNameFunction)(struct J9VMThread* vmThread, struct J9ClassLoader* loader1, struct J9ClassLoader* loader2, U_8* name1, U_8* name2, UDATA length, UDATA copyUTFs) ; + UDATA ( *checkClassLoadingConstraintForNameFunction)(struct J9VMThread* vmThread, struct J9ClassLoader* loader1, struct J9ClassLoader* loader2, U_8* name1, U_8* name2, UDATA length, UDATA copyUTF1, UDATA copyUTF2) ; struct J9UTF8** classNameList; struct J9UTF8** classNameListEnd; U_8* classNameSegment; diff --git a/runtime/vm/createramclass.cpp b/runtime/vm/createramclass.cpp index 9a3bdec8b4a..a74e2301455 100644 --- a/runtime/vm/createramclass.cpp +++ b/runtime/vm/createramclass.cpp @@ -634,7 +634,7 @@ addInterfaceMethods(J9VMThread *vmStruct, J9ClassLoader *classLoader, J9Class *i vTableMethodLoader = methodClass->classLoader; } if (interfaceLoader != vTableMethodLoader) { - if (0 != j9bcv_checkClassLoadingConstraintsForSignature(vmStruct, vTableMethodLoader, interfaceLoader, vTableMethodSigUTF, interfaceMethodSigUTF)) { + if (0 != j9bcv_checkClassLoadingConstraintsForSignature(vmStruct, vTableMethodLoader, interfaceLoader, vTableMethodSigUTF, interfaceMethodSigUTF, FALSE)) { J9UTF8 *vTableMethodClassNameUTF = J9ROMCLASS_CLASSNAME(romClass); if (NULL != methodClass) { vTableMethodClassNameUTF = J9ROMCLASS_CLASSNAME(methodClass->romClass); @@ -1282,7 +1282,7 @@ processVTableMethod(J9VMThread *vmThread, J9ClassLoader *classLoader, UDATA *vTa J9ClassLoader *superclassVTableMethodLoader = superclassVTableMethodClass->classLoader; if (superclassVTableMethodLoader != classLoader) { J9UTF8 *superclassVTableMethodSigUTF = J9ROMMETHOD_SIGNATURE(superclassVTableROMMethod); - if (0 != j9bcv_checkClassLoadingConstraintsForSignature(vmThread, classLoader, superclassVTableMethodLoader, sigUTF, superclassVTableMethodSigUTF)) { + if (0 != j9bcv_checkClassLoadingConstraintsForSignature(vmThread, classLoader, superclassVTableMethodLoader, sigUTF, superclassVTableMethodSigUTF, FALSE)) { J9UTF8 *superclassVTableMethodClassNameUTF = J9ROMCLASS_CLASSNAME(superclassVTableMethodClass->romClass); J9UTF8 *newClassNameUTF = J9ROMCLASS_CLASSNAME(romClass); J9UTF8 *superclassVTableMethodNameUTF = J9ROMMETHOD_NAME(superclassVTableROMMethod); diff --git a/runtime/vm/lookupmethod.c b/runtime/vm/lookupmethod.c index e80ce48889d..41a8d460506 100644 --- a/runtime/vm/lookupmethod.c +++ b/runtime/vm/lookupmethod.c @@ -242,7 +242,14 @@ processMethod(J9VMThread * currentThread, UDATA lookupOptions, J9Method * method lookupSig = J9ROMNAMEANDSIGNATURE_SIGNATURE(nameAndSig); } - if (j9bcv_checkClassLoadingConstraintsForSignature(currentThread, cl1, cl2, lookupSig, methodSig) != 0) { + if (0 != j9bcv_checkClassLoadingConstraintsForSignature( + currentThread, + cl1, + cl2, + lookupSig, + methodSig, + J9_ARE_ALL_BITS_SET(lookupOptions, J9_LOOK_LOCAL_NAS)) + ) { *exception = J9VMCONSTANTPOOL_JAVALANGLINKAGEERROR; /* was VerifyError; but Sun throws Linkage */ *exceptionClass = methodClass; *errorType = J9_VISIBILITY_NON_MODULE_ACCESS_ERROR; diff --git a/runtime/vm/resolvesupport.cpp b/runtime/vm/resolvesupport.cpp index 4addc749382..b2983d3638b 100644 --- a/runtime/vm/resolvesupport.cpp +++ b/runtime/vm/resolvesupport.cpp @@ -810,7 +810,7 @@ resolveStaticFieldRefInto(J9VMThread *vmStruct, J9Method *method, J9ConstantPool } if (cl1 != cl2) { J9UTF8 *fieldSignature = J9ROMFIELDSHAPE_SIGNATURE(field); - if (j9bcv_checkClassLoadingConstraintsForSignature(vmStruct, cl1, cl2, signature, fieldSignature) != 0) { + if (j9bcv_checkClassLoadingConstraintsForSignature(vmStruct, cl1, cl2, signature, fieldSignature, FALSE) != 0) { if (throwException) { setCurrentException(vmStruct, J9VMCONSTANTPOOL_JAVALANGVERIFYERROR, NULL); } @@ -1060,7 +1060,7 @@ resolveInstanceFieldRefInto(J9VMThread *vmStruct, J9Method *method, J9ConstantPo } if (cl1 != cl2) { J9UTF8 *fieldSignature = J9ROMFIELDSHAPE_SIGNATURE(field); - if (j9bcv_checkClassLoadingConstraintsForSignature(vmStruct, cl1, cl2, signature, fieldSignature) != 0) { + if (j9bcv_checkClassLoadingConstraintsForSignature(vmStruct, cl1, cl2, signature, fieldSignature, FALSE) != 0) { if (throwException) { setCurrentException(vmStruct, J9VMCONSTANTPOOL_JAVALANGVERIFYERROR, NULL); }