最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

java - Troubleshooting Nashorn "Method code too large!" exception - Stack Overflow

programmeradmin0浏览0评论

Running jjs or ScriptEngine#eval on my JavaScript () crashes with this exception and no more details:

Exception in thread "main" java.lang.RuntimeException: Method code too large!
        at jdk.internal.objectweb.asm.MethodWriter.getSize(MethodWriter.java:2065)
        at jdk.internal.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.Compilerpile(Compiler.java:361)
        at jdk.nashorn.internal.runtime.Contextpile(Context.java:1071)
        at jdk.nashorn.internal.runtime.ContextpileScript(Context.java:1019)
        at jdk.nashorn.internal.runtime.ContextpileScript(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.

Running jjs or ScriptEngine#eval on my JavaScript (https://gist.github./also/005fd7c200b20f012e10) crashes with this exception and no more details:

Exception in thread "main" java.lang.RuntimeException: Method code too large!
        at jdk.internal.objectweb.asm.MethodWriter.getSize(MethodWriter.java:2065)
        at jdk.internal.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.pile(Compiler.java:361)
        at jdk.nashorn.internal.runtime.Context.pile(Context.java:1071)
        at jdk.nashorn.internal.runtime.Context.pileScript(Context.java:1019)
        at jdk.nashorn.internal.runtime.Context.pileScript(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.

Share Improve this question asked Oct 12, 2014 at 20:12 alsoalso 9747 silver badges22 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

Nashorn tries to split too large scripts/functions into smaller blocks to pile 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/download.html. You may want to try that as well.

The current JDK 8u40 is still throwing the bug. Ref the detailed note on:

http://skrishnamachari.wordpress./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.

发布评论

评论列表(0)

  1. 暂无评论