getting around the 64k method bytecode limit

1,907 views
Skip to first unread message

Domas Lapinskas

unread,
Jun 6, 2011, 5:32:45 PM6/6/11
to RingoJS
Hello,

I'm putting together a multiplayer game with server-side hosting using
RingoJs. In this game levels are stored as commonJS modules. I've run
into a bit of a snag: upon trying to require() a level, I get an
error:

Encountered code generation error while compiling script: generated
bytecode for method exceeds 64K limit.

Is there a way increase, remove or otherwise get around this limit?
My googling has yielded one other year old thread with this problem,
but no acceptable resolution.
A level js file for my game looks like this:

exports.data={ ...stuff ...};

where stuff is a huge object literal containing other object literals,
arrays of integers and such.

An example of a level file that causes this error:
http://www63.zippyshare.com/v/42377273/file.html
I'm using RingoJS 0.8

Thanks!

gabriel munteanu

unread,
Jun 7, 2011, 3:05:53 AM6/7/11
to rin...@googlegroups.com
it is a java problem, not related to js per se.
an easy workaround is to remove the optimization, and not compile the
js code at all, but run it in interpreted mode.

put this into web.xml:
-----------------------
<init-param>
<param-name>optlevel</param-name>
<param-value>-1</param-value>
</init-param>
---------------------

cheers, jgabios
http://bash.editia.info

> --
> You received this message because you are subscribed to the Google Groups "RingoJS" group.
> To post to this group, send email to rin...@googlegroups.com.
> To unsubscribe from this group, send email to ringojs+u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/ringojs?hl=en.
>
>

McKinley

unread,
Jun 7, 2011, 2:59:35 AM6/7/11
to rin...@googlegroups.com
Every tool that generates Java code runs into this limitation. It will not be fixed in our lifetime if history is any judge: http://bugs.sun.com/view_bug.do?bug_id=4262078

You will have to work around it. Based on your example it seems like you must know many things about the size of you game data and you can create a way to divide your game data among many files. You should be able to join that data in one wrapper file that you can include in place of your original. Example:

/*** example of level1.js ***/

var tiles1 = require("./level1-part1");
var tiles2 = require("./level1-part2");
var tiles3 = require("./level1-part3");
exports.tiles = tiles1.concat(tiles2, tiles3);

/*** end example ***/

If you want to avoid the expense of an array copy in the above example you can change your game data handler to accept a multidimensional array:

exports.tiles = [tiles1, tiles2, tiles3];

If my examples do not work around the the 64K method size limit let me know and I'll take a closer look.

Cheers,

McKinley

McKinley

unread,
Jun 7, 2011, 3:18:16 AM6/7/11
to rin...@googlegroups.com
If you need absolute performance, however, don't put your data in code but rather a binary format and read it with http://ringojs.org/api/v0.8/binary/.

Kind regards,

McKinley

Domas Lapinskas

unread,
Jun 7, 2011, 5:55:19 PM6/7/11
to rin...@googlegroups.com
Hey,

Thanks for the replies!

Setting optimization to -1 did work, but CPU usage was pretty high.

Level files need to also be usable client-side, in a browser. For this
and other reasons binary isn't very convenient, but it did give me an
idea: I ended up parsing the level file as JSON data rather than
javascript code.

--
Domas

Reply all
Reply to author
Forward
0 new messages