8044502: Get rid of global optimistic flag
authorattila
Wed, 04 Jun 2014 14:32:23 +0200
changeset 24779 3bf490e146c3
parent 24778 2ff5d7041566
child 24780 747cf25884d6
8044502: Get rid of global optimistic flag Reviewed-by: lagergren, sundar
nashorn/make/build.xml
nashorn/src/jdk/nashorn/api/scripting/NashornScriptEngine.java
nashorn/src/jdk/nashorn/internal/codegen/Compiler.java
nashorn/src/jdk/nashorn/internal/codegen/ObjectClassGenerator.java
nashorn/src/jdk/nashorn/internal/runtime/CompiledFunction.java
nashorn/src/jdk/nashorn/internal/runtime/Context.java
nashorn/src/jdk/nashorn/internal/runtime/ScriptEnvironment.java
nashorn/src/jdk/nashorn/internal/runtime/resources/Options.properties
nashorn/test/script/trusted/event_queue.js
nashorn/test/script/trusted/optimistic_recompilation.js
nashorn/test/src/jdk/nashorn/api/javaaccess/NumberAccessTest.java
nashorn/test/src/jdk/nashorn/api/javaaccess/NumberBoxingTest.java
nashorn/test/src/jdk/nashorn/internal/runtime/CodeStoreAndPathTest.java
--- a/nashorn/make/build.xml	Wed Jun 04 13:08:57 2014 +0200
+++ b/nashorn/make/build.xml	Wed Jun 04 14:32:23 2014 +0200
@@ -364,6 +364,7 @@
   </target>
 
   <target name="test" depends="jar, check-testng, check-external-tests, compile-test, generate-policy-file" if="testng.available">
+    <delete dir="${build.dir}/nashorn_code_cache"/>
     <fileset id="test.classes" dir="${build.test.classes.dir}">
       <include name="**/api/javaaccess/*Test.class"/>
       <include name="**/api/scripting/*Test.class"/>
@@ -373,30 +374,12 @@
       <include name="**/runtime/regexp/*Test.class"/>
       <include name="**/runtime/regexp/joni/*Test.class"/>
       <include name="**/framework/*Test.class"/>
-      <exclude name="jdk/nashorn/internal/runtime/CodeStoreAndPathTest.class"/>
     </fileset>
 
     <fileset id="test.nosecurity.classes" dir="${build.test.classes.dir}">
       <include name="**/framework/ScriptTest.class"/>
     </fileset>
 
-    <fileset id="test.nooptimistic.classes" dir="${build.test.classes.dir}">
-      <include name="jdk/nashorn/internal/runtime/CodeStoreAndPathTest.class"/>
-    </fileset>
-
-    <testng outputdir="${build.nooptimistic.test.results.dir}" classfilesetref="test.nooptimistic.classes"
-       verbose="${testng.verbose}" haltonfailure="true" useDefaultListeners="false" listeners="${testng.listeners}" workingDir="${basedir}">
-      <jvmarg line="${ext.class.path}"/>
-      <jvmarg line="${run.test.jvmargs} -Xmx${run.test.xmx} ${run.test.jvmsecurityargs}"/>
-      <sysproperty key="nashorn.optimistic" value="false"/>
-      <propertyset>
-        <propertyref prefix="nashorn."/>
-      </propertyset>
-      <classpath>
-          <pathelement path="${run.test.classpath}"/>
-      </classpath>
-    </testng>
-
     <testng outputdir="${build.test.results.dir}" classfilesetref="test.classes"
        verbose="${testng.verbose}" haltonfailure="true" useDefaultListeners="false" listeners="${testng.listeners}" workingDir="${basedir}">
       <jvmarg line="${ext.class.path}"/>
--- a/nashorn/src/jdk/nashorn/api/scripting/NashornScriptEngine.java	Wed Jun 04 13:08:57 2014 +0200
+++ b/nashorn/src/jdk/nashorn/api/scripting/NashornScriptEngine.java	Wed Jun 04 14:32:23 2014 +0200
@@ -59,7 +59,6 @@
 import jdk.nashorn.internal.runtime.Context;
 import jdk.nashorn.internal.runtime.ErrorManager;
 import jdk.nashorn.internal.runtime.Property;
-import jdk.nashorn.internal.runtime.ScriptEnvironment;
 import jdk.nashorn.internal.runtime.ScriptFunction;
 import jdk.nashorn.internal.runtime.ScriptObject;
 import jdk.nashorn.internal.runtime.ScriptRuntime;
@@ -636,15 +635,6 @@
         };
     }
 
-    /**
-     * Check if the global script environment tells us to do optimistic
-     * compilation
-     * @return true if optimistic compilation enabled
-     */
-    public static boolean isOptimistic() {
-        return ScriptEnvironment.globalOptimistic();
-    }
-
     private ScriptFunction compileImpl(final Source source, final ScriptContext ctxt) throws ScriptException {
         return compileImpl(source, getNashornGlobalFrom(ctxt));
     }
--- a/nashorn/src/jdk/nashorn/internal/codegen/Compiler.java	Wed Jun 04 13:08:57 2014 +0200
+++ b/nashorn/src/jdk/nashorn/internal/codegen/Compiler.java	Wed Jun 04 14:32:23 2014 +0200
@@ -143,8 +143,6 @@
      */
     private RecompilableScriptFunctionData compiledFunction;
 
-    private static boolean initialized = false;
-
     /**
      * Compilation phases that a compilation goes through
      */
@@ -368,14 +366,7 @@
         this.firstCompileUnitName     = firstCompileUnitName();
         this.strict                   = isStrict;
 
-        if (!initialized) {
-            initialized = true;
-            if (!ScriptEnvironment.globalOptimistic()) {
-                log.warning("Running without optimistic types. This is a configuration that may be deprecated.");
-            }
-        }
-
-        this.optimistic = ScriptEnvironment.globalOptimistic();
+        this.optimistic = env._optimistic_types;
     }
 
     private static String safeSourceName(final ScriptEnvironment env, final CodeInstaller<ScriptEnvironment> installer, final Source source) {
--- a/nashorn/src/jdk/nashorn/internal/codegen/ObjectClassGenerator.java	Wed Jun 04 13:08:57 2014 +0200
+++ b/nashorn/src/jdk/nashorn/internal/codegen/ObjectClassGenerator.java	Wed Jun 04 14:32:23 2014 +0200
@@ -99,13 +99,6 @@
     private final DebugLogger log;
 
     /**
-     * is field debugging enabled. Several modules in codegen and properties use this, hence
-     * public access.
-     */
-
-    private static final boolean EXPLICIT_OBJECT = Options.getBooleanProperty("nashorn.fields.objects");
-
-    /**
      * Should the runtime only use java.lang.Object slots for fields? If this is false, the representation
      * will be a primitive 64-bit long value used for all primitives and a java.lang.Object for references.
      * This introduces a larger number of method handles in the system, as we need to have different getters
@@ -113,7 +106,7 @@
      *
      * This is engineered to plug into the TaggedArray implementation, when it's done.
      */
-    public static final boolean OBJECT_FIELDS_ONLY = EXPLICIT_OBJECT || !ScriptEnvironment.globalOptimistic();
+    public static final boolean OBJECT_FIELDS_ONLY = Options.getBooleanProperty("nashorn.fields.objects");
 
     /** The field types in the system */
     private static final List<Type> FIELD_TYPES = new LinkedList<>();
--- a/nashorn/src/jdk/nashorn/internal/runtime/CompiledFunction.java	Wed Jun 04 13:08:57 2014 +0200
+++ b/nashorn/src/jdk/nashorn/internal/runtime/CompiledFunction.java	Wed Jun 04 14:32:23 2014 +0200
@@ -424,11 +424,6 @@
     }
 
     boolean matchesCallSite(final MethodType callSiteType, final boolean pickVarArg) {
-        if (!ScriptEnvironment.globalOptimistic()) {
-            // Without optimistic recompilation, always choose the first eagerly compiled version.
-            return true;
-        }
-
         final MethodType type  = type();
         final int fnParamCount = getParamCount(type);
         final boolean isVarArg = fnParamCount == Integer.MAX_VALUE;
--- a/nashorn/src/jdk/nashorn/internal/runtime/Context.java	Wed Jun 04 13:08:57 2014 +0200
+++ b/nashorn/src/jdk/nashorn/internal/runtime/Context.java	Wed Jun 04 14:32:23 2014 +0200
@@ -440,7 +440,7 @@
         }
 
         if (env._persistent_cache) {
-            if (env._lazy_compilation || ScriptEnvironment.globalOptimistic()) {
+            if (env._lazy_compilation || env._optimistic_types) {
                 getErr().println("Can not use persistent class caching with lazy compilation or optimistic compilation.");
             } else {
                 try {
--- a/nashorn/src/jdk/nashorn/internal/runtime/ScriptEnvironment.java	Wed Jun 04 13:08:57 2014 +0200
+++ b/nashorn/src/jdk/nashorn/internal/runtime/ScriptEnvironment.java	Wed Jun 04 14:32:23 2014 +0200
@@ -118,16 +118,6 @@
         ERROR
     }
 
-    private static final boolean GLOBAL_OPTIMISTIC = Options.getBooleanProperty("nashorn.optimistic", true);
-
-    /**
-     * What is the default optimistic compilation policy?
-     * @return true if optimistic, false otherwise
-     */
-    public static boolean globalOptimistic() {
-        return GLOBAL_OPTIMISTIC;
-    }
-
     /**
      * Behavior when encountering a function declaration in a lexical context where only statements are acceptable
      * (function declarations are source elements, but not statements).
@@ -137,6 +127,9 @@
     /** Should lazy compilation take place */
     public final boolean _lazy_compilation;
 
+    /** Should optimistic types be used */
+    public final boolean _optimistic_types;
+
     /** Create a new class loaded for each compilation */
     public final boolean _loader_per_compile;
 
@@ -244,6 +237,7 @@
         _fx                   = options.getBoolean("fx");
         _global_per_engine    = options.getBoolean("global.per.engine");
         _lazy_compilation     = options.getBoolean("lazy.compilation");
+        _optimistic_types     = options.getBoolean("optimistic.types");
         _loader_per_compile   = options.getBoolean("loader.per.compile");
         _no_java              = options.getBoolean("no.java");
         _no_syntax_extensions = options.getBoolean("no.syntax.extensions");
--- a/nashorn/src/jdk/nashorn/internal/runtime/resources/Options.properties	Wed Jun 04 13:08:57 2014 +0200
+++ b/nashorn/src/jdk/nashorn/internal/runtime/resources/Options.properties	Wed Jun 04 14:32:23 2014 +0200
@@ -197,7 +197,15 @@
 nashorn.option.lazy.compilation = {                                                                      \
     name="--lazy-compilation",                                                                           \
     is_undocumented=true,                                                                                \
-    desc="Use lazy code generation strategies - do not compile the entire script at once." \
+    desc="Use lazy code generation strategies - do not compile the entire script at once.", \
+    default=true                                   \
+}
+
+nashorn.option.optimistic.types = {                                                                      \
+    name="--optimistic-types",                                                                           \
+    is_undocumented=true,                                                                                \
+    desc="Use optimistic type assumptions with deoptimizing recompilation.", \
+    default=true                                   \
 }
 
 nashorn.option.loader.per.compile = {              \
--- a/nashorn/test/script/trusted/event_queue.js	Wed Jun 04 13:08:57 2014 +0200
+++ b/nashorn/test/script/trusted/event_queue.js	Wed Jun 04 14:32:23 2014 +0200
@@ -29,7 +29,6 @@
  * @fork
  * @option -Dnashorn.debug=true
  * @option --log=recompile:quiet
- * @option --lazy-compilation
  */
 
 print(Debug);
--- a/nashorn/test/script/trusted/optimistic_recompilation.js	Wed Jun 04 13:08:57 2014 +0200
+++ b/nashorn/test/script/trusted/optimistic_recompilation.js	Wed Jun 04 14:32:23 2014 +0200
@@ -28,7 +28,6 @@
  * @fork
  * @option -Dnashorn.debug=true
  * @option --log=recompile:quiet
- * @option --lazy-compilation
  */
 
 var forName       = java.lang.Class["forName(String)"];
--- a/nashorn/test/src/jdk/nashorn/api/javaaccess/NumberAccessTest.java	Wed Jun 04 13:08:57 2014 +0200
+++ b/nashorn/test/src/jdk/nashorn/api/javaaccess/NumberAccessTest.java	Wed Jun 04 14:32:23 2014 +0200
@@ -32,7 +32,6 @@
 import javax.script.ScriptEngine;
 import javax.script.ScriptEngineManager;
 import javax.script.ScriptException;
-import jdk.nashorn.api.scripting.NashornScriptEngine;
 import org.testng.TestNG;
 import org.testng.annotations.AfterClass;
 import org.testng.annotations.BeforeClass;
@@ -47,7 +46,6 @@
 
     private static ScriptEngine e;
     private static SharedObject o;
-    private static boolean optimistic;
 
     public static void main(final String[] args) {
         TestNG.main(args);
@@ -57,7 +55,6 @@
     public static void setUpClass() throws ScriptException {
         final ScriptEngineManager m = new ScriptEngineManager();
         e = m.getEngineByName("nashorn");
-        optimistic = ((NashornScriptEngine)e).isOptimistic();
         o = new SharedObject();
         e.put("o", o);
         e.eval("var SharedObject = Packages.jdk.nashorn.api.javaaccess.SharedObject;");
@@ -267,11 +264,7 @@
     @Test
     public void accessFieldByte() throws ScriptException {
         e.eval("var p_byte = o.publicByte;");
-        if(optimistic) {
-            assertEquals((int)o.publicByte, e.get("p_byte"));
-        } else {
-            assertEquals(o.publicByte, e.get("p_byte"));
-        }
+        assertEquals((double)o.publicByte, ((Number)e.get("p_byte")).doubleValue());
         e.eval("o.publicByte = 16;");
         assertEquals(16, o.publicByte);
     }
@@ -294,11 +287,7 @@
     @Test
     public void accessStaticFieldByte() throws ScriptException {
         e.eval("var ps_byte = SharedObject.publicStaticByte;");
-        if(optimistic) {
-            assertEquals((int)SharedObject.publicStaticByte, e.get("ps_byte"));
-        } else {
-            assertEquals(SharedObject.publicStaticByte, e.get("ps_byte"));
-        }
+        assertEquals((double)SharedObject.publicStaticByte, ((Number)e.get("ps_byte")).doubleValue());
         e.eval("SharedObject.publicStaticByte = 16;");
         assertEquals(16, SharedObject.publicStaticByte);
     }
@@ -321,11 +310,7 @@
     @Test
     public void accessFinalFieldByte() throws ScriptException {
         e.eval("var pf_byte = o.publicFinalByte;");
-        if(optimistic) {
-            assertEquals((int)o.publicFinalByte, e.get("pf_byte"));
-        } else {
-            assertEquals(o.publicFinalByte, e.get("pf_byte"));
-        }
+        assertEquals((double)o.publicFinalByte, ((Number)e.get("pf_byte")).doubleValue());
         e.eval("o.publicFinalByte = 16;");
         assertEquals(-7, o.publicFinalByte);
     }
@@ -348,11 +333,7 @@
     @Test
     public void accessStaticFinalFieldByte() throws ScriptException {
         e.eval("var psf_byte = SharedObject.publicStaticFinalByte;");
-        if(optimistic) {
-            assertEquals((int)SharedObject.publicStaticFinalByte, e.get("psf_byte"));
-        } else {
-            assertEquals(SharedObject.publicStaticFinalByte, e.get("psf_byte"));
-        }
+        assertEquals((double)SharedObject.publicStaticFinalByte, ((Number)e.get("psf_byte")).doubleValue());
         e.eval("SharedObject.publicStaticFinalByte = 16;");
         assertEquals(-70, SharedObject.publicStaticFinalByte);
     }
@@ -377,11 +358,7 @@
     @Test
     public void accessFieldShort() throws ScriptException {
         e.eval("var p_short = o.publicShort;");
-        if(optimistic) {
-            assertEquals((int)o.publicShort, e.get("p_short"));
-        } else {
-            assertEquals(o.publicShort, e.get("p_short"));
-        }
+        assertEquals((double)o.publicShort, ((Number)e.get("p_short")).doubleValue());
         e.eval("o.publicShort = 18;");
         assertEquals(18, o.publicShort);
     }
@@ -404,11 +381,7 @@
     @Test
     public void accessStaticFieldShort() throws ScriptException {
         e.eval("var ps_short = SharedObject.publicStaticShort;");
-        if(optimistic) {
-            assertEquals((int)SharedObject.publicStaticShort, e.get("ps_short"));
-        } else {
-            assertEquals(SharedObject.publicStaticShort, e.get("ps_short"));
-        }
+        assertEquals((double)SharedObject.publicStaticShort, ((Number)e.get("ps_short")).doubleValue());
         e.eval("SharedObject.publicStaticShort = 180;");
         assertEquals(180, SharedObject.publicStaticShort);
     }
@@ -431,11 +404,7 @@
     @Test
     public void accessFinalFieldShort() throws ScriptException {
         e.eval("var pf_short = o.publicFinalShort;");
-        if(optimistic) {
-            assertEquals((int)o.publicFinalShort, e.get("pf_short"));
-        } else {
-            assertEquals(o.publicFinalByte, e.get("pf_byte"));
-        }
+        assertEquals((double)o.publicFinalShort, ((Number)e.get("pf_short")).doubleValue());
         e.eval("o.publicFinalShort = 180;");
         assertEquals(31220, o.publicFinalShort);
     }
@@ -458,11 +427,7 @@
     @Test
     public void accessStaticFinalFieldShort() throws ScriptException {
         e.eval("var psf_short = SharedObject.publicStaticFinalShort;");
-        if(optimistic) {
-            assertEquals((int)SharedObject.publicStaticFinalShort, e.get("psf_short"));
-        } else {
-            assertEquals(SharedObject.publicStaticFinalShort, e.get("psf_short"));
-        }
+        assertEquals((double)SharedObject.publicStaticFinalShort, ((Number)e.get("psf_short")).doubleValue());
         e.eval("SharedObject.publicStaticFinalShort = 180;");
         assertEquals(8888, SharedObject.publicStaticFinalShort);
     }
@@ -590,11 +555,7 @@
     @Test
     public void accessFieldFloat() throws ScriptException {
         e.eval("var p_float = o.publicFloat;");
-        if(optimistic) {
-            assertEquals((double)o.publicFloat, e.get("p_float"));
-        } else {
-            assertEquals(o.publicFloat, e.get("p_float"));
-        }
+        assertEquals((double)o.publicFloat, ((Number)e.get("p_float")).doubleValue());
         o.publicFloat = 0.0f / 0.0f;
         assertEquals(true, e.eval("isNaN(o.publicFloat)"));
         o.publicFloat = 1.0f / 0.0f;
@@ -629,12 +590,7 @@
     @Test
     public void accessStaticFieldFloat() throws ScriptException {
         e.eval("var ps_float = SharedObject.publicStaticFloat;");
-        if(optimistic) {
-            assertTrue((int)SharedObject.publicStaticFloat == SharedObject.publicStaticFloat);
-            assertEquals((int)SharedObject.publicStaticFloat, e.get("ps_float"));
-        } else {
-            assertEquals(SharedObject.publicStaticFloat, e.get("ps_float"));
-        }
+        assertEquals((double)SharedObject.publicStaticFloat, ((Number)e.get("ps_float")).doubleValue());
         SharedObject.publicStaticFloat = 0.0f / 0.0f;
         assertEquals(true, e.eval("isNaN(SharedObject.publicStaticFloat)"));
         SharedObject.publicStaticFloat = 1.0f / 0.0f;
@@ -669,12 +625,7 @@
     @Test
     public void accessFinalFloat() throws ScriptException {
         e.eval("var pf_float = o.publicFinalFloat;");
-        if(optimistic) {
-            assertTrue((int)o.publicFinalFloat == o.publicFinalFloat);
-            assertEquals((int)o.publicFinalFloat, e.get("pf_float"));
-        } else {
-            assertEquals(o.publicFinalFloat, e.get("pf_float"));
-        }
+        assertEquals((double)o.publicFinalFloat, ((Number)e.get("pf_float")).doubleValue());
         e.eval("o.publicFinalFloat = 20.0;");
         assertEquals(7.72e8f, o.publicFinalFloat, 1e-10);
     }
@@ -697,12 +648,7 @@
     @Test
     public void accessStaticFinalFieldFloat() throws ScriptException {
         e.eval("var psf_float = SharedObject.publicStaticFinalFloat;");
-        if(optimistic) {
-            assertTrue(((int)SharedObject.publicStaticFinalFloat) == SharedObject.publicStaticFinalFloat);
-            assertEquals((int)SharedObject.publicStaticFinalFloat, e.get("psf_float"));
-        } else {
-            assertEquals(SharedObject.publicStaticFinalFloat, e.get("psf_float"));
-        }
+        assertEquals((double)SharedObject.publicStaticFinalFloat, ((Number)e.get("psf_float")).doubleValue());
         e.eval("SharedObject.publicStaticFinalFloat = 20.0;");
         assertEquals(0.72e8f, SharedObject.publicStaticFinalFloat, 1e-10);
     }
--- a/nashorn/test/src/jdk/nashorn/api/javaaccess/NumberBoxingTest.java	Wed Jun 04 13:08:57 2014 +0200
+++ b/nashorn/test/src/jdk/nashorn/api/javaaccess/NumberBoxingTest.java	Wed Jun 04 14:32:23 2014 +0200
@@ -31,7 +31,6 @@
 import javax.script.ScriptEngine;
 import javax.script.ScriptEngineManager;
 import javax.script.ScriptException;
-import jdk.nashorn.api.scripting.NashornScriptEngine;
 import org.testng.TestNG;
 import org.testng.annotations.AfterClass;
 import org.testng.annotations.BeforeClass;
@@ -46,7 +45,6 @@
 
     private static ScriptEngine e;
     private static SharedObject o;
-    private static boolean optimistic;
 
     public static void main(final String[] args) {
         TestNG.main(args);
@@ -56,7 +54,6 @@
     public static void setUpClass() throws ScriptException {
         final ScriptEngineManager m = new ScriptEngineManager();
         e = m.getEngineByName("nashorn");
-        optimistic = ((NashornScriptEngine)e).isOptimistic();
         o = new SharedObject();
         e.put("o", o);
         e.eval("var SharedObject = Packages.jdk.nashorn.api.javaaccess.SharedObject;");
@@ -141,7 +138,7 @@
     @Test
     public void accessFieldByteBoxing() throws ScriptException {
         e.eval("var p_byte = o.publicByteBox;");
-        assertEqualsInt(o.publicByteBox, "p_byte");
+        assertEqualsDouble(o.publicByteBox, "p_byte");
         e.eval("o.publicByteBox = 16;");
         assertEquals(Byte.valueOf((byte)16), o.publicByteBox);
     }
@@ -149,7 +146,7 @@
     @Test
     public void accessStaticFieldByteBoxing() throws ScriptException {
         e.eval("var ps_byte = SharedObject.publicStaticByte;");
-        assertEqualsInt(SharedObject.publicStaticByte, "ps_byte");
+        assertEqualsDouble(SharedObject.publicStaticByte, "ps_byte");
         e.eval("SharedObject.publicStaticByte = 16;");
         assertEquals(16, SharedObject.publicStaticByte);
     }
@@ -157,7 +154,7 @@
     @Test
     public void accessFinalFieldByteBoxing() throws ScriptException {
         e.eval("var pf_byte = o.publicFinalByteBox;");
-        assertEqualsInt(o.publicFinalByteBox, "pf_byte");
+        assertEqualsDouble(o.publicFinalByteBox, "pf_byte");
         e.eval("o.publicFinalByteBox = 16;");
         assertEquals(Byte.valueOf((byte)19), o.publicFinalByteBox);
     }
@@ -165,7 +162,7 @@
     @Test
     public void accessStaticFinalFieldByteBoxing() throws ScriptException {
         e.eval("var psf_byte = SharedObject.publicStaticFinalByte;");
-        assertEqualsInt(SharedObject.publicStaticFinalByte, "psf_byte");
+        assertEqualsDouble(SharedObject.publicStaticFinalByte, "psf_byte");
         e.eval("SharedObject.publicStaticFinalByte = 16;");
         assertEquals(-70, SharedObject.publicStaticFinalByte);
     }
@@ -175,23 +172,19 @@
     @Test
     public void accessFieldShortBoxing() throws ScriptException {
         e.eval("var p_short = o.publicShortBox;");
-        assertEqualsInt(o.publicShortBox, "p_short");
+        assertEqualsDouble(o.publicShortBox, "p_short");
         e.eval("o.publicShortBox = 18;");
         assertEquals(Short.valueOf((short)18), o.publicShortBox);
     }
 
-    private static void assertEqualsInt(final Number n, final String name) {
-        if(optimistic) {
-            assertEquals(n.intValue(), e.get(name));
-        } else {
-            assertEquals(n, e.get(name));
-        }
+    private static void assertEqualsDouble(final Number n, final String name) {
+        assertEquals(n.doubleValue(), ((Number)e.get(name)).doubleValue());
     }
 
     @Test
     public void accessStaticFieldShortBoxing() throws ScriptException {
         e.eval("var ps_short = SharedObject.publicStaticShort;");
-        assertEqualsInt(SharedObject.publicStaticShort, "ps_short");
+        assertEqualsDouble(SharedObject.publicStaticShort, "ps_short");
         e.eval("SharedObject.publicStaticShort = 180;");
         assertEquals(180, SharedObject.publicStaticShort);
     }
@@ -199,7 +192,7 @@
     @Test
     public void accessFinalFieldShortBoxing() throws ScriptException {
         e.eval("var pf_short = o.publicFinalShortBox;");
-        assertEqualsInt(o.publicFinalShortBox, "pf_short");
+        assertEqualsDouble(o.publicFinalShortBox, "pf_short");
         e.eval("o.publicFinalShortBox = 180;");
         assertEquals(Short.valueOf((short)-26777), o.publicFinalShortBox);
     }
@@ -207,7 +200,7 @@
     @Test
     public void accessStaticFinalFieldShortBoxing() throws ScriptException {
         e.eval("var psf_short = SharedObject.publicStaticFinalShort;");
-        assertEqualsInt(SharedObject.publicStaticFinalShort, "psf_short");
+        assertEqualsDouble(SharedObject.publicStaticFinalShort, "psf_short");
         e.eval("SharedObject.publicStaticFinalShort = 180;");
         assertEquals(8888, SharedObject.publicStaticFinalShort);
     }
@@ -258,7 +251,7 @@
     @Test
     public void accessFieldFloatBoxing() throws ScriptException {
         e.eval("var p_float = o.publicFloatBox;");
-        assertEqualsFloat(o.publicFloatBox, "p_float");
+        assertEqualsDouble(o.publicFloatBox, "p_float");
         o.publicFloatBox = 0.0f / 0.0f;
         assertEquals(true, e.eval("isNaN(o.publicFloatBox)"));
         o.publicFloatBox = 1.0f / 0.0f;
@@ -275,17 +268,10 @@
         assertEquals(Float.NEGATIVE_INFINITY, o.publicFloatBox, 1e-10);
     }
 
-    private static void assertEqualsFloat(final Float n, final String name) {
-        if(optimistic) {
-            assertEquals(n, ((Number)e.get(name)).floatValue());
-        } else {
-            assertEquals(n, e.get(name));
-        }
-    }
     @Test
     public void accessStaticFieldFloatBoxing() throws ScriptException {
         e.eval("var ps_float = SharedObject.publicStaticFloat;");
-        assertEqualsFloat(SharedObject.publicStaticFloat, "ps_float");
+        assertEqualsDouble(SharedObject.publicStaticFloat, "ps_float");
         SharedObject.publicStaticFloat = 0.0f / 0.0f;
         assertEquals(true, e.eval("isNaN(SharedObject.publicStaticFloat)"));
         SharedObject.publicStaticFloat = 1.0f / 0.0f;
@@ -305,7 +291,7 @@
     @Test
     public void accessFinalFloatBoxing() throws ScriptException {
         e.eval("var pf_float = o.publicFinalFloatBox;");
-        assertEqualsFloat(o.publicFinalFloatBox, "pf_float");
+        assertEqualsDouble(o.publicFinalFloatBox, "pf_float");
         e.eval("o.publicFinalFloatBox = 20.0;");
         assertEquals(1.372e4f, o.publicFinalFloatBox, 1e-10);
     }
@@ -313,7 +299,7 @@
     @Test
     public void accessStaticFinalFieldFloatBoxing() throws ScriptException {
         e.eval("var psf_float = SharedObject.publicStaticFinalFloat;");
-        assertEqualsFloat(SharedObject.publicStaticFinalFloat, "psf_float");
+        assertEqualsDouble(SharedObject.publicStaticFinalFloat, "psf_float");
         e.eval("SharedObject.publicStaticFinalFloat = 20.0;");
         assertEquals(0.72e8f, SharedObject.publicStaticFinalFloat, 1e-10);
     }
--- a/nashorn/test/src/jdk/nashorn/internal/runtime/CodeStoreAndPathTest.java	Wed Jun 04 13:08:57 2014 +0200
+++ b/nashorn/test/src/jdk/nashorn/internal/runtime/CodeStoreAndPathTest.java	Wed Jun 04 14:32:23 2014 +0200
@@ -96,6 +96,8 @@
     final String codeCache = "build/nashorn_code_cache";
     final String oldUserDir = System.getProperty("user.dir");
 
+    private static final String[] ENGINE_OPTIONS = new String[]{"--persistent-code-cache", "--optimistic-types=false", "--lazy-compilation=false"};
+
     public void checkCompiledScripts(final DirectoryStream<Path> stream, int numberOfScripts) throws IOException {
         for (final Path file : stream) {
             numberOfScripts--;
@@ -106,11 +108,9 @@
 
     @Test
     public void pathHandlingTest() throws ScriptException, IOException {
-        assertFalse(ScriptEnvironment.globalOptimistic());
         System.setProperty("nashorn.persistent.code.cache", codeCache);
-        final String[] options = new String[]{"--persistent-code-cache"};
         final NashornScriptEngineFactory fac = new NashornScriptEngineFactory();
-        final ScriptEngine e = fac.getScriptEngine(options);
+        final ScriptEngine e = fac.getScriptEngine(ENGINE_OPTIONS);
         final Path expectedCodeCachePath = FileSystems.getDefault().getPath(oldUserDir + File.separator + codeCache);
         final Path actualCodeCachePath = FileSystems.getDefault().getPath(System.getProperty(
                             "nashorn.persistent.code.cache")).toAbsolutePath();
@@ -124,11 +124,9 @@
 
     @Test
     public void changeUserDirTest() throws ScriptException, IOException {
-        assertFalse(ScriptEnvironment.globalOptimistic());
         System.setProperty("nashorn.persistent.code.cache", codeCache);
-        final String[] options = new String[]{"--persistent-code-cache"};
         final NashornScriptEngineFactory fac = new NashornScriptEngineFactory();
-        final ScriptEngine e = fac.getScriptEngine(options);
+        final ScriptEngine e = fac.getScriptEngine(ENGINE_OPTIONS);
         final Path codeCachePath = FileSystems.getDefault().getPath(System.getProperty(
                             "nashorn.persistent.code.cache")).toAbsolutePath();
         final String newUserDir = "build/newUserDir";
@@ -148,11 +146,9 @@
 
     @Test
     public void codeCacheTest() throws ScriptException, IOException {
-        assertFalse(ScriptEnvironment.globalOptimistic());
         System.setProperty("nashorn.persistent.code.cache", codeCache);
-        final String[] options = new String[]{"--persistent-code-cache"};
         final NashornScriptEngineFactory fac = new NashornScriptEngineFactory();
-        final ScriptEngine e = fac.getScriptEngine(options);
+        final ScriptEngine e = fac.getScriptEngine(ENGINE_OPTIONS);
         final Path codeCachePath = FileSystems.getDefault().getPath(System.getProperty(
                             "nashorn.persistent.code.cache")).toAbsolutePath();
         e.eval(code1);