Your SlideShare is downloading. ×
0
Understanding JVM
Understanding JVM
Understanding JVM
Understanding JVM
Understanding JVM
Understanding JVM
Understanding JVM
Understanding JVM
Understanding JVM
Understanding JVM
Understanding JVM
Understanding JVM
Understanding JVM
Understanding JVM
Understanding JVM
Understanding JVM
Understanding JVM
Understanding JVM
Understanding JVM
Understanding JVM
Understanding JVM
Understanding JVM
Understanding JVM
Understanding JVM
Understanding JVM
Understanding JVM
Understanding JVM
Understanding JVM
Understanding JVM
Understanding JVM
Understanding JVM
Understanding JVM
Understanding JVM
Understanding JVM
Understanding JVM
Understanding JVM
Understanding JVM
Understanding JVM
Understanding JVM
Understanding JVM
Understanding JVM
Understanding JVM
Understanding JVM
Understanding JVM
Understanding JVM
Understanding JVM
Understanding JVM
Understanding JVM
Understanding JVM
Understanding JVM
Understanding JVM
Understanding JVM
Understanding JVM
Understanding JVM
Understanding JVM
Understanding JVM
Understanding JVM
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

Understanding JVM

1,942

Published on

Introduction to JVM memory structure and reasons for different OutOfMemoryError.

Introduction to JVM memory structure and reasons for different OutOfMemoryError.

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

No Downloads
Views
Total Views
1,942
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
120
Comments
0
Likes
12
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. Understanding JVM Aparna Chaudhary Friday, October 4, 13
  • 2. VM Memory What’s inside my VM? Friday, October 4, 13
  • 3. VM Memory Guest OS Memory What’s inside my VM? Friday, October 4, 13
  • 4. JVM Memory VM Memory Guest OS Memory What’s inside my VM? Friday, October 4, 13
  • 5. JVM Memory VM Memory ize ermS XX:MaxP - PermGen Guest OS Memory What’s inside my VM? Friday, October 4, 13
  • 6. JVM Memory VM Memory read S Per Th -XS ize ermS XX:MaxP - Stack PermGen Guest OS Memory What’s inside my VM? Friday, October 4, 13
  • 7. HEAP JVM Memory VM Memory read S Per Th -XS ize ermS XX:MaxP - Stack PermGen Guest OS Memory What’s inside my VM? Friday, October 4, 13
  • 8. HEAP Initial -Xms JVM Memory VM Memory read S Per Th -XS ize ermS XX:MaxP - Stack PermGen Guest OS Memory What’s inside my VM? Friday, October 4, 13
  • 9. -Xmx HEAP Initial -Xms JVM Memory VM Memory read S Per Th -XS ize ermS XX:MaxP - Stack PermGen Guest OS Memory What’s inside my VM? Friday, October 4, 13
  • 10. OutOfMemoryError 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... Friday, October 4, 13
  • 11. OutOfMemoryError Exception in thread "main": java.lang.OutOfMemoryError: PermGen Space Friday, October 4, 13
  • 12. Perm Gen Space Used for Storing the JVM’s internal representation of Java Classes Friday, October 4, 13
  • 13. Object described by references Class references loaded by Classl oader Life of a class Friday, October 4, 13
  • 14. Object described by references Class references loaded by references Classl oader Life of a class Friday, October 4, 13
  • 15. references Object references Object Class Class references references Classloader1 Classloader2 Life of a class Friday, October 4, 13
  • 16. references Object references Object Class Class references references Class Classloader1 Class Class Class Class Class Class Class Classloader2 Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Life of a class Friday, October 4, 13
  • 17. references Object references Object Class Class references references Class Classloader1 Class Class Class Class Class Class Class Classloader2 Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Class Life of a class Friday, October 4, 13
  • 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
  • 19. OOM - PermGen Symptom At server startup Cause Bigger PermGen footprint Resolution Increase PermGen capacity -XX:MaxPermSize Friday, October 4, 13
  • 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
  • 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
  • 22. OutOfMemoryError Exception in thread "main": java.lang.OutOfMemoryError: GC overhead limit exceeded Friday, October 4, 13
  • 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
  • 24. OOM - GC overhead limit exceeded When is this error triggered? ✓Too ✓Too Friday, October 4, 13 many Full GC iterations much time spent in GC
  • 25. OutOfMemoryError Exception in thread "main": java.lang.OutOfMemoryError: Unable to create new native thread Friday, October 4, 13
  • 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
  • 27. Why? -Xmx HEAP Initial -Xms JVM Memory d Stack ize VM Memory PermGen Threa -XSS Per ermS -XX:MaxP Guest OS Memory Friday, October 4, 13 not eno ugh stack space
  • 28. OOM - Unable to create new native thread ✓ Check ulimit - process limit ✓ Consider using thread-pools ✓ Reduce heap space or perform Friday, October 4, 13 vertical scaling
  • 29. OutOfMemoryError Exception in thread "main": java.lang.OutOfMemoryError: Java heap space Friday, October 4, 13
  • 30. JVM Heap Structure Survivor Space Eden S0 S1 Young Generation Friday, October 4, 13 Tenured Old Generation
  • 31. Object Allocation Eden From To Survivor Spaces Young Gen = Eden + Survivor Spaces Friday, October 4, 13
  • 32. Object Allocation are allocated in Eden Just allocated Eden From To Survivor Spaces Young Gen = Eden + Survivor Spaces Friday, October 4, 13
  • 33. Filling up Eden Space Eden From To Survivor Spaces Friday, October 4, 13
  • 34. Filling up Eden Space are allocated in Eden Just allocated Eden From To Survivor Spaces Friday, October 4, 13
  • 35. Minor GC - Copy referenced objects Eden From To Survivor Spaces Unreferenced Referenced Friday, October 4, 13
  • 36. Minor GC - Copy referenced objects Eden From To Survivor Spaces Unreferenced Referenced Friday, October 4, 13
  • 37. Minor GC - Copy referenced objects Eden From To Survivor Spaces Unreferenced Referenced Friday, October 4, 13
  • 38. Minor GC - Copy referenced objects Eden To 1 1 1 1 Survivor Spaces From Unreferenced Referenced Friday, October 4, 13
  • 39. Next Minor GC - Object Aging Eden From 1 1 1 1 Survivor Spaces To Unreferenced Referenced Friday, October 4, 13
  • 40. Next Minor GC - Object Aging Eden From 1 1 1 1 Survivor Spaces To Unreferenced Referenced Friday, October 4, 13
  • 41. Next Minor GC - Object Aging Eden From 1 1 Survivor Spaces To Unreferenced Referenced Friday, October 4, 13
  • 42. Next Minor GC - Object Aging Eden From 1 2 Survivor Spaces To Unreferenced Referenced Friday, October 4, 13
  • 43. Next Minor GC - Object Aging Eden From 2 2 Survivor Spaces To Unreferenced Referenced Friday, October 4, 13
  • 44. Next Minor GC - Object Aging Eden From 2 2 1 Survivor Spaces To Unreferenced Referenced Friday, October 4, 13
  • 45. Next Minor GC - Object Aging Eden From 2 2 1 Survivor Spaces 1 To Unreferenced Referenced Friday, October 4, 13
  • 46. Next Minor GC - Additional Aging Eden To 2 2 1 Survivor Spaces 1 From Unreferenced Referenced Friday, October 4, 13
  • 47. Next Minor GC - Additional Aging Eden To 2 1 Survivor Spaces From Unreferenced Referenced Friday, October 4, 13
  • 48. Next Minor GC - Additional Aging Eden To 1 2 3 Survivor Spaces From Unreferenced Referenced Friday, October 4, 13
  • 49. Next Minor GC - Promotion Eden From 1 14 1 2 3 To Survivor Spaces Tenured Unreferenced Referenced Friday, October 4, 13
  • 50. Next Minor GC - Promotion Eden From 1 1 2 3 To Survivor Spaces Tenured 14 Unreferenced Referenced Friday, October 4, 13
  • 51. Major GC Eden From 1 1 1 2 3 To Survivor Spaces Tenured Unreferenced Referenced Friday, October 4, 13
  • 52. Major GC Eden From 1 1 1 2 3 To Survivor Spaces Tenured Unreferenced Referenced Friday, October 4, 13
  • 53. Warning! This knowledge does not make us JVM experts! Always focus first on software before hacking JVM. Friday, October 4, 13
  • 54. JVM Diagnosis jmap jhat Friday, October 4, 13
  • 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
  • 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
  • 57. What Next? Demo VisualVM Eclipse Memory Analyzer Tool Other tools and commands GC Algorithms (Optional) Friday, October 4, 13

×