Download - Jdk Tools For Performance Diagnostics
![Page 1: Jdk Tools For Performance Diagnostics](https://reader035.vdocuments.net/reader035/viewer/2022081414/54b73df04a7959404e8b47d6/html5/thumbnails/1.jpg)
JDK tools for performance diagnostics
Dror Bereznitsky
Director of Technologies, AlphaCSP
![Page 2: Jdk Tools For Performance Diagnostics](https://reader035.vdocuments.net/reader035/viewer/2022081414/54b73df04a7959404e8b47d6/html5/thumbnails/2.jpg)
2
Introduction
Application to slow ?
Image courtesy of WTL photos - flickr
![Page 3: Jdk Tools For Performance Diagnostics](https://reader035.vdocuments.net/reader035/viewer/2022081414/54b73df04a7959404e8b47d6/html5/thumbnails/3.jpg)
3
Introduction
Leaking Memory
?
Image courtesy of neoliminal- flickr
![Page 4: Jdk Tools For Performance Diagnostics](https://reader035.vdocuments.net/reader035/viewer/2022081414/54b73df04a7959404e8b47d6/html5/thumbnails/4.jpg)
4
Intoduction
Suffering from deadlocks?
Image courtesy of hfb - flickr
![Page 5: Jdk Tools For Performance Diagnostics](https://reader035.vdocuments.net/reader035/viewer/2022081414/54b73df04a7959404e8b47d6/html5/thumbnails/5.jpg)
5
Introduction
The JDK has tools that can help you …
Image courtesy of docman - flickr
![Page 6: Jdk Tools For Performance Diagnostics](https://reader035.vdocuments.net/reader035/viewer/2022081414/54b73df04a7959404e8b47d6/html5/thumbnails/6.jpg)
6
JDK tools for performance diag.
Image courtesy of dodgechallenger1 - flickr
• JDK tools for performance diagnostics:
VisualVM BTrace jhat jmap
jconsole jstat jinfo jps jstack
![Page 7: Jdk Tools For Performance Diagnostics](https://reader035.vdocuments.net/reader035/viewer/2022081414/54b73df04a7959404e8b47d6/html5/thumbnails/7.jpg)
7
VisualVM
![Page 8: Jdk Tools For Performance Diagnostics](https://reader035.vdocuments.net/reader035/viewer/2022081414/54b73df04a7959404e8b47d6/html5/thumbnails/8.jpg)
8
VisualVM
• Java troubleshooting tool• Visual tool integrating several
command line JDK tools and much more
• For development and production time
![Page 9: Jdk Tools For Performance Diagnostics](https://reader035.vdocuments.net/reader035/viewer/2022081414/54b73df04a7959404e8b47d6/html5/thumbnails/9.jpg)
9
VisualVM Features
• Display local/remote Java applications
• Monitor memory and threads• Take and browse heap +
thread dumps• Extensible with plugins• Attach API or JMX
![Page 10: Jdk Tools For Performance Diagnostics](https://reader035.vdocuments.net/reader035/viewer/2022081414/54b73df04a7959404e8b47d6/html5/thumbnails/10.jpg)
10
• MBean browser• Visual GC• Memory sampler• Profiler – CPU, Memory• BTrace plugin• Direct buffers monitor (JDK 7)• Many more …
VisualVM Plugins
![Page 11: Jdk Tools For Performance Diagnostics](https://reader035.vdocuments.net/reader035/viewer/2022081414/54b73df04a7959404e8b47d6/html5/thumbnails/11.jpg)
11
VisualVM Feature Matrix
JDK 1.4.2JDK 5JDK 6Local
JDK 6Remote
Overview
System properties
Monitor
Threads
Profiler
Thread Dump
Heap Dump
Heam Dump OOME
MBean Browser
JConsole plugins
![Page 12: Jdk Tools For Performance Diagnostics](https://reader035.vdocuments.net/reader035/viewer/2022081414/54b73df04a7959404e8b47d6/html5/thumbnails/12.jpg)
12
Supported VMs
Java VMRemarks
Sun JDK
Open JDK
Apple JDK
Oracle JRockit
IBM J9Using JMX only
HP-UX JDK
SAP JDK Requires the VisualVM Extensions plugin
![Page 13: Jdk Tools For Performance Diagnostics](https://reader035.vdocuments.net/reader035/viewer/2022081414/54b73df04a7959404e8b47d6/html5/thumbnails/13.jpg)
13
Getting Started
• Version 1.0 ships with JDK6 since update 7• Look for jvisualvm in your JDK bin directory
• Version 1.1.1 now ships with JDK6 update 14
• Latest version can be downloaded from https://visualvm.dev.java.net
![Page 14: Jdk Tools For Performance Diagnostics](https://reader035.vdocuments.net/reader035/viewer/2022081414/54b73df04a7959404e8b47d6/html5/thumbnails/14.jpg)
14
The Demo Application
![Page 15: Jdk Tools For Performance Diagnostics](https://reader035.vdocuments.net/reader035/viewer/2022081414/54b73df04a7959404e8b47d6/html5/thumbnails/15.jpg)
15
VisualVM Demo
VisualVM Demo
![Page 16: Jdk Tools For Performance Diagnostics](https://reader035.vdocuments.net/reader035/viewer/2022081414/54b73df04a7959404e8b47d6/html5/thumbnails/16.jpg)
16
Working With Remote Applications
• Start a jstatd daemon on the remote host• Allow remote monitoring tools to attach
to running JVMs• May have security implications
• Add the remote host to the ‘Remote’ node in the Applications window
![Page 17: Jdk Tools For Performance Diagnostics](https://reader035.vdocuments.net/reader035/viewer/2022081414/54b73df04a7959404e8b47d6/html5/thumbnails/17.jpg)
17
Extending VisualVM
What is VisualVM, really?Generic desktop application
infrastructure for analyzing sources of data.
Default data sources• Applications• Hosts• Dumps• Snapshots
![Page 18: Jdk Tools For Performance Diagnostics](https://reader035.vdocuments.net/reader035/viewer/2022081414/54b73df04a7959404e8b47d6/html5/thumbnails/18.jpg)
18
Extending VisualVM
• Why you would want to extend VisualVM:• Tool-Centric
You have a monitoring or management tool that you want to make available to VisualVM• BTrace plugin
• Application-Centric You have an application with specific monitoring/management needs• Glassfish plugin
![Page 19: Jdk Tools For Performance Diagnostics](https://reader035.vdocuments.net/reader035/viewer/2022081414/54b73df04a7959404e8b47d6/html5/thumbnails/19.jpg)
19
Extending VisualVM
• What Can You Create?• Tabs: Main tabs, Sub tabs
• Actions: Menu items, Toolbar buttons
• Application Types
• Data Sources
![Page 20: Jdk Tools For Performance Diagnostics](https://reader035.vdocuments.net/reader035/viewer/2022081414/54b73df04a7959404e8b47d6/html5/thumbnails/20.jpg)
20
Getting Started With Extending VisualVM
• Install JDK 6• Read VisualVM API Javadoc &
Tutorials• Create VisualVM modules
• Netbeans IDE
• VisualVM samples collection
![Page 21: Jdk Tools For Performance Diagnostics](https://reader035.vdocuments.net/reader035/viewer/2022081414/54b73df04a7959404e8b47d6/html5/thumbnails/21.jpg)
21
VisualVM Usage Scenarios
• General health monitoring• Diagnose specific problems
• Memory leaks• Deadlocks• Excessive use of finalizers• Hot lock contention• Hung process
![Page 22: Jdk Tools For Performance Diagnostics](https://reader035.vdocuments.net/reader035/viewer/2022081414/54b73df04a7959404e8b47d6/html5/thumbnails/22.jpg)
22
BTrace
![Page 23: Jdk Tools For Performance Diagnostics](https://reader035.vdocuments.net/reader035/viewer/2022081414/54b73df04a7959404e8b47d6/html5/thumbnails/23.jpg)
23
BTrace
• Dynamic tracing tool for the Java platform
• Safe – read, no write• Low-overhead • Tracing code is written in Java• Available as a VisualVM plugin or
as a command line tool
![Page 24: Jdk Tools For Performance Diagnostics](https://reader035.vdocuments.net/reader035/viewer/2022081414/54b73df04a7959404e8b47d6/html5/thumbnails/24.jpg)
24
Dynamic Tracing
• Works by dynamically instrumenting classes of a running Java program – using ASM 3.0• ASM is an all purpose Java bytecode
manipulation and analysis framework
• Inserts tracing actions by hot-swapping the traced program classes
![Page 25: Jdk Tools For Performance Diagnostics](https://reader035.vdocuments.net/reader035/viewer/2022081414/54b73df04a7959404e8b47d6/html5/thumbnails/25.jpg)
25
BTrace HelloWorld Example
import com.sun.btrace.annotations.*; import static com.sun.btrace.BTraceUtils.*;@BTrace public class HelloWorld {
@OnMethod( clazz="java.lang.Thread", method="start"
) public static void func() {
println("about to start a thread!"); }
}
![Page 26: Jdk Tools For Performance Diagnostics](https://reader035.vdocuments.net/reader035/viewer/2022081414/54b73df04a7959404e8b47d6/html5/thumbnails/26.jpg)
26
BTrace Terminology
• Probe Point• "location" or "event" at which a set of tracing
statements are executed.
• Trace Actions/Actions• Trace statements that are executed whenever
a probe "fires".
• Action Methods• Trace statements that are executed when a
probe fires • defined inside a static method• Such methods are called "action" methods.
![Page 27: Jdk Tools For Performance Diagnostics](https://reader035.vdocuments.net/reader035/viewer/2022081414/54b73df04a7959404e8b47d6/html5/thumbnails/27.jpg)
27
BTrace HelloWorld Example
import com.sun.btrace.annotations.*; import static com.sun.btrace.BTraceUtils.*;@BTrace public class HelloWorld {
@OnMethod( clazz="java.lang.Thread", method="start"
) public static void func() {
println("about to start a thread!"); }
}
Probe Point
Action Method
![Page 28: Jdk Tools For Performance Diagnostics](https://reader035.vdocuments.net/reader035/viewer/2022081414/54b73df04a7959404e8b47d6/html5/thumbnails/28.jpg)
28
Some BTrace Annotations
• @OnMethod• Specify target class(es), target
method(s) and "location(s)" within the method(s)
• @OnLowMemory• Trace memory threshold exceed event
• @OnTimer• Specify tracing actions that have to run
periodically once every N milliseconds
![Page 29: Jdk Tools For Performance Diagnostics](https://reader035.vdocuments.net/reader035/viewer/2022081414/54b73df04a7959404e8b47d6/html5/thumbnails/29.jpg)
29
• can not create new objects. • can not create new arrays. • can not throw exceptions. • can not catch exceptions.• can not have loops (for, while,
do..while)• Almost everything is restricted …
?BTrace Restrictions
![Page 30: Jdk Tools For Performance Diagnostics](https://reader035.vdocuments.net/reader035/viewer/2022081414/54b73df04a7959404e8b47d6/html5/thumbnails/30.jpg)
30
com.sun.btrace.BTraceUtils
• Contains 270 public static methods which may be called from a BTrace script
• Many useful methods:• deadlocks - prints the Java level
deadlocks detected (if any)• dumpHeap - dump the snapshot of the
Java heap• jstack - Prints the java stack trace of
the current thread
![Page 31: Jdk Tools For Performance Diagnostics](https://reader035.vdocuments.net/reader035/viewer/2022081414/54b73df04a7959404e8b47d6/html5/thumbnails/31.jpg)
31
Getting Started
• BTrace is available as a VisualVM plugin• Requires VisualVM 1.0.1+• Available at the BTrace plugin center -
https://btrace.dev.java.net/uc/updates.xml
![Page 32: Jdk Tools For Performance Diagnostics](https://reader035.vdocuments.net/reader035/viewer/2022081414/54b73df04a7959404e8b47d6/html5/thumbnails/32.jpg)
32
BTrace Demo
Demo
![Page 33: Jdk Tools For Performance Diagnostics](https://reader035.vdocuments.net/reader035/viewer/2022081414/54b73df04a7959404e8b47d6/html5/thumbnails/33.jpg)
33
BTrace Demo Source
@BTracepublic class SizeOfStatusCache {
@OnMethod( clazz = "com.alphacsp.performance.seminar.twitter.Main", method = "pollForNewStatuses", location = @Location(Kind.RETURN))
public static void onNewStatuses(Object obj) { List statusCache =
(List) get(field(classOf(obj), "statusCache", true), obj);
println(concat("Number of cached statuses: ",str(size(statusCache))));
}
}
![Page 34: Jdk Tools For Performance Diagnostics](https://reader035.vdocuments.net/reader035/viewer/2022081414/54b73df04a7959404e8b47d6/html5/thumbnails/34.jpg)
34
BTrace Usage Scenarios
• Fine grained performance analysis
• Runtime profiling and monitoring• Collecting statistics• When no graphic user interface
available
![Page 35: Jdk Tools For Performance Diagnostics](https://reader035.vdocuments.net/reader035/viewer/2022081414/54b73df04a7959404e8b47d6/html5/thumbnails/35.jpg)
35
jhat
jhat
![Page 36: Jdk Tools For Performance Diagnostics](https://reader035.vdocuments.net/reader035/viewer/2022081414/54b73df04a7959404e8b47d6/html5/thumbnails/36.jpg)
36
jhat
• Java Heap Analysis Tool• Parses a java heap dump and
launches a web server • Basic web interface for browsing
the heap dump• Useful for analyzing memory
leaks
![Page 37: Jdk Tools For Performance Diagnostics](https://reader035.vdocuments.net/reader035/viewer/2022081414/54b73df04a7959404e8b47d6/html5/thumbnails/37.jpg)
37
jhat Features
• View all class instances• View class classloader• View all references to an object• View reference chains from
Rootset• Use OQL (Object Query Language)
to query heap dumps
![Page 38: Jdk Tools For Performance Diagnostics](https://reader035.vdocuments.net/reader035/viewer/2022081414/54b73df04a7959404e8b47d6/html5/thumbnails/38.jpg)
38
OQL
• SQL-like query language to query Java heap
• Based on JavaScript expression language
• Built-in objects and functions• OQL help is available from the
jhat OQL screen
![Page 39: Jdk Tools For Performance Diagnostics](https://reader035.vdocuments.net/reader035/viewer/2022081414/54b73df04a7959404e8b47d6/html5/thumbnails/39.jpg)
39
Getting Started
C:\jdk1.6.0_13\bin>jhat -J-mx512m c:\heapdump-1245057502890.hprof
Reading from c:\heapdump-1245057502890.hprof...Dump file created Mon Jun 15 12:18:22 IDT 2009Snapshot read, resolving...Resolving 120908 objects...Chasing references, expect 24
dots........................Eliminating duplicate
references........................Snapshot resolved.Started HTTP server on port 7000Server is ready.
![Page 40: Jdk Tools For Performance Diagnostics](https://reader035.vdocuments.net/reader035/viewer/2022081414/54b73df04a7959404e8b47d6/html5/thumbnails/40.jpg)
40
jhat demo
jhat Demo
![Page 41: Jdk Tools For Performance Diagnostics](https://reader035.vdocuments.net/reader035/viewer/2022081414/54b73df04a7959404e8b47d6/html5/thumbnails/41.jpg)
41
jhat Usage Scenarios
• When analyzing large heap dumps – can use a remote powerful server
• When you do not have a graphic user interface
• If you want to perform smart queries on heap content
![Page 42: Jdk Tools For Performance Diagnostics](https://reader035.vdocuments.net/reader035/viewer/2022081414/54b73df04a7959404e8b47d6/html5/thumbnails/42.jpg)
42
Summary
Summary
![Page 43: Jdk Tools For Performance Diagnostics](https://reader035.vdocuments.net/reader035/viewer/2022081414/54b73df04a7959404e8b47d6/html5/thumbnails/43.jpg)
43
Summary
• The JDK contains useful performance diagnostics tools
• These tools can be used for detecting, analyzing and solving performance related issues
![Page 44: Jdk Tools For Performance Diagnostics](https://reader035.vdocuments.net/reader035/viewer/2022081414/54b73df04a7959404e8b47d6/html5/thumbnails/44.jpg)
44
References
• Monitoring and Troubleshooting Java applications using JDK tools (PDF)
• VisualVM• VisualVM Sample Collection• TS-4247 Getting More Out of the Java
VisualVM Tool (PDF)• btrace• ASM• jhat
![Page 45: Jdk Tools For Performance Diagnostics](https://reader035.vdocuments.net/reader035/viewer/2022081414/54b73df04a7959404e8b47d6/html5/thumbnails/45.jpg)
45
Thank You