一、用jmap
命令输出
二、解析
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
: 类指针压缩空间大小, 默认为1GG1HeapRegionSize
: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、指针压缩1. 64位平台上默认打开
使用
-XX:+UseCompressedOops
压缩对象指针
"oops"
指的是普通对象指针("ordinary" object pointers
)。
Java
堆中对象指针会被压缩成32位。
使用堆基地址(如果堆在低26G内存中的话,基地址为0)使用
-XX:+UseCompressedClassPointers
选项来压缩类指针
对象中指向类元数据的指针会被压缩成32位
类指针压缩空间会有一个基地址
2、元空间和类指针压缩空间的区别
类指针压缩空间只包含类的元数据,比如
InstanceKlass, ArrayKlass
仅当打开了UseCompressedClassPointers
选项才生效
为了提高性能,Java
中的虚方法表也存放到这里
这里到底存放哪些元数据的类型,目前仍在减少元空间包含类的其它比较大的元数据,比如方法,字节码,常量池等。
三、用jstat
命令输出
四、解析
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
。