From c4938dc798b83558b8fbc45169c3b64223ea0f2b Mon Sep 17 00:00:00 2001 From: Maurizio Cimadamore Date: Mon, 13 May 2024 12:36:40 +0100 Subject: [PATCH] Avoid call to VM::isModuleSystemInited Use initial error stream --- .../share/classes/java/lang/Module.java | 2 ++ .../jdk/internal/reflect/Reflection.java | 17 +++++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/java.base/share/classes/java/lang/Module.java b/src/java.base/share/classes/java/lang/Module.java index 5b1111a6d72a6..933c3c39b5e47 100644 --- a/src/java.base/share/classes/java/lang/Module.java +++ b/src/java.base/share/classes/java/lang/Module.java @@ -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; diff --git a/src/java.base/share/classes/jdk/internal/reflect/Reflection.java b/src/java.base/share/classes/jdk/internal/reflect/Reflection.java index 349ff1af9b5ce..38308ec6f853a 100644 --- a/src/java.base/share/classes/jdk/internal/reflect/Reflection.java +++ b/src/java.base/share/classes/jdk/internal/reflect/Reflection.java @@ -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); } }