大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
今天我们的系列文章要介绍的是这四个工具:
创新互联自2013年创立以来,是专业互联网技术服务公司,拥有项目做网站、成都做网站网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元博爱做网站,已为上家服务,为博爱各地企业和个人服务,联系电话:13518219792
Jstat(sun.tools.jstat) 它的全称是Java Virtual Machine Statistics Monitoring Tool,是用来监控JVM状态的工具。
jstack(sun.tools.jstack) 它的全称是Java Stack Trace,是用来做java栈的跟踪工具。
jmap(sun.tools.jmap) 它的全称是Java Memory Map,是java的内存管理工具。
jhat (com.sun.tools.hat.Main) 它的全称是Java Heap Analyse Tool,是java的堆分析工具。
有了这四个工具,基本上JVM运行期间的方方面面都可以被覆盖到了。下面我们将具体对每一个工具进行详细讲解。本文将会首先讲解Jstat的具体使用。
jstat主要对JVM运行期间的各种参数进行收集,包括查看类的加载情况,jc中新生代老年代元数据空间的使用情况等。
先看下Jstat的命令:
jstat outputOptions [-t] [-h lines] vmid [interval [count]]
上面我们讲了JStat命令的基本格式,在本节我们会详细讲解JStat的输出选项。
使用jstat -options可以看到jstat支持的几个options选项:
jstat -options -class-compiler-gc-gccapacity-gccause-gcmetacapacity-gcnew-gcnewcapacity-gcold-gcoldcapacity-gcutil-printcompilation
输出class loader的统计信息,我们举个例子:
jstat -class -t 53528 100 5Timestamp Loaded Bytes Unloaded Bytes Time 19822.8 5214 10752.5 0 0.0 2.91 19823.0 5214 10752.5 0 0.0 2.91 19823.0 5214 10752.5 0 0.0 2.91 19823.2 5214 10752.5 0 0.0 2.91 19823.2 5214 10752.5 0 0.0 2.91
上面的例子中53528是目标JVM的pid,100表示取样的间隔时间是100ms,5表示最后只展示5条数据。
上面的Timestamp表示的JVM的启动的时间。
compiler统计的是Java HotSpot VM Just-in-Time JIT即时编译器的信息。
JIT即时编译器是为了提升代码的执行速度而产生的。JVM对于一些热点代码,比如多次循环和经常使用的方法。对于这些热点代码,JIT会将其编译成机器代码,从而提升执行速度。
还是举刚刚的JVM的例子:
jstat -compiler 53528 100 5Compiled Failed Invalid Time FailedType FailedMethod 2675 0 0 5.35 0 2675 0 0 5.35 0 2675 0 0 5.35 0 2675 0 0 5.35 0 2675 0 0 5.35 0
gc统计的是gc heap信息
jstat -gc 53528 100 5 S0C S1C S0U S1U EC EU OC OU MC MU CCSC CCSU YGC YGCT FGC FGCT CGC CGCT GCT 0.0 4096.0 0.0 3978.2 56320.0 33792.0 15360.0 15215.0 21552.0 20680.9 2688.0 2468.0 4 0.025 0 0.000 2 0.003 0.028 0.0 4096.0 0.0 3978.2 56320.0 33792.0 15360.0 15215.0 21552.0 20680.9 2688.0 2468.0 4 0.025 0 0.000 2 0.003 0.028 0.0 4096.0 0.0 3978.2 56320.0 33792.0 15360.0 15215.0 21552.0 20680.9 2688.0 2468.0 4 0.025 0 0.000 2 0.003 0.028 0.0 4096.0 0.0 3978.2 56320.0 33792.0 15360.0 15215.0 21552.0 20680.9 2688.0 2468.0 4 0.025 0 0.000 2 0.003 0.028 0.0 4096.0 0.0 3978.2 56320.0 33792.0 15360.0 15215.0 21552.0 20680.9 2688.0 2468.0 4 0.025 0 0.000 2 0.003 0.028
gc的输出参数比较多,我们一一进行解释,这样大家对于gc的运行内核会有更多的理解:
Young Gen被划分为1个Eden Space和2个Suvivor Space。当对象刚刚被创建的时候,是放在Eden space。垃圾回收的时候,会扫描Eden Space和一个Suvivor Space。如果在垃圾回收的时候发现Eden Space中的对象仍然有效,则会将其复制到另外一个Suvivor Space。
就这样不断的扫描,最后经过多次扫描发现任然有效的对象会被放入Old Gen表示其生命周期比较长,可以减少垃圾回收时间。
在JDK8之前,类定义、字节码和常量等很少会变更的信息是放在持久代Perm Gen中的。不过在JDK8之后,Perm Gen已经被取消了,现在叫做Metaspace。Metaspace并不在java虚拟机中,它使用的是本地内存。Metaspace可以通过-XX:MaxMetaspaceSize来控制。
Compressed Class Space,它是和-XX:+UseCompressedOops,-XX:+UseCompressedClassesPointers有关的。实际上是一个指针的压缩,可以使用32bits来表示之前64bits的指针。
gccapacity统计的是内存池的创建和大小等统计信息
jstat -gccapacity 53528 100 5 NGCMN NGCMX NGC S0C S1C EC OGCMN OGCMX OGC OC MCMN MCMX MC CCSMN CCSMX CCSC YGC FGC CGC 0.0 716800.0 60416.0 0.0 4096.0 56320.0 0.0 716800.0 15360.0 15360.0 0.0 1069056.0 21552.0 0.0 1048576.0 2688.0 4 0 2 0.0 716800.0 60416.0 0.0 4096.0 56320.0 0.0 716800.0 15360.0 15360.0 0.0 1069056.0 21552.0 0.0 1048576.0 2688.0 4 0 2 0.0 716800.0 60416.0 0.0 4096.0 56320.0 0.0 716800.0 15360.0 15360.0 0.0 1069056.0 21552.0 0.0 1048576.0 2688.0 4 0 2 0.0 716800.0 60416.0 0.0 4096.0 56320.0 0.0 716800.0 15360.0 15360.0 0.0 1069056.0 21552.0 0.0 1048576.0 2688.0 4 0 2 0.0 716800.0 60416.0 0.0 4096.0 56320.0 0.0 716800.0 15360.0 15360.0 0.0 1069056.0 21552.0 0.0 1048576.0 2688.0 4 0 2
gcnew表示新生代的统计信息
jstat -gcnew 53528 100 5 S0C S1C S0U S1U TT MTT DSS EC EU YGC YGCT 0.0 4096.0 0.0 3978.2 15 15 5120.0 56320.0 33792.0 4 0.025 0.0 4096.0 0.0 3978.2 15 15 5120.0 56320.0 33792.0 4 0.025 0.0 4096.0 0.0 3978.2 15 15 5120.0 56320.0 33792.0 4 0.025 0.0 4096.0 0.0 3978.2 15 15 5120.0 56320.0 33792.0 4 0.025 0.0 4096.0 0.0 3978.2 15 15 5120.0 56320.0 33792.0 4 0.025
gcnewcapacity统计的是新生代的指标,和gccapacity的结果是很类似的:
jstat -gcnewcapacity 53528 100 5 NGCMN NGCMX NGC S0CMX S0C S1CMX S1C ECMX EC YGC FGC CGC 0.0 716800.0 60416.0 0.0 0.0 716800.0 4096.0 716800.0 56320.0 4 0 2 0.0 716800.0 60416.0 0.0 0.0 716800.0 4096.0 716800.0 56320.0 4 0 2 0.0 716800.0 60416.0 0.0 0.0 716800.0 4096.0 716800.0 56320.0 4 0 2 0.0 716800.0 60416.0 0.0 0.0 716800.0 4096.0 716800.0 56320.0 4 0 2 0.0 716800.0 60416.0 0.0 0.0 716800.0 4096.0 716800.0 56320.0 4 0 2
gcold统计old代的信息
jstat -gcold 53528 100 5 MC MU CCSC CCSU OC OU YGC FGC FGCT CGC CGCT GCT 21552.0 20680.9 2688.0 2468.0 15360.0 15215.0 4 0 0.000 2 0.003 0.028 21552.0 20680.9 2688.0 2468.0 15360.0 15215.0 4 0 0.000 2 0.003 0.028 21552.0 20680.9 2688.0 2468.0 15360.0 15215.0 4 0 0.000 2 0.003 0.028 21552.0 20680.9 2688.0 2468.0 15360.0 15215.0 4 0 0.000 2 0.003 0.028 21552.0 20680.9 2688.0 2468.0 15360.0 15215.0 4 0 0.000 2 0.003 0.028
结果的几项指标前面已经介绍过了,这里就不再重复了
gcoldcapacity表示old代的容量信息
jstat -gcoldcapacity 53528 100 5 OGCMN OGCMX OGC OC YGC FGC FGCT CGC CGCT GCT 0.0 716800.0 15360.0 15360.0 4 0 0.000 2 0.003 0.028 0.0 716800.0 15360.0 15360.0 4 0 0.000 2 0.003 0.028 0.0 716800.0 15360.0 15360.0 4 0 0.000 2 0.003 0.028 0.0 716800.0 15360.0 15360.0 4 0 0.000 2 0.003 0.028 0.0 716800.0 15360.0 15360.0 4 0 0.000 2 0.003 0.028
gcmetacapacity统计的是元数据区域的容量信息
jstat -gcmetacapacity 53528 100 5 MCMN MCMX MC CCSMN CCSMX CCSC YGC FGC FGCT CGC CGCT GCT 0.0 1069056.0 21552.0 0.0 1048576.0 2688.0 4 0 0.000 2 0.003 0.028 0.0 1069056.0 21552.0 0.0 1048576.0 2688.0 4 0 0.000 2 0.003 0.028 0.0 1069056.0 21552.0 0.0 1048576.0 2688.0 4 0 0.000 2 0.003 0.028 0.0 1069056.0 21552.0 0.0 1048576.0 2688.0 4 0 0.000 2 0.003 0.028 0.0 1069056.0 21552.0 0.0 1048576.0 2688.0 4 0 0.000 2 0.003 0.028
gcutil统计的是GC总体的情况
jstat -gcutil 53528 100 5 S0 S1 E O M CCS YGC YGCT FGC FGCT CGC CGCT GCT 0.00 97.12 60.00 99.06 95.96 91.82 4 0.025 0 0.000 2 0.003 0.028 0.00 97.12 60.00 99.06 95.96 91.82 4 0.025 0 0.000 2 0.003 0.028 0.00 97.12 60.00 99.06 95.96 91.82 4 0.025 0 0.000 2 0.003 0.028 0.00 97.12 60.00 99.06 95.96 91.82 4 0.025 0 0.000 2 0.003 0.028 0.00 97.12 60.00 99.06 95.96 91.82 4 0.025 0 0.000 2 0.003 0.028
gccause和gcutil非常相识,只不过多了下面两列:
jstat -gccause 53528 100 5 S0 S1 E O M CCS YGC YGCT FGC FGCT CGC CGCT GCT LGCC GCC 0.00 97.12 60.00 99.06 95.96 91.82 4 0.025 0 0.000 2 0.003 0.028 Metadata GC Threshold No GC 0.00 97.12 60.00 99.06 95.96 91.82 4 0.025 0 0.000 2 0.003 0.028 Metadata GC Threshold No GC 0.00 97.12 60.00 99.06 95.96 91.82 4 0.025 0 0.000 2 0.003 0.028 Metadata GC Threshold No GC 0.00 97.12 60.00 99.06 95.96 91.82 4 0.025 0 0.000 2 0.003 0.028 Metadata GC Threshold No GC 0.00 97.12 60.00 99.06 95.96 91.82 4 0.025 0 0.000 2 0.003 0.028 Metadata GC Threshold No GC
printcompilation是JVM编译器的方法统计
jstat -printcompilation 53528 100 5Compiled Size Type Method 2675 23 1 jdk/internal/misc/InnocuousThread eraseThreadLocals 2675 23 1 jdk/internal/misc/InnocuousThread eraseThreadLocals 2675 23 1 jdk/internal/misc/InnocuousThread eraseThreadLocals 2675 23 1 jdk/internal/misc/InnocuousThread eraseThreadLocals 2675 23 1 jdk/internal/misc/InnocuousThread eraseThreadLocals
本文介绍了JDK14中自带的jstat JVM分析工具,希望大家能够在实际的工作中用到。
https://www.imdb.com/list/ls080419900/?publish=publish
https://www.imdb.com/list/ls080419956/?publish=publish
https://www.imdb.com/list/ls080419916/?publish=publish
https://www.imdb.com/list/ls080419990/?publish=publish
https://www.imdb.com/list/ls080419855/?publish=publish
https://www.imdb.com/list/ls080419867/?publish=publish
https://www.imdb.com/list/ls080418035/?publish=publish
https://www.imdb.com/list/ls080418063/?publish=publish
https://www.imdb.com/list/ls080418085/?publish=publish
https://www.imdb.com/list/ls080418713/?publish=publish
https://www.imdb.com/list/ls080418783/?publish=publish
https://www.imdb.com/list/ls080418174/?publish=publish
https://www.imdb.com/list/ls080418113/?publish=publish
https://www.imdb.com/list/ls080418138/?publish=publish
https://www.imdb.com/list/ls080418184/?publish=publish
https://www.imdb.com/list/ls080418326/?publish=publish
https://www.imdb.com/list/ls080418399/?publish=publish
https://www.imdb.com/list/ls080418659/?publish=publish
https://www.imdb.com/list/ls080418638/?publish=publish
https://www.imdb.com/list/ls080418696/?publish=publish
https://www.imdb.com/list/ls080418253/?publish=publish
https://www.imdb.com/list/ls080418274/?publish=publish
https://www.imdb.com/list/ls080418239/?publish=publish
https://www.imdb.com/list/ls080418248/?publish=publish
https://www.imdb.com/list/ls080418280/?publish=publish
https://www.imdb.com/list/ls080418459/?publish=publish
https://www.imdb.com/list/ls080418481/?publish=publish
https://www.imdb.com/list/ls080418875/?publish=publish
https://www.imdb.com/list/ls080418874/?publish=publish
https://www.imdb.com/list/ls080418834/?publish=publish
https://www.imdb.com/list/ls080418869/?publish=publish
https://www.imdb.com/list/ls080418844/?publish=publish
https://www.imdb.com/list/ls080430017/?publish=publish
https://www.imdb.com/list/ls080430045/?publish=publish
https://www.imdb.com/list/ls080430562/?publish=publish
https://www.imdb.com/list/ls080430172/?publish=publish
https://www.imdb.com/list/ls080430111/?publish=publish
https://www.imdb.com/list/ls080430167/?publish=publish
https://www.imdb.com/list/ls080430191/?publish=publish
https://www.imdb.com/list/ls080430314/?publish=publish
https://www.imdb.com/list/ls080430389/?publish=publish
https://www.imdb.com/list/ls080430652/?publish=publish
https://www.imdb.com/list/ls080430614/?publish=publish