Skip to content

Commit

Permalink
Merge pull request #21006 from keithc-ca/checkPackageAccess
Browse files Browse the repository at this point in the history
Remove J9VMInternals.checkPackageAccess() from Java 24+
  • Loading branch information
pshipton authored Jan 25, 2025
2 parents efeca47 + 6b2a3c9 commit 1c0f64e
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 71 deletions.
8 changes: 4 additions & 4 deletions jcl/src/java.base/share/classes/java/lang/J9VMInternals.java
Original file line number Diff line number Diff line change
Expand Up @@ -385,13 +385,13 @@ private static void threadCleanup(Thread thread) {
}
}

/*[IF JAVA_SPEC_VERSION < 24]*/
/*[PR CVMC 124584] checkPackageAccess(), not defineClassImpl(), should use ProtectionDomain */
private static void checkPackageAccess(final Class<?> clazz, ProtectionDomain pd) {
/*[IF JAVA_SPEC_VERSION < 24]*/
@SuppressWarnings("removal")
final SecurityManager sm = System.getSecurityManager();
if (sm != null) {
ProtectionDomain[] pdArray = (pd == null) ? new ProtectionDomain[]{} : new ProtectionDomain[]{pd};
ProtectionDomain[] pdArray = (pd == null) ? new ProtectionDomain[] {} : new ProtectionDomain[] { pd };
AccessController.doPrivileged(new PrivilegedAction<Object>() {
@Override
public Object run() {
Expand All @@ -401,15 +401,15 @@ public Object run() {
}
if (Proxy.isProxyClass(clazz)) {
/*[PR CMVC 198986] Fix proxies */
ClassLoader cl = clazz.getClassLoaderImpl();
ClassLoader cl = clazz.getClassLoaderImpl();
sun.reflect.misc.ReflectUtil.checkProxyPackageAccess(cl, clazz.getInterfaces());
}
return null;
}
}, new AccessControlContext(pdArray));
}
/*[ENDIF] JAVA_SPEC_VERSION < 24 */
}
/*[ENDIF] JAVA_SPEC_VERSION < 24 */

/*[PR CMVC 104341] Exceptions in Object.finalize() not ignored */

Expand Down
4 changes: 3 additions & 1 deletion runtime/oti/j9protos.h
Original file line number Diff line number Diff line change
Expand Up @@ -1353,7 +1353,9 @@ extern J9_CFUNC void JNICALL initializeAttachedThread (J9VMThread *vmContext, c
extern J9_CFUNC void JNICALL initializeAttachedThreadImpl (J9VMThread *vmContext, const char *name, j9object_t *group, UDATA daemon, J9VMThread *initializee);
extern J9_CFUNC void JNICALL runStaticMethod (J9VMThread *vmContext, U_8* className, J9NameAndSignature* selector, UDATA argCount, UDATA* arguments);
extern J9_CFUNC void JNICALL internalRunStaticMethod (J9VMThread *vmContext, J9Method *method, BOOLEAN returnsObject, UDATA argCount, UDATA* arguments);
extern J9_CFUNC void JNICALL sendCheckPackageAccess (J9VMThread *vmContext, J9Class * clazz, j9object_t protectionDomain);
#if JAVA_SPEC_VERSION < 24
extern J9_CFUNC void JNICALL sendCheckPackageAccess(J9VMThread *vmContext, J9Class *clazz, j9object_t protectionDomain);
#endif /* JAVA_SPEC_VERSION < 24 */
extern J9_CFUNC void JNICALL sidecarInvokeReflectConstructor (J9VMThread *vmContext, jobject constructorRef, jobject recevierRef, jobjectArray argsRef);
extern J9_CFUNC void JNICALL sidecarInvokeReflectConstructorImpl (J9VMThread *vmContext, jobject constructorRef, jobject recevierRef, jobjectArray argsRef);
extern J9_CFUNC void JNICALL sendFromMethodDescriptorString (J9VMThread *vmThread, J9UTF8 *descriptor, J9ClassLoader *classLoader, J9Class *appendArgType);
Expand Down
2 changes: 1 addition & 1 deletion runtime/oti/vm_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -2918,8 +2918,8 @@ findFieldExt(J9VMThread *vmStruct, J9Class *clazz, U_8 *fieldName, UDATA fieldNa
void
fieldIndexTableRemove(J9JavaVM* vm, J9Class *ramClass);


/* ---------------- resolvesupport.c ---------------- */

#if JAVA_SPEC_VERSION < 24
/**
* Perform a package access check from the ProtectionDomain to the targetClass
Expand Down
2 changes: 1 addition & 1 deletion runtime/oti/vmconstantpool.xml
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0-only WITH Classpath-ex
for each combination of method flags.
-->
<staticmethodref class="java/lang/J9VMInternals" name="completeInitialization" signature="()V"/>
<staticmethodref class="java/lang/J9VMInternals" name="checkPackageAccess" signature="(Ljava/lang/Class;Ljava/security/ProtectionDomain;)V"/>
<staticmethodref class="java/lang/J9VMInternals" name="checkPackageAccess" signature="(Ljava/lang/Class;Ljava/security/ProtectionDomain;)V" versions="8-23"/>
<staticmethodref class="java/lang/J9VMInternals" name="threadCleanup" signature="(Ljava/lang/Thread;)V"/>
<staticmethodref class="java/lang/J9VMInternals" name="newInstanceImpl" signature="(Ljava/lang/Class;)Ljava/lang/Object;" flags="jit_newInstancePrototype"/>
<staticmethodref class="java/lang/J9VMInternals" name="formatNoSuchMethod" signature="(Ljava/lang/String;Ljava/lang/Class;Ljava/lang/String;Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/String;"/>
Expand Down
2 changes: 2 additions & 0 deletions runtime/vm/callin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,7 @@ internalRunStaticMethod(J9VMThread *currentThread, J9Method *method, BOOLEAN ret
Trc_VM_internalRunStaticMethod_Exit(currentThread);
}

#if JAVA_SPEC_VERSION < 24
void JNICALL
sendCheckPackageAccess(J9VMThread *currentThread, J9Class *clazz, j9object_t protectionDomain)
{
Expand All @@ -763,6 +764,7 @@ sendCheckPackageAccess(J9VMThread *currentThread, J9Class *clazz, j9object_t pro
}
Trc_VM_sendCheckPackageAccess_Exit(currentThread);
}
#endif /* JAVA_SPEC_VERSION < 24 */

void JNICALL
sendCompleteInitialization(J9VMThread *currentThread)
Expand Down
8 changes: 4 additions & 4 deletions runtime/vm/createramclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1772,13 +1772,13 @@ loadSuperClassAndInterfaces(J9VMThread *vmThread, J9ClassLoader *classLoader, J9

for (i = 0; i<romClass->interfaceCount; i++) {
J9UTF8 *interfaceName = NNSRP_GET(interfaceNames[i], J9UTF8*);

if (J9UTF8_EQUALS(interfaceName, className)) {
/* className and interfaceName are the same */
setCurrentException(vmThread, J9VMCONSTANTPOOL_JAVALANGCLASSCIRCULARITYERROR, NULL);
return FALSE;
}

J9Class *interfaceClass = internalFindClassUTF8(vmThread, J9UTF8_DATA(interfaceName), J9UTF8_LENGTH(interfaceName), classLoader, classPreloadFlags);

Trc_VM_CreateRAMClassFromROMClass_loadedInterface(vmThread, J9UTF8_LENGTH(interfaceName), J9UTF8_DATA(interfaceName), interfaceClass);
Expand Down Expand Up @@ -2407,7 +2407,7 @@ internalCreateRAMClassDone(J9VMThread *vmThread, J9ClassLoader *classLoader, J9C
javaVM->memoryManagerFunctions->j9gc_modron_global_collect_with_overrides(vmThread, J9MMCONSTANT_EXPLICIT_GC_NATIVE_OUT_OF_MEMORY);
state->classObject = POP_OBJECT_IN_SPECIAL_FRAME(vmThread);
omrthread_monitor_enter(javaVM->classTableMutex);

if (J9_ARE_NO_BITS_SET(options, J9_FINDCLASS_FLAG_HIDDEN)) {
/* If the class was successfully loaded while we were GCing, use that one */
if (elementClass == NULL) {
Expand All @@ -2418,7 +2418,7 @@ internalCreateRAMClassDone(J9VMThread *vmThread, J9ClassLoader *classLoader, J9C
if (alreadyLoadedClass != NULL) {
goto alreadyLoaded;
}

/* Try the store again - if it fails again, throw native OOM */
if (hashClassTableAtPut(vmThread, classLoader, J9UTF8_DATA(className), J9UTF8_LENGTH(className), state->ramClass)) {
goto nativeOOM;
Expand Down
Loading

0 comments on commit 1c0f64e

Please sign in to comment.