Groovy ConfigSlurper给Class文件带来了太大的RuntimeException [英] Groovy ConfigSlurper gives Class file too large RuntimeException
问题描述
我使用Groovy ConfigSlurper从Groovy脚本中加载一个大的Groovy文件(741KB),并在它尝试编译时始终收到一个RuntimeException。
I am using the Groovy ConfigSlurper to load a large groovy file (741KB) from a Groovy script and consistently receive a RuntimeException when it tries to do the compilation.
Groovy 2.1.1,Java 1.6(Apple / MacOSX)
Groovy 2.1.1, Java 1.6 (Apple/MacOSX)
我称之为:
I call it like so:
conf = new ConfigSlurper().parse(new File('conf.groovy').toURL())
总是会在下面得到例外。 ConfigSlurper可以编译的文件大小是否已知?
And always get the exception below. Is there a known limitation to the size of a file ConfigSlurper can compile?
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
General error during class generation: Class file too large!
java.lang.RuntimeException: Class file too large!
at org.objectweb.asm.ClassWriter.toByteArray(Unknown Source)
at org.codehaus.groovy.control.CompilationUnit$15.call(CompilationUnit.java:797)
at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1036)
at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:573)
at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:551)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:528)
at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:279)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:258)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:244)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:202)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:212)
at groovy.lang.GroovyClassLoader$parseClass.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at groovy.util.ConfigSlurper.parse(ConfigSlurper.groovy:146)
at groovy.util.ConfigSlurper$parse.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at write_users.run(write_users.groovy:19)
at groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:257)
at groovy.lang.GroovyShell.run(GroovyShell.java:220)
at groovy.lang.GroovyShell.run(GroovyShell.java:150)
at groovy.ui.GroovyMain.processOnce(GroovyMain.java:588)
at groovy.ui.GroovyMain.run(GroovyMain.java:375)
at groovy.ui.GroovyMain.process(GroovyMain.java:361)
at groovy.ui.GroovyMain.processArgs(GroovyMain.java:120)
at groovy.ui.GroovyMain.main(GroovyMain.java:100)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:106)
at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:128)
1 error
推荐答案
有一个已知的限制,但它可以说不是Groovy;它是 ASM库,最终是Java。
There is a known limitation but it is arguably not Groovy; it is the ASM library and ultimately Java.
由于斯图尔特万花筒有在谈话中提到,通常很有必要知道在抽象层次之下发生了什么。
As Stuart Halloway has mentioned in talks, it is often insightful to know what is happening one layer below your level of abstraction.
例如,此链接显示此代码:
For example, this link shows that this code:
public byte[] toByteArray() {
if (index > Short.MAX_VALUE) {
throw new RuntimeException("Class file too large!");
}
...可能是此处显示的异常:
... is likely the exception shown here:
java.lang.RuntimeException: Class file too large!
at org.objectweb.asm.ClassWriter.toByteArray(Unknown Source)
为什么ASM方法抛出这个异常? 这篇文章指出:
Why does the ASM method throw this exception? This post states:
事实证明,代码太大错误的幻数是
65535字节(编译字节码,而不是源代码) 。
It turns out that the magic number for the "code too large" error is 65535 bytes (compiled byte code, not source code).
Groovy的内部实现可能太大,这会导致合成方法过大JVM。
It is probable that the file is too large for Groovy's internal implementation, which would result in a synthetic method that is too large for the JVM.
这篇关于Groovy ConfigSlurper给Class文件带来了太大的RuntimeException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!