Skip to content

Commit

Permalink
Merge pull request #10529 from DanHeidinga/djh/defineClass
Browse files Browse the repository at this point in the history
Ensure Lookup::defineClass links the class
  • Loading branch information
tajila committed Sep 9, 2020
2 parents 6ae4ef7 + 0a45262 commit a716896
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
31 changes: 19 additions & 12 deletions jcl/src/java.base/share/classes/com/ibm/oti/vm/VMLangAccess.java
@@ -1,17 +1,6 @@
/*[INCLUDE-IF Sidecar16]*/
package com.ibm.oti.vm;

import java.util.Properties;

/*[IF Sidecar19-SE]*/
import jdk.internal.reflect.ConstantPool;
/*[ELSE]*/
import sun.reflect.ConstantPool;
/*[ENDIF]*/


/*******************************************************************************
* Copyright (c) 2012, 2019 IBM Corp. and others
* Copyright (c) 2012, 2020 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 All @@ -32,6 +21,16 @@
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
*******************************************************************************/

package com.ibm.oti.vm;

import java.util.Properties;

/*[IF Sidecar19-SE]*/
import jdk.internal.reflect.ConstantPool;
/*[ELSE]*/
import sun.reflect.ConstantPool;
/*[ENDIF]*/

/**
* Interface to allow privileged access to classes
* from outside the java.lang package. Based on sun.misc.SharedSecrets
Expand Down Expand Up @@ -169,4 +168,12 @@ public interface VMLangAccess {
* @return A java.lang.Thread created
*/
public Thread createThread(Runnable runnable, String threadName, boolean isSystemThreadGroup, boolean inheritThreadLocals, boolean isDaemon, ClassLoader contextClassLoader);


/**
* Prepare the passed in class
*
* @param theClass The class to prepare
*/
public void prepare(Class<?> theClass);
}
11 changes: 8 additions & 3 deletions jcl/src/java.base/share/classes/java/lang/VMAccess.java
@@ -1,8 +1,6 @@
/*[INCLUDE-IF Sidecar16]*/
package java.lang;

/*******************************************************************************
* Copyright (c) 2012, 2019 IBM Corp. and others
* Copyright (c) 2012, 2020 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 All @@ -23,6 +21,8 @@
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
*******************************************************************************/

package java.lang;

import java.util.Objects;
import java.util.Properties;

Expand Down Expand Up @@ -220,4 +220,9 @@ public void addPackageToList(java.lang.Class<?> newClass, ClassLoader loader) {
public Thread createThread(Runnable runnable, String threadName, boolean isSystemThreadGroup, boolean inheritThreadLocals, boolean isDaemon, ClassLoader contextClassLoader) {
return new Thread(runnable, threadName, isSystemThreadGroup, inheritThreadLocals, isDaemon, contextClassLoader);
}

@Override
public void prepare(Class<?> theClass) {
J9VMInternals.prepare(theClass);
}
}
Expand Up @@ -2160,6 +2160,9 @@ public Class<?> defineClass(byte[] classBytes) throws NullPointerException, Ille
JavaLangAccess jlAccess = SharedSecrets.getJavaLangAccess();
Class<?> targetClass = jlAccess.defineClass(accessClass.getClassLoader(), targetClassName, classBytes, accessClass.getProtectionDomain(), null);

/* Class needs to be linked but without having been initialized */
getVMLangAccess().prepare(targetClass);

return targetClass;
}
/*[ENDIF] Sidecar19-SE-OpenJ9*/
Expand Down

0 comments on commit a716896

Please sign in to comment.