-
-
Save yv84/e0e9c0f4296b5e6f75bab9cfc19fb63f to your computer and use it in GitHub Desktop.
GcPermgenTest
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 characters
package ru.serce.gctest; | |
import java.lang.reflect.Method; | |
import javassist.ClassPool; | |
import javassist.CtClass; | |
import javassist.CtMethod; | |
public class GcPermgenTest { | |
static { | |
new OutOfMemoryError().printStackTrace(); | |
} | |
public static void main(String[] args) throws InterruptedException { | |
for(long i = 0;; i++) { | |
genClass(i); | |
} | |
} | |
private static Object genClass(long i) { | |
try { | |
ClassLoader loader = new ClassLoader() { | |
}; | |
ClassPool pool = new ClassPool(null); | |
pool.appendSystemPath(); | |
CtClass cc = pool.makeClass("Main" + i); | |
CtMethod method = CtMethod.make( | |
"public static long doSome() {" + | |
"return " + i + "L;" + | |
"}", cc); | |
cc.addMethod(method); | |
Class<?> clazz = cc.toClass(loader); | |
Method m = clazz.getMethod("doSome"); | |
return m.invoke(null, null); | |
} catch (Throwable e) { | |
e.printStackTrace(); | |
throw new RuntimeException(e); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment