-
Bug
-
Resolution: Fixed
-
P3
-
8u51, 9
-
b83
-
generic
-
generic
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8142283 | emb-9 | Sundararajan Athijegannathan | P3 | Resolved | Fixed | team |
JDK-8140986 | 8u91 | Sundararajan Athijegannathan | P3 | Resolved | Fixed | b01 |
JDK-8136616 | 8u72 | Sundararajan Athijegannathan | P3 | Resolved | Fixed | b01 |
JDK-8147355 | emb-8u91 | Sundararajan Athijegannathan | P3 | Resolved | Fixed | b01 |
From http://stackoverflow.com/questions/32585425/java-nashorn-inconsistent-binding-behavior-is-this-a-bug:
-------------------------------
import javax.script.Bindings;
import javax.script.ScriptContext;
import javax.script.ScriptEngine;
import jdk.nashorn.api.scripting.NashornScriptEngineFactory;
public class JsBugTest {
public static Object resolve(final ScriptEngine engine, final String script) {
Object r = null;
try {
r = engine.eval(script);
} catch (final Exception ex) {
System.out.println("exception: " + ex.getMessage());
r = null;
}
return r;
}
public static void runTest()
{
final ScriptEngine jsEngine = new NashornScriptEngineFactory().getScriptEngine("--log=fields", "-ot=false");
final String script = "DataA + 'foo';";
final Bindings binds = jsEngine.getBindings(ScriptContext.ENGINE_SCOPE);
Object ret;
for (int i = 0; i < 12; i++) {
binds.remove("DataA");
ret = resolve(jsEngine, script);
if (ret != null) {
System.out.println("Iteration " + i + ": Returned value should be null but is: \"" + ret + "\"");
}
binds.put("DataA", "foo");
ret = resolve(jsEngine, script);
if (ret == null) {
System.out.println("Iteration " + i + " failed");
}
}
}
public static void main(final String[] args) {
JsBugTest.runTest();
}
}
-------------------------------
The program prints:
exception: ReferenceError: "DataA" is not defined in <eval> at line number 1
but then on iteration 8 starts printing:
Iteration 8: Returned value should be null but is: "undefinedfoo"
Running with "--log=fields" we see:
exception: ReferenceError: "DataA" is not defined in <eval> at line number 1
[fields] Megamorphic getter: dyn:getProp|getElem|getMethod:DataA(Object)Object@jdk.nashorn.internal.scripts.Script$\^eval\_ DataA false
Iteration 8: Returned value should be null but is: "undefinedfoo"
That is, we switch the call site to a megamorphic getter right before the incorrect behaviour starts happening.
-------------------------------
import javax.script.Bindings;
import javax.script.ScriptContext;
import javax.script.ScriptEngine;
import jdk.nashorn.api.scripting.NashornScriptEngineFactory;
public class JsBugTest {
public static Object resolve(final ScriptEngine engine, final String script) {
Object r = null;
try {
r = engine.eval(script);
} catch (final Exception ex) {
System.out.println("exception: " + ex.getMessage());
r = null;
}
return r;
}
public static void runTest()
{
final ScriptEngine jsEngine = new NashornScriptEngineFactory().getScriptEngine("--log=fields", "-ot=false");
final String script = "DataA + 'foo';";
final Bindings binds = jsEngine.getBindings(ScriptContext.ENGINE_SCOPE);
Object ret;
for (int i = 0; i < 12; i++) {
binds.remove("DataA");
ret = resolve(jsEngine, script);
if (ret != null) {
System.out.println("Iteration " + i + ": Returned value should be null but is: \"" + ret + "\"");
}
binds.put("DataA", "foo");
ret = resolve(jsEngine, script);
if (ret == null) {
System.out.println("Iteration " + i + " failed");
}
}
}
public static void main(final String[] args) {
JsBugTest.runTest();
}
}
-------------------------------
The program prints:
exception: ReferenceError: "DataA" is not defined in <eval> at line number 1
but then on iteration 8 starts printing:
Iteration 8: Returned value should be null but is: "undefinedfoo"
Running with "--log=fields" we see:
exception: ReferenceError: "DataA" is not defined in <eval> at line number 1
[fields] Megamorphic getter: dyn:getProp|getElem|getMethod:DataA(Object)Object@jdk.nashorn.internal.scripts.Script$\^eval\_ DataA false
Iteration 8: Returned value should be null but is: "undefinedfoo"
That is, we switch the call site to a megamorphic getter right before the incorrect behaviour starts happening.
- backported by
-
JDK-8136616 Call site switching to megamorphic causes incorrect property read
-
- Resolved
-
-
JDK-8140986 Call site switching to megamorphic causes incorrect property read
-
- Resolved
-
-
JDK-8142283 Call site switching to megamorphic causes incorrect property read
-
- Resolved
-
-
JDK-8147355 Call site switching to megamorphic causes incorrect property read
-
- Resolved
-