0. 前言
jstat(JVMStatisticsMonitoringTool): 虚拟机统计信息监视工具。
所有命令都可以先 -help一下,-help 是软件的通用命令,可以看一下有什么参数
jstat -help
jstat -help
Usage: jstat -help|-options
jstat -<option> [-t] [-h<lines>] <vmid> [<interval> [<count>]]
Definitions:
<option> An option reported by the -options option
<vmid> Virtual Machine Identifier. A vmid takes the following form:
<lvmid>[@<hostname>[:<port>]]
Where <lvmid> is the local vm identifier for the target
Java virtual machine, typically a process id; <hostname> is
the name of the host running the target Java virtual machine;
and <port> is the port number for the rmiregistry on the
target host. See the jvmstat documentation for a more complete
description of the Virtual Machine Identifier.
<lines> Number of samples between header lines.
<interval> Sampling interval. The following forms are allowed:
<n>["ms"|"s"]
Where <n> is an integer and the suffix specifies the units as
milliseconds("ms") or seconds("s"). The default units are "ms".
<count> Number of samples to take before terminating.
-J<flag> Pass <flag> directly to the runtime system.
1. jstat 命令
由图可知除去-help(帮助命令),通用命令为
jstat -<option> [-t] [-h<lines>] <vmid> [<interval> [<count>]]
参数 时间 每隔多少行 进程号 时间间隔 打印次数
命令官方解释: https://docs.oracle.com/javase/8/docs/technotes/tools/unix/jstat.html
1.1. jstat -options
具体的参数命令可以通过jstat -options查看 如下
jstat -options
-class 类加载统计
-compiler 编译统计
-gc 垃圾回收统计
-gccapacity 堆内存统计
-gccause 近一次GC统计和原因
-gcmetacapacity 元数据空间统计
-gcnew 新生代垃圾回收统计
-gcnewcapacity 新生代内存统计
-gcold 老年代垃圾回收统计
-gcoldcapacity 老年代内存统计
-gcutil 垃圾回收统计(百分比)
-printcompilation JVM编译方法统计
项option代表用户希望查询的虚拟机信息,主要分为三类:类加载、垃圾收集、运行期编译状况
- 垃圾收集
- 运行期编译状况
- 类加载
2. 垃圾回收统计的各列含义
2.1. 垃圾收集
-gc 垃圾回收统计
-gcnew 新生代垃圾回收统计
-gcold 老年代垃圾回收统计
-gcutil 垃圾回收统计(百分比)
S0C:第一个幸存区的大小
S1C:第二个幸存区的大小
S0U:第一个幸存区的使用大小
S1U:第二个幸存区的使用大小
EC:伊甸园区的大小
EU:伊甸园区的使用大小
OC:老年代大小
OU:老年代使用大小
MC:方法区大小
MU:方法区使用大小
CCSC:压缩类空间大小
CCSU:压缩类空间使用大小
GCT:垃圾回收消耗总时间
YGC: Young GC 代表Minor GC次数;
YGCT: Young GC Time 代表Minor GC耗时;
FGC: Full GC 代表Full GC次数;
FGCT:老年代垃圾回收消耗时间;
GCT: GC Time 代表Minor & Full GC共计耗时;
TT:对象在新生代存活的次数
MTT:对象在新生代存活的最大次数
DSS: Desired survivor size,期望幸存者大小
S0:第一个幸存区百分比
S1:第二个幸存区百分比
E: Eden 代表伊甸区使用百分比;
O: Old 代表老年代使用百分比;
M: Metaspace 元空间
CCS:压缩类空间利用率为百分比
2.2. 运行期编译状况
-gccapacity 堆内存统计
-gcmetacapacity 元数据空间统计
-gcnewcapacity 新生代内存统计
-gcoldcapacity 老年代内存统计
-compiler 编译统计
-printcompilation JVM编译方法统计
NGCMN:新生代最小容量
NGCMX:新生代最大容量
NGC:当前新生代容量
S0C:第一个幸存区大小
S1C:第二个幸存区的大小
EC:伊甸园区的大小
OGCMN:老年代最小容量
OGCMX:老年代最大容量
OGC:当前老年代大小
OC:当前老年代大小
MCMN:最小元数据容量
MCMX:最大元数据容量
MC:当前元数据空间大小
CCSMN:最小压缩类空间大小
CCSMX:最大压缩类空间大小
CCSC:当前压缩类空间大小
YGC:年轻代gc次数
FGC:老年代GC次数
S0CMX:最大幸存1区大小
S1CMX:最大幸存2区大小
ECMX:最大伊甸园区大小
2.3. 类加载
-class 类加载统计
Loaded:加载class的数量
Bytes:所占用空间大小
Unloaded:未加载数量
Bytes:未加载占用空间
Time:时间
Compiled:编译任务的数目
Failed:失败数量
Invalid:不可用数量
Time:时间
FailedType:失败类型
FailedMethod:失败的方法
Size:方法生成的字节码的大小
Type:编译类型
Method 方法
2.4. gc原因
LGCC:上次GC的原因
GCC:当前GC的原因
enum Cause {
_java_lang_system_gc,// System.gc()触发
_full_gc_alot,
_scavenge_alot,
_allocation_profiler,
_jvmti_force_gc, // JVMTI(JVM Tool Interface)触发
_gc_locker, // 通过jni方式操作数组或者是字符串的时候,为了避免GC过程移动数组或字符串的内存地址,jvm实现了一个GC_locker,最后一个位于jni临界区内的线程退出临界区时,发起一次CGCause为_gc_locker的GC.
_heap_inspection,//jamp -hisot:live命令时会触发
_heap_dump,//dump堆
_wb_young_gc,// whitebox测试
_wb_conc_mark,
_update_allocation_context_stats_inc,
_update_allocation_context_stats_full,
/* implementation independent, but reserved for GC use */
_no_gc,
_no_cause_specified,
_allocation_failure,//内存分配失败触发的GC
/* implementation specific */
_tenured_generation_full,
_metadata_GC_threshold,//metaspace区域分配时分配不下,从而触发的GC
_cms_generation_full,
_cms_initial_mark,//CMS回收器初始标记
_cms_final_remark,//CMS回收器最终标记
_cms_concurrent_mark,//CMS回收器
_old_generation_expanded_on_last_scavenge,
_old_generation_too_full_to_scavenge,
_adaptive_size_policy,// ps中动态调整堆以及各个区大小时
_g1_inc_collection_pause,//G1分配不下触发的GC
_g1_humongous_allocation,// 分配超大对象失败时触发GC
_last_ditch_collection,//metaspace区域分配不下时,最后的一次回收
_last_gc_cause//
};
Pause Young (G1 Evacuation Pause) 触发流程
3. 常用的gc命令
jstat -gc 12141 1000 40
打印gc信息 每隔1000ms 打印40次
jstat -gcutil 12141 1000 40