java.lang.OutOfMemoryError : Metaspace at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:763) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) at groovy.lang.GroovyClassLoader.access$400(GroovyClassLoader.java:62) at groovy.lang.GroovyClassLoader$ClassCollector.createClass(GroovyClassLoader.java:500) at groovy.lang.GroovyClassLoader$ClassCollector.onClassNode(GroovyClassLoader.java:517) at groovy.lang.GroovyClassLoader$ClassCollector.call(GroovyClassLoader.java:521) at org.codehaus.groovy.control.CompilationUnit$16.call(CompilationUnit.java:822) at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1053) at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:591) at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:569) at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:546) at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298) at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268) at groovy.lang.GroovyShell.parseClass(GroovyShell.java:688) at groovy.lang.GroovyShell.parse(GroovyShell.java:700) at groovy.lang.GroovyShell.evaluate(GroovyShell.java:584) at groovy.lang.GroovyShell.evaluate(GroovyShell.java:623) at groovy.lang.GroovyShell.evaluate(GroovyShell.java:594) at org.springframework.scripting.groovy.GroovyScriptEvaluator.evaluate(GroovyScriptEvaluator.java:118)
…… [Loaded Script1 from file:/groovy/shell] a = 1, result is false [Loaded Script1 from file:/groovy/shell] a = 2, result is false [Loaded Script1 from file:/groovy/shell] a = 0, result is false [Loaded Script1 from file:/groovy/shell] a = 8, result is false [GC (Metadata GC Threshold) 838057K->253201K(1080832K), 0.1350074 secs] [Full GC (Metadata GC Threshold) 253201K->244956K(1232896K), 0.4860932 secs] [GC (Last ditch collection) 244956K->245557K(1421824K), 0.0403506 secs] …… Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "main" ……
…… [Loaded Script1 from file:/groovy/shell] a = 9, result is false [Loaded Script1 from file:/groovy/shell] a = 3, result is true [Loaded Script1 from file:/groovy/shell] a = 7, result is false [Loaded Script1 from file:/groovy/shell] a = 7, result is false [GC (Metadata GC Threshold) 722452K->251702K(1090560K), 0.0483118 secs] [Full GC (Metadata GC Threshold) 251702K->240778K(1254912K), 0.4303570 secs] [GC (Last ditch collection) 240778K->241270K(1373696K), 0.0274501 secs] [Full GC (Last ditch collection) [Unloading class Script1 0x00000007c103c428] [Unloading class Script1 0x00000007c103bc28] [Unloading class Script1 0x00000007c103b428] [Unloading class Script1 0x00000007c103ac28] [Unloading class Script1 0x00000007c103a428] ……
Profiler:
同上面一样,程序开始也是打印了很多 [Loaded Script1 from file:/groovy/shell],但不同的是达到 Metadata GC Threshold 进行 GC 之后,可以将 Non-Heap Memory 占用降下来,并且从控制台可以看到在 GC 时打印了很多 [Unloading class Script1 xxx],程序持续运行很长时间也没问题。