# HG changeset patch # User alanb # Date 1480583069 0 # Node ID 180839e7d68a5d3c404e0f66452bb1177a1c28e4 # Parent d5a4c77def78aaba9b412339346aa7bfad2390d1 8169069: Module system implementation refresh (11/2016) Reviewed-by: alanb, mchung, sundar Contributed-by: alan.bateman@oracle.com, mandy.chung@oracle.com, sundararajan.athijegannathan@oracle.com diff -r d5a4c77def78 -r 180839e7d68a nashorn/make/project.properties --- a/nashorn/make/project.properties Wed Nov 23 16:16:37 2016 +0000 +++ b/nashorn/make/project.properties Thu Dec 01 09:04:29 2016 +0000 @@ -154,7 +154,9 @@ --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.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 diff -r d5a4c77def78 -r 180839e7d68a nashorn/src/jdk.dynalink/share/classes/module-info.java --- a/nashorn/src/jdk.dynalink/share/classes/module-info.java Wed Nov 23 16:16:37 2016 +0000 +++ b/nashorn/src/jdk.dynalink/share/classes/module-info.java Thu Dec 01 09:04:29 2016 +0000 @@ -23,6 +23,9 @@ * questions. */ +/** + * Dynalink + */ module jdk.dynalink { requires java.logging; diff -r d5a4c77def78 -r 180839e7d68a nashorn/src/jdk.scripting.nashorn.shell/share/classes/module-info.java --- a/nashorn/src/jdk.scripting.nashorn.shell/share/classes/module-info.java Wed Nov 23 16:16:37 2016 +0000 +++ b/nashorn/src/jdk.scripting.nashorn.shell/share/classes/module-info.java Thu Dec 01 09:04:29 2016 +0000 @@ -23,6 +23,9 @@ * questions. */ +/** + * Nashorn shell module + */ module jdk.scripting.nashorn.shell { requires java.desktop; requires java.compiler; diff -r d5a4c77def78 -r 180839e7d68a nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Context.java --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Context.java Wed Nov 23 16:16:37 2016 +0000 +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Context.java Thu Dec 01 09:04:29 2016 +0000 @@ -320,7 +320,7 @@ private final WeakValueCache> anonymousHostClasses = new WeakValueCache<>(); 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 byte[] ANONYMOUS_HOST_CLASS_BYTES = getAnonymousHostClassBytes(); @@ -357,21 +357,6 @@ cw.visitEnd(); return cw.toByteArray(); } - - private static Unsafe getUnsafe() { - return AccessController.doPrivileged(new PrivilegedAction() { - @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 ? */ diff -r d5a4c77def78 -r 180839e7d68a nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ScriptLoader.java --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ScriptLoader.java Wed Nov 23 16:16:37 2016 +0000 +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ScriptLoader.java Thu Dec 01 09:04:29 2016 +0000 @@ -69,12 +69,12 @@ private Module createModule(final String moduleName) { final Module structMod = context.getStructLoader().getModule(); final ModuleDescriptor.Builder builder = - new ModuleDescriptor.Builder(moduleName) + ModuleDescriptor.module(moduleName) .requires("java.base") .requires("java.logging") .requires(NASHORN_MODULE.getName()) .requires(structMod.getName()) - .conceals(SCRIPTS_PKG); + .contains(SCRIPTS_PKG); if (Context.javaSqlFound) { builder.requires("java.sql"); diff -r d5a4c77def78 -r 180839e7d68a nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/StructureLoader.java --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/StructureLoader.java Wed Nov 23 16:16:37 2016 +0000 +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/StructureLoader.java Thu Dec 01 09:04:29 2016 +0000 @@ -63,10 +63,10 @@ private Module createModule(final String moduleName) { final ModuleDescriptor descriptor - = new ModuleDescriptor.Builder(moduleName) + = ModuleDescriptor.module(moduleName) .requires("java.base") .requires(NASHORN_MODULE.getName()) - .conceals(SCRIPTS_PKG) + .contains(SCRIPTS_PKG) .build(); final Module mod = Context.createModuleTrusted(descriptor, this); diff -r d5a4c77def78 -r 180839e7d68a nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/scripts/ModuleGraphManipulator.java --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/scripts/ModuleGraphManipulator.java Wed Nov 23 16:16:37 2016 +0000 +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/scripts/ModuleGraphManipulator.java Thu Dec 01 09:04:29 2016 +0000 @@ -61,8 +61,8 @@ throw new IllegalStateException(myClass + " loaded by wrong loader!"); } - // From this module add a qualified export to nashorn module - MY_MODULE.addExports(MY_PKG_NAME, nashornModule); + // open package to nashorn module + MY_MODULE.addOpens(MY_PKG_NAME, nashornModule); } // The following method is reflectively invoked from Nashorn diff -r d5a4c77def78 -r 180839e7d68a nashorn/src/jdk.scripting.nashorn/share/classes/module-info.java --- a/nashorn/src/jdk.scripting.nashorn/share/classes/module-info.java Wed Nov 23 16:16:37 2016 +0000 +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/module-info.java Thu Dec 01 09:04:29 2016 +0000 @@ -23,9 +23,12 @@ * questions. */ +/** + * Nashorn + */ module jdk.scripting.nashorn { requires java.logging; - requires public java.scripting; + requires transitive java.scripting; requires jdk.dynalink; exports jdk.nashorn.api.scripting; diff -r d5a4c77def78 -r 180839e7d68a nashorn/test/TEST.ROOT --- a/nashorn/test/TEST.ROOT Wed Nov 23 16:16:37 2016 +0000 +++ b/nashorn/test/TEST.ROOT Thu Dec 01 09:04:29 2016 +0000 @@ -8,7 +8,7 @@ groups=TEST.groups # Minimum jtreg version -requiredVersion=4.2 b03 +requiredVersion=4.2 b04 # Use new module options useNewOptions=true diff -r d5a4c77def78 -r 180839e7d68a nashorn/test/script/nosecurity/JDK-8044798.js --- a/nashorn/test/script/nosecurity/JDK-8044798.js Wed Nov 23 16:16:37 2016 +0000 +++ b/nashorn/test/script/nosecurity/JDK-8044798.js Thu Dec 01 09:04:29 2016 +0000 @@ -33,13 +33,14 @@ var Arrays = Java.type("java.util.Arrays"); var CharArray = Java.type("char[]"); +var Reflector = Java.type("jdk.nashorn.test.models.Reflector"); var DebuggerSupport = Java.type("jdk.nashorn.internal.runtime.DebuggerSupport"); var DebuggerValueDesc = Java.type("jdk.nashorn.internal.runtime.DebuggerSupport.DebuggerValueDesc"); var valueDescFields = DebuggerValueDesc.class.declaredFields; Arrays.sort(valueDescFields, function(f1, f2) f1.name.compareTo(f2.name)); for each (var f in valueDescFields) { - f.accessible = true; + Reflector.setAccessible(f); } var debuggerSupportMethods = DebuggerSupport.class.declaredMethods; @@ -49,7 +50,7 @@ var getSourceInfoMethod, valueAsStringMethod; for each (var m in debuggerSupportMethods) { - m.accessible = true; + Reflector.setAccessible(m); switch (m.name) { case "eval": evalMethod = m; @@ -129,10 +130,10 @@ // private compile method of Context class var compileMethod = contextCls.getDeclaredMethod("compile", sourceCls, errorMgrCls, booleanCls, booleanCls); -compileMethod.accessible = true; +Reflector.setAccessible(compileMethod); var getContextMethod = contextCls.getMethod("getContext"); -getContextMethod.accessible = true; +Reflector.setAccessible(getContextMethod); var sourceForMethod = sourceCls.getMethod("sourceFor", stringCls, stringCls); var scriptCls = compileMethod.invoke(getContextMethod.invoke(null), @@ -149,7 +150,7 @@ print("Source info"); for each (var f in srcInfoFields) { - f.accessible = true; + Reflector.setAccessible(f); var fieldValue = f.get(srcInfo); if (fieldValue instanceof CharArray) { fieldValue = new java.lang.String(fieldValue); diff -r d5a4c77def78 -r 180839e7d68a nashorn/test/src/jdk/nashorn/internal/runtime/doubleconv/test/BignumTest.java --- a/nashorn/test/src/jdk/nashorn/internal/runtime/doubleconv/test/BignumTest.java Wed Nov 23 16:16:37 2016 +0000 +++ b/nashorn/test/src/jdk/nashorn/internal/runtime/doubleconv/test/BignumTest.java Thu Dec 01 09:04:29 2016 +0000 @@ -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. * * This code is free software; you can redistribute it and/or modify it @@ -69,7 +69,7 @@ * Bignum class tests * * @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 */ @SuppressWarnings("javadoc") diff -r d5a4c77def78 -r 180839e7d68a nashorn/test/src/jdk/nashorn/internal/runtime/doubleconv/test/DiyFpTest.java --- a/nashorn/test/src/jdk/nashorn/internal/runtime/doubleconv/test/DiyFpTest.java Wed Nov 23 16:16:37 2016 +0000 +++ b/nashorn/test/src/jdk/nashorn/internal/runtime/doubleconv/test/DiyFpTest.java Thu Dec 01 09:04:29 2016 +0000 @@ -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. * * This code is free software; you can redistribute it and/or modify it @@ -44,7 +44,7 @@ * DiyFp class tests * * @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 */ @SuppressWarnings("javadoc") diff -r d5a4c77def78 -r 180839e7d68a nashorn/test/src/jdk/nashorn/test/models/Reflector.java --- a/nashorn/test/src/jdk/nashorn/test/models/Reflector.java Wed Nov 23 16:16:37 2016 +0000 +++ b/nashorn/test/src/jdk/nashorn/test/models/Reflector.java Thu Dec 01 09:04:29 2016 +0000 @@ -26,6 +26,7 @@ package jdk.nashorn.test.models; import java.lang.reflect.Constructor; +import java.lang.reflect.Executable; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.lang.reflect.Module; @@ -42,6 +43,22 @@ private Reflector() {} 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) { if (m.getDeclaringClass().getModule() != NASHORN_MOD) { throw new RuntimeException(m + " is not from Nashorn module");