问题
Running jjs
or ScriptEngine#eval
on my JavaScript (https://gist.github.com/also/005fd7c200b20f012e10) crashes with this exception and no more details:
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 causing the method code to be too large? I've tried some log options to jjs
(--log=codegen:info
), but I haven't seen anything that points at a culprit.
I've tested with Java versions 1.9.0-ea-b34 and 1.8.0_20-b26.
回答1:
Nashorn tries to split too large scripts/functions into smaller blocks to compile to bytecode to workaround the per method bytecode size limit imposed by JVM. The Nashorn splitter has improved in jdk 1.8.0 update 40 (being developed, not yet released - but early access available from https://jdk8.java.net/download.html. You may want to try that as well.
回答2:
The current JDK 8u40 is still throwing the bug. Ref the detailed note on:
http://skrishnamachari.wordpress.com/2014/06/18/nashorn-bug/
Also is there a possibility to access the latest Nashorn source to be able to quickly debug through. Atleast find a hack/ validate and have it stick for our use till some final patch is provided.
来源:https://stackoverflow.com/questions/26329503/troubleshooting-nashorn-method-code-too-large-exception