在我的JavaScript (https://gist.github.com/also/005fd7c200b20f012e10)上运行jjs或ScriptEngine#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进行了测试。
发布于 2014-10-21 11:54:12
Nashorn尝试将过大的脚本/函数拆分成较小的块,以便编译为字节码,以解决JVM施加的每个方法字节码大小的限制。Nashorn拆分器在jdk 1.8.0更新40中得到了改进(正在开发中,尚未发布-但可从https://jdk8.java.net/download.html获得早期访问)。你可能也想试一试。
发布于 2014-12-18 17:00:51
当前的JDK 8u40仍在抛出这个错误。请参阅以下详细说明:
http://skrishnamachari.wordpress.com/2014/06/18/nashorn-bug/
也有可能访问最新的Nashorn源代码,以便能够快速调试通过。至少找到一个hack/ validate,让它坚持供我们使用,直到提供一些最终的补丁。
https://stackoverflow.com/questions/26329503
复制相似问题