Rhino won't execute files with really long object literal declarations

502 views
Skip to first unread message

Jacob Beard

unread,
Feb 2, 2012, 9:20:27 PM2/2/12
to mozill...@googlegroups.com
Hi,

I've written a compiler for a domain-specific language which targets JavaScript, and it generates some really large data structures. I've found that Rhino fails to execute files with object literal declarations that are too long. In particular 
I've generated one very large data structure which is 414,769 characters long. javascript-core, v8, and spidermonkey all execute the file correctly, but Rhino fails to execute it at all. 

Trying to compile the script using jsc yields the following error:

jacob@jacob-VirtualBox:~/workspace/scion/build/tests/combined-script-and-annotated-scxml-json-test/big$ java -Xss10m -classpath /usr/share/java/js.jar:/usr/share/java/jline.jar org.mozilla.javascript.tools.jsc.Main assign1000.js 
Exception in thread "main" org.mozilla.javascript.EvaluatorException: Encountered code generation error while compiling script: generated bytecode for method exceeds 64K limit. (assign1000.js#1)
at org.mozilla.javascript.Context.reportRuntimeError(Context.java:949)
at org.mozilla.javascript.optimizer.Codegen.reportClassFileFormatException(Codegen.java:210)
at org.mozilla.javascript.optimizer.Codegen.generateCode(Codegen.java:343)
at org.mozilla.javascript.optimizer.Codegen.compileToClassFile(Codegen.java:196)
at org.mozilla.javascript.optimizer.ClassCompiler.compileToClassFiles(ClassCompiler.java:187)
at org.mozilla.javascript.tools.jsc.Main.processSource(Main.java:276)
at org.mozilla.javascript.tools.jsc.Main.main(Main.java:73)

Is there a way to work around this?

Please let me know. Thanks,

Jake

Jacob Beard

unread,
Feb 2, 2012, 9:28:07 PM2/2/12
to mozill...@googlegroups.com
Hi,

It looks like running rhino with -opt -1 solves this issue.

Jake

Hannes Wallnöfer

unread,
Feb 3, 2012, 1:53:24 AM2/3/12
to mozill...@googlegroups.com
Yes, running with -opt -1 is one way to solve the problem.

Another solution that should work is to use the "rhino_1_8" git branch
(without -opt -1).

https://github.com/mozilla/rhino/tree/rhino_1_8

That branch is able to split up very long object literals into
multiple java methods to circumvent the 64k java method size limit.
I've implemented this for coffeescript which had same problem and now
works in compiled mode on rhino_1_8.

Of course it might still fail for you if you really have one huge
object literal (versus one that is composed of multiple nested
object/array literals). If you try please let me know if it works!

Hannes

2012/2/3 Jacob Beard <jbe...@cs.mcgill.ca>:

Jacob Beard

unread,
Feb 3, 2012, 11:25:23 AM2/3/12
to mozill...@googlegroups.com
Cool, I'll give it a try.

Thanks,

Jake

2012/2/3 Hannes Wallnöfer <han...@gmail.com>:

Jacob Beard

unread,
Feb 5, 2012, 8:02:31 PM2/5/12
to mozill...@googlegroups.com
Works great!

Thanks again,

Jake

Hannes Wallnöfer

unread,
Feb 6, 2012, 8:30:59 AM2/6/12
to mozill...@googlegroups.com
Good to hear, and thanks for the feedback!

Hannes

2012/2/6 Jacob Beard <jbe...@cs.mcgill.ca>:

Reply all
Reply to author
Forward
0 new messages