8167614: Avoid module dependency from jdk.dynalink to jdk.internal.module of java.base module
Reviewed-by: jlaskey, alanb
--- a/nashorn/src/jdk.dynalink/share/classes/jdk/dynalink/beans/CallerSensitiveDynamicMethod.java Wed Oct 12 13:23:15 2016 +0200
+++ b/nashorn/src/jdk.dynalink/share/classes/jdk/dynalink/beans/CallerSensitiveDynamicMethod.java Wed Oct 12 22:42:23 2016 +0530
@@ -100,7 +100,6 @@
import jdk.dynalink.SecureLookupSupplier;
import jdk.dynalink.internal.AccessControlContextFactory;
import jdk.dynalink.linker.support.Lookup;
-import jdk.internal.module.Modules;
import jdk.internal.reflect.CallerSensitive;
@@ -180,57 +179,10 @@
}
private static MethodHandle unreflect(final MethodHandles.Lookup lookup, final Method m) {
- try {
- return Lookup.unreflect(lookup, m);
- } catch (final IllegalAccessError iae) {
- if (addModuleRead(lookup, m)) {
- try {
- return Lookup.unreflect(lookup, m);
- } catch (final IllegalAccessError e2) {
- // fall through and throw original error as cause
- }
- }
- throw iae;
- }
+ return Lookup.unreflect(lookup, m);
}
private static MethodHandle unreflectConstructor(final MethodHandles.Lookup lookup, final Constructor<?> c) {
- try {
- return Lookup.unreflectConstructor(lookup, c);
- } catch (final IllegalAccessError iae) {
- if (addModuleRead(lookup, c)) {
- try {
- return Lookup.unreflectConstructor(lookup, c);
- } catch (final IllegalAccessError e2) {
- // fall through and throw original error as cause
- }
- }
- throw iae;
- }
- }
-
-
- private static boolean addModuleRead(final MethodHandles.Lookup lookup, final Executable e) {
- // Don't add module read link if this is not a CallerSensitive member
- if (!e.isAnnotationPresent(CallerSensitive.class)) {
- return false;
- }
-
- // If the lookup is public lookup, don't bother adding module read link!
- // public lookup cannot unreflect caller sensitives anyway!
- if (lookup == MethodHandles.publicLookup()) {
- return false;
- }
-
- // try to add missing module read from using module to declararing module!
- final Class<?> declClass = e.getDeclaringClass();
- final Module useModule = lookup.lookupClass().getModule();
- final Module declModule = declClass.getModule();
- if (useModule != null && declModule != null && declModule.isExported(declClass.getPackageName())) {
- Modules.addReads(useModule, declModule);
- return true;
- }
-
- return false;
+ return Lookup.unreflectConstructor(lookup, c);
}
}
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Context.java Wed Oct 12 13:23:15 2016 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Context.java Wed Oct 12 22:42:23 2016 +0530
@@ -389,6 +389,15 @@
// is created, and invalidated forever once the second global is created.
private final AtomicReference<GlobalConstants> globalConstantsRef = new AtomicReference<>();
+ // Are java.sql, java.sql.rowset modules found in the system?
+ static final boolean javaSqlFound, javaSqlRowsetFound;
+
+ static {
+ final Layer boot = Layer.boot();
+ javaSqlFound = boot.findModule("java.sql").isPresent();
+ javaSqlRowsetFound = boot.findModule("java.sql.rowset").isPresent();
+ }
+
/**
* Get the current global scope
* @return the current global scope
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ScriptLoader.java Wed Oct 12 13:23:15 2016 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ScriptLoader.java Wed Oct 12 22:42:23 2016 +0530
@@ -68,12 +68,23 @@
private Module createModule(final String moduleName) {
final Module structMod = context.getStructLoader().getModule();
- final ModuleDescriptor descriptor
- = new ModuleDescriptor.Builder(moduleName)
+ final ModuleDescriptor.Builder builder =
+ new ModuleDescriptor.Builder(moduleName)
+ .requires("java.base")
+ .requires("java.logging")
.requires(NASHORN_MODULE.getName())
.requires(structMod.getName())
- .conceals(SCRIPTS_PKG)
- .build();
+ .conceals(SCRIPTS_PKG);
+
+ if (Context.javaSqlFound) {
+ builder.requires("java.sql");
+ }
+
+ if (Context.javaSqlRowsetFound) {
+ builder.requires("java.sql.rowset");
+ }
+
+ final ModuleDescriptor descriptor = builder.build();
final Module mod = Context.createModuleTrusted(structMod.getLayer(), descriptor, this);
loadModuleManipulator();
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/StructureLoader.java Wed Oct 12 13:23:15 2016 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/StructureLoader.java Wed Oct 12 22:42:23 2016 +0530
@@ -64,6 +64,7 @@
private Module createModule(final String moduleName) {
final ModuleDescriptor descriptor
= new ModuleDescriptor.Builder(moduleName)
+ .requires("java.base")
.requires(NASHORN_MODULE.getName())
.conceals(SCRIPTS_PKG)
.build();