Skip to content

Instantly share code, notes, and snippets.

@SerCeMan
Last active September 27, 2017 04:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save SerCeMan/876fcdfaca602af2df8d to your computer and use it in GitHub Desktop.
Save SerCeMan/876fcdfaca602af2df8d to your computer and use it in GitHub Desktop.
GcPermgenTest
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