Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion jcl/src/java.base/share/classes/com/ibm/oti/vm/VM.java
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,11 @@ public static int markCurrentThreadAsSystem()
* constantpool associated with clazz
*/
public static ConstantPool getConstantPoolFromAnnotationBytes(Class<?> clazz, byte[] array) {
/* Check the cp cache on the Class object first. */
ConstantPool cp = VM.getVMLangAccess().getConstantPoolCache(clazz);
if (null != cp) {
return cp;
}
if (null == array) {
return getVMLangAccess().getConstantPool(clazz);
}
Expand All @@ -642,7 +647,7 @@ public static ConstantPool getConstantPoolFromAnnotationBytes(Class<?> clazz, by
} else {
ramCPAddr = Unsafe.getUnsafe().getLong(array, offset);
}
Object internalCP = getVMLangAccess().createInternalConstantPool(ramCPAddr);
Object internalCP = getVMLangAccess().createInternalConstantPool(ramCPAddr, clazz);
return getVMLangAccess().getConstantPool(internalCP);
}

Expand Down
16 changes: 14 additions & 2 deletions jcl/src/java.base/share/classes/com/ibm/oti/vm/VMLangAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,10 @@ public interface VMLangAccess {
* Returns an InternalConstantPool object.
*
* @param addr - the native addr of the J9ConstantPool
* @param clazz - the clazz object of the J9Class associated with the constantPool
* @return An InternalConstantPool object
*/
public Object createInternalConstantPool(long addr);
public Object createInternalConstantPool(long addr, Class<?> clazz);

/**
* Returns a ConstantPool object
Expand All @@ -148,9 +149,10 @@ public interface VMLangAccess {
* natives expect an InternalConstantPool as the constantPoolOop parameter.
*
* @param j9class the native address of the J9Class
* @param clazz the class object
* @return InternalConstantPool a wrapper for a j9constantpool
*/
public Object getInternalConstantPoolFromJ9Class(long j9class);
public Object getInternalConstantPoolFromJ9Class(long j9class, Class<?> clazz);

/**
* Returns an InternalConstantPool object from a Class. The ConstantPool
Expand Down Expand Up @@ -210,4 +212,14 @@ public interface VMLangAccess {
*/
public boolean getIncludeModuleVersion(StackTraceElement element);
/*[ENDIF] JAVA_SPEC_VERSION >= 11*/

/**
* Returns a cached constantPool Object from a given java.lang.Class.
*
* @param clazz
*
* @return cpObject
*/
public ConstantPool getConstantPoolCache(Class<?> clazz);

}
2 changes: 2 additions & 0 deletions jcl/src/java.base/share/classes/java/lang/Class.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ public final class Class<T> implements java.io.Serializable, GenericDeclaration,
private transient long vmRef;
private transient ClassLoader classLoader;

transient ConstantPool constantPoolObject;

/*[IF JAVA_SPEC_VERSION >= 9]*/
private transient Module module;
/*[ENDIF] JAVA_SPEC_VERSION >= 9 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,20 @@
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 OR GPL-2.0-only WITH OpenJDK-assembly-exception-1.0
*/

import com.ibm.oti.vm.VM;

/**
* Represents the internal J9ConstantPool
*
*/
final class InternalConstantPool {
@SuppressWarnings("unused")
private final long vmRef;
private final Class<?> clazz;

public InternalConstantPool(long addr) {
vmRef = addr;
public InternalConstantPool(long addr, Class<?> clazz) {
this.vmRef = addr;
this.clazz = clazz;
VM.dumpString("addr: " + addr + " clazz: " + clazz.getName());
}
}
22 changes: 17 additions & 5 deletions jcl/src/java.base/share/classes/java/lang/VMAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ public Package getSystemPackage(String name) {
* @return An InternalConstantPool reference object
*/
@Override
public Object createInternalConstantPool(long addr) {
return new InternalConstantPool(addr);
public Object createInternalConstantPool(long addr, Class<?> clazz) {
return new InternalConstantPool(addr, clazz);
}

/**
Expand All @@ -208,11 +208,12 @@ public ConstantPool getConstantPool(Object internalConstantPool) {
* natives expect an InternalConstantPool as the constantPoolOop parameter.
*
* @param j9class the native address of the J9Class
* @param clazz the class object
* @return InternalConstantPool a wrapper for a j9constantpool
*/
public Object getInternalConstantPoolFromJ9Class(long j9class) {
public Object getInternalConstantPoolFromJ9Class(long j9class, Class<?> clazz) {
long j9constantpool = VM.getJ9ConstantPoolFromJ9Class(j9class);
return createInternalConstantPool(j9constantpool);
return createInternalConstantPool(j9constantpool, clazz);
}

/**
Expand All @@ -230,7 +231,7 @@ public Object getInternalConstantPoolFromClass(Class clazz) {
} else {
j9class = helpers.getJ9ClassFromClass64(clazz);
}
return getInternalConstantPoolFromJ9Class(j9class);
return getInternalConstantPoolFromJ9Class(j9class, clazz);
}

/*[IF JAVA_SPEC_VERSION >= 9]*/
Expand Down Expand Up @@ -276,5 +277,16 @@ public boolean getIncludeClassLoaderName(StackTraceElement element) {
public boolean getIncludeModuleVersion(StackTraceElement element) {
return element.getIncludeModuleVersion();
}

/**
* Returns a cached constantPool Object from a given java.lang.Class
*
* @param clazz
*
* @return cpObject
*/
public ConstantPool getConstantPoolCache(Class<?> clazz) {
return clazz.constantPoolObject;
}
/*[ENDIF] JAVA_SPEC_VERSION >= 11 */
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ private static final Object resolveConstantDynamic(long j9class, String name, St
Object result = null;

VMLangAccess access = VM.getVMLangAccess();
Object internalConstantPool = access.getInternalConstantPoolFromJ9Class(j9class);
Class<?> classObject = getClassFromJ9Class(j9class);
Object internalConstantPool = access.getInternalConstantPoolFromJ9Class(j9class, classObject);

Class<?> typeClass = fromFieldDescriptorString(fieldDescriptor, access.getClassloader(classObject));

Expand Down Expand Up @@ -241,8 +241,8 @@ private static final Object invokeBsm(MethodHandle bsm, Object[] staticArgs) thr
private static final Object resolveInvokeDynamic(long j9class, String name, String methodDescriptor, long bsmData) throws Throwable {
/*[IF OPENJDK_METHODHANDLES]*/
VMLangAccess access = VM.getVMLangAccess();
Object internalConstantPool = access.getInternalConstantPoolFromJ9Class(j9class);
Class<?> classObject = getClassFromJ9Class(j9class);
Object internalConstantPool = access.getInternalConstantPoolFromJ9Class(j9class, classObject);

MethodType type = null;
Object[] result = new Object[2];
Expand Down Expand Up @@ -340,8 +340,8 @@ private static final Object resolveInvokeDynamic(long j9class, String name, Stri
try {
/*[ENDIF] JAVA_SPEC_VERSION < 11 */
VMLangAccess access = VM.getVMLangAccess();
Object internalConstantPool = access.getInternalConstantPoolFromJ9Class(j9class);
Class<?> classObject = getClassFromJ9Class(j9class);
Object internalConstantPool = access.getInternalConstantPoolFromJ9Class(j9class, classObject);

type = MethodTypeHelper.vmResolveFromMethodDescriptorString(methodDescriptor, access.getClassloader(classObject), null);
final MethodHandles.Lookup lookup = new MethodHandles.Lookup(classObject, false);
Expand Down
5 changes: 5 additions & 0 deletions runtime/gc_include/ObjectAllocationAPI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,10 @@ class MM_ObjectAllocationAPI
allocateSize = J9_GC_MINIMUM_OBJECT_SIZE;
}

if (J9VMJAVALANGINTERNALCONSTANTPOOL_OR_NULL(currentThread->javaVM) == clazz) {
return NULL;
}

/* Allocate the object */
switch(_gcAllocationType) {
#if defined(J9VM_GC_THREAD_LOCAL_HEAP)
Expand Down Expand Up @@ -441,6 +445,7 @@ class MM_ObjectAllocationAPI
VM_AtomicSupport::writeBarrier();
}
#endif /* J9VM_GC_THREAD_LOCAL_HEAP || J9VM_GC_SEGREGATED_HEAP */

return instance;
}

Expand Down
Loading