Created
June 29, 2022 05:42
-
-
Save jsmucr/e3c36fd3393fc1345ad3dfa711b46960 to your computer and use it in GitHub Desktop.
Revisions
-
jsmucr created this gist
Jun 29, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ import groovy.lang.GroovyClassLoader; class LeakDynamic { public static interface TestClass { String getThingy(); } static String getTheThingy() { return "the thingy"; } @SuppressWarnings("unchecked") public static void main(String[] args) throws Exception { for (int i = 0; i < 1000; i++) { var cl = new GroovyClassLoader(); var c = cl.parseClass("class TestClass" + i + " implements LeakDynamic.TestClass { public String getThingy() { return LeakDynamic.getTheThingy(); } }"); var t = (TestClass) c.getConstructor().newInstance(); assert t.getThingy() == getTheThingy(); } } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ import groovy.lang.GroovyClassLoader; class LeakStatic { public static interface TestClass { String getThingy(); } static String getTheThingy() { return "the thingy"; } @SuppressWarnings("unchecked") public static void main(String[] args) throws Exception { for (int i = 0; i < 1000; i++) { var cl = new GroovyClassLoader(); var c = cl.parseClass("class TestClass" + i + " implements LeakStatic.TestClass { @groovy.transform.CompileStatic public String getThingy() { return LeakStatic.getTheThingy(); } }"); var t = (TestClass) c.getConstructor().newInstance(); assert t.getThingy() == getTheThingy(); } } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ #!/bin/sh sdk install groovy 3.0.11 javac -cp ~/.sdkman/candidates/groovy/3.0.11/lib/groovy-3.0.11.jar LeakDynamic.java # Lowering the heap to 16 MiB is still OK. export JAVA_OPTS="-Xmx32M -XX:+HeapDumpOnOutOfMemoryError -Xlog:class+unload=info" # Way faster than with CompileStatic. time java $JAVA_OPTS -cp ~/.sdkman/candidates/groovy/3.0.11/lib/groovy-3.0.11.jar:. LeakDynamic This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ #!/bin/sh sdk install groovy 3.0.11 javac -cp ~/.sdkman/candidates/groovy/3.0.11/lib/groovy-3.0.11.jar LeakStatic.java # Lowering the heap to 16 MiB leads to OOM. export JAVA_OPTS="-Xmx32M -XX:+HeapDumpOnOutOfMemoryError -Xlog:class+unload=info" # Way faster than without CompileStatic. time java $JAVA_OPTS -cp ~/.sdkman/candidates/groovy/3.0.11/lib/groovy-3.0.11.jar:. LeakStatic