changeset 1333:7066af6e7b06 jdk9-b71

Merge
author lana
date Sun, 28 Jun 2015 16:38:44 -0700
parents 3951ff3b5272 69e616b3bc44
children 91869e340c47 555e9e0f6a55
files
diffstat 6 files changed, 88 insertions(+), 86 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/Compiler.java	Thu Jun 25 10:21:42 2015 -0700
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/Compiler.java	Sun Jun 28 16:38:44 2015 -0700
@@ -607,7 +607,7 @@
             newFunctionNode.uniqueName(reservedName);
         }
 
-        final boolean info = log.levelFinerThanOrEqual(Level.INFO);
+        final boolean info = log.isLoggable(Level.INFO);
 
         final DebugLogger timeLogger = env.isTimingEnabled() ? env._timing.getLogger() : null;
 
@@ -644,8 +644,8 @@
         if (info) {
             final StringBuilder sb = new StringBuilder("<< Finished compile job for ");
             sb.append(newFunctionNode.getSource()).
-                append(':').
-                append(quote(newFunctionNode.getName()));
+            append(':').
+            append(quote(newFunctionNode.getName()));
 
             if (time > 0L && timeLogger != null) {
                 assert env.isTimingEnabled();
@@ -713,7 +713,7 @@
         if (cacheKey != null && env._persistent_cache) {
             // If this is an on-demand compilation create a function initializer for the function being compiled.
             // Otherwise use function initializer map generated by codegen.
-            Map<Integer, FunctionInitializer> initializers = new HashMap<>();
+            final Map<Integer, FunctionInitializer> initializers = new HashMap<>();
             if (isOnDemandCompilation()) {
                 initializers.put(functionNode.getId(), new FunctionInitializer(functionNode, getInvalidatedProgramPoints()));
             } else {
@@ -829,9 +829,9 @@
         final long                        totalSize = osc.calculateObjectSize(functionNode);
 
         sb.append(phaseName).
-            append(" Total size = ").
-            append(totalSize / 1024 / 1024).
-            append("MB");
+        append(" Total size = ").
+        append(totalSize / 1024 / 1024).
+        append("MB");
         log.info(sb);
 
         Collections.sort(list, new Comparator<ClassHistogramElement>() {
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/lookup/MethodHandleFactory.java	Thu Jun 25 10:21:42 2015 -0700
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/lookup/MethodHandleFactory.java	Sun Jun 28 16:38:44 2015 -0700
@@ -131,8 +131,8 @@
     static Object traceReturn(final DebugLogger logger, final Object value) {
         final String str = "    return" +
                 (VOID_TAG.equals(value) ?
-                    ";" :
-                    " " + stripName(value) + "; // [type=" + (value == null ? "null]" : stripName(value.getClass()) + ']'));
+                        ";" :
+                            " " + stripName(value) + "; // [type=" + (value == null ? "null]" : stripName(value.getClass()) + ']'));
         if (logger == null) {
             err(str);
         } else if (logger.isEnabled()) {
@@ -164,13 +164,13 @@
             }
 
             sb.append('\'').
-                append(stripName(argString(args[i]))).
-                append('\'').
-                append(' ').
-                append('[').
-                append("type=").
-                append(args[i] == null ? "null" : stripName(args[i].getClass())).
-                append(']');
+            append(stripName(argString(args[i]))).
+            append('\'').
+            append(' ').
+            append('[').
+            append("type=").
+            append(args[i] == null ? "null" : stripName(args[i].getClass())).
+            append(']');
 
             if (i + 1 < args.length) {
                 sb.append(", ");
@@ -216,8 +216,8 @@
 
         if (arg instanceof ScriptObject) {
             return arg.toString() +
-                " (map=" + Debug.id(((ScriptObject)arg).getMap()) +
-                ')';
+                    " (map=" + Debug.id(((ScriptObject)arg).getMap()) +
+                    ')';
         }
 
         return arg.toString();
@@ -262,7 +262,7 @@
         return addDebugPrintout(null, Level.OFF, mh, paramStart, printReturnValue, tag);
     }
 
-     /**
+    /**
      * Add a debug printout to a method handle, tracing parameters and return values
      *
      * @param logger a specific logger to which to write the output
@@ -278,7 +278,7 @@
 
         //if there is no logger, or if it's set to log only coarser events
         //than the trace level, skip and return
-        if (logger != null && logger.levelCoarserThan(level)) {
+        if (logger == null || !logger.isLoggable(level)) {
             return mh;
         }
 
@@ -289,9 +289,9 @@
         trace = MethodHandles.foldArguments(
                 mh,
                 trace.asCollector(
-                    Object[].class,
-                    type.parameterCount()).
-                asType(type.changeReturnType(void.class)));
+                        Object[].class,
+                        type.parameterCount()).
+                        asType(type.changeReturnType(void.class)));
 
         final Class<?> retType = type.returnType();
         if (printReturnValue) {
@@ -299,7 +299,7 @@
                 final MethodHandle traceReturn = MethodHandles.insertArguments(TRACE_RETURN, 0, logger);
                 trace = MethodHandles.filterReturnValue(trace,
                         traceReturn.asType(
-                            traceReturn.type().changeParameterType(0, retType).changeReturnType(retType)));
+                                traceReturn.type().changeParameterType(0, retType).changeReturnType(retType)));
             } else {
                 trace = MethodHandles.filterReturnValue(trace, MethodHandles.insertArguments(TRACE_RETURN_VOID, 0, logger));
             }
@@ -355,9 +355,9 @@
                     sb.append("] ");
                 } else {
                     sb.append(d)
-                        .append('{')
-                        .append(Integer.toHexString(System.identityHashCode(d)))
-                        .append('}');
+                    .append('{')
+                    .append(Integer.toHexString(System.identityHashCode(d)))
+                    .append('}');
                 }
 
                 if (i + 1 < data.length) {
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/JavaAdapterBytecodeGenerator.java	Thu Jun 25 10:21:42 2015 -0700
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/JavaAdapterBytecodeGenerator.java	Sun Jun 28 16:38:44 2015 -0700
@@ -106,7 +106,9 @@
  * <li>
  * If the adapter being generated can have class-level overrides, constructors taking same arguments as the superclass
  * constructors are created. These constructors simply delegate to the superclass constructor. They are simply used to
- * create instances of the adapter class, with no instance-level overrides, as they don't have them.
+ * create instances of the adapter class, with no instance-level overrides, as they don't have them. If the original
+ * class' constructor was variable arity, the adapter constructor will also be variable arity. Protected constructors
+ * are exposed as public.
  * </li>
  * </ul>
  * </p><p>
@@ -190,7 +192,6 @@
     private static final int MAX_GENERATED_TYPE_NAME_LENGTH = 255;
 
     private static final String CLASS_INIT = "<clinit>";
-    static final String CONVERTER_INIT = "<converter-init>";
 
     // Method name prefix for invoking super-methods
     static final String SUPER_PREFIX = "super$";
@@ -494,7 +495,8 @@
         final Type[] argTypes = originalCtorType.getArgumentTypes();
 
         // All constructors must be public, even if in the superclass they were protected.
-        final InstructionAdapter mv = new InstructionAdapter(cw.visitMethod(ACC_PUBLIC, INIT,
+        final InstructionAdapter mv = new InstructionAdapter(cw.visitMethod(ACC_PUBLIC |
+                (ctor.isVarArgs() ? ACC_VARARGS : 0), INIT,
                 Type.getMethodDescriptor(originalCtorType.getReturnType(), argTypes), null, null));
 
         mv.visitCode();
@@ -543,7 +545,8 @@
         System.arraycopy(originalArgTypes, 0, newArgTypes, 0, argLen);
 
         // All constructors must be public, even if in the superclass they were protected.
-        // Existing super constructor <init>(this, args...) triggers generating <init>(this, scriptObj, args...).
+        // Existing super constructor <init>(this, args...) triggers generating <init>(this, args..., scriptObj).
+        // Any variable arity constructors become fixed-arity with explicit array arguments.
         final InstructionAdapter mv = new InstructionAdapter(cw.visitMethod(ACC_PUBLIC, INIT,
                 Type.getMethodDescriptor(originalCtorType.getReturnType(), newArgTypes), null, null));
 
@@ -593,7 +596,7 @@
         if (! fromFunction) {
             newArgTypes[argLen] = OBJECT_TYPE;
             final InstructionAdapter mv2 = new InstructionAdapter(cw.visitMethod(ACC_PUBLIC, INIT,
-                Type.getMethodDescriptor(originalCtorType.getReturnType(), newArgTypes), null, null));
+                    Type.getMethodDescriptor(originalCtorType.getReturnType(), newArgTypes), null, null));
             generateOverridingConstructorWithObjectParam(mv2, ctor, originalCtorType.getDescriptor());
         }
     }
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/logging/DebugLogger.java	Thu Jun 25 10:21:42 2015 -0700
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/logging/DebugLogger.java	Sun Jun 28 16:38:44 2015 -0700
@@ -99,10 +99,10 @@
                         final StringBuilder sb = new StringBuilder();
 
                         sb.append('[')
-                           .append(record.getLoggerName())
-                           .append("] ")
-                           .append(record.getMessage())
-                           .append('\n');
+                        .append(record.getLoggerName())
+                        .append("] ")
+                        .append(record.getMessage())
+                        .append('\n');
 
                         return sb.toString();
                     }
@@ -194,7 +194,7 @@
      */
     public void indent(final int pos) {
         if (isEnabled) {
-           indent += pos * INDENT_SPACE;
+            indent += pos * INDENT_SPACE;
         }
     }
 
@@ -227,57 +227,14 @@
     }
 
     /**
-     * Check if the logger is above the level of detail given
+     * Check if the event of given level will be logged.
      * @see java.util.logging.Level
      *
-     * The higher the level, the more severe the warning
-     *
      * @param level logging level
-     * @return true if level is above the given one
+     * @return true if event of given level will be logged.
      */
-    public boolean levelCoarserThan(final Level level) {
-        return getLevel().intValue() > level.intValue();
-    }
-
-    /**
-     * Check if the logger is above or equal to the level
-     * of detail given
-     * @see java.util.logging.Level
-     *
-     * The higher the level, the more severe the warning
-     *
-     * @param level logging level
-     * @return true if level is above the given one
-     */
-    public boolean levelCoarserThanOrEqual(final Level level) {
-        return getLevel().intValue() >= level.intValue();
-    }
-
-    /**
-     * Check if the logger is below the level of detail given
-     * @see java.util.logging.Level
-     *
-     * The higher the level, the more severe the warning
-     *
-     * @param level logging level
-     * @return true if level is above the given one
-     */
-    public boolean levelFinerThan(final Level level) {
-        return getLevel().intValue() < level.intValue();
-    }
-
-    /**
-     * Check if the logger is below or equal to the level
-     * of detail given
-     * @see java.util.logging.Level
-     *
-     * The higher the level, the more severe the warning
-     *
-     * @param level logging level
-     * @return true if level is above the given one
-     */
-    public boolean levelFinerThanOrEqual(final Level level) {
-        return getLevel().intValue() <= level.intValue();
+    public boolean isLoggable(final Level level) {
+        return logger.isLoggable(level);
     }
 
     /**
@@ -566,7 +523,7 @@
      * @param str   string to log
      */
     public void log(final Level level, final String str) {
-        if (isEnabled && !isQuiet) {
+        if (isEnabled && !isQuiet && logger.isLoggable(level)) {
             final StringBuilder sb = new StringBuilder();
             for (int i = 0 ; i < indent ; i++) {
                 sb.append(' ');
@@ -584,7 +541,7 @@
      * @param objs  objects for which to invoke toString and concatenate to log
      */
     public void log(final Level level, final Object... objs) {
-        if (isEnabled && !isQuiet) {
+        if (isEnabled && !isQuiet && logger.isLoggable(level)) {
             final StringBuilder sb = new StringBuilder();
             for (final Object obj : objs) {
                 sb.append(obj);
--- a/test/TEST.groups	Thu Jun 25 10:21:42 2015 -0700
+++ b/test/TEST.groups	Sun Jun 28 16:38:44 2015 -0700
@@ -27,3 +27,6 @@
 
 # All nashorn tests are tier 2.
 tier2 = src
+
+# No nashorn tests are tier 3.
+tier3 =
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/script/basic/JDK-8129410.js	Sun Jun 28 16:38:44 2015 -0700
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ * 
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ * 
+ * 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-8129410: Java adapters with class-level overrides should preserve variable arity constructors
+ *
+ * @test
+ * @run
+ */
+
+var VarArgConstructor = Java.type("jdk.nashorn.test.models.VarArgConstructor");
+var VarArgConstructorExtended = Java.extend(VarArgConstructor, {});
+
+// If the fix didn't work we wouldn't even get past the constructor invocation
+// as it'd complain there's no matching arity constructor.
+var newExtended = new VarArgConstructorExtended(1, true, "a", "b");
+
+// Assert the expected constructor was invoked.
+Assert.assertEquals("vararg", newExtended.indicator);