package org.glamey.training.jvm.oom;

import java.lang.reflect.Method;
import org.glamey.training.db.mybatis.domain.UserEntity;
import org.springframework.cglib.proxy.Enhancer;
import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

/**
 * 测试perm区溢出
 *
 * @author zhouyang.zhou. 2017.02.17.15.
 */
public class PermSizeOOMDemo {

  public static void main(String[] args) {
    while (true) {
      Enhancer enhancer = new Enhancer();
      enhancer.setSuperclass(UserEntity.class);
      enhancer.setUseCache(false);
      enhancer.setCallback(new MethodInterceptor() {
        @Override public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
          return methodProxy.invoke(o, objects);
        }
      });
      Object object = enhancer.create();
      System.out.println(object == null ? null : object.getClass());

      UserEntity userEntity = (UserEntity) object;
      String address = userEntity.getAddress();
      System.out.println(address);
      break;
    }
  }
}

@@ -301,16 +301,73 @@
 m%E5%8C%BA%E6%BA%A2%E5%87%BA%0A *%0A
+ * -Xms100m -Xmx200m -XX:NewSize=50m -XX:PermSize=50m%0A *%0A
  * @auth
@@ -474,24 +474,43 @@
 g%5B%5D args) %7B%0A
+    int count = 0;%0A
     while (t
@@ -955,18 +955,40 @@
 ut.print
-ln
+f(%22%25d--%3E%25s%5Cn%22, count++, 
 (object 
@@ -1026,156 +1026,9 @@
 s())
-;%0A%0A      UserEntity userEntity = (UserEntity) object;%0A      String address = userEntity.getAddress();%0A      System.out.println(address);%0A      break
+)
 ;%0A  

设置persize大小测试溢出情况。