Skip to content

Commit

Permalink
Merge pull request eclipse-openj9#388 from gacholio/master
Browse files Browse the repository at this point in the history
Move constraint checks to vTable creation
  • Loading branch information
DanHeidinga authored Oct 20, 2017
2 parents 08e9aa9 + 901157d commit e8fb2b9
Show file tree
Hide file tree
Showing 8 changed files with 191 additions and 184 deletions.
10 changes: 0 additions & 10 deletions runtime/bcverify/bcverify.c
Original file line number Diff line number Diff line change
Expand Up @@ -2615,16 +2615,6 @@ j9bcv_verifyBytecodes (J9PortLibrary * portLib, J9Class * clazz, J9ROMClass * ro

romMethod = J9_NEXT_ROM_METHOD(romMethod);
}

if (clazz && (result == BCV_SUCCESS)) {
verifyData->romMethod = checkAllClassLoadingConstraints (verifyData, clazz);
if (verifyData->romMethod) {
verifyData->errorModule = J9NLS_BCV_ERR_CLASSLOADING_CONSTRAINT__MODULE;
verifyData->errorCode = J9NLS_BCV_ERR_CLASSLOADING_CONSTRAINT__ID;
result = BCV_ERR_INTERNAL_ERROR;
}
}


_done:
verifyData->vmStruct->omrVMThread->vmState = oldState;
Expand Down
112 changes: 1 addition & 111 deletions runtime/bcverify/clconstraints.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 1991, 2014 IBM Corp. and others
* Copyright (c) 1991, 2017 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -63,116 +63,6 @@ validateArgs (J9VMThread* vmThread, J9ClassLoader* loader1, J9ClassLoader* loade
}
}

/*
* Returns NULL if no constraints have been violated, or a pointer to the first method which
* violates a constraint if constraints have been violated.
*
* Note that in the case of interface methods, the pointer to the violating method may point
* to an inherited method (i.e. the pointer may be to some superclass).
*
*/
J9ROMMethod *
checkAllClassLoadingConstraints (J9BytecodeVerificationData * verifyData, J9Class * ramClass)
{
UDATA *superVTable;
UDATA *vTable = (UDATA *) (ramClass + 1);
UDATA i, superCount;
UDATA count = *vTable;
UDATA classDepth = J9CLASS_DEPTH(ramClass);
J9Class *superclass;
J9ITable *iTable = (J9ITable *) ramClass->iTable;
J9ITable *superITable;

/* there are no class loading constraints on Object, so we can ignore that case */
if (classDepth == 0) {
return NULL;
}

Trc_RTV_checkAllClassLoadingConstraints_Entry(ramClass, J9UTF8_LENGTH(J9ROMCLASS_CLASSNAME(ramClass->romClass)), J9UTF8_DATA(J9ROMCLASS_CLASSNAME(ramClass->romClass)));

superclass = ramClass->superclasses[classDepth - 1];
superVTable = (UDATA *) (superclass + 1);
superCount = *superVTable;
superITable = (J9ITable*)superclass->iTable;

/* skip the size and the first entry (unresolved method) */
for (i = 2; i <= count; i++) {
J9Method *method = (J9Method *) vTable[i];
if (J9_CLASS_FROM_METHOD(method) == ramClass) {
/* the method was declared in this class */
if (i <= superCount) {
/* this method overrides a superclass method */
J9Method *superMethod = (J9Method *) superVTable[i];
J9ClassLoader *methodClassLoader = J9_CLASS_FROM_METHOD(superMethod)->classLoader;
if (methodClassLoader != ramClass->classLoader) {
J9ROMMethod *romMethod = J9_ROM_METHOD_FROM_RAM_METHOD(method);
J9UTF8 *sig = J9ROMMETHOD_GET_SIGNATURE(ramClass->romClass, romMethod);
J9ROMMethod *superRomMethod = J9_ROM_METHOD_FROM_RAM_METHOD(superMethod);
J9UTF8 *superSig = J9ROMMETHOD_GET_SIGNATURE(ramClass->romClass, superRomMethod);

Trc_RTV_checkAllClassLoadingConstraints_CheckSuperclassMethod(superMethod);

if (j9bcv_checkClassLoadingConstraintsForSignature(verifyData->vmStruct,
ramClass->classLoader,
methodClassLoader,
sig,
superSig)
) {
Trc_RTV_checkAllClassLoadingConstraints_SuperclassViolation(romMethod, J9UTF8_LENGTH(J9ROMCLASS_CLASSNAME(ramClass->romClass)), J9UTF8_DATA(J9ROMCLASS_CLASSNAME(ramClass->romClass)));
Trc_RTV_checkAllClassLoadingConstraints_Exit(romMethod);
return romMethod;
}
}
}
}
}

if (ramClass->romClass->modifiers & J9AccInterface) {
return NULL;
}

while (iTable != superITable) {
J9ClassLoader *interfaceClassLoader = iTable->interfaceClass->classLoader;
UDATA iTableSize = iTable->interfaceClass->romClass->romMethodCount;
UDATA *iTableCursor = (UDATA *) (iTable + 1);
for (i = 0; i < iTableSize; i++) {
J9Method* iMethod = iTable->interfaceClass->ramMethods + i;
IDATA vTableOffset = (IDATA) *iTableCursor++;

if (vTableOffset > 0) {
J9Method *concreteMethod = *((J9Method **) ((U_8*) ramClass + vTableOffset));
J9ClassLoader *concreteClassLoader = (J9_CLASS_FROM_METHOD(concreteMethod))->classLoader;

if (concreteClassLoader != interfaceClassLoader) {
J9ROMMethod *iRomMethod = J9_ROM_METHOD_FROM_RAM_METHOD(iMethod);
J9Class *methodClass = J9_CLASS_FROM_METHOD(iMethod);
J9UTF8 *iSig = J9ROMMETHOD_GET_SIGNATURE(methodClass->romClass, iRomMethod);
J9ROMMethod *romMethod = J9_ROM_METHOD_FROM_RAM_METHOD(concreteMethod);
J9UTF8 *sig = J9ROMMETHOD_GET_SIGNATURE(methodClass->romClass, romMethod);

Trc_RTV_checkAllClassLoadingConstraints_CheckInterfaceMethod(iMethod);

if (j9bcv_checkClassLoadingConstraintsForSignature(verifyData->vmStruct,
concreteClassLoader,
interfaceClassLoader,
sig,
iSig)
) {
Trc_RTV_checkAllClassLoadingConstraints_InterfaceViolation(romMethod, J9UTF8_LENGTH(J9ROMCLASS_CLASSNAME(ramClass->romClass)), J9UTF8_DATA(J9ROMCLASS_CLASSNAME(ramClass->romClass)));
Trc_RTV_checkAllClassLoadingConstraints_Exit(romMethod);
return romMethod;
}
}
}
}
iTable = iTable->next;
}

Trc_RTV_checkAllClassLoadingConstraints_Exit(NULL);

return NULL;
}


/*
* sig1 must come from a ROMSegment in loader1.
Expand Down
12 changes: 6 additions & 6 deletions runtime/bcverify/j9bcverify.tdf
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ TraceAssert=Assert_RTV_validateClassLoadingConstraints Overhead=2 Level=5 NoEnv
TraceAssert=Assert_RTV_true Overhead=1 Level=1 NoEnv Assert="P1"
TraceAssert=Assert_RTV_notEqual Overhead=1 Level=1 NoEnv Assert="P1 != P2"

TraceEntry=Trc_RTV_checkAllClassLoadingConstraints_Entry NoEnv Overhead=1 Level=2 Template="checkAllClassLoadingConstraints(ramClass=%p -- %.*s)"
TraceEvent=Trc_RTV_checkAllClassLoadingConstraints_CheckSuperclassMethod NoEnv Overhead=1 Level=2 Template="Found method overridden from a superclass in a different loader: %p"
TraceException=Trc_RTV_checkAllClassLoadingConstraints_SuperclassViolation NoEnv Overhead=1 Level=1 Template="Method overridden from superclass violates a class loading constraint: romMethod %p in %.*s"
TraceEvent=Trc_RTV_checkAllClassLoadingConstraints_CheckInterfaceMethod NoEnv Overhead=1 Level=2 Template="Found method overridden from an interface in a different loader: %p"
TraceException=Trc_RTV_checkAllClassLoadingConstraints_InterfaceViolation NoEnv Overhead=1 Level=1 Template="Method overridden from interface violates a class loading constraint: romMethod %p in %.*s"
TraceExit=Trc_RTV_checkAllClassLoadingConstraints_Exit NoEnv Overhead=1 Level=2 Template="checkAllClassLoadingConstraints -- return %p"
TraceEntry=Trc_RTV_checkAllClassLoadingConstraints_Entry Obsolete NoEnv Overhead=1 Level=2 Template="checkAllClassLoadingConstraints(ramClass=%p -- %.*s)"
TraceEvent=Trc_RTV_checkAllClassLoadingConstraints_CheckSuperclassMethod Obsolete NoEnv Overhead=1 Level=2 Template="Found method overridden from a superclass in a different loader: %p"
TraceException=Trc_RTV_checkAllClassLoadingConstraints_SuperclassViolation Obsolete NoEnv Overhead=1 Level=1 Template="Method overridden from superclass violates a class loading constraint: romMethod %p in %.*s"
TraceEvent=Trc_RTV_checkAllClassLoadingConstraints_CheckInterfaceMethod Obsolete NoEnv Overhead=1 Level=2 Template="Found method overridden from an interface in a different loader: %p"
TraceException=Trc_RTV_checkAllClassLoadingConstraints_InterfaceViolation Obsolete NoEnv Overhead=1 Level=1 Template="Method overridden from interface violates a class loading constraint: romMethod %p in %.*s"
TraceExit=Trc_RTV_checkAllClassLoadingConstraints_Exit Obsolete NoEnv Overhead=1 Level=2 Template="checkAllClassLoadingConstraints -- return %p"

TraceEntry=Trc_RTV_checkClassLoadingConstraintsForSignature_Entry Overhead=1 Level=3 Template="checkClassLoadingConstraintsForSignature(loader1=%p, loader2=%p, sig1=%p, sig2=%p -- %.*s)"
TraceExit=Trc_RTV_checkClassLoadingConstraintsForSignature_Exit Overhead=1 Level=3 Template="checkClassLoadingConstraintsForSignature(result=%zu)"
Expand Down
36 changes: 36 additions & 0 deletions runtime/nls/j9vm/j9vm.nls
Original file line number Diff line number Diff line change
Expand Up @@ -1746,3 +1746,39 @@ J9NLS_VM_FAILED_TO_LOAD_MODULE_REQUIRED_DLL.explanation=The JVM failed to load t
J9NLS_VM_FAILED_TO_LOAD_MODULE_REQUIRED_DLL.system_action=The JVM continues.
J9NLS_VM_FAILED_TO_LOAD_MODULE_REQUIRED_DLL.user_response=No action required if the specified library won't be referenced.
# END NON-TRANSLATABLE

# Message for LinkageError when a class loading constraint violation occurs when overriding a method
# arguments 1 and 2 are the overridden method's class's name
# arguments 3 and 4 are the overridden method name
# arguments 5 and 6 are the overridden method's signature
# arguments 7 and 8 are classloader name
# argument 9 is the classloader's identity hashcode
# arguments 10 and 11 are classloader's class
# arguments 12 and 13 are the other classloader name
# argument 14 is the other classloader's identity hashcode
# arguments 15 and 16 are the other classloader's class
# arguments 17 and 18 are the name of class being created
J9NLS_VM_LOADING_CONSTRAINT_OVERRIDE_VIOLATION=loading constraint violation when overriding method \"%2$.*1$s.%4$.*3$s%6$.*5$s\" during creation of class \"%18$.*17$s\": loader \"%8$.*7$s@%9$x\" of class \"%11$.*10$s\" and loader \"%13$.*12$s@%14$x\" of class \"%16$.*15$s\" have different types for the method signature
# START NON-TRANSLATABLE
J9NLS_VM_LOADING_CONSTRAINT_OVERRIDE_VIOLATION.sample_input_1=4
J9NLS_VM_LOADING_CONSTRAINT_OVERRIDE_VIOLATION.sample_input_2=Main
J9NLS_VM_LOADING_CONSTRAINT_OVERRIDE_VIOLATION.sample_input_3=4
J9NLS_VM_LOADING_CONSTRAINT_OVERRIDE_VIOLATION.sample_input_4=method
J9NLS_VM_LOADING_CONSTRAINT_OVERRIDE_VIOLATION.sample_input_5=15
J9NLS_VM_LOADING_CONSTRAINT_OVERRIDE_VIOLATION.sample_input_6=()LLoadedTwice;
J9NLS_VM_LOADING_CONSTRAINT_OVERRIDE_VIOLATION.sample_input_7=4
J9NLS_VM_LOADING_CONSTRAINT_OVERRIDE_VIOLATION.sample_input_8=Main
J9NLS_VM_LOADING_CONSTRAINT_OVERRIDE_VIOLATION.sample_input_9=2011a4e
J9NLS_VM_LOADING_CONSTRAINT_OVERRIDE_VIOLATION.sample_input_10=8
J9NLS_VM_LOADING_CONSTRAINT_OVERRIDE_VIOLATION.sample_input_11=Violator
J9NLS_VM_LOADING_CONSTRAINT_OVERRIDE_VIOLATION.sample_input_12=6
J9NLS_VM_LOADING_CONSTRAINT_OVERRIDE_VIOLATION.sample_input_13=Loader
J9NLS_VM_LOADING_CONSTRAINT_OVERRIDE_VIOLATION.sample_input_14=200b50c
J9NLS_VM_LOADING_CONSTRAINT_OVERRIDE_VIOLATION.sample_input_15=4
J9NLS_VM_LOADING_CONSTRAINT_OVERRIDE_VIOLATION.sample_input_16=Main
J9NLS_VM_LOADING_CONSTRAINT_OVERRIDE_VIOLATION.sample_input_17=4
J9NLS_VM_LOADING_CONSTRAINT_OVERRIDE_VIOLATION.sample_input_18=Main
J9NLS_VM_LOADING_CONSTRAINT_OVERRIDE_VIOLATION.explanation=A class loading constraint has been violated. The two class loader's have different classes for one of the class names in the signature.
J9NLS_VM_LOADING_CONSTRAINT_OVERRIDE_VIOLATION.system_action=A java/lang/LinkageError will be thrown
J9NLS_VM_LOADING_CONSTRAINT_OVERRIDE_VIOLATION.user_response=Examine the use of ClassLoaders to determine why a class of the same name is loaded in two different loaders
# END NON-TRANSLATABLE
10 changes: 0 additions & 10 deletions runtime/oti/bcverify_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,16 +162,6 @@ bcvIsInitOrClinit (J9CfrConstantPoolInfo * info);

/* ---------------- clconstraints.c ---------------- */

/**
* @brief
* @param verifyData
* @param ramClass
* @return J9ROMMethod *
*/
J9ROMMethod *
checkAllClassLoadingConstraints (J9BytecodeVerificationData * verifyData, J9Class * ramClass);


/**
* @brief
* @param vmThread
Expand Down
3 changes: 3 additions & 0 deletions runtime/oti/vm_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,9 @@ struct J9Class;
void
setClassLoadingConstraintSignatureError(J9VMThread *currentThread, J9ClassLoader *loader1, J9Class *class1, J9ClassLoader *loader2, J9Class *class2, J9Class *exceptionClass, U_8 *methodName, UDATA methodNameLength, U_8 *signature, UDATA signatureLength);

void
setClassLoadingConstraintOverrideError(J9VMThread *currentThread, J9UTF8 *newClassNameUTF, J9ClassLoader *loader1, J9UTF8 *class1NameUTF, J9ClassLoader *loader2, J9UTF8 *class2NameUTF, J9UTF8 *exceptionClassNameUTF, U_8 *methodName, UDATA methodNameLength, U_8 *signature, UDATA signatureLength);

/* ---------------- gphandle.c ---------------- */

struct J9PortLibrary;
Expand Down
Loading

0 comments on commit e8fb2b9

Please sign in to comment.