java comes with command line tools jmap jhat and jinfo use example code detail

  • 2020-07-21 08:02:32
  • OfStack

java comes with command-line tools (jmap,jhat,jinfo)

(1) JMAP

1. The role

Print processes, core files, and Shared objects for remote processes to store map or heap storage details.

2. Use


jmap[options]pid
jmap[options]executablecore
jmap[options][pid]server-id@]remote-hostname-or-IP

If the specified process is running on a 64-bit Java virtual machine (JVM), you may need to specify the -ES21en-ES22en64 option, such as jmap-ES24en-ES25en64-ES27en.

3. Parameter options

3.1

When the option is not used, the jmap command prints the Shared object map

Such as


C:\Users\Administrator>jmap9208
AttachingtoprocessID9208,pleasewait...
Debuggerattachedsuccessfully.
Servercompilerdetected.
JVMversionis24.75-b04
0x00000000623c00008016KD:\Java\jdk1.7.0_75\jre\bin\server\jvm.dll
0x0000000062ba0000840KD:\Java\jdk1.7.0_75\jre\bin\msvcr100.dll
0x0000000062cc0000144KD:\Java\jdk1.7.0_75\jre\bin\sunec.dll
0x0000000062cf000068KD:\Java\jdk1.7.0_75\jre\bin\nio.dll
0x0000000062d10000100KD:\Java\jdk1.7.0_75\jre\bin\net.dll
0x0000000062d30000160KD:\Java\jdk1.7.0_75\jre\bin\java.dll
0x00000000634d000084KD:\Java\jdk1.7.0_75\jre\bin\zip.dll
0x000000006595000044KD:\Java\jdk1.7.0_75\jre\bin\sunmscapi.dll
0x000000006596000060KD:\Java\jdk1.7.0_75\jre\bin\verify.dll
0x000000006597000044KD:\Java\jdk1.7.0_75\jre\bin\management.dll
...

3.2

-dump:[live,] format=b, file=filename

Dump the Java heap in hprof2 base format. Specify live to identify the object that dumped the active state. The generated file can be viewed by the jhat command.


C:\Users\Administrator>jmap-dump:format=b,file=9208_0413.hprof9208
DumpingheaptoC:\Users\Administrator\9208_0413.hprof...
Heapdumpfilecreated

3.3-finalizerinfo

Prints information about the object that will end


C:\Users\Administrator>jmap-finalizerinfo9208
AttachingtoprocessID9208,pleasewait...
Debuggerattachedsuccessfully.
Servercompilerdetected.
JVMversionis24.75-b04
Numberofobjectspendingforfinalization:0

3.4 -heap

Print garbage collection and heap digest information, and generate the heap digest used by the -ES68en heap


C:\Users\Administrator>jmap-heap9208
AttachingtoprocessID9208,pleasewait...
Debuggerattachedsuccessfully.
Servercompilerdetected.
JVMversionis24.75-b04
 
usingthread-localobjectallocation.
ParallelGCwith4thread(s)
 
HeapConfiguration:
MinHeapFreeRatio=0
MaxHeapFreeRatio=100
MaxHeapSize=2124414976(2026.0MB)
NewSize=1310720(1.25MB)
MaxNewSize=17592186044415MB
OldSize=5439488(5.1875MB)
NewRatio=2
SurvivorRatio=8
PermSize=21757952(20.75MB)
MaxPermSize=85983232(82.0MB)
G1HeapRegionSize=0(0.0MB)
 
HeapUsage:
PSYoungGeneration
EdenSpace:
capacity=68157440(65.0MB)
used=16646688(15.875518798828125MB)
free=51510752(49.124481201171875MB)
24.423875075120193%used
FromSpace:
capacity=5242880(5.0MB)
used=5228248(4.986045837402344MB)
free=14632(0.01395416259765625MB)
99.72091674804688%used
ToSpace:
capacity=15728640(15.0MB)
used=0(0.0MB)
free=15728640(15.0MB)
0.0%used
PSOldGeneration
capacity=88080384(84.0MB)
used=27239848(25.977943420410156MB)
free=60840536(58.022056579589844MB)
30.9261231195359%used
PSPermGeneration
capacity=22020096(21.0MB)
used=15369592(14.657585144042969MB)
free=6650504(6.342414855957031MB)
69.7980244954427%used
 10057internedStringsoccupying867832bytes.

3.5 -histo[:live]

A histogram of the print heap


num#instances#bytesclassname
----------------------------------------------
...
877:132[Lcom.sun.jndi.ldap.pool.Pool;
878:232com.sun.org.apache.xerces.internal.impl.dv.dtd.ENTITYDatatypeValidator
879:232java.lang.Shutdown$Lock
880:132org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler
881:232com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver
882:132java.lang.reflect.WeakCache$CacheKey
883:132java.text.FieldPosition
884:132java.util.concurrent.atomic.AtomicReferenceFieldUpdater$AtomicReferenceFieldUpdaterImpl
885:232sun.security.x509.CertificateVersion
886:232[Lorg.apache.catalina.deploy.ContextEnvironment;
887:132[Lorg.apache.tomcat.util.net.AbstractEndpoint$Acceptor$AcceptorState;
888:132sun.nio.cs.StandardCharsets
...

3.6 -clstats

wise statistics for java heap. 1.7.0_75 is not supported

(2) jhat

2.1 role

Analyze the Java heap. The jhat command parses the Java heap dump file and starts the Web server. The jhat command lets you browse through heap dumps. Support for OQL syntax.

2.2 the use of

jhat [ options ] heap-dump-file

2.3 Parameter Description

1.-stack false|true

Close the trace object allocation call stack. The default value is true.

-refs false|true

Closes the trace of a reference to an object. The default is true.

-port port-number

Set the jhatHTTP server for the port. The default value is 7000.

-exclude exclude-file

Specifies a file that lists the excluded data members that should be queried from accessible objects

-baseline exclude-file

Specify the base heap dump. Both heap dump objects with the same object ID are marked as not new objects. This is useful for comparing two different heap dumps.

-debug int

Level 0 indicates no debug output


C:\Users\Administrator>jhat-port80009208_0413.hprof
Readingfrom9208_0413.hprof...
DumpfilecreatedThuApr1321:18:58CST2017
Snapshotread,resolving...
Resolving389761objects...
Chasingreferences,expect77dots..........................................................................
Eliminatingduplicatereferences............................................................................
Snapshotresolved.
StartedHTTPserveronport8000
Serverisready.

Next, you can view it through a browser. http: / / localhost: 8000 /.

(3)jinfo

3.1 role

Generated configuration information. If the specified process is running on 64-bit JVM, you may need to specify the -J-d64 option

3.2 the use of


jinfo[option]pid
jinfo[option]executablecore
jinfo[option][servier-id]remote-hostname-or-IP

3.3 Option parameters

no-option: Prints both command line flags and system property key-value pairs.

-flag name

Prints the name and the value of the specified command line flag.

-flag [+|-]name

Turns on or disables the specified Boolean command line flag.

jhat [ options ] heap-dump-file0

Sets the specified command line flag to the specified value.

-flags

The print command line flag is passed to JVM.

-sysprops

Print Java system property key-value pairs.

Print command-line arguments to the process


C:\Users\Administrator>jinfo-flags9208
AttachingtoprocessID9208,pleasewait...
Debuggerattachedsuccessfully.
Servercompilerdetected.
JVMversionis24.75-b04
 -Djava.util.logging.config.file=D:\apache-tomcat-7.0.67\conf\logging.properties-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
-Djava.endorsed.dirs=D:\apache-tomcat-7.0.67\endorsed-Dcatalina.base=D:\apache-tomcat-7.0.67-Dcatalina.home=D:\apache-tomcat-7.0.67-Djava.io.
tmpdir=D:\apache-tomcat-7.0.67\temp
# in catalina.sh You can find the Settings in 

Print parameter value


# Value type parameter 
C:\Users\Administrator>jinfo-flagNewSize9208
-XX:NewSize=1310720
 
# Switch type parameter 
C:\Users\Administrator>jinfo-flagPrintGC9208
-XX:-PrintGC
 
C:\Users\Administrator>jinfo-flagXmn9208
nosuchflag'Xmn'

It can be concluded that: -xms,-xmn series parameters cannot be specified or printed by jinfo; The jinfo command operates on arguments in the -XX:*** format.

Set parameter values


C:\Users\Administrator>jmap9208
AttachingtoprocessID9208,pleasewait...
Debuggerattachedsuccessfully.
Servercompilerdetected.
JVMversionis24.75-b04
0x00000000623c00008016KD:\Java\jdk1.7.0_75\jre\bin\server\jvm.dll
0x0000000062ba0000840KD:\Java\jdk1.7.0_75\jre\bin\msvcr100.dll
0x0000000062cc0000144KD:\Java\jdk1.7.0_75\jre\bin\sunec.dll
0x0000000062cf000068KD:\Java\jdk1.7.0_75\jre\bin\nio.dll
0x0000000062d10000100KD:\Java\jdk1.7.0_75\jre\bin\net.dll
0x0000000062d30000160KD:\Java\jdk1.7.0_75\jre\bin\java.dll
0x00000000634d000084KD:\Java\jdk1.7.0_75\jre\bin\zip.dll
0x000000006595000044KD:\Java\jdk1.7.0_75\jre\bin\sunmscapi.dll
0x000000006596000060KD:\Java\jdk1.7.0_75\jre\bin\verify.dll
0x000000006597000044KD:\Java\jdk1.7.0_75\jre\bin\management.dll
...
0

I hope you found this article helpful


Related articles: