2013-07-20 53 views
3

我正在使用Groovy ConfigSlurper從Groovy腳本加載大型groovy文件(741KB),並在嘗試執行編譯時始終收到RuntimeException。Groovy ConfigSlurper給出的Class文件太大RuntimeException

Groovy的2.1.1,Java 1.6的(蘋果/ MacOSX的)

我叫它像這樣:

conf = new ConfigSlurper().parse(new File('conf.groovy').toURL()) 

,一定可以得到下面的異常。 ConfigSlurper可以編譯的文件的大小有一個已知的限制嗎?

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 

回答

4

有一個已知的限制,但它可以說是不Groovy;它是ASM library並最終是Java。

由於Stuart Halloway已經在談判中提到過,所以知道發生在抽象層次下一層的事情往往很有見地。

例如,this link表明該代碼:

public byte[] toByteArray() { 
     if (index > Short.MAX_VALUE) { 
      throw new RuntimeException("Class file too large!"); 
     } 

......很可能這裏顯示的異常:

java.lang.RuntimeException: Class file too large! 
    at org.objectweb.asm.ClassWriter.toByteArray(Unknown Source) 

爲什麼ASM方法拋出此異常? This post狀態:

事實證明,一個神奇的數字爲「代碼過大」的錯誤是 65535字節(編譯後的字節代碼,而不是源代碼)。

該文件對於Groovy的內部實現來說可能太大,這會導致JVM的合成方法太大。