Skip to content

Commit

Permalink
Search RAM CP for identical String entries to patch
Browse files Browse the repository at this point in the history
For each patch object, apply to all matching String entries in the constantpool

Signed-off-by: Jack Lu <Jack.S.Lu@ibm.com>
  • Loading branch information
fengxue-IS committed Feb 6, 2020
1 parent 573628b commit cd81472
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions runtime/jcl/common/sun_misc_Unsafe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,25 @@ Java_sun_misc_Unsafe_defineAnonymousClass(JNIEnv *env, jobject receiver, jclass
if (constPatches != NULL) {
vmFuncs->internalEnterVMFromJNI(currentThread);
J9Class *clazz = J9VM_J9CLASS_FROM_HEAPCLASS(currentThread, J9_JNI_UNWRAP_REFERENCE(anonClass));

j9object_t item = NULL;
U_32 *cpShapeDescription = J9ROMCLASS_CPSHAPEDESCRIPTION(clazz->romClass);
J9ConstantPool *ramCP = J9_CP_FROM_CLASS(clazz);
J9ROMConstantPoolItem *romCP = ramCP->romConstantPool;

/* Get J9 constantpool mapped item for patch item, only support patching STRING entries has been added */
for (U_16 i = 0; i < cpPatchMap.size; i++) {
item = J9JAVAARRAYOFOBJECT_LOAD(currentThread, patchArray, i);
j9object_t item = J9JAVAARRAYOFOBJECT_LOAD(currentThread, patchArray, i);
if ((item != NULL) && (J9_CP_TYPE(cpShapeDescription, cpPatchMap.indexMap[i]) == J9CPTYPE_STRING)) {
J9RAMStringRef *ramStringRef = ((J9RAMStringRef *)ramCP) + cpPatchMap.indexMap[i];
J9STATIC_OBJECT_STORE(currentThread, clazz, &ramStringRef->stringObject, item);
J9UTF8 *romString = J9ROMSTRINGREF_UTF8DATA((J9ROMStringRef *)&romCP[cpPatchMap.indexMap[i]]);

/* For each patch object, search the RAM constantpool for identical string entries */
for (U_16 j = 1; j < clazz->romClass->ramConstantPoolCount; j++) {
if ((J9_CP_TYPE(cpShapeDescription, j) == J9CPTYPE_STRING)
&& J9UTF8_EQUALS(romString, J9ROMSTRINGREF_UTF8DATA((J9ROMStringRef *)&romCP[j]))
) {
J9RAMStringRef *ramStringRef = ((J9RAMStringRef *)ramCP) + j;
J9STATIC_OBJECT_STORE(currentThread, clazz, &ramStringRef->stringObject, item);
}
}
}
}

Expand Down

0 comments on commit cd81472

Please sign in to comment.