Understanding JVM

Understanding JVM

Introduction to JVM memory structure and reasons for different OutOfMemoryError.

8e0ede7586a03357acfe3eb3ac362c28?s=128

Aparna Chaudhary

October 04, 2013
Tweet

Transcript

  1. 3.

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

    Memory Guest OS Memory Friday, October 4, 13
  2. 4.

    What’s inside my VM? VM Memory Guest OS Memory JVM

    Memory VM Memory Guest OS Memory JVM Memory Friday, October 4, 13
  3. 5.

    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. 6.

    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. 7.

    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. 8.

    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. 9.

    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. 10.

    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. 13.

    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. 14.

    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. 15.

    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. 16.

    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. 17.

    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. 18.

    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. 19.

    OOM - PermGen Symptom At server startup Cause Bigger PermGen

    footprint Resolution Increase PermGen capacity -XX:MaxPermSize Friday, October 4, 13
  16. 20.

    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. 21.

    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. 23.

    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. 24.

    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. 26.

    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. 27.

    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. 28.

    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. 30.

    JVM Heap Structure Eden S0 S1 Tenured Old Generation Young

    Generation Survivor Space Friday, October 4, 13
  24. 31.

    Eden To From Survivor Spaces Object Allocation Young Gen =

    Eden + Survivor Spaces Friday, October 4, 13
  25. 32.

    Eden To From Survivor Spaces Just allocated are allocated in

    Eden Object Allocation Young Gen = Eden + Survivor Spaces Friday, October 4, 13
  26. 34.

    Eden To From Survivor Spaces Just allocated are allocated in

    Eden Filling up Eden Space Friday, October 4, 13
  27. 35.

    Minor GC - Copy referenced objects Eden To From Survivor

    Spaces Unreferenced Referenced Friday, October 4, 13
  28. 36.

    Minor GC - Copy referenced objects Eden To From Survivor

    Spaces Unreferenced Referenced Friday, October 4, 13
  29. 37.

    Minor GC - Copy referenced objects Eden To From Survivor

    Spaces Unreferenced Referenced Friday, October 4, 13
  30. 38.

    Minor GC - Copy referenced objects Eden To From Survivor

    Spaces Unreferenced Referenced 1 1 1 1 Friday, October 4, 13
  31. 39.

    Next Minor GC - Object Aging Eden From To Survivor

    Spaces Unreferenced Referenced 1 1 1 1 Friday, October 4, 13
  32. 40.

    Next Minor GC - Object Aging Eden From To Survivor

    Spaces Unreferenced Referenced 1 1 1 1 Friday, October 4, 13
  33. 41.

    Next Minor GC - Object Aging Eden From To Survivor

    Spaces Unreferenced Referenced 1 1 Friday, October 4, 13
  34. 42.

    Next Minor GC - Object Aging Eden From To Survivor

    Spaces Unreferenced Referenced 1 2 Friday, October 4, 13
  35. 43.

    Next Minor GC - Object Aging Eden From To Survivor

    Spaces Unreferenced Referenced 2 2 Friday, October 4, 13
  36. 44.

    Next Minor GC - Object Aging Eden From To Survivor

    Spaces Unreferenced Referenced 2 2 1 Friday, October 4, 13
  37. 45.

    Next Minor GC - Object Aging Eden From To Survivor

    Spaces Unreferenced Referenced 2 2 1 1 Friday, October 4, 13
  38. 46.

    Next Minor GC - Additional Aging Eden To From Survivor

    Spaces Unreferenced Referenced 2 2 1 1 Friday, October 4, 13
  39. 47.

    Next Minor GC - Additional Aging Eden To From Survivor

    Spaces Unreferenced Referenced 2 1 Friday, October 4, 13
  40. 48.

    Next Minor GC - Additional Aging Eden To From Survivor

    Spaces Unreferenced Referenced 3 2 1 Friday, October 4, 13
  41. 49.

    Next Minor GC - Promotion Eden From To Survivor Spaces

    Unreferenced Referenced 3 2 1 1 14 Tenured Friday, October 4, 13
  42. 50.

    Next Minor GC - Promotion Eden From To Survivor Spaces

    Unreferenced Referenced 3 2 1 1 14 Tenured Friday, October 4, 13
  43. 51.
  44. 52.
  45. 53.

    Warning! This knowledge does not make us JVM experts! Always

    focus first on software before hacking JVM. Friday, October 4, 13
  46. 55.

    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
  47. 56.

    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
  48. 57.

    What Next? Demo VisualVM Eclipse Memory Analyzer Tool Other tools

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