Skip to content

Commit

Permalink
Fix Object References: (eclipse-openj9#33)
Browse files Browse the repository at this point in the history
* Fix Object References:

- fixup object refs for classes found inside hashtable
- two pathways related to jcldefine and resolvesupport
- created function initializeImageClassObject

Signed-off-by: akshayben <[email protected]>
  • Loading branch information
akshayben authored Jul 25, 2019
1 parent 786c90f commit 3ae9c40
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 2 deletions.
9 changes: 8 additions & 1 deletion runtime/jcl/common/jcldefine.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,15 @@ defineClassCommon(JNIEnv *env, jobject classLoaderObject,
if (vmFuncs->hashClassTableAt(classLoader, utf8Name, utf8Length) != NULL) {
/* Bad, we have already defined this class - fail */
omrthread_monitor_exit(vm->classTableMutex);

if (J9_ARE_NO_BITS_SET(options, J9_FINDCLASS_FLAG_NAME_IS_INVALID)) {
vmFuncs->setCurrentException(currentThread, J9VMCONSTANTPOOL_JAVALANGLINKAGEERROR, (UDATA *)*(j9object_t*)className);
/* TODO: Incorrect pathway for loading already cached class */
if (J9_ARE_ANY_BITS_SET(vm->extendedRuntimeFlags2, J9_EXTENDED_RUNTIME2_RAMSTATE_WARM_RUN)) {
clazz = vmFuncs->hashClassTableAt(classLoader, utf8Name, utf8Length);
clazz = vmFuncs->initializeImageClassObject(currentThread, classLoader, clazz);
} else {
vmFuncs->setCurrentException(currentThread, J9VMCONSTANTPOOL_JAVALANGLINKAGEERROR, (UDATA*)* (j9object_t*)className);
}
}
goto done;
}
Expand Down
1 change: 1 addition & 0 deletions runtime/oti/j9nonbuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -4789,6 +4789,7 @@ typedef struct J9InternalVMFunctions {
void ( *deregisterCPEntry)(struct J9JavaVM *javaVM, struct J9ClassPathEntry *cpEntry);
J9ClassLoader* (*findClassLoader)(struct J9JavaVM *javaVM, uint32_t classLoaderCategory);
void (*initializeImageClassLoaderObject)(struct J9JavaVM *javaVM, struct J9ClassLoader *classLoader, j9object_t classLoaderObject);
struct J9Class* (*initializeImageClassObject)(struct J9VMThread *vmThread, struct J9ClassLoader *classLoader, struct J9Class *clazz);
} J9InternalVMFunctions;

/* Jazz 99339: define a new structure to replace JavaVM so as to pass J9NativeLibrary to JVMTIEnv */
Expand Down
13 changes: 12 additions & 1 deletion runtime/oti/jvmimage_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,19 @@ UDATA* findEntryLocationInTable(ImageTableHeader *table, UDATA entry);
J9ClassLoader* findClassLoader(J9JavaVM *javaVM, uint32_t classLoaderCategory);

/*
* Initializes class loader object. Mimics behaviour of internalAllocateClassLoader
* Initializes class object. Mimics behaviour of internalCreateRAMClass
*
* @param javaVM[in] the java vm
* @param classLoader the class loader loading the class
* @param clazz the class being loader
*
* @return class object if object allocation passes otherwise null
*/
J9Class* initializeImageClassObject(J9VMThread *vmThread, J9ClassLoader *classLoader, J9Class *clazz);

/*
* Initializes class loader object. Mimics behaviour of internalAllocateClassLoader
*
* @param javaVM[in] the java vm
* @param classLoader the class loader
* @param classLoaderObject unwrapped class loader object ref
Expand Down
43 changes: 43 additions & 0 deletions runtime/vm/JVMImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,49 @@ initializeImageClassLoaderObject(J9JavaVM *javaVM, J9ClassLoader *classLoader, j
omrthread_monitor_exit(javaVM->classLoaderBlocksMutex);
}

extern "C" J9Class *
initializeImageClassObject(J9VMThread *vmThread, J9ClassLoader *classLoader, J9Class *clazz)
{
J9JavaVM *javaVM = vmThread->javaVM;

/* Allocate class object */
J9Class *jlClass = J9VMCONSTANTPOOL_CLASSREF_AT(javaVM, J9VMCONSTANTPOOL_JAVALANGCLASS)->value;

if (NULL == jlClass) {
return NULL;
}
J9Class *lockClass = J9VMJAVALANGJ9VMINTERNALSCLASSINITIALIZATIONLOCK_OR_NULL(javaVM);

j9object_t classObject = javaVM->memoryManagerFunctions->J9AllocateObject(vmThread, jlClass, J9_GC_ALLOCATE_OBJECT_TENURED | J9_GC_ALLOCATE_OBJECT_NON_INSTRUMENTABLE | J9_GC_ALLOCATE_OBJECT_HASHED);
if (NULL == classObject) {
setHeapOutOfMemoryError(vmThread);
return NULL;
}

/* Allocate lock object if lock class already allocated */
if (NULL != lockClass) {
j9object_t lockObject;
UDATA allocateFlags = J9_GC_ALLOCATE_OBJECT_NON_INSTRUMENTABLE;

PUSH_OBJECT_IN_SPECIAL_FRAME(vmThread, (j9object_t)classObject);
lockObject = javaVM->memoryManagerFunctions->J9AllocateObject(vmThread, lockClass, allocateFlags);
classObject = POP_OBJECT_IN_SPECIAL_FRAME(vmThread);

if (NULL == lockObject) {
setHeapOutOfMemoryError(vmThread);
return NULL;
}
J9VMJAVALANGJ9VMINTERNALSCLASSINITIALIZATIONLOCK_SET_THECLASS(vmThread, lockObject, classObject);
J9VMJAVALANGCLASS_SET_INITIALIZATIONLOCK(vmThread, classObject, lockObject);
}

J9VMJAVALANGCLASS_SET_CLASSLOADER(vmThread, classObject, classLoader->classLoaderObject);
J9VMJAVALANGCLASS_SET_VMREF(vmThread, classObject, clazz);
J9STATIC_OBJECT_STORE(vmThread, clazz, (j9object_t*)&clazz->classObject, (j9object_t)classObject);

return clazz;
}

extern "C" void
shutdownJVMImage(J9JavaVM *javaVM)
{
Expand Down
1 change: 1 addition & 0 deletions runtime/vm/JVMImage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "j9comp.h"
#include "j9protos.h"
#include "ut_j9vm.h"
#include "objhelp.h"

class JVMImage
{
Expand Down
6 changes: 6 additions & 0 deletions runtime/vm/classsupport.c
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,12 @@ loadNonArrayClass(J9VMThread* vmThread, J9Module *j9module, U_8* className, UDAT

foundClass = hashClassTableAt(classLoader, className, classNameLength);
if (NULL != foundClass) {
if (IS_WARM_RUN(vmThread->javaVM)
&& J9_ARE_ALL_BITS_SET(vmThread->javaVM->extendedRuntimeFlags, J9_EXTENDED_RUNTIME_CLASS_OBJECT_ASSIGNED)
&& foundClass->classObject == NULL) {
foundClass = initializeImageClassObject(vmThread, classLoader, foundClass);
}

if (!fastMode) {
omrthread_monitor_exit(vmThread->javaVM->classTableMutex);
}
Expand Down
1 change: 1 addition & 0 deletions runtime/vm/intfunc.c
Original file line number Diff line number Diff line change
Expand Up @@ -378,4 +378,5 @@ J9InternalVMFunctions J9InternalFunctions = {
deregisterCPEntry,
findClassLoader,
initializeImageClassLoaderObject,
initializeImageClassObject,
};

0 comments on commit 3ae9c40

Please sign in to comment.