8142968: Module System implementation

Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282

Co-authored-by: Alex Buckley <alex.buckley@oracle.com>
Co-authored-by: Jonathan Gibbons <jonathan.gibbons@oracle.com>
Co-authored-by: Karen Kinnear <karen.kinnear@oracle.com>
Co-authored-by: Mandy Chung <mandy.chung@oracle.com>
Co-authored-by: Mark Reinhold <mark.reinhold@oracle.com>
Co-authored-by: Sundararajan Athijegannathan <sundararajan.athijegannathan@oracle.com>
Co-authored-by: Erik Joelsson <erik.joelsson@oracle.com>
Reviewed-by: mhaupt, hannesw
This commit is contained in:
Alan Bateman 2016-03-17 19:04:35 +00:00
parent 457c588e74
commit 9a9e272b1d
55 changed files with 725 additions and 281 deletions

View File

@ -40,10 +40,9 @@
<target name="compile" depends="prepare" description="Compiles the nasgen sources">
<javac srcdir="${src.dir}"
destdir="${build.classes.dir}"
classpath="${javac.classpath}"
debug="${javac.debug}"
includeantruntime="false" fork="true">
<compilerarg value="-J-Xbootclasspath/p:${javac.classpath}"/>
<compilerarg value="-XaddExports:${nasgen.module.imports}"/>
<compilerarg value="-Xlint:unchecked"/>
<compilerarg value="-Xlint:deprecation"/>
<compilerarg value="-XDignore.symbol.file"/>

View File

@ -37,12 +37,11 @@ dist.dir=dist
dist.jar=${dist.dir}/nasgen.jar
dist.javadoc.dir=${dist.dir}/javadoc
nashorn.dir=../../
javac.debug=true
javac.classpath=\
${nashorn.dir}/build/classes
nasgen.module.imports=\
java.base/jdk.internal.org.objectweb.asm=ALL-UNNAMED,\
java.base/jdk.internal.org.objectweb.asm.util=ALL-UNNAMED
meta.inf.dir=${src.dir}/META-INF
run.classpath=\

View File

@ -143,6 +143,9 @@ public class ClassGenerator {
try {
return super.getCommonSuperClass(type1, type2);
} catch (final RuntimeException | LinkageError e) {
if (MemberInfo.isScriptObject(type1) && MemberInfo.isScriptObject(type2)) {
return StringConstants.SCRIPTOBJECT_TYPE;
}
return StringConstants.OBJECT_TYPE;
}
}

View File

@ -26,14 +26,15 @@ package jdk.nashorn.internal.tools.nasgen;
import static jdk.nashorn.internal.tools.nasgen.StringConstants.OBJECT_ARRAY_DESC;
import static jdk.nashorn.internal.tools.nasgen.StringConstants.OBJECT_DESC;
import static jdk.nashorn.internal.tools.nasgen.StringConstants.OBJ_PKG;
import static jdk.nashorn.internal.tools.nasgen.StringConstants.RUNTIME_PKG;
import static jdk.nashorn.internal.tools.nasgen.StringConstants.SCRIPTS_PKG;
import static jdk.nashorn.internal.tools.nasgen.StringConstants.SCRIPTOBJECT_DESC;
import static jdk.nashorn.internal.tools.nasgen.StringConstants.STRING_DESC;
import static jdk.nashorn.internal.tools.nasgen.StringConstants.TYPE_SYMBOL;
import jdk.internal.org.objectweb.asm.Opcodes;
import jdk.internal.org.objectweb.asm.Type;
import jdk.nashorn.internal.objects.annotations.Where;
import jdk.nashorn.internal.runtime.ScriptObject;
/**
* Details about a Java method or field annotated with any of the field/method
@ -460,6 +461,40 @@ public final class MemberInfo implements Cloneable {
}
}
/**
* Returns if the given (internal) name of a class represents a ScriptObject subtype.
*/
public static boolean isScriptObject(final String name) {
// very crude check for ScriptObject subtype!
if (name.startsWith(OBJ_PKG + "Native") ||
name.equals(OBJ_PKG + "Global") ||
name.equals(OBJ_PKG + "ArrayBufferView")) {
return true;
}
if (name.startsWith(RUNTIME_PKG)) {
final String simpleName = name.substring(name.lastIndexOf('/') + 1);
switch (simpleName) {
case "ScriptObject":
case "ScriptFunction":
case "NativeJavaPackage":
case "Scope":
return true;
}
}
if (name.startsWith(SCRIPTS_PKG)) {
final String simpleName = name.substring(name.lastIndexOf('/') + 1);
switch (simpleName) {
case "JD":
case "JO":
return true;
}
}
return false;
}
private static boolean isValidJSType(final Type type) {
return isJSPrimitiveType(type) || isJSObjectType(type);
}
@ -488,20 +523,11 @@ public final class MemberInfo implements Cloneable {
}
private static boolean isScriptObject(final Type type) {
if (type.getDescriptor().equals(SCRIPTOBJECT_DESC)) {
return true;
if (type.getSort() != Type.OBJECT) {
return false;
}
if (type.getSort() == Type.OBJECT) {
try {
final Class<?> clazz = Class.forName(type.getClassName(), false, MY_LOADER);
return ScriptObject.class.isAssignableFrom(clazz);
} catch (final ClassNotFoundException cnfe) {
return false;
}
}
return false;
return isScriptObject(type.getInternalName());
}
private void error(final String msg) {

View File

@ -77,6 +77,7 @@ import static jdk.internal.org.objectweb.asm.Opcodes.SASTORE;
import static jdk.internal.org.objectweb.asm.Opcodes.SIPUSH;
import static jdk.internal.org.objectweb.asm.Opcodes.SWAP;
import static jdk.nashorn.internal.tools.nasgen.StringConstants.INIT;
import static jdk.nashorn.internal.tools.nasgen.StringConstants.OBJ_ANNO_PKG;
import static jdk.nashorn.internal.tools.nasgen.StringConstants.SPECIALIZATION_INIT2;
import static jdk.nashorn.internal.tools.nasgen.StringConstants.SPECIALIZATION_INIT3;
import static jdk.nashorn.internal.tools.nasgen.StringConstants.SPECIALIZATION_TYPE;
@ -85,7 +86,6 @@ import java.util.List;
import jdk.internal.org.objectweb.asm.Handle;
import jdk.internal.org.objectweb.asm.MethodVisitor;
import jdk.internal.org.objectweb.asm.Type;
import jdk.nashorn.internal.objects.annotations.SpecializedFunction.LinkLogic;
/**
* Base class for all method generating classes.
@ -98,7 +98,7 @@ public class MethodGenerator extends MethodVisitor {
private final Type returnType;
private final Type[] argumentTypes;
static final Type EMPTY_LINK_LOGIC_TYPE = Type.getType(LinkLogic.getEmptyLinkLogicClass());
static final Type EMPTY_LINK_LOGIC_TYPE = Type.getType("L" + OBJ_ANNO_PKG + "SpecializedFunction$LinkLogic$Empty;");
MethodGenerator(final MethodVisitor mv, final int access, final String name, final String descriptor) {
super(Main.ASM_VERSION, mv);

View File

@ -31,33 +31,31 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import jdk.internal.org.objectweb.asm.Type;
import jdk.nashorn.internal.objects.annotations.Constructor;
import jdk.nashorn.internal.objects.annotations.Function;
import jdk.nashorn.internal.objects.annotations.Getter;
import jdk.nashorn.internal.objects.annotations.Property;
import jdk.nashorn.internal.objects.annotations.ScriptClass;
import jdk.nashorn.internal.objects.annotations.Setter;
import jdk.nashorn.internal.objects.annotations.SpecializedFunction;
import jdk.nashorn.internal.objects.annotations.SpecializedFunction.LinkLogic;
import jdk.nashorn.internal.objects.annotations.Where;
import jdk.nashorn.internal.tools.nasgen.MemberInfo.Kind;
import static jdk.nashorn.internal.tools.nasgen.StringConstants.OBJ_ANNO_PKG;
import static jdk.nashorn.internal.tools.nasgen.StringConstants.RUNTIME_PKG;
/**
* All annotation information from a class that is annotated with
* the annotation com.sun.oracle.objects.annotations.ScriptClass.
*
*/
public final class ScriptClassInfo {
private static String getTypeDescriptor(String pkg, String name) {
return "L" + pkg + name + ";";
}
// descriptors for various annotations
static final String SCRIPT_CLASS_ANNO_DESC = Type.getDescriptor(ScriptClass.class);
static final String CONSTRUCTOR_ANNO_DESC = Type.getDescriptor(Constructor.class);
static final String FUNCTION_ANNO_DESC = Type.getDescriptor(Function.class);
static final String GETTER_ANNO_DESC = Type.getDescriptor(Getter.class);
static final String SETTER_ANNO_DESC = Type.getDescriptor(Setter.class);
static final String PROPERTY_ANNO_DESC = Type.getDescriptor(Property.class);
static final String WHERE_ENUM_DESC = Type.getDescriptor(Where.class);
static final String LINK_LOGIC_DESC = Type.getDescriptor(LinkLogic.class);
static final String SPECIALIZED_FUNCTION = Type.getDescriptor(SpecializedFunction.class);
static final String SCRIPT_CLASS_ANNO_DESC = getTypeDescriptor(OBJ_ANNO_PKG, "ScriptClass");
static final String CONSTRUCTOR_ANNO_DESC = getTypeDescriptor(OBJ_ANNO_PKG, "Constructor");
static final String FUNCTION_ANNO_DESC = getTypeDescriptor(OBJ_ANNO_PKG, "Function");
static final String GETTER_ANNO_DESC = getTypeDescriptor(OBJ_ANNO_PKG, "Getter");
static final String SETTER_ANNO_DESC = getTypeDescriptor(OBJ_ANNO_PKG, "Setter");
static final String PROPERTY_ANNO_DESC = getTypeDescriptor(OBJ_ANNO_PKG, "Property");
static final String WHERE_ENUM_DESC = getTypeDescriptor(OBJ_ANNO_PKG, "Where");
static final String LINK_LOGIC_DESC = getTypeDescriptor(OBJ_ANNO_PKG, "SpecializedFunction$LinkLogic");
static final String SPECIALIZED_FUNCTION = getTypeDescriptor(OBJ_ANNO_PKG, "SpecializedFunction");
static final Map<String, Kind> annotations = new HashMap<>();
@ -276,6 +274,7 @@ public final class ScriptClassInfo {
try {
memInfo.verify();
} catch (final Exception e) {
e.printStackTrace();
error(e.getMessage());
}
}

View File

@ -41,7 +41,6 @@ import jdk.internal.org.objectweb.asm.FieldVisitor;
import jdk.internal.org.objectweb.asm.MethodVisitor;
import jdk.internal.org.objectweb.asm.Opcodes;
import jdk.internal.org.objectweb.asm.Type;
import jdk.nashorn.internal.objects.annotations.Where;
import jdk.nashorn.internal.tools.nasgen.MemberInfo.Kind;
/**

View File

@ -50,7 +50,6 @@ import jdk.internal.org.objectweb.asm.ClassWriter;
import jdk.internal.org.objectweb.asm.FieldVisitor;
import jdk.internal.org.objectweb.asm.MethodVisitor;
import jdk.internal.org.objectweb.asm.util.CheckClassAdapter;
import jdk.nashorn.internal.objects.annotations.Where;
import jdk.nashorn.internal.tools.nasgen.MemberInfo.Kind;
/**

View File

@ -31,25 +31,23 @@ import java.util.Collection;
import java.util.Collections;
import java.util.List;
import jdk.internal.org.objectweb.asm.Type;
import jdk.nashorn.internal.objects.NativeSymbol;
import jdk.nashorn.internal.runtime.AccessorProperty;
import jdk.nashorn.internal.runtime.PropertyMap;
import jdk.nashorn.internal.runtime.PrototypeObject;
import jdk.nashorn.internal.runtime.ScriptFunction;
import jdk.nashorn.internal.runtime.ScriptObject;
import jdk.nashorn.internal.runtime.Specialization;
import jdk.nashorn.internal.runtime.Symbol;
/**
* String constants used for code generation/instrumentation.
*/
@SuppressWarnings("javadoc")
public interface StringConstants {
static final String NASHORN_INTERNAL = "jdk/nashorn/internal/";
static final String OBJ_PKG = NASHORN_INTERNAL + "objects/";
static final String OBJ_ANNO_PKG = OBJ_PKG + "annotations/";
static final String RUNTIME_PKG = NASHORN_INTERNAL + "runtime/";
static final String SCRIPTS_PKG = NASHORN_INTERNAL + "scripts/";
// standard jdk types, methods
static final Type TYPE_METHODHANDLE = Type.getType(MethodHandle.class);
static final Type TYPE_METHODHANDLE_ARRAY = Type.getType(MethodHandle[].class);
static final Type TYPE_SPECIALIZATION = Type.getType(Specialization.class);
static final Type TYPE_SPECIALIZATION_ARRAY = Type.getType(Specialization[].class);
static final Type TYPE_SPECIALIZATION = Type.getType("L" + RUNTIME_PKG + "Specialization;");
static final Type TYPE_SPECIALIZATION_ARRAY = Type.getType("[L" + RUNTIME_PKG + "Specialization;");
static final Type TYPE_OBJECT = Type.getType(Object.class);
static final Type TYPE_STRING = Type.getType(String.class);
static final Type TYPE_CLASS = Type.getType(Class.class);
@ -85,13 +83,13 @@ public interface StringConstants {
static final String LIST_DESC = TYPE_LIST.getDescriptor();
// Nashorn types, methods
static final Type TYPE_ACCESSORPROPERTY = Type.getType(AccessorProperty.class);
static final Type TYPE_PROPERTYMAP = Type.getType(PropertyMap.class);
static final Type TYPE_PROTOTYPEOBJECT = Type.getType(PrototypeObject.class);
static final Type TYPE_SCRIPTFUNCTION = Type.getType(ScriptFunction.class);
static final Type TYPE_SCRIPTOBJECT = Type.getType(ScriptObject.class);
static final Type TYPE_NATIVESYMBOL = Type.getType(NativeSymbol.class);
static final Type TYPE_SYMBOL = Type.getType(Symbol.class);
static final Type TYPE_ACCESSORPROPERTY = Type.getType("L" + RUNTIME_PKG + "AccessorProperty;");
static final Type TYPE_PROPERTYMAP = Type.getType("L" + RUNTIME_PKG + "PropertyMap;");
static final Type TYPE_PROTOTYPEOBJECT = Type.getType("L" + RUNTIME_PKG + "PrototypeObject;");
static final Type TYPE_SCRIPTFUNCTION = Type.getType("L" + RUNTIME_PKG + "ScriptFunction;");
static final Type TYPE_SCRIPTOBJECT = Type.getType("L" + RUNTIME_PKG + "ScriptObject;");
static final Type TYPE_NATIVESYMBOL = Type.getType("L" + OBJ_PKG + "NativeSymbol;");
static final Type TYPE_SYMBOL = Type.getType("L" + RUNTIME_PKG + "Symbol;");
static final String PROTOTYPE_SUFFIX = "$Prototype";
static final String CONSTRUCTOR_SUFFIX = "$Constructor";

View File

@ -0,0 +1,39 @@
/*
* Copyright (c) 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package jdk.nashorn.internal.tools.nasgen;
/**
* Enum to tell where a Function or Property belongs.
* Note: keep this in sync. with jdk.nashorn.internal.objects.annotations.Where.
*/
public enum Where {
/** this means that the item belongs in the Constructor of an object */
CONSTRUCTOR,
/** this means that the item belongs in the Prototype of an object */
PROTOTYPE,
/** this means that the item belongs in the Instance of an object */
INSTANCE
}

View File

@ -38,11 +38,14 @@ JDK_CLASSES := $(call PathList, $(strip $(addprefix $(JDK_OUTPUTDIR)/modules/, \
NASHORN_JAR := $(IMAGES_OUTPUTDIR)/nashorn.jar
MODULESOURCEPATH := $(NASHORN_TOPDIR)/src/*/share/classes
# Need to use source and target 8 for nasgen to work.
$(eval $(call SetupJavaCompiler,GENERATE_NEWBYTECODE_DEBUG, \
JVM := $(JAVA), \
JAVAC := $(NEW_JAVAC), \
FLAGS := -g -source 8 -target 8 -bootclasspath $(JDK_CLASSES), \
FLAGS := -g -source 9 -target 9 -upgrademodulepath "$(JDK_OUTPUTDIR)/modules/" \
-system none -modulesourcepath "$(MODULESOURCEPATH)", \
SERVER_DIR := $(SJAVAC_SERVER_DIR), \
SERVER_JVM := $(SJAVAC_SERVER_JAVA)))
@ -52,10 +55,11 @@ $(eval $(call SetupJavaCompiler,GENERATE_NEWBYTECODE_DEBUG, \
# seamlessly.
$(eval $(call SetupJavaCompilation,jdk.scripting.nashorn, \
SETUP := GENERATE_NEWBYTECODE_DEBUG, \
MODULE := jdk.scripting.nashorn, \
SRC := $(NASHORN_TOPDIR)/src/jdk.scripting.nashorn/share/classes, \
EXCLUDE_FILES := META-INF/MANIFEST.MF, \
COPY := .properties .js, \
BIN := $(SUPPORT_OUTPUTDIR)/special_classes/jdk.scripting.nashorn/classes))
BIN := $(SUPPORT_OUTPUTDIR)/special_classes))
NASGEN_SRC := $(NASHORN_TOPDIR)/buildtools/nasgen/src
ASM_SRC := $(JDK_TOPDIR)/src/java.base/share/classes/jdk/internal/org/objectweb/asm
@ -64,24 +68,31 @@ ASM_SRC := $(JDK_TOPDIR)/src/java.base/share/classes/jdk/internal/org/objectweb/
$(eval $(call SetupJavaCompilation,BUILD_NASGEN, \
SETUP := GENERATE_OLDBYTECODE, \
SRC := $(NASGEN_SRC) $(ASM_SRC), \
BIN := $(BUILDTOOLS_OUTPUTDIR)/nasgen_classes, \
ADD_JAVAC_FLAGS := -Xbootclasspath/p:"$(SUPPORT_OUTPUTDIR)/special_classes/jdk.scripting.nashorn/classes"))
# Nasgen needs nashorn classes
$(BUILD_NASGEN): $(jdk.scripting.nashorn)
BIN := $(BUILDTOOLS_OUTPUTDIR)/nasgen_classes))
NASHORN_CLASSES_DIR := $(JDK_OUTPUTDIR)/modules/jdk.scripting.nashorn
NASGEN_RUN_FILE := $(NASHORN_CLASSES_DIR)/_the.nasgen.run
ifeq ($(BOOT_JDK_MODULAR), true)
NASGEN_OPTIONS := \
-cp $(BUILDTOOLS_OUTPUTDIR)/nasgen_classes \
-Xpatch:$(BUILDTOOLS_OUTPUTDIR)/nasgen_classes \
-XaddExports:$(subst $(SPACE),$(COMMA),$(strip \
java.base/jdk.internal.org.objectweb.asm=ALL-UNNAMED \
java.base/jdk.internal.org.objectweb.asm.util=ALL-UNNAMED \
))
else
NASGEN_OPTIONS := \
-Xbootclasspath/p:$(BUILDTOOLS_OUTPUTDIR)/nasgen_classes
endif
# Copy classes to final classes dir and run nasgen to modify classes in jdk.nashorn.internal.objects package
$(NASGEN_RUN_FILE): $(BUILD_NASGEN)
$(NASGEN_RUN_FILE): $(BUILD_NASGEN) $(jdk.scripting.nashorn)
$(ECHO) Running nasgen
$(MKDIR) -p $(@D)
$(RM) -rf $(@D)/jdk $(@D)/netscape
$(CP) -R -p $(SUPPORT_OUTPUTDIR)/special_classes/jdk.scripting.nashorn/classes/* $(@D)/
$(FIXPATH) $(JAVA) \
-Xbootclasspath/p:$(call PathList, $(BUILDTOOLS_OUTPUTDIR)/nasgen_classes \
$(SUPPORT_OUTPUTDIR)/special_classes/jdk.scripting.nashorn/classes) \
$(CP) -R -p $(SUPPORT_OUTPUTDIR)/special_classes/jdk.scripting.nashorn/* $(@D)/
$(JAVA) $(NASGEN_OPTIONS) \
jdk.nashorn.internal.tools.nasgen.Main $(@D) jdk.nashorn.internal.objects $(@D)
$(TOUCH) $@

View File

@ -35,13 +35,11 @@
<classpath>
<pathelement location="${basedir}/jcov2/lib/jcov_j2se_rt.jar"/>
<pathelement location="${basedir}/buildtools/nasgen/dist/nasgen.jar"/>
<pathelement location="${dist.dir}/nasgen.jar"/>
<pathelement path="${build.dir}/classes"/>
</classpath>
<jvmarg value="-Xbootclasspath/p:${basedir}/build/classes"/>
<arg value="${build.dir}/classes"/>
<jvmarg value="-XaddExports:${nasgen.module.imports}"/>
<arg value="${nashorn.module.classes.dir}"/>
<arg value="jdk.nashorn.internal.objects"/>
<arg value="${build.dir}/classes"/>
<arg value="${nashorn.module.classes.dir}"/>
</java>
</target>

View File

@ -32,13 +32,10 @@
<property file="${user.home}/.nashorn.project.local.properties"/>
<loadproperties srcFile="make/project.properties"/>
<path id="dist.path">
<pathelement location="${dist.dir}"/>
<path id="nashorn.jar.path">
<pathelement location="${nashorn.jar}"/>
</path>
<path id="nashorn.boot.prefix.path">
<pathelement location="${dist.jar}"/>
</path>
<property name="boot.class.path" value="-Xbootclasspath/p:${toString:nashorn.boot.prefix.path}"/>
<property name="nashorn.override.option" value="-Xpatch:${build.classes.dir}"/>
<condition property="svn.executable" value="/usr/local/bin/svn" else="svn">
<available file="/usr/local/bin/svn"/>
</condition>
@ -136,7 +133,10 @@
<target name="prepare" depends="init">
<mkdir dir="${build.dir}"/>
<mkdir dir="${build.classes.dir}"/>
<mkdir dir="${build.classes.dir}/META-INF/services"/>
<mkdir dir="${nashorn.module.classes.dir}"/>
<mkdir dir="${dynalink.module.classes.dir}"/>
<mkdir dir="${nashorn.shell.module.classes.dir}"/>
<mkdir dir="${nashorn.module.classes.dir}/META-INF/services"/>
<mkdir dir="${build.test.classes.dir}"/>
<mkdir dir="${dist.dir}"/>
<mkdir dir="${dist.javadoc.dir}"/>
@ -150,9 +150,8 @@
</target>
<target name="compile" depends="prepare" description="Compiles nashorn">
<javac srcdir="${src.dir}"
destdir="${build.classes.dir}"
classpath="${javac.classpath}"
<javac srcdir="${dynalink.module.src.dir}"
destdir="${dynalink.module.classes.dir}"
source="${javac.source}"
target="${javac.target}"
debug="${javac.debug}"
@ -163,36 +162,59 @@
<compilerarg value="-Xdiags:verbose"/>
<compilerarg value="-parameters"/>
</javac>
<copy todir="${build.classes.dir}/META-INF/services">
<fileset dir="${meta.inf.dir}/services/"/>
</copy>
<copy todir="${build.classes.dir}/jdk/nashorn/api/scripting/resources">
<javac srcdir="${nashorn.module.src.dir}"
destdir="${nashorn.module.classes.dir}"
source="${javac.source}"
target="${javac.target}"
debug="${javac.debug}"
encoding="${javac.encoding}"
includeantruntime="false" fork="true">
<compilerarg value="-Xlint:all"/>
<compilerarg value="-XDignore.symbol.file"/>
<compilerarg value="-Xdiags:verbose"/>
<compilerarg value="-parameters"/>
<compilerarg value="${nashorn.override.option}"/>
</javac>
<javac srcdir="${nashorn.shell.module.src.dir}"
destdir="${nashorn.shell.module.classes.dir}"
source="${javac.source}"
target="${javac.target}"
debug="${javac.debug}"
encoding="${javac.encoding}"
includeantruntime="false" fork="true">
<compilerarg value="-Xlint:all"/>
<compilerarg value="-XDignore.symbol.file"/>
<compilerarg value="-Xdiags:verbose"/>
<compilerarg value="-parameters"/>
<compilerarg value="${nashorn.override.option}"/>
</javac>
<!-- -Xpatch does not like module-info.class files! -->
<delete>
<fileset dir="${build.classes.dir}" includes="**/module-info.class"/>
</delete>
<copy todir="${nashorn.module.classes.dir}/jdk/nashorn/api/scripting/resources">
<fileset dir="${nashorn.module.src.dir}/jdk/nashorn/api/scripting/resources/"/>
</copy>
<copy todir="${build.classes.dir}/jdk/nashorn/internal/runtime/resources">
<copy todir="${nashorn.module.classes.dir}/jdk/nashorn/internal/runtime/resources">
<fileset dir="${nashorn.module.src.dir}/jdk/nashorn/internal/runtime/resources/"/>
</copy>
<copy todir="${build.classes.dir}/jdk/nashorn/tools/resources">
<copy todir="${nashorn.module.classes.dir}/jdk/nashorn/tools/resources">
<fileset dir="${nashorn.module.src.dir}/jdk/nashorn/tools/resources/"/>
</copy>
<copy file="${dynalink.module.src.dir}/jdk/dynalink/support/messages.properties" todir="${build.classes.dir}/jdk/dynalink/support"/>
<copy file="${nashorn.module.src.dir}/jdk/nashorn/internal/codegen/anchor.properties" todir="${build.classes.dir}/jdk/nashorn/internal/codegen"/>
<copy file="${dynalink.module.src.dir}/jdk/dynalink/support/messages.properties" todir="${dynalink.module.classes.dir}/jdk/dynalink/support"/>
<copy file="${nashorn.module.src.dir}/jdk/nashorn/internal/codegen/anchor.properties" todir="${nashorn.module.classes.dir}/jdk/nashorn/internal/codegen"/>
<echo message="version_string=${nashorn.fullversion}" file="${build.classes.dir}/jdk/nashorn/internal/runtime/resources/version.properties"/>
<echo file="${build.classes.dir}/jdk/nashorn/internal/runtime/resources/version.properties" append="true">${line.separator}</echo>
<echo message="version_short=${nashorn.version}" file="${build.classes.dir}/jdk/nashorn/internal/runtime/resources/version.properties" append="true"/>
<echo message="version_string=${nashorn.fullversion}" file="${nashorn.module.classes.dir}/jdk/nashorn/internal/runtime/resources/version.properties"/>
<echo file="${nashorn.module.classes.dir}/jdk/nashorn/internal/runtime/resources/version.properties" append="true">${line.separator}</echo>
<echo message="version_short=${nashorn.version}" file="${nashorn.module.classes.dir}/jdk/nashorn/internal/runtime/resources/version.properties" append="true"/>
</target>
<target name="jar" depends="compile, run-nasgen, generate-cc-template" description="Creates nashorn.jar" unless="compile.suppress.jar">
<jar jarfile="${dist.jar}" manifest="${meta.inf.dir}/MANIFEST.MF" index="true" filesetmanifest="merge">
<!--
Exclude jjs classes from nashorn.jar to avoid desktop dependency.
We have a test to make sure basic nashorn code has only "compact1"
dependency - except for jjs shell code which has desktop dependency.
-->
<fileset dir="${build.classes.dir}">
<exclude name="**/jdk/nashorn/tools/jjs/*"/>
</fileset>
<jar jarfile="${dynalink.jar}">
<fileset dir="${dynalink.module.classes.dir}"/>
</jar>
<jar jarfile="${nashorn.jar}" index="true" filesetmanifest="merge">
<fileset dir="${nashorn.module.classes.dir}"/>
<manifest>
<attribute name="Archiver-Version" value="n/a"/>
<attribute name="Build-Jdk" value="${java.runtime.version}"/>
@ -204,6 +226,9 @@
</section>
</manifest>
</jar>
<jar jarfile="${jjs.jar}">
<fileset dir="${nashorn.shell.module.classes.dir}"/>
</jar>
</target>
<target name="use-promoted-nashorn" depends="init">
@ -212,35 +237,10 @@
<property name="compile.suppress.jar" value="defined"/>
</target>
<target name="build-fxshell" depends="jar">
<description>Builds the javafx shell.</description>
<mkdir dir="${fxshell.classes.dir}"/>
<javac srcdir="${fxshell.dir}"
destdir="${fxshell.classes.dir}"
classpath="${dist.jar}${path.separator}${javac.classpath}"
debug="${javac.debug}"
encoding="${javac.encoding}"
includeantruntime="false">
</javac>
<jar jarfile="${fxshell.jar}" manifest="${meta.inf.dir}/MANIFEST.MF" index="true" filesetmanifest="merge">
<fileset dir="${fxshell.classes.dir}"/>
<manifest>
<attribute name="Archiver-Version" value="n/a"/>
<attribute name="Build-Jdk" value="${java.runtime.version}"/>
<attribute name="Built-By" value="n/a"/>
<attribute name="Created-By" value="Ant jar task"/>
<section name="jdk/nashorn/">
<attribute name="Implementation-Title" value="Oracle Nashorn FXShell"/>
<attribute name="Implementation-Version" value="${nashorn.version}"/>
</section>
</manifest>
</jar>
</target>
<!-- generate javadoc for all Nashorn and ASM classes -->
<target name="javadoc" depends="jar">
<javadoc destdir="${dist.javadoc.dir}" use="yes" overview="${nashorn.module.src.dir}/overview.html"
extdirs="${nashorn.ext.path}" windowtitle="${nashorn.product.name} ${nashorn.version}"
windowtitle="${nashorn.product.name} ${nashorn.version}"
additionalparam="-quiet" failonerror="true" useexternalfile="true">
<arg value="${javadoc.option}"/>
<classpath>
@ -260,7 +260,7 @@
<!-- generate javadoc for Nashorn classes -->
<target name="javadocnh" depends="jar">
<javadoc destdir="${dist.javadoc.dir}" use="yes" overview="${nashorn.module.src.dir}/overview.html"
extdirs="${nashorn.ext.path}" windowtitle="${nashorn.product.name} ${nashorn.version}"
windowtitle="${nashorn.product.name} ${nashorn.version}"
additionalparam="-quiet" failonerror="true" useexternalfile="true">
<arg value="${javadoc.option}"/>
<classpath>
@ -304,7 +304,7 @@
<!-- generate shell.html for shell tool documentation -->
<target name="shelldoc" depends="jar">
<java classname="${nashorn.shell.tool}" dir="${basedir}" output="${dist.dir}/shell.html" failonerror="true" fork="true">
<jvmarg line="${boot.class.path}"/>
<jvmarg line="${nashorn.override.option}"/>
<arg value="-scripting"/>
<arg value="docs/genshelldoc.js"/>
</java>
@ -334,10 +334,11 @@
debug="${javac.debug}"
encoding="${javac.encoding}"
includeantruntime="false" fork="true">
<compilerarg value="${boot.class.path}"/>
<compilerarg value="${nashorn.override.option}"/>
<compilerarg value="-Xlint:unchecked"/>
<compilerarg value="-Xlint:deprecation"/>
<compilerarg value="-Xdiags:verbose"/>
<compilerarg value="-XaddExports:${test.module.imports}"/>
</javac>
<copy todir="${build.test.classes.dir}/META-INF/services">
@ -379,7 +380,11 @@
<target name="generate-policy-file" depends="prepare">
<echo file="${build.dir}/nashorn.policy">
grant codeBase "file:/${toString:dist.path}/nashorn.jar" {
grant codeBase "file:/${basedir}/${dynalink.module.classes.dir}" {
permission java.security.AllPermission;
};
grant codeBase "file:/${basedir}/${nashorn.module.classes.dir}" {
permission java.security.AllPermission;
};
@ -530,7 +535,6 @@ grant codeBase "file:/${basedir}/test/script/markdown.js" {
</fileset>
<testng outputdir="${build.nosecurity.test.results.dir}/${testResultsSubDir}" classfilesetref="test.nosecurity.classes"
verbose="${testng.verbose}" haltonfailure="true" useDefaultListeners="false" listeners="${testng.listeners}" workingDir="${basedir}">
<jvmarg line="${boot.class.path}"/>
<jvmarg line="${run.test.jvmargs} -Xmx${run.test.xmx} -Dbuild.dir=${build.dir}"/>
<sysproperty key="nashorn.jar" value="${dist.dir}/nashorn.jar"/>
<propertyset>
@ -553,7 +557,6 @@ grant codeBase "file:/${basedir}/test/script/markdown.js" {
<property name="debug.test.jvmargs" value=""/>
<testng outputdir="${build.test.results.dir}/${testResultsSubDir}" classfilesetref="test.classes"
verbose="${testng.verbose}" haltonfailure="true" useDefaultListeners="false" listeners="${testng.listeners}" workingDir="${basedir}">
<jvmarg line="${boot.class.path}"/>
<jvmarg line="${run.test.jvmargs} -Xmx${run.test.xmx} ${run.test.jvmsecurityargs} -Dbuild.dir=${build.dir}"/>
<jvmarg line="${debug.test.jvmargs}"/>
<propertyset>
@ -571,7 +574,7 @@ grant codeBase "file:/${basedir}/test/script/markdown.js" {
</testng>
</target>
<target name="test" depends="prepare, javadocnh, test-pessimistic, test-optimistic"/>
<target name="test" depends="prepare, test-pessimistic, test-optimistic"/>
<target name="test-optimistic" depends="jar, -test-classes-all,-test-classes-single, check-testng, check-external-tests, compile-test, generate-policy-file" if="testng.available">
<echo message="Running test suite in OPTIMISTIC mode..."/>
@ -616,7 +619,6 @@ grant codeBase "file:/${basedir}/test/script/markdown.js" {
<testng outputdir="${build.test.results.dir}" classfilesetref="test.classes"
verbose="${testng.verbose}" haltonfailure="true" useDefaultListeners="false" listeners="${testng.listeners}" workingDir="${basedir}">
<jvmarg line="${boot.class.path}"/>
<jvmarg line="${run.test.jvmargs} -Xmx${run.test.xmx} -Dbuild.dir=${build.dir}"/>
<propertyset>
<propertyref prefix="testjfx-test-sys-prop."/>
@ -636,7 +638,6 @@ grant codeBase "file:/${basedir}/test/script/markdown.js" {
<testng outputdir="${build.test.results.dir}" classfilesetref="test.classes"
verbose="${testng.verbose}" haltonfailure="true" useDefaultListeners="false" listeners="${testng.listeners}" workingDir="${basedir}">
<jvmarg line="${boot.class.path}"/>
<jvmarg line="${run.test.jvmargs} -Xmx${run.test.xmx} ${run.test.jvmsecurityargs} -Dbuild.dir=${build.dir}"/>
<propertyset>
<propertyref prefix="testmarkdown-test-sys-prop."/>
@ -655,7 +656,6 @@ grant codeBase "file:/${basedir}/test/script/markdown.js" {
<testng outputdir="${build.test.results.dir}" classfilesetref="test.classes"
verbose="${testng.verbose}" haltonfailure="true" useDefaultListeners="false" listeners="${testng.listeners}" workingDir="${basedir}">
<jvmarg line="${boot.class.path}"/>
<jvmarg line="${run.test.jvmargs} -Xmx${run.test.xmx} ${run.test.jvmsecurityargs} -Dbuild.dir=${build.dir}"/>
<propertyset>
<propertyref prefix="nashorn."/>
@ -675,7 +675,6 @@ grant codeBase "file:/${basedir}/test/script/markdown.js" {
<target name="test262-parallel" depends="jar, check-testng, check-external-tests, compile-test, generate-policy-file" if="testng.available">
<!-- use just build.test.classes.dir to avoid referring to TestNG -->
<java classname="${parallel.test.runner}" dir="${basedir}" fork="true" failonerror="true">
<jvmarg line="${boot.class.path}"/>
<jvmarg line="${run.test.jvmargs} -Xmx${run.test.xmx} ${run.test.jvmsecurityargs} -Dbuild.dir=${build.dir}"/>
<!-- avoid too many typeinfo cache files. Each script is run only once anyway -->
<jvmarg line="-Dnashorn.typeInfo.disabled=true"/>
@ -696,7 +695,6 @@ grant codeBase "file:/${basedir}/test/script/markdown.js" {
<java classname="${parallel.test.runner}" dir="${basedir}"
failonerror="true"
fork="true">
<jvmarg line="${boot.class.path}"/>
<jvmarg line="${run.test.jvmargs} -Xmx${run.test.xmx} ${run.test.jvmsecurityargs}"/>
<classpath>
<pathelement path="${run.test.classpath}"/>
@ -715,7 +713,6 @@ grant codeBase "file:/${basedir}/test/script/markdown.js" {
<target name="run" depends="jar"
description="Run the shell with a sample script">
<java classname="${nashorn.shell.tool}" fork="true" dir="samples">
<jvmarg line="${boot.class.path}"/>
<jvmarg line="${run.test.jvmargs} -Xmx${run.test.xmx}"/>
<arg value="-dump-on-error"/>
<arg value="test.js"/>
@ -725,7 +722,6 @@ grant codeBase "file:/${basedir}/test/script/markdown.js" {
<target name="debug" depends="jar"
description="Debug the shell with a sample script">
<java classname="${nashorn.shell.tool}" fork="true" dir="samples">
<jvmarg line="${boot.class.path}"/>
<jvmarg line="${run.test.jvmargs} -Xmx${run.test.xmx}"/>
<arg value="--print-code"/>
<arg value="--verify-code"/>

View File

@ -32,7 +32,7 @@
</nbjpdastart>
<java classname="jdk.nashorn.tools.Shell" classpath="${run.test.classpath}" dir="samples" fork="true">
<jvmarg line="-Dnashorn.optimistic"/>
<jvmarg line="${boot.class.path}"/>
<jvmarg line="${nashorn.override.path}"/>
<jvmarg line="${run.test.jvmargs}"/>
<jvmarg value="-Xdebug"/>
<jvmarg value="-Xrunjdwp:transport=dt_socket,address=${jpda.address}"/>

View File

@ -31,8 +31,8 @@ jdk.jline.src.dir=../jdk/src/jdk.internal.le/share/classes
# source and target levels
build.compiler=modern
javac.source=1.8
javac.target=1.8
javac.source=1.9
javac.target=1.9
javadoc.option=-tag "implSpec:a:Implementation Requirements:"
@ -53,6 +53,12 @@ nashorn.shell.tool=jdk.nashorn.tools.Shell
# nasgen tool
nasgen.tool=jdk.nashorn.internal.tools.nasgen.Main
nasgen.module.imports=\
nasgen.module.imports=\
java.base/jdk.internal.org.objectweb.asm=ALL-UNNAMED,\
java.base/jdk.internal.org.objectweb.asm.util=ALL-UNNAMED
# parallel test runner tool
parallel.test.runner=jdk.nashorn.internal.test.framework.ParallelTestRunner
@ -70,15 +76,11 @@ build.nooptimistic.test.results.dir=${build.dir}/test/nooptimistic/reports
# This directory is removed when the project is cleaned:
dist.dir=dist
dist.jar=${dist.dir}/nashorn.jar
dynalink.jar=${dist.dir}/dynalink.jar
nashorn.jar=${dist.dir}/nashorn.jar
jjs.jar=${dist.dir}/jjs.jar
dist.javadoc.dir=${dist.dir}/javadoc
# nashorn javafx shell
fxshell.tool = jdk.nashorn.tools.FXShell
fxshell.classes.dir = ${build.dir}/fxshell/classes
fxshell.dir = tools/fxshell
fxshell.jar = ${dist.dir}/nashornfx.jar
# configuration for java flight recorder
run.test.jvmargs.jfr=-XX:+UnlockCommercialFeatures -XX:+FlightRecorder -XX:FlightRecorderOptions=defaultrecording=true,disk=true,dumponexit=true,dumponexitpath=${build.dir},stackdepth=128
@ -121,16 +123,28 @@ testng.listeners=\
javac.debug=true
javac.encoding=ascii
javac.classpath=\
${build.classes.dir}
javac.test.classpath=\
${build.classes.dir}${path.separator}\
${build.test.classes.dir}${path.separator}\
${file.reference.testng.jar}${path.separator}\
${file.reference.jcommander.jar}${path.separator}\
${file.reference.bsh.jar}${path.separator}\
${file.reference.snakeyaml.jar}
test.module.imports=\
jdk.scripting.nashorn/jdk.nashorn.internal.ir=ALL-UNNAMED,\
jdk.scripting.nashorn/jdk.nashorn.internal.codegen=ALL-UNNAMED,\
jdk.scripting.nashorn/jdk.nashorn.internal.parser=ALL-UNNAMED,\
jdk.scripting.nashorn/jdk.nashorn.internal.objects=ALL-UNNAMED,\
jdk.scripting.nashorn/jdk.nashorn.internal.runtime=ALL-UNNAMED,\
jdk.scripting.nashorn/jdk.nashorn.internal.runtime.doubleconv=ALL-UNNAMED,\
jdk.scripting.nashorn/jdk.nashorn.internal.runtime.linker=ALL-UNNAMED,\
jdk.scripting.nashorn/jdk.nashorn.internal.runtime.events=ALL-UNNAMED,\
jdk.scripting.nashorn/jdk.nashorn.internal.runtime.options=ALL-UNNAMED,\
jdk.scripting.nashorn/jdk.nashorn.internal.runtime.regexp=ALL-UNNAMED,\
jdk.scripting.nashorn/jdk.nashorn.internal.runtime.regexp.joni=ALL-UNNAMED,\
jdk.scripting.nashorn/jdk.nashorn.tools=ALL-UNNAMED,\
java.base/jdk.internal.org.objectweb.asm=ALL-UNNAMED
meta.inf.dir=${nashorn.module.src.dir}/META-INF
run.classpath=\
@ -298,8 +312,11 @@ run.test.classpath=\
${nashorn.api.tests.jar}
dynalink.module.src.dir=src/jdk.dynalink/share/classes
dynalink.module.classes.dir=${build.classes.dir}/jdk.dynalink
nashorn.module.src.dir=src/jdk.scripting.nashorn/share/classes
nashorn.module.classes.dir=${build.classes.dir}/jdk.scripting.nashorn
nashorn.shell.module.src.dir=src/jdk.scripting.nashorn.shell/share/classes
nashorn.shell.module.classes.dir=${build.classes.dir}/jdk.scripting.nashorn.shell
src.dir=${dynalink.module.src.dir}${path.separator}\
${nashorn.module.src.dir}${path.separator}\
@ -324,6 +341,8 @@ run.test.user.country=TR
run.test.jvmargs.common=\
-server \
-XaddExports:${test.module.imports} \
-Xpatch:${build.classes.dir} \
-Dfile.encoding=UTF-8 \
-Duser.language=${run.test.user.language} \
-Duser.country=${run.test.user.country} \

View File

@ -30,3 +30,5 @@
*/
print("Hello World");
var System = Java.type("java.lang.System");
print(System.getProperty("jdk.launcher.patch.0"));

View File

@ -384,7 +384,6 @@ public final class DynamicLinkerFactory {
addClasses(knownLinkerClasses, fallbackLinkers);
final List<GuardingDynamicLinker> discovered = discoverAutoLoadLinkers();
// Now, concatenate ...
final List<GuardingDynamicLinker> linkers =
new ArrayList<>(prioritizedLinkers.size() + discovered.size()

View File

@ -158,13 +158,13 @@ class CallerSensitiveDynamicMethod extends SingleDynamicMethod {
GET_LOOKUP_CONTEXT);
if(target instanceof Method) {
final MethodHandle mh = Lookup.unreflect(lookup, (Method)target);
final MethodHandle mh = Lookup.unreflectCallerSensitive(lookup, (Method)target);
if(Modifier.isStatic(((Member)target).getModifiers())) {
return StaticClassIntrospector.editStaticMethodHandle(mh);
}
return mh;
}
return StaticClassIntrospector.editConstructorMethodHandle(Lookup.unreflectConstructor(lookup,
return StaticClassIntrospector.editConstructorMethodHandle(Lookup.unreflectConstructorCallerSensitive(lookup,
(Constructor<?>)target));
}

View File

@ -84,6 +84,7 @@
package jdk.dynalink.beans;
import java.lang.reflect.Modifier;
import java.lang.reflect.Module;
import java.security.AccessControlContext;
import java.security.AccessController;
import java.security.PrivilegedAction;
@ -106,23 +107,29 @@ class CheckRestrictedPackage {
// Non-public classes are always restricted
return true;
}
final SecurityManager sm = System.getSecurityManager();
if(sm == null) {
// No further restrictions if we don't have a security manager
return false;
}
final String name = clazz.getName();
final int i = name.lastIndexOf('.');
if (i == -1) {
// Classes in default package are never restricted
return false;
}
final String pkgName = name.substring(0, i);
final Module module = clazz.getModule();
if (module != null && !module.isExported(pkgName)) {
return true;
}
final SecurityManager sm = System.getSecurityManager();
if(sm == null) {
// No further restrictions if we don't have a security manager
return false;
}
// Do a package access check from within an access control context with no permissions
try {
AccessController.doPrivileged(new PrivilegedAction<Void>() {
@Override
public Void run() {
sm.checkPackageAccess(name.substring(0, i));
sm.checkPackageAccess(pkgName);
return null;
}
}, NO_PERMISSIONS_CONTEXT);

View File

@ -87,8 +87,11 @@ import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.reflect.Constructor;
import java.lang.reflect.Executable;
import java.lang.reflect.Field;
import java.lang.reflect.Module;
import java.lang.reflect.Method;
import jdk.internal.module.Modules;
/**
* A wrapper around {@link java.lang.invoke.MethodHandles.Lookup} that masks
@ -127,6 +130,42 @@ public final class Lookup {
return unreflect(lookup, m);
}
private static boolean addModuleRead(final MethodHandles.Lookup lookup, final Executable e) {
// may be module read missing from a script class!
final Class<?> declClass = e.getDeclaringClass();
final Module from = lookup.lookupClass().getModule();
final Module to = declClass.getModule();
if (from != null && to != null) {
Modules.addReads(from, to);
return true;
}
return false;
}
/**
* Performs a {@link java.lang.invoke.MethodHandles.Lookup#unreflect(Method)}, of a caller sensitive method
* converting any encountered {@link IllegalAccessException} into an {@link IllegalAccessError}.
*
* @param lookup the lookup used to unreflect
* @param m the method to unreflect
* @return the unreflected method handle.
*/
public static MethodHandle unreflectCallerSensitive(final MethodHandles.Lookup lookup, final Method m) {
try {
return unreflect(lookup, m);
} catch (final IllegalAccessError iae) {
if (addModuleRead(lookup, m)) {
try {
return unreflect(lookup, m);
} catch (final IllegalAccessError e2) {
// fall through and throw original error as cause
}
}
throw iae;
}
}
/**
* Performs a {@link java.lang.invoke.MethodHandles.Lookup#unreflect(Method)},
* converting any encountered {@link IllegalAccessException} into an
@ -227,6 +266,29 @@ public final class Lookup {
return unreflectConstructor(lookup, c);
}
/**
* Performs a caller sensitive {@link java.lang.invoke.MethodHandles.Lookup#unreflectConstructor(Constructor)}, converting any
* encountered {@link IllegalAccessException} into an {@link IllegalAccessError}.
*
* @param lookup the lookup used to unreflect
* @param c the constructor to unreflect
* @return the unreflected constructor handle.
*/
public static MethodHandle unreflectConstructorCallerSensitive(final MethodHandles.Lookup lookup, final Constructor<?> c) {
try {
return unreflectConstructor(lookup, c);
} catch (final IllegalAccessError iae) {
if (addModuleRead(lookup, c)) {
try {
return unreflectConstructor(lookup, c);
} catch (final IllegalAccessError e2) {
// fall through and throw original error as cause
}
}
throw iae;
}
}
/**
* Performs a {@link java.lang.invoke.MethodHandles.Lookup#unreflectConstructor(Constructor)},
* converting any encountered {@link IllegalAccessException} into an

View File

@ -0,0 +1,37 @@
/*
* Copyright (c) 2015, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
module jdk.dynalink {
requires java.logging;
exports jdk.dynalink;
exports jdk.dynalink.beans;
exports jdk.dynalink.linker;
exports jdk.dynalink.linker.support;
exports jdk.dynalink.support;
uses jdk.dynalink.linker.GuardingDynamicLinkerExporter;
}

View File

@ -0,0 +1,32 @@
/*
* Copyright (c) 2014, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
module jdk.scripting.nashorn.shell {
requires java.desktop;
requires java.compiler;
requires jdk.scripting.nashorn;
requires jdk.internal.le;
}

View File

@ -1,5 +0,0 @@
Manifest-Version: 1.0
Main-Class: jdk.nashorn.tools.Shell
Name: jdk/nashorn/
Implementation-Vendor: Oracle Corporation

View File

@ -1,25 +0,0 @@
#
# Copyright (c) 2010, 2013, 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
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation. Oracle designates this
# particular file as subject to the "Classpath" exception as provided
# by Oracle in the LICENSE file that accompanied this code.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
#
jdk.nashorn.api.scripting.NashornScriptEngineFactory

View File

@ -353,6 +353,8 @@ public final class OptimisticTypesPersistence {
}
}
private static final String ANCHOR_PROPS = "anchor.properties";
/**
* In order to ensure that changes in Nashorn code don't cause corruption in the data, we'll create a
* per-code-version directory. Normally, this will create the SHA-1 digest of the nashorn.jar. In case the classpath
@ -368,7 +370,7 @@ public final class OptimisticTypesPersistence {
// getResource("OptimisticTypesPersistence.class") but behavior of getResource with regard to its willingness
// to hand out URLs to .class files is also unspecified. Therefore, the most robust way to obtain an URL to our
// package is to have a small non-class anchor file and start out from its URL.
final URL url = OptimisticTypesPersistence.class.getResource("anchor.properties");
final URL url = OptimisticTypesPersistence.class.getResource(ANCHOR_PROPS);
final String protocol = url.getProtocol();
if (protocol.equals("jar")) {
// Normal deployment: nashorn.jar
@ -391,7 +393,7 @@ public final class OptimisticTypesPersistence {
final String fileStr = url.getFile();
final String className = OptimisticTypesPersistence.class.getName();
final int packageNameLen = className.lastIndexOf('.');
final String dirStr = fileStr.substring(0, fileStr.length() - packageNameLen - 1);
final String dirStr = fileStr.substring(0, fileStr.length() - packageNameLen - 1 - ANCHOR_PROPS.length());
final File dir = new File(dirStr);
return "dev-" + new SimpleDateFormat("yyyyMMdd-HHmmss").format(new Date(getLastModifiedClassFile(
dir, 0L)));

View File

@ -36,6 +36,7 @@ import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED;
import static jdk.nashorn.internal.runtime.Source.sourceFor;
import java.io.File;
import java.io.InputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.lang.invoke.MethodHandle;
@ -490,7 +491,7 @@ public final class Context {
private static final ConcurrentMap<String, Class<?>> structureClasses = new ConcurrentHashMap<>();
/*package-private*/ @SuppressWarnings("static-method")
ClassLoader getSharedLoader() {
StructureLoader getSharedLoader() {
return sharedLoader;
}
@ -842,8 +843,8 @@ public final class Context {
@Override
public Source run() {
try {
final URL resURL = Context.class.getResource(resource);
return resURL != null ? sourceFor(srcStr, resURL) : null;
final InputStream resStream = Context.class.getResourceAsStream(resource);
return resStream != null ? sourceFor(srcStr, Source.readFully(resStream)) : null;
} catch (final IOException exp) {
return null;
}

View File

@ -30,25 +30,40 @@ import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.lang.reflect.Module;
import java.security.CodeSource;
import java.security.Permission;
import java.security.PermissionCollection;
import java.security.Permissions;
import java.security.SecureClassLoader;
import java.util.HashSet;
import java.util.Set;
import jdk.internal.module.Modules;
/**
* Superclass for Nashorn class loader classes.
*/
abstract class NashornLoader extends SecureClassLoader {
private static final String OBJECTS_PKG = "jdk.nashorn.internal.objects";
private static final String RUNTIME_PKG = "jdk.nashorn.internal.runtime";
private static final String RUNTIME_ARRAYS_PKG = "jdk.nashorn.internal.runtime.arrays";
private static final String RUNTIME_LINKER_PKG = "jdk.nashorn.internal.runtime.linker";
private static final String SCRIPTS_PKG = "jdk.nashorn.internal.scripts";
protected static final String OBJECTS_PKG = "jdk.nashorn.internal.objects";
protected static final String RUNTIME_PKG = "jdk.nashorn.internal.runtime";
protected static final String RUNTIME_ARRAYS_PKG = "jdk.nashorn.internal.runtime.arrays";
protected static final String RUNTIME_LINKER_PKG = "jdk.nashorn.internal.runtime.linker";
protected static final String SCRIPTS_PKG = "jdk.nashorn.internal.scripts";
protected static final String OBJECTS_PKG_INTERNAL = "jdk/nashorn/internal/objects";
protected static final String RUNTIME_PKG_INTERNAL = "jdk/nashorn/internal/runtime";
protected static final String RUNTIME_ARRAYS_PKG_INTERNAL = "jdk/nashorn/internal/runtime/arrays";
protected static final String RUNTIME_LINKER_PKG_INTERNAL = "jdk/nashorn/internal/runtime/linker";
protected static final String SCRIPTS_PKG_INTERNAL = "jdk/nashorn/internal/scripts";
protected static final Module nashornModule = NashornLoader.class.getModule();
private static final Permission[] SCRIPT_PERMISSIONS;
private static final Set<String> scriptsPkgSet = new HashSet<>();
static {
scriptsPkgSet.add(SCRIPTS_PKG);
/*
* Generated classes get access to runtime, runtime.linker, objects, scripts packages.
* Note that the actual scripts can not access these because Java.type, Packages
@ -69,6 +84,22 @@ abstract class NashornLoader extends SecureClassLoader {
super(parent);
}
protected static Module defineModule(final String moduleName, final ClassLoader loader) {
return Modules.defineModule(loader, moduleName, scriptsPkgSet);
}
protected static void addReadsModule(final Module from, final Module to) {
Modules.addReads(from, to);
}
protected static void addModuleExports(final Module from, final String pkg, final Module to) {
if (to == null) {
Modules.addExportsToAll(from, pkg);
} else {
Modules.addExports(from, pkg, to);
}
}
protected static void checkPackageAccess(final String name) {
final int i = name.lastIndexOf('.');
if (i != -1) {

View File

@ -25,6 +25,7 @@
package jdk.nashorn.internal.runtime;
import java.lang.reflect.Module;
import java.security.CodeSource;
import java.util.Objects;
@ -35,6 +36,8 @@ import java.util.Objects;
final class ScriptLoader extends NashornLoader {
private static final String NASHORN_PKG_PREFIX = "jdk.nashorn.internal.";
private volatile boolean structureAccessAdded;
private final Module scriptModule;
private final Context context;
/*package-private*/ Context getContext() {
@ -47,13 +50,39 @@ final class ScriptLoader extends NashornLoader {
ScriptLoader(final ClassLoader parent, final Context context) {
super(parent);
this.context = context;
// new scripts module, it's specific exports and read-edges
scriptModule = defineModule("jdk.scripting.nashorn.scripts", this);
addModuleExports(scriptModule, SCRIPTS_PKG, nashornModule);
addReadsModule(scriptModule, nashornModule);
addReadsModule(scriptModule, Object.class.getModule());
// specific exports from nashorn to new scripts module
nashornModule.addExports(OBJECTS_PKG, scriptModule);
nashornModule.addExports(RUNTIME_PKG, scriptModule);
nashornModule.addExports(RUNTIME_ARRAYS_PKG, scriptModule);
nashornModule.addExports(RUNTIME_LINKER_PKG, scriptModule);
nashornModule.addExports(SCRIPTS_PKG, scriptModule);
// nashorn needs to read scripts module methods,fields
nashornModule.addReads(scriptModule);
}
@Override
protected Class<?> loadClass(final String name, final boolean resolve) throws ClassNotFoundException {
checkPackageAccess(name);
if (name.startsWith(NASHORN_PKG_PREFIX)) {
return context.getSharedLoader().loadClass(name);
final StructureLoader sharedCl = context.getSharedLoader();
final Class<?> cl = sharedCl.loadClass(name);
if (! structureAccessAdded) {
if (cl.getClassLoader() == sharedCl) {
structureAccessAdded = true;
final Module structModule = sharedCl.getModule();
addModuleExports(structModule, SCRIPTS_PKG, scriptModule);
addReadsModule(scriptModule, structModule);
}
}
return cl;
}
return super.loadClass(name, resolve);
}

View File

@ -922,7 +922,7 @@ public final class Source implements Loggable {
return (cs != null) ? new String(readBytes(is), cs).toCharArray() : readFully(is);
}
private static char[] readFully(final InputStream is) throws IOException {
public static char[] readFully(final InputStream is) throws IOException {
return byteToCharArray(readBytes(is));
}

View File

@ -30,6 +30,7 @@ import static jdk.nashorn.internal.codegen.Compiler.binaryName;
import static jdk.nashorn.internal.codegen.CompilerConstants.JS_OBJECT_DUAL_FIELD_PREFIX;
import static jdk.nashorn.internal.codegen.CompilerConstants.JS_OBJECT_SINGLE_FIELD_PREFIX;
import java.lang.reflect.Module;
import java.security.ProtectionDomain;
import jdk.nashorn.internal.codegen.ObjectClassGenerator;
@ -40,11 +41,26 @@ final class StructureLoader extends NashornLoader {
private static final String SINGLE_FIELD_PREFIX = binaryName(SCRIPTS_PACKAGE) + '.' + JS_OBJECT_SINGLE_FIELD_PREFIX.symbolName();
private static final String DUAL_FIELD_PREFIX = binaryName(SCRIPTS_PACKAGE) + '.' + JS_OBJECT_DUAL_FIELD_PREFIX.symbolName();
private final Module structuresModule;
/**
* Constructor.
*/
StructureLoader(final ClassLoader parent) {
super(parent);
// new structures module, it's exports, read edges
structuresModule = defineModule("jdk.scripting.nashorn.structures", this);
addModuleExports(structuresModule, SCRIPTS_PKG, nashornModule);
addReadsModule(structuresModule, nashornModule);
addReadsModule(structuresModule, Object.class.getModule());
// specific exports from nashorn to the structures module
nashornModule.addExports(SCRIPTS_PKG, structuresModule);
nashornModule.addExports(RUNTIME_PKG, structuresModule);
// nashorn has to read fields from classes of the new module
nashornModule.addReads(structuresModule);
}
/**
@ -74,6 +90,10 @@ final class StructureLoader extends NashornLoader {
return isDualFieldStructure(name) || isSingleFieldStructure(name);
}
protected Module getModule() {
return structuresModule;
}
@Override
protected Class<?> findClass(final String name) throws ClassNotFoundException {
if (isDualFieldStructure(name)) {

View File

@ -51,6 +51,7 @@ import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.Module;
import java.security.AccessControlContext;
import java.security.AccessController;
import java.security.PrivilegedAction;
@ -197,12 +198,8 @@ final class JavaAdapterBytecodeGenerator {
private static final String GET_METHOD_PROPERTY_METHOD_DESCRIPTOR = Type.getMethodDescriptor(OBJECT_TYPE, SCRIPT_OBJECT_TYPE);
private static final String VOID_METHOD_DESCRIPTOR = Type.getMethodDescriptor(Type.VOID_TYPE);
// Package used when the adapter can't be defined in the adaptee's package (either because it's sealed, or because
// it's a java.* package.
private static final String ADAPTER_PACKAGE_PREFIX = "jdk/nashorn/javaadapters/";
// Class name suffix used to append to the adaptee class name, when it can be defined in the adaptee's package.
private static final String ADAPTER_CLASS_NAME_SUFFIX = "$$NashornJavaAdapter";
private static final String JAVA_PACKAGE_PREFIX = "java/";
static final String ADAPTER_PACKAGE_INTERNAL = "jdk/nashorn/javaadapters/";
static final String ADAPTER_PACKAGE = "jdk.nashorn.javaadapters";
private static final int MAX_GENERATED_TYPE_NAME_LENGTH = 255;
// Method name prefix for invoking super-methods
@ -237,6 +234,7 @@ final class JavaAdapterBytecodeGenerator {
private final Set<MethodInfo> methodInfos = new HashSet<>();
private final boolean autoConvertibleFromFunction;
private boolean hasExplicitFinalizer = false;
private final Set<Module> accessedModules = new HashSet<>();
private final ClassWriter cw;
@ -300,7 +298,7 @@ final class JavaAdapterBytecodeGenerator {
}
JavaAdapterClassLoader createAdapterClassLoader() {
return new JavaAdapterClassLoader(generatedClassName, cw.toByteArray());
return new JavaAdapterClassLoader(generatedClassName, cw.toByteArray(), accessedModules);
}
boolean isAutoConvertibleFromFunction() {
@ -314,12 +312,7 @@ final class JavaAdapterBytecodeGenerator {
final Package pkg = namingType.getPackage();
final String namingTypeName = Type.getInternalName(namingType);
final StringBuilder buf = new StringBuilder();
if (namingTypeName.startsWith(JAVA_PACKAGE_PREFIX) || pkg == null || pkg.isSealed()) {
// Can't define new classes in java.* packages
buf.append(ADAPTER_PACKAGE_PREFIX).append(namingTypeName);
} else {
buf.append(namingTypeName).append(ADAPTER_CLASS_NAME_SUFFIX);
}
buf.append(ADAPTER_PACKAGE_INTERNAL).append(namingTypeName.replace('/', '_'));
final Iterator<Class<?>> it = interfaces.iterator();
if(superType == Object.class && it.hasNext()) {
it.next(); // Skip first interface, it was used to primarily name the adapter
@ -359,7 +352,7 @@ final class JavaAdapterBytecodeGenerator {
// If the class is a SAM, allow having ScriptFunction passed as class overrides
mv.dup();
mv.instanceOf(SCRIPT_FUNCTION_TYPE);
mv.dup();
mv.dup();
mv.putstatic(generatedClassName, IS_FUNCTION_FIELD_NAME, BOOLEAN_TYPE_DESCRIPTOR);
final Label notFunction = new Label();
mv.ifeq(notFunction);
@ -379,9 +372,9 @@ final class JavaAdapterBytecodeGenerator {
private void emitInitCallThis(final InstructionAdapter mv) {
loadField(mv, GLOBAL_FIELD_NAME, SCRIPT_OBJECT_TYPE_DESCRIPTOR);
GET_CALL_THIS.invoke(mv);
if(classOverride) {
if(classOverride) {
mv.putstatic(generatedClassName, CALL_THIS_FIELD_NAME, OBJECT_TYPE_DESCRIPTOR);
} else {
} else {
// It is presumed ALOAD 0 was already executed
mv.putfield(generatedClassName, CALL_THIS_FIELD_NAME, OBJECT_TYPE_DESCRIPTOR);
}
@ -404,6 +397,14 @@ final class JavaAdapterBytecodeGenerator {
}
private boolean generateConstructors(final Constructor<?> ctor) {
for (final Class<?> pt : ctor.getParameterTypes()) {
if (pt.isPrimitive()) continue;
final Module ptMod = pt.getModule();
if (ptMod != null) {
accessedModules.add(ptMod);
}
}
if(classOverride) {
// Generate a constructor that just delegates to ctor. This is used with class-level overrides, when we want
// to create instances without further per-instance overrides.
@ -411,16 +412,16 @@ final class JavaAdapterBytecodeGenerator {
return false;
}
// Generate a constructor that delegates to ctor, but takes an additional ScriptObject parameter at the
// beginning of its parameter list.
generateOverridingConstructor(ctor, false);
// Generate a constructor that delegates to ctor, but takes an additional ScriptObject parameter at the
// beginning of its parameter list.
generateOverridingConstructor(ctor, false);
if (samName == null) {
return false;
}
// If all our abstract methods have a single name, generate an additional constructor, one that takes a
// ScriptFunction as its first parameter and assigns it as the implementation for all abstract methods.
generateOverridingConstructor(ctor, true);
}
// If all our abstract methods have a single name, generate an additional constructor, one that takes a
// ScriptFunction as its first parameter and assigns it as the implementation for all abstract methods.
generateOverridingConstructor(ctor, true);
// If the original type only has a single abstract method name, as well as a default ctor, then it can
// be automatically converted from JS function.
return ctor.getParameterTypes().length == 0;
@ -499,7 +500,7 @@ final class JavaAdapterBytecodeGenerator {
mv.iconst(1);
mv.putfield(generatedClassName, IS_FUNCTION_FIELD_NAME, BOOLEAN_TYPE_DESCRIPTOR);
mv.visitVarInsn(ALOAD, 0);
mv.visitVarInsn(ALOAD, 0);
mv.visitVarInsn(ALOAD, extraArgOffset);
emitInitCallThis(mv);
}
@ -668,7 +669,7 @@ final class JavaAdapterBytecodeGenerator {
// stack: [callThis, delegate]
mv.goTo(callCallee);
mv.visitLabel(notFunction);
} else {
} else {
// If it's not a SAM method, and the delegate is a function,
// it'll fall back to default behavior
mv.ifne(defaultBehavior);
@ -808,7 +809,7 @@ final class JavaAdapterBytecodeGenerator {
if (isVarArgCall) {
// Variable arity calls are always (Object callee, Object this, Object[] params)
callParamTypes = new Class<?>[] { Object.class, Object.class, Object[].class };
} else {
} else {
// Adjust invocation type signature for conversions we instituted in
// convertParam; also, byte and short get passed as ints.
final Class<?>[] origParamTypes = type.parameterArray();
@ -858,13 +859,13 @@ final class JavaAdapterBytecodeGenerator {
private void loadField(final InstructionAdapter mv, final String name, final String desc) {
if(classOverride) {
if(classOverride) {
mv.getstatic(generatedClassName, name, desc);
} else {
mv.visitVarInsn(ALOAD, 0);
} else {
mv.visitVarInsn(ALOAD, 0);
mv.getfield(generatedClassName, name, desc);
}
}
}
}
private static void convertReturnValue(final InstructionAdapter mv, final Class<?> origReturnType) {
if (origReturnType == void.class) {
@ -1082,6 +1083,11 @@ final class JavaAdapterBytecodeGenerator {
*/
private void gatherMethods(final Class<?> type) throws AdaptationException {
if (Modifier.isPublic(type.getModifiers())) {
final Module module = type.getModule();
if (module != null) {
accessedModules.add(module);
}
final Method[] typeMethods = type.isInterface() ? type.getMethods() : type.getDeclaredMethods();
for (final Method typeMethod: typeMethods) {
@ -1106,12 +1112,26 @@ final class JavaAdapterBytecodeGenerator {
continue;
}
for (final Class<?> pt : typeMethod.getParameterTypes()) {
if (pt.isPrimitive()) continue;
final Module ptMod = pt.getModule();
if (ptMod != null) {
accessedModules.add(ptMod);
}
}
final Class<?> rt = typeMethod.getReturnType();
if (!rt.isPrimitive()) {
final Module rtMod = rt.getModule();
if (rtMod != null) accessedModules.add(rtMod);
}
final MethodInfo mi = new MethodInfo(typeMethod);
if (Modifier.isFinal(m) || isCallerSensitive(typeMethod)) {
finalMethods.add(mi);
} else if (!finalMethods.contains(mi) && methodInfos.add(mi) && Modifier.isAbstract(m)) {
abstractMethodNames.add(mi.getName());
}
abstractMethodNames.add(mi.getName());
}
}
}
}

View File

@ -25,6 +25,7 @@
package jdk.nashorn.internal.runtime.linker;
import java.lang.reflect.Module;
import java.security.AccessControlContext;
import java.security.AccessController;
import java.security.PrivilegedAction;
@ -34,12 +35,14 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import jdk.dynalink.beans.StaticClass;
import jdk.nashorn.internal.codegen.DumpBytecode;
import jdk.nashorn.internal.runtime.Context;
import jdk.nashorn.internal.runtime.JSType;
import jdk.nashorn.internal.runtime.ScriptFunction;
import jdk.nashorn.internal.runtime.ScriptObject;
import jdk.internal.module.Modules;
/**
* This class encapsulates the bytecode of the adapter class and can be used to load it into the JVM as an actual Class.
@ -49,6 +52,12 @@ import jdk.nashorn.internal.runtime.ScriptObject;
* class are normally created by {@code JavaAdapterBytecodeGenerator}.
*/
final class JavaAdapterClassLoader {
private static final Module nashornModule = JavaAdapterClassLoader.class.getModule();
private static final Set<String> adapterPkgs = new HashSet<>();
static {
adapterPkgs.add(JavaAdapterBytecodeGenerator.ADAPTER_PACKAGE);
}
private static final AccessControlContext CREATE_LOADER_ACC_CTXT = ClassAndLoader.createPermAccCtxt("createClassLoader");
private static final AccessControlContext GET_CONTEXT_ACC_CTXT = ClassAndLoader.createPermAccCtxt(Context.NASHORN_GET_CONTEXT);
private static final Collection<String> VISIBLE_INTERNAL_CLASS_NAMES = Collections.unmodifiableCollection(new HashSet<>(
@ -56,10 +65,12 @@ final class JavaAdapterClassLoader {
private final String className;
private final byte[] classBytes;
private final Set<Module> accessedModules;
JavaAdapterClassLoader(final String className, final byte[] classBytes) {
JavaAdapterClassLoader(final String className, final byte[] classBytes, final Set<Module> accessedModules) {
this.className = className.replace('/', '.');
this.classBytes = classBytes;
this.accessedModules = accessedModules;
}
/**
@ -82,6 +93,14 @@ final class JavaAdapterClassLoader {
}, CREATE_LOADER_ACC_CTXT);
}
private static void addExports(final Module from, final String pkg, final Module to) {
if (to == null) {
Modules.addExportsToAll(from, pkg);
} else {
Modules.addExports(from, pkg, to);
}
}
// Note that the adapter class is created in the protection domain of the class/interface being
// extended/implemented, and only the privileged global setter action class is generated in the protection domain
// of Nashorn itself. Also note that the creation and loading of the global setter is deferred until it is
@ -93,6 +112,26 @@ final class JavaAdapterClassLoader {
return new SecureClassLoader(parentLoader) {
private final ClassLoader myLoader = getClass().getClassLoader();
// new adapter module
private final Module adapterModule = Modules.defineModule(this, "jdk.scripting.nashorn.javaadapters", adapterPkgs);
{
// new adapter module exports and read-edges
addExports(adapterModule, JavaAdapterBytecodeGenerator.ADAPTER_PACKAGE, null);
Modules.addReads(adapterModule, nashornModule);
Modules.addReads(adapterModule, Object.class.getModule());
for (Module mod : accessedModules) {
Modules.addReads(adapterModule, mod);
}
// specific exports from nashorn to the new adapter module
nashornModule.addExports("jdk.nashorn.internal.runtime", adapterModule);
nashornModule.addExports("jdk.nashorn.internal.runtime.linker", adapterModule);
// nashorn should be be able to read methods of classes loaded in adapter module
nashornModule.addReads(adapterModule);
}
@Override
public Class<?> loadClass(final String name, final boolean resolve) throws ClassNotFoundException {
try {

View File

@ -228,7 +228,7 @@ public final class JavaAdapterServices {
});
try {
return MethodHandles.lookup().findStatic(Class.forName(className, true, loader), "invoke",
return MethodHandles.publicLookup().findStatic(Class.forName(className, true, loader), "invoke",
MethodType.methodType(void.class, MethodHandle.class, Object.class));
} catch(final ReflectiveOperationException e) {
throw new AssertionError(e.getMessage(), e);

View File

@ -25,7 +25,9 @@
package jdk.nashorn.internal.runtime.linker;
import java.lang.invoke.MethodHandles;
import java.lang.reflect.Modifier;
import jdk.internal.module.Modules;
import jdk.dynalink.CallSiteDescriptor;
import jdk.dynalink.NamedOperation;
import jdk.dynalink.StandardOperation;
@ -87,8 +89,11 @@ final class NashornStaticClassLinker implements TypeBasedGuardingDynamicLinker {
if (NashornLinker.isAbstractClass(receiverClass)) {
// Change this link request into a link request on the adapter class.
final Object[] args = request.getArguments();
args[0] = JavaAdapterFactory.getAdapterClassFor(new Class<?>[] { receiverClass }, null,
NashornCallSiteDescriptor.getLookupInternal(request.getCallSiteDescriptor()));
final MethodHandles.Lookup lookup =
NashornCallSiteDescriptor.getLookupInternal(request.getCallSiteDescriptor());
args[0] = JavaAdapterFactory.getAdapterClassFor(new Class<?>[] { receiverClass }, null, lookup);
Modules.addReads(lookup.lookupClass().getModule(), ((StaticClass)args[0]).getRepresentedClass().getModule());
final LinkRequest adapterRequest = request.replaceArguments(request.getCallSiteDescriptor(), args);
final GuardedInvocation gi = checkNullConstructor(delegate(linkerServices, adapterRequest), receiverClass);
// Finally, modify the guard to test for the original abstract class.

View File

@ -0,0 +1,43 @@
/*
* Copyright (c) 2014, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
module jdk.scripting.nashorn {
requires java.logging;
requires public java.scripting;
requires jdk.dynalink;
exports jdk.nashorn.api.scripting;
exports jdk.nashorn.api.tree;
exports jdk.nashorn.internal.runtime to
jdk.scripting.nashorn.shell;
exports jdk.nashorn.internal.objects to
jdk.scripting.nashorn.shell;
exports jdk.nashorn.tools to
jdk.scripting.nashorn.shell;
provides javax.script.ScriptEngineFactory with jdk.nashorn.api.scripting.NashornScriptEngineFactory;
}

View File

@ -8,4 +8,4 @@ keys=intermittent randomness
groups=TEST.groups
# Minimum jtreg version
requiredVersion=4.1 b12
requiredVersion=4.2 b01

View File

@ -51,7 +51,7 @@ if (! new File(jjsCmd).isFile()) {
jjsCmd = javahome + "/bin/jjs";
jjsCmd = jjsCmd.toString().replace(/\//g, File.separator);
}
jjsCmd += " -J-Xbootclasspath/p:" + nashornJar;
jjsCmd += " -J-Xpatch:" + nashornJar;
$ENV.PWD=System.getProperty("user.dir") // to avoid RE on Cygwin
$EXEC(jjsCmd, "var x = Object.create(null);\nx;\nprint('PASSED');\nexit(0)");

View File

@ -27,7 +27,6 @@
* @test
* @option -Dnashorn.mirror.always=false
* @fork
* @run
*/
// basic API exercise checks
@ -120,18 +119,25 @@ printValue(this);
var Source = Java.type("jdk.nashorn.internal.runtime.Source");
var Context = Java.type("jdk.nashorn.internal.runtime.Context");
var ThrowErrorManager = Java.type("jdk.nashorn.internal.runtime.Context.ThrowErrorManager");
var contextCls = java.lang.Class.forName("jdk.nashorn.internal.runtime.Context");
var sourceCls = Source.class;
var errorMgrCls = Java.type("jdk.nashorn.internal.runtime.ErrorManager").class;
var booleanCls = Java.type("java.lang.Boolean").TYPE;
var stringCls = Java.type("java.lang.String").class;
// private compile method of Context class
var compileMethod = Context.class.getDeclaredMethod("compile",
var compileMethod = contextCls.getDeclaredMethod("compile",
sourceCls, errorMgrCls, booleanCls, booleanCls);
compileMethod.accessible = true;
var scriptCls = compileMethod.invoke(Context.context,
Source.sourceFor("test", "print('hello')"),
new Context.ThrowErrorManager(), false, false);
var getContextMethod = contextCls.getMethod("getContext");
getContextMethod.accessible = true;
var sourceForMethod = sourceCls.getMethod("sourceFor", stringCls, stringCls);
var scriptCls = compileMethod.invoke(getContextMethod.invoke(null),
sourceForMethod.invoke(null, "test", "print('hello')"),
ThrowErrorManager.class.newInstance(), false, false);
var SCRIPT_CLASS_NAME_PREFIX = "jdk.nashorn.internal.scripts.Script$";
print("script class name pattern satisfied? " +

View File

@ -25,13 +25,32 @@
* JDK-8044851: nashorn properties leak memory
*
* @test
* @run
* @option -Dnashorn.debug=true
* @fork
*/
var Property = Java.type("jdk.nashorn.internal.runtime.Property");
var PropertyMap = Java.type("jdk.nashorn.internal.runtime.PropertyMap");
// Class objects
var objectCls = Java.type("java.lang.Object").class;
var propertyCls = Property.class;
var propertyMapCls = PropertyMap.class;
// Method objects
var findPropertyMethod = propertyMapCls.getMethod("findProperty", objectCls);
var getKeyMethod = propertyCls.getMethod("getKey");
var isSpillMethod = propertyCls.getMethod("isSpill");
var getSlotMethod = propertyCls.getMethod("getSlot");
function printProperty(value, property) {
print(value, property.getKey(), property.isSpill() ? "spill" : "field", property.getSlot());
print(value, getKeyMethod.invoke(property),
isSpillMethod.invoke(property) ? "spill" : "field", getSlotMethod.invoke(property));
}
function findProperty(obj, name) {
var map = Debug.map(obj);
return findPropertyMethod.invoke(map, name);
}
var obj = {}, i, name;
@ -39,7 +58,7 @@ var obj = {}, i, name;
for (i = 0; i < 8; ++i) {
name = 'property' + i;
obj[name] = 'a' + i;
printProperty(obj[name], Debug.map(obj).findProperty(name));
printProperty(obj[name], findProperty(obj, name));
}
print();
@ -51,14 +70,14 @@ for (i = 0; i < 8; ++i) {
for (i = 0; i < 8; ++i) {
name = 'property' + i;
obj[name] = 'b' + i;
printProperty(obj[name], Debug.map(obj).findProperty(name));
printProperty(obj[name], findProperty(obj, name));
}
print();
for (i = 0; i < 8; ++i) {
name = 'property' + i;
Object.defineProperty(obj, name, {get: function() {return i;}, set: function(v) {}, configurable: true});
printProperty(obj[name], Debug.map(obj).findProperty(name));
printProperty(obj[name], findProperty(obj, name));
}
print();
@ -70,7 +89,7 @@ for (i = 0; i < 8; ++i) {
for (i = 0; i < 8; ++i) {
name = 'property' + i;
obj[name] = 'c' + i;
printProperty(obj[name], Debug.map(obj).findProperty(name));
printProperty(obj[name], findProperty(obj, name));
}
print();
@ -82,12 +101,12 @@ for (i = 7; i > -1; --i) {
for (i = 0; i < 8; ++i) {
name = 'property' + i;
obj[name] = 'd' + i;
printProperty(obj[name], Debug.map(obj).findProperty(name));
printProperty(obj[name], findProperty(obj, name));
}
print();
for (i = 0; i < 8; ++i) {
name = 'property' + i;
Object.defineProperty(obj, name, {get: function() {return i;}, set: function(v) {}});
printProperty(obj[name], Debug.map(obj).findProperty(name));
printProperty(obj[name], findProperty(obj, name));
}

View File

@ -27,6 +27,7 @@
* @test
* @run
* @option -Dnashorn.debug=true
* @option -scripting
* @fork
*/
@ -36,10 +37,27 @@ var objectType = Java.type("java.lang.Object");
var Context = Java.type("jdk.nashorn.internal.runtime.Context");
var JSType = Java.type("jdk.nashorn.internal.runtime.JSType");
var Property = Java.type("jdk.nashorn.internal.runtime.Property");
var PropertyMap = Java.type("jdk.nashorn.internal.runtime.PropertyMap");
var context = Context.getContext();
var dualFields = context.useDualFields();
var optimisticTypes = context.getEnv()._optimistic_types;
// Class objects
var objectCls = Java.type("java.lang.Object").class;
var contextCls = Context.class;
var JSTypeCls = JSType.class;
var propertyCls = Property.class;
var propertyMapCls = PropertyMap.class;
// Method objects
var getContextMethod = contextCls.getMethod("getContext");
var isRepresentableAsIntMethod = JSTypeCls.getMethod("isRepresentableAsInt", java.lang.Double.TYPE);
var hasDualFieldsMethod = propertyCls.getMethod("hasDualFields");
var getTypeMethod = propertyCls.getMethod("getType");
var findPropertyMethod = propertyMapCls.getMethod("findProperty", objectCls);
var context = getContextMethod.invoke(null);
var useDualFieldsMethod = contextCls.getMethod("useDualFields");
var dualFields = useDualFieldsMethod.invoke(context);
var optimisticTypes = $OPTIONS._optimistic_types;
if (dualFields != optimisticTypes) {
throw new Error("Wrong dual fields setting");
@ -51,11 +69,11 @@ function testMap(obj) {
Object.defineProperty(obj, "z", {value: 0.5});
var map = Debug.map(obj);
for (var key in obj) {
var prop = map.findProperty(key);
if (prop.hasDualFields() !== dualFields) {
var prop = findPropertyMethod.invoke(map, key);
if (hasDualFieldsMethod.invoke(prop) !== dualFields) {
throw new Error("Wrong property flags: " + prop);
}
if (prop.getType() != getExpectedType(obj[key])) {
if (getTypeMethod.invoke(prop) != getExpectedType(obj[key])) {
throw new Error("Wrong property type: " + prop.getType() + " // " + getExpectedType(obj[key]));
}
}
@ -66,7 +84,7 @@ function getExpectedType(value) {
return objectType.class;
}
if (typeof value === "number") {
return JSType.isRepresentableAsInt(value) ? intType.class : doubleType.class;
return isRepresentableAsIntMethod.invoke(null, value) ? intType.class : doubleType.class;
}
return objectType.class;
}

View File

@ -543,11 +543,14 @@ var spill = {
var AccessorProperty = Java.type("jdk.nashorn.internal.runtime.AccessorProperty");
var SpillProperty = Java.type("jdk.nashorn.internal.runtime.SpillProperty");
var PropertyMap = Java.type("jdk.nashorn.internal.runtime.PropertyMap");
var findPropertyMethod = PropertyMap.class.getMethod("findProperty", java.lang.Object.class);
Assert.assertTrue(Object.keys(fields).length === 3);
Assert.assertTrue(Debug.map(fields).findProperty("p0").getClass() === AccessorProperty.class);
Assert.assertTrue(Debug.map(fields).findProperty("p2").getClass() === AccessorProperty.class);
Assert.assertTrue(findPropertyMethod.invoke(Debug.map(fields), "p0").getClass() === AccessorProperty.class);
Assert.assertTrue(findPropertyMethod.invoke(Debug.map(fields), "p2").getClass() === AccessorProperty.class);
Assert.assertTrue(Object.keys(spill).length === 500);
Assert.assertTrue(Debug.map(spill).findProperty("p0").getClass() === SpillProperty.class);
Assert.assertTrue(Debug.map(spill).findProperty("p499").getClass() === SpillProperty.class);
Assert.assertTrue(findPropertyMethod.invoke(Debug.map(spill), "p0").getClass() === SpillProperty.class);
Assert.assertTrue(findPropertyMethod.invoke(Debug.map(spill), "p499").getClass() === SpillProperty.class);

View File

@ -6,9 +6,9 @@ java.lang.ClassNotFoundException: java.lang.String
[JavaClass java.util.ArrayList]
[JavaClass java.lang.String]
[JavaPackage java.lang.String]
[JavaClass jdk.nashorn.javaadapters.java.util.ArrayList]
[JavaClass jdk.nashorn.javaadapters.java.util.ArrayList]
[JavaClass jdk.nashorn.javaadapters.java.io.File]
[JavaClass jdk.nashorn.javaadapters.java_util_ArrayList]
[JavaClass jdk.nashorn.javaadapters.java_util_ArrayList]
[JavaClass jdk.nashorn.javaadapters.java_io_File]
TypeError: Java.extend needs Java types as its arguments. in <eval> at line number 1
java.lang.NullPointerException
java.lang.ClassNotFoundException: java.lang.NullPointerException

View File

@ -1,7 +1,7 @@
class javax.script.ScriptContext$$NashornJavaAdapter
class jdk.nashorn.javaadapters.javax_script_ScriptContext
TypeError: Java.extend needs at least one type argument. in nashorn:mozilla_compat.js at line number 39
class jdk.nashorn.javaadapters.java.util.ArrayList
class jdk.nashorn.javaadapters.java.util.ArrayList
class jdk.nashorn.javaadapters.java_util_ArrayList
class jdk.nashorn.javaadapters.java_util_ArrayList
[JavaClass java.lang.Integer]
TypeError: [object JavaPackage] is not a Java class in nashorn:mozilla_compat.js at line number 373 at column number 16
[JavaClass java.util.HashSet]

View File

@ -30,6 +30,7 @@
* @option -Dnashorn.debug=true
* @option --log=recompile:quiet
* @option --optimistic-types=true
* @run
*/
print(Debug);

View File

@ -29,6 +29,7 @@
* @option -Dnashorn.debug=true
* @option --log=recompile:quiet
* @option --optimistic-types=true
* @run
*/
var forName = java.lang.Class["forName(String)"];

View File

@ -69,6 +69,7 @@ import static org.testng.Assert.assertTrue;
* Bignum class tests
*
* @test
* @modules jdk.scripting.nashorn/jdk.nashorn.internal.runtime.doubleconv
* @run testng jdk.nashorn.internal.runtime.doubleconv.test.BignumTest
*/
@SuppressWarnings("javadoc")

View File

@ -44,6 +44,7 @@ import static org.testng.Assert.assertTrue;
* DiyFp class tests
*
* @test
* @modules jdk.scripting.nashorn/jdk.nashorn.internal.runtime.doubleconv
* @run testng jdk.nashorn.internal.runtime.doubleconv.test.DiyFpTest
*/
@SuppressWarnings("javadoc")

View File

@ -32,6 +32,7 @@ import org.testng.annotations.Test;
* Joni coverage tests
*
* @test
* @modules jdk.scripting.nashorn/jdk.nashorn.internal.runtime.regexp.joni
* @run testng jdk.nashorn.internal.runtime.regexp.joni.test.JoniTest
*/
@SuppressWarnings("javadoc")

View File

@ -38,6 +38,7 @@ import org.testng.annotations.Test;
* Basic tests for the JDK based RegExp implementation.
*
* @test
* @modules jdk.scripting.nashorn/jdk.nashorn.internal.runtime.regexp
* @run testng jdk.nashorn.internal.runtime.regexp.test.JdkRegExpTest
*/
public class JdkRegExpTest {

View File

@ -34,6 +34,7 @@ import org.testng.annotations.Test;
* Tests for JSType methods.
*
* @test
* @modules jdk.scripting.nashorn/jdk.nashorn.internal.runtime
* @run testng jdk.nashorn.internal.runtime.test.ConsStringTest
*/
public class ConsStringTest {

View File

@ -44,6 +44,9 @@ import org.testng.annotations.Test;
* Basic Context API tests.
*
* @test
* @modules jdk.scripting.nashorn/jdk.nashorn.internal.runtime
* jdk.scripting.nashorn/jdk.nashorn.internal.runtime.options
* jdk.scripting.nashorn/jdk.nashorn.internal.objects
* @run testng jdk.nashorn.internal.runtime.test.ContextTest
*/
@SuppressWarnings("javadoc")

View File

@ -42,6 +42,7 @@ import org.testng.annotations.Test;
* JDK-8044518: Ensure exceptions related to optimistic recompilation are not serializable
*
* @test
* @modules jdk.scripting.nashorn/jdk.nashorn.internal.runtime
* @run testng jdk.nashorn.internal.runtime.test.ExceptionsNotSerializable
*/
@SuppressWarnings("javadoc")

View File

@ -47,6 +47,10 @@ import org.testng.annotations.Test;
* @test
* @bug 8078414
* @summary Test that arbitrary classes can't be converted to mirror's superclasses/interfaces.
* @modules jdk.scripting.nashorn/jdk.nashorn.internal.runtime
* @modules jdk.scripting.nashorn/jdk.nashorn.internal.runtime.linker
* @modules jdk.scripting.nashorn/jdk.nashorn.internal.runtime.options
* @modules jdk.scripting.nashorn/jdk.nashorn.internal.objects
* @run testng jdk.nashorn.internal.runtime.test.JDK_8078414_Test
*/
public class JDK_8078414_Test {

View File

@ -37,6 +37,7 @@ import org.testng.annotations.Test;
* Tests for JSType methods.
*
* @test
* @modules jdk.scripting.nashorn/jdk.nashorn.internal.runtime
* @run testng jdk.nashorn.internal.runtime.test.JSTypeTest
*/
public class JSTypeTest {

View File

@ -176,8 +176,6 @@ public final class ScriptRunnable extends AbstractScriptRunnable implements ITes
final List<String> cmd = new ArrayList<>();
cmd.add(System.getProperty("java.home") + separator + "bin" + separator + "java");
// cmd.add("-Djava.ext.dirs=dist");
cmd.add("-Xbootclasspath/a:dist/nashorn.jar");
for (final String str : forkJVMOptions) {
if(!str.isEmpty()) {
cmd.add(str);