Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Understanding JVM

Understanding JVM

Introduction to JVM memory structure and reasons for different OutOfMemoryError.

Aparna Chaudhary

October 04, 2013
Tweet

More Decks by Aparna Chaudhary

Other Decks in Technology

Transcript

  1. What’s inside my VM? VM Memory Guest OS Memory VM

    Memory Guest OS Memory Friday, October 4, 13
  2. What’s inside my VM? VM Memory Guest OS Memory JVM

    Memory VM Memory Guest OS Memory JVM Memory Friday, October 4, 13
  3. What’s inside my VM? VM Memory Guest OS Memory JVM

    Memory PermGen -XX:MaxPermSize VM Memory Guest OS Memory JVM Memory PermGen -XX:MaxPermSize Friday, October 4, 13
  4. What’s inside my VM? VM Memory Guest OS Memory JVM

    Memory PermGen -XX:MaxPermSize Stack -XSS Per Thread VM Memory Guest OS Memory JVM Memory PermGen -XX:MaxPermSize Stack -XSS Per Thread Friday, October 4, 13
  5. What’s inside my VM? VM Memory Guest OS Memory JVM

    Memory PermGen -XX:MaxPermSize Stack -XSS Per Thread HEAP VM Memory Guest OS Memory JVM Memory PermGen -XX:MaxPermSize Stack -XSS Per Thread HEAP Friday, October 4, 13
  6. What’s inside my VM? VM Memory Guest OS Memory JVM

    Memory PermGen -XX:MaxPermSize Stack -XSS Per Thread HEAP Initial -Xms VM Memory Guest OS Memory JVM Memory PermGen -XX:MaxPermSize Stack -XSS Per Thread HEAP Initial -Xms Friday, October 4, 13
  7. What’s inside my VM? VM Memory Guest OS Memory JVM

    Memory PermGen -XX:MaxPermSize Stack -XSS Per Thread HEAP Initial -Xms -Xmx VM Memory Guest OS Memory JVM Memory PermGen -XX:MaxPermSize Stack -XSS Per Thread HEAP Initial -Xms -Xmx Friday, October 4, 13
  8. Exception in thread "main": java.lang.OutOfMemoryError: Java heap space Exception in

    thread "main": java.lang.OutOfMemoryError: PermGen space Exception in thread "main": java.lang.OutOfMemoryError: GC overhead limit exceeded Exception in thread "main": java.lang.OutOfMemoryError: Unable to create new native thread and more... OutOfMemoryError Friday, October 4, 13
  9. Life of a class described by loaded by references references

    Object Class Classl oader described by loaded by references references Object Class Classl oader Friday, October 4, 13
  10. Life of a class described by loaded by references references

    Object Class Classl oader references described by loaded by references references Object Class Classl oader references Friday, October 4, 13
  11. Life of a class Object Class Classloader1 references references Object

    Class Classloader2 references references Object Class Classloader1 references references Object Class Classloader2 references references Friday, October 4, 13
  12. Life of a class Object Class Classloader1 references references Object

    Class Classloader2 references references Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Object Class Classloader1 references references Object Class Classloader2 references references Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Friday, October 4, 13
  13. Life of a class Object Class Classloader1 references references Object

    Class Classloader2 references references Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Object Class Classloader1 references references Object Class Classloader2 references references Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Friday, October 4, 13
  14. OOM - PermGen This occurs when JVM wants to load

    new class definitions; but there is not enough space in PermGen space Friday, October 4, 13
  15. OOM - PermGen Symptom At server startup Cause Bigger PermGen

    footprint Resolution Increase PermGen capacity -XX:MaxPermSize Friday, October 4, 13
  16. OOM - PermGen Symptom PermGen space increases gradually Cause Possible

    classloader leak Resolution Investigate any third party API you are using for any potential class loader leak defect Friday, October 4, 13
  17. OOM - PermGen Symptom OOM after deploy-redeploy cycles Cause Possible

    classloader leak in the App Server Resolution Someone should fix it for you. Hmm..where is EAP? Friday, October 4, 13
  18. OOM - GC overhead limit exceeded Policy to allow the

    VM to detect potential OutOfMemoryError conditions earlier and before it runs out of Java Heap space. Can be turned off -XX:-UseGCOverheadLimit But don’t! Friday, October 4, 13
  19. OOM - GC overhead limit exceeded When is this error

    triggered? ✓Too many Full GC iterations ✓Too much time spent in GC Friday, October 4, 13
  20. OOM - Unable to create new native thread JVM is

    asking a new thread from the OS and the underlying OS cannot allocate a new thread anymore. Friday, October 4, 13
  21. Why? VM Memory Guest OS Memory JVM Memory PermGen -XX:MaxPermSize

    Stack -XSS Per Thread HEAP Initial -Xms -Xmx not enough stack space Friday, October 4, 13
  22. OOM - Unable to create new native thread ✓Check ulimit

    - process limit ✓Consider using thread-pools ✓Reduce heap space or perform vertical scaling Friday, October 4, 13
  23. JVM Heap Structure Eden S0 S1 Tenured Old Generation Young

    Generation Survivor Space Friday, October 4, 13
  24. Eden To From Survivor Spaces Object Allocation Young Gen =

    Eden + Survivor Spaces Friday, October 4, 13
  25. Eden To From Survivor Spaces Just allocated are allocated in

    Eden Object Allocation Young Gen = Eden + Survivor Spaces Friday, October 4, 13
  26. Eden To From Survivor Spaces Just allocated are allocated in

    Eden Filling up Eden Space Friday, October 4, 13
  27. Minor GC - Copy referenced objects Eden To From Survivor

    Spaces Unreferenced Referenced Friday, October 4, 13
  28. Minor GC - Copy referenced objects Eden To From Survivor

    Spaces Unreferenced Referenced Friday, October 4, 13
  29. Minor GC - Copy referenced objects Eden To From Survivor

    Spaces Unreferenced Referenced Friday, October 4, 13
  30. Minor GC - Copy referenced objects Eden To From Survivor

    Spaces Unreferenced Referenced 1 1 1 1 Friday, October 4, 13
  31. Next Minor GC - Object Aging Eden From To Survivor

    Spaces Unreferenced Referenced 1 1 1 1 Friday, October 4, 13
  32. Next Minor GC - Object Aging Eden From To Survivor

    Spaces Unreferenced Referenced 1 1 1 1 Friday, October 4, 13
  33. Next Minor GC - Object Aging Eden From To Survivor

    Spaces Unreferenced Referenced 1 1 Friday, October 4, 13
  34. Next Minor GC - Object Aging Eden From To Survivor

    Spaces Unreferenced Referenced 1 2 Friday, October 4, 13
  35. Next Minor GC - Object Aging Eden From To Survivor

    Spaces Unreferenced Referenced 2 2 Friday, October 4, 13
  36. Next Minor GC - Object Aging Eden From To Survivor

    Spaces Unreferenced Referenced 2 2 1 Friday, October 4, 13
  37. Next Minor GC - Object Aging Eden From To Survivor

    Spaces Unreferenced Referenced 2 2 1 1 Friday, October 4, 13
  38. Next Minor GC - Additional Aging Eden To From Survivor

    Spaces Unreferenced Referenced 2 2 1 1 Friday, October 4, 13
  39. Next Minor GC - Additional Aging Eden To From Survivor

    Spaces Unreferenced Referenced 2 1 Friday, October 4, 13
  40. Next Minor GC - Additional Aging Eden To From Survivor

    Spaces Unreferenced Referenced 3 2 1 Friday, October 4, 13
  41. Next Minor GC - Promotion Eden From To Survivor Spaces

    Unreferenced Referenced 3 2 1 1 14 Tenured Friday, October 4, 13
  42. Next Minor GC - Promotion Eden From To Survivor Spaces

    Unreferenced Referenced 3 2 1 1 14 Tenured Friday, October 4, 13
  43. Warning! This knowledge does not make us JVM experts! Always

    focus first on software before hacking JVM. Friday, October 4, 13
  44. Class Histogram jmap -F -histo `pgrep java` Make it a

    practice to proactively use this command after a load test and endurance test. Friday, October 4, 13
  45. Heap Dump jmap [ option ] <pid> jmap -F -dump:live,format=b,file=/

    var/opt/jboss-as/tmp/io/ heapdump.hprof `pgrep java` http://docs.oracle.com/javase/6/docs/technotes/tools/share/jmap.html Friday, October 4, 13
  46. What Next? Demo VisualVM Eclipse Memory Analyzer Tool Other tools

    and commands GC Algorithms (Optional) Friday, October 4, 13