2017年8月

JVM Troubleshooting 学习笔记

Java Platform, Standard Edition Troubleshooting Guide

Command-line options that are prefixed with -XX are specific to Java HotSpot VM. For more information about command-line options used by Java HotSpot VM, see Java HotSpot VM Command-Line Options.
The jcmd is a new JDK profiling utility in JDK 8. It is suggested to use the latest diagnostic utility, jcmd instead of the earlier jstack, jinfo, and jmap utilities.

Java SE Monitoring and Management Guide
Monitoring and Management for the Java Platform

JVM - jstat

Monitors Java Virtual Machine (JVM) statistics. This command is experimental and unsupported.

jstat [ generalOption | outputOptions vmid [ interval[s|ms] [ count ] ]
//vmid: protocol:lvmid[@hostname[:port]/servername]

refer: https://docs.oracle.com/javase/8/docs/technotes/tools/windows/jstat.html

$_ jstat -help
$_ jstat -options
-class
-compiler
-gc
-gccapacity
-gccause
-gcnew
-gcnewcapacity
-gcold
-gcoldcapacity
-gcpermcapacity
-gcutil
-printcompilation
$_ ./jstat -printcompilation  -t 18128 1s
$_ ./jstat -printcompilation  -t 18128 1s 2
$_ ./jstat -gc -t 18128 1s 2

Timestamp S0C S1C S0U S1U EC EU OC
OU PC PU YGC YGCT FGC FGCT GCT

     3346.4 571392.0 607744.0 340114.4 384.0  1505280.0 1505280.0 5460992.0  1679695.0  66560.0 61799.4   2463  493.065  59    220.141  713.206
     3347.4 585216.0 607744.0  0.0   384.0  1505280.0 302819.9 5460992.0  1933919.0  66560.0 61799.4   2463  493.496  59    220.141  713.637

JVM - jcmd

The jcmd utility is used to send diagnostic command requests to the JVM, where these requests are useful for controlling Java Flight Recordings, troubleshoot, and diagnose JVM and Java Applications. It must be used on the same machine where the JVM is running, and have the same effective user and group identifiers that were used to launch the JVM.
 Sample
 jcmd
 jcmd PerfCounter.print
 jcmd 2125 help //2125 is the pid
 jcmd 2125 GC.heap_dump filename=Myheapdump
 jcmd 2125 VM.uptime
 jcmd VM.system_properties
 jcmd VM.flags
 jcmd MyProgram help Thread.print
 jcmd Thread.print
 jcmd [options]
 jcmd 7060 JFR.start name=MyRecording settings=profile delay=20s duration=2m filename=C:\TEMP\myrecording.jfr
 jcmd 7060 JFR.check
 jcmd 7060 JFR.stop
More:

jcmd man page: https://docs.oracle.com/javase/8/docs/technotes/tools/windows/jcmd.html
Useful Commands for jcmd Utility: https://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot/tooldescr006.html#BABEJDGE 
Troubleshoot with jcmd Utility: https://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot/tooldescr006.html#BABFFIFA

JVM - jps

Lists the instrumented Java Virtual Machines (JVMs of HotSpot) on the target system.
只能列出当前用户的java 进程, 不能列出其它用户的.

  1. A jstatd process is assumed to be running on the target host.
  2. The jps command uses the Java launcher to find the class name and arguments passed to the main method. If the target JVM is started with a custom launcher, then the class or JAR file name and the arguments to the main method are not available. In this case, the jps command outputs the string Unknown for the class name or JAR file name and for the arguments to the main method.
  3. The command only lists the JVMs for which the principle has access rights as determined by operating system-specific access control mechanisms.

Sample

jps
jps –l remote.domain
jps –m remote.domain:2002 (see jstatd –n)
jps -v //列出启动时的参数

Refer: https://docs.oracle.com/javase/8/docs/technotes/tools/windows/jps.html

core dump 或者 crash dump

core dump:A core dump or a crash dump is a memory snapshot of a running process.

如何获得:

  1. A core dump can be automatically created by the operating system
    when a fatal or unhandled error (for example, signal or system
    exception) occurs.
  2. or can be forced by means of system-provided command-line utilities.
  3. kill -6 on Linux or Solaris systems 将会强制产生一个core 文件,即使程序无响应。

    更多如何获得 参看 [这里][1]
    

IBM JVM(J9) 的javacore 文件和一般进程的core dump 不是一回事。
IBM JVM (J9) java core file: http://www-01.ibm.com/support/docview.wss?uid=swg21393547