1 JDK8 uses jcmd instead of jstack
, jinfo
, and tools in previous versionsjmap
2JMC diagnosis, JMC is composed of JMX, JFR and several other downloadable function plug-ins, among which:
a.JMX plays the role of monitoring and management. Can connect to running jvm, can collect and display some key properties in real time
b. JFR performance analysis
c. In the jdk8 environment, user-defined behaviors and rules can be triggered
d. Other plugins of JMC such as: - WLS, DTrace [similar to JFR], JOverflow [analyze heap situation]
Program additional parameters -XX:+UnlockCommercialFeatures -XX:+FlightRecorder
3 JFR has 2 recording schemes
I use Continuous Recordings without much performance impact on the application. But there is no heap statistics or allocation profiling related information, very useful for debugging rare errors.
II Using Profiling Recordings, you will get a lot of useful information, which will have a greater impact on the application, even up to 2% of the impact, mainly used in the following three aspects
a Analyze large object creation and method calls
b Find classes that use more and more memory , possibly leading to memory leaks. That is, classes that cannot properly reclaim memory
c Find performance bottlenecks like synchronized
4 There are three ways to start JFR
I Start a profiling recording
java -XX:+UnlockCommercialFeatures -XX:+FlightRecorder -XX:StartFlightRecording=delay=20s,duration=60s,name=myrecording,filename=C:\TEMP\myrecording.jfr,settings=profile MyApp
II Start a continuous recording
java -XX:+UnlockCommercialFeatures -XX:+FlightRecorder -XX:FlightRecorderOptions=default recording=true,disk=true,repository=/tmp,maxage=6h,settings=default MyApp
III Start with JCMD Utility
jcmd pid help
jcmd pid JFR.start name=MyRecording settings=profile delay=20s duration=2m filename=C:\TEMP\myrecording.jfr
5 Native Memory Tracking
I 应用设置 -XX:NativeMemoryTracking=summary or -XX:NativeMemoryTracking=detail
II jcmd <pid> VM.native_memory summary or
jcmd <pid> VM.native_memory detail
.
III jcmd <pid> VM.native_memory baseline
jcmd <pid> VM.native_memory summary.diff or jcmd <pid> VM.native_memory detail.diff
6 java -agentlib:hprof=help
I Performance Analysis of a Single Class
java -agentlib:hprof=heap=sites ToBeProfiledClass
javac -J-agentlib:hprof=heap=sites ToBeProfiledJAVA [partial performance]
II is configured to run as a whole project
-agentlib:hprof=heap=dump,cpu=samples,format=b
For example, export the following file: java.hprof
7 Jhat tool usage
start jhat java.hprof
8 jstat tool
jstat -help / jstat -options
Such as: jstat -gcutil pid 1s 10
9 jconsole remote configuration
-Djava.rmi.server.hostname=192.168.2.3
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=9999
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
10 Detect Deadlocks
Add parameter -XX:+PrintConcurrentLocks
heap summary:-XX:+PrintClassHistogram print out details