1

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();
Kazuo
  • 387
  • 5
  • 12
  • It seems to work with -Drhino.opt.level=9 (or any other value) as described in the answer here: http://stackoverflow.com/questions/14538541/performance-of-the-compiled-vs-interpreted-javascript-in-java7-rhino Would be nice to have a way to do it during runtime, so I am going to wait for an answer or comment regarding that. – Kazuo Feb 07 '14 at 01:27

0 Answers0