8169069: Module system implementation refresh (11/2016)
Co-authored-by: Mandy Chung <mandy.chung@oracle.com> Co-authored-by: Sundararajan Athijegannathan <sundararajan.athijegannathan@oracle.com> Reviewed-by: alanb, mchung, sundar
This commit is contained in:
parent
1be16f5dee
commit
a8e63c4db5
@ -154,7 +154,9 @@ test.module.imports=\
|
|||||||
--add-exports jdk.scripting.nashorn/jdk.nashorn.internal.runtime.regexp=ALL-UNNAMED \
|
--add-exports jdk.scripting.nashorn/jdk.nashorn.internal.runtime.regexp=ALL-UNNAMED \
|
||||||
--add-exports jdk.scripting.nashorn/jdk.nashorn.internal.runtime.regexp.joni=ALL-UNNAMED \
|
--add-exports jdk.scripting.nashorn/jdk.nashorn.internal.runtime.regexp.joni=ALL-UNNAMED \
|
||||||
--add-exports jdk.scripting.nashorn/jdk.nashorn.tools=ALL-UNNAMED \
|
--add-exports jdk.scripting.nashorn/jdk.nashorn.tools=ALL-UNNAMED \
|
||||||
--add-exports java.base/jdk.internal.org.objectweb.asm=ALL-UNNAMED
|
--add-exports java.base/jdk.internal.org.objectweb.asm=ALL-UNNAMED \
|
||||||
|
--add-opens jdk.scripting.nashorn/jdk.nashorn.internal.runtime=ALL-UNNAMED \
|
||||||
|
--add-opens jdk.scripting.nashorn/jdk.nashorn.internal.runtime.doubleconv=ALL-UNNAMED
|
||||||
|
|
||||||
meta.inf.dir=${nashorn.module.src.dir}/META-INF
|
meta.inf.dir=${nashorn.module.src.dir}/META-INF
|
||||||
|
|
||||||
|
@ -23,6 +23,9 @@
|
|||||||
* questions.
|
* questions.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dynalink
|
||||||
|
*/
|
||||||
module jdk.dynalink {
|
module jdk.dynalink {
|
||||||
requires java.logging;
|
requires java.logging;
|
||||||
|
|
||||||
|
@ -23,6 +23,9 @@
|
|||||||
* questions.
|
* questions.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Nashorn shell module
|
||||||
|
*/
|
||||||
module jdk.scripting.nashorn.shell {
|
module jdk.scripting.nashorn.shell {
|
||||||
requires java.desktop;
|
requires java.desktop;
|
||||||
requires java.compiler;
|
requires java.compiler;
|
||||||
|
@ -320,7 +320,7 @@ public final class Context {
|
|||||||
private final WeakValueCache<CodeSource, Class<?>> anonymousHostClasses = new WeakValueCache<>();
|
private final WeakValueCache<CodeSource, Class<?>> anonymousHostClasses = new WeakValueCache<>();
|
||||||
|
|
||||||
private static final class AnonymousContextCodeInstaller extends ContextCodeInstaller {
|
private static final class AnonymousContextCodeInstaller extends ContextCodeInstaller {
|
||||||
private static final Unsafe UNSAFE = getUnsafe();
|
private static final Unsafe UNSAFE = Unsafe.getUnsafe();
|
||||||
private static final String ANONYMOUS_HOST_CLASS_NAME = Compiler.SCRIPTS_PACKAGE.replace('/', '.') + ".AnonymousHost";
|
private static final String ANONYMOUS_HOST_CLASS_NAME = Compiler.SCRIPTS_PACKAGE.replace('/', '.') + ".AnonymousHost";
|
||||||
private static final byte[] ANONYMOUS_HOST_CLASS_BYTES = getAnonymousHostClassBytes();
|
private static final byte[] ANONYMOUS_HOST_CLASS_BYTES = getAnonymousHostClassBytes();
|
||||||
|
|
||||||
@ -357,21 +357,6 @@ public final class Context {
|
|||||||
cw.visitEnd();
|
cw.visitEnd();
|
||||||
return cw.toByteArray();
|
return cw.toByteArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Unsafe getUnsafe() {
|
|
||||||
return AccessController.doPrivileged(new PrivilegedAction<Unsafe>() {
|
|
||||||
@Override
|
|
||||||
public Unsafe run() {
|
|
||||||
try {
|
|
||||||
final Field theUnsafeField = Unsafe.class.getDeclaredField("theUnsafe");
|
|
||||||
theUnsafeField.setAccessible(true);
|
|
||||||
return (Unsafe)theUnsafeField.get(null);
|
|
||||||
} catch (final ReflectiveOperationException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Is Context global debug mode enabled ? */
|
/** Is Context global debug mode enabled ? */
|
||||||
|
@ -69,12 +69,12 @@ final class ScriptLoader extends NashornLoader {
|
|||||||
private Module createModule(final String moduleName) {
|
private Module createModule(final String moduleName) {
|
||||||
final Module structMod = context.getStructLoader().getModule();
|
final Module structMod = context.getStructLoader().getModule();
|
||||||
final ModuleDescriptor.Builder builder =
|
final ModuleDescriptor.Builder builder =
|
||||||
new ModuleDescriptor.Builder(moduleName)
|
ModuleDescriptor.module(moduleName)
|
||||||
.requires("java.base")
|
.requires("java.base")
|
||||||
.requires("java.logging")
|
.requires("java.logging")
|
||||||
.requires(NASHORN_MODULE.getName())
|
.requires(NASHORN_MODULE.getName())
|
||||||
.requires(structMod.getName())
|
.requires(structMod.getName())
|
||||||
.conceals(SCRIPTS_PKG);
|
.contains(SCRIPTS_PKG);
|
||||||
|
|
||||||
if (Context.javaSqlFound) {
|
if (Context.javaSqlFound) {
|
||||||
builder.requires("java.sql");
|
builder.requires("java.sql");
|
||||||
|
@ -63,10 +63,10 @@ final class StructureLoader extends NashornLoader {
|
|||||||
|
|
||||||
private Module createModule(final String moduleName) {
|
private Module createModule(final String moduleName) {
|
||||||
final ModuleDescriptor descriptor
|
final ModuleDescriptor descriptor
|
||||||
= new ModuleDescriptor.Builder(moduleName)
|
= ModuleDescriptor.module(moduleName)
|
||||||
.requires("java.base")
|
.requires("java.base")
|
||||||
.requires(NASHORN_MODULE.getName())
|
.requires(NASHORN_MODULE.getName())
|
||||||
.conceals(SCRIPTS_PKG)
|
.contains(SCRIPTS_PKG)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
final Module mod = Context.createModuleTrusted(descriptor, this);
|
final Module mod = Context.createModuleTrusted(descriptor, this);
|
||||||
|
@ -61,8 +61,8 @@ final class ModuleGraphManipulator {
|
|||||||
throw new IllegalStateException(myClass + " loaded by wrong loader!");
|
throw new IllegalStateException(myClass + " loaded by wrong loader!");
|
||||||
}
|
}
|
||||||
|
|
||||||
// From this module add a qualified export to nashorn module
|
// open package to nashorn module
|
||||||
MY_MODULE.addExports(MY_PKG_NAME, nashornModule);
|
MY_MODULE.addOpens(MY_PKG_NAME, nashornModule);
|
||||||
}
|
}
|
||||||
|
|
||||||
// The following method is reflectively invoked from Nashorn
|
// The following method is reflectively invoked from Nashorn
|
||||||
|
@ -23,9 +23,12 @@
|
|||||||
* questions.
|
* questions.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Nashorn
|
||||||
|
*/
|
||||||
module jdk.scripting.nashorn {
|
module jdk.scripting.nashorn {
|
||||||
requires java.logging;
|
requires java.logging;
|
||||||
requires public java.scripting;
|
requires transitive java.scripting;
|
||||||
requires jdk.dynalink;
|
requires jdk.dynalink;
|
||||||
|
|
||||||
exports jdk.nashorn.api.scripting;
|
exports jdk.nashorn.api.scripting;
|
||||||
|
@ -8,7 +8,7 @@ keys=intermittent randomness
|
|||||||
groups=TEST.groups
|
groups=TEST.groups
|
||||||
|
|
||||||
# Minimum jtreg version
|
# Minimum jtreg version
|
||||||
requiredVersion=4.2 b03
|
requiredVersion=4.2 b04
|
||||||
|
|
||||||
# Use new module options
|
# Use new module options
|
||||||
useNewOptions=true
|
useNewOptions=true
|
||||||
|
@ -33,13 +33,14 @@
|
|||||||
|
|
||||||
var Arrays = Java.type("java.util.Arrays");
|
var Arrays = Java.type("java.util.Arrays");
|
||||||
var CharArray = Java.type("char[]");
|
var CharArray = Java.type("char[]");
|
||||||
|
var Reflector = Java.type("jdk.nashorn.test.models.Reflector");
|
||||||
var DebuggerSupport = Java.type("jdk.nashorn.internal.runtime.DebuggerSupport");
|
var DebuggerSupport = Java.type("jdk.nashorn.internal.runtime.DebuggerSupport");
|
||||||
var DebuggerValueDesc = Java.type("jdk.nashorn.internal.runtime.DebuggerSupport.DebuggerValueDesc");
|
var DebuggerValueDesc = Java.type("jdk.nashorn.internal.runtime.DebuggerSupport.DebuggerValueDesc");
|
||||||
|
|
||||||
var valueDescFields = DebuggerValueDesc.class.declaredFields;
|
var valueDescFields = DebuggerValueDesc.class.declaredFields;
|
||||||
Arrays.sort(valueDescFields, function(f1, f2) f1.name.compareTo(f2.name));
|
Arrays.sort(valueDescFields, function(f1, f2) f1.name.compareTo(f2.name));
|
||||||
for each (var f in valueDescFields) {
|
for each (var f in valueDescFields) {
|
||||||
f.accessible = true;
|
Reflector.setAccessible(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
var debuggerSupportMethods = DebuggerSupport.class.declaredMethods;
|
var debuggerSupportMethods = DebuggerSupport.class.declaredMethods;
|
||||||
@ -49,7 +50,7 @@ var evalMethod, valueInfoMethod, valueInfosMethod;
|
|||||||
var getSourceInfoMethod, valueAsStringMethod;
|
var getSourceInfoMethod, valueAsStringMethod;
|
||||||
|
|
||||||
for each (var m in debuggerSupportMethods) {
|
for each (var m in debuggerSupportMethods) {
|
||||||
m.accessible = true;
|
Reflector.setAccessible(m);
|
||||||
switch (m.name) {
|
switch (m.name) {
|
||||||
case "eval":
|
case "eval":
|
||||||
evalMethod = m;
|
evalMethod = m;
|
||||||
@ -129,10 +130,10 @@ var stringCls = Java.type("java.lang.String").class;
|
|||||||
// private compile method of Context class
|
// private compile method of Context class
|
||||||
var compileMethod = contextCls.getDeclaredMethod("compile",
|
var compileMethod = contextCls.getDeclaredMethod("compile",
|
||||||
sourceCls, errorMgrCls, booleanCls, booleanCls);
|
sourceCls, errorMgrCls, booleanCls, booleanCls);
|
||||||
compileMethod.accessible = true;
|
Reflector.setAccessible(compileMethod);
|
||||||
|
|
||||||
var getContextMethod = contextCls.getMethod("getContext");
|
var getContextMethod = contextCls.getMethod("getContext");
|
||||||
getContextMethod.accessible = true;
|
Reflector.setAccessible(getContextMethod);
|
||||||
|
|
||||||
var sourceForMethod = sourceCls.getMethod("sourceFor", stringCls, stringCls);
|
var sourceForMethod = sourceCls.getMethod("sourceFor", stringCls, stringCls);
|
||||||
var scriptCls = compileMethod.invoke(getContextMethod.invoke(null),
|
var scriptCls = compileMethod.invoke(getContextMethod.invoke(null),
|
||||||
@ -149,7 +150,7 @@ Arrays.sort(srcInfoFields, function(f1, f2) f1.name.compareTo(f2.name));
|
|||||||
|
|
||||||
print("Source info");
|
print("Source info");
|
||||||
for each (var f in srcInfoFields) {
|
for each (var f in srcInfoFields) {
|
||||||
f.accessible = true;
|
Reflector.setAccessible(f);
|
||||||
var fieldValue = f.get(srcInfo);
|
var fieldValue = f.get(srcInfo);
|
||||||
if (fieldValue instanceof CharArray) {
|
if (fieldValue instanceof CharArray) {
|
||||||
fieldValue = new java.lang.String(fieldValue);
|
fieldValue = new java.lang.String(fieldValue);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -69,7 +69,7 @@ import static org.testng.Assert.assertTrue;
|
|||||||
* Bignum class tests
|
* Bignum class tests
|
||||||
*
|
*
|
||||||
* @test
|
* @test
|
||||||
* @modules jdk.scripting.nashorn/jdk.nashorn.internal.runtime.doubleconv
|
* @modules jdk.scripting.nashorn/jdk.nashorn.internal.runtime.doubleconv:open
|
||||||
* @run testng jdk.nashorn.internal.runtime.doubleconv.test.BignumTest
|
* @run testng jdk.nashorn.internal.runtime.doubleconv.test.BignumTest
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("javadoc")
|
@SuppressWarnings("javadoc")
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -44,7 +44,7 @@ import static org.testng.Assert.assertTrue;
|
|||||||
* DiyFp class tests
|
* DiyFp class tests
|
||||||
*
|
*
|
||||||
* @test
|
* @test
|
||||||
* @modules jdk.scripting.nashorn/jdk.nashorn.internal.runtime.doubleconv
|
* @modules jdk.scripting.nashorn/jdk.nashorn.internal.runtime.doubleconv:open
|
||||||
* @run testng jdk.nashorn.internal.runtime.doubleconv.test.DiyFpTest
|
* @run testng jdk.nashorn.internal.runtime.doubleconv.test.DiyFpTest
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("javadoc")
|
@SuppressWarnings("javadoc")
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
package jdk.nashorn.test.models;
|
package jdk.nashorn.test.models;
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
|
import java.lang.reflect.Executable;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Module;
|
import java.lang.reflect.Module;
|
||||||
@ -42,6 +43,22 @@ public final class Reflector {
|
|||||||
private Reflector() {}
|
private Reflector() {}
|
||||||
private static final Module NASHORN_MOD = Context.class.getModule();
|
private static final Module NASHORN_MOD = Context.class.getModule();
|
||||||
|
|
||||||
|
public static void setAccessible(Executable e) {
|
||||||
|
if (e.getDeclaringClass().getModule() != NASHORN_MOD) {
|
||||||
|
throw new RuntimeException(e + " is not from Nashorn module");
|
||||||
|
}
|
||||||
|
|
||||||
|
e.setAccessible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setAccessible(Field f) {
|
||||||
|
if (f.getDeclaringClass().getModule() != NASHORN_MOD) {
|
||||||
|
throw new RuntimeException(f + " is not from Nashorn module");
|
||||||
|
}
|
||||||
|
|
||||||
|
f.setAccessible(true);
|
||||||
|
}
|
||||||
|
|
||||||
public static Object invoke(final Method m, final Object self, final Object...args) {
|
public static Object invoke(final Method m, final Object self, final Object...args) {
|
||||||
if (m.getDeclaringClass().getModule() != NASHORN_MOD) {
|
if (m.getDeclaringClass().getModule() != NASHORN_MOD) {
|
||||||
throw new RuntimeException(m + " is not from Nashorn module");
|
throw new RuntimeException(m + " is not from Nashorn module");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user