JVM Tuning Series: (v) JVM Common debugging parameters and tools

Source: Internet
Author: User
Tags gc overhead limit exceeded jconsole

Common debugging Parameters for the JVM:

–VERBOSE:GC display information on the output device when a memory collection occurs on a virtual machine

-xloggc:filename logging of GC-related log information to a file for analysis

-xx:-heapdumponoutofmemoryerror Export the relevant information in this heap when an oom is first encountered

-xx:onerror= "<cmdargs>;<cmd args>" after a fatal error running the custom command

-XX:-P rintclasshistogram The column information of the print class instance after Ctrl-break, same as Jmap-histo function

-XX:-P rintconcurrentlocks information about printing concurrent locks after ctrl-break, same as jstack-l function

-xx:-P RINTGC Printing related information per GC

-XX:-P rintgcdetails Print details per GC

-XX:-P rintgctimestamps Print timestamp for each GC

-xx:+printgcapplicationstoppedtime when a program is paused during a print garbage collection

-XX:+PRINTHEAPATGC detailed stack information before and after printing a GC

-xx:+printtenuringdistribution View the threshold for the new survival period after each minor GC, that is, the number of replications in the young generation survivor.

-xx:-traceclassloading Tracking class Loading information

-xx:-traceclassunloading The unload information of the tracking class

-xx:-traceloaderconstraints Tracking class loader constraints related information

-xx:errorfile=/opt/tomcat/bin/hs_error_%p.log Crash Log

[GC [defnew:209792k->4417k (235968K), 0.0201630 secs] 246722k->41347k (498112K), 0.0204050 secs]

Younggen Memory Area before recycling 209792K, after recycling 4417K, Younggen size is 235968K, heap memory area before the recovery 246722K, after recovery 41347K, the size of the heap is 498112K,GC The time consumed is 0.0204050 secs

[GC [1 cms-initial-mark:655374k (1310720K)] 662197K (1546688K), 0.0303050 secs] [times:user=0.02 sys=0.02, real=0.03 secs]

[Weak refs processing, 0.0417710 secs] [1 cms-remark:655734k (1310720K)] 766736K (1546688K), 0.0932010 secs] [times:user=0.17 sys=0.00, real=0.09 secs]

The Cms-initial-mark phase was paused for 0.0303050 seconds, while the Cms-remark phase was paused for 0.0932010 seconds, so the total time for two pauses was 0.123506 seconds.

Both fail causes full gc:prommotionfailed and concurrent mode failed:

[Parnew (Promotion failed): 320138k->320138k (353920K), 0.2365970 secs]

[cms:1458785k->1120688k (2520704K), 9.4584090 secs]

Prommotion failed because there is not enough space for rescue, so as to transfer objects to the elderly, old generation does not have enough space to accommodate these objects; Or the Laosheng generation of free space is fragmented, resulting in the absence of large enough contiguous space to store the Cenozoic pair, leading to a FULLGC generation. The solution to this problem has two completely opposite tendencies: to increase the space for salvation and to increase the age generation . Adjust-xx:survivorratio parameters

Concurrent mode failed is due to the recovery of the old age of the CMS is too slow, resulting in the old generation in the CMS before the completion of being stained, causing the full GC, to avoid this phenomenon is to adjust the small -xx: the value of the Cmsinitiatingoccupancyfraction parameter.

Java.lang.OutOfMemoryError:GC Overhead limit exceeded:

JDK6 the newly added error type. is a protection mechanism that occurs when a GC takes up a large amount of time to free up a small space. The solution is to turn off the feature and use-xx:-usegcoverheadlimit. You need to see if you have code or a dead loop that uses large memory.

Common Debugging Tools for JVMs:

jconsole– Jconsole is a real-time graphical monitoring tool based on Javamanagementextensions (JMX), This tool leverages the JMX instructions built into the JVM to provide real-time performance and resource monitoring, including memory usage for Java programs, Heap size, thread state, class allocation State and space usage, and more. The following environment variables are set under Linux: Export display=:0.0

jstatd– Start the JVM monitoring service. It is an RMI-based application that provides information about native JVM applications to remote machines. Default Port 1099.

-nr When an existing RMI Registry is not found, no attempt is made to create an internal RMI Registry

- p Port port number, default = 1099

-nrminame defaults to jstatremotehost; If multiple JSTATD services start on the same host, Rminame uniquely identifies a JSTATD service

-j JVM Options

Add the following code $JAVA the _home/jre/lib/security/java.policy file:

Grantcodebase "file:${java.home}/. /lib/tools.jar "{

Permission java.security.AllPermission;

};

The default port is 1099:jstatd-j-djava.security.policy=jstatd.all.policy

Specify hostname specified port: jstatd-j-djava.rmi.server.hostname=192.168.8.7-j-djava.security.policy=test/jstatd.all.policy-p 6001

Start Jmx:jstatd-j-djava.rmi.server.hostname=192.168.8.7-j-djava.security.policy=test/jstatd.all.policy- J-dcom.sun.management.jmxremote.port=6001-j-dcom.sun.management.jmxremote.ssl= False-j-dcom.sun.management.jmxremote.authenticate=false-j-djava.awt.headless=true

(java.net.MalformedURLException:Local host name Unknown:java.net.unknownhostexception:a: a

The reason is that there is no host name in the/etc/hosts file: A, the workaround is to include a in the Hosts file:

127.0.0.1 a localhost)

jps–JPS is used to look at the specific state of all the processes within the JVM, including the process ID, path of process initiation, and so on.

The-m output is passed to the main method parameter, and if it is an inline JVM, the output is null.

-L OUTPUT The full package name of the application main class, or the full path to the application jar file.

-V output passed to the JVM parameters.

Jstack- jstack is used to print out the Java stack information for a given Java process ID or core file or remote Debugging service, if it is on a 64-bit machine, you need to specify the option "-J-D64" If the Java program crashes to generate a core file, The Jstack tool can be used to obtain the Java stack and nativestack information for the core file. Windows Jstack only supports-L.

- F when ' jstack [-l] PID ' does not have a corresponding time to force the printing stack information

- l long list. Prints additional information about the lock, such as the ownable synchronizers list belonging to Java.util.concurrent.

- m prints all of the stack information for Java and Native/C + + frameworks.

JSTACKPID displays the current status of all threads in the JVM and the current thread

Jinfo – You can output and modify the opts of the Java process at runtime. Useful for outputting Java system parameters and command-line parameters. View and modify the running environment parameters of a running Java program.

Jinfo-flag MaxPermSize 4084

jmap–Jmap can get a specific memory match from the core file or process, including the heap size, Perm size, and so on, to print out the case of a Java process (using PID) in memory, all ' objects '.

-heap : Printing JVM Heap
-histo: Prints the histogram of the JVM heap. Its output information includes the class name, the number of objects, and the size of the object.
-histo:live: same as above, but only if the surviving object is output, the full GC will be triggered

-permstat: print permanentgeneration heap condition

Jmap-dump:format=b,file=outfile 3024 can output the 3024 process memory heap out to the outfile file, and then with the jhat for analysis.

Jhat , a tool for offline analysis of Java heap, can analyze the heap information files exported from different virtual machines, such as files exported on Linux that can be analyzed on Windows

jhat-j-xmx512m

jstat– Jstat leverages the JVM's built-in instructions for real-time command line monitoring of Java application resources and performance, and can observe CLASSLOADER,COMPILER,GC related information, including the heap Monitoring of size and garbage collection status, and so on.

-class: Statistics class loader behavior information
-compile: Statistical compilation Behavior Information
-GC: Statistics on JDK GC time heap information
-gccapacity: Statistics of different generations (do not know how to translate well, including the new district, old age area, Permanent district) corresponding heap capacity situation
-gccause: Statistical GC case, (same as-gcutil) and event that caused GC
-gcnew: When statistics GC, the Cenozoic situation
-gcnewcapacity: When statistics GC, the Cenozoic heap capacity
-gcold: Statistics GC, the situation of the elderly area
-gcoldcapacity: When statistics GC, the old area heap capacity
-gcpermcapacity: When statistics GC, permanent area heap capacity
-gcutil: When statistics GC, heap condition

-compiler: Displays information such as the number of real-time VMS compiled

-snap: View the values of each monitor of the Java process's Jvmstat

JSTAT-GC [email protected]

Java-verbose:class PID outputs information about the classes that the virtual machine loads, and when the virtual machine reports that the class cannot find or class conflicts, this parameter can be used to diagnose the condition in which the virtual machine loads the class.

Java–verbose:jni output native method invocation, typically used to diagnose JNI call error messages

Common JVM analysis information gets:

1, confirm the existence of Sun JDK6 on the server, if there is no suggestion to install one, we need to use the tools inside (JPS, Jmap, Jstat, Jconsole, Jstack)

2. Get mkey Java Process ID (hereafter referred to as PID)

A) How to: Enter JPS on the command line in the bin directory of the Sun JDK to view the process ID of the Mkey

3. Extracting GC information ()

A) How-to: Example: Jstat–gcpid 600000 43200 >> gc_20110909.log

4. Extract the heap area information (10 minutes interval)

A) Operating method: Jmap-heap PID >>heap_20110909.log

5, extract the object information (interval 10 minutes to extract one time)

A) Operating method: Jmap-histo PID > Histo_*.log (large file, * generate input by serial number)

6, Thread dump log

A) Jstack PID

b) down log (in the domain directory, if there is no downtime, the kill-3 PID can be used if conditions permit (this action kills the process))

Lite version:

After the server hangs, execute the following command before restarting:

JPS-VL query to the corresponding Java process, referred to as PID

Jstat–gcutilpid >>/opt/tomcat/bin/gcutil.log

Vmstat3

Jstackpid >/opt/tomcat/bin/jstack.log

Jmap-histo PID >/opt/tomcat/bin/histo.log

Network aspects:

Whiletrue; Do a=$ (netstat-n | awk '/^tcp/{++s[$NF]} END {for (A in S) print A,s[a]} '); Echo $A; Sleep 3; Done

Netstat-an | grep1521

Restart the service. Extract the relevant logs to send

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

JVM Tuning Series: (v) JVM Common debugging parameters and tools

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.