Skip to content

Commit

Permalink
Copy local signature from MethodHandleNatives.resolve
Browse files Browse the repository at this point in the history
Signed-off-by: Theresa Mammarella <[email protected]>
  • Loading branch information
theresa-m committed Nov 29, 2024
1 parent b5ee59c commit ec0efc6
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 20 deletions.
15 changes: 7 additions & 8 deletions runtime/bcverify/clconstraints.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
Expand All @@ -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) {
Expand All @@ -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;
Expand All @@ -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;
}
Expand Down
33 changes: 30 additions & 3 deletions runtime/jcl/common/java_dyn_methodhandle.c
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,16 @@ 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 (0 != verifyData->checkClassLoadingConstraintForNameFunction(
currentThread,
targetClassloader,
ramClass->classLoader,
&lookupSigData[sigOffset],
&lookupSigData[sigOffset],
sigLength,
TRUE,
TRUE)
) {
result = FALSE;
}
omrthread_monitor_exit(vm->classTableMutex);
Expand Down Expand Up @@ -445,7 +454,16 @@ 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(0 != verifyData->checkClassLoadingConstraintForNameFunction(
currentThread,
targetClassloader,
argumentRamClass->classLoader,
&J9UTF8_DATA(targetSig)[index],
&lookupSigData[index],
endIndex - index,
TRUE,
TRUE)
) {
result = FALSE;
goto releaseMutexAndReturn;
}
Expand Down Expand Up @@ -477,7 +495,16 @@ 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(0 != verifyData->checkClassLoadingConstraintForNameFunction(
currentThread,
targetClassloader,
returnRamClass->classLoader,
&J9UTF8_DATA(targetSig)[index],
&lookupSigData[index],
endIndex - index,
TRUE,
TRUE)
) {
result = FALSE;
goto releaseMutexAndReturn;
}
Expand Down
3 changes: 2 additions & 1 deletion runtime/jcl/common/java_lang_invoke_MethodHandleNatives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions runtime/jcl/common/java_lang_invoke_VarHandle.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ accessCheckFieldType(J9VMThread *currentThread, J9Class* lookupClass, J9Class* t
&lookupSigData[1],
&lookupSigData[1],
J9UTF8_LENGTH(lookupSig) - 2,
TRUE,
TRUE) != 0) {
result = FALSE;
}
Expand Down
4 changes: 2 additions & 2 deletions runtime/oti/bcverify_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions runtime/oti/j9consts.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion runtime/oti/j9nonbuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions runtime/vm/createramclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 8 additions & 1 deletion runtime/vm/lookupmethod.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions runtime/vm/resolvesupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 (0 != j9bcv_checkClassLoadingConstraintsForSignature(vmStruct, cl1, cl2, signature, fieldSignature, FALSE)) {
if (throwException) {
setCurrentException(vmStruct, J9VMCONSTANTPOOL_JAVALANGVERIFYERROR, NULL);
}
Expand Down Expand Up @@ -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 (0 != j9bcv_checkClassLoadingConstraintsForSignature(vmStruct, cl1, cl2, signature, fieldSignature, FALSE)) {
if (throwException) {
setCurrentException(vmStruct, J9VMCONSTANTPOOL_JAVALANGVERIFYERROR, NULL);
}
Expand Down

0 comments on commit ec0efc6

Please sign in to comment.