8046898: Make sure that lazy compilation is the default, remove redundant "enable lazy compilation" flags, added warning message if compile logging is enabled and lazy is switched off. Verified existing test suite code coverage equivalence between lazy and eager.
authorlagergren
Tue, 17 Jun 2014 11:37:03 +0200
changeset 24993 b707d46bae40
parent 24883 f9f624aecf27
child 24994 92a19723a5ac
8046898: Make sure that lazy compilation is the default, remove redundant "enable lazy compilation" flags, added warning message if compile logging is enabled and lazy is switched off. Verified existing test suite code coverage equivalence between lazy and eager. Reviewed-by: attila, hannesw
nashorn/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/MemberInfo.java
nashorn/make/project.properties
nashorn/src/jdk/nashorn/internal/codegen/Compiler.java
nashorn/src/jdk/nashorn/internal/ir/BinaryNode.java
nashorn/src/jdk/nashorn/internal/ir/FunctionNode.java
nashorn/src/jdk/nashorn/internal/objects/NativeObject.java
nashorn/src/jdk/nashorn/internal/runtime/Context.java
nashorn/src/jdk/nashorn/internal/runtime/FinalScriptFunctionData.java
nashorn/src/jdk/nashorn/internal/runtime/PropertyMap.java
nashorn/src/jdk/nashorn/internal/runtime/RecompilableScriptFunctionData.java
nashorn/src/jdk/nashorn/internal/runtime/ScriptObject.java
nashorn/src/jdk/nashorn/internal/runtime/Source.java
nashorn/src/jdk/nashorn/internal/runtime/arrays/ArrayFilter.java
nashorn/src/jdk/nashorn/internal/runtime/logging/DebugLogger.java
nashorn/test/src/UnnamedPackageTestCallback.java
--- a/nashorn/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/MemberInfo.java	Thu Jun 12 15:37:37 2014 -0700
+++ b/nashorn/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/MemberInfo.java	Tue Jun 17 11:37:03 2014 +0200
@@ -412,6 +412,10 @@
                     }
                 }
             }
+            break;
+
+            default:
+            break;
         }
     }
 
@@ -450,7 +454,7 @@
 
         if (type.getSort() == Type.OBJECT) {
             try {
-                final Class clazz = Class.forName(type.getClassName(), false, myLoader);
+                final Class<?> clazz = Class.forName(type.getClassName(), false, myLoader);
                 return ScriptObject.class.isAssignableFrom(clazz);
             } catch (final ClassNotFoundException cnfe) {
                 return false;
--- a/nashorn/make/project.properties	Thu Jun 12 15:37:37 2014 -0700
+++ b/nashorn/make/project.properties	Tue Jun 17 11:37:03 2014 +0200
@@ -283,7 +283,7 @@
   -XX:+HeapDumpOnOutOfMemoryError
 
 # turn on assertions for tests
-run.test.jvmargs.main=${run.test.jvmargs.common} -ea -Dnashorn.lazy
+run.test.jvmargs.main=${run.test.jvmargs.common} -ea
 
 # extra jvmargs that might be useful for debugging
 #
@@ -305,7 +305,7 @@
 # -XX:+PrintNMethods
 
 # Use best known performance options for octane
-run.test.jvmargs.octane.main=${run.test.jvmargs.common} -Dnashorn.lazy -XX:+UnlockDiagnosticVMOptions -XX:+UseNewCode -XX:TypeProfileLevel=222
+run.test.jvmargs.octane.main=${run.test.jvmargs.common} -XX:+UnlockDiagnosticVMOptions -XX:+UseNewCode -XX:TypeProfileLevel=222
 
 # Security manager args - make sure that we run with the nashorn.policy that the build creates
 run.test.jvmsecurityargs=-Xverify:all -Djava.security.manager -Djava.security.policy=${basedir}/build/nashorn.policy
--- a/nashorn/src/jdk/nashorn/internal/codegen/Compiler.java	Thu Jun 12 15:37:37 2014 -0700
+++ b/nashorn/src/jdk/nashorn/internal/codegen/Compiler.java	Tue Jun 17 11:37:03 2014 +0200
@@ -47,7 +47,9 @@
 import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.atomic.AtomicInteger;
+import java.util.function.Consumer;
 import java.util.logging.Level;
+
 import jdk.internal.dynalink.support.NameCodec;
 import jdk.nashorn.internal.codegen.ClassEmitter.Flag;
 import jdk.nashorn.internal.codegen.types.Type;
@@ -421,7 +423,14 @@
 
     @Override
     public DebugLogger initLogger(final Context ctxt) {
-        return ctxt.getLogger(this.getClass());
+        return ctxt.getLogger(this.getClass(), new Consumer<DebugLogger>() {
+            @Override
+            public void accept(final DebugLogger newLogger) {
+                if (!Compiler.this.getScriptEnvironment()._lazy_compilation) {
+                    newLogger.warning("WARNING: Running with lazy compilation switched off. This is not a default setting.");
+                }
+            }
+        });
     }
 
     ScriptEnvironment getScriptEnvironment() {
--- a/nashorn/src/jdk/nashorn/internal/ir/BinaryNode.java	Thu Jun 12 15:37:37 2014 -0700
+++ b/nashorn/src/jdk/nashorn/internal/ir/BinaryNode.java	Tue Jun 17 11:37:03 2014 +0200
@@ -45,7 +45,7 @@
 public final class BinaryNode extends Expression implements Assignment<Expression>, Optimistic {
     // Placeholder for "undecided optimistic ADD type". Unfortunately, we can't decide the type of ADD during optimistic
     // type calculation as it can have local variables as its operands that will decide its ultimate type.
-    private static final Type OPTIMISTIC_UNDECIDED_TYPE = Type.typeFor(new Object(){}.getClass());
+    private static final Type OPTIMISTIC_UNDECIDED_TYPE = Type.typeFor(new Object(){/*empty*/}.getClass());
 
     /** Left hand side argument. */
     private final Expression lhs;
--- a/nashorn/src/jdk/nashorn/internal/ir/FunctionNode.java	Thu Jun 12 15:37:37 2014 -0700
+++ b/nashorn/src/jdk/nashorn/internal/ir/FunctionNode.java	Tue Jun 17 11:37:03 2014 +0200
@@ -99,7 +99,7 @@
         BYTECODE_GENERATED,
         /** method has been installed */
         BYTECODE_INSTALLED
-    };
+    }
 
     /** Source of entity. */
     private final Source source;
@@ -388,10 +388,11 @@
     }
 
     /**
-     * static source name getter
+     * Static source name getter
+     *
      * @param source
      * @param sourceURL
-     * @return
+     * @return source name
      */
     public static String getSourceName(final Source source, final String sourceURL) {
         return sourceURL != null ? sourceURL : source.getName();
--- a/nashorn/src/jdk/nashorn/internal/objects/NativeObject.java	Thu Jun 12 15:37:37 2014 -0700
+++ b/nashorn/src/jdk/nashorn/internal/objects/NativeObject.java	Tue Jun 17 11:37:03 2014 +0200
@@ -75,7 +75,10 @@
  */
 @ScriptClass("Object")
 public final class NativeObject {
+    /** Methodhandle to proto getter */
     public static final MethodHandle GET__PROTO__ = findOwnMH("get__proto__", ScriptObject.class, Object.class);
+
+    /** Methodhandle to proto setter */
     public static final MethodHandle SET__PROTO__ = findOwnMH("set__proto__", Object.class, Object.class, Object.class);
 
     private static final Object TO_STRING = new Object();
--- a/nashorn/src/jdk/nashorn/internal/runtime/Context.java	Thu Jun 12 15:37:37 2014 -0700
+++ b/nashorn/src/jdk/nashorn/internal/runtime/Context.java	Tue Jun 17 11:37:03 2014 +0200
@@ -1236,6 +1236,16 @@
      * @return debuglogger associated with that class
      */
     public DebugLogger getLogger(final Class<? extends Loggable> clazz) {
+        return getLogger(clazz, null);
+    }
+
+    /**
+     * Get a logger, given a loggable class
+     * @param clazz a Loggable class
+     * @param initHook an init hook - if this is the first time the logger is created in the context, run the init hook
+     * @return debuglogger associated with that class
+     */
+    public DebugLogger getLogger(final Class<? extends Loggable> clazz, final Consumer<DebugLogger> initHook) {
         final String name = getLoggerName(clazz);
         DebugLogger logger = loggers.get(name);
         if (logger == null) {
@@ -1244,6 +1254,9 @@
             }
             final LoggerInfo info = env._loggers.get(name);
             logger = new DebugLogger(name, info.getLevel(), info.isQuiet());
+            if (initHook != null) {
+                initHook.accept(logger);
+            }
             loggers.put(name, logger);
         }
         return logger;
--- a/nashorn/src/jdk/nashorn/internal/runtime/FinalScriptFunctionData.java	Thu Jun 12 15:37:37 2014 -0700
+++ b/nashorn/src/jdk/nashorn/internal/runtime/FinalScriptFunctionData.java	Tue Jun 17 11:37:03 2014 +0200
@@ -34,6 +34,8 @@
  */
 final class FinalScriptFunctionData extends ScriptFunctionData {
 
+    private static final long serialVersionUID = -930632846167768864L;
+
     /**
      * Constructor - used for bind
      *
--- a/nashorn/src/jdk/nashorn/internal/runtime/PropertyMap.java	Thu Jun 12 15:37:37 2014 -0700
+++ b/nashorn/src/jdk/nashorn/internal/runtime/PropertyMap.java	Tue Jun 17 11:37:03 2014 +0200
@@ -185,6 +185,7 @@
      * properties with keys that are valid array indices.</p>
      *
      * @param properties   Collection of initial properties.
+     * @param className    class name
      * @param fieldCount   Number of fields in use.
      * @param fieldMaximum Number of fields available.
      * @param spillLength  Number of used spill slots.
--- a/nashorn/src/jdk/nashorn/internal/runtime/RecompilableScriptFunctionData.java	Thu Jun 12 15:37:37 2014 -0700
+++ b/nashorn/src/jdk/nashorn/internal/runtime/RecompilableScriptFunctionData.java	Tue Jun 17 11:37:03 2014 +0200
@@ -54,7 +54,6 @@
 import jdk.nashorn.internal.runtime.logging.DebugLogger;
 import jdk.nashorn.internal.runtime.logging.Loggable;
 import jdk.nashorn.internal.runtime.logging.Logger;
-import jdk.nashorn.internal.runtime.options.Options;
 import jdk.nashorn.internal.scripts.JS;
 
 /**
@@ -65,9 +64,6 @@
  */
 @Logger(name="recompile")
 public final class RecompilableScriptFunctionData extends ScriptFunctionData implements Loggable {
-    /** Is lazy compilation enabled? TODO: this should be the default */
-    public static final boolean LAZY_COMPILATION = Options.getBooleanProperty("nashorn.lazy");
-
     /** Prefix used for all recompiled script classes */
     public static final String RECOMPILATION_PREFIX = "Recompilation$";
 
@@ -240,6 +236,12 @@
         return "function " + (name == null ? "" : name) + "() { [native code] }";
     }
 
+    /**
+     * Setter for code and source
+     *
+     * @param code   map of code, class name to class
+     * @param source source
+     */
     public void setCodeAndSource(final Map<String, Class<?>> code, final Source source) {
         this.source = source;
         if (methodLocator != null) {
--- a/nashorn/src/jdk/nashorn/internal/runtime/ScriptObject.java	Thu Jun 12 15:37:37 2014 -0700
+++ b/nashorn/src/jdk/nashorn/internal/runtime/ScriptObject.java	Tue Jun 17 11:37:03 2014 +0200
@@ -2267,7 +2267,7 @@
 
             if (mh != null) {
                 assert func != null;
-                if (scopeAccess && func != null && func.isStrict()) {
+                if (scopeAccess && func.isStrict()) {
                     mh = bindTo(mh, UNDEFINED);
                 }
                 return new GuardedInvocation(
--- a/nashorn/src/jdk/nashorn/internal/runtime/Source.java	Thu Jun 12 15:37:37 2014 -0700
+++ b/nashorn/src/jdk/nashorn/internal/runtime/Source.java	Tue Jun 17 11:37:03 2014 +0200
@@ -99,12 +99,13 @@
                 // Force any access errors
                 data.checkPermissionAndClose();
                 return existingSource;
-            } else {
-                // All sources in cache must be fully loaded
-                data.load();
-                CACHE.put(newSource, newSource);
-                return newSource;
             }
+
+            // All sources in cache must be fully loaded
+            data.load();
+            CACHE.put(newSource, newSource);
+
+            return newSource;
         } catch (final RuntimeException e) {
             final Throwable cause = e.getCause();
             if (cause instanceof IOException) {
@@ -291,7 +292,9 @@
         }
 
         protected void checkPermissionAndClose() throws IOException {
-            try (InputStream in = url.openStream()) {}
+            try (InputStream in = url.openStream()) {
+                // empty
+            }
             debug("permission checked for ", url);
         }
 
@@ -366,20 +369,24 @@
     }
 
     /**
-     * Returns an instance
+     * Returns a Source instance
      *
      * @param name    source name
      * @param content contents as char array
+     *
+     * @return source instance
      */
     public static Source sourceFor(final String name, final char[] content) {
         return new Source(name, baseName(name), new RawData(content));
     }
 
     /**
-     * Returns an instance
+     * Returns a Source instance
      *
      * @param name    source name
      * @param content contents as string
+     *
+     * @return source instance
      */
     public static Source sourceFor(final String name, final String content) {
         return new Source(name, baseName(name), new RawData(content));
@@ -391,6 +398,8 @@
      * @param name  source name
      * @param url   url from which source can be loaded
      *
+     * @return source instance
+     *
      * @throws IOException if source cannot be loaded
      */
     public static Source sourceFor(final String name, final URL url) throws IOException {
@@ -404,6 +413,8 @@
      * @param url   url from which source can be loaded
      * @param cs    Charset used to convert bytes to chars
      *
+     * @return source instance
+     *
      * @throws IOException if source cannot be loaded
      */
     public static Source sourceFor(final String name, final URL url, final Charset cs) throws IOException {
@@ -416,6 +427,8 @@
      * @param name  source name
      * @param file  file from which source can be loaded
      *
+     * @return source instance
+     *
      * @throws IOException if source cannot be loaded
      */
     public static Source sourceFor(final String name, final File file) throws IOException {
@@ -429,6 +442,8 @@
      * @param file  file from which source can be loaded
      * @param cs    Charset used to convert bytes to chars
      *
+     * @return source instance
+     *
      * @throws IOException if source cannot be loaded
      */
     public static Source sourceFor(final String name, final File file, final Charset cs) throws IOException {
@@ -441,6 +456,9 @@
      *
      * @param name source name
      * @param reader reader from which source can be loaded
+     *
+     * @return source instance
+     *
      * @throws IOException if source cannot be loaded
      */
     public static Source sourceFor(final String name, final Reader reader) throws IOException {
@@ -542,9 +560,9 @@
      * @return Index of first character of line.
      */
     private int findBOLN(final int position) {
-        final char[] data = data();
+        final char[] d = data();
         for (int i = position - 1; i > 0; i--) {
-            final char ch = data[i];
+            final char ch = d[i];
 
             if (ch == '\n' || ch == '\r') {
                 return i + 1;
@@ -560,10 +578,10 @@
      * @return Index of last character of line.
      */
     private int findEOLN(final int position) {
-        final char[] data = data();
-        final int length = data.length;
+        final char[] d = data();
+        final int length = d.length;
         for (int i = position; i < length; i++) {
-            final char ch = data[i];
+            final char ch = d[i];
 
             if (ch == '\n' || ch == '\r') {
                 return i - 1;
@@ -583,12 +601,12 @@
      * @return Line number.
      */
     public int getLine(final int position) {
-        final char[] data = data();
+        final char[] d = data();
         // Line count starts at 1.
         int line = 1;
 
         for (int i = 0; i < position; i++) {
-            final char ch = data[i];
+            final char ch = d[i];
             // Works for both \n and \r\n.
             if (ch == '\n') {
                 line++;
--- a/nashorn/src/jdk/nashorn/internal/runtime/arrays/ArrayFilter.java	Thu Jun 12 15:37:37 2014 -0700
+++ b/nashorn/src/jdk/nashorn/internal/runtime/arrays/ArrayFilter.java	Tue Jun 17 11:37:03 2014 +0200
@@ -141,21 +141,6 @@
         return this;
     }
 
-    private static void printTrace(final Throwable t, final String msg) {
-        final java.io.StringWriter sw = new java.io.StringWriter();
-        final java.io.PrintWriter pw = new java.io.PrintWriter(sw, false);
-        pw.println(msg);
-        final StackTraceElement[] trace = t.getStackTrace();
-        for(final StackTraceElement e: trace) {
-            pw.println(" at " + e);
-            if(e.getClassName().startsWith("jdk.nashorn.")) {
-                break;
-            }
-        }
-        pw.flush();
-        System.out.println(sw.toString());
-    }
-
     @Override
     public Type getOptimisticType() {
         return underlying.getOptimisticType();
--- a/nashorn/src/jdk/nashorn/internal/runtime/logging/DebugLogger.java	Thu Jun 12 15:37:37 2014 -0700
+++ b/nashorn/src/jdk/nashorn/internal/runtime/logging/DebugLogger.java	Tue Jun 17 11:37:03 2014 +0200
@@ -540,7 +540,7 @@
 
     /**
      * Shorthand for outputting a log string as log level
-     * {@link java.util.logging.Level#FINE} on this logger
+     * {@link java.util.logging.Level#SEVERE} on this logger
      * @param objs object array to log - use this to perform lazy concatenation to avoid unconditional toString overhead
      */
     public void severe(final Object... objs) {
--- a/nashorn/test/src/UnnamedPackageTestCallback.java	Thu Jun 12 15:37:37 2014 -0700
+++ b/nashorn/test/src/UnnamedPackageTestCallback.java	Tue Jun 17 11:37:03 2014 +0200
@@ -23,6 +23,14 @@
  * questions.
  */
 
+/**
+ * Interface for callbacks used by the test suite.
+ */
 public interface UnnamedPackageTestCallback {
+    /**
+     * Call function
+     * @param s string argument
+     * @return string
+     */
     String call(String s);
 }