Skip to content

Commit

Permalink
Avoid call to VM::isModuleSystemInited
Browse files Browse the repository at this point in the history
Use initial error stream
  • Loading branch information
mcimadamore committed May 13, 2024
1 parent d9fe9a7 commit c4938dc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/java.base/share/classes/java/lang/Module.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@
import jdk.internal.loader.ClassLoaders;
import jdk.internal.misc.CDS;
import jdk.internal.misc.Unsafe;
import jdk.internal.misc.VM;
import jdk.internal.module.ModuleBootstrap;
import jdk.internal.module.ModuleBootstrap.IllegalNativeAccess;
import jdk.internal.module.ModuleLoaderMap;
import jdk.internal.module.ServicesCatalog;
import jdk.internal.module.Resources;
Expand Down
17 changes: 9 additions & 8 deletions src/java.base/share/classes/jdk/internal/reflect/Reflection.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,15 @@ public static void ensureMemberAccess(Class<?> currentClass,

@ForceInline
public static void ensureNativeAccess(Class<?> currentClass, Class<?> owner, String methodName) {
if (VM.isModuleSystemInited()) {
// if there is no caller class, act as if the call came from unnamed module of system class loader
Module module = currentClass != null ?
currentClass.getModule() :
ClassLoader.getSystemClassLoader().getUnnamedModule();
class Holder {
static final JavaLangAccess JLA = SharedSecrets.getJavaLangAccess();
}
// if there is no caller class, act as if the call came from unnamed module of system class loader
Module module = currentClass != null ?
currentClass.getModule() :
ClassLoader.getSystemClassLoader().getUnnamedModule();
class Holder {
static final JavaLangAccess JLA = SharedSecrets.getJavaLangAccess();
}
if (module != null) {
// not in init phase
Holder.JLA.ensureNativeAccess(module, owner, methodName, currentClass);
}
}
Expand Down

0 comments on commit c4938dc

Please sign in to comment.