The java documentation about the JavaScript ScriptEngine implementation says, that it is possible to set the system property "rhino.opt.level" if there is no security manager active. ("When security manager is not used, System property "rhino.opt.level" can be defined in the range [-1, 9]. By default, the value is set to -1 which means optimizer is disabled.", see http://docs.oracle.com/javase/7/docs/technotes/guides/scripting/programmer_guide/#jsengine)
My question now is, how this can be done. I tried setting it as an environment variable and in the code using
System.setProperty("rhino.opt.level", "9");
but it had no effect on the compiled scripts whatsoever. Is there a command line argument that needs to be passed to the jvm or something similar?
Edit: My test code:
String script = IOUtil.readTextFile("test.js", "UTF-8"); // reads the file's content
System.setProperty("rhino.opt.level", "9");
final ScriptEngine scriptEngine = new ScriptEngineManager().getEngineByName("JavaScript");
Compilable compiler = (Compilable) scriptEngine;
CompiledScript cs = compiler.compile(script);
cs.eval();