Seems to be some sort of binding limit around 500 mark for Nashorn

Paul Taylor paultaylor at jthink.net
Thu Sep 26 12:51:14 UTC 2024


HI, my code loads a Nashorn Script Engine binding values representing 
metadata fields and allows user to write Javascript to modify those 
metadata fields by passing the script to the eval method and then 
checking for modified metadata values. It was working fine but as I have 
increased the number of values added to the bindings I have unexpected 
issues that some binding variables values are missing or changed despite 
the script not modifying these values.

I am now able to mimic the problem with self contained example

|import javax.script.ScriptContext; import javax.script.ScriptEngine; 
public class JsTest { public static void main(String[] args) throws 
Exception { int numberOfBindingVars = Integer.parseInt(args[0]); 
ScriptEngine engine; for(int i=0; i<10; i++) { engine = new 
org.openjdk.nashorn.api.scripting.NashornScriptEngineFactory().getScriptEngine(); 
for(int k=0;k<numberOfBindingVars;k++) { engine.put("var"+k,"1963"); } 
System.out.println(String.format("Bindings %d", 
engine.getBindings(ScriptContext.ENGINE_SCOPE).size())); for(int 
k=0;k<numberOfBindingVars;k++) { if(engine.get("var"+k)==null) { 
System.out.println("Missing var"+k); } } } } } Running this with 
parameter **400** works fine and gives me Bindings 400 Bindings 400 
Bindings 400 Bindings 400 Bindings 400 Bindings 400 Bindings 400 
Bindings 400 Bindings 400 Bindings 400 But if I increase parameter to 
**500** the binding count is inconsistent , although wierdly checking 
for each value doesnt reveal any missing. Bindings 500 Bindings 499 
Bindings 498 Bindings 497 Bindings 496 Bindings 495 Bindings 494 
Bindings 500 Bindings 499 Bindings 498 And if run with **1000** I get 
inconsistent count again, also unable to find certain vars around the 
500 mark Bindings 1000 Bindings 999 Missing var448 Bindings 1000 
Bindings 999 Missing var448 Bindings 998 Missing var448 Missing var449 
Bindings 997 Missing var448 Missing var449 Missing var450 Bindings 996 
Missing var448 Missing var449 Missing var450 Missing var451 Bindings 995 
Missing var448 Missing var449 Missing var450 Missing var451 Missing 
var452 Bindings 994 Missing var448 Missing var449 Missing var450 Missing 
var451 Missing var452 Missing var453 Bindings 993 Missing var448 Missing 
var449 Missing var450 Missing var451 Missing var452 Missing var453 
Missing var454 In all cases works okay the first time, but with the 500 
and 1000 calls thesubsequent iterations are incorrect. Seems like there 
is some other Nashorn process trimming the size of the bindings?|
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/nashorn-dev/attachments/20240926/bf9197ae/attachment.htm>


More information about the nashorn-dev mailing list