jmap输出
[tomcat@n01 ~]$ /opt/java/jdk1.8.0_101/bin/jmap -heap 11368Attaching to process ID11368, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is25.101-b13
using thread-local objectallocation.
Parallel GC with2thread(s)
Heap Configuration:
MinHeapFreeRatio= 0MaxHeapFreeRatio= 100MaxHeapSize= 2684354560 (2560.0MB)
NewSize= 1073741824 (1024.0MB)
MaxNewSize= 1073741824 (1024.0MB)
OldSize= 1610612736 (1536.0MB)
NewRatio= 2SurvivorRatio= 8MetaspaceSize= 21807104 (20.796875MB)
CompressedClassSpaceSize= 1073741824 (1024.0MB)
MaxMetaspaceSize= 17592186044415MB
G1HeapRegionSize= 0 (0.0MB)
Heap Usage:
PS Young Generation
Eden Space:
capacity= 852492288 (813.0MB)
used= 420427144 (400.95056915283203MB)free = 432065144 (412.04943084716797MB)49.31741317993014%used
From Space:
capacity= 113770496 (108.5MB)
used= 2299712 (2.19317626953125MB)free = 111470784 (106.30682373046875MB)2.021360617079493%used
To Space:
capacity= 107479040 (102.5MB)
used= 0 (0.0MB)free = 107479040 (102.5MB)0.0%used
PS Old Generation
capacity= 1610612736 (1536.0MB)
used= 50883368 (48.526161193847656MB)free = 1559729368 (1487.4738388061523MB)3.1592552860577903%used27595 interned Strings occupying 3138384 bytes.
MaxHeapFreeRatio: GC后如果发现空闲堆内存占到整个预估堆内存的N%(百分比),则收缩堆内存的预估最大值, 预估堆内存是堆大小动态调控的重要选项之一. 堆内存预估最大值一定小于或等于固定最大值(-Xmx指定的数值). 前者会根据使用情况动态调大或缩小, 以提高GC回收的效率
MinHeapFreeRatio: GC后如果发现空闲堆内存占到整个预估堆内存的N%(百分比), 则放大堆内存的预估最大值
MaxHeapSize: 即-Xmx, 堆内存大小的上限
InitialHeapSize: 即-Xms, 堆内存大小的初始值
NewSize: 新生代预估堆内存占用的默认值
MaxNewSize: 新生代占整个堆内存的最大值
OldSize: 老年代的默认大小, default size of the tenured generation
NewRatio: 老年代对比新生代的空间大小, 比如2代表老年代空间是新生代的两倍大小. The ratio of old generation to young generation.
SurvivorRatio: Eden/Survivor的值. 这个值的说明, 很多网上转载的都是错的. 8表示Survivor:Eden=1:8, 因为survivor区有2个, 所以Eden的占比为8/10. Ratio of eden/survivor space size. -XX:SurvivorRatio=6 sets the ratio between each survivor space and eden to be 1:6, each survivor space will be one eighth of the young generation.
MetaspaceSize: 分配给类元数据空间的初始大小(Oracle逻辑存储上的初始高水位,the initial high-water-mark ). 此值为估计值. MetaspaceSize设置得过大会延长垃圾回收时间. 垃圾回收过后, 引起下一次垃圾回收的类元数据空间的大小可能会变大
MaxMetaspaceSize: 是分配给类元数据空间的最大值, 超过此值就会触发Full GC. 此值仅受限于系统内存的大小, JVM会动态地改变此值
CompressedClassSpaceSize: 类指针压缩空间大小, 默认为1G
G1HeapRegionSize: G1区块的大小, 取值为1M至32M. 其取值是要根据最小Heap大小划分出2048个区块. With G1 the Java heap is subdivided into uniformly sized regions. This sets the size of the individual sub-divisions. The default value of this parameter is determined ergonomically based upon heap size. The minimum value is 1Mb and the maximum value is 32Mb. Sets the size of a G1 region. The value will be a power of two and can range from 1MB to 32MB. The goal is to have around 2048 regions based on the minimum Java heap size.
指针压缩1. 64位平台上默认打开
1)使用-XX:+UseCompressedOops压缩对象指针
"oops"指的是普通对象指针("ordinary" object pointers)。
Java堆中对象指针会被压缩成32位。
使用堆基地址(如果堆在低26G内存中的话,基地址为0)
2)使用-XX:+UseCompressedClassPointers选项来压缩类指针
对象中指向类元数据的指针会被压缩成32位
类指针压缩空间会有一个基地址
2. 元空间和类指针压缩空间的区别
1)类指针压缩空间只包含类的元数据,比如InstanceKlass, ArrayKlass
仅当打开了UseCompressedClassPointers选项才生效
为了提高性能,Java中的虚方法表也存放到这里
这里到底存放哪些元数据的类型,目前仍在减少
2)元空间包含类的其它比较大的元数据,比如方法,字节码,常量池等。
[tomcat@n01 ~]$ /opt/java/jdk1.8.0_101/bin/jstat -gcutil 11368S0 S1 E O M CCS YGC YGCT FGC FGCT GCT2.02 0.00 49.32 3.16 92.13 88.17 24 1.220 3 0.637 1.857
S0: Survivor 0区的空间使用率 Survivor space 0 utilization as a percentage of the space's current capacity.
S1: Survivor 1区的空间使用率 Survivor space 1 utilization as a percentage of the space's current capacity.
E: Eden区的空间使用率 Eden space utilization as a percentage of the space's current capacity.
O: 老年代的空间使用率 Old space utilization as a percentage of the space's current capacity.
M: 元数据的空间使用率 Metaspace utilization as a percentage of the space's current capacity.
CCS: 类指针压缩空间使用率 Compressed class space utilization as a percentage.
YGC: 新生代GC次数 Number of young generation GC events.
YGCT: 新生代GC总时长 Young generation garbage collection time.
FGC: Full GC次数 Number of full GC events.
FGCT: Full GC总时长 Full garbage collection time.
GCT: 总共的GC时长 Total garbage collection time.
记录GC日志
加入参数
-verbose:gc -Xloggc:$CATALINA_BASE/logs/gc.log XX:+PrintGCTimeStamps-XX:+PrintGCDetails
例如
export JAVA_HOME=/opt/java/jdk1.8.0_101
export CATALINA_HOME=/opt/tomcat/apache-tomcat-8.0.36-redis
export CATALINA_BASE=/home/tomcat/tomcat8_jdk8
export JAVA_OPTS="-server -Xms1280m -Xmx1280m -XX:MaxNewSize=896m -Djava.awt.hea
dless=true -verbose:gc -Xloggc:$CATALINA_BASE/logs/gc.log -XX:+PrintGCTimeStamps-XX:+PrintGCDetails"cd $CATALINA_HOME/bin
./catalina.sh start
如果jvm进程不明原因退出, 可以查看syslog, 位置是 /var/log/messages
-XX:MaxTenuringThreshold 垃圾最大年龄, 如果设置为0的话,则年轻代对象不经过Survivor区,直接进入年老代. 对于年老代比较多的应用,可以提高效率.如果将此值设置为一个较大值,则年轻代对象会在Survivor区进行多次复制,这样可以增加对象再年轻代的存活 时间,增加在年轻代即被回收的概率. 该参数只有在串行GC时才有效.