Troubleshooting Nashorn "Method code too big!" an exception

Executing jjs

or ScriptEngine#eval

on my JavaScript ( https://gist.github.com/also/005fd7c200b20f012e10 ) crashes with this exception and no more detail:

Exception in thread "main" java.lang.RuntimeException: Method code too large!
        at jdk.internal.org.objectweb.asm.MethodWriter.getSize(MethodWriter.java:2065)
        at jdk.internal.org.objectweb.asm.ClassWriter.toByteArray(ClassWriter.java:856)
        at jdk.nashorn.internal.codegen.ClassEmitter.toByteArray(ClassEmitter.java:577)
        at jdk.nashorn.internal.codegen.CompilationPhase$8.transform(CompilationPhase.java:396)
        at jdk.nashorn.internal.codegen.CompilationPhase.apply(CompilationPhase.java:513)
        at jdk.nashorn.internal.codegen.Compiler.compile(Compiler.java:361)
        at jdk.nashorn.internal.runtime.Context.compile(Context.java:1071)
        at jdk.nashorn.internal.runtime.Context.compileScript(Context.java:1019)
        at jdk.nashorn.internal.runtime.Context.compileScript(Context.java:490)
        at jdk.nashorn.tools.Shell.runScripts(Shell.java:306)
        at jdk.nashorn.tools.Shell.run(Shell.java:168)
        at jdk.nashorn.tools.Shell.main(Shell.java:132)
        at jdk.nashorn.tools.Shell.main(Shell.java:111)

      

How can I figure out what is calling the method code too large? I've tried some log options for jjs

( --log=codegen:info

), but I haven't seen anything that points to the culprit.

I tested with Java versions 1.9.0-ea-b34 and 1.8.0_20-b26.

+3


source to share


2 answers


Nashorn tries to break overly large scripts / functions into smaller chunks for compilation to bytecode to get around the byte size limit for each method imposed by the JVM. Nashorn splitter improved in jdk 1.8.0 update 40 (under development, not released yet - but early access is available from https://jdk8.java.net/download.html . Want to try this.



+5


source


The current JDK 8u40 is still throwing an error. Detailed note:

http://skrishnamachari.wordpress.com/2014/06/18/nashorn-bug/



It's also possible to access the latest Nashorn source to be able to debug quickly. At the very least, find a hack / confirm and pin it for our use until some latest patch is provided.

+3


source







All Articles