Nashorn疑难解答“方法代码太大了!”例外 [英] Troubleshooting Nashorn "Method code too large!" exception

查看:804
本文介绍了Nashorn疑难解答“方法代码太大了!”例外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的JavaScript上运行 jjs ScriptEngine#eval https://gist.github.com/also/005fd7c200b20f012e10 )因此异常而崩溃,没有更多细节:

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)

我怎么能算是什么导致方法代码太大?我已经尝试了一些日志选项 jjs - log = codegen:info ),但我还没有看到任何指向罪魁祸首的事情。

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.

我已经使用Java版本1.9.0-ea-b34和1.8.0_20-b26进行了测试。

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

推荐答案

Nashorn尝试将过大的脚本/函数拆分为较小的块以编译为字节码,以解决JVM强加的每个方法字节码大小限制。 Nashorn分离器在jdk 1.8.0更新40中得到了改进(正在开发,尚未发布 - 但可以从获得早期访问) https://jdk8.java.net/download.html 。您可能也想尝试一下。

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.

这篇关于Nashorn疑难解答“方法代码太大了!”例外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆