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
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
diff --git a/nashorn/bin/runoptdualcatch.sh b/nashorn/bin/runoptdualcatch.sh
index eca0327..7bde221 100644
--- a/nashorn/bin/runoptdualcatch.sh
+++ b/nashorn/bin/runoptdualcatch.sh
@@ -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 \
diff --git a/nashorn/src/jdk/nashorn/internal/codegen/Compiler.java b/nashorn/src/jdk/nashorn/internal/codegen/Compiler.java
index 2ab51de..881587b 100644
--- a/nashorn/src/jdk/nashorn/internal/codegen/Compiler.java
+++ b/nashorn/src/jdk/nashorn/internal/codegen/Compiler.java
@@ -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) {
diff --git a/nashorn/src/jdk/nashorn/internal/codegen/ObjectClassGenerator.java b/nashorn/src/jdk/nashorn/internal/codegen/ObjectClassGenerator.java
index b47b355..71cf33d 100644
--- a/nashorn/src/jdk/nashorn/internal/codegen/ObjectClassGenerator.java
+++ b/nashorn/src/jdk/nashorn/internal/codegen/ObjectClassGenerator.java
@@ -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);
}
diff --git a/nashorn/src/jdk/nashorn/internal/runtime/ScriptEnvironment.java b/nashorn/src/jdk/nashorn/internal/runtime/ScriptEnvironment.java
index 5b5c7f7..4a8e0fb 100644
--- a/nashorn/src/jdk/nashorn/internal/runtime/ScriptEnvironment.java
+++ b/nashorn/src/jdk/nashorn/internal/runtime/ScriptEnvironment.java
@@ -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)) {
diff --git a/nashorn/src/jdk/nashorn/internal/runtime/options/Options.java b/nashorn/src/jdk/nashorn/internal/runtime/options/Options.java
index cd774bb..ce7e4e4 100644
--- a/nashorn/src/jdk/nashorn/internal/runtime/options/Options.java
+++ b/nashorn/src/jdk/nashorn/internal/runtime/options/Options.java
@@ -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);
}