Preface
This article mainly introduces the fault handling tools of Java virtual machines. These tools mentioned in the article include:
| name | Main functions |
| jps | JVM process Status Tool, displays all HotSpot virtual machine processes in the specified system. Usually local host |
| jstat | JVM Statistics Monitoring Tool, used to collect operating data of all aspects of HotSpot virtual machine |
| jinfo | Configuration Info for java, display virtual machine configuration information |
| jmap | Memory Map for Java, generates a virtual machine's memory storage snapshot (heapdump file) |
| jhat | JVM Heap Dump Browser, is used to analyze heapdump files. It establishes an HTTP/HTML server, allowing users to view analysis results on the browser. |
| jstack | Stack Trace for Java, displays thread snapshots of virtual machines |
jps: Virtual machine process status tool
The function of jps is similar to the ps command in unix/liunx. It's just that it prints out the running virtual machine process and displays the name of the virtual machine execution main class and the local virtual machine unique ID of these processes (Local Virtual Machine Identifier, LVMID, usually the system process ID).
jps command format:
jps [options] [hostId]
jps can query the remote virtual machine process status of the RMI service through the RMI protocol, and hostId is the host name registered in the RMI registry.
jps other common options:
-q Only output LVMID, omitting the name of the main class;
-m Output parameters passed to the main() function of the main class when the virtual machine process is started;
-l Output the full name of the main class. If the process executes a jar package, output the jar path;
-v Output JVM parameters when virtual machine process starts.
jps command sample:
[root@localhost ~]# jps -l3914 org.zhangyoubao.payservice.App12180 sun.tools.jps.Jps6913 org.zhangyoubao.userprofiler.App
jstat: Virtual machine statistics monitoring tool
jstat is a tool used to monitor various operating status information of virtual machines. It can display running parameters such as class load, memory gc.jit in local or remote virtual machine processes.
jstat command format:
jstat [option vmid [interval [s|ms] [count]]]
interval and count represent query intervals and times. If these two parameters are omitted, it means that only query once.
Other commonly used options for jstat:
-class Monitor the number of load/unloads of class and the total space loading time;
-compiler outputs methods, time-consuming and other information compiled by the JIT compiler;
-printcompilation The method that outputs a JIT compiled method;
-gc monitors the status of the java heap;
-gccapacity The monitoring content is basically the same as -gc, but the output focuses on the maximum/minimum space of each area of Java;
-gcutil The monitoring content is basically the same as -gc, but the output focuses on the use of space occupies 100%;
-gccause Like the -gcutil function, the additional output causes the last GC;
-gcnew Monitors the status of the new generation of GCs;
-gcnewcapacity monitors the new generation and outputs the same as -gccapacity;
-gcold Monitors GC status in the elderly;
-gcoldcapacity Monitors the elderly and outputs the same as -gccapacity;
-gcpermcapactiy Monitors permanent generation (code area), outputs the same as -gccapacity;
jstat command sample:
[root@localhost ~]# jstat -gc 6913 S0C S1C S0U S1U EC EU OC OU PC PU YGC YGCT FGC FGCT GCT 34048.0 34048.0 0.0 3217.8 272640.0 171092.7 683264.0 168910.7 46872.0 28031.2 37857 380.644 69 3.447 384.091
jinfo:Java configuration information tool
The function of jinfo is to view and adjust various parameters of the virtual machine in real time.
jinfo command format:
jinfo [option] pid
Other commonly used options for jinfo:
-flag name=value Modify parameters
-flag name parameter parameter
Sample jinfo command:
[root@localhost ~]# jinfo 6913Attaching to process ID 6913, please wait...Debugger attached successfully.Server compiler detected.JVM version is 24.91-b01Java System Properties:...VM Flags:-Xms1000m -Xmx1000m -Dconf=/usr/local/user_profiler/conf -Dserver.root=/usr/local/user_profiler -Dcom.sun.management.jmxremote.port=7003 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+UseConcMarkSweepGC
jmap:java memory mapping tool
The jmap command can be used to produce heap storage snapshots (dump files). It can also check the details of finalize queue (self-save queue), Java heap and code area.
jmap command format:
jmap [option] vmid
Other commonly used options for jmap:
-dump generates a snapshot of the java heap storage. Format: -dump:[live,]format=b,file=<filename>;
-finalizerinfo Displays an object in F-Queue that is waiting for the Finalizer phenomenon to execute the finalize method;
-heap Displays the detailed information of the java heap, such as which type of recycler is used, parameter configuration, generational status waiting;
-histo Displays statistics of objects in the heap, including classes, instance books, and total capacity;
-permstat Use ClassLoader as the statistical portal to display permanent generation memory information;
-F When the virtual machine process heap-dump option does not respond, you can use this option to force a dump snapshot.
jmap command sample:
[root@localhost ~]# jmap -histo 6913|head -20 num #instances #bytes class name---------------------------------------------- 1: 1864966 113459432 [C 2: 201846 49201192 [B 3: 1597065 38329560 java.lang.String 4: 117477 15037056 org.zhangyoubao.thriftdef.UserUsefulInfo 5: 47104 11072048 [I 6: 268631 8596192 java.util.HashMap$Entry 7: 48812 7451760 <constMethodKlass> 8: 100683 6443712 com.mysql.jdbc.ConnectionPropertiesImpl$BooleanConnectionProperty 9: 48812 6257856 <methodKlass> 10: 4230 5271640 <constantPoolKlass> 11: 159491 5103712 java.util.Hashtable$Entry 12: 120226 4809040 org.zhangyoubao.common.cache.adv.Node 13: 127027 4064864 java.util.concurrent.ConcurrentHashMap$HashEntry 14: 230433 3686928 java.lang.Integer 15: 3765 3049824 <constantPoolCacheKlass> 16: 20917 3012048 com.mysql.jdbc.Field 17: 4230 2943840 <instanceKlassKlass>
where [C=char[],[B=byte[],[S=short[],[I=int[],[[I=int[][] .
jhat: Virtual machine heap transfer snapshot analysis tool
The jhat command is used in conjunction with jmap and is used to analyze dump files generated by jmap. jhat has a built-in mini HTTP/HTML server. After the analysis results of the generated dump file can be viewed in the browser.
jhat command format:
jmap filename
jhat command sample:
[root@localhost ~]# jhat html_intercept_server.dump Reading from html_intercept_server.dump...Dump file created Wed Nov 23 13:05:33 CST 2016Snapshot read, resolving...Resolving 203681 objects...Chasing references, expect 40 dots..................Eliminating duplicate references.............Snapshot resolved.Started HTTP server on port 7000Server is ready.
jstack:java thread stack trace tool
jstack is used to generate a thread snapshot of the current time of the virtual machine. Thread snapshots are the method stack plan that each thread of the current virtual machine is executing. The main purpose of generating thread snapshots is to locate the reasons why the thread is paused for a long time. When the thread pauses, use jstack to see what unresponsive threads do in the background or what resources are waiting for.
jstack command format:
jstack [option] vmid
jstack other options:
-F When the normally output request is not responded, force the thread stack to be output;
-l Display additional information about the lock in addition to displaying the stack;
-m If a local method is called, the stack of C/C++ can be displayed.
jstack command sample:
[root@localhost ~]# jstack 29577|head -202016-11-23 12:58:23Full thread dump OpenJDK Server VM (24.91-b01 mixed mode):"pool-1-thread-7261" prio=10 tid=0x0893a400 nid=0x6b0d waiting on condition [0x652ad000] java.lang.Thread.State: TIMED_WAITING (parking) at sun.misc.Unsafe.park(Native Method) - parking to wait for <0x75b5b400> (a java.util.concurrent.SynchronousQueue$TransferStack) at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:226) at java.util.concurrent.SynchronousQueue$TransferStack.awaitFulfill(SynchronousQueue.java:460) at java.util.concurrent.SynchronousQueue$TransferStack.transfer(SynchronousQueue.java:359) at java.util.concurrent.SynchronousQueue.poll(SynchronousQueue.java:942) at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1068) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:745)"service_hot_lscs-0" daemon prio=10 tid=0x6982dc00 nid=0x6aeb waiting on condition [0x64ce1000] java.lang.Thread.State: TIMED_WAITING (sleeping) at java.lang.Thread.sleep(Native Method) at org.zhangyoubao.video.client.runner.SimpleVideoRunner.doWork(SimpleVideoRunner.java:150)
Summarize
The above is the entire content of this article. I hope the content of this article will be of some help to your study or work. If you have any questions, you can leave a message to communicate.