JVM | Command line diagnosis and tuning jhsdb jmap jstat jps

Table of Contents

jmap

View heap usage

View the class list, including the number of instances and memory size occupied

Generate heap dump snapshot dump file of jvm

jstat

View gc information, check the number of gc times, and time

Check the usage and size of three generations (young/old/perm) objects in VM memory

View metadata space statistics

View information about young generation objects

View information about young generation objects and their occupancy

View information about old generation objects

View information about old generation objects and their usage

View the latest GC statistics and reasons

jps

View currently running java processes

View the parameters passed to main() when the process starts

View JVM parameters when the process is started

Some error reports

Cannot connect to core dump or remote debug server. Use jhsdb jmap instead

ERROR: ptrace(PTRACE_ATTACH, ..) failed for 30865: Operation not permitted…


jmap

View heap usage

jmap -heap [pid]

View class list, including the number of instances and memory size occupied

jmap -histo [pid]

If you bring live, only live objects will be counted:

jmap -histo:live [pid]

Generate jvm heap dump snapshot dump file

jmap -dump:format=b,file=dumpFileName [pid]

jstat

View JVM statistics, class loading, memory, garbage collection, JIT compilation and other operating data.

jstat -<option> [-t] [-h<lines>] <vmid> [<interval> [<count>]]

View gc information, number of gc views, and time

jstat -gc [pid]

Information description:

  • S0C: Capacity of the first survivor (survivor area) in the young generation (bytes)
  • S1C: The capacity of the second survivor (survivor area) in the young generation (bytes)
  • S0U: The first survivor (survivor area) in the young generation currently uses space (bytes)
  • S1U: The second survivor (survivor area) in the young generation currently uses space (bytes)
  • EC: The capacity of Eden in the young generation (bytes)
  • EU: Eden currently uses space (bytes) in the young generation
  • OC: Capacity of the old generation (bytes)
  • OU: Old generation currently used space (bytes)
  • MC: capacity of metaspace (bytes)
  • MU: metaspace (metaspace) currently used space (bytes)
  • CCSC: The capacity of the current compression class space (bytes)
  • CCSU: The current compression class space currently uses space (bytes)
  • YGC: The number of GCs in the young generation from application startup to sampling time
  • YGCT: The time (s) used for gc in the young generation from application startup to sampling time
  • FGC: Number of old generation (full gc) gcs from application startup to sampling time
  • FGCT: The time (s) used for gc in the old generation (full gc) from application startup to sampling
  • GCT: The total time (s) used by gc from application startup to sampling

View the usage and occupied size of third-generation (young/old/perm) objects in VM memory

jstat -gccapacity [pid]

Information description:

  • NGCMN: Initialization (minimum) size (bytes) in the young generation (young)
  • NGCMX: The maximum capacity (bytes) of the young generation (young)
  • NGC: Current capacity (bytes) in the young generation (young)
  • S0C: Capacity of the first survivor (survivor area) in the young generation (bytes)
  • S1C: The capacity of the second survivor (survivor area) in the young generation (bytes)
  • EC: The capacity of Eden in the young generation (bytes)
  • OGCMN: Initialized (minimum) capacity size (bytes) in the old generation
  • OGCMX: Maximum capacity of the old generation (bytes)
  • OGC: The current newly generated capacity of the old generation (bytes)
  • OC: Capacity of the old generation (bytes)
  • MCMN: initial (minimum) size (bytes) in metaspace
  • MCMX: Maximum capacity of metaspace (bytes)
  • MC: The current newly generated capacity of metaspace (metaspace) (bytes)
  • CCSMN: minimum compressed class space size
  • CCSMX: Maximum compressed class space size
  • CCSC: Current compression class space size
  • YGC: The number of GCs in the young generation from application startup to sampling time
  • FGC: Number of old generation (full gc) gcs from application startup to sampling time

View metadata space statistics

jstat -gcmetacapacity [pid]

Information description:

  • MCMN: Minimum metadata capacity
  • MCMX: Maximum metadata capacity
  • MC: Current metadata space size
  • CCSMN: minimum compressed class space size
  • CCSMX: Maximum compressed class space size
  • CCSC: Current compression class space size
  • YGC: The number of GCs in the young generation from application startup to sampling time
  • FGC: Number of old generation (full gc) gcs from application startup to sampling time
  • FGCT: The time (s) used for gc in the old generation (full gc) from application startup to sampling
  • GCT: The total time (s) used by gc from application startup to sampling

View information about young generation objects

jstat -gcnew [pid]

Information description:

  • S0C: Capacity of the first survivor (survivor area) in the young generation (bytes)
  • S1C: The capacity of the second survivor (survivor area) in the young generation (bytes)
  • S0U: The first survivor (survivor area) in the young generation currently uses space (bytes)
  • S1U: The second survivor (survivor area) in the young generation currently uses space (bytes)
  • TT: Holding limit
  • MTT: Maximum holding limit
  • DSS: Desired survivor area size
  • EC: The capacity of Eden in the young generation (bytes)
  • EU: Eden currently uses space (bytes) in the young generation
  • YGC: The number of GCs in the young generation from application startup to sampling time
  • YGCT: The time (s) used for gc in the young generation from application startup to sampling time

View the information and occupancy of young generation objects

jstat -gcnewcapacity [pid]

Information description:

  • NGCMN: Initialization (minimum) size (bytes) in the young generation (young)
  • NGCMX: The maximum capacity (bytes) of the young generation (young)
  • NGC: Current capacity (bytes) in the young generation (young)
  • S0CMX: The maximum capacity (bytes) of the first survivor (survivor area) in the young generation
  • S0C: Capacity of the first survivor (survivor area) in the young generation (bytes)
  • S1CMX: The maximum capacity (bytes) of the second survivor (survivor area) in the young generation
  • S1C: The capacity of the second survivor (survivor area) in the young generation (bytes)
  • ECMX: Maximum capacity of Eden in the young generation (bytes)
  • EC: The capacity of Eden in the young generation (bytes)
  • YGC: The number of GCs in the young generation from application startup to sampling time
  • FGC: Number of old generation (full gc) gcs from application startup to sampling time

View information about old generation objects

jstat -gcold [pid]

Information description:

  • MC: capacity of metaspace (bytes)
  • MU: metaspace (metaspace) currently used space (bytes)
  • CCSC: Compressed class space size
  • CCSU: Compressed class space usage size
  • OC: Capacity of Old generation (bytes)
  • OU: Old generation currently uses space (bytes)
  • YGC: The number of GCs in the young generation from application startup to sampling time
  • FGC: Number of old generation (full gc) gcs from application startup to sampling time
  • FGCT: The time it takes for gc from application startup to sampling time (full gc) (s)
  • GCT: The total time (s) used by gc from application startup to sampling

View the information and occupancy of old generation objects

jstat -gcoldcapacity [pid]

Information description:

  • OGCMN: Initialization (minimum) size in Old generation (bytes)
  • OGCMX: Maximum capacity of Old generation (bytes)
  • OGC: The current newly generated capacity of the Old generation (bytes)
  • OC: Capacity of Old generation (bytes)
  • YGC: The number of GCs in the young generation from application startup to sampling time
  • FGC: Number of old generation (full gc) gcs from application startup to sampling time
  • FGCT: The time it takes for gc from application startup to sampling time (full gc) (s)
  • GCT: The total time (s) used by gc from application startup to sampling

View the latest GC statistics and reasons

jstat -gccause [pid]

Information description:

  • LGCC: last GC reason
  • GCC: Current GC reason (No GC means that GC is not currently executed)

jps

View the currently running java process

jps

View parameters passed to main() when the process starts

jps -m

View JVM parameters when the process is started

jps -v

Partial error reporting

Cannot connect to core dump or remote debug server. Use jhsdb jmap instead

It is caused by the jdk version. After jdk8, you need to add jhsdb to run (note the format here):

jhsdb jmap --heap --pid [pid]

ERROR: ptrace(PTRACE_ATTACH, ..) failed for 30865: Operation not permitted…

The new version of Linux system (this problem will occur after Ubuntu 11.04) has added the ptrace-scope mechanism. This mechanism is to prevent users from accessing the memory and status of the currently running process, and some debugging software itself uses ptrace to obtain the memory status of a process (including GDB), so in new versions of Linux systems, by default Access is no longer allowed and can be temporarily enabled (pay attention to permissions):

echo 0 >/proc/sys/kernel/yama/ptrace_scope

Permanent modification:

vi /etc/sysctl.d/10-ptrace.conf
 
kernel.yama.ptrace_scope = 0