coolrainman 2014-10-08
java内存分为堆内存,永久存储区(方法区)内存,栈内存(虚拟机栈,程序计数器,本地方法栈)等。
堆内存分为新生代,老生代,新生代分为eden区,survivor0,survivor1区,堆内存由XX:Xmx,XX:Xms设置。新生代内存由XX:Xmn设置或者XX:NewSize;XX:MaxNewSize设置。
永久存储区用来存储class类,常量等信息,由XX:PermSize或者XX:MaxPermSize设置。
栈内存是每个线程都有一个栈,栈大小是有XX:Xss设置的,相等条件下xss越小,生成的线程数量就越多。
GC分为yonggc和fullgc,younggc是将对象在新生代内存移动并且移到老生代,fullgc将回收新生代和老生代的对象。
设置JVM参数如下:
<jvm-arg>-Xmx2048M</jvm-arg>
<jvm-arg>-Xms2048M</jvm-arg>
<jvm-arg>-XX:NewSize=800M</jvm-arg>
<jvm-arg>-XX:MaxNewSize=800M</jvm-arg>
<jvm-arg>-XX:+PrintGCDateStamps</jvm-arg>
<jvm-arg>-XX:+PrintHeapAtGC</jvm-arg>
<jvm-arg>-XX:+PrintGCDetails</jvm-arg>
<jvm-arg>-loggc:/home/work/gamesdk/gamesdk_log/online/gc.log</jvm-arg>
<jvm-arg>-Xss512k</jvm-arg>
<jvm-arg>-XX:+UseCMSInitiatingOccupancyOnly</jvm-arg>
<jvm-arg>-XX:CMSInitiatingOccupancyFraction=70</jvm-arg>
<jvm-arg>-XX:+UseConcMarkSweepGC</jvm-arg>
<jvm-arg>-XX:+UseCMSCompactAtFullCollection</jvm-arg>
<jvm-arg>-XX:+CMSParallelRemarkEnabled</jvm-arg>
<jvm-arg>-XX:+DisableExplicitGC</jvm-arg>
<jvm-arg>-Xnoclassgc</jvm-arg>
<jvm-arg>-Duser.dir=/home/work/gamesdk</jvm-arg>
GC日志会生成如下格式,含义如下:
[GC488.096(时间戳):[ParNew(新生代内存回收):672269K(新生代原内存)->16513K(回收后内存)(737280K(总内存大小,不包含suivivor2)),0.0350340(回收时间)secs]1370470K(堆区回收前内存)->714812K(堆区回收后内存)(2015232K(堆区总内存,不包含suvivor2区)),0.0365730(回收时间)secs][Times:user=0.10(younggc用户耗时)sys=0.01(younggc系统耗时),real=0.03secs(GC实际耗时)]
参考文章:
http://blog.csdn.net/huangzhaoyang2009/article/details/11860757
http://www.cnblogs.com/redcreen/archive/2011/05/04/2037057.html
http://www.ibm.com/developerworks/cn/java/j-lo-jvm-perf/