Your SlideShare is downloading. ×
0
Javaday2010 - Jvm Power Tools - What is my JVM doing?
Javaday2010 - Jvm Power Tools - What is my JVM doing?
Javaday2010 - Jvm Power Tools - What is my JVM doing?
Javaday2010 - Jvm Power Tools - What is my JVM doing?
Javaday2010 - Jvm Power Tools - What is my JVM doing?
Javaday2010 - Jvm Power Tools - What is my JVM doing?
Javaday2010 - Jvm Power Tools - What is my JVM doing?
Javaday2010 - Jvm Power Tools - What is my JVM doing?
Javaday2010 - Jvm Power Tools - What is my JVM doing?
Javaday2010 - Jvm Power Tools - What is my JVM doing?
Javaday2010 - Jvm Power Tools - What is my JVM doing?
Javaday2010 - Jvm Power Tools - What is my JVM doing?
Javaday2010 - Jvm Power Tools - What is my JVM doing?
Javaday2010 - Jvm Power Tools - What is my JVM doing?
Javaday2010 - Jvm Power Tools - What is my JVM doing?
Javaday2010 - Jvm Power Tools - What is my JVM doing?
Javaday2010 - Jvm Power Tools - What is my JVM doing?
Javaday2010 - Jvm Power Tools - What is my JVM doing?
Javaday2010 - Jvm Power Tools - What is my JVM doing?
Javaday2010 - Jvm Power Tools - What is my JVM doing?
Javaday2010 - Jvm Power Tools - What is my JVM doing?
Javaday2010 - Jvm Power Tools - What is my JVM doing?
Javaday2010 - Jvm Power Tools - What is my JVM doing?
Javaday2010 - Jvm Power Tools - What is my JVM doing?
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Javaday2010 - Jvm Power Tools - What is my JVM doing?

4,610

Published on

We are so used to Java that we often forget what's required behind the scenes to give us robustness, security, platform independence, performance, rich APIs and commercial/open source …

We are so used to Java that we often forget what's required behind the scenes to give us robustness, security, platform independence, performance, rich APIs and commercial/open source ecosystem.

But it is interesting (and sometimes necessary) to get a deeper look at what's happening behind the scenes... The JVM gives us powerful tools to monitor, debug, tune & troubleshoot its internal mechanisms, including the Garbage Collector and dynamic Just in Time compiler

Published in: Technology
0 Comments
18 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
4,610
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
226
Comments
0
Likes
18
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Managing & Tuning JDK monitoring & management power tools: what is my Java Virtual Machine doing? Carlo Bonamico - NIS s.r.l. / JUG Genova carlo.bonamico@nispro.it Carlo Bonamico - carlo.bonamico@nispro.it - JUG Genova Javaday IV – Roma – 30 gennaio 2010
  • 2. We are so used to Java... ● That we often forget what's required behind the scenes to give us  robustness and security  platform independence – linux/windows/solaris/you name it... – 32/64 bit  performance – with significant increases at every JVM release (think 1.6 vs 1.5) – benefit to existing code with NO changes  manageability  rich APIs and commercial/open source ecosystem ● But it is interesting (and sometimes necessary) to get a deeper look at what's happening behind the scenes... Carlo Bonamico - carlo.bonamico@nispro.it - JUG Genova Javaday IV – Roma – 30 gennaio 2010
  • 3. The good news ● is that the JVM lets us (almost) forget about memory management, code compilation and optimization ● The better news is that it also gives us powerful tools to  monitor  debug  tune  troubleshoot ● Its internal mechanisms  including the Garbage Collector and dynamic Just in Time compiler Carlo Bonamico - carlo.bonamico@nispro.it - JUG Genova Javaday IV – Roma – 30 gennaio 2010
  • 4. We will learn how to... ● find active JVMs with jps ● anaylze memory consumption and garbage collection behavior with jstat ● get an overview of VM activities with jconsole ● analyze in depth VM behavior with VisualVM identifying  local and remote Virtual Machines  performance bottlenecks with VisualVM's profiler  threading issues with the Thread Dump Analyzer  causes of OutOfMemory errors and PermGen errors ● detect memory leaks ● trace and debug running applications in production with btrace Carlo Bonamico - carlo.bonamico@nispro.it - JUG Genova Javaday IV – Roma – 30 gennaio 2010
  • 5. Finding the right VM with jps ● List all java processes ● jps  including command line parameters and properties ● jps ­lvm ● 29760 sun.tools.jps.Jps ­lvm ­Dapplication.home=/usr/lib/jvm/java­6­ sun­1.6.0.16 ­Xms8m ● 4752 org.codehaus.classworlds.Launcher "cli:execute­phase" ­Xmx768m  ­Dclassworlds.conf=/home/charlieb/build/apache­maven­ 2.2.1/bin/m2.conf ­Dmaven.home=/home/charlieb/build/apache­maven­ 2.2.1  on a remote machine (requires jstatd running on the server) ● jps ­lvm server Carlo Bonamico - carlo.bonamico@nispro.it - JUG Genova Javaday IV – Roma – 30 gennaio 2010
  • 6. jstat ● To enable remote access to a machine stats ● jstatd ­Djava.security.policy=jstatd.policy  which contains ● grant codebase "file:${java.home}/../lib/tools.jar" { ●    permission java.security.AllPermission; ● }; ● ● Carlo Bonamico - carlo.bonamico@nispro.it - JUG Genova Javaday IV – Roma – 30 gennaio 2010
  • 7. Efficient Garbage Collection ● Almost nobody does reference counting today :-)  When your JVM is using a few GBs of memory, it cannot check all objects all the time ● So you need a smart way of separating objects that are likely to be collected from the ones in use  generations: objects that have been created recently are more likely to be collected soon – think of request attributes  objects that have been there for a long time are unlikely to be collected – think of Spring services, EJBs, singletons Carlo Bonamico - carlo.bonamico@nispro.it - JUG Genova Javaday IV – Roma – 30 gennaio 2010
  • 8. Generational Collection in the JVM ● Heap space split into  Eden – Young objects  Survivor 1/2 – Older objects  Old ● Perm(anent)Gen(eration) area for objects that will not be deallocated until the end  class and method objects Carlo Bonamico - carlo.bonamico@nispro.it - JUG Genova Javaday IV – Roma – 30 gennaio 2010
  • 9. Start with an OOM / Permgen ● OutOfMemoryError  but increasing -Xmx will not help... ● Then it might be a PermGen space saturation  increase -XX:MaxPermSize=256m  find and detect classloading issues Carlo Bonamico - carlo.bonamico@nispro.it - JUG Genova Javaday IV – Roma – 30 gennaio 2010
  • 10. Monitoring with jstat ● Command line tool for accessing GC and JIT stats ● jstat ­gcutil <vmid> <interval> ● jstat ­gcutil 21891 250  refresh every 250 ms ●   S0     S1     E      O      P     YGC    YGCT    FGC    FGCT     GCT ●  12.44   0.00  27.20   9.49  96.70    78    0.176     5    0.495    0.672 ●  12.44   0.00  62.16   9.49  96.70    78    0.176     5    0.495    0.672 GC ●  12.44   0.00  83.97   9.49  96.70    78    0.176     5    0.495    0.672 ●   0.00   7.74   0.00   9.51  96.70    79    0.177     5    0.495    0.673 ●   0.00   7.74  23.37   9.51  96.70    79    0.177     5    0.495    0.673 ●   0.00   7.74  43.82   9.51  96.70    79    0.177     5    0.495    0.673 ●   0.00   7.74  58.11   9.51  96.71    79    0.177     5    0.495    0.673  S0/S1 = survivor spaces, E = Eden, O = Old, P = Permanent  All values are % of available space Carlo Bonamico - carlo.bonamico@nispro.it - JUG Genova Javaday IV – Roma – 30 gennaio 2010
  • 11. JVM Overview with jconsole ● Included since JDK 1.5  memory analysis  CPU load  Classloading stats  Thread stats  Classpath  JMX console  (and more...) Carlo Bonamico - carlo.bonamico@nispro.it - JUG Genova Javaday IV – Roma – 30 gennaio 2010
  • 12. Classpath, launch arguments and properties Carlo Bonamico - carlo.bonamico@nispro.it - JUG Genova Javaday IV – Roma – 30 gennaio 2010
  • 13. Incremental GC as seen by jconsole Carlo Bonamico - carlo.bonamico@nispro.it - JUG Genova Javaday IV – Roma – 30 gennaio 2010
  • 14. In-depth with (j)visualvm ● Even more powerful than jconsole  Included in the JDK since 1.6.0_07 ● Supports  local VMs through the JVMPI interface – the same used by any IDE for debug  remote VMs through – jstatd – direct JMX over RMI connection Carlo Bonamico - carlo.bonamico@nispro.it - JUG Genova Javaday IV – Roma – 30 gennaio 2010
  • 15. Thread Monitoring and Dump Carlo Bonamico - carlo.bonamico@nispro.it - JUG Genova Javaday IV – Roma – 30 gennaio 2010
  • 16. Memory analysis Carlo Bonamico - carlo.bonamico@nispro.it - JUG Genova Javaday IV – Roma – 30 gennaio 2010
  • 17. And more... ● CPU/Memory profiler  subset of NetBeans profiler  new sampling profiler since version 1.2.1 Carlo Bonamico - carlo.bonamico@nispro.it - JUG Genova Javaday IV – Roma – 30 gennaio 2010
  • 18. BTrace ● B(ytecode)Trace  conceptually similar to Solaris DTrace  can be used on any Java platform/app. ● Dynamically connects to a running Java application  and attach short “scripts” which log a range of events and infos such as – method calls – execution times – constructor invocation – available memory Carlo Bonamico - carlo.bonamico@nispro.it - JUG Genova Javaday IV – Roma – 30 gennaio 2010
  • 19. Btrace scripts ● Script execution is tied to several situations  reaching a specific line number  invoking a given method – identified by signature or annotation  returning from a method  invoking system calls (e.g. exit)  recurring timer ● In a way, BTrace scripts are very similar to read-only AOP’s aspects  can be attached to any existing Java code Carlo Bonamico - carlo.bonamico@nispro.it - JUG Genova Javaday IV – Roma – 30 gennaio 2010
  • 20. Examples ● The scripts are simple Java classes which take advantage of methods from the btrace API  simple but powerful annotations. ● Tracing session creation with hibernate ● @BTrace ● public class HelloWorldTrace { ● ● // probe the openSession() method of Hibernate SessionFactory ● @OnMethod( ● clazz=”org.hibernate.SessionFactory”, ● method=”openSession” ● ) ● public static void onOpenSessionTrace() { ● // you can only log using the stati println method from BTraceUtils ● println(”Hibernate: opening a new session…”); ● } ● } Carlo Bonamico - carlo.bonamico@nispro.it - JUG Genova Javaday IV – Roma – 30 gennaio 2010
  • 21. Examples: JAX-WS ● Intercepts all calls to methods in classes which are annotated with @WebService and logs execution times ● @OnMethod( ● clazz="@javax.jws.WebService", ● method="@javax.jws.WebMethod" ● ) ● public static void onWebserviceEntry() { – print("entering webservice "); – println(strcat(strcat(name(probeClass()), "."), probeMethod())); – startTime = timeMillis(); ● } ● ● @OnMethod( ● clazz="@javax.jws.WebService", ● method="@javax.jws.WebMethod", ● location=@Location(Kind.RETURN) ● ) ● public static void onWebserviceReturn() { – println(strcat("Time taken (msec) ", str(timeMillis() ­ startTime))); ● } Carlo Bonamico - carlo.bonamico@nispro.it - JUG Genova Javaday IV – Roma – 30 gennaio 2010
  • 22. Yesterday news ● JDK 1.6.0_18 released last week  includes visualvm 1.2.1  includes NUMA-aware Garbage Collector – Non-Uniform Memory Allocation – takes into account that the cost of accessing RAM is not uniform anymore – 30% more efficient with large memory allocations – linux/solaris only :-) Carlo Bonamico - carlo.bonamico@nispro.it - JUG Genova Javaday IV – Roma – 30 gennaio 2010
  • 23. References ● VisualVM official site  https://visualvm.dev.java.net ● BTrace  https://btrace.dev.java.net ● Articles on Hotspot  http://java.sun.com/javase/technologies/hotspot/index .jsp Carlo Bonamico - carlo.bonamico@nispro.it - JUG Genova Javaday IV – Roma – 30 gennaio 2010
  • 24. Thanks for your attention! ● Learn more at  http://www.carlobonamico.com/blog  http://juggenova.net – presentations, demos, code samples ● Meet me at the my company (NIS) booth in the exhibition hall ● Contact me at  carlo.bonamico@gmail.com ● Related reading: Continuous Integration with Hudson  http://www.slideshare.net/carlo.bonamico/continuous-integration-with-hudson Carlo Bonamico - carlo.bonamico@nispro.it - JUG Genova Javaday IV – Roma – 30 gennaio 2010

×