Running precompiled JS bytecode

A. Sundararajan sundararajan.athijegannathan at oracle.com
Sun Jul 28 23:39:21 PDT 2013


Hi Jordan Fix,

Nashorn generated code is not usable by re-loading from a .class file. A 
static field by the name "constants" is set after generating, loading 
bytecode generated for a script. The "constants" array contains both 
serializable and non-serializable items (such as PropertyMap). Code 
generator generates bytecode and associated constants array together - 
installs code with CodeInstaller object (passed from Context) and sets 
the "constants" array.

Unless you figure out a way to serialize constants array (say you may 
skip PropertyMaps - but put enough information to reconstruct those and 
so on) and deserialize to set constants field after loading bits from a 
.class file/byte array, "precompiled" scheme won't work.

-Sundar


On Monday 29 July 2013 09:31 AM, Jordan Fix wrote:
> Hello,
>
> I've been attempting to modify the nashorn shell so that you can specify a byte code file to load in and execute instead of having to do the compilation prior to execution every time. This allows hand modification of byte code for example. I've hit an issue which I don't know how to get past, hoping someone can give me a tip.
>
> To get started I've passed the compile only and dump flags to the shell to get the byte code for a simple hello world JS file, and have been hackily trying to get this to work with a new "precompiled" flag. I load in the byte code file, and tried to follow a similar flow to when it is compiled at runtime without going through the compilation phases -- I just add the byte code to the compiler and then call install on it with the byte code and file name.
>
> I am currently getting the following exception:
>
> Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
>                  at jdk.nashorn.internal.scripts.Script$test.$getMap(test.js)
>                  at jdk.nashorn.internal.scripts.Script$test.runScript(test.js)
>                  at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:520)
>                  at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:203)
>                  at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:366)
>                  at jdk.nashorn.tools.Shell.apply(Shell.java:619)
>                  at jdk.nashorn.tools.Shell.runScripts(Shell.java:529)
>                  at jdk.nashorn.tools.Shell.run(Shell.java:296)
>                  at jdk.nashorn.tools.Shell.main(Shell.java:154)
>                  at jdk.nashorn.tools.Shell.main(Shell.java:133)
>
> I'm guessing this has something to do with the execution environment not being set up correctly, as there is an empty array being loaded from.
>
> Thanks for any assistance you can give me.
> Jordan Fix
>
>



More information about the nashorn-dev mailing list