【问题标题】:Troubleshooting Nashorn "Method code too large!" exceptionNashorn 故障排除“方法代码太大!”例外
【发布时间】:2014-12-07 09:34:33
【问题描述】:

在我的 JavaScript (https://gist.github.com/also/005fd7c200b20f012e10) 上运行 jjsScriptEngine#eval 会崩溃并出现此异常并且没有更多详细信息:

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) 的一些日志选项,但我没有看到任何指向罪魁祸首的东西。

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

【问题讨论】:

    标签: java javascript java-8 nashorn java-9


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      当前的 JDK 8u40 仍然在抛出这个 bug。参考详细说明:

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

      还有可能访问最新的 Nashorn 源代码以便能够快速调试。至少找到一个 hack/validate 并让它一直供我们使用,直到提供最终补丁。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-12-07
        • 1970-01-01
        • 1970-01-01
        • 2021-11-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多