8037177: -Dnashorn.optimistic should be enabled by default, meaning that it has to be explicitly set to false to run with the jdk 8 style conservative types
authorlagergren
Wed, 12 Mar 2014 10:31:22 +0100
changeset 24722 f0c8b6256080
parent 24721 81f70e23cd3b
child 24723 215d17db59ad
8037177: -Dnashorn.optimistic should be enabled by default, meaning that it has to be explicitly set to false to run with the jdk 8 style conservative types Summary: This will be the new default setting, so the explicit flag should be removed, and instead reverse checked for explicitly DISABLED optimistic types. In the future, we might remove the flag altogether. Reviewed-by: attila, hannesw
nashorn/bin/runoptdualcatch.sh
nashorn/src/jdk/nashorn/internal/codegen/Compiler.java
nashorn/src/jdk/nashorn/internal/codegen/ObjectClassGenerator.java
nashorn/src/jdk/nashorn/internal/runtime/ScriptEnvironment.java
nashorn/src/jdk/nashorn/internal/runtime/options/Options.java
--- a/nashorn/bin/runoptdualcatch.sh	Wed Mar 05 09:51:00 2014 +0100
+++ b/nashorn/bin/runoptdualcatch.sh	Wed Mar 12 10:31:22 2014 +0100
@@ -12,7 +12,6 @@
 $FLAGS \
 -ea \
 -esa \
--Dnashorn.optimistic \
 -Xbootclasspath/p:$FAST_CATCH_COMBINATOR:$NASHORN_JAR \
 -Xms2G -Xmx2G \
 -XX:+UnlockCommercialFeatures \
@@ -26,7 +25,6 @@
 -cp $CLASSPATH:../build/test/classes/ \
 jdk.nashorn.tools.Shell ${@}
 
-#-XX:+UnlockDiagnosticVMOptions \
 #-XX:+ShowHiddenFrames \
 #-XX:+PrintOptoAssembly \
 #-XX:-TieredCompilation \
--- a/nashorn/src/jdk/nashorn/internal/codegen/Compiler.java	Wed Mar 05 09:51:00 2014 +0100
+++ b/nashorn/src/jdk/nashorn/internal/codegen/Compiler.java	Wed Mar 12 10:31:22 2014 +0100
@@ -107,8 +107,8 @@
     public static final DebugLogger LOG = new DebugLogger("compiler");
 
     static {
-        if (ScriptEnvironment.globalOptimistic()) {
-            LOG.warning("Running with optimistic types. This is experimental. To switch off, use -Dnashorn.optimistic=false");
+        if (!ScriptEnvironment.globalOptimistic()) {
+            LOG.warning("Running without optimistic types. This is a configuration that may be deprecated.");
         }
     }
 
@@ -229,7 +229,7 @@
     public FunctionNode compile(final String className, final FunctionNode functionNode) throws CompilationException {
         try {
             return compileInternal(className, functionNode);
-        } catch(AssertionError e) {
+        } catch(final AssertionError e) {
             throw new AssertionError("Assertion failure compiling " + functionNode.getSource(), e);
         }
     }
@@ -255,7 +255,7 @@
                 printMemoryUsage(phase.toString(), newFunctionNode);
             }
 
-            final long duration = Timing.isEnabled() ? (phase.getEndTime() - phase.getStartTime()) : 0L;
+            final long duration = Timing.isEnabled() ? phase.getEndTime() - phase.getStartTime() : 0L;
             time += duration;
 
             if (fine) {
--- a/nashorn/src/jdk/nashorn/internal/codegen/ObjectClassGenerator.java	Wed Mar 05 09:51:00 2014 +0100
+++ b/nashorn/src/jdk/nashorn/internal/codegen/ObjectClassGenerator.java	Wed Mar 12 10:31:22 2014 +0100
@@ -150,7 +150,7 @@
             LOG.warning("Running with primitive fields - there is untested functionality!");
             FIELD_TYPES.add(PRIMITIVE_FIELD_TYPE);
         } else {
-            System.err.println("Running with object fields only");
+            LOG.warning("Running with object fields only - this is a deprecated configuration.");
         }
         FIELD_TYPES.add(Type.OBJECT);
     }
--- a/nashorn/src/jdk/nashorn/internal/runtime/ScriptEnvironment.java	Wed Mar 05 09:51:00 2014 +0100
+++ b/nashorn/src/jdk/nashorn/internal/runtime/ScriptEnvironment.java	Wed Mar 12 10:31:22 2014 +0100
@@ -112,7 +112,7 @@
         ERROR
     }
 
-    private static final boolean GLOBAL_OPTIMISTIC = Options.getBooleanProperty("nashorn.optimistic");
+    private static final boolean GLOBAL_OPTIMISTIC = Options.getBooleanProperty("nashorn.optimistic", true);
 
     /**
      * What is the default optimistic compilation policy?
@@ -261,11 +261,11 @@
         String func = null;
         final String pc = options.getString("print.code");
         if (pc != null) {
-            StringTokenizer st = new StringTokenizer(pc, ",");
+            final StringTokenizer st = new StringTokenizer(pc, ",");
             while (st.hasMoreTokens()) {
-                StringTokenizer st2 = new StringTokenizer(st.nextToken(), ":");
+                final StringTokenizer st2 = new StringTokenizer(st.nextToken(), ":");
                 while (st2.hasMoreTokens()) {
-                    String cmd = st2.nextToken();
+                    final String cmd = st2.nextToken();
                     if ("dir".equals(cmd)) {
                         dir = st2.nextToken();
                     } else if ("function".equals(cmd)) {
--- a/nashorn/src/jdk/nashorn/internal/runtime/options/Options.java	Wed Mar 05 09:51:00 2014 +0100
+++ b/nashorn/src/jdk/nashorn/internal/runtime/options/Options.java	Wed Mar 12 10:31:22 2014 +0100
@@ -137,9 +137,10 @@
      * Convenience function for getting system properties in a safe way
 
      * @param name of boolean property
-     * @return true if set to true, false if unset or set to false
+     * @param defValue default value of boolean property
+     * @return true if set to true, default value if unset or set to false
      */
-    public static boolean getBooleanProperty(final String name) {
+    public static boolean getBooleanProperty(final String name, final Boolean defValue) {
         name.getClass(); // null check
         if (!name.startsWith("nashorn.")) {
             throw new IllegalArgumentException(name);
@@ -151,6 +152,9 @@
                     public Boolean run() {
                         try {
                             final String property = System.getProperty(name);
+                            if (property == null && defValue != null) {
+                                return defValue;
+                            }
                             return property != null && !"false".equalsIgnoreCase(property);
                         } catch (final SecurityException e) {
                             // if no permission to read, assume false
@@ -162,6 +166,16 @@
 
     /**
      * Convenience function for getting system properties in a safe way
+
+     * @param name of boolean property
+     * @return true if set to true, false if unset or set to false
+     */
+    public static boolean getBooleanProperty(final String name) {
+        return getBooleanProperty(name, null);
+    }
+
+    /**
+     * Convenience function for getting system properties in a safe way
      *
      * @param name of string property
      * @param defValue the default value if unset
@@ -525,7 +539,7 @@
             return new Option<>(value != null && Boolean.parseBoolean(value));
         case "integer":
             try {
-                return new Option<>((value == null) ? 0 : Integer.parseInt(value));
+                return new Option<>(value == null ? 0 : Integer.parseInt(value));
             } catch (final NumberFormatException nfe) {
                 throw new IllegalOptionException(t);
             }