Merge
authorjwilhelm
Fri, 17 Nov 2017 02:50:51 +0100
changeset 47910 b4d2929683b6
parent 47909 da4fb7d2f917 (current diff)
parent 47826 7f06714e7f0b (diff)
child 47911 af1361361585
Merge
--- a/make/Help.gmk	Fri Nov 17 11:08:44 2017 +0530
+++ b/make/Help.gmk	Fri Nov 17 02:50:51 2017 +0100
@@ -36,15 +36,18 @@
 	$(info =====================)
 	$(info )
 	$(info Common make targets)
-	$(info $(_) make [default]         # Compile all modules in langtools, hotspot, jdk, jaxws,)
-	$(info $(_)                        # jaxp and corba, and create a runnable "exploded" image)
-	$(info $(_) make all               # Compile everything, all repos, docs and images)
-	$(info $(_) make images            # Create complete jdk and jre images (alias for product-images))
-	$(info $(_) make <name>-image      # Build just the image (jdk, jre, test, docs etc))
+	$(info $(_) make [default]         # Compile all modules and create a runnable "exploded")
+	$(info $(_)                        # image (alias for jdk or exploded-image))
+	$(info $(_) make all               # Create all images: product, test, docs)
+	$(info $(_)                        # (alias for all-images))
+	$(info $(_) make images            # Create complete jdk and jre images)
+	$(info $(_)                        # (alias for product-images))
+	$(info $(_) make <name>-image      # Build just the image for any of: )
+	$(info $(_)                        # jdk, jre, test, docs, symbols, profiles)
 	$(info $(_) make <phase>           # Build the specified phase and everything it depends on)
 	$(info $(_)                        # (gensrc, java, copy, libs, launchers, gendata, rmic))
-	$(info $(_) make *-only            # Applies to most targets and disables compling the)
-	$(info $(_)                        # dependencies for the target. This is faster but may)
+	$(info $(_) make *-only            # Applies to most targets and disables building the)
+	$(info $(_)                        # dependencies for that target. This is faster but may)
 	$(info $(_)                        # result in incorrect build results!)
 	$(info $(_) make docs              # Create all docs)
 	$(info $(_) make docs-jdk-api      # Create just JDK javadocs)
@@ -74,7 +77,7 @@
 	$(info $(_) make hotspot           # Build all of hotspot)
 	$(info $(_) make hotspot-<variant> # Build just the specified jvm variant)
 	$(info $(_) make hotspot-gensrc    # Only build the gensrc part of hotspot)
-	$(info $(_) make hotspot-<variant>-<phase> # Build the specified phase for the specified module)
+	$(info $(_) make hotspot-<variant>-<phase> # Build the specified phase for the variant)
 	$(info )
 	$(info Targets for specific modules)
 	$(info $(_) make <module>          # Build <module> and everything it depends on)
--- a/make/common/MakeBase.gmk	Fri Nov 17 11:08:44 2017 +0530
+++ b/make/common/MakeBase.gmk	Fri Nov 17 02:50:51 2017 +0100
@@ -473,15 +473,32 @@
     $(subst $(SPACE),?,$(strip $1))
 
 ################################################################################
-# Make directory without forking mkdir if not needed
+# Make directory without forking mkdir if not needed.
+#
+# If a directory with an encoded space is provided, the wildcard function
+# sometimes returns false answers (typically if the dir existed when the
+# makefile was parsed, but was deleted by a previous rule). In that case, always
+# call mkdir regardless of what wildcard says.
+#
 # 1: List of directories to create
 MakeDir = \
     $(strip \
-        $(eval MakeDir_dirs_to_make := $(strip $(foreach d, $1, $(if $(wildcard $d), , \
-            "$(call DecodeSpace, $d)")))) \
+        $(eval MakeDir_dirs_to_make := $(strip $(foreach d, $1, \
+          $(if $(findstring ?, $d), '$(call DecodeSpace, $d)', \
+            $(if $(wildcard $d), , $d) \
+          ) \
+        ))) \
         $(if $(MakeDir_dirs_to_make), $(shell $(MKDIR) -p $(MakeDir_dirs_to_make))) \
     )
 
+# Make directory for target file. Should handle spaces in filenames. Just
+# calling $(call MakeDir $(@D)) will not work if the directory contains a space
+# and the target file already exists. In that case, the target file will have
+# its wildcard ? resolved and the $(@D) will evaluate each space separated dir
+# part on its own.
+MakeTargetDir = \
+    $(call MakeDir, $(dir $(call EncodeSpace, $@)))
+
 ################################################################################
 # Assign a variable only if it is empty
 # Param 1 - Variable to assign
@@ -499,7 +516,7 @@
   # If the source and target parent directories are the same, recursive copy doesn't work
   # so we fall back on regular copy, which isn't preserving symlinks.
   define install-file
-	$(call MakeDir, $(@D))
+	$(call MakeTargetDir)
 	$(RM) '$(call DecodeSpace, $@)'
 	if [ '$(call DecodeSpace, $(dir $@))' != \
 	    '$(call DecodeSpace, $(dir $(call EncodeSpace, $<)))' ]; then \
@@ -526,21 +543,21 @@
   # If copying a soft link to a directory, need to delete the target first to avoid
   # weird errors.
   define install-file
-	$(call MakeDir, $(@D))
+	$(call MakeTargetDir)
 	$(RM) '$(call DecodeSpace, $@)'
 	$(CP) -fRP '$(call DecodeSpace, $<)' '$(call DecodeSpace, $@)'
 	if [ -n "`$(XATTR) -ls '$(call DecodeSpace, $@)'`" ]; then $(XATTR) -cs '$(call DecodeSpace, $@)'; fi
   endef
 else
   define install-file
-	$(call MakeDir, $(@D))
+	$(call MakeTargetDir)
 	$(CP) -fP '$(call DecodeSpace, $<)' '$(call DecodeSpace, $@)'
   endef
 endif
 
 # Variant of install file that does not preserve symlinks
 define install-file-nolink
-	$(call MakeDir, $(@D))
+	$(call MakeTargetDir)
 	$(CP) -f '$(call DecodeSpace, $<)' '$(call DecodeSpace, $@)'
 endef
 
@@ -590,13 +607,13 @@
 # careful when using this on Windows since the symlink created is only valid in
 # the unix emulation environment.
 define link-file-relative
-	$(call MakeDir, $(@D))
+	$(call MakeTargetDir)
 	$(RM) '$(call DecodeSpace, $@)'
 	$(LN) -s '$(call DecodeSpace, $(call RelativePath, $<, $(@D)))' '$(call DecodeSpace, $@)'
 endef
 
 define link-file-absolute
-	$(call MakeDir, $(@D))
+	$(call MakeTargetDir)
 	$(RM) '$(call DecodeSpace, $@)'
 	$(LN) -s '$(call DecodeSpace, $<)' '$(call DecodeSpace, $@)'
 endef
--- a/make/nashorn/build.xml	Fri Nov 17 11:08:44 2017 +0530
+++ b/make/nashorn/build.xml	Fri Nov 17 02:50:51 2017 +0100
@@ -830,8 +830,8 @@
 
     <!-- underscorejs -->
     <mkdir dir="${test.external.dir}/underscore"/>
-    <get src="http://underscorejs.org/underscore.js" dest="${test.external.dir}/underscore" skipexisting="true" ignoreerrors="true"/>
-    <get src="http://underscorejs.org/underscore-min.js" dest="${test.external.dir}/underscore" skipexisting="true" ignoreerrors="true"/>
+    <get src="http://underscorejs.org/underscore.js" dest="${test.external.dir}/underscore" skipexisting="true" ignoreerrors="true" tryGzipEncoding="true"/>
+    <get src="http://underscorejs.org/underscore-min.js" dest="${test.external.dir}/underscore" skipexisting="true" ignoreerrors="true" tryGzipEncoding="true"/>
 
     <!-- yui -->
     <mkdir dir="${test.external.dir}/yui"/>
--- a/src/java.base/share/classes/java/lang/invoke/BoundMethodHandle.java	Fri Nov 17 11:08:44 2017 +0530
+++ b/src/java.base/share/classes/java/lang/invoke/BoundMethodHandle.java	Fri Nov 17 02:50:51 2017 +0100
@@ -25,25 +25,21 @@
 
 package java.lang.invoke;
 
-import jdk.internal.loader.BootLoader;
-import jdk.internal.org.objectweb.asm.ClassWriter;
-import jdk.internal.org.objectweb.asm.FieldVisitor;
-import jdk.internal.org.objectweb.asm.MethodVisitor;
 import jdk.internal.vm.annotation.Stable;
 import sun.invoke.util.ValueConversions;
-import sun.invoke.util.Wrapper;
 
-import java.lang.invoke.LambdaForm.NamedFunction;
-import java.lang.invoke.MethodHandles.Lookup;
-import java.lang.reflect.Field;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-import java.util.function.Function;
+import java.util.ArrayList;
+import java.util.List;
 
 import static java.lang.invoke.LambdaForm.BasicType;
 import static java.lang.invoke.LambdaForm.BasicType.*;
-import static java.lang.invoke.MethodHandleStatics.*;
-import static jdk.internal.org.objectweb.asm.Opcodes.*;
+import static java.lang.invoke.LambdaForm.BasicType.V_TYPE_NUM;
+import static java.lang.invoke.LambdaForm.BasicType.V_TYPE_NUM;
+import static java.lang.invoke.LambdaForm.BasicType.V_TYPE_NUM;
+import static java.lang.invoke.MethodHandles.Lookup.IMPL_LOOKUP;
+import static java.lang.invoke.MethodHandleNatives.Constants.*;
+import static java.lang.invoke.MethodHandleStatics.newInternalError;
+import static java.lang.invoke.MethodHandleStatics.uncaughtException;
 
 /**
  * The flavor of method handle which emulates an invoke instruction
@@ -56,7 +52,7 @@
 
     /*non-public*/ BoundMethodHandle(MethodType type, LambdaForm form) {
         super(type, form);
-        assert(speciesData() == speciesData(form));
+        assert(speciesData() == speciesDataFor(form));
     }
 
     //
@@ -70,13 +66,13 @@
             case L_TYPE:
                 return bindSingle(type, form, x);  // Use known fast path.
             case I_TYPE:
-                return (BoundMethodHandle) SpeciesData.EMPTY.extendWith(I_TYPE).constructor().invokeBasic(type, form, ValueConversions.widenSubword(x));
+                return (BoundMethodHandle) SPECIALIZER.topSpecies().extendWith(I_TYPE_NUM).factory().invokeBasic(type, form, ValueConversions.widenSubword(x));
             case J_TYPE:
-                return (BoundMethodHandle) SpeciesData.EMPTY.extendWith(J_TYPE).constructor().invokeBasic(type, form, (long) x);
+                return (BoundMethodHandle) SPECIALIZER.topSpecies().extendWith(J_TYPE_NUM).factory().invokeBasic(type, form, (long) x);
             case F_TYPE:
-                return (BoundMethodHandle) SpeciesData.EMPTY.extendWith(F_TYPE).constructor().invokeBasic(type, form, (float) x);
+                return (BoundMethodHandle) SPECIALIZER.topSpecies().extendWith(F_TYPE_NUM).factory().invokeBasic(type, form, (float) x);
             case D_TYPE:
-                return (BoundMethodHandle) SpeciesData.EMPTY.extendWith(D_TYPE).constructor().invokeBasic(type, form, (double) x);
+                return (BoundMethodHandle) SPECIALIZER.topSpecies().extendWith(D_TYPE_NUM).factory().invokeBasic(type, form, (double) x);
             default : throw newInternalError("unexpected xtype: " + xtype);
             }
         } catch (Throwable t) {
@@ -98,6 +94,7 @@
     BoundMethodHandle bindArgumentL(int pos, Object value) {
         return editor().bindArgumentL(this, pos, value);
     }
+
     /*non-public*/
     BoundMethodHandle bindArgumentI(int pos, int value) {
         return editor().bindArgumentI(this, pos, value);
@@ -114,7 +111,6 @@
     BoundMethodHandle bindArgumentD(int pos, double value) {
         return editor().bindArgumentD(this, pos, value);
     }
-
     @Override
     BoundMethodHandle rebind() {
         if (!tooComplex()) {
@@ -137,28 +133,29 @@
     static BoundMethodHandle makeReinvoker(MethodHandle target) {
         LambdaForm form = DelegatingMethodHandle.makeReinvokerForm(
                 target, MethodTypeForm.LF_REBIND,
-                Species_L.SPECIES_DATA, Species_L.SPECIES_DATA.getterFunction(0));
+                Species_L.BMH_SPECIES, Species_L.BMH_SPECIES.getterFunction(0));
         return Species_L.make(target.type(), form, target);
     }
 
     /**
-     * Return the {@link SpeciesData} instance representing this BMH species. All subclasses must provide a
+     * Return the {@link BoundMethodHandle.SpeciesData} instance representing this BMH species. All subclasses must provide a
      * static field containing this value, and they must accordingly implement this method.
      */
-    /*non-public*/ abstract SpeciesData speciesData();
+    /*non-public*/ abstract BoundMethodHandle.SpeciesData speciesData();
 
-    /*non-public*/ static SpeciesData speciesData(LambdaForm form) {
+    /*non-public*/ static BoundMethodHandle.SpeciesData speciesDataFor(LambdaForm form) {
         Object c = form.names[0].constraint;
-        if (c instanceof SpeciesData)
+        if (c instanceof SpeciesData) {
             return (SpeciesData) c;
+        }
         // if there is no BMH constraint, then use the null constraint
-        return SpeciesData.EMPTY;
+        return SPECIALIZER.topSpecies();
     }
 
     /**
      * Return the number of fields in this BMH.  Equivalent to speciesData().fieldCount().
      */
-    /*non-public*/ abstract int fieldCount();
+    /*non-public*/ final int fieldCount() { return speciesData().fieldCount(); }
 
     @Override
     Object internalProperties() {
@@ -167,7 +164,7 @@
 
     @Override
     final String internalValues() {
-        int count = speciesData().fieldCount();
+        int count = fieldCount();
         if (count == 1) {
             return "[" + arg(0) + "]";
         }
@@ -180,17 +177,18 @@
 
     /*non-public*/ final Object arg(int i) {
         try {
-            switch (speciesData().fieldType(i)) {
-            case L_TYPE: return          speciesData().getters[i].invokeBasic(this);
-            case I_TYPE: return (int)    speciesData().getters[i].invokeBasic(this);
-            case J_TYPE: return (long)   speciesData().getters[i].invokeBasic(this);
-            case F_TYPE: return (float)  speciesData().getters[i].invokeBasic(this);
-            case D_TYPE: return (double) speciesData().getters[i].invokeBasic(this);
+            Class<?> fieldType = speciesData().fieldTypes().get(i);
+            switch (BasicType.basicType(fieldType)) {
+                case L_TYPE: return          speciesData().getter(i).invokeBasic(this);
+                case I_TYPE: return (int)    speciesData().getter(i).invokeBasic(this);
+                case J_TYPE: return (long)   speciesData().getter(i).invokeBasic(this);
+                case F_TYPE: return (float)  speciesData().getter(i).invokeBasic(this);
+                case D_TYPE: return (double) speciesData().getter(i).invokeBasic(this);
             }
         } catch (Throwable ex) {
             throw uncaughtException(ex);
         }
-        throw new InternalError("unexpected type: " + speciesData().typeChars+"."+i);
+        throw new InternalError("unexpected type: " + speciesData().key()+"."+i);
     }
 
     //
@@ -210,20 +208,21 @@
 
     private  // make it private to force users to access the enclosing class first
     static final class Species_L extends BoundMethodHandle {
+
         final Object argL0;
+
         private Species_L(MethodType mt, LambdaForm lf, Object argL0) {
             super(mt, lf);
             this.argL0 = argL0;
         }
+
         @Override
         /*non-public*/ SpeciesData speciesData() {
-            return SPECIES_DATA;
+            return BMH_SPECIES;
         }
-        @Override
-        /*non-public*/ int fieldCount() {
-            return 1;
-        }
-        /*non-public*/ static final SpeciesData SPECIES_DATA = new SpeciesData("L", Species_L.class);
+
+        /*non-public*/ static @Stable SpeciesData BMH_SPECIES;
+
         /*non-public*/ static BoundMethodHandle make(MethodType mt, LambdaForm lf, Object argL0) {
             return new Species_L(mt, lf, argL0);
         }
@@ -234,7 +233,7 @@
         @Override
         /*non-public*/ final BoundMethodHandle copyWithExtendL(MethodType mt, LambdaForm lf, Object narg) {
             try {
-                return (BoundMethodHandle) SPECIES_DATA.extendWith(L_TYPE).constructor().invokeBasic(mt, lf, argL0, narg);
+                return (BoundMethodHandle) BMH_SPECIES.extendWith(L_TYPE_NUM).factory().invokeBasic(mt, lf, argL0, narg);
             } catch (Throwable ex) {
                 throw uncaughtException(ex);
             }
@@ -242,7 +241,7 @@
         @Override
         /*non-public*/ final BoundMethodHandle copyWithExtendI(MethodType mt, LambdaForm lf, int narg) {
             try {
-                return (BoundMethodHandle) SPECIES_DATA.extendWith(I_TYPE).constructor().invokeBasic(mt, lf, argL0, narg);
+                return (BoundMethodHandle) BMH_SPECIES.extendWith(I_TYPE_NUM).factory().invokeBasic(mt, lf, argL0, narg);
             } catch (Throwable ex) {
                 throw uncaughtException(ex);
             }
@@ -250,7 +249,7 @@
         @Override
         /*non-public*/ final BoundMethodHandle copyWithExtendJ(MethodType mt, LambdaForm lf, long narg) {
             try {
-                return (BoundMethodHandle) SPECIES_DATA.extendWith(J_TYPE).constructor().invokeBasic(mt, lf, argL0, narg);
+                return (BoundMethodHandle) BMH_SPECIES.extendWith(J_TYPE_NUM).factory().invokeBasic(mt, lf, argL0, narg);
             } catch (Throwable ex) {
                 throw uncaughtException(ex);
             }
@@ -258,7 +257,7 @@
         @Override
         /*non-public*/ final BoundMethodHandle copyWithExtendF(MethodType mt, LambdaForm lf, float narg) {
             try {
-                return (BoundMethodHandle) SPECIES_DATA.extendWith(F_TYPE).constructor().invokeBasic(mt, lf, argL0, narg);
+                return (BoundMethodHandle) BMH_SPECIES.extendWith(F_TYPE_NUM).factory().invokeBasic(mt, lf, argL0, narg);
             } catch (Throwable ex) {
                 throw uncaughtException(ex);
             }
@@ -266,7 +265,7 @@
         @Override
         /*non-public*/ final BoundMethodHandle copyWithExtendD(MethodType mt, LambdaForm lf, double narg) {
             try {
-                return (BoundMethodHandle) SPECIES_DATA.extendWith(D_TYPE).constructor().invokeBasic(mt, lf, argL0, narg);
+                return (BoundMethodHandle) BMH_SPECIES.extendWith(D_TYPE_NUM).factory().invokeBasic(mt, lf, argL0, narg);
             } catch (Throwable ex) {
                 throw uncaughtException(ex);
             }
@@ -277,601 +276,177 @@
     // BMH species meta-data
     //
 
-    /**
-     * Meta-data wrapper for concrete BMH types.
-     * Each BMH type corresponds to a given sequence of basic field types (LIJFD).
-     * The fields are immutable; their values are fully specified at object construction.
-     * Each BMH type supplies an array of getter functions which may be used in lambda forms.
-     * A BMH is constructed by cloning a shorter BMH and adding one or more new field values.
-     * The shortest possible BMH has zero fields; its class is SimpleMethodHandle.
-     * BMH species are not interrelated by subtyping, even though it would appear that
-     * a shorter BMH could serve as a supertype of a longer one which extends it.
-     */
-    static class SpeciesData {
-        private final String                             typeChars;
-        private final BasicType[]                        typeCodes;
-        private final Class<? extends BoundMethodHandle> clazz;
-        // Bootstrapping requires circular relations MH -> BMH -> SpeciesData -> MH
-        // Therefore, we need a non-final link in the chain.  Use array elements.
-        @Stable private final MethodHandle[]             constructor;
-        @Stable private final MethodHandle[]             getters;
-        @Stable private final NamedFunction[]            nominalGetters;
-        @Stable private final SpeciesData[]              extensions;
+    /*non-public*/
+    static final class SpeciesData extends ClassSpecializer<BoundMethodHandle, String, SpeciesData>.SpeciesData {
+        // This array is filled in lazily, as new species come into being over time.
+        @Stable final private SpeciesData[] extensions = new SpeciesData[ARG_TYPE_LIMIT];
 
-        /*non-public*/ int fieldCount() {
-            return typeCodes.length;
-        }
-        /*non-public*/ BasicType fieldType(int i) {
-            return typeCodes[i];
-        }
-        /*non-public*/ char fieldTypeChar(int i) {
-            return typeChars.charAt(i);
+        public SpeciesData(Specializer outer, String key) {
+            outer.super(key);
         }
-        String fieldSignature() {
-            return typeChars;
-        }
-        public Class<? extends BoundMethodHandle> fieldHolder() {
-            return clazz;
-        }
-        public String toString() {
-            return "SpeciesData<"+fieldSignature()+">";
+
+        @Override
+        protected String deriveClassName() {
+            String typeString = deriveTypeString();
+            if (typeString.isEmpty()) {
+                return SimpleMethodHandle.class.getName();
+            }
+            return BoundMethodHandle.class.getName() + "$Species_" + typeString;
         }
 
-        /**
-         * Return a {@link LambdaForm.Name} containing a {@link LambdaForm.NamedFunction} that
-         * represents a MH bound to a generic invoker, which in turn forwards to the corresponding
-         * getter.
-         */
-        NamedFunction getterFunction(int i) {
-            NamedFunction nf = nominalGetters[i];
-            assert(nf.memberDeclaringClassOrNull() == fieldHolder());
-            assert(nf.returnType() == fieldType(i));
-            return nf;
-        }
-
-        NamedFunction[] getterFunctions() {
-            return nominalGetters;
-        }
-
-        MethodHandle[] getterHandles() { return getters; }
-
-        MethodHandle constructor() {
-            return constructor[0];
+        @Override
+        protected List<Class<?>> deriveFieldTypes(String key) {
+            ArrayList<Class<?>> types = new ArrayList<>(key.length());
+            for (int i = 0; i < key.length(); i++) {
+                types.add(basicType(key.charAt(i)).basicTypeClass());
+            }
+            return types;
         }
 
-        static final SpeciesData EMPTY = new SpeciesData("", BoundMethodHandle.class);
-
-        SpeciesData(String types, Class<? extends BoundMethodHandle> clazz) {
-            this.typeChars = types;
-            this.typeCodes = basicTypes(types);
-            this.clazz = clazz;
-            if (!INIT_DONE) {
-                this.constructor = new MethodHandle[1];  // only one ctor
-                this.getters = new MethodHandle[types.length()];
-                this.nominalGetters = new NamedFunction[types.length()];
-            } else {
-                this.constructor = Factory.makeCtors(clazz, types, null);
-                this.getters = Factory.makeGetters(clazz, types, null);
-                this.nominalGetters = Factory.makeNominalGetters(types, null, this.getters);
-            }
-            this.extensions = new SpeciesData[ARG_TYPE_LIMIT];
+        @Override
+        protected String deriveTypeString() {
+            // (If/when we have to add nominal types, just inherit the more complex default.)
+            return key();
         }
 
-        private void initForBootstrap() {
-            assert(!INIT_DONE);
-            if (constructor() == null) {
-                String types = typeChars;
-                CACHE.put(types, this);
-                Factory.makeCtors(clazz, types, this.constructor);
-                Factory.makeGetters(clazz, types, this.getters);
-                Factory.makeNominalGetters(types, this.nominalGetters, this.getters);
+        @Override
+        protected MethodHandle deriveTransformHelper(MemberName transform, int whichtm) {
+            if (whichtm == Specializer.TN_COPY_NO_EXTEND) {
+                return factory();
+            } else if (whichtm < ARG_TYPE_LIMIT) {
+                return extendWith((byte) whichtm).factory();
+            } else {
+                throw newInternalError("bad transform");
             }
         }
 
-        private static final ConcurrentMap<String, SpeciesData> CACHE = new ConcurrentHashMap<>();
-        private static final boolean INIT_DONE;  // set after <clinit> finishes...
-
-        SpeciesData extendWith(byte type) {
-            return extendWith(BasicType.basicType(type));
-        }
-
-        SpeciesData extendWith(BasicType type) {
-            int ord = type.ordinal();
-            SpeciesData d = extensions[ord];
-            if (d != null)  return d;
-            extensions[ord] = d = get(typeChars+type.basicTypeChar());
-            return d;
+        @Override
+        protected <X> List<X> deriveTransformHelperArguments(MemberName transform, int whichtm, List<X> args, List<X> fields) {
+            assert(verifyTHAargs(transform, whichtm, args, fields));
+            // The rule is really simple:  Keep the first two arguments
+            // the same, then put in the fields, then put any other argument.
+            args.addAll(2, fields);
+            return args;
         }
 
-        private static SpeciesData get(String types) {
-            return CACHE.computeIfAbsent(types, new Function<String, SpeciesData>() {
-                @Override
-                public SpeciesData apply(String types) {
-                    Class<? extends BoundMethodHandle> bmhcl = Factory.getConcreteBMHClass(types);
-                    // SpeciesData instantiation may throw VirtualMachineError because of
-                    // code cache overflow...
-                    SpeciesData speciesData = new SpeciesData(types, bmhcl);
-                    // CHM.computeIfAbsent ensures only one SpeciesData will be set
-                    // successfully on the concrete BMH class if ever
-                    Factory.setSpeciesDataToConcreteBMHClass(bmhcl, speciesData);
-                    // the concrete BMH class is published via SpeciesData instance
-                    // returned here only after it's SPECIES_DATA field is set
-                    return speciesData;
-                }
-            });
-        }
-
-        /**
-         * This is to be called when assertions are enabled. It checks whether SpeciesData for all of the statically
-         * defined species subclasses of BoundMethodHandle has been added to the SpeciesData cache. See below in the
-         * static initializer for
-         */
-        static boolean speciesDataCachePopulated() {
-            Class<BoundMethodHandle> rootCls = BoundMethodHandle.class;
-            for (Class<?> c : rootCls.getDeclaredClasses()) {
-                if (rootCls.isAssignableFrom(c)) {
-                    final Class<? extends BoundMethodHandle> cbmh = c.asSubclass(BoundMethodHandle.class);
-                    SpeciesData d = Factory.getSpeciesDataFromConcreteBMHClass(cbmh);
-                    assert(d != null) : cbmh.getName();
-                    assert(d.clazz == cbmh);
-                    assert(CACHE.get(d.typeChars) == d);
-                }
+        private boolean verifyTHAargs(MemberName transform, int whichtm, List<?> args, List<?> fields) {
+            assert(transform == Specializer.BMH_TRANSFORMS.get(whichtm));
+            assert(args.size() == transform.getMethodType().parameterCount());
+            assert(fields.size() == this.fieldCount());
+            final int MH_AND_LF = 2;
+            if (whichtm == Specializer.TN_COPY_NO_EXTEND) {
+                assert(transform.getMethodType().parameterCount() == MH_AND_LF);
+            } else if (whichtm < ARG_TYPE_LIMIT) {
+                assert(transform.getMethodType().parameterCount() == MH_AND_LF+1);
+                final BasicType type = basicType((byte) whichtm);
+                assert(transform.getParameterTypes()[MH_AND_LF] == type.basicTypeClass());
+            } else {
+                return false;
             }
             return true;
         }
 
-        static {
-            // Pre-fill the BMH species-data cache with EMPTY and all BMH's inner subclasses.
-            EMPTY.initForBootstrap();
-            Species_L.SPECIES_DATA.initForBootstrap();
-            // check that all static SpeciesData instances have been initialized
-            assert speciesDataCachePopulated();
-            // Note:  Do not simplify this, because INIT_DONE must not be
-            // a compile-time constant during bootstrapping.
-            INIT_DONE = Boolean.TRUE;
+        /*non-public*/ SpeciesData extendWith(byte typeNum) {
+            SpeciesData sd = extensions[typeNum];
+            if (sd != null)  return sd;
+            sd = SPECIALIZER.findSpecies(key() + BasicType.basicType(typeNum).basicTypeChar());
+            extensions[typeNum] = sd;
+            return sd;
         }
     }
 
-    static SpeciesData getSpeciesData(String types) {
-        return SpeciesData.get(types);
+    /*non-public*/
+    static final Specializer SPECIALIZER = new Specializer();
+    static {
+        SimpleMethodHandle.BMH_SPECIES = BoundMethodHandle.SPECIALIZER.findSpecies("");
+        Species_L.BMH_SPECIES = BoundMethodHandle.SPECIALIZER.findSpecies("L");
     }
 
-    /**
-     * Generation of concrete BMH classes.
-     *
-     * A concrete BMH species is fit for binding a number of values adhering to a
-     * given type pattern. Reference types are erased.
-     *
-     * BMH species are cached by type pattern.
-     *
-     * A BMH species has a number of fields with the concrete (possibly erased) types of
-     * bound values. Setters are provided as an API in BMH. Getters are exposed as MHs,
-     * which can be included as names in lambda forms.
-     */
-    static class Factory {
+    /*non-public*/
+    static final class Specializer extends ClassSpecializer<BoundMethodHandle, String, SpeciesData> {
+
+        private static final MemberName SPECIES_DATA_ACCESSOR;
 
-        private static final String JLO_SIG  = "Ljava/lang/Object;";
-        private static final String MH       = "java/lang/invoke/MethodHandle";
-        private static final String MH_SIG   = "L"+MH+";";
-        private static final String BMH      = "java/lang/invoke/BoundMethodHandle";
-        private static final String BMH_NAME = "java.lang.invoke.BoundMethodHandle";
-        private static final String BMH_SIG  = "L"+BMH+";";
-        private static final String SPECIES_DATA     = "java/lang/invoke/BoundMethodHandle$SpeciesData";
-        private static final String SPECIES_DATA_SIG = "L"+SPECIES_DATA+";";
-        private static final String STABLE_SIG       = "Ljdk/internal/vm/annotation/Stable;";
+        static {
+            try {
+                SPECIES_DATA_ACCESSOR = IMPL_LOOKUP.resolveOrFail(REF_invokeVirtual, BoundMethodHandle.class,
+                        "speciesData", MethodType.methodType(BoundMethodHandle.SpeciesData.class));
+            } catch (ReflectiveOperationException ex) {
+                throw newInternalError("Bootstrap link error", ex);
+            }
+        }
 
-        private static final String SPECIES_PREFIX_NAME = "Species_";
-        private static final String SPECIES_PREFIX_PATH = BMH + "$" + SPECIES_PREFIX_NAME;
-        private static final String SPECIES_CLASS_PREFIX = BMH_NAME + "$" + SPECIES_PREFIX_NAME;
-
-        private static final String BMHSPECIES_DATA_EWI_SIG = "(B)" + SPECIES_DATA_SIG;
-        private static final String MYSPECIES_DATA_SIG = "()" + SPECIES_DATA_SIG;
-        private static final String INT_SIG    = "()I";
+        private Specializer() {
+            super(  // Reified type parameters:
+                    BoundMethodHandle.class, String.class, BoundMethodHandle.SpeciesData.class,
+                    // Principal constructor type:
+                    MethodType.methodType(void.class, MethodType.class, LambdaForm.class),
+                    // Required linkage between class and species:
+                    SPECIES_DATA_ACCESSOR,
+                    "BMH_SPECIES",
+                    BMH_TRANSFORMS);
+        }
 
-        private static final String SIG_INCIPIT = "(Ljava/lang/invoke/MethodType;Ljava/lang/invoke/LambdaForm;";
+        @Override
+        protected String topSpeciesKey() {
+            return "";
+        }
 
-        private static final String[] E_THROWABLE = new String[] { "java/lang/Throwable" };
-
-        private static final ConcurrentMap<String, Class<? extends BoundMethodHandle>> CLASS_CACHE = new ConcurrentHashMap<>();
+        @Override
+        protected BoundMethodHandle.SpeciesData newSpeciesData(String key) {
+            return new BoundMethodHandle.SpeciesData(this, key);
+        }
 
-        /**
-         * Get a concrete subclass of BMH for a given combination of bound types.
-         *
-         * @param types the type signature, wherein reference types are erased to 'L'
-         * @return the concrete BMH class
-         */
-        static Class<? extends BoundMethodHandle> getConcreteBMHClass(String types) {
-            // CHM.computeIfAbsent ensures generateConcreteBMHClass is called
-            // only once per key.
-            return CLASS_CACHE.computeIfAbsent(
-                types, new Function<String, Class<? extends BoundMethodHandle>>() {
-                    @Override
-                    public Class<? extends BoundMethodHandle> apply(String types) {
-                        String shortTypes = LambdaForm.shortenSignature(types);
-                        String className = SPECIES_CLASS_PREFIX + shortTypes;
-                        Class<?> c = BootLoader.loadClassOrNull(className);
-                        if (TRACE_RESOLVE) {
-                            System.out.println("[BMH_RESOLVE] " + shortTypes +
-                                    (c != null ? " (success)" : " (fail)") );
-                        }
-                        if (c != null) {
-                            return c.asSubclass(BoundMethodHandle.class);
-                        } else {
-                            // Not pregenerated, generate the class
-                            return generateConcreteBMHClass(shortTypes, types);
-                        }
-                    }
-                });
+        static final List<MemberName> BMH_TRANSFORMS;
+        static final int TN_COPY_NO_EXTEND = V_TYPE_NUM;
+        static {
+            final Class<BoundMethodHandle> BMH = BoundMethodHandle.class;
+            // copyWithExtendLIJFD + copyWith
+            try {
+                BMH_TRANSFORMS = List.of(
+                        IMPL_LOOKUP.resolveOrFail(REF_invokeVirtual, BMH, "copyWithExtendL", MethodType.methodType(BMH, MethodType.class, LambdaForm.class, Object.class)),
+                        IMPL_LOOKUP.resolveOrFail(REF_invokeVirtual, BMH, "copyWithExtendI", MethodType.methodType(BMH, MethodType.class, LambdaForm.class, int.class)),
+                        IMPL_LOOKUP.resolveOrFail(REF_invokeVirtual, BMH, "copyWithExtendJ", MethodType.methodType(BMH, MethodType.class, LambdaForm.class, long.class)),
+                        IMPL_LOOKUP.resolveOrFail(REF_invokeVirtual, BMH, "copyWithExtendF", MethodType.methodType(BMH, MethodType.class, LambdaForm.class, float.class)),
+                        IMPL_LOOKUP.resolveOrFail(REF_invokeVirtual, BMH, "copyWithExtendD", MethodType.methodType(BMH, MethodType.class, LambdaForm.class, double.class)),
+                        IMPL_LOOKUP.resolveOrFail(REF_invokeVirtual, BMH, "copyWith", MethodType.methodType(BMH, MethodType.class, LambdaForm.class))
+                );
+            } catch (ReflectiveOperationException ex) {
+                throw newInternalError("Failed resolving copyWith methods", ex);
+            }
+
+            // as it happens, there is one transform per BasicType including V_TYPE
+            assert(BMH_TRANSFORMS.size() == TYPE_LIMIT);
         }
 
         /**
-         * Generate a concrete subclass of BMH for a given combination of bound types.
-         *
-         * A concrete BMH species adheres to the following schema:
+         * Generation of concrete BMH classes.
          *
-         * <pre>
-         * class Species_[[types]] extends BoundMethodHandle {
-         *     [[fields]]
-         *     final SpeciesData speciesData() { return SpeciesData.get("[[types]]"); }
-         * }
-         * </pre>
-         *
-         * The {@code [[types]]} signature is precisely the string that is passed to this
-         * method.
-         *
-         * The {@code [[fields]]} section consists of one field definition per character in
-         * the type signature, adhering to the naming schema described in the definition of
-         * {@link #makeFieldName}.
-         *
-         * For example, a concrete BMH species for two reference and one integral bound values
-         * would have the following shape:
+         * A concrete BMH species is fit for binding a number of values adhering to a
+         * given type pattern. Reference types are erased.
          *
-         * <pre>
-         * class BoundMethodHandle { ... private static
-         * final class Species_LLI extends BoundMethodHandle {
-         *     final Object argL0;
-         *     final Object argL1;
-         *     final int argI2;
-         *     private Species_LLI(MethodType mt, LambdaForm lf, Object argL0, Object argL1, int argI2) {
-         *         super(mt, lf);
-         *         this.argL0 = argL0;
-         *         this.argL1 = argL1;
-         *         this.argI2 = argI2;
-         *     }
-         *     final SpeciesData speciesData() { return SPECIES_DATA; }
-         *     final int fieldCount() { return 3; }
-         *     &#64;Stable static SpeciesData SPECIES_DATA; // injected afterwards
-         *     static BoundMethodHandle make(MethodType mt, LambdaForm lf, Object argL0, Object argL1, int argI2) {
-         *         return new Species_LLI(mt, lf, argL0, argL1, argI2);
-         *     }
-         *     final BoundMethodHandle copyWith(MethodType mt, LambdaForm lf) {
-         *         return new Species_LLI(mt, lf, argL0, argL1, argI2);
-         *     }
-         *     final BoundMethodHandle copyWithExtendL(MethodType mt, LambdaForm lf, Object narg) {
-         *         return SPECIES_DATA.extendWith(L_TYPE).constructor().invokeBasic(mt, lf, argL0, argL1, argI2, narg);
-         *     }
-         *     final BoundMethodHandle copyWithExtendI(MethodType mt, LambdaForm lf, int narg) {
-         *         return SPECIES_DATA.extendWith(I_TYPE).constructor().invokeBasic(mt, lf, argL0, argL1, argI2, narg);
-         *     }
-         *     final BoundMethodHandle copyWithExtendJ(MethodType mt, LambdaForm lf, long narg) {
-         *         return SPECIES_DATA.extendWith(J_TYPE).constructor().invokeBasic(mt, lf, argL0, argL1, argI2, narg);
-         *     }
-         *     final BoundMethodHandle copyWithExtendF(MethodType mt, LambdaForm lf, float narg) {
-         *         return SPECIES_DATA.extendWith(F_TYPE).constructor().invokeBasic(mt, lf, argL0, argL1, argI2, narg);
-         *     }
-         *     public final BoundMethodHandle copyWithExtendD(MethodType mt, LambdaForm lf, double narg) {
-         *         return SPECIES_DATA.extendWith(D_TYPE).constructor().invokeBasic(mt, lf, argL0, argL1, argI2, narg);
-         *     }
-         * }
-         * </pre>
+         * BMH species are cached by type pattern.
          *
-         * @param types the type signature, wherein reference types are erased to 'L'
-         * @return the generated concrete BMH class
+         * A BMH species has a number of fields with the concrete (possibly erased) types of
+         * bound values. Setters are provided as an API in BMH. Getters are exposed as MHs,
+         * which can be included as names in lambda forms.
          */
-        static Class<? extends BoundMethodHandle> generateConcreteBMHClass(String shortTypes,
-                String types) {
-            final String className  = speciesInternalClassName(shortTypes);
-            byte[] classFile = generateConcreteBMHClassBytes(shortTypes, types, className);
-
-            // load class
-            InvokerBytecodeGenerator.maybeDump(className, classFile);
-            Class<? extends BoundMethodHandle> bmhClass =
-                UNSAFE.defineClass(className, classFile, 0, classFile.length,
-                                   BoundMethodHandle.class.getClassLoader(), null)
-                    .asSubclass(BoundMethodHandle.class);
-
-            return bmhClass;
-        }
-
-        static String speciesInternalClassName(String shortTypes) {
-            return SPECIES_PREFIX_PATH + shortTypes;
-        }
-
-        static byte[] generateConcreteBMHClassBytes(final String shortTypes,
-                final String types, final String className) {
-            final String sourceFile = SPECIES_PREFIX_NAME + shortTypes;
-
-            final ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS + ClassWriter.COMPUTE_FRAMES);
-            final int NOT_ACC_PUBLIC = 0;  // not ACC_PUBLIC
-            cw.visit(V1_6, NOT_ACC_PUBLIC + ACC_FINAL + ACC_SUPER, className, null, BMH, null);
-            cw.visitSource(sourceFile, null);
-
-            // emit static types and SPECIES_DATA fields
-            FieldVisitor fw = cw.visitField(NOT_ACC_PUBLIC + ACC_STATIC, "SPECIES_DATA", SPECIES_DATA_SIG, null, null);
-            fw.visitAnnotation(STABLE_SIG, true);
-            fw.visitEnd();
-
-            // emit bound argument fields
-            for (int i = 0; i < types.length(); ++i) {
-                final char t = types.charAt(i);
-                final String fieldName = makeFieldName(types, i);
-                final String fieldDesc = t == 'L' ? JLO_SIG : String.valueOf(t);
-                cw.visitField(ACC_FINAL, fieldName, fieldDesc, null, null).visitEnd();
-            }
-
-            MethodVisitor mv;
-
-            // emit constructor
-            mv = cw.visitMethod(ACC_PRIVATE, "<init>", makeSignature(types, true), null, null);
-            mv.visitCode();
-            mv.visitVarInsn(ALOAD, 0); // this
-            mv.visitVarInsn(ALOAD, 1); // type
-            mv.visitVarInsn(ALOAD, 2); // form
-
-            mv.visitMethodInsn(INVOKESPECIAL, BMH, "<init>", makeSignature("", true), false);
-
-            for (int i = 0, j = 0; i < types.length(); ++i, ++j) {
-                // i counts the arguments, j counts corresponding argument slots
-                char t = types.charAt(i);
-                mv.visitVarInsn(ALOAD, 0);
-                mv.visitVarInsn(typeLoadOp(t), j + 3); // parameters start at 3
-                mv.visitFieldInsn(PUTFIELD, className, makeFieldName(types, i), typeSig(t));
-                if (t == 'J' || t == 'D') {
-                    ++j; // adjust argument register access
-                }
-            }
-
-            mv.visitInsn(RETURN);
-            mv.visitMaxs(0, 0);
-            mv.visitEnd();
-
-            // emit implementation of speciesData()
-            mv = cw.visitMethod(NOT_ACC_PUBLIC + ACC_FINAL, "speciesData", MYSPECIES_DATA_SIG, null, null);
-            mv.visitCode();
-            mv.visitFieldInsn(GETSTATIC, className, "SPECIES_DATA", SPECIES_DATA_SIG);
-            mv.visitInsn(ARETURN);
-            mv.visitMaxs(0, 0);
-            mv.visitEnd();
-
-            // emit implementation of fieldCount()
-            mv = cw.visitMethod(NOT_ACC_PUBLIC + ACC_FINAL, "fieldCount", INT_SIG, null, null);
-            mv.visitCode();
-            int fc = types.length();
-            if (fc <= (ICONST_5 - ICONST_0)) {
-                mv.visitInsn(ICONST_0 + fc);
-            } else {
-                mv.visitIntInsn(SIPUSH, fc);
-            }
-            mv.visitInsn(IRETURN);
-            mv.visitMaxs(0, 0);
-            mv.visitEnd();
-            // emit make()  ...factory method wrapping constructor
-            mv = cw.visitMethod(NOT_ACC_PUBLIC + ACC_STATIC, "make", makeSignature(types, false), null, null);
-            mv.visitCode();
-            // make instance
-            mv.visitTypeInsn(NEW, className);
-            mv.visitInsn(DUP);
-            // load mt, lf
-            mv.visitVarInsn(ALOAD, 0);  // type
-            mv.visitVarInsn(ALOAD, 1);  // form
-            // load factory method arguments
-            for (int i = 0, j = 0; i < types.length(); ++i, ++j) {
-                // i counts the arguments, j counts corresponding argument slots
-                char t = types.charAt(i);
-                mv.visitVarInsn(typeLoadOp(t), j + 2); // parameters start at 3
-                if (t == 'J' || t == 'D') {
-                    ++j; // adjust argument register access
-                }
-            }
-
-            // finally, invoke the constructor and return
-            mv.visitMethodInsn(INVOKESPECIAL, className, "<init>", makeSignature(types, true), false);
-            mv.visitInsn(ARETURN);
-            mv.visitMaxs(0, 0);
-            mv.visitEnd();
-
-            // emit copyWith()
-            mv = cw.visitMethod(NOT_ACC_PUBLIC + ACC_FINAL, "copyWith", makeSignature("", false), null, null);
-            mv.visitCode();
-            // make instance
-            mv.visitTypeInsn(NEW, className);
-            mv.visitInsn(DUP);
-            // load mt, lf
-            mv.visitVarInsn(ALOAD, 1);
-            mv.visitVarInsn(ALOAD, 2);
-            // put fields on the stack
-            emitPushFields(types, className, mv);
-            // finally, invoke the constructor and return
-            mv.visitMethodInsn(INVOKESPECIAL, className, "<init>", makeSignature(types, true), false);
-            mv.visitInsn(ARETURN);
-            mv.visitMaxs(0, 0);
-            mv.visitEnd();
-
-            // for each type, emit copyWithExtendT()
-            for (BasicType type : BasicType.ARG_TYPES) {
-                int ord = type.ordinal();
-                char btChar = type.basicTypeChar();
-                mv = cw.visitMethod(NOT_ACC_PUBLIC + ACC_FINAL, "copyWithExtend" + btChar, makeSignature(String.valueOf(btChar), false), null, E_THROWABLE);
-                mv.visitCode();
-                // return SPECIES_DATA.extendWith(t).constructor().invokeBasic(mt, lf, argL0, ..., narg)
-                // obtain constructor
-                mv.visitFieldInsn(GETSTATIC, className, "SPECIES_DATA", SPECIES_DATA_SIG);
-                int iconstInsn = ICONST_0 + ord;
-                assert(iconstInsn <= ICONST_5);
-                mv.visitInsn(iconstInsn);
-                mv.visitMethodInsn(INVOKEVIRTUAL, SPECIES_DATA, "extendWith", BMHSPECIES_DATA_EWI_SIG, false);
-                mv.visitMethodInsn(INVOKEVIRTUAL, SPECIES_DATA, "constructor", "()" + MH_SIG, false);
-                // load mt, lf
-                mv.visitVarInsn(ALOAD, 1);
-                mv.visitVarInsn(ALOAD, 2);
-                // put fields on the stack
-                emitPushFields(types, className, mv);
-                // put narg on stack
-                mv.visitVarInsn(typeLoadOp(btChar), 3);
-                // finally, invoke the constructor and return
-                mv.visitMethodInsn(INVOKEVIRTUAL, MH, "invokeBasic", makeSignature(types + btChar, false), false);
-                mv.visitInsn(ARETURN);
-                mv.visitMaxs(0, 0);
-                mv.visitEnd();
-            }
-
-            cw.visitEnd();
-
-            return cw.toByteArray();
-        }
-
-        private static int typeLoadOp(char t) {
-            switch (t) {
-            case 'L': return ALOAD;
-            case 'I': return ILOAD;
-            case 'J': return LLOAD;
-            case 'F': return FLOAD;
-            case 'D': return DLOAD;
-            default : throw newInternalError("unrecognized type " + t);
+        class Factory extends ClassSpecializer<BoundMethodHandle, String, BoundMethodHandle.SpeciesData>.Factory {
+            @Override
+            protected String chooseFieldName(Class<?> type, int index) {
+                return "arg" + super.chooseFieldName(type, index);
             }
         }
 
-        private static void emitPushFields(String types, String className, MethodVisitor mv) {
-            for (int i = 0; i < types.length(); ++i) {
-                char tc = types.charAt(i);
-                mv.visitVarInsn(ALOAD, 0);
-                mv.visitFieldInsn(GETFIELD, className, makeFieldName(types, i), typeSig(tc));
-            }
-        }
-
-        static String typeSig(char t) {
-            return t == 'L' ? JLO_SIG : String.valueOf(t);
-        }
-
-        //
-        // Getter MH generation.
-        //
-
-        private static MethodHandle makeGetter(Class<?> cbmhClass, String types, int index) {
-            String fieldName = makeFieldName(types, index);
-            Class<?> fieldType = Wrapper.forBasicType(types.charAt(index)).primitiveType();
-            try {
-                return LOOKUP.findGetter(cbmhClass, fieldName, fieldType);
-            } catch (NoSuchFieldException | IllegalAccessException e) {
-                throw newInternalError(e);
-            }
+        @Override
+        protected Factory makeFactory() {
+            return new Factory();
         }
-
-        static MethodHandle[] makeGetters(Class<?> cbmhClass, String types, MethodHandle[] mhs) {
-            if (mhs == null)  mhs = new MethodHandle[types.length()];
-            for (int i = 0; i < mhs.length; ++i) {
-                mhs[i] = makeGetter(cbmhClass, types, i);
-                assert(mhs[i].internalMemberName().getDeclaringClass() == cbmhClass);
-            }
-            return mhs;
-        }
-
-        static MethodHandle[] makeCtors(Class<? extends BoundMethodHandle> cbmh, String types, MethodHandle mhs[]) {
-            if (mhs == null)  mhs = new MethodHandle[1];
-            if (types.equals(""))  return mhs;  // hack for empty BMH species
-            mhs[0] = makeCbmhCtor(cbmh, types);
-            return mhs;
-        }
-
-        static NamedFunction[] makeNominalGetters(String types, NamedFunction[] nfs, MethodHandle[] getters) {
-            if (nfs == null)  nfs = new NamedFunction[types.length()];
-            for (int i = 0; i < nfs.length; ++i) {
-                nfs[i] = new NamedFunction(getters[i]);
-            }
-            return nfs;
-        }
-
-        //
-        // Auxiliary methods.
-        //
-
-        static SpeciesData getSpeciesDataFromConcreteBMHClass(Class<? extends BoundMethodHandle> cbmh) {
-            try {
-                Field F_SPECIES_DATA = cbmh.getDeclaredField("SPECIES_DATA");
-                return (SpeciesData) F_SPECIES_DATA.get(null);
-            } catch (ReflectiveOperationException ex) {
-                throw newInternalError(ex);
-            }
-        }
+      }
 
-        static void setSpeciesDataToConcreteBMHClass(Class<? extends BoundMethodHandle> cbmh, SpeciesData speciesData) {
-            try {
-                Field F_SPECIES_DATA = cbmh.getDeclaredField("SPECIES_DATA");
-                // ## FIXME: annotation parser can't create proxy classes until module system is fully initialzed
-                // assert F_SPECIES_DATA.getDeclaredAnnotation(Stable.class) != null;
-                F_SPECIES_DATA.set(null, speciesData);
-            } catch (ReflectiveOperationException ex) {
-                throw newInternalError(ex);
-            }
-        }
-
-        /**
-         * Field names in concrete BMHs adhere to this pattern:
-         * arg + type + index
-         * where type is a single character (L, I, J, F, D).
-         */
-        private static String makeFieldName(String types, int index) {
-            assert index >= 0 && index < types.length();
-            return "arg" + types.charAt(index) + index;
-        }
-
-        private static String makeSignature(String types, boolean ctor) {
-            StringBuilder buf = new StringBuilder(SIG_INCIPIT);
-            int len = types.length();
-            for (int i = 0; i < len; i++) {
-                buf.append(typeSig(types.charAt(i)));
-            }
-            return buf.append(')').append(ctor ? "V" : BMH_SIG).toString();
-        }
-
-        private static MethodType makeConstructorType(String types) {
-            int length = types.length();
-            Class<?> ptypes[] = new Class<?>[length + 2];
-            ptypes[0] = MethodType.class;
-            ptypes[1] = LambdaForm.class;
-            for (int i = 0; i < length; i++) {
-                ptypes[i + 2] = BasicType.basicType(types.charAt(i)).basicTypeClass();
-            }
-            return MethodType.makeImpl(BoundMethodHandle.class, ptypes, true);
-        }
-
-        static MethodHandle makeCbmhCtor(Class<? extends BoundMethodHandle> cbmh, String types) {
-            try {
-                return LOOKUP.findStatic(cbmh, "make", makeConstructorType(types));
-            } catch (NoSuchMethodException | IllegalAccessException | IllegalArgumentException | TypeNotPresentException e) {
-                throw newInternalError(e);
-            }
-        }
-    }
-
-    static final Lookup LOOKUP = Lookup.IMPL_LOOKUP;
-
-    /**
-     * All subclasses must provide such a value describing their type signature.
-     */
-    static final SpeciesData SPECIES_DATA = SpeciesData.EMPTY;
-
-    private static final SpeciesData[] SPECIES_DATA_CACHE = new SpeciesData[6];
-    private static SpeciesData checkCache(int size, String types) {
-        int idx = size - 1;
-        SpeciesData data = SPECIES_DATA_CACHE[idx];
-        if (data != null)  return data;
-        SPECIES_DATA_CACHE[idx] = data = getSpeciesData(types);
-        return data;
-    }
-    static SpeciesData speciesData_L()      { return checkCache(1, "L"); }
-    static SpeciesData speciesData_LL()     { return checkCache(2, "LL"); }
-    static SpeciesData speciesData_LLL()    { return checkCache(3, "LLL"); }
-    static SpeciesData speciesData_LLLL()   { return checkCache(4, "LLLL"); }
-    static SpeciesData speciesData_LLLLL()  { return checkCache(5, "LLLLL"); }
+    static SpeciesData speciesData_L()      { return Species_L.BMH_SPECIES; }
+    static SpeciesData speciesData_LL()     { return SPECIALIZER.findSpecies("LL"); }
+    static SpeciesData speciesData_LLL()    { return SPECIALIZER.findSpecies("LLL"); }
+    static SpeciesData speciesData_LLLL()   { return SPECIALIZER.findSpecies("LLLL"); }
+    static SpeciesData speciesData_LLLLL()  { return SPECIALIZER.findSpecies("LLLLL"); }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/java.base/share/classes/java/lang/invoke/ClassSpecializer.java	Fri Nov 17 02:50:51 2017 +0100
@@ -0,0 +1,1030 @@
+/*
+ * Copyright (c) 2017, 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 java.lang.invoke;
+
+import jdk.internal.loader.BootLoader;
+import jdk.internal.org.objectweb.asm.ClassWriter;
+import jdk.internal.org.objectweb.asm.FieldVisitor;
+import jdk.internal.org.objectweb.asm.MethodVisitor;
+import jdk.internal.vm.annotation.Stable;
+import sun.invoke.util.BytecodeName;
+
+import java.lang.reflect.*;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.security.ProtectionDomain;
+import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.function.Function;
+
+import static java.lang.invoke.LambdaForm.*;
+import static java.lang.invoke.MethodHandleNatives.Constants.REF_getStatic;
+import static java.lang.invoke.MethodHandleNatives.Constants.REF_putStatic;
+import static java.lang.invoke.MethodHandleStatics.*;
+import static java.lang.invoke.MethodHandles.Lookup.IMPL_LOOKUP;
+import static jdk.internal.org.objectweb.asm.Opcodes.*;
+
+/**
+ * Class specialization code.
+ * @param <T> top class under which species classes are created.
+ * @param <K> key which identifies individual specializations.
+ * @param <S> species data type.
+ */
+/*non-public*/
+abstract class ClassSpecializer<T,K,S extends ClassSpecializer<T,K,S>.SpeciesData> {
+    private final Class<T> topClass;
+    private final Class<K> keyType;
+    private final Class<S> metaType;
+    private final MemberName sdAccessor;
+    private final String sdFieldName;
+    private final List<MemberName> transformMethods;
+    private final MethodType baseConstructorType;
+    private final S topSpecies;
+    private final ConcurrentMap<K, S> cache = new ConcurrentHashMap<>();
+    private final Factory factory;
+    private @Stable boolean topClassIsSuper;
+
+    /** Return the top type mirror, for type {@code T} */
+    public final Class<T> topClass() { return topClass; }
+
+    /** Return the key type mirror, for type {@code K} */
+    public final Class<K> keyType() { return keyType; }
+
+    /** Return the species metadata type mirror, for type {@code S} */
+    public final Class<S> metaType() { return metaType; }
+
+    /** Report the leading arguments (if any) required by every species factory.
+     * Every species factory adds its own field types as additional arguments,
+     * but these arguments always come first, in every factory method.
+     */
+    protected MethodType baseConstructorType() { return baseConstructorType; }
+
+    /** Return the trivial species for the null sequence of arguments. */
+    protected final S topSpecies() { return topSpecies; }
+
+    /** Return the list of transform methods originally given at creation of this specializer. */
+    protected final List<MemberName> transformMethods() { return transformMethods; }
+
+    /** Return the factory object used to build and load concrete species code. */
+    protected final Factory factory() { return factory; }
+
+    /**
+     * Constructor for this class specializer.
+     * @param topClass type mirror for T
+     * @param keyType type mirror for K
+     * @param metaType type mirror for S
+     * @param baseConstructorType principal constructor type
+     * @param sdAccessor the method used to get the speciesData
+     * @param sdFieldName the name of the species data field, inject the speciesData object
+     * @param transformMethods optional list of transformMethods
+     */
+    protected ClassSpecializer(Class<T> topClass,
+                               Class<K> keyType,
+                               Class<S> metaType,
+                               MethodType baseConstructorType,
+                               MemberName sdAccessor,
+                               String sdFieldName,
+                               List<MemberName> transformMethods) {
+        this.topClass = topClass;
+        this.keyType = keyType;
+        this.metaType = metaType;
+        this.sdAccessor = sdAccessor;
+        // FIXME: use List.copyOf once 8177290 is in
+        this.transformMethods = List.of(transformMethods.toArray(new MemberName[transformMethods.size()]));
+        this.sdFieldName = sdFieldName;
+        this.baseConstructorType = baseConstructorType.changeReturnType(void.class);
+        this.factory = makeFactory();
+        K tsk = topSpeciesKey();
+        S topSpecies = null;
+        if (tsk != null && topSpecies == null) {
+            // if there is a key, build the top species if needed:
+            topSpecies = findSpecies(tsk);
+        }
+        this.topSpecies = topSpecies;
+    }
+
+    // Utilities for subclass constructors:
+    protected static <T> Constructor<T> reflectConstructor(Class<T> defc, Class<?>... ptypes) {
+        try {
+            return defc.getDeclaredConstructor(ptypes);
+        } catch (NoSuchMethodException ex) {
+            throw newIAE(defc.getName()+"("+MethodType.methodType(void.class, ptypes)+")", ex);
+        }
+    }
+
+    protected static Field reflectField(Class<?> defc, String name) {
+        try {
+            return defc.getDeclaredField(name);
+        } catch (NoSuchFieldException ex) {
+            throw newIAE(defc.getName()+"."+name, ex);
+        }
+    }
+
+    private static RuntimeException newIAE(String message, Throwable cause) {
+        return new IllegalArgumentException(message, cause);
+    }
+
+    public final S findSpecies(K key) {
+        S speciesData = cache.computeIfAbsent(key, new Function<>() {
+            @Override
+            public S apply(K key1) {
+                return factory.loadSpecies(newSpeciesData(key1));
+            }
+        });
+        // Note:  Species instantiation may throw VirtualMachineError because of
+        // code cache overflow.  If this happens the species bytecode may be
+        // loaded but not linked to its species metadata (with MH's etc).
+        // That will cause a throw out of CHM.computeIfAbsent,
+        // which will shut down the caller thread.
+        //
+        // In a latter attempt to get the same species, the already-loaded
+        // class will be present in the system dictionary, causing an
+        // error when the species generator tries to reload it.
+        // We try to detect this case and link the pre-existing code.
+        //
+        // Although it would be better to start fresh by loading a new
+        // copy, we have to salvage the previously loaded but broken code.
+        // (As an alternative, we might spin a new class with a new name,
+        // or use the anonymous class mechanism.)
+        //
+        // In the end, as long as everybody goes through the same CHM,
+        // CHM.computeIfAbsent will ensure only one SpeciesData will be set
+        // successfully on a concrete class if ever.
+        // The concrete class is published via SpeciesData instance
+        // returned here only after the class and species data are linked together.
+        assert(speciesData != null);
+        return speciesData;
+    }
+
+    /**
+     * Meta-data wrapper for concrete subtypes of the top class.
+     * Each concrete subtype corresponds to a given sequence of basic field types (LIJFD).
+     * The fields are immutable; their values are fully specified at object construction.
+     * Each species supplies an array of getter functions which may be used in lambda forms.
+     * A concrete value is always constructed from the full tuple of its field values,
+     * accompanied by the required constructor parameters.
+     * There *may* also be transforms which cloning a species instance and
+     * either replace a constructor parameter or add one or more new field values.
+     * The shortest possible species has zero fields.
+     * Subtypes are not interrelated among themselves by subtyping, even though
+     * it would appear that a shorter species could serve as a supertype of a
+     * longer one which extends it.
+     */
+    public abstract class SpeciesData {
+        // Bootstrapping requires circular relations Class -> SpeciesData -> Class
+        // Therefore, we need non-final links in the chain.  Use @Stable fields.
+        private final K key;
+        private final List<Class<?>> fieldTypes;
+        @Stable private Class<? extends T> speciesCode;
+        @Stable private List<MethodHandle> factories;
+        @Stable private List<MethodHandle> getters;
+        @Stable private List<LambdaForm.NamedFunction> nominalGetters;
+        @Stable private final MethodHandle[] transformHelpers = new MethodHandle[transformMethods.size()];
+
+        protected SpeciesData(K key) {
+            this.key = keyType.cast(Objects.requireNonNull(key));
+            List<Class<?>> types = deriveFieldTypes(key);
+            // TODO: List.copyOf
+            int arity = types.size();
+            this.fieldTypes = List.of(types.toArray(new Class<?>[arity]));
+        }
+
+        public final K key() {
+            return key;
+        }
+
+        protected final List<Class<?>> fieldTypes() {
+            return fieldTypes;
+        }
+
+        protected final int fieldCount() {
+            return fieldTypes.size();
+        }
+
+        protected ClassSpecializer<T,K,S> outer() {
+            return ClassSpecializer.this;
+        }
+
+        protected final boolean isResolved() {
+            return speciesCode != null && factories != null && !factories.isEmpty();
+        }
+
+        @Override public String toString() {
+            return metaType.getSimpleName() + "[" + key.toString() + " => " + (isResolved() ? speciesCode.getSimpleName() : "UNRESOLVED") + "]";
+        }
+
+        @Override
+        public int hashCode() {
+            return key.hashCode();
+        }
+
+        @Override
+        public boolean equals(Object obj) {
+            if (!(obj instanceof ClassSpecializer.SpeciesData)) {
+                return false;
+            }
+            @SuppressWarnings("rawtypes")
+            ClassSpecializer.SpeciesData that = (ClassSpecializer.SpeciesData) obj;
+            return this.outer() == that.outer() && this.key.equals(that.key);
+        }
+
+        /** Throws NPE if this species is not yet resolved. */
+        protected final Class<? extends T> speciesCode() {
+            return Objects.requireNonNull(speciesCode);
+        }
+
+        /**
+         * Return a {@link MethodHandle} which can get the indexed field of this species.
+         * The return type is the type of the species field it accesses.
+         * The argument type is the {@code fieldHolder} class of this species.
+         */
+        protected MethodHandle getter(int i) {
+            return getters.get(i);
+        }
+
+        /**
+         * Return a {@link LambdaForm.Name} containing a {@link LambdaForm.NamedFunction} that
+         * represents a MH bound to a generic invoker, which in turn forwards to the corresponding
+         * getter.
+         */
+        protected LambdaForm.NamedFunction getterFunction(int i) {
+            LambdaForm.NamedFunction nf = nominalGetters.get(i);
+            assert(nf.memberDeclaringClassOrNull() == speciesCode());
+            assert(nf.returnType() == BasicType.basicType(fieldTypes.get(i)));
+            return nf;
+        }
+
+        protected List<LambdaForm.NamedFunction> getterFunctions() {
+            return nominalGetters;
+        }
+
+        protected List<MethodHandle> getters() {
+            return getters;
+        }
+
+        protected MethodHandle factory() {
+            return factories.get(0);
+        }
+
+        protected MethodHandle transformHelper(int whichtm) {
+            MethodHandle mh = transformHelpers[whichtm];
+            if (mh != null)  return mh;
+            mh = deriveTransformHelper(transformMethods().get(whichtm), whichtm);
+            // Do a little type checking before we start using the MH.
+            // (It will be called with invokeBasic, so this is our only chance.)
+            final MethodType mt = transformHelperType(whichtm);
+            mh = mh.asType(mt);
+            return transformHelpers[whichtm] = mh;
+        }
+
+        private final MethodType transformHelperType(int whichtm) {
+            MemberName tm = transformMethods().get(whichtm);
+            ArrayList<Class<?>> args = new ArrayList<>();
+            ArrayList<Class<?>> fields = new ArrayList<>();
+            Collections.addAll(args, tm.getParameterTypes());
+            fields.addAll(fieldTypes());
+            List<Class<?>> helperArgs = deriveTransformHelperArguments(tm, whichtm, args, fields);
+            return MethodType.methodType(tm.getReturnType(), helperArgs);
+        }
+
+        // Hooks for subclasses:
+
+        /**
+         * Given a key, derive the list of field types, which all instances of this
+         * species must store.
+         */
+        protected abstract List<Class<?>> deriveFieldTypes(K key);
+
+        /**
+         * Given the index of a method in the transforms list, supply a factory
+         * method that takes the arguments of the transform, plus the local fields,
+         * and produce a value of the required type.
+         * You can override this to return null or throw if there are no transforms.
+         * This method exists so that the transforms can be "grown" lazily.
+         * This is necessary if the transform *adds* a field to an instance,
+         * which sometimtes requires the creation, on the fly, of an extended species.
+         * This method is only called once for any particular parameter.
+         * The species caches the result in a private array.
+         *
+         * @param transform the transform being implemented
+         * @param whichtm the index of that transform in the original list of transforms
+         * @return the method handle which creates a new result from a mix of transform
+         * arguments and field values
+         */
+        protected abstract MethodHandle deriveTransformHelper(MemberName transform, int whichtm);
+
+        /**
+         * During code generation, this method is called once per transform to determine
+         * what is the mix of arguments to hand to the transform-helper.  The bytecode
+         * which marshals these arguments is open-coded in the species-specific transform.
+         * The two lists are of opaque objects, which you shouldn't do anything with besides
+         * reordering them into the output list.  (They are both mutable, to make editing
+         * easier.)  The imputed types of the args correspond to the transform's parameter
+         * list, while the imputed types of the fields correspond to the species field types.
+         * After code generation, this method may be called occasionally by error-checking code.
+         *
+         * @param transform the transform being implemented
+         * @param whichtm the index of that transform in the original list of transforms
+         * @param args a list of opaque objects representing the incoming transform arguments
+         * @param fields a list of opaque objects representing the field values of the receiver
+         * @param <X> the common element type of the various lists
+         * @return a new list
+         */
+        protected abstract <X> List<X> deriveTransformHelperArguments(MemberName transform, int whichtm,
+                                                                      List<X> args, List<X> fields);
+
+        /** Given a key, generate the name of the class which implements the species for that key.
+         * This algorithm must be stable.
+         *
+         * @return class name, which by default is {@code outer().topClass().getName() + "$Species_" + deriveTypeString(key)}
+         */
+        protected String deriveClassName() {
+            return outer().topClass().getName() + "$Species_" + deriveTypeString();
+        }
+
+        /**
+         * Default implementation collects basic type characters,
+         * plus possibly type names, if some types don't correspond
+         * to basic types.
+         *
+         * @return a string suitable for use in a class name
+         */
+        protected String deriveTypeString() {
+            List<Class<?>> types = fieldTypes();
+            StringBuilder buf = new StringBuilder();
+            StringBuilder end = new StringBuilder();
+            for (Class<?> type : types) {
+                BasicType basicType = BasicType.basicType(type);
+                if (basicType.basicTypeClass() == type) {
+                    buf.append(basicType.basicTypeChar());
+                } else {
+                    buf.append('V');
+                    end.append(classSig(type));
+                }
+            }
+            String typeString;
+            if (end.length() > 0) {
+                typeString = BytecodeName.toBytecodeName(buf.append("_").append(end).toString());
+            } else {
+                typeString = buf.toString();
+            }
+            return LambdaForm.shortenSignature(typeString);
+        }
+
+        /**
+         * Report what immediate super-class to use for the concrete class of this species.
+         * Normally this is {@code topClass}, but if that is an interface, the factory must override.
+         * The super-class must provide a constructor which takes the {@code baseConstructorType} arguments, if any.
+         * This hook also allows the code generator to use more than one canned supertype for species.
+         *
+         * @return the super-class of the class to be generated
+         */
+        protected Class<? extends T> deriveSuperClass() {
+            final Class<T> topc = topClass();
+            if (!topClassIsSuper) {
+                try {
+                    final Constructor<T> con = reflectConstructor(topc, baseConstructorType().parameterArray());
+                    if (!topc.isInterface() && !Modifier.isPrivate(con.getModifiers())) {
+                        topClassIsSuper = true;
+                    }
+                } catch (Exception|InternalError ex) {
+                    // fall through...
+                }
+                if (!topClassIsSuper) {
+                    throw newInternalError("must override if the top class cannot serve as a super class");
+                }
+            }
+            return topc;
+        }
+    }
+
+    protected abstract S newSpeciesData(K key);
+
+    protected K topSpeciesKey() {
+        return null;  // null means don't report a top species
+    }
+
+    /**
+     * Code generation support for instances.
+     * Subclasses can modify the behavior.
+     */
+    public class Factory {
+        /**
+         * Get a concrete subclass of the top class for a given combination of bound types.
+         *
+         * @param speciesData the species requiring the class, not yet linked
+         * @return a linked version of the same species
+         */
+        S loadSpecies(S speciesData) {
+            String className = speciesData.deriveClassName();
+            assert(className.indexOf('/') < 0) : className;
+            Class<?> salvage = null;
+            try {
+                salvage = BootLoader.loadClassOrNull(className);
+                if (TRACE_RESOLVE && salvage != null) {
+                    // Used by jlink species pregeneration plugin, see
+                    // jdk.tools.jlink.internal.plugins.GenerateJLIClassesPlugin
+                    System.out.println("[SPECIES_RESOLVE] " + className + " (salvaged)");
+                }
+            } catch (Error ex) {
+                if (TRACE_RESOLVE) {
+                    System.out.println("[SPECIES_FRESOLVE] " + className + " (Error) " + ex.getMessage());
+                }
+            }
+            final Class<? extends T> speciesCode;
+            if (salvage != null) {
+                speciesCode = salvage.asSubclass(topClass());
+                factory.linkSpeciesDataToCode(speciesData, speciesCode);
+                factory.linkCodeToSpeciesData(speciesCode, speciesData, true);
+            } else {
+                // Not pregenerated, generate the class
+                try {
+                    speciesCode = generateConcreteSpeciesCode(className, speciesData);
+                    if (TRACE_RESOLVE) {
+                        // Used by jlink species pregeneration plugin, see
+                        // jdk.tools.jlink.internal.plugins.GenerateJLIClassesPlugin
+                        System.out.println("[SPECIES_RESOLVE] " + className + " (generated)");
+                    }
+                    // This operation causes a lot of churn:
+                    linkSpeciesDataToCode(speciesData, speciesCode);
+                    // This operation commits the relation, but causes little churn:
+                    linkCodeToSpeciesData(speciesCode, speciesData, false);
+                } catch (Error ex) {
+                    if (TRACE_RESOLVE) {
+                        System.out.println("[SPECIES_RESOLVE] " + className + " (Error #2)" );
+                    }
+                    // We can get here if there is a race condition loading a class.
+                    // Or maybe we are out of resources.  Back out of the CHM.get and retry.
+                    throw ex;
+                }
+            }
+
+            if (!speciesData.isResolved()) {
+                throw newInternalError("bad species class linkage for " + className + ": " + speciesData);
+            }
+            assert(speciesData == factory.loadSpeciesDataFromCode(speciesCode));
+            return speciesData;
+        }
+
+        /**
+         * Generate a concrete subclass of the top class for a given combination of bound types.
+         *
+         * A concrete species subclass roughly matches the following schema:
+         *
+         * <pre>
+         * class Species_[[types]] extends [[T]] {
+         *     final [[S]] speciesData() { return ... }
+         *     static [[T]] make([[fields]]) { return ... }
+         *     [[fields]]
+         *     final [[T]] transform([[args]]) { return ... }
+         * }
+         * </pre>
+         *
+         * The {@code [[types]]} signature is precisely the key for the species.
+         *
+         * The {@code [[fields]]} section consists of one field definition per character in
+         * the type signature, adhering to the naming schema described in the definition of
+         * {@link #chooseFieldName}.
+         *
+         * For example, a concrete species for two references and one integral bound value
+         * has a shape like the following:
+         *
+         * <pre>
+         * class TopClass { ... private static
+         * final class Species_LLI extends TopClass {
+         *     final Object argL0;
+         *     final Object argL1;
+         *     final int argI2;
+         *     private Species_LLI(CT ctarg, ..., Object argL0, Object argL1, int argI2) {
+         *         super(ctarg, ...);
+         *         this.argL0 = argL0;
+         *         this.argL1 = argL1;
+         *         this.argI2 = argI2;
+         *     }
+         *     final SpeciesData speciesData() { return BMH_SPECIES; }
+         *     &#64;Stable static SpeciesData BMH_SPECIES; // injected afterwards
+         *     static TopClass make(CT ctarg, ..., Object argL0, Object argL1, int argI2) {
+         *         return new Species_LLI(ctarg, ..., argL0, argL1, argI2);
+         *     }
+         *     final TopClass copyWith(CT ctarg, ...) {
+         *         return new Species_LLI(ctarg, ..., argL0, argL1, argI2);
+         *     }
+         *     // two transforms, for the sake of illustration:
+         *     final TopClass copyWithExtendL(CT ctarg, ..., Object narg) {
+         *         return BMH_SPECIES.transform(L_TYPE).invokeBasic(ctarg, ..., argL0, argL1, argI2, narg);
+         *     }
+         *     final TopClass copyWithExtendI(CT ctarg, ..., int narg) {
+         *         return BMH_SPECIES.transform(I_TYPE).invokeBasic(ctarg, ..., argL0, argL1, argI2, narg);
+         *     }
+         * }
+         * </pre>
+         *
+         * @param className of the species
+         * @param speciesData what species we are generating
+         * @return the generated concrete TopClass class
+         */
+        Class<? extends T> generateConcreteSpeciesCode(String className, ClassSpecializer<T,K,S>.SpeciesData speciesData) {
+            byte[] classFile = generateConcreteSpeciesCodeFile(className, speciesData);
+
+            // load class
+            InvokerBytecodeGenerator.maybeDump(classBCName(className), classFile);
+            Class<?> speciesCode;
+
+            ClassLoader cl = topClass().getClassLoader();
+            ProtectionDomain pd = null;
+            if (cl != null) {
+                pd = AccessController.doPrivileged(
+                        new PrivilegedAction<>() {
+                            @Override
+                            public ProtectionDomain run() {
+                                return topClass().getProtectionDomain();
+                            }
+                        });
+            }
+            try {
+                speciesCode = UNSAFE.defineClass(className, classFile, 0, classFile.length, cl, pd);
+            } catch (Exception ex) {
+                throw newInternalError(ex);
+            }
+
+            return speciesCode.asSubclass(topClass());
+        }
+
+        // These are named like constants because there is only one per specialization scheme:
+        private final String SPECIES_DATA = classBCName(metaType);
+        private final String SPECIES_DATA_SIG = classSig(SPECIES_DATA);
+        private final String SPECIES_DATA_NAME = sdAccessor.getName();
+        private final int SPECIES_DATA_MODS = sdAccessor.getModifiers();
+        private final List<String> TRANSFORM_NAMES;  // derived from transformMethods
+        private final List<MethodType> TRANSFORM_TYPES;
+        private final List<Integer> TRANSFORM_MODS;
+        {
+            // Tear apart transformMethods to get the names, types, and modifiers.
+            List<String> tns = new ArrayList<>();
+            List<MethodType> tts = new ArrayList<>();
+            List<Integer> tms = new ArrayList<>();
+            for (int i = 0; i < transformMethods.size(); i++) {
+                MemberName tm = transformMethods.get(i);
+                tns.add(tm.getName());
+                final MethodType tt = tm.getMethodType();
+                tts.add(tt);
+                tms.add(tm.getModifiers());
+            }
+            TRANSFORM_NAMES = List.of(tns.toArray(new String[0]));
+            TRANSFORM_TYPES = List.of(tts.toArray(new MethodType[0]));
+            TRANSFORM_MODS = List.of(tms.toArray(new Integer[0]));
+        }
+        private static final int ACC_PPP = ACC_PUBLIC | ACC_PRIVATE | ACC_PROTECTED;
+
+        /*non-public*/ byte[] generateConcreteSpeciesCodeFile(String className0, ClassSpecializer<T,K,S>.SpeciesData speciesData) {
+            final String className = classBCName(className0);
+            final String superClassName = classBCName(speciesData.deriveSuperClass());
+
+            final ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS + ClassWriter.COMPUTE_FRAMES);
+            final int NOT_ACC_PUBLIC = 0;  // not ACC_PUBLIC
+            cw.visit(V1_6, NOT_ACC_PUBLIC + ACC_FINAL + ACC_SUPER, className, null, superClassName, null);
+
+            final String sourceFile = className.substring(className.lastIndexOf('.')+1);
+            cw.visitSource(sourceFile, null);
+
+            // emit static types and BMH_SPECIES fields
+            FieldVisitor fw = cw.visitField(NOT_ACC_PUBLIC + ACC_STATIC, sdFieldName, SPECIES_DATA_SIG, null, null);
+            fw.visitAnnotation(STABLE_SIG, true);
+            fw.visitEnd();
+
+            // handy holder for dealing with groups of typed values (ctor arguments and fields)
+            class Var {
+                final int index;
+                final String name;
+                final Class<?> type;
+                final String desc;
+                final BasicType basicType;
+                final int slotIndex;
+                Var(int index, int slotIndex) {
+                    this.index = index;
+                    this.slotIndex = slotIndex;
+                    name = null; type = null; desc = null;
+                    basicType = BasicType.V_TYPE;
+                }
+                Var(String name, Class<?> type, Var prev) {
+                    int slotIndex = prev.nextSlotIndex();
+                    int index = prev.nextIndex();
+                    if (name == null)  name = "x";
+                    if (name.endsWith("#"))
+                        name = name.substring(0, name.length()-1) + index;
+                    assert(!type.equals(void.class));
+                    String desc = classSig(type);
+                    BasicType basicType = BasicType.basicType(type);
+                    this.index = index;
+                    this.name = name;
+                    this.type = type;
+                    this.desc = desc;
+                    this.basicType = basicType;
+                    this.slotIndex = slotIndex;
+                }
+                Var lastOf(List<Var> vars) {
+                    int n = vars.size();
+                    return (n == 0 ? this : vars.get(n-1));
+                }
+                <X> List<Var> fromTypes(List<X> types) {
+                    Var prev = this;
+                    ArrayList<Var> result = new ArrayList<>(types.size());
+                    int i = 0;
+                    for (X x : types) {
+                        String vn = name;
+                        Class<?> vt;
+                        if (x instanceof Class) {
+                            vt = (Class<?>) x;
+                            // make the names friendlier if debugging
+                            assert((vn = vn + "_" + (i++)) != null);
+                        } else {
+                            @SuppressWarnings("unchecked")
+                            Var v = (Var) x;
+                            vn = v.name;
+                            vt = v.type;
+                        }
+                        prev = new Var(vn, vt, prev);
+                        result.add(prev);
+                    }
+                    return result;
+                }
+
+                int slotSize() { return basicType.basicTypeSlots(); }
+                int nextIndex() { return index + (slotSize() == 0 ? 0 : 1); }
+                int nextSlotIndex() { return slotIndex >= 0 ? slotIndex + slotSize() : slotIndex; }
+                boolean isInHeap() { return slotIndex < 0; }
+                void emitVarInstruction(int asmop, MethodVisitor mv) {
+                    if (asmop == ALOAD)
+                        asmop = typeLoadOp(basicType.basicTypeChar());
+                    else
+                        throw new AssertionError("bad op="+asmop+" for desc="+desc);
+                    mv.visitVarInsn(asmop, slotIndex);
+                }
+                public void emitFieldInsn(int asmop, MethodVisitor mv) {
+                    mv.visitFieldInsn(asmop, className, name, desc);
+                }
+            }
+
+            final Var NO_THIS = new Var(0, 0),
+                    AFTER_THIS = new Var(0, 1),
+                    IN_HEAP = new Var(0, -1);
+
+            // figure out the field types
+            final List<Class<?>> fieldTypes = speciesData.fieldTypes();
+            final List<Var> fields = new ArrayList<>(fieldTypes.size());
+            {
+                Var nextF = IN_HEAP;
+                for (Class<?> ft : fieldTypes) {
+                    String fn = chooseFieldName(ft, nextF.nextIndex());
+                    nextF = new Var(fn, ft, nextF);
+                    fields.add(nextF);
+                }
+            }
+
+            // emit bound argument fields
+            for (Var field : fields) {
+                cw.visitField(ACC_FINAL, field.name, field.desc, null, null).visitEnd();
+            }
+
+            MethodVisitor mv;
+
+            // emit implementation of speciesData()
+            mv = cw.visitMethod((SPECIES_DATA_MODS & ACC_PPP) + ACC_FINAL,
+                    SPECIES_DATA_NAME, "()" + SPECIES_DATA_SIG, null, null);
+            mv.visitCode();
+            mv.visitFieldInsn(GETSTATIC, className, sdFieldName, SPECIES_DATA_SIG);
+            mv.visitInsn(ARETURN);
+            mv.visitMaxs(0, 0);
+            mv.visitEnd();
+
+            // figure out the constructor arguments
+            MethodType superCtorType = ClassSpecializer.this.baseConstructorType();
+            MethodType thisCtorType = superCtorType.appendParameterTypes(fieldTypes);
+
+            // emit constructor
+            {
+                mv = cw.visitMethod(ACC_PRIVATE,
+                        "<init>", methodSig(thisCtorType), null, null);
+                mv.visitCode();
+                mv.visitVarInsn(ALOAD, 0); // this
+
+                final List<Var> ctorArgs = AFTER_THIS.fromTypes(superCtorType.parameterList());
+                for (Var ca : ctorArgs) {
+                    ca.emitVarInstruction(ALOAD, mv);
+                }
+
+                // super(ca...)
+                mv.visitMethodInsn(INVOKESPECIAL, superClassName,
+                        "<init>", methodSig(superCtorType), false);
+
+                // store down fields
+                Var lastFV = AFTER_THIS.lastOf(ctorArgs);
+                for (Var f : fields) {
+                    // this.argL1 = argL1
+                    mv.visitVarInsn(ALOAD, 0);  // this
+                    lastFV = new Var(f.name, f.type, lastFV);
+                    lastFV.emitVarInstruction(ALOAD, mv);
+                    f.emitFieldInsn(PUTFIELD, mv);
+                }
+
+                mv.visitInsn(RETURN);
+                mv.visitMaxs(0, 0);
+                mv.visitEnd();
+            }
+
+            // emit make()  ...factory method wrapping constructor
+            {
+                MethodType ftryType = thisCtorType.changeReturnType(topClass());
+                mv = cw.visitMethod(NOT_ACC_PUBLIC + ACC_STATIC,
+                        "make", methodSig(ftryType), null, null);
+                mv.visitCode();
+                // make instance
+                mv.visitTypeInsn(NEW, className);
+                mv.visitInsn(DUP);
+                // load factory method arguments:  ctarg... and arg...
+                for (Var v : NO_THIS.fromTypes(ftryType.parameterList())) {
+                    v.emitVarInstruction(ALOAD, mv);
+                }
+
+                // finally, invoke the constructor and return
+                mv.visitMethodInsn(INVOKESPECIAL, className,
+                        "<init>", methodSig(thisCtorType), false);
+                mv.visitInsn(ARETURN);
+                mv.visitMaxs(0, 0);
+                mv.visitEnd();
+            }
+
+            // For each transform, emit the customized override of the transform method.
+            // This method mixes together some incoming arguments (from the transform's
+            // static type signature) with the field types themselves, and passes
+            // the resulting mish-mosh of values to a method handle produced by
+            // the species itself.  (Typically this method handle is the factory
+            // method of this species or a related one.)
+            for (int whichtm = 0; whichtm < TRANSFORM_NAMES.size(); whichtm++) {
+                final String     TNAME = TRANSFORM_NAMES.get(whichtm);
+                final MethodType TTYPE = TRANSFORM_TYPES.get(whichtm);
+                final int        TMODS = TRANSFORM_MODS.get(whichtm);
+                mv = cw.visitMethod((TMODS & ACC_PPP) | ACC_FINAL,
+                        TNAME, TTYPE.toMethodDescriptorString(), null, E_THROWABLE);
+                mv.visitCode();
+                // return a call to the corresponding "transform helper", something like this:
+                //   MY_SPECIES.transformHelper(whichtm).invokeBasic(ctarg, ..., argL0, ..., xarg)
+                mv.visitFieldInsn(GETSTATIC, className,
+                        sdFieldName, SPECIES_DATA_SIG);
+                emitIntConstant(whichtm, mv);
+                mv.visitMethodInsn(INVOKEVIRTUAL, SPECIES_DATA,
+                        "transformHelper", "(I)" + MH_SIG, false);
+
+                List<Var> targs = AFTER_THIS.fromTypes(TTYPE.parameterList());
+                List<Var> tfields = new ArrayList<>(fields);
+                // mix them up and load them for the transform helper:
+                List<Var> helperArgs = speciesData.deriveTransformHelperArguments(transformMethods.get(whichtm), whichtm, targs, tfields);
+                List<Class<?>> helperTypes = new ArrayList<>(helperArgs.size());
+                for (Var ha : helperArgs) {
+                    helperTypes.add(ha.basicType.basicTypeClass());
+                    if (ha.isInHeap()) {
+                        assert(tfields.contains(ha));
+                        mv.visitVarInsn(ALOAD, 0);
+                        ha.emitFieldInsn(GETFIELD, mv);
+                    } else {
+                        assert(targs.contains(ha));
+                        ha.emitVarInstruction(ALOAD, mv);
+                    }
+                }
+
+                // jump into the helper (which is probably a factory method)
+                final Class<?> rtype = TTYPE.returnType();
+                final BasicType rbt = BasicType.basicType(rtype);
+                MethodType invokeBasicType = MethodType.methodType(rbt.basicTypeClass(), helperTypes);
+                mv.visitMethodInsn(INVOKEVIRTUAL, MH,
+                        "invokeBasic", methodSig(invokeBasicType), false);
+                if (rbt == BasicType.L_TYPE) {
+                    mv.visitTypeInsn(CHECKCAST, classBCName(rtype));
+                    mv.visitInsn(ARETURN);
+                } else {
+                    throw newInternalError("NYI: transform of type "+rtype);
+                }
+                mv.visitMaxs(0, 0);
+                mv.visitEnd();
+            }
+
+            cw.visitEnd();
+
+            return cw.toByteArray();
+        }
+
+        private int typeLoadOp(char t) {
+            switch (t) {
+            case 'L': return ALOAD;
+            case 'I': return ILOAD;
+            case 'J': return LLOAD;
+            case 'F': return FLOAD;
+            case 'D': return DLOAD;
+            default : throw newInternalError("unrecognized type " + t);
+            }
+        }
+
+        private void emitIntConstant(int con, MethodVisitor mv) {
+            if (ICONST_M1 - ICONST_0 <= con && con <= ICONST_5 - ICONST_0)
+                mv.visitInsn(ICONST_0 + con);
+            else if (con == (byte) con)
+                mv.visitIntInsn(BIPUSH, con);
+            else if (con == (short) con)
+                mv.visitIntInsn(SIPUSH, con);
+            else {
+                mv.visitLdcInsn(con);
+            }
+
+        }
+
+        //
+        // Getter MH generation.
+        //
+
+        private MethodHandle findGetter(Class<?> speciesCode, List<Class<?>> types, int index) {
+            Class<?> fieldType = types.get(index);
+            String fieldName = chooseFieldName(fieldType, index);
+            try {
+                return IMPL_LOOKUP.findGetter(speciesCode, fieldName, fieldType);
+            } catch (NoSuchFieldException | IllegalAccessException e) {
+                throw newInternalError(e);
+            }
+        }
+
+        private List<MethodHandle> findGetters(Class<?> speciesCode, List<Class<?>> types) {
+            MethodHandle[] mhs = new MethodHandle[types.size()];
+            for (int i = 0; i < mhs.length; ++i) {
+                mhs[i] = findGetter(speciesCode, types, i);
+                assert(mhs[i].internalMemberName().getDeclaringClass() == speciesCode);
+            }
+            return List.of(mhs);
+        }
+
+        private List<MethodHandle> findFactories(Class<? extends T> speciesCode, List<Class<?>> types) {
+            MethodHandle[] mhs = new MethodHandle[1];
+            mhs[0] = findFactory(speciesCode, types);
+            return List.of(mhs);
+        }
+
+        List<LambdaForm.NamedFunction> makeNominalGetters(List<Class<?>> types, List<MethodHandle> getters) {
+            LambdaForm.NamedFunction[] nfs = new LambdaForm.NamedFunction[types.size()];
+            for (int i = 0; i < nfs.length; ++i) {
+                nfs[i] = new LambdaForm.NamedFunction(getters.get(i));
+            }
+            return List.of(nfs);
+        }
+
+        //
+        // Auxiliary methods.
+        //
+
+        protected void linkSpeciesDataToCode(ClassSpecializer<T,K,S>.SpeciesData speciesData, Class<? extends T> speciesCode) {
+            speciesData.speciesCode = speciesCode.asSubclass(topClass);
+            final List<Class<?>> types = speciesData.fieldTypes;
+            speciesData.factories = this.findFactories(speciesCode, types);
+            speciesData.getters = this.findGetters(speciesCode, types);
+            speciesData.nominalGetters = this.makeNominalGetters(types, speciesData.getters);
+        }
+
+        private Field reflectSDField(Class<? extends T> speciesCode) {
+            final Field field = reflectField(speciesCode, sdFieldName);
+            assert(field.getType() == metaType);
+            assert(Modifier.isStatic(field.getModifiers()));
+            return field;
+        }
+
+        private S readSpeciesDataFromCode(Class<? extends T> speciesCode) {
+            try {
+                MemberName sdField = IMPL_LOOKUP.resolveOrFail(REF_getStatic, speciesCode, sdFieldName, metaType);
+                Object base = MethodHandleNatives.staticFieldBase(sdField);
+                long offset = MethodHandleNatives.staticFieldOffset(sdField);
+                UNSAFE.loadFence();
+                return metaType.cast(UNSAFE.getObject(base, offset));
+            } catch (Error err) {
+                throw err;
+            } catch (Exception ex) {
+                throw newInternalError("Failed to load speciesData from speciesCode: " + speciesCode.getName(), ex);
+            } catch (Throwable t) {
+                throw uncaughtException(t);
+            }
+        }
+
+        protected S loadSpeciesDataFromCode(Class<? extends T> speciesCode) {
+            if (speciesCode == topClass()) {
+                return topSpecies;
+            }
+            S result = readSpeciesDataFromCode(speciesCode);
+            if (result.outer() != ClassSpecializer.this) {
+                throw newInternalError("wrong class");
+            }
+            return result;
+        }
+
+        protected void linkCodeToSpeciesData(Class<? extends T> speciesCode, ClassSpecializer<T,K,S>.SpeciesData speciesData, boolean salvage) {
+            try {
+                assert(readSpeciesDataFromCode(speciesCode) == null ||
+                    (salvage && readSpeciesDataFromCode(speciesCode).equals(speciesData)));
+
+                MemberName sdField = IMPL_LOOKUP.resolveOrFail(REF_putStatic, speciesCode, sdFieldName, metaType);
+                Object base = MethodHandleNatives.staticFieldBase(sdField);
+                long offset = MethodHandleNatives.staticFieldOffset(sdField);
+                UNSAFE.storeFence();
+                UNSAFE.putObject(base, offset, speciesData);
+                UNSAFE.storeFence();
+            } catch (Error err) {
+                throw err;
+            } catch (Exception ex) {
+                throw newInternalError("Failed to link speciesData to speciesCode: " + speciesCode.getName(), ex);
+            } catch (Throwable t) {
+                throw uncaughtException(t);
+            }
+        }
+
+        /**
+         * Field names in concrete species classes adhere to this pattern:
+         * type + index, where type is a single character (L, I, J, F, D).
+         * The factory subclass can customize this.
+         * The name is purely cosmetic, since it applies to a private field.
+         */
+        protected String chooseFieldName(Class<?> type, int index) {
+            BasicType bt = BasicType.basicType(type);
+            return "" + bt.basicTypeChar() + index;
+        }
+
+        MethodHandle findFactory(Class<? extends T> speciesCode, List<Class<?>> types) {
+            final MethodType type = baseConstructorType().changeReturnType(topClass()).appendParameterTypes(types);
+            try {
+                return IMPL_LOOKUP.findStatic(speciesCode, "make", type);
+            } catch (NoSuchMethodException | IllegalAccessException | IllegalArgumentException | TypeNotPresentException e) {
+                throw newInternalError(e);
+            }
+        }
+    }
+
+    /** Hook that virtualizes the Factory class, allowing subclasses to extend it. */
+    protected Factory makeFactory() {
+        return new Factory();
+    }
+
+
+    // Other misc helpers:
+    private static final String MH = "java/lang/invoke/MethodHandle";
+    private static final String MH_SIG = "L" + MH + ";";
+    private static final String STABLE = "jdk/internal/vm/annotation/Stable";
+    private static final String STABLE_SIG = "L" + STABLE + ";";
+    private static final String[] E_THROWABLE = new String[] { "java/lang/Throwable" };
+    static {
+        assert(MH_SIG.equals(classSig(MethodHandle.class)));
+        assert(MH.equals(classBCName(MethodHandle.class)));
+    }
+
+    static String methodSig(MethodType mt) {
+        return mt.toMethodDescriptorString();
+    }
+    static String classSig(Class<?> cls) {
+        if (cls.isPrimitive() || cls.isArray())
+            return MethodType.methodType(cls).toMethodDescriptorString().substring(2);
+        return classSig(classBCName(cls));
+    }
+    static String classSig(String bcName) {
+        assert(bcName.indexOf('.') < 0);
+        assert(!bcName.endsWith(";"));
+        assert(!bcName.startsWith("["));
+        return "L" + bcName + ";";
+    }
+    static String classBCName(Class<?> cls) {
+        return classBCName(className(cls));
+    }
+    static String classBCName(String str) {
+        assert(str.indexOf('/') < 0) : str;
+        return str.replace('.', '/');
+    }
+    static String className(Class<?> cls) {
+        assert(!cls.isArray() && !cls.isPrimitive());
+        return cls.getName();
+    }
+}
--- a/src/java.base/share/classes/java/lang/invoke/GenerateJLIClassesHelper.java	Fri Nov 17 11:08:44 2017 +0530
+++ b/src/java.base/share/classes/java/lang/invoke/GenerateJLIClassesHelper.java	Fri Nov 17 02:50:51 2017 +0100
@@ -25,14 +25,14 @@
 
 package java.lang.invoke;
 
-import java.util.Map;
 import jdk.internal.org.objectweb.asm.ClassWriter;
 import jdk.internal.org.objectweb.asm.Opcodes;
+import sun.invoke.util.Wrapper;
+
 import java.util.ArrayList;
 import java.util.HashSet;
-import sun.invoke.util.Wrapper;
-
-import static java.lang.invoke.MethodHandleNatives.Constants.*;
+import java.util.List;
+import java.util.Map;
 
 /**
  * Helper class to assist the GenerateJLIClassesPlugin to get access to
@@ -118,8 +118,7 @@
                 // require an even more complex naming scheme
                 LambdaForm reinvoker = makeReinvokerFor(methodTypes[i]);
                 forms.add(reinvoker);
-                String speciesSig = BoundMethodHandle
-                        .speciesData(reinvoker).fieldSignature();
+                String speciesSig = BoundMethodHandle.speciesDataFor(reinvoker).key();
                 assert(speciesSig.equals("L"));
                 names.add(reinvoker.kind.defaultLambdaName + "_" + speciesSig);
 
@@ -205,20 +204,19 @@
                 DelegatingMethodHandle.NF_getTarget);
     }
 
-    static Map.Entry<String, byte[]> generateConcreteBMHClassBytes(
-            final String types) {
+    @SuppressWarnings({"rawtypes", "unchecked"})
+    static Map.Entry<String, byte[]> generateConcreteBMHClassBytes(final String types) {
         for (char c : types.toCharArray()) {
             if ("LIJFD".indexOf(c) < 0) {
                 throw new IllegalArgumentException("All characters must "
                         + "correspond to a basic field type: LIJFD");
             }
         }
-        String shortTypes = LambdaForm.shortenSignature(types);
-        final String className =
-                BoundMethodHandle.Factory.speciesInternalClassName(shortTypes);
-        return Map.entry(className,
-                         BoundMethodHandle.Factory.generateConcreteBMHClassBytes(
-                                 shortTypes, types, className));
+        final BoundMethodHandle.SpeciesData species = BoundMethodHandle.SPECIALIZER.findSpecies(types);
+        final String className = species.speciesCode().getName();
+        final ClassSpecializer.Factory factory = BoundMethodHandle.SPECIALIZER.factory();
+        final byte[] code = factory.generateConcreteSpeciesCodeFile(className, species);
+        return Map.entry(className.replace('.', '/'), code);
     }
 
 }
--- a/src/java.base/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java	Fri Nov 17 11:08:44 2017 +0530
+++ b/src/java.base/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java	Fri Nov 17 02:50:51 2017 +0100
@@ -183,8 +183,7 @@
             new java.security.PrivilegedAction<>() {
                 public Void run() {
                     try {
-                        String dumpName = className;
-                        //dumpName = dumpName.replace('/', '-');
+                        String dumpName = className.replace('.','/');
                         File dumpFile = new File(DUMP_CLASS_FILES_DIR, dumpName+".class");
                         System.out.println("dump: " + dumpFile);
                         dumpFile.getParentFile().mkdirs();
@@ -630,7 +629,7 @@
         String name = form.kind.methodName;
         switch (form.kind) {
             case BOUND_REINVOKER: {
-                name = name + "_" + BoundMethodHandle.speciesData(form).fieldSignature();
+                name = name + "_" + BoundMethodHandle.speciesDataFor(form).key();
                 return resolveFrom(name, invokerType, DelegatingMethodHandle.Holder.class);
             }
             case DELEGATE:                  return resolveFrom(name, invokerType, DelegatingMethodHandle.Holder.class);
--- a/src/java.base/share/classes/java/lang/invoke/LambdaForm.java	Fri Nov 17 11:08:44 2017 +0530
+++ b/src/java.base/share/classes/java/lang/invoke/LambdaForm.java	Fri Nov 17 02:50:51 2017 +0100
@@ -143,12 +143,22 @@
         D_TYPE('D', double.class, Wrapper.DOUBLE),  // all primitive types
         V_TYPE('V', void.class,   Wrapper.VOID);    // not valid in all contexts
 
-        static final BasicType[] ALL_TYPES = BasicType.values();
-        static final BasicType[] ARG_TYPES = Arrays.copyOf(ALL_TYPES, ALL_TYPES.length-1);
+        static final @Stable BasicType[] ALL_TYPES = BasicType.values();
+        static final @Stable BasicType[] ARG_TYPES = Arrays.copyOf(ALL_TYPES, ALL_TYPES.length-1);
 
         static final int ARG_TYPE_LIMIT = ARG_TYPES.length;
         static final int TYPE_LIMIT = ALL_TYPES.length;
 
+        // Derived int constants, which (unlike the enums) can be constant folded.
+        // We can remove them when JDK-8161245 is fixed.
+        static final byte
+                L_TYPE_NUM = (byte) L_TYPE.ordinal(),
+                I_TYPE_NUM = (byte) I_TYPE.ordinal(),
+                J_TYPE_NUM = (byte) J_TYPE.ordinal(),
+                F_TYPE_NUM = (byte) F_TYPE.ordinal(),
+                D_TYPE_NUM = (byte) D_TYPE.ordinal(),
+                V_TYPE_NUM = (byte) V_TYPE.ordinal();
+
         final char btChar;
         final Class<?> btClass;
         final Wrapper btWrapper;
@@ -679,6 +689,9 @@
         Class<?> rtype = signatureReturn(sig).btClass;
         return MethodType.makeImpl(rtype, ptypes, true);
     }
+    static MethodType basicMethodType(MethodType mt) {
+        return signatureType(basicTypeSignature(mt));
+    }
 
     /**
      * Check if i-th name is a call to MethodHandleImpl.selectAlternative.
@@ -1291,14 +1304,28 @@
         assert(sigp == sig.length);
         return String.valueOf(sig);
     }
+
+    /** Hack to make signatures more readable when they show up in method names.
+     * Signature should start with a sequence of uppercase ASCII letters.
+     * Runs of three or more are replaced by a single letter plus a decimal repeat count.
+     * A tail of anything other than uppercase ASCII is passed through unchanged.
+     * @param signature sequence of uppercase ASCII letters with possible repetitions
+     * @return same sequence, with repetitions counted by decimal numerals
+     */
     public static String shortenSignature(String signature) {
-        // Hack to make signatures more readable when they show up in method names.
         final int NO_CHAR = -1, MIN_RUN = 3;
         int c0, c1 = NO_CHAR, c1reps = 0;
         StringBuilder buf = null;
         int len = signature.length();
         if (len < MIN_RUN)  return signature;
         for (int i = 0; i <= len; i++) {
+            if (c1 != NO_CHAR && !('A' <= c1 && c1 <= 'Z')) {
+                // wrong kind of char; bail out here
+                if (buf != null) {
+                    buf.append(signature.substring(i - c1reps, len));
+                }
+                break;
+            }
             // shift in the next char:
             c0 = c1; c1 = (i == len ? NO_CHAR : signature.charAt(i));
             if (c1 == c0) { ++c1reps; continue; }
@@ -1342,7 +1369,7 @@
             this.arguments = that.arguments;
             this.constraint = constraint;
             assert(constraint == null || isParam());  // only params have constraints
-            assert(constraint == null || constraint instanceof BoundMethodHandle.SpeciesData || constraint instanceof Class);
+            assert(constraint == null || constraint instanceof ClassSpecializer.SpeciesData || constraint instanceof Class);
         }
         Name(MethodHandle function, Object... arguments) {
             this(new NamedFunction(function), arguments);
--- a/src/java.base/share/classes/java/lang/invoke/LambdaFormBuffer.java	Fri Nov 17 11:08:44 2017 +0530
+++ b/src/java.base/share/classes/java/lang/invoke/LambdaFormBuffer.java	Fri Nov 17 02:50:51 2017 +0100
@@ -27,6 +27,8 @@
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.List;
+
 import static java.lang.invoke.LambdaForm.*;
 import static java.lang.invoke.LambdaForm.BasicType.*;
 
@@ -325,15 +327,15 @@
      *  whose function is in the corresponding position in newFns.
      *  Only do this if the arguments are exactly equal to the given.
      */
-    LambdaFormBuffer replaceFunctions(NamedFunction[] oldFns, NamedFunction[] newFns,
+    LambdaFormBuffer replaceFunctions(List<NamedFunction> oldFns, List<NamedFunction> newFns,
                                       Object... forArguments) {
         assert(inTrans());
-        if (oldFns.length == 0)  return this;
+        if (oldFns.isEmpty())  return this;
         for (int i = arity; i < length; i++) {
             Name n = names[i];
-            int nfi = indexOf(n.function, oldFns);
+            int nfi = oldFns.indexOf(n.function);
             if (nfi >= 0 && Arrays.equals(n.arguments, forArguments)) {
-                changeName(i, new Name(newFns[nfi], n.arguments));
+                changeName(i, new Name(newFns.get(nfi), n.arguments));
             }
         }
         return this;
--- a/src/java.base/share/classes/java/lang/invoke/LambdaFormEditor.java	Fri Nov 17 11:08:44 2017 +0530
+++ b/src/java.base/share/classes/java/lang/invoke/LambdaFormEditor.java	Fri Nov 17 02:50:51 2017 +0100
@@ -381,10 +381,11 @@
     /// Editing methods for method handles.  These need to have fast paths.
 
     private BoundMethodHandle.SpeciesData oldSpeciesData() {
-        return BoundMethodHandle.speciesData(lambdaForm);
+        return BoundMethodHandle.speciesDataFor(lambdaForm);
     }
+
     private BoundMethodHandle.SpeciesData newSpeciesData(BasicType type) {
-        return oldSpeciesData().extendWith(type);
+        return oldSpeciesData().extendWith((byte) type.ordinal());
     }
 
     BoundMethodHandle bindArgumentL(BoundMethodHandle mh, int pos, Object value) {
@@ -461,7 +462,7 @@
             buf.replaceParameterByNewExpression(pos, new Name(getter, newBaseAddress));
         } else {
             // cannot bind the MH arg itself, unless oldData is empty
-            assert(oldData == BoundMethodHandle.SpeciesData.EMPTY);
+            assert(oldData == BoundMethodHandle.SPECIALIZER.topSpecies());
             newBaseAddress = new Name(L_TYPE).withConstraint(newData);
             buf.replaceParameterByNewExpression(0, new Name(getter, newBaseAddress));
             buf.insertParameter(0, newBaseAddress);
--- a/src/java.base/share/classes/java/lang/invoke/MethodHandleImpl.java	Fri Nov 17 11:08:44 2017 +0530
+++ b/src/java.base/share/classes/java/lang/invoke/MethodHandleImpl.java	Fri Nov 17 02:50:51 2017 +0100
@@ -776,11 +776,11 @@
             if (PROFILE_GWT) {
                 int[] counts = new int[2];
                 mh = (BoundMethodHandle)
-                        BoundMethodHandle.speciesData_LLLL().constructor().invokeBasic(type, form,
+                        BoundMethodHandle.speciesData_LLLL().factory().invokeBasic(type, form,
                                 (Object) test, (Object) profile(target), (Object) profile(fallback), counts);
             } else {
                 mh = (BoundMethodHandle)
-                        BoundMethodHandle.speciesData_LLL().constructor().invokeBasic(type, form,
+                        BoundMethodHandle.speciesData_LLL().factory().invokeBasic(type, form,
                                 (Object) test, (Object) profile(target), (Object) profile(fallback));
             }
         } catch (Throwable ex) {
@@ -1089,7 +1089,7 @@
         BoundMethodHandle.SpeciesData data = BoundMethodHandle.speciesData_LLLLL();
         BoundMethodHandle mh;
         try {
-            mh = (BoundMethodHandle) data.constructor().invokeBasic(type, form, (Object) target, (Object) exType,
+            mh = (BoundMethodHandle) data.factory().invokeBasic(type, form, (Object) target, (Object) exType,
                     (Object) catcher, (Object) collectArgs, (Object) unboxResult);
         } catch (Throwable ex) {
             throw uncaughtException(ex);
@@ -1890,7 +1890,7 @@
         BoundMethodHandle.SpeciesData data = BoundMethodHandle.speciesData_LLL();
         BoundMethodHandle mh;
         try {
-            mh = (BoundMethodHandle) data.constructor().invokeBasic(type, form, (Object) clauseData,
+            mh = (BoundMethodHandle) data.factory().invokeBasic(type, form, (Object) clauseData,
                     (Object) collectArgs, (Object) unboxResult);
         } catch (Throwable ex) {
             throw uncaughtException(ex);
@@ -2133,7 +2133,7 @@
         BoundMethodHandle.SpeciesData data = BoundMethodHandle.speciesData_LLLL();
         BoundMethodHandle mh;
         try {
-            mh = (BoundMethodHandle) data.constructor().invokeBasic(type, form, (Object) target, (Object) cleanup,
+            mh = (BoundMethodHandle) data.factory().invokeBasic(type, form, (Object) target, (Object) cleanup,
                     (Object) collectArgs, (Object) unboxResult);
         } catch (Throwable ex) {
             throw uncaughtException(ex);
--- a/src/java.base/share/classes/java/lang/invoke/SimpleMethodHandle.java	Fri Nov 17 11:08:44 2017 +0530
+++ b/src/java.base/share/classes/java/lang/invoke/SimpleMethodHandle.java	Fri Nov 17 02:50:51 2017 +0100
@@ -25,6 +25,8 @@
 
 package java.lang.invoke;
 
+import jdk.internal.vm.annotation.Stable;
+
 import static java.lang.invoke.LambdaForm.BasicType.*;
 import static java.lang.invoke.MethodHandleStatics.*;
 
@@ -33,6 +35,7 @@
  * @author jrose
  */
 final class SimpleMethodHandle extends BoundMethodHandle {
+
     private SimpleMethodHandle(MethodType type, LambdaForm form) {
         super(type, form);
     }
@@ -41,10 +44,11 @@
         return new SimpleMethodHandle(type, form);
     }
 
-    /*non-public*/ static final SpeciesData SPECIES_DATA = SpeciesData.EMPTY;
+    /*non-public*/ static @Stable BoundMethodHandle.SpeciesData BMH_SPECIES;
 
-    /*non-public*/ public SpeciesData speciesData() {
-            return SPECIES_DATA;
+    @Override
+    /*non-public*/ BoundMethodHandle.SpeciesData speciesData() {
+            return BMH_SPECIES;
     }
 
     @Override
@@ -58,18 +62,13 @@
     }
 
     @Override
-    /*non-public*/ public int fieldCount() {
-        return 0;
-    }
-
-    @Override
     /*non-public*/ final BoundMethodHandle copyWithExtendL(MethodType mt, LambdaForm lf, Object narg) {
         return BoundMethodHandle.bindSingle(mt, lf, narg); // Use known fast path.
     }
     @Override
     /*non-public*/ final BoundMethodHandle copyWithExtendI(MethodType mt, LambdaForm lf, int narg) {
         try {
-            return (BoundMethodHandle) SPECIES_DATA.extendWith(I_TYPE).constructor().invokeBasic(mt, lf, narg);
+            return (BoundMethodHandle) BMH_SPECIES.extendWith(I_TYPE_NUM).factory().invokeBasic(mt, lf, narg);
         } catch (Throwable ex) {
             throw uncaughtException(ex);
         }
@@ -77,7 +76,7 @@
     @Override
     /*non-public*/ final BoundMethodHandle copyWithExtendJ(MethodType mt, LambdaForm lf, long narg) {
         try {
-            return (BoundMethodHandle) SPECIES_DATA.extendWith(J_TYPE).constructor().invokeBasic(mt, lf, narg);
+            return (BoundMethodHandle) BMH_SPECIES.extendWith(J_TYPE_NUM).factory().invokeBasic(mt, lf, narg);
         } catch (Throwable ex) {
             throw uncaughtException(ex);
         }
@@ -85,7 +84,7 @@
     @Override
     /*non-public*/ final BoundMethodHandle copyWithExtendF(MethodType mt, LambdaForm lf, float narg) {
         try {
-            return (BoundMethodHandle) SPECIES_DATA.extendWith(F_TYPE).constructor().invokeBasic(mt, lf, narg);
+            return (BoundMethodHandle) BMH_SPECIES.extendWith(F_TYPE_NUM).factory().invokeBasic(mt, lf, narg);
         } catch (Throwable ex) {
             throw uncaughtException(ex);
         }
@@ -93,7 +92,7 @@
     @Override
     /*non-public*/ final BoundMethodHandle copyWithExtendD(MethodType mt, LambdaForm lf, double narg) {
         try {
-            return (BoundMethodHandle) SPECIES_DATA.extendWith(D_TYPE).constructor().invokeBasic(mt, lf, narg);
+            return (BoundMethodHandle) BMH_SPECIES.extendWith(D_TYPE_NUM).factory().invokeBasic(mt, lf, narg);
         } catch (Throwable ex) {
             throw uncaughtException(ex);
         }
--- a/src/java.base/share/classes/java/net/InetAddress.java	Fri Nov 17 11:08:44 2017 +0530
+++ b/src/java.base/share/classes/java/net/InetAddress.java	Fri Nov 17 02:50:51 2017 +0100
@@ -1133,7 +1133,7 @@
 
     /**
      * Create an instance of the NameService interface based on
-     * the setting of the {@codejdk.net.hosts.file} system property.
+     * the setting of the {@code jdk.net.hosts.file} system property.
      *
      * <p>The default NameService is the PlatformNameService, which typically
      * delegates name and address resolution calls to the underlying
--- a/src/java.base/share/classes/java/security/Certificate.java	Fri Nov 17 11:08:44 2017 +0530
+++ b/src/java.base/share/classes/java/security/Certificate.java	Fri Nov 17 02:50:51 2017 +0100
@@ -57,13 +57,12 @@
  *
  * @author Benjamin Renaud
  * @since 1.1
- * @deprecated A new certificate handling package is created in the Java platform.
- *             This Certificate interface is entirely deprecated and
- *             is here to allow for a smooth transition to the new
- *             package.
+ * @deprecated This class is deprecated and subject to removal in a future
+ *     version of Java SE. It has been replaced by
+ *     {@code java.security.cert.Certificate} and related classes.
  * @see java.security.cert.Certificate
  */
-@Deprecated(since="1.2")
+@Deprecated(since="1.2", forRemoval=true)
 public interface Certificate {
 
     /**
--- a/src/java.base/share/classes/java/security/Identity.java	Fri Nov 17 11:08:44 2017 +0530
+++ b/src/java.base/share/classes/java/security/Identity.java	Fri Nov 17 02:50:51 2017 +0100
@@ -52,12 +52,13 @@
  *
  * @author Benjamin Renaud
  * @since 1.1
- * @deprecated This class is no longer used. Its functionality has been
- * replaced by {@code java.security.KeyStore}, the
- * {@code java.security.cert} package, and
- * {@code java.security.Principal}.
+ * @deprecated This class is deprecated and subject to removal in a future
+ *     version of Java SE. It has been replaced by
+ *     {@code java.security.KeyStore}, the {@code java.security.cert} package,
+ *     and {@code java.security.Principal}.
  */
-@Deprecated(since="1.2")
+@Deprecated(since="1.2", forRemoval=true)
+@SuppressWarnings("removal")
 public abstract class Identity implements Principal, Serializable {
 
     /** use serialVersionUID from JDK 1.1.x for interoperability */
--- a/src/java.base/share/classes/java/security/IdentityScope.java	Fri Nov 17 11:08:44 2017 +0530
+++ b/src/java.base/share/classes/java/security/IdentityScope.java	Fri Nov 17 02:50:51 2017 +0100
@@ -57,12 +57,13 @@
  * @author Benjamin Renaud
  * @since 1.1
  *
- * @deprecated This class is no longer used. Its functionality has been
- * replaced by {@code java.security.KeyStore}, the
- * {@code java.security.cert} package, and
- * {@code java.security.Principal}.
+ * @deprecated This class is deprecated and subject to removal in a future
+ *     version of Java SE. It has been replaced by
+ *     {@code java.security.KeyStore}, the {@code java.security.cert} package,
+ *     and {@code java.security.Principal}.
  */
-@Deprecated(since="1.2")
+@Deprecated(since="1.2", forRemoval=true)
+@SuppressWarnings("removal")
 public abstract
 class IdentityScope extends Identity {
 
--- a/src/java.base/share/classes/java/security/Signer.java	Fri Nov 17 11:08:44 2017 +0530
+++ b/src/java.base/share/classes/java/security/Signer.java	Fri Nov 17 02:50:51 2017 +0100
@@ -40,12 +40,13 @@
  * @author Benjamin Renaud
  * @since 1.1
  *
- * @deprecated This class is no longer used. Its functionality has been
- * replaced by {@code java.security.KeyStore}, the
- * {@code java.security.cert} package, and
- * {@code java.security.Principal}.
+ * @deprecated This class is deprecated and subject to removal in a future
+ *     version of Java SE. It has been replaced by
+ *     {@code java.security.KeyStore}, the {@code java.security.cert} package,
+ *     and {@code java.security.Principal}.
  */
-@Deprecated(since="1.2")
+@Deprecated(since="1.2", forRemoval=true)
+@SuppressWarnings("removal")
 public abstract class Signer extends Identity {
 
     private static final long serialVersionUID = -1763464102261361480L;
--- a/src/java.base/share/classes/java/security/acl/Acl.java	Fri Nov 17 11:08:44 2017 +0530
+++ b/src/java.base/share/classes/java/security/acl/Acl.java	Fri Nov 17 02:50:51 2017 +0100
@@ -84,11 +84,13 @@
  * @author Satish Dharmaraj
  * @since 1.1
  *
- * @deprecated This package has been replaced by {@code java.security.Policy}
- *      and related classes since 1.2.
+ * @deprecated This class is deprecated and subject to removal in a future
+ *     version of Java SE. It has been replaced by {@code java.security.Policy}
+ *     and related classes since 1.2.
  */
 
-@Deprecated(since="9")
+@Deprecated(since="9", forRemoval=true)
+@SuppressWarnings("removal")
 public interface Acl extends Owner {
 
     /**
--- a/src/java.base/share/classes/java/security/acl/AclEntry.java	Fri Nov 17 11:08:44 2017 +0530
+++ b/src/java.base/share/classes/java/security/acl/AclEntry.java	Fri Nov 17 02:50:51 2017 +0100
@@ -52,10 +52,12 @@
  * @author      Satish Dharmaraj
  * @since 1.1
  *
- * @deprecated This package has been replaced by {@code java.security.Policy}
- *      and related classes since 1.2.
+ * @deprecated This class is deprecated and subject to removal in a future
+ *     version of Java SE. It has been replaced by {@code java.security.Policy}
+ *     and related classes since 1.2.
  */
-@Deprecated(since="9")
+@Deprecated(since="9", forRemoval=true)
+@SuppressWarnings("removal")
 public interface AclEntry extends Cloneable {
 
     /**
--- a/src/java.base/share/classes/java/security/acl/AclNotFoundException.java	Fri Nov 17 11:08:44 2017 +0530
+++ b/src/java.base/share/classes/java/security/acl/AclNotFoundException.java	Fri Nov 17 02:50:51 2017 +0100
@@ -32,10 +32,11 @@
  * @author      Satish Dharmaraj
  * @since 1.1
  *
- * @deprecated This package has been replaced by {@code java.security.Policy}
- *      and related classes since 1.2.
+ * @deprecated This class is deprecated and subject to removal in a future
+ *     version of Java SE. It has been replaced by {@code java.security.Policy}
+ *     and related classes since 1.2.
  */
-@Deprecated(since="9")
+@Deprecated(since="9", forRemoval=true)
 public class AclNotFoundException extends Exception {
 
     private static final long serialVersionUID = 5684295034092681791L;
--- a/src/java.base/share/classes/java/security/acl/Group.java	Fri Nov 17 11:08:44 2017 +0530
+++ b/src/java.base/share/classes/java/security/acl/Group.java	Fri Nov 17 02:50:51 2017 +0100
@@ -41,10 +41,11 @@
  * @author      Satish Dharmaraj
  * @since 1.1
  *
- * @deprecated This package has been replaced by {@code java.security.Policy}
- *      and related classes since 1.2.
+ * @deprecated This class is deprecated and subject to removal in a future
+ *     version of Java SE. It has been replaced by {@code java.security.Policy}
+ *     and related classes since 1.2.
  */
-@Deprecated(since="9")
+@Deprecated(since="9", forRemoval=true)
 public interface Group extends Principal {
 
     /**
--- a/src/java.base/share/classes/java/security/acl/LastOwnerException.java	Fri Nov 17 11:08:44 2017 +0530
+++ b/src/java.base/share/classes/java/security/acl/LastOwnerException.java	Fri Nov 17 02:50:51 2017 +0100
@@ -34,10 +34,11 @@
  * @author Satish Dharmaraj
  * @since 1.1
  *
- * @deprecated This package has been replaced by {@code java.security.Policy}
- *      and related classes since 1.2.
+ * @deprecated This class is deprecated and subject to removal in a future
+ *     version of Java SE. It has been replaced by {@code java.security.Policy}
+ *     and related classes since 1.2.
  */
-@Deprecated(since="9")
+@Deprecated(since="9", forRemoval=true)
 public class LastOwnerException extends Exception {
 
     private static final long serialVersionUID = -5141997548211140359L;
--- a/src/java.base/share/classes/java/security/acl/NotOwnerException.java	Fri Nov 17 11:08:44 2017 +0530
+++ b/src/java.base/share/classes/java/security/acl/NotOwnerException.java	Fri Nov 17 02:50:51 2017 +0100
@@ -33,10 +33,11 @@
  * @author      Satish Dharmaraj
  * @since 1.1
  *
- * @deprecated This package has been replaced by {@code java.security.Policy}
- *      and related classes since 1.2.
+ * @deprecated This class is deprecated and subject to removal in a future
+ *     version of Java SE. It has been replaced by {@code java.security.Policy}
+ *     and related classes since 1.2.
  */
-@Deprecated(since="9")
+@Deprecated(since="9", forRemoval=true)
 public class NotOwnerException extends Exception {
 
     private static final long serialVersionUID = -5555597911163362399L;
--- a/src/java.base/share/classes/java/security/acl/Owner.java	Fri Nov 17 11:08:44 2017 +0530
+++ b/src/java.base/share/classes/java/security/acl/Owner.java	Fri Nov 17 02:50:51 2017 +0100
@@ -37,10 +37,12 @@
  * @since 1.1
  * @see java.security.acl.Acl
  *
- * @deprecated This package has been replaced by {@code java.security.Policy}
- *      and related classes since 1.2.
+ * @deprecated This class is deprecated and subject to removal in a future
+ *     version of Java SE. It has been replaced by {@code java.security.Policy}
+ *     and related classes since 1.2.
  */
-@Deprecated(since="9")
+@Deprecated(since="9", forRemoval=true)
+@SuppressWarnings("removal")
 public interface Owner {
 
     /**
--- a/src/java.base/share/classes/java/security/acl/Permission.java	Fri Nov 17 11:08:44 2017 +0530
+++ b/src/java.base/share/classes/java/security/acl/Permission.java	Fri Nov 17 02:50:51 2017 +0100
@@ -33,10 +33,11 @@
  * @author Satish Dharmaraj
  * @since 1.1
  *
- * @deprecated This package has been replaced by {@code java.security.Policy}
- *      and related classes since 1.2.
+ * @deprecated This class is deprecated and subject to removal in a future
+ *     version of Java SE. It has been replaced by {@code java.security.Policy}
+ *     and related classes since 1.2.
  */
-@Deprecated(since="9")
+@Deprecated(since="9", forRemoval=true)
 public interface Permission {
 
     /**
--- a/src/java.base/share/classes/java/security/acl/package-info.java	Fri Nov 17 11:08:44 2017 +0530
+++ b/src/java.base/share/classes/java/security/acl/package-info.java	Fri Nov 17 02:50:51 2017 +0100
@@ -27,7 +27,8 @@
  * The classes and interfaces in this package have been deprecated. New
  * classes should not be added to this package. The {@code java.security}
  * package contains suitable replacements. See {@link java.security.Policy}
- * and related classes for details.
+ * and related classes for details. This package is subject to removal in a
+ * future version of Java SE.
  *
  * @since 1.1
  */
--- a/src/java.base/share/classes/java/util/stream/AbstractTask.java	Fri Nov 17 11:08:44 2017 +0530
+++ b/src/java.base/share/classes/java/util/stream/AbstractTask.java	Fri Nov 17 02:50:51 2017 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2017, 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
@@ -27,6 +27,7 @@
 import java.util.Spliterator;
 import java.util.concurrent.CountedCompleter;
 import java.util.concurrent.ForkJoinPool;
+import java.util.concurrent.ForkJoinWorkerThread;
 
 /**
  * Abstract base class for most fork-join tasks used to implement stream ops.
@@ -88,13 +89,7 @@
                             K extends AbstractTask<P_IN, P_OUT, R, K>>
         extends CountedCompleter<R> {
 
-    /**
-     * Default target factor of leaf tasks for parallel decomposition.
-     * To allow load balancing, we over-partition, currently to approximately
-     * four tasks per processor, which enables others to help out
-     * if leaf tasks are uneven or some processors are otherwise busy.
-     */
-    static final int LEAF_TARGET = ForkJoinPool.getCommonPoolParallelism() << 2;
+    private static final int LEAF_TARGET = ForkJoinPool.getCommonPoolParallelism() << 2;
 
     /** The pipeline helper, common to all tasks in a computation */
     protected final PipelineHelper<P_OUT> helper;
@@ -157,6 +152,22 @@
     }
 
     /**
+     * Default target of leaf tasks for parallel decomposition.
+     * To allow load balancing, we over-partition, currently to approximately
+     * four tasks per processor, which enables others to help out
+     * if leaf tasks are uneven or some processors are otherwise busy.
+     */
+    public static int getLeafTarget() {
+        Thread t = Thread.currentThread();
+        if (t instanceof ForkJoinWorkerThread) {
+            return ((ForkJoinWorkerThread) t).getPool().getParallelism() << 2;
+        }
+        else {
+            return LEAF_TARGET;
+        }
+    }
+
+    /**
      * Constructs a new node of type T whose parent is the receiver; must call
      * the AbstractTask(T, Spliterator) constructor with the receiver and the
      * provided Spliterator.
@@ -181,7 +192,7 @@
      * @return suggested target leaf size
      */
     public static long suggestTargetSize(long sizeEstimate) {
-        long est = sizeEstimate / LEAF_TARGET;
+        long est = sizeEstimate / getLeafTarget();
         return est > 0L ? est : 1L;
     }
 
--- a/src/java.base/share/classes/java/util/stream/ForEachOps.java	Fri Nov 17 11:08:44 2017 +0530
+++ b/src/java.base/share/classes/java/util/stream/ForEachOps.java	Fri Nov 17 02:50:51 2017 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2017, 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
@@ -28,7 +28,6 @@
 import java.util.Spliterator;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.CountedCompleter;
-import java.util.concurrent.ForkJoinTask;
 import java.util.function.Consumer;
 import java.util.function.DoubleConsumer;
 import java.util.function.IntConsumer;
@@ -378,7 +377,7 @@
             this.spliterator = spliterator;
             this.targetSize = AbstractTask.suggestTargetSize(spliterator.estimateSize());
             // Size map to avoid concurrent re-sizes
-            this.completionMap = new ConcurrentHashMap<>(Math.max(16, AbstractTask.LEAF_TARGET << 1));
+            this.completionMap = new ConcurrentHashMap<>(Math.max(16, AbstractTask.getLeafTarget() << 1));
             this.action = action;
             this.leftPredecessor = null;
         }
--- a/src/java.base/share/classes/java/util/stream/StreamSpliterators.java	Fri Nov 17 11:08:44 2017 +0530
+++ b/src/java.base/share/classes/java/util/stream/StreamSpliterators.java	Fri Nov 17 02:50:51 2017 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2017, 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
@@ -897,7 +897,7 @@
      * Note: The source spliterator may report {@code ORDERED} since that
      * spliterator be the result of a previous pipeline stage that was
      * collected to a {@code Node}. It is the order of the pipeline stage
-     * that governs whether the this slice spliterator is to be used or not.
+     * that governs whether this slice spliterator is to be used or not.
      */
     abstract static class UnorderedSliceSpliterator<T, T_SPLITR extends Spliterator<T>> {
         static final int CHUNK_SIZE = 1 << 7;
@@ -914,7 +914,7 @@
             this.unlimited = limit < 0;
             this.skipThreshold = limit >= 0 ? limit : 0;
             this.chunkSize = limit >= 0 ? (int)Math.min(CHUNK_SIZE,
-                ((skip + limit) / AbstractTask.LEAF_TARGET) + 1) : CHUNK_SIZE;
+                                                        ((skip + limit) / AbstractTask.getLeafTarget()) + 1) : CHUNK_SIZE;
             this.permits = new AtomicLong(limit >= 0 ? skip + limit : skip);
         }
 
--- a/src/java.base/share/classes/sun/security/tools/keytool/Resources.java	Fri Nov 17 11:08:44 2017 +0530
+++ b/src/java.base/share/classes/sun/security/tools/keytool/Resources.java	Fri Nov 17 02:50:51 2017 +0100
@@ -456,21 +456,21 @@
         {"the.tsa.certificate", "The TSA certificate"},
         {"the.input", "The input"},
         {"reply", "Reply"},
-        {"one.in.many", "%s #%d of %d"},
+        {"one.in.many", "%1$s #%2$d of %3$d"},
         {"alias.in.cacerts", "Issuer <%s> in cacerts"},
         {"alias.in.keystore", "Issuer <%s>"},
         {"with.weak", "%s (weak)"},
-        {"key.bit", "%d-bit %s key"},
-        {"key.bit.weak", "%d-bit %s key (weak)"},
+        {"key.bit", "%1$d-bit %2$s key"},
+        {"key.bit.weak", "%1$d-bit %2$s key (weak)"},
         {"unknown.size.1", "unknown size %s key"},
         {".PATTERN.printX509Cert.with.weak",
                 "Owner: {0}\nIssuer: {1}\nSerial number: {2}\nValid from: {3} until: {4}\nCertificate fingerprints:\n\t SHA1: {5}\n\t SHA256: {6}\nSignature algorithm name: {7}\nSubject Public Key Algorithm: {8}\nVersion: {9}"},
         {"PKCS.10.with.weak",
                 "PKCS #10 Certificate Request (Version 1.0)\n" +
-                        "Subject: %s\nFormat: %s\nPublic Key: %s\nSignature algorithm: %s\n"},
-        {"verified.by.s.in.s.weak", "Verified by %s in %s with a %s"},
-        {"whose.sigalg.risk", "%s uses the %s signature algorithm which is considered a security risk."},
-        {"whose.key.risk", "%s uses a %s which is considered a security risk."},
+                        "Subject: %1$s\nFormat: %2$s\nPublic Key: %3$s\nSignature algorithm: %4$s\n"},
+        {"verified.by.s.in.s.weak", "Verified by %1$s in %2$s with a %3$s"},
+        {"whose.sigalg.risk", "%1$s uses the %2$s signature algorithm which is considered a security risk."},
+        {"whose.key.risk", "%1$s uses a %2$s which is considered a security risk."},
         {"jks.storetype.warning", "The %1$s keystore uses a proprietary format. It is recommended to migrate to PKCS12 which is an industry standard format using \"keytool -importkeystore -srckeystore %2$s -destkeystore %2$s -deststoretype pkcs12\"."},
         {"migrate.keystore.warning", "Migrated \"%1$s\" to %4$s. The %2$s keystore is backed up as \"%3$s\"."},
         {"backup.keystore.warning", "The original keystore \"%1$s\" is backed up as \"%3$s\"..."},
--- a/src/java.scripting/share/classes/javax/script/ScriptEngineFactory.java	Fri Nov 17 11:08:44 2017 +0530
+++ b/src/java.scripting/share/classes/javax/script/ScriptEngineFactory.java	Fri Nov 17 02:50:51 2017 +0100
@@ -176,6 +176,8 @@
      * @param args names of the arguments in the method call.
      *
      * @return The String used to invoke the method in the syntax of the scripting language.
+     *
+     * @throws NullPointerException if obj or m or args or any of the elements of args is null.
      */
     public String getMethodCallSyntax(String obj, String m, String... args);
 
--- a/src/java.xml/share/classes/javax/xml/xpath/XPathFunction.java	Fri Nov 17 11:08:44 2017 +0530
+++ b/src/java.xml/share/classes/javax/xml/xpath/XPathFunction.java	Fri Nov 17 02:50:51 2017 +0100
@@ -51,6 +51,6 @@
    *
    * @throws XPathFunctionException If <code>args</code> cannot be evaluated with this <code>XPath</code> function.
    */
-  public Object evaluate(List<Object> args)
+  public Object evaluate(List<?> args)
     throws XPathFunctionException;
 }
--- a/src/jdk.jartool/share/classes/sun/security/tools/jarsigner/Resources.java	Fri Nov 17 11:08:44 2017 +0530
+++ b/src/jdk.jartool/share/classes/sun/security/tools/jarsigner/Resources.java	Fri Nov 17 02:50:51 2017 +0100
@@ -270,7 +270,7 @@
         {"The.1.algorithm.specified.for.the.2.option.is.considered.a.security.risk.",
                 "The %1$s algorithm specified for the %2$s option is considered a security risk."},
         {"The.1.signing.key.has.a.keysize.of.2.which.is.considered.a.security.risk.",
-                "The %s signing key has a keysize of %d which is considered a security risk."},
+                "The %1$s signing key has a keysize of %2$d which is considered a security risk."},
         {"This.jar.contains.entries.whose.certificate.chain.is.invalid.reason.1",
                  "This jar contains entries whose certificate chain is invalid. Reason: %s"},
         {"This.jar.contains.entries.whose.tsa.certificate.chain.is.invalid.reason.1",
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/FrameOutputWriter.java	Fri Nov 17 11:08:44 2017 +0530
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/FrameOutputWriter.java	Fri Nov 17 02:50:51 2017 +0100
@@ -139,7 +139,7 @@
         head.addContent(windowTitle);
         Content meta = HtmlTree.META("Content-Type", CONTENT_TYPE, configuration.charset);
         head.addContent(meta);
-        head.addContent(getStyleSheetProperties(configuration));
+        addStyleSheetProperties(configuration, head);
         head.addContent(getFramesJavaScript());
         Content htmlTree = HtmlTree.HTML(configuration.getLocale().getLanguage(),
                 head, body);
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlConfiguration.java	Fri Nov 17 11:08:44 2017 +0530
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlConfiguration.java	Fri Nov 17 02:50:51 2017 +0100
@@ -133,6 +133,11 @@
     public String stylesheetfile = "";
 
     /**
+     * Argument for command line option "--add-stylesheet".
+     */
+    public List<String> additionalStylesheets = new ArrayList<>();
+
+    /**
      * Argument for command line option "-Xdocrootparent".
      */
     public String docrootparent = "";
@@ -304,6 +309,22 @@
                 return false;
             }
         }
+        // check if stylesheetfile exists
+        if (!stylesheetfile.isEmpty()) {
+            DocFile stylesheet = DocFile.createFileForInput(this, stylesheetfile);
+            if (!stylesheet.exists()) {
+                reporter.print(ERROR, getText("doclet.File_not_found", stylesheetfile));
+                return false;
+            }
+        }
+        // check if additional stylesheets exists
+        for (String ssheet : additionalStylesheets) {
+            DocFile ssfile = DocFile.createFileForInput(this, ssheet);
+            if (!ssfile.exists()) {
+                reporter.print(ERROR, getText("doclet.File_not_found", ssheet));
+                return false;
+            }
+        }
 
         // In a more object-oriented world, this would be done by methods on the Option objects.
         // Note that -windowtitle silently removes any and all HTML elements, and so does not need
@@ -554,6 +575,13 @@
     public Set<Doclet.Option> getSupportedOptions() {
         Resources resources = getResources();
         Doclet.Option[] options = {
+            new Option(resources, "--add-stylesheet", 1) {
+                @Override
+                public boolean process(String opt, List<String> args) {
+                    additionalStylesheets.add(args.get(0));
+                    return true;
+                }
+            },
             new Option(resources, "-bottom", 1) {
                 @Override
                 public boolean process(String opt,  List<String> args) {
@@ -722,7 +750,7 @@
                     return true;
                 }
             },
-            new Option(resources, "-stylesheetfile", 1) {
+            new Option(resources, "--main-stylesheet -stylesheetfile", 1) {
                 @Override
                 public boolean process(String opt,  List<String> args) {
                     stylesheetfile = args.get(0);
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlDoclet.java	Fri Nov 17 11:08:44 2017 +0530
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlDoclet.java	Fri Nov 17 02:50:51 2017 +0100
@@ -125,6 +125,9 @@
         boolean nodeprecated = configuration.nodeprecated;
         performCopy(configuration.helpfile);
         performCopy(configuration.stylesheetfile);
+        for (String stylesheet : configuration.additionalStylesheets) {
+            performCopy(stylesheet);
+        }
         // do early to reduce memory footprint
         if (configuration.classuse) {
             ClassUseWriter.generate(configuration, classtree);
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlDocletWriter.java	Fri Nov 17 11:08:44 2017 +0530
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlDocletWriter.java	Fri Nov 17 02:50:51 2017 +0100
@@ -2162,6 +2162,7 @@
                 pathToRoot.resolve(stylesheet).getPath(),
                 "Style");
         head.addContent(link);
+        addStylesheets(configuration, head);
         if (configuration.createindex) {
             HtmlTree jq_link = HtmlTree.LINK("stylesheet", "text/css",
                     pathToRoot.resolve(DocPaths.JQUERY_FILES.resolve(DocPaths.JQUERY_STYLESHEET_FILE)).getPath(),
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/IndexRedirectWriter.java	Fri Nov 17 11:08:44 2017 +0530
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/IndexRedirectWriter.java	Fri Nov 17 02:50:51 2017 +0100
@@ -94,7 +94,7 @@
             head.addContent(metaRefresh);
         }
 
-        head.addContent(getStyleSheetProperties(configuration));
+        addStyleSheetProperties(configuration, head);
 
         ContentBuilder bodyContent = new ContentBuilder();
         bodyContent.addContent(HtmlTree.NOSCRIPT(
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SourceToHTMLConverter.java	Fri Nov 17 11:08:44 2017 +0530
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SourceToHTMLConverter.java	Fri Nov 17 02:50:51 2017 +0100
@@ -26,6 +26,7 @@
 package jdk.javadoc.internal.doclets.formats.html;
 
 import java.io.*;
+import java.util.List;
 
 import javax.lang.model.element.Element;
 import javax.lang.model.element.PackageElement;
@@ -210,7 +211,7 @@
         Content head = new HtmlTree(HtmlTag.HEAD);
         head.addContent(HtmlTree.TITLE(new StringContent(
                 configuration.getText("doclet.Window_Source_title"))));
-        head.addContent(getStyleSheetProperties());
+        addStyleSheetProperties(head);
         Content htmlTree = HtmlTree.HTML(configuration.getLocale().getLanguage(),
                 head, body);
         Content htmlDocument = new HtmlDocument(htmlDocType, htmlTree);
@@ -227,9 +228,9 @@
     /**
      * Returns a link to the stylesheet file.
      *
-     * @return an HtmlTree for the lINK tag which provides the stylesheet location
+     * @param head an HtmlTree to which the stylesheet links will be added
      */
-    public HtmlTree getStyleSheetProperties() {
+    public void addStyleSheetProperties(Content head) {
         String filename = configuration.stylesheetfile;
         DocPath stylesheet;
         if (filename.length() > 0) {
@@ -240,7 +241,21 @@
         }
         DocPath p = relativePath.resolve(stylesheet);
         HtmlTree link = HtmlTree.LINK("stylesheet", "text/css", p.getPath(), "Style");
-        return link;
+        head.addContent(link);
+        addStylesheets(head);
+    }
+
+    protected void addStylesheets(Content tree) {
+        List<String> stylesheets = configuration.additionalStylesheets;
+        if (!stylesheets.isEmpty()) {
+            stylesheets.forEach((ssheet) -> {
+                DocFile file = DocFile.createFileForInput(configuration, ssheet);
+                DocPath ssheetPath = DocPath.create(file.getName());
+                HtmlTree slink = HtmlTree.LINK("stylesheet", "text/css", relativePath.resolve(ssheetPath).getPath(),
+                        "Style");
+                tree.addContent(slink);
+            });
+        }
     }
 
     /**
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/HtmlDocWriter.java	Fri Nov 17 11:08:44 2017 +0530
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/HtmlDocWriter.java	Fri Nov 17 02:50:51 2017 +0100
@@ -311,9 +311,9 @@
      * Returns a link to the stylesheet file.
      *
      * @param configuration the configuration for this doclet
-     * @return an HtmlTree for the lINK tag which provides the stylesheet location
+     * @param head HtmlTree to which the stylesheet links will be added
      */
-    public HtmlTree getStyleSheetProperties(HtmlConfiguration configuration) {
+    public void addStyleSheetProperties(HtmlConfiguration configuration, Content head) {
         String stylesheetfile = configuration.stylesheetfile;
         DocPath stylesheet;
         if (stylesheetfile.isEmpty()) {
@@ -325,7 +325,21 @@
         HtmlTree link = HtmlTree.LINK("stylesheet", "text/css",
                 pathToRoot.resolve(stylesheet).getPath(),
                 "Style");
-        return link;
+        head.addContent(link);
+        addStylesheets(configuration, head);
+    }
+
+    protected void addStylesheets(HtmlConfiguration configuration, Content tree) {
+        List<String> stylesheets = configuration.additionalStylesheets;
+        if (!stylesheets.isEmpty()) {
+            stylesheets.forEach((ssheet) -> {
+                DocFile file = DocFile.createFileForInput(configuration, ssheet);
+                DocPath ssheetPath = DocPath.create(file.getName());
+                HtmlTree slink = HtmlTree.LINK("stylesheet", "text/css", pathToRoot.resolve(ssheetPath).getPath(),
+                        "Style");
+                tree.addContent(slink);
+            });
+        }
     }
 
     protected Comment getGeneratedBy(boolean timestamp) {
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/resources/standard.properties	Fri Nov 17 11:08:44 2017 +0530
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/resources/standard.properties	Fri Nov 17 02:50:51 2017 +0100
@@ -175,6 +175,10 @@
 doclet.Same_element_name_used=Element name or pattern used twice: {0}
 
 # option specifiers
+doclet.usage.add-stylesheet.parameters=\
+    <file>
+doclet.usage.add-stylesheet.description=\
+    Additional stylesheet file for the generated documentation
 doclet.usage.d.parameters=\
     <directory>
 doclet.usage.d.description=\
@@ -329,9 +333,9 @@
 doclet.usage.keywords.description=\
     Include HTML meta tags with package, class and member info
 
-doclet.usage.stylesheetfile.parameters=\
-    <path>
-doclet.usage.stylesheetfile.description=\
+doclet.usage.main-stylesheet.parameters=\
+    <file>
+doclet.usage.main-stylesheet.description=\
     File to change style of the generated documentation
 
 doclet.usage.docencoding.parameters=\
--- a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/JarArchive.java	Fri Nov 17 11:08:44 2017 +0530
+++ b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/JarArchive.java	Fri Nov 17 02:50:51 2017 +0100
@@ -74,14 +74,16 @@
 
     private final Path file;
     private final String moduleName;
+    private final Runtime.Version version;
     // currently processed JarFile
     private JarFile jarFile;
 
-    protected JarArchive(String mn, Path file) {
+    protected JarArchive(String mn, Path file, Runtime.Version version) {
         Objects.requireNonNull(mn);
         Objects.requireNonNull(file);
         this.moduleName = mn;
         this.file = file;
+        this.version = Objects.requireNonNull(version);
     }
 
     @Override
@@ -126,7 +128,7 @@
         if (jarFile != null) {
             jarFile.close();
         }
-        jarFile = new JarFile(file.toFile(), true, ZipFile.OPEN_READ, JarFile.runtimeVersion());
+        jarFile = new JarFile(file.toFile(), true, ZipFile.OPEN_READ, version);
     }
 
     protected JarFile getJarFile() {
--- a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/JlinkTask.java	Fri Nov 17 11:08:44 2017 +0530
+++ b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/JlinkTask.java	Fri Nov 17 02:50:51 2017 +0100
@@ -421,6 +421,9 @@
      * the observable modules to those in the transitive closure of
      * the modules specified in {@code limitMods} plus other modules
      * specified in the {@code roots} set.
+     *
+     * @throws IllegalArgumentException if java.base module is present
+     * but its descriptor has no version
      */
     public static ModuleFinder newModuleFinder(List<Path> paths,
                                                Set<String> limitMods,
@@ -429,8 +432,25 @@
         if (Objects.requireNonNull(paths).isEmpty()) {
              throw new IllegalArgumentException("Empty module path");
         }
+
         Path[] entries = paths.toArray(new Path[0]);
-        ModuleFinder finder = ModulePath.of(Runtime.version(), true, entries);
+        Runtime.Version version = Runtime.version();
+        ModuleFinder finder = ModulePath.of(version, true, entries);
+
+        if (finder.find("java.base").isPresent()) {
+            // use the version of java.base module, if present, as
+            // the release version for multi-release JAR files
+            ModuleDescriptor.Version v = finder.find("java.base").get()
+                .descriptor().version().orElseThrow(() ->
+                    new IllegalArgumentException("No version in java.base descriptor")
+                );
+
+            // java.base version is different than the current runtime version
+            version = Runtime.Version.parse(v.toString());
+            if (Runtime.version().major() != version.major()) {
+                finder = ModulePath.of(version, true, entries);
+            }
+        }
 
         // if limitmods is specified then limit the universe
         if (limitMods != null && !limitMods.isEmpty()) {
@@ -744,6 +764,7 @@
         final ByteOrder order;
         final Path packagedModulesPath;
         final boolean ignoreSigning;
+        final Runtime.Version version;
         final Set<Archive> archives;
 
         ImageHelper(Configuration cf,
@@ -754,6 +775,17 @@
             this.order = order;
             this.packagedModulesPath = packagedModulesPath;
             this.ignoreSigning = ignoreSigning;
+
+            // use the version of java.base module, if present, as
+            // the release version for multi-release JAR files
+            this.version = cf.findModule("java.base")
+                .map(ResolvedModule::reference)
+                .map(ModuleReference::descriptor)
+                .flatMap(ModuleDescriptor::version)
+                .map(ModuleDescriptor.Version::toString)
+                .map(Runtime.Version::parse)
+                .orElse(Runtime.version());
+
             this.archives = modsPaths.entrySet().stream()
                                 .map(e -> newArchive(e.getKey(), e.getValue()))
                                 .collect(Collectors.toSet());
@@ -763,7 +795,7 @@
             if (path.toString().endsWith(".jmod")) {
                 return new JmodArchive(module, path);
             } else if (path.toString().endsWith(".jar")) {
-                ModularJarArchive modularJarArchive = new ModularJarArchive(module, path);
+                ModularJarArchive modularJarArchive = new ModularJarArchive(module, path, version);
 
                 Stream<Archive.Entry> signatures = modularJarArchive.entries().filter((entry) -> {
                     String name = entry.name().toUpperCase(Locale.ENGLISH);
--- a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ModularJarArchive.java	Fri Nov 17 11:08:44 2017 +0530
+++ b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ModularJarArchive.java	Fri Nov 17 02:50:51 2017 +0100
@@ -39,8 +39,8 @@
     private static final String JAR_EXT = ".jar";
     private static final String MODULE_INFO = "module-info.class";
 
-    public ModularJarArchive(String mn, Path jmod) {
-        super(mn, jmod);
+    public ModularJarArchive(String mn, Path jmod, Runtime.Version version) {
+        super(mn, jmod, version);
         String filename = Objects.requireNonNull(jmod.getFileName()).toString();
         if (!filename.endsWith(JAR_EXT)) {
             throw new UnsupportedOperationException("Unsupported format: " + filename);
--- a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/GenerateJLIClassesPlugin.java	Fri Nov 17 11:08:44 2017 +0530
+++ b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/GenerateJLIClassesPlugin.java	Fri Nov 17 02:50:51 2017 +0100
@@ -242,8 +242,14 @@
         lines.map(line -> line.split(" "))
              .forEach(parts -> {
                 switch (parts[0]) {
-                    case "[BMH_RESOLVE]":
-                        speciesTypes.add(expandSignature(parts[1]));
+                    case "[SPECIES_RESOLVE]":
+                        // Allow for new types of species data classes being resolved here
+                        if (parts.length == 3 && parts[1].startsWith("java.lang.invoke.BoundMethodHandle$Species_")) {
+                            String species = parts[1].substring("java.lang.invoke.BoundMethodHandle$Species_".length());
+                            if (!"L".equals(species)) {
+                                speciesTypes.add(expandSignature(species));
+                            }
+                        }
                         break;
                     case "[LF_RESOLVE]":
                         String methodType = parts[3];
@@ -449,7 +455,7 @@
             "/java.base/" + INVOKERS_HOLDER + ".class";
 
     // Convert LL -> LL, L3 -> LLL
-    private static String expandSignature(String signature) {
+    public static String expandSignature(String signature) {
         StringBuilder sb = new StringBuilder();
         char last = 'X';
         int count = 0;
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/scripting/NashornScriptEngineFactory.java	Fri Nov 17 11:08:44 2017 +0530
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/scripting/NashornScriptEngineFactory.java	Fri Nov 17 02:50:51 2017 +0100
@@ -76,14 +76,16 @@
 
     @Override
     public String getMethodCallSyntax(final String obj, final String method, final String... args) {
-        final StringBuilder sb = new StringBuilder().append(obj).append('.').append(method).append('(');
+        final StringBuilder sb = new StringBuilder().
+            append(Objects.requireNonNull(obj)).append('.').
+            append(Objects.requireNonNull(method)).append('(');
         final int len = args.length;
 
         if (len > 0) {
-            sb.append(args[0]);
+            sb.append(Objects.requireNonNull(args[0]));
         }
         for (int i = 1; i < len; i++) {
-            sb.append(',').append(args[i]);
+            sb.append(',').append(Objects.requireNonNull(args[i]));
         }
         sb.append(')');
 
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeMath.java	Fri Nov 17 11:08:44 2017 +0530
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeMath.java	Fri Nov 17 02:50:51 2017 +0100
@@ -105,8 +105,8 @@
      * @return abs of argument
      */
     @SpecializedFunction
-    public static int abs(final Object self, final int x) {
-        return Math.abs(x);
+    public static double abs(final Object self, final int x) {
+        return x == Integer.MIN_VALUE? Math.abs((double)x) : Math.abs(x);
     }
 
     /**
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ScriptObject.java	Fri Nov 17 11:08:44 2017 +0530
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ScriptObject.java	Fri Nov 17 02:50:51 2017 +0100
@@ -2050,7 +2050,7 @@
 
         final PropertyMap newMap = oldMap.replaceProperty(property, property.removeFlags(Property.NEEDS_DECLARATION));
         setMap(newMap);
-        set(key, value, 0);
+        set(key, value, NashornCallSiteDescriptor.CALLSITE_DECLARE);
     }
 
     /**
@@ -3071,7 +3071,7 @@
         }
 
         if (f != null) {
-            if (!f.getProperty().isWritable() || !f.getProperty().hasNativeSetter()) {
+            if ((!f.getProperty().isWritable() && !NashornCallSiteDescriptor.isDeclaration(callSiteFlags)) || !f.getProperty().hasNativeSetter()) {
                 if (isScopeFlag(callSiteFlags) && f.getProperty().isLexicalBinding()) {
                     throw typeError("assign.constant", key.toString()); // Overwriting ES6 const should throw also in non-strict mode.
                 }
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/NashornCallSiteDescriptor.java	Fri Nov 17 11:08:44 2017 +0530
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/NashornCallSiteDescriptor.java	Fri Nov 17 02:50:51 2017 +0100
@@ -505,6 +505,15 @@
     }
 
     /**
+     * Returns true if {@code flags} has the {@link  #CALLSITE_DECLARE} bit set.
+     * @param flags the flags
+     * @return true if the flag is set, false otherwise.
+     */
+    public static boolean isDeclaration(final int flags) {
+        return (flags & CALLSITE_DECLARE) != 0;
+    }
+
+    /**
      * Get a program point from a descriptor (must be optimistic)
      * @param desc descriptor
      * @return program point
--- a/test/jdk/ProblemList.txt	Fri Nov 17 11:08:44 2017 +0530
+++ b/test/jdk/ProblemList.txt	Fri Nov 17 02:50:51 2017 +0100
@@ -174,6 +174,8 @@
 
 java/net/DatagramSocket/SendDatagramToBadAddress.java           7143960 macosx-all
 
+java/net/httpclient/websocket/ConnectionHandover.java           8188895 windows-all
+
 ############################################################################
 
 # jdk_nio
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/java/lang/invoke/ClassSpecializerTest.java	Fri Nov 17 02:50:51 2017 +0100
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2017, 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.
+ *
+ * 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.
+ */
+
+/* @test
+ * @summary Smoke-test class specializer, used to create BoundMethodHandle classes
+ * @compile/module=java.base java/lang/invoke/ClassSpecializerHelper.java
+ * @run testng/othervm/timeout=250 -ea -esa ClassSpecializerTest
+ */
+
+// Useful diagnostics to try:
+//   -Djava.lang.invoke.MethodHandle.TRACE_RESOLVE=true
+//   -Djava.lang.invoke.MethodHandle.DUMP_CLASS_FILES=true
+
+
+import org.testng.annotations.*;
+import java.lang.invoke.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import static java.lang.invoke.ClassSpecializerHelper.*;
+
+
+public class ClassSpecializerTest {
+    @Test
+    public void testFindSpecies() throws Throwable {
+        System.out.println("testFindSpecies");
+        System.out.println("test = " + SPEC_TEST);
+        ArrayList<Object> args = new ArrayList<>();
+        for (int key = 0; key <= Kind.MAX_KEY; key++) {
+            Kind k = SpecTest.kind(key);
+            System.out.println("k = " + k);
+            MethodHandle mh = k.factory();
+            System.out.println("k.f = " + mh);
+            args.clear();
+            for (Class<?> pt : mh.type().parameterList()) {
+                args.add(coughUpA(pt));
+            }
+            args.set(0, key * 1000 + 42);
+            Frob f = (Frob) mh.invokeWithArguments(args.toArray());
+            assert(f.kind() == k);
+            System.out.println("k.f(...) = " + f.toString());
+            List<Object> l = f.asList();
+            System.out.println("f.l = " + l);
+            args.subList(0,1).clear();  // drop label
+            assert(args.equals(l));
+        }
+    }
+    private static Object coughUpA(Class<?> pt) throws Throwable {
+        if (pt == String.class)  return "foo";
+        if (pt.isArray()) return java.lang.reflect.Array.newInstance(pt.getComponentType(), 2);
+        if (pt == Integer.class)  return 42;
+        if (pt == Double.class)  return 3.14;
+        if (pt.isAssignableFrom(List.class))
+            return Arrays.asList("hello", "world", "from", pt.getSimpleName());
+        return MethodHandles.zero(pt).invoke();
+    }
+    public static void main(String... av) throws Throwable {
+        System.out.println("TEST: ClassSpecializerTest");
+        new ClassSpecializerTest().testFindSpecies();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/java/lang/invoke/java.base/java/lang/invoke/ClassSpecializerHelper.java	Fri Nov 17 02:50:51 2017 +0100
@@ -0,0 +1,155 @@
+/*
+ * Copyright (c) 2017, 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.
+ *
+ * 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 java.lang.invoke;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import static java.lang.invoke.MethodHandleNatives.Constants.*;
+
+/**
+ * Helper class, injected into java.lang.invoke,
+ * that bridges to the private ClassSpecializer mechanism.
+ */
+
+public interface ClassSpecializerHelper {
+    interface Frob {
+        Kind kind();
+        int label();
+        List<Object> asList();
+    }
+    abstract class FrobImpl implements Frob {
+        private final int label;
+        public FrobImpl(int label) {
+            this.label = label;
+        }
+        public int label() { return label; }
+        @Override public abstract Kind kind();
+
+        public String toString() {
+            final StringBuilder buf = new StringBuilder();
+            buf.append("Frob[label=").append(label);
+            final Kind k = kind();
+            if (k != null) {
+                for (MethodHandle mh : k.getters()) {
+                    Object x = "?";
+                    try {
+                        x = mh.invoke(this);
+                    } catch (Throwable ex) {
+                        x = "<<"+ex.getMessage()+">>";
+                    }
+                    buf.append(", ").append(x);
+                }
+            }
+            buf.append("]");
+            return buf.toString();
+        }
+
+        public List<Object> asList() {
+            final List<MethodHandle> getters = kind().getters();
+            ArrayList<Object> res = new ArrayList<>(getters.size());
+            for (MethodHandle getter : getters) {
+                try {
+                    res.add(getter.invoke(this));
+                } catch (Throwable ex) {
+                    throw new AssertionError(ex);
+                }
+            }
+            return res;
+        }
+    }
+
+    public static class Kind extends ClassSpecializer<Frob, Byte, Kind>.SpeciesData {
+        public Kind(SpecTest outer, Byte key) {
+            outer.super(key);
+        }
+
+        public MethodHandle factory() {
+            return super.factory();
+        }
+
+        public List<MethodHandle> getters() {
+            return super.getters();
+        }
+
+        private static final List<Class<?>> FIELD_TYPES
+                = Arrays.asList(String.class, float.class, Double.class, boolean.class, Object[].class, Object.class);
+
+        public static int MAX_KEY = FIELD_TYPES.size();
+
+        @Override
+        protected List<Class<?>> deriveFieldTypes(Byte key) {
+            return FIELD_TYPES.subList(0, key);
+        }
+
+        @Override
+        protected Class<? extends Frob> deriveSuperClass() {
+            return FrobImpl.class;
+        }
+
+        @Override
+        protected MethodHandle deriveTransformHelper(MemberName transform, int whichtm) {
+            throw new AssertionError();
+        }
+
+        @Override
+        protected <X> List<X> deriveTransformHelperArguments(MemberName transform, int whichtm, List<X> args, List<X> fields) {
+            throw new AssertionError();
+        }
+    }
+
+    class SpecTest extends ClassSpecializer<Frob, Byte, Kind> {
+        private static final MemberName SPECIES_DATA_ACCESSOR;
+        static {
+            try {
+                SPECIES_DATA_ACCESSOR = MethodHandles.publicLookup()
+                    .resolveOrFail(REF_invokeVirtual, FrobImpl.class, "kind", MethodType.methodType(Kind.class));
+            } catch (ReflectiveOperationException ex) {
+                throw new AssertionError("Bootstrap link error", ex);
+            }
+        }
+
+        public SpecTest() {
+            super(Frob.class, Byte.class, Kind.class,
+                    MethodType.methodType(void.class, int.class),
+                    SPECIES_DATA_ACCESSOR,
+                    "KIND",
+                    Arrays.asList());
+        }
+
+        @Override
+        protected Kind newSpeciesData(Byte key) {
+            return new Kind(this, key);
+        }
+
+        public static Kind kind(int key) {
+            return (Kind) SPEC_TEST.findSpecies((byte)key);
+        }
+    }
+
+    static final SpecTest SPEC_TEST = new SpecTest();
+
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/java/util/stream/CustomFJPoolTest.java	Fri Nov 17 02:50:51 2017 +0100
@@ -0,0 +1,154 @@
+/*
+ * Copyright (c) 2017, 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.
+ */
+
+/*
+ * @test
+ * @summary Tests stream execution in a custom ForkJoinPool
+ * @bug 8190974
+ * @run testng/othervm CustomFJPoolTest
+ * @run testng/othervm -Djava.util.concurrent.ForkJoinPool.common.parallelism=0 CustomFJPoolTest
+ */
+
+import org.testng.annotations.Test;
+
+import java.util.Comparator;
+import java.util.Spliterator;
+import java.util.concurrent.ForkJoinPool;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.function.Consumer;
+import java.util.stream.IntStream;
+import java.util.stream.StreamSupport;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+
+@Test
+public class CustomFJPoolTest {
+
+    // A Spliterator that counts the number of spliterators created
+    // including itself, thus the count starts at 1
+    static class SplitCountingSpliterator<T> implements Spliterator<T> {
+        final Spliterator<T> s;
+        final AtomicInteger nsplits;
+
+        // Top-level constructor
+        public SplitCountingSpliterator(Spliterator<T> s) {
+            this.s = s;
+            nsplits = new AtomicInteger(1);
+        }
+
+        // Splitting constructor
+        SplitCountingSpliterator(Spliterator<T> s, AtomicInteger nsplits) {
+            this.s = s;
+            this.nsplits = nsplits;
+        }
+
+        int splits() {
+            return nsplits.get();
+        }
+
+        @Override
+
+        public boolean tryAdvance(Consumer<? super T> action) {
+            return s.tryAdvance(action);
+        }
+
+        @Override
+        public void forEachRemaining(Consumer<? super T> action) {
+            s.forEachRemaining(action);
+        }
+
+        @Override
+        public Spliterator<T> trySplit() {
+            var split = s.trySplit();
+            if (split != null) {
+                nsplits.incrementAndGet();
+                return new SplitCountingSpliterator<>(split, nsplits);
+            }
+            else {
+                return null;
+            }
+        }
+
+        @Override
+        public long estimateSize() {
+            return s.estimateSize();
+        }
+
+        @Override
+        public long getExactSizeIfKnown() {
+            return s.getExactSizeIfKnown();
+        }
+
+        @Override
+        public int characteristics() {
+            return s.characteristics();
+        }
+
+        @Override
+        public boolean hasCharacteristics(int characteristics) {
+            return s.hasCharacteristics(characteristics);
+        }
+
+        @Override
+        public Comparator<? super T> getComparator() {
+            return s.getComparator();
+        }
+    }
+
+    public void testCustomPools() throws Exception {
+        int splitsForP1 = countSplits(new ForkJoinPool(1));
+        int splitsForP2 = countSplits(new ForkJoinPool(2));
+        assertEquals(splitsForP2, splitsForP1 * 2);
+
+        int commonParallelism = ForkJoinPool.getCommonPoolParallelism();
+        if (commonParallelism > 1 && commonParallelism < 128) {
+            int splitsForPHalfC = countSplits(new ForkJoinPool(commonParallelism / 2));
+            int splitsForPC = countSplits(ForkJoinPool.commonPool());
+
+            assertTrue(splitsForPHalfC < splitsForPC);
+            assertEquals(splitsForPC / splitsForPHalfC,
+                         nearestPowerOfTwo(commonParallelism) / nearestPowerOfTwo(commonParallelism / 2));
+        }
+    }
+
+    static int countSplits(ForkJoinPool fjp) throws Exception {
+        // The number of splits will be equivalent to the number of leaf nodes
+        // and will be a power of 2
+        var fInteger = fjp.submit(() -> {
+            var s = IntStream.range(0, 1024).boxed().parallel().spliterator();
+            var cs = new SplitCountingSpliterator<>(s);
+            StreamSupport.stream(cs, true).forEach(e -> {});
+            return cs.splits();
+        });
+        return fInteger.get();
+    }
+
+    static int nearestPowerOfTwo(int i) {
+        return (i & (i - 1)) == 0
+               ? i
+               : 1 << (32 - Integer.numberOfLeadingZeros(i));
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/tools/jlink/multireleasejar/CheckRuntimeVersion.java	Fri Nov 17 02:50:51 2017 +0100
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2017, 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.
+ *
+ * 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.
+ */
+
+import java.lang.module.ModuleDescriptor;
+import java.lang.module.ModuleFinder;
+import java.lang.module.ModuleReference;
+import java.util.Arrays;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+public class CheckRuntimeVersion {
+    public static void main(String... args) {
+        int version = Integer.parseInt(args[0]);
+        if (Runtime.version().major() != version) {
+            throw new RuntimeException(version + " != current runtime version "
+                + Runtime.version());
+        }
+
+        Set<String> expected = Arrays.stream(args, 1, args.length)
+                                     .collect(Collectors.toSet());
+        Set<String> modules = ModuleFinder.ofSystem().findAll().stream()
+            .map(ModuleReference::descriptor)
+            .map(ModuleDescriptor::name)
+            .collect(Collectors.toSet());
+
+        if (!modules.equals(expected)) {
+            throw new RuntimeException("Expected: " + expected +
+                " observable modules: " + modules);
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/tools/jlink/multireleasejar/JLinkMRJavaBaseVersionTest.java	Fri Nov 17 02:50:51 2017 +0100
@@ -0,0 +1,163 @@
+/*
+ * Copyright (c) 2017, 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.
+ *
+ * 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.
+ */
+
+/*
+ * @test
+ * @bug 8177471
+ * @summary  jlink should use the version from java.base.jmod to find modules
+ * @modules java.base/jdk.internal.module
+ * @library /test/lib
+ * @build jdk.test.lib.process.* CheckRuntimeVersion
+ * @run testng/othervm JLinkMRJavaBaseVersionTest
+ */
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.lang.module.ModuleFinder;
+import java.lang.module.ModuleReference;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.List;
+import java.util.jar.JarFile;
+import java.util.spi.ToolProvider;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import jdk.internal.module.ModulePath;
+import jdk.test.lib.process.ProcessTools;
+import org.testng.Assert;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+public class JLinkMRJavaBaseVersionTest {
+    private static final ToolProvider JAR_TOOL = ToolProvider.findFirst("jar")
+            .orElseThrow(() -> new RuntimeException("jar tool not found"));
+    private static final ToolProvider JAVAC_TOOL = ToolProvider.findFirst("javac")
+            .orElseThrow(() -> new RuntimeException("javac tool not found"));
+    private static final ToolProvider JLINK_TOOL = ToolProvider.findFirst("jlink")
+            .orElseThrow(() -> new RuntimeException("jlink tool not found"));
+
+    private static final Path javaHome = Paths.get(System.getProperty("java.home"));
+
+    // resource text for version 9
+    private byte[] resource9 = ("9 resource file").getBytes();
+    // resource text for current version
+    private byte[] resource = (Runtime.version().major() + " resource file").getBytes();
+
+    static Path getJmods() {
+        Path jmods = Paths.get(System.getProperty("java9.home", javaHome.toString())).resolve("jmods");
+        if (Files.notExists(jmods)) {
+            throw new RuntimeException(jmods + " not found");
+        }
+        return jmods;
+    }
+
+    @BeforeClass
+    public void initialize() throws IOException {
+        Path srcdir = Paths.get(System.getProperty("test.src"));
+
+        // create class files from source
+        Path base = srcdir.resolve("base");
+        Path mr9 = Paths.get("mr9");
+        javac(base, mr9, base.toString());
+
+        // current version
+        Path rt = srcdir.resolve("rt");
+        Path rtmods = Paths.get("rtmods");
+        javac(rt, rtmods, rt.toString());
+
+        // build multi-release jar file with different module-info.class
+        String[] args = {
+                "-cf", "m1.jar",
+                "-C", rtmods.resolve("m1").toString(), ".",
+                "--release ", "9",
+                "-C", mr9.resolve("m1").toString(), "."
+
+        };
+        JAR_TOOL.run(System.out, System.err, args);
+    }
+
+    private void javac(Path source, Path destination, String srcpath) throws IOException {
+        String[] args = Stream.concat(
+                Stream.of("-d", destination.toString(), "--release", "9",
+                          "--module-source-path", srcpath),
+                Files.walk(source)
+                     .map(Path::toString)
+                     .filter(s -> s.endsWith(".java"))
+        ).toArray(String[]::new);
+        int rc = JAVAC_TOOL.run(System.out, System.err, args);
+        Assert.assertEquals(rc, 0);
+    }
+
+    @Test
+    public void basicTest() throws Throwable {
+        if (Files.notExists(javaHome.resolve("lib").resolve("modules"))) {
+            // exploded image
+            return;
+        }
+
+        Runtime.Version version = targetRuntimeVersion();
+        System.out.println("Testing jlink with " + getJmods() + " of target version " + version);
+
+        // use jlink to build image from multi-release jar
+        jlink("m1.jar", "myimage");
+
+        // validate runtime image
+        Path java = Paths.get("myimage", "bin", "java");
+        ProcessTools.executeProcess(java.toString(), "-m", "m1/p.Main");
+
+        // validate the image linked with the proper MR version
+
+        if (version.equalsIgnoreOptional(Runtime.version())) {
+            ProcessTools.executeProcess(java.toString(), "-cp", System.getProperty("test.classes"),
+                                        "CheckRuntimeVersion", String.valueOf(version.major()),
+                                        "java.base", "java.logging", "m1")
+                .shouldHaveExitValue(0);
+        } else {
+            ProcessTools.executeProcess(java.toString(), "-cp", System.getProperty("test.classes"),
+                                        "CheckRuntimeVersion", String.valueOf(version.major()),
+                                        "java.base", "m1")
+                .shouldHaveExitValue(0);
+        }
+    }
+
+    private Runtime.Version targetRuntimeVersion() {
+        ModuleReference mref = ModulePath.of(Runtime.version(), true, getJmods())
+            .find("java.base")
+            .orElseThrow(() -> new RuntimeException("java.base not found from " + getJmods()));
+
+        return Runtime.Version.parse(mref.descriptor().version().get().toString());
+    }
+
+    private void jlink(String jar, String image) {
+        List<String> args = List.of("--output", image,
+                                    "--add-modules", "m1",
+                                    "--module-path",
+                                    getJmods().toString() + File.pathSeparator + jar);
+        System.out.println("jlink " + args.stream().collect(Collectors.joining(" ")));
+        int exitCode = JLINK_TOOL.run(System.out, System.err, args.toArray(new String[0]));
+        Assert.assertEquals(exitCode, 0);
+    }
+}
--- a/test/jdk/tools/jlink/plugins/GenerateJLIClassesPluginTest.java	Fri Nov 17 11:08:44 2017 +0530
+++ b/test/jdk/tools/jlink/plugins/GenerateJLIClassesPluginTest.java	Fri Nov 17 02:50:51 2017 +0100
@@ -21,6 +21,8 @@
  * questions.
  */
 
+import java.nio.charset.Charset;
+import java.nio.file.Files;
 import java.nio.file.Path;
 import java.util.Collection;
 import java.util.List;
@@ -74,11 +76,30 @@
                     classFilesForSpecies(GenerateJLIClassesPlugin.defaultSpecies()),
                     List.of());
 
+        // Check that --generate-jli-classes=@file works as intended
+        Path baseFile = Files.createTempFile("base", "trace");
+        String species = "LLLLLLLLLLLLLLLLLLL";
+        String fileString = "[SPECIES_RESOLVE] java.lang.invoke.BoundMethodHandle$Species_" + species + " (salvaged)\n";
+        Files.write(baseFile, fileString.getBytes(Charset.defaultCharset()));
+        result = JImageGenerator.getJLinkTask()
+                .modulePath(helper.defaultModulePath())
+                .output(helper.createNewImageDir("generate-jli-file"))
+                .option("--generate-jli-classes=@" + baseFile.toString())
+                .addMods("java.base")
+                .call();
+
+        image = result.assertSuccess();
+
+        JImageValidator.validate(
+            image.resolve("lib").resolve("modules"),
+                    classFilesForSpecies(List.of(species)), // species should be in the image
+                    classFilesForSpecies(List.of(species.substring(1)))); // but not it's immediate parent
     }
 
     private static List<String> classFilesForSpecies(Collection<String> species) {
         return species.stream()
-                .map(s -> "/java.base/java/lang/invoke/BoundMethodHandle$Species_" + s + ".class")
+                .map(s -> "/java.base/java/lang/invoke/BoundMethodHandle$Species_"
+                        + GenerateJLIClassesPlugin.expandSignature(s) + ".class")
                 .collect(Collectors.toList());
     }
 }
--- a/test/langtools/jdk/javadoc/doclet/testHelpOption/TestHelpOption.java	Fri Nov 17 11:08:44 2017 +0530
+++ b/test/langtools/jdk/javadoc/doclet/testHelpOption/TestHelpOption.java	Fri Nov 17 02:50:51 2017 +0100
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug      4934778 4777599 6553182 8146427 8146475 8175055
+ * @bug      4934778 4777599 6553182 8146427 8146475 8175055 8185371
  * @summary  Make sure that -help, -helpfile and -nohelp options work correctly.
  * @author   jamieh
  * @library ../lib
@@ -161,6 +161,7 @@
                 "-sourcetab ",
                 "-keywords ",
                 "-stylesheetfile ",
+                "--add-stylesheet ",
                 "-docencoding ",
                 "-html4 ",
                 "-html5 ",
--- a/test/langtools/jdk/javadoc/doclet/testOptions/TestOptions.java	Fri Nov 17 11:08:44 2017 +0530
+++ b/test/langtools/jdk/javadoc/doclet/testOptions/TestOptions.java	Fri Nov 17 02:50:51 2017 +0100
@@ -23,8 +23,9 @@
 
 /*
  * @test
- * @bug      4749567 8071982 8175200 8186332
- * @summary  Test the output for -header, -footer, -nooverview, -nodeprecatedlist, -nonavbar, -notree, -stylesheetfile options.
+ * @bug      4749567 8071982 8175200 8186332 8185371
+ * @summary  Test the output for -header, -footer, -nooverview, -nodeprecatedlist, -nonavbar, -notree,
+ *           -stylesheetfile, --main-stylesheet, --add-stylesheet options.
  * @author   Bhavesh Patel
  * @library  ../lib
  * @modules jdk.javadoc/jdk.javadoc.internal.tool
@@ -118,6 +119,64 @@
     }
 
     @Test
+    void testStylesheetFileAltOption() {
+        javadoc("-d", "out-stylesheet-file",
+                "--main-stylesheet", new File(testSrc, "custom-stylesheet.css").getAbsolutePath(),
+                "-sourcepath", testSrc,
+                "pkg");
+        checkExit(Exit.OK);
+
+        checkOutput("custom-stylesheet.css", true, "Custom javadoc style sheet");
+        checkOutput("pkg/Foo.html", true, "<link rel=\"stylesheet\" type=\"text/css\" "
+                + "href=\"../custom-stylesheet.css\" title=\"Style\">");
+    }
+
+    @Test
+    void testAdditionalStylesheetFile() {
+        javadoc("-d", "out-additional-css",
+                "--add-stylesheet", new File(testSrc, "additional-stylesheet-1.css").getAbsolutePath(),
+                "--add-stylesheet", new File(testSrc, "additional-stylesheet-2.css").getAbsolutePath(),
+                "--add-stylesheet", new File(testSrc, "additional-stylesheet-3.css").getAbsolutePath(),
+                "-sourcepath", testSrc,
+                "pkg");
+        checkExit(Exit.OK);
+
+        checkOutput("additional-stylesheet-1.css", true, "Additional javadoc style sheet 1");
+        checkOutput("additional-stylesheet-2.css", true, "Additional javadoc style sheet 2");
+        checkOutput("additional-stylesheet-3.css", true, "Additional javadoc style sheet 3");
+        checkOutput("pkg/Foo.html", true,
+                "<link rel=\"stylesheet\" type=\"text/css\" href=\"../additional-stylesheet-1.css\" title=\"Style\">\n"
+                + "<link rel=\"stylesheet\" type=\"text/css\" href=\"../additional-stylesheet-2.css\" title=\"Style\">\n"
+                + "<link rel=\"stylesheet\" type=\"text/css\" href=\"../additional-stylesheet-3.css\" title=\"Style\">");
+    }
+
+    @Test
+    void testInvalidStylesheetFile() {
+        javadoc("-d", "out-invalid-css",
+                "--main-stylesheet", new File(testSrc, "custom-stylesheet-1.css").getAbsolutePath(),
+                "-sourcepath", testSrc,
+                "pkg");
+        checkExit(Exit.ERROR);
+
+        checkOutput(Output.OUT, true,
+                "javadoc: error - File not found:",
+                "custom-stylesheet-1.css");
+    }
+
+    @Test
+    void testInvalidAdditionalStylesheetFiles() {
+        javadoc("-d", "out-invalid-additional-css",
+                "--add-stylesheet", new File(testSrc, "additional-stylesheet-4.css").getAbsolutePath(),
+                "-sourcepath", testSrc,
+                "pkg");
+        checkExit(Exit.ERROR);
+
+        checkOutput(Output.OUT, true,
+                "javadoc: error - File not found:",
+                "additional-stylesheet-4.css");
+    }
+
+    @Test
     void testLinkSource() {
         javadoc("-d", "out-9",
                 "-linksource",
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/jdk/javadoc/doclet/testOptions/additional-stylesheet-1.css	Fri Nov 17 02:50:51 2017 +0100
@@ -0,0 +1,5 @@
+/* Additional javadoc style sheet 1 */
+
+body {
+    background-color:#f8f8ff;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/jdk/javadoc/doclet/testOptions/additional-stylesheet-2.css	Fri Nov 17 02:50:51 2017 +0100
@@ -0,0 +1,5 @@
+/* Additional javadoc style sheet 2 */
+
+.subNav {
+    background-color:#fafad2;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/jdk/javadoc/doclet/testOptions/additional-stylesheet-3.css	Fri Nov 17 02:50:51 2017 +0100
@@ -0,0 +1,5 @@
+/* Additional javadoc style sheet 3 */
+
+a:link, a:visited {
+    color:#8b0000;
+}
--- a/test/make/TestCopyFiles.gmk	Fri Nov 17 11:08:44 2017 +0530
+++ b/test/make/TestCopyFiles.gmk	Fri Nov 17 02:50:51 2017 +0100
@@ -44,6 +44,7 @@
 DEST_DIR := $(OUTPUT_DIR)/dest
 
 $(OUTPUT_DIR)/_src_created: $(DEPS)
+	$(RM) -r $(DEST_DIR)
 	$(RM) -r $(SRC_DIR)
 	$(MKDIR) -p $(SRC_DIR)
 	$(MKDIR) -p $(SRC_DIR)/foo
@@ -51,7 +52,7 @@
 	$(TOUCH) $(SRC_DIR)/foo/foofile
 	$(TOUCH) "$(SRC_DIR)/foo/foo file"
         # Spaces in directories only works with gnu make 4.0 or later
-        ifeq (4.0, $(firstword $(sort 4.0 $(MAKE_VERSION))))
+        ifeq (4.0dfd, $(firstword $(sort 4.0 $(MAKE_VERSION))))
 	  $(MKDIR) -p "$(SRC_DIR)/foo bar"
 	  $(TOUCH) "$(SRC_DIR)/foo bar/foobarfile"
 	  $(TOUCH) "$(SRC_DIR)/foo bar/foo bar file"
@@ -65,15 +66,32 @@
     FILES := $(call CacheFind, $(SRC_DIR)), \
 ))
 
+# Optionally define a rule that deletes all the target files after the makefile
+# has been parsed. GNU make has specific problems with this in combination with
+# spaces in directory names.
+ifeq ($(DELETE_FIRST), true)
+  delete-targets:
+	$(RM) -r $(DEST_DIR)
+	$(ECHO) '$(DEST_DIR)/foo' '$(wildcard $(DEST_DIR)/foo)'
+
+  $(COPY_1): delete-targets
+endif
+
 do-copy1: $(COPY_1)
 
 run-test1: $(OUTPUT_DIR)/_src_created
+	$(ECHO) "Copy 1 first time"
 	+$(MAKE) -f $(THIS_FILE) do-copy1
 	$(DIFF) -r $(SRC_DIR) $(DEST_DIR)
+        # Rerun the copy a second time, with the targets present at make parse
+        # time, but then deleted by a prerequisite rule.
+	$(ECHO) "Copy 1 second time"
+	+$(MAKE) -f $(THIS_FILE) do-copy1 DELETE_FIRST=true
+	$(DIFF) -r $(SRC_DIR) $(DEST_DIR)
 
 TEST_TARGETS += run-test1
 
-.PHONY: do-copy1 run-test1
+.PHONY: do-copy1 run-test1 delete-targets
 
 ################################################################################
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/nashorn/script/basic/JDK-8191306.js	Fri Nov 17 02:50:51 2017 +0100
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2017, 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.
+ *
+ * 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-8191306 Math.abs corner case with optimistic typing
+ *
+ * @test
+ * @run
+ */
+
+print(Math.abs(-2147483648))
+print(Math.abs(java.lang.Integer.MIN_VALUE))
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/nashorn/script/basic/JDK-8191306.js.EXPECTED	Fri Nov 17 02:50:51 2017 +0100
@@ -0,0 +1,2 @@
+2147483648
+2147483648
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/nashorn/script/nosecurity/es6/JDK-8185119.js	Fri Nov 17 02:50:51 2017 +0100
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2017, 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.
+ * 
+ * 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-8185119: Uninitialized const when using multiple threads
+ *
+ * @test
+ * @option --language=es6
+ * @run
+ */
+
+function f() {
+    let a;
+    const b = {};
+    b.crash; // b is sometimes undefined
+
+    function c() {
+        a; b;
+    }
+}
+
+let count = new java.util.concurrent.atomic.AtomicInteger();
+
+let T = Java.extend(Java.type('java.lang.Thread'), {
+    run: function() {
+        for (let j = 0; j < 100; j++) {
+            f();
+        }
+        count.getAndIncrement();
+    }
+});
+
+const threads = [new T(), new T(), new T(), new T()];
+threads.forEach(t => t.start());
+threads.forEach(t => t.join());
+
+Assert.assertEquals(count.intValue(), 4);
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/nashorn/src/jdk/nashorn/api/scripting/test/JDK_8068741_Test.java	Fri Nov 17 02:50:51 2017 +0100
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2017, 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.api.scripting.test;
+
+import javax.script.ScriptEngineFactory;
+import jdk.nashorn.api.scripting.NashornScriptEngineFactory;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+/**
+ * @test
+ * @run testng jdk.nashorn.api.scripting.test.JDK_8068741_Test
+ * @bug 8068741
+ * @summary javax.script.ScriptEngineFactory.getMethodCallSyntax() spec allows null passed as an object
+ */
+public class JDK_8068741_Test {
+    @Test
+    public void testGetMethodCallSyntax() {
+        ScriptEngineFactory fac = new NashornScriptEngineFactory();
+        checkThrowsNPE(() -> fac.getMethodCallSyntax(null, "foo"));
+        checkThrowsNPE(() -> fac.getMethodCallSyntax("obj", null));
+        checkThrowsNPE(() -> fac.getMethodCallSyntax("obj", "foo", (String[])null));
+        checkThrowsNPE(() -> fac.getMethodCallSyntax("obj", "foo", null, "xyz"));
+        checkThrowsNPE(() -> fac.getMethodCallSyntax("obj", "foo", "xyz", null));
+    }
+
+    private void checkThrowsNPE(Runnable r) {
+        boolean gotNPE = false;
+        try {
+            r.run();
+        } catch (NullPointerException npe) {
+            gotNPE = true;
+            System.err.println("Got NPE as expected: " + npe);
+        }
+        Assert.assertTrue(gotNPE);
+    }
+}