Skip to content

Commit

Permalink
Merge pull request eclipse-openj9#328 from tajila/gradle
Browse files Browse the repository at this point in the history
search for loadlocationtype when calling defineclass v2
  • Loading branch information
gacholio authored Oct 17, 2017
2 parents b536e6c + ad619a5 commit a0d064a
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 43 deletions.
22 changes: 4 additions & 18 deletions runtime/bcutil/dynload.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ static IDATA readZip (J9JavaVM * javaVM, J9ClassPathEntry * cpEntry);
static IDATA convertToOSFilename (J9JavaVM * javaVM, U_8 * dir, UDATA dirLength, U_8 * moduleName, U_8 * className, UDATA classNameLength);
static IDATA checkSunClassFileBuffers (J9JavaVM * javaVM, U_32 sunClassFileSize);
static IDATA searchClassInModule(J9VMThread * vmThread, J9Module * j9module, U_8 * className, UDATA classNameLength, BOOLEAN verbose, J9TranslationLocalBuffer *localBuffer);
static IDATA searchClassInClassPath(J9VMThread * vmThread, J9ClassPathEntry * classPath, UDATA classPathCount, U_8 * className, UDATA classNameLength, UDATA flags, BOOLEAN verbose, J9TranslationLocalBuffer *localBuffer);
static IDATA searchClassInClassPath(J9VMThread * vmThread, J9ClassPathEntry * classPath, UDATA classPathCount, U_8 * className, UDATA classNameLength, BOOLEAN verbose, J9TranslationLocalBuffer *localBuffer);
static IDATA searchClassInPatchPaths(J9VMThread * vmThread, J9ClassPathEntry * patchPaths, UDATA patchPathCount, U_8 * className, UDATA classNameLength, BOOLEAN verbose, J9TranslationLocalBuffer *localBuffer);
static IDATA searchClassInCPEntry(J9VMThread * vmThread, J9ClassPathEntry * cpEntry, J9Module * j9module, U_8 * moduleName, U_8 * className, UDATA classNameLength, BOOLEAN verbose);
static IDATA readFileFromJImage (J9VMThread * vmThread, J9Module * j9module, U_8 * moduleName, J9ClassPathEntry *cpEntry);

IDATA
findLocallyDefinedClass(J9VMThread * vmThread, J9Module * j9module, U_8 * className, U_32 classNameLength, J9ClassLoader * classLoader, J9ClassPathEntry * classPath, UDATA classPathEntryCount, UDATA options, UDATA flags, J9TranslationLocalBuffer *localBuffer)
findLocallyDefinedClass(J9VMThread * vmThread, J9Module * j9module, U_8 * className, U_32 classNameLength, J9ClassLoader * classLoader, J9ClassPathEntry * classPath, UDATA classPathEntryCount, UDATA options, J9TranslationLocalBuffer *localBuffer)
{
IDATA result = 0;
J9JavaVM *javaVM = vmThread->javaVM;
Expand Down Expand Up @@ -169,7 +169,7 @@ findLocallyDefinedClass(J9VMThread * vmThread, J9Module * j9module, U_8 * classN
}

/* If the class is still not found, search it in classpath */
result = searchClassInClassPath(vmThread, classPath, classPathEntryCount, mbString, mbLength, flags, verbose, localBuffer);
result = searchClassInClassPath(vmThread, classPath, classPathEntryCount, mbString, mbLength, verbose, localBuffer);

_end:
if (0 != result) {
Expand Down Expand Up @@ -243,14 +243,13 @@ searchClassInModule(J9VMThread * vmThread, J9Module * j9module, U_8 * className,
* @param [in] classPathCount number of entries in classPath array
* @param [in] className name of the class to be searched
* @param [in] classNameLength length of the className
* @param [in] flags flags to control which class path entries should be searched
* @param [in] verbose if TRUE record the class loading stats
* @param [in/out] localBuffer contains values for entryIndex, loadLocationType and cpEntryUsed. This pointer can't be NULL.
*
* @return 0 on success, 1 if the class is not found, -1 on error
*/
static IDATA
searchClassInClassPath(J9VMThread * vmThread, J9ClassPathEntry * classPath, UDATA classPathCount, U_8 * className, UDATA classNameLength, UDATA flags, BOOLEAN verbose, J9TranslationLocalBuffer *localBuffer)
searchClassInClassPath(J9VMThread * vmThread, J9ClassPathEntry * classPath, UDATA classPathCount, U_8 * className, UDATA classNameLength, BOOLEAN verbose, J9TranslationLocalBuffer *localBuffer)
{
J9JavaVM *javaVM = vmThread->javaVM;
J9InternalVMFunctions const * const vmFuncs = javaVM->internalVMFunctions;
Expand All @@ -263,19 +262,6 @@ searchClassInClassPath(J9VMThread * vmThread, J9ClassPathEntry * classPath, UDAT

for (i = 0; i < classPathCount; i++) {
cpEntry = &classPath[i];
/*
* should we consider this entry? This is important for J2ME VMs, where
* the classpath may contain a mix of BP and CP entries
*/
if (flags & BCU_BOOTSTRAP_ENTRIES_ONLY) {
if (!(cpEntry->flags & CPE_FLAG_BOOTSTRAP)) {
continue;
}
} else if (flags & BCU_NON_BOOTSTRAP_ENTRIES_ONLY) {
if ( cpEntry->flags & CPE_FLAG_BOOTSTRAP) {
continue;
}
}

/* Warm up the entry */
vmFuncs->initializeClassPathEntry(javaVM, cpEntry);
Expand Down
7 changes: 6 additions & 1 deletion runtime/jcl/common/jcldefine.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ defineClassCommon(JNIEnv *env, jobject classLoaderObject,
tempClassBytes = classBytes;
tempLength = length;

/* Try to find classLocation. Ignore return code because there are valid cases where it might not find it (ie. bytecode spinning).
* If the class is not found the default class location is fine.
*/
dynFuncs->findLocallyDefinedClassFunction(currentThread, NULL, utf8Name, (U_32) utf8Length, classLoader, classLoader->classPathEntries, classLoader->classPathEntryCount, (UDATA) FALSE, &localBuffer);

/* skip if we are anonClass */
if (J9_ARE_NO_BITS_SET(options, J9_FINDCLASS_FLAG_ANON)) {
/* Check for romClass cookie, it indicates that we are defining a class out of a JXE not from class bytes */
Expand All @@ -164,7 +169,7 @@ defineClassCommon(JNIEnv *env, jobject classLoaderObject,
protectionDomain ? *(j9object_t*)protectionDomain : NULL,
NULL,
J9_CP_INDEX_NONE,
LOAD_LOCATION_UNKNOWN,
localBuffer.loadLocationType,
NULL,
hostClass);
/* Done if a class was found or and exception is pending, otherwise try to define the bytes */
Expand Down
1 change: 0 additions & 1 deletion runtime/jcl/common/vm_scar.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,6 @@ J9VMDllMain(J9JavaVM* vm, IDATA stage, void* reserved)
vm->jclFlags |=
J9_JCL_FLAG_REFERENCE_OBJECTS |
J9_JCL_FLAG_FINALIZATION |
J9_JCL_FLAG_CLASSLOADERS |
J9_JCL_FLAG_THREADGROUPS;
vm->jclSysPropBuffer = NULL;

Expand Down
2 changes: 1 addition & 1 deletion runtime/oti/bcutil_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ internalLoadROMClass(J9VMThread *vmThread, J9LoadROMClassData *loadData, J9Trans
* @return zero on success, -1 on failure.
*/
IDATA
findLocallyDefinedClass(J9VMThread * vmThread, J9Module *j9module, U_8 * className, U_32 classNameLength, J9ClassLoader * classLoader, J9ClassPathEntry * classPath, UDATA classPathEntryCount, UDATA options, UDATA flags, J9TranslationLocalBuffer *localBuffer);
findLocallyDefinedClass(J9VMThread * vmThread, J9Module *j9module, U_8 * className, U_32 classNameLength, J9ClassLoader * classLoader, J9ClassPathEntry * classPath, UDATA classPathEntryCount, UDATA options, J9TranslationLocalBuffer *localBuffer);


#endif /* J9VM_OPT_DYNAMIC_LOAD_SUPPORT */ /* End File Level Build Flags */
Expand Down
1 change: 0 additions & 1 deletion runtime/oti/j9consts.h
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,6 @@ extern "C" {

#define J9_JCL_FLAG_REFERENCE_OBJECTS 0x1
#define J9_JCL_FLAG_FINALIZATION 0x2
#define J9_JCL_FLAG_CLASSLOADERS 0x4
#define J9_JCL_FLAG_THREADGROUPS 0x8
#define J9_JCL_FLAG_RESOURCE_MANAGED 0x10
#define J9_JCL_FLAG_COM_SUN_MANAGEMENT_PROP 0x20
Expand Down
4 changes: 1 addition & 3 deletions runtime/oti/j9nonbuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -1800,7 +1800,7 @@ typedef struct J9TranslationBufferSet {
U_8* classFileError;
UDATA classFileSize;
void* romClassBuilder;
IDATA ( *findLocallyDefinedClassFunction)(struct J9VMThread * vmThread, struct J9Module * j9module, U_8 * className, U_32 classNameLength, struct J9ClassLoader * classLoader, struct J9ClassPathEntry * classPath, UDATA classPathEntryCount, UDATA options, UDATA flags, struct J9TranslationLocalBuffer *localBuffer) ;
IDATA ( *findLocallyDefinedClassFunction)(struct J9VMThread * vmThread, struct J9Module * j9module, U_8 * className, U_32 classNameLength, struct J9ClassLoader * classLoader, struct J9ClassPathEntry * classPath, UDATA classPathEntryCount, UDATA options, struct J9TranslationLocalBuffer *localBuffer) ;
struct J9Class* ( *internalDefineClassFunction)(struct J9VMThread* vmThread, void* className, UDATA classNameLength, U_8* classData, UDATA classDataLength, j9object_t classDataObject, struct J9ClassLoader* classLoader, j9object_t protectionDomain, UDATA options, struct J9ROMClass *existingROMClass, struct J9Class *hostClass, struct J9TranslationLocalBuffer *localBuffer) ;
I_32 ( *closeZipFileFunction)(struct J9VMInterface* vmi, struct VMIZipFile* zipFile) ;
void ( *reportStatisticsFunction)(struct J9JavaVM * javaVM, struct J9ClassLoader* loader, struct J9ROMClass* romClass, struct J9TranslationLocalBuffer *localBuffer) ;
Expand All @@ -1809,8 +1809,6 @@ typedef struct J9TranslationBufferSet {
} J9TranslationBufferSet;

#define BCU_UNUSED_2 2
#define BCU_BOOTSTRAP_ENTRIES_ONLY 16
#define BCU_NON_BOOTSTRAP_ENTRIES_ONLY 32
#define BCU_VERBOSE 1
#define BCU_TRACK_UTF8DATA 4
#define BCU_UNUSED_40 64
Expand Down
1 change: 0 additions & 1 deletion runtime/oti/j9vm.hdf
Original file line number Diff line number Diff line change
Expand Up @@ -1121,7 +1121,6 @@ typedef UDATA (* lookupNativeAddressCallback)(struct J9VMThread *currentThread,
<data type="const char*" name="className" description="name of class to find" />
<data type="UDATA" name="classNameLength" description="length of the className param" />
<data type="struct J9ClassLoader*" name="classloader" description="caller classloader" />
<data type="UDATA" name="flags" description="flags that control how class is loaded" />
<data type="IDATA*" name="classFound" description="returns non zero if class was found" />
<data type="IDATA*" return="true" name="result" description="returns non zero if the hook ran" />
</event>
Expand Down
2 changes: 1 addition & 1 deletion runtime/vm/KeyHashTable.c
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ hashPkgTableIDFor(J9VMThread *vmThread, J9ClassLoader *classLoader, J9ROMClass*

key.tag = (UDATA)romClass | TAG_ROM_CLASS;

if (isSystemClassLoader && (LOAD_LOCATION_UNKNOWN == locationType)) {
if (isSystemClassLoader && (J9ROMCLASS_IS_UNSAFE(romClass) || (LOAD_LOCATION_UNKNOWN == locationType))) {
key.tag |= TAG_GENERATED_PACKAGE;
}

Expand Down
21 changes: 7 additions & 14 deletions runtime/vm/classsupport.c
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,6 @@ resolveKnownClass(J9JavaVM * vm, UDATA index)
* @param classNameLength Length of the class name
* @param classLoader Class loader object
* @param options
* @param flags contains 0 or BOOTSTRAP_ENTRIES_ONLY
* @param [in/out] localBuffer contains values for entryIndex, loadLocationType and cpEntryUsed. This pointer can't be NULL.
* @return pointer to class if locally defined, 0 if not defined, -1 if we cannot do dynamic load
*
Expand All @@ -500,7 +499,7 @@ resolveKnownClass(J9JavaVM * vm, UDATA index)
*/

static IDATA
callFindLocallyDefinedClass(J9VMThread* vmThread, J9Module *j9module, U_8* className, UDATA classNameLength, J9ClassLoader* classLoader, UDATA options, UDATA flags, J9TranslationLocalBuffer *localBuffer) {
callFindLocallyDefinedClass(J9VMThread* vmThread, J9Module *j9module, U_8* className, UDATA classNameLength, J9ClassLoader* classLoader, UDATA options, J9TranslationLocalBuffer *localBuffer) {
IDATA findResult = -1;
J9TranslationBufferSet *dynamicLoadBuffers = vmThread->javaVM->dynamicLoadBuffers;
J9ROMClass* returnVal = NULL;
Expand Down Expand Up @@ -530,15 +529,15 @@ callFindLocallyDefinedClass(J9VMThread* vmThread, J9Module *j9module, U_8* class
vmThread,
(const char *)className,
classNameLength,
classLoader,
flags,
classLoader,
&classFound,
returnPointer);
if (returnVal != NULL){

if (returnVal != NULL) {
findResult = classFound;
} else {
findResult = dynamicLoadBuffers->findLocallyDefinedClassFunction(vmThread, j9module, className, (U_32)classNameLength, classLoader, classPathEntries,
classLoader->classPathEntryCount, options, flags, localBuffer);
classLoader->classPathEntryCount, options, localBuffer);
if ((-1 == findResult) && (J9_PRIVATE_FLAGS_REPORT_ERROR_LOADING_CLASS & vmThread->privateFlags)) {
vmThread->privateFlags |= J9_PRIVATE_FLAGS_FAILED_LOADING_REQUIRED_CLASS;
}
Expand Down Expand Up @@ -589,14 +588,8 @@ attemptDynamicClassLoad(J9VMThread* vmThread, J9Module *j9module, U_8* className
IDATA findResult = -1;
J9TranslationLocalBuffer localBuffer = {J9_CP_INDEX_NONE, LOAD_LOCATION_UNKNOWN, NULL};

if (J9_JCL_FLAG_CLASSLOADERS & vmThread->javaVM->jclFlags) {
findResult = callFindLocallyDefinedClass(vmThread, j9module, className, classNameLength, classLoader, options, 0, &localBuffer);
} else {
findResult = callFindLocallyDefinedClass(vmThread, j9module, className, classNameLength, classLoader, options, BCU_BOOTSTRAP_ENTRIES_ONLY, &localBuffer);
if (-1 == findResult) {
findResult = callFindLocallyDefinedClass(vmThread, j9module, className, classNameLength, classLoader, options, BCU_NON_BOOTSTRAP_ENTRIES_ONLY, &localBuffer);
}
}
findResult = callFindLocallyDefinedClass(vmThread, j9module, className, classNameLength, classLoader, options, &localBuffer);

if (-1 != findResult) {
J9TranslationBufferSet *dynamicLoadBuffers = vmThread->javaVM->dynamicLoadBuffers;

Expand Down
4 changes: 2 additions & 2 deletions runtime/vm/createramclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2575,9 +2575,9 @@ internalCreateRAMClassFromROMClassImpl(J9VMThread *vmThread, J9ClassLoader *clas
}
if (classLoader == javaVM->systemClassLoader) {
/* We don't add class location entries with locationType, LOAD_LOCATION_UNKNOWN, in the classLocationHashTable.
* This should save footprint.
* This should save footprint. Same applies for classes created with Unsafe.defineclass or Unsafe.defineAnonClass.
*/
if ((NULL == classBeingRedefined) && (LOAD_LOCATION_UNKNOWN != locationType)) {
if ((NULL == classBeingRedefined) && (LOAD_LOCATION_UNKNOWN != locationType) && (!J9ROMCLASS_IS_UNSAFE(romClass))) {
J9ClassLocation classLocation;

classLocation.clazz = ramClass;
Expand Down

0 comments on commit a0d064a

Please sign in to comment.