C:\Users\Administrator>jmap Usage: jmap [option] <pid> (to connect to running process) jmap [option] <executable <core> (to connect to a core file) jmap [option] [server_id@]<remote server IP or hostname> (to connect to remote debug server)
where <option> is one of: <none> to print same info as Solaris pmap -heap to print java heap summary -histo[:live] to print histogram of java object heap; if the "live" suboption is specified, only count live objects -clstats to print class loader statistics -finalizerinfo to print information on objects awaiting finalization -dump:<dump-options> to dump java heap in hprof binary format dump-options: live dump only live objects; if not specified, all objects in the heap are dumped. format=b binary format file=<file> dump heap to <file> Example: jmap -dump:live,format=b,file=heap.bin <pid> -F force. Use with -dump:<dump-options> <pid> or -histo to force a heap dump or histogram when <pid> does not respond. The "live" suboption is not supported in this mode. -h | -help to print this help message -J<flag> to pass <flag> directly to the runtime system
C:\Users\Administrator>jmap -clstats 6444 Attaching to process ID 6444, please wait... Debugger attached successfully. Server compiler detected. JVM version is 25.111-b14 finding class loader instances ..done. computing per loader stat ..done. please wait.. computing liveness...liveness analysis may be inaccurate ... class_loader classes bytes parent_loader alive? type
<bootstrap> 567 1071357 null live <internal> 0x00000006c140a808 24 71712 0x00000006c140a878 live sun/misc/Launcher$AppClassLoader@0x00000007c000f6a0 0x00000006c140a878 0 0 null live sun/misc/Launcher$ExtClassLoader@0x00000007c000fa48
C:\Users\Administrator>jmap -heap 6444 Attaching to process ID 6444, please wait... Debugger attached successfully. Server compiler detected. JVM version is 25.111-b14
using thread-local object allocation. Parallel GC with 8 thread(s) 【使用的GC收集器,8个线程】
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.
jvmstat -gc
1 2 3
C:\Users\Administrator>jstat -gc 6444 S0C S1C S0U S1U EC EU OC OU MC MU CCSC CCSU YGC YGCT FGC FGCT GCT 512.0 512.0 0.0 0.0 31232.0 14367.0 175104.0 780.2 4864.0 3519.5 512.0 386.2 788 0.479 0 0.000 0.479
command must be a valid jcmd command for the selected jvm. Use the command "help" to see which commands are available. If the pid is 0, commands will be sent to all Java processes. The main class argument will be used to match (either partially or fully) the class used to start Java. If no options are given, lists Java processes (same as -p).
PerfCounter.print display the counters exposed by this process -f read and execute commands from the file -l list JVM processes on the local machine -h this help
查看JFR.dump有哪些参数: C:\Users\Administrator>jcmd 12048 help JFR.dump 12048: JFR.dump Copies contents of a JFR recording to file. Either the name or the recording id must be specified.
Options: (options must be specified using the <key> or <key>=<value> syntax) name : [optional] Recording name, e.g. \"My Recording\" (STRING, no default value) recording : [optional] Recording number, use JFR.check to list available recordings (JLONG, -1) filename : Copy recording data to file, i.e \"C:\Users\user\My Recording.jfr\" (STRING, no default value) compress : [optional] GZip-compress "filename" destination (BOOLEAN, false)
"Monitor Ctrl-Break" #6 daemon prio=5 os_prio=0 tid=0x000000001efc7800 nid=0x4af4 runnable [0x000000001f6ae000] java.lang.Thread.State: RUNNABLE at java.net.SocketInputStream.socketRead0(Native Method) at java.net.SocketInputStream.socketRead(SocketInputStream.java:116) at java.net.SocketInputStream.read(SocketInputStream.java:170) at java.net.SocketInputStream.read(SocketInputStream.java:141) at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:284) at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:326) at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178) - locked <0x00000006c14089e8> (a java.io.InputStreamReader) at java.io.InputStreamReader.read(InputStreamReader.java:184) at java.io.BufferedReader.fill(BufferedReader.java:161) at java.io.BufferedReader.readLine(BufferedReader.java:324) - locked <0x00000006c14089e8> (a java.io.InputStreamReader) at java.io.BufferedReader.readLine(BufferedReader.java:389) at com.intellij.rt.execution.application.AppMainV2$1.run(AppMainV2.java:64)
"Finalizer" #3 daemon prio=8 os_prio=1 tid=0x0000000003559800 nid=0x2f04 in Object.wait() [0x000000001f3af000] java.lang.Thread.State: WAITING (on object monitor) at java.lang.Object.wait(Native Method) - waiting on <0x00000006c1406d08> (a java.lang.ref.ReferenceQueue$Lock) at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:143) - locked <0x00000006c1406d08> (a java.lang.ref.ReferenceQueue$Lock) at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:164) at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:209)
"Reference Handler" #2 daemon prio=10 os_prio=2 tid=0x0000000003558000 nid=0x3a0 in Object.wait() [0x000000001eeae000] java.lang.Thread.State: WAITING (on object monitor) at java.lang.Object.wait(Native Method) - waiting on <0x00000006c1406d48> (a java.lang.ref.Reference$Lock) at java.lang.Object.wait(Object.java:502) at java.lang.ref.Reference.tryHandlePending(Reference.java:191) - locked <0x00000006c1406d48> (a java.lang.ref.Reference$Lock) at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:153)
"main" #1 prio=5 os_prio=0 tid=0x0000000003462800 nid=0x28bc runnable [0x000000000328f000] java.lang.Thread.State: RUNNABLE at java.io.FileOutputStream.writeBytes(Native Method) at java.io.FileOutputStream.write(FileOutputStream.java:326) at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82) at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140) - locked <0x00000006c141bf30> (a java.io.BufferedOutputStream) at java.io.PrintStream.write(PrintStream.java:482) - locked <0x00000006c140a1e8> (a java.io.PrintStream) at sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:221) at sun.nio.cs.StreamEncoder.implFlushBuffer(StreamEncoder.java:291) at sun.nio.cs.StreamEncoder.flushBuffer(StreamEncoder.java:104) - locked <0x00000006c140a1a0> (a java.io.OutputStreamWriter) at java.io.OutputStreamWriter.flushBuffer(OutputStreamWriter.java:185) at java.io.PrintStream.write(PrintStream.java:527) - eliminated <0x00000006c140a1e8> (a java.io.PrintStream) at java.io.PrintStream.print(PrintStream.java:669) at java.io.PrintStream.println(PrintStream.java:806) - locked <0x00000006c140a1e8> (a java.io.PrintStream) at com.twodragonlake.jvm.memory.MyTest5.main(MyTest5.java:34)
C:\Users\Administrator>jcmd 14044 Thread.print 14044: 2019-04-30 17:00:02 Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.111-b14 mixed mode):
....略....
【检测到死锁】 Found one Java-level deadlock: ============================= "thread2": waiting to lock monitor 0x000000001c6b35f8 (object 0x000000076b345af0, a java.lang.Object), which is held by "thread1" "thread1": waiting to lock monitor 0x000000001e801e68 (object 0x000000076b345b00, a java.lang.Object), which is held by "thread2"
Java stack information for the threads listed above: =================================================== "thread2": at com.twodragonlake.jvm.memory.DeadLock$2.run(DeadLock.java:48) - waiting to lock <0x000000076b345af0> (a java.lang.Object) - locked <0x000000076b345b00> (a java.lang.Object) at java.lang.Thread.run(Thread.java:745) "thread1": at com.twodragonlake.jvm.memory.DeadLock$1.run(DeadLock.java:37) - waiting to lock <0x000000076b345b00> (a java.lang.Object) - locked <0x000000076b345af0> (a java.lang.Object) at java.lang.Thread.run(Thread.java:745)
C:\Users\Administrator>jstack 10900 2019-04-30 17:26:40 Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.111-b14 mixed mode):
.... 略 .... 【检测到死锁】 Found one Java-level deadlock: ============================= "thread2": waiting to lock monitor 0x000000001ef45148 (object 0x000000076b345af0, a java.lang.Object), which is held by "thread1" "thread1": waiting to lock monitor 0x000000001cdb34b8 (object 0x000000076b345b00, a java.lang.Object), which is held by "thread2"
Java stack information for the threads listed above: =================================================== "thread2": at com.twodragonlake.jvm.memory.DeadLock$2.run(DeadLock.java:48) - waiting to lock <0x000000076b345af0> (a java.lang.Object) - locked <0x000000076b345b00> (a java.lang.Object) at java.lang.Thread.run(Thread.java:745) "thread1": at com.twodragonlake.jvm.memory.DeadLock$1.run(DeadLock.java:37) - waiting to lock <0x000000076b345b00> (a java.lang.Object) - locked <0x000000076b345af0> (a java.lang.Object) at java.lang.Thread.run(Thread.java:745)
C:\Users\Administrator>jhat e:dump.hprof Reading from e:dump.hprof... Dump file created Tue Apr 30 11:41:21 CST 2019 Snapshot read, resolving... Resolving 257676 objects... Chasing references, expect 51 dots................................................... Eliminating duplicate references................................................... Snapshot resolved. Started HTTP server on port 7000 Server is ready.
jhat启动了一个server,端口是7000,因此我们打开浏览器就能对齐进行访问看到我们要的结果。 打开http://127.0.0.1:7000/ ,单击【class com.twodragonlake.jvm.memory.MyTest5下边的信息 】就可以打开MyTest5下边的信息 【Execute Object Query Language (OQL) query】可以使用OQL查询各种类或者对象的信息,比如【 select s from java.lang.String s where s.value.length >= 100】