jvm internals - nejug nov 2010

Download JVM Internals - NEJUG Nov 2010

If you can't read please download the document

Upload: doug-hawkins

Post on 10-May-2015

4.616 views

Category:

Technology


2 download

DESCRIPTION

NEJUG JVM Internals Presentation covers... - Garbage Collection - Byte Code - HotSpot Optimizations

TRANSCRIPT

  • 1.JVM InternalsDouglas Q. Hawkins - [email protected] http://www.dougqh.net/ Wednesday, November 10, 2010

2. JVM InternalsDouglas Q. Hawkins - [email protected] http://www.dougqh.net/http://www.meetup.com/boston-java Wednesday, November 10, 2010 3. JVM Internals HotSpot Garbage Collector HotSpot OptimizationsClass File Format & Byte CodeCompile TimeRun Time Demos Presentation Materialshttp://www.slideshare.net/dougqhhttps://github.com/dougqh Wednesday, November 10, 2010 4. Garbage Collection Wednesday, November 10, 2010 5. Garbage CollectionCurrent HotSpot CollectorsDemosGarbage First (G1) Collector Wednesday, November 10, 2010 6. Generational Hypothesis Generational Hypothesis92 to 98% objects die youngFew references exist from old objects to new objectshttp://www.devx.com/Java/Article/21977http://www.ibm.com/developerworks/java/library/j-jtp09275.htmlhttp://java.sun.com/j2se/reference/whitepapers/memorymanagement_whitepaper.pdf Wednesday, November 10, 2010 7. HotSpot Garbage CollectorHeap http://download.oracle.com/javase/1.5.0/docs/guide/vm/gc-ergonomics.html http://java.sun.com/j2se/reference/whitepapers/memorymanagement_whitepaper.pdf Wednesday, November 10, 2010 8. HotSpot Garbage CollectorYoung GenerationOld Generation http://download.oracle.com/javase/1.5.0/docs/guide/vm/gc-ergonomics.html http://java.sun.com/j2se/reference/whitepapers/memorymanagement_whitepaper.pdf Wednesday, November 10, 2010 9. HotSpot Garbage CollectorYoung Generation EdenS1S2 Old Generation http://download.oracle.com/javase/1.5.0/docs/guide/vm/gc-ergonomics.html http://java.sun.com/j2se/reference/whitepapers/memorymanagement_whitepaper.pdf Wednesday, November 10, 2010 10. Object AllocationYoung Generation EdenS1 S2 Old Generation http://blogs.sun.com/jonthecollector/entry/the_real_thing http://blogs.sun.com/jonthecollector/entry/a_little_thread_privacy_please Wednesday, November 10, 2010 11. Object AllocationYoung Generation EdenS1 S2 Old Generation http://blogs.sun.com/jonthecollector/entry/the_real_thing http://blogs.sun.com/jonthecollector/entry/a_little_thread_privacy_please Wednesday, November 10, 2010 12. Object AllocationYoung Generation EdenS1 S2 Old Generation http://blogs.sun.com/jonthecollector/entry/the_real_thing http://blogs.sun.com/jonthecollector/entry/a_little_thread_privacy_please Wednesday, November 10, 2010 13. Object AllocationYoung Generation EdenS1 S2 Old Generation http://blogs.sun.com/jonthecollector/entry/the_real_thing http://blogs.sun.com/jonthecollector/entry/a_little_thread_privacy_please Wednesday, November 10, 2010 14. Object AllocationYoung Generation EdenS1 S2 Old Generation http://blogs.sun.com/jonthecollector/entry/the_real_thing http://blogs.sun.com/jonthecollector/entry/a_little_thread_privacy_please Wednesday, November 10, 2010 15. Object AllocationYoung Generation EdenS1 S2 Old Generation http://blogs.sun.com/jonthecollector/entry/the_real_thing http://blogs.sun.com/jonthecollector/entry/a_little_thread_privacy_please Wednesday, November 10, 2010 16. Object AllocationYoung Generation EdenS1 S2 Old Generation http://blogs.sun.com/jonthecollector/entry/the_real_thing http://blogs.sun.com/jonthecollector/entry/a_little_thread_privacy_please Wednesday, November 10, 2010 17. Object AllocationYoung Generation EdenS1 S2 Old Generation http://blogs.sun.com/jonthecollector/entry/the_real_thing http://blogs.sun.com/jonthecollector/entry/a_little_thread_privacy_please Wednesday, November 10, 2010 18. Object Allocation TLABYoung Generation EdenS1 S2 Old Generation http://blogs.sun.com/jonthecollector/entry/the_real_thing http://blogs.sun.com/jonthecollector/entry/a_little_thread_privacy_please Wednesday, November 10, 2010 19. Object Allocation TLABYoung Generation EdenS1 S2 Old Generation http://blogs.sun.com/jonthecollector/entry/the_real_thing http://blogs.sun.com/jonthecollector/entry/a_little_thread_privacy_please Wednesday, November 10, 2010 20. Object Allocation TLABYoung Generation EdenS1 S2 Old Generation http://blogs.sun.com/jonthecollector/entry/the_real_thing http://blogs.sun.com/jonthecollector/entry/a_little_thread_privacy_please Wednesday, November 10, 2010 21. Object Allocation TLABYoung Generation EdenS1 S2 Old Generation http://blogs.sun.com/jonthecollector/entry/the_real_thing http://blogs.sun.com/jonthecollector/entry/a_little_thread_privacy_please Wednesday, November 10, 2010 22. Object Allocation TLABYoung Generation EdenS1 S2 Old Generation http://blogs.sun.com/jonthecollector/entry/the_real_thing http://blogs.sun.com/jonthecollector/entry/a_little_thread_privacy_please Wednesday, November 10, 2010 23. Object Allocation TLABYoung Generation EdenS1 S2 Old Generation http://blogs.sun.com/jonthecollector/entry/the_real_thing http://blogs.sun.com/jonthecollector/entry/a_little_thread_privacy_please Wednesday, November 10, 2010 24. Object Allocation TLABYoung Generation EdenS1 S2 Old Generation http://blogs.sun.com/jonthecollector/entry/the_real_thing http://blogs.sun.com/jonthecollector/entry/a_little_thread_privacy_please Wednesday, November 10, 2010 25. Object Allocation TLABYoung Generation EdenS1 S2 Old Generation http://blogs.sun.com/jonthecollector/entry/the_real_thing http://blogs.sun.com/jonthecollector/entry/a_little_thread_privacy_please Wednesday, November 10, 2010 26. Object Allocation TLABYoung Generation EdenS1 S2 Old Generation http://blogs.sun.com/jonthecollector/entry/the_real_thing http://blogs.sun.com/jonthecollector/entry/a_little_thread_privacy_please Wednesday, November 10, 2010 27. Minor CollectionTLABYoung Generation EdenS1 S2 Old Generation http://www.fasterj.com/articles/G1.shtml http://java.sun.com/docs/hotspot/gc1.4.2/faq.html http://www.oracle.com/technetwork/java/gc-tuning-5-138395.html Wednesday, November 10, 2010 28. Minor CollectionTLABYoung Generation EdenS1 S2 Old Generation http://www.fasterj.com/articles/G1.shtml http://java.sun.com/docs/hotspot/gc1.4.2/faq.html http://www.oracle.com/technetwork/java/gc-tuning-5-138395.html Wednesday, November 10, 2010 29. Minor CollectionTLABYoung Generation EdenS1 S2 Old Generation http://www.fasterj.com/articles/G1.shtml http://java.sun.com/docs/hotspot/gc1.4.2/faq.html http://www.oracle.com/technetwork/java/gc-tuning-5-138395.html Wednesday, November 10, 2010 30. Minor CollectionYoung Generation EdenS1 S2 Old Generation http://www.fasterj.com/articles/G1.shtml http://java.sun.com/docs/hotspot/gc1.4.2/faq.html http://www.oracle.com/technetwork/java/gc-tuning-5-138395.html Wednesday, November 10, 2010 31. Minor CollectionYoung Generation EdenS1 S2 Old Generation http://www.fasterj.com/articles/G1.shtml http://java.sun.com/docs/hotspot/gc1.4.2/faq.html http://www.oracle.com/technetwork/java/gc-tuning-5-138395.html Wednesday, November 10, 2010 32. Minor CollectionYoung Generation EdenS1 S2 Old Generation http://www.fasterj.com/articles/G1.shtml http://java.sun.com/docs/hotspot/gc1.4.2/faq.html http://www.oracle.com/technetwork/java/gc-tuning-5-138395.html Wednesday, November 10, 2010 33. Minor CollectionYoung Generation EdenS1 S2 Old Generation http://www.fasterj.com/articles/G1.shtml http://java.sun.com/docs/hotspot/gc1.4.2/faq.html http://www.oracle.com/technetwork/java/gc-tuning-5-138395.html Wednesday, November 10, 2010 34. Minor CollectionYoung Generation EdenS1 S2 Old Generation http://www.fasterj.com/articles/G1.shtml http://java.sun.com/docs/hotspot/gc1.4.2/faq.html http://www.oracle.com/technetwork/java/gc-tuning-5-138395.html Wednesday, November 10, 2010 35. Minor CollectionYoung Generation EdenS1 S2 Old Generation http://www.fasterj.com/articles/G1.shtml http://java.sun.com/docs/hotspot/gc1.4.2/faq.html http://www.oracle.com/technetwork/java/gc-tuning-5-138395.html Wednesday, November 10, 2010 36. Minor CollectionYoung Generation EdenS1 S2 Old Generation http://www.fasterj.com/articles/G1.shtml http://java.sun.com/docs/hotspot/gc1.4.2/faq.html http://www.oracle.com/technetwork/java/gc-tuning-5-138395.html Wednesday, November 10, 2010 37. Minor CollectionYoung Generation EdenS1 S2 Old Generation http://www.fasterj.com/articles/G1.shtml http://java.sun.com/docs/hotspot/gc1.4.2/faq.html http://www.oracle.com/technetwork/java/gc-tuning-5-138395.html Wednesday, November 10, 2010 38. Application Thread GC Threadhttp://www.austinjug.org/presentations/JDK6PerfUpdate_Dec2009.pdf Wednesday, November 10, 2010 39. Stop the World! Application Thread GC Threadhttp://www.austinjug.org/presentations/JDK6PerfUpdate_Dec2009.pdf Wednesday, November 10, 2010 40. Application Thread GC Threadhttp://www.austinjug.org/presentations/JDK6PerfUpdate_Dec2009.pdf Wednesday, November 10, 2010 41. Serial Application Thread GC Threadhttp://www.austinjug.org/presentations/JDK6PerfUpdate_Dec2009.pdf Wednesday, November 10, 2010 42. SerialParallel Application Thread GC Threadhttp://www.austinjug.org/presentations/JDK6PerfUpdate_Dec2009.pdf Wednesday, November 10, 2010 43. Demo Wednesday, November 10, 2010 44. Major CollectionYoung Generation EdenS1S2 Old Generationhttp://www.devx.com/Java/Article/21977/0http://www.austinjug.org/presentations/JDK6PerfUpdate_Dec2009.pdfhttp://java.sun.com/j2se/reference/whitepapers/memorymanagement_whitepaper.pdf Wednesday, November 10, 2010 45. Major CollectionYoung Generation EdenS1S2 Old Generationhttp://www.devx.com/Java/Article/21977/0http://www.austinjug.org/presentations/JDK6PerfUpdate_Dec2009.pdfhttp://java.sun.com/j2se/reference/whitepapers/memorymanagement_whitepaper.pdf Wednesday, November 10, 2010 46. Major CollectionYoung Generation EdenS1S2 Old Generationhttp://www.devx.com/Java/Article/21977/0http://www.austinjug.org/presentations/JDK6PerfUpdate_Dec2009.pdfhttp://java.sun.com/j2se/reference/whitepapers/memorymanagement_whitepaper.pdf Wednesday, November 10, 2010 47. Major CollectionYoung Generation EdenS1S2 Old Generationhttp://www.devx.com/Java/Article/21977/0http://www.austinjug.org/presentations/JDK6PerfUpdate_Dec2009.pdfhttp://java.sun.com/j2se/reference/whitepapers/memorymanagement_whitepaper.pdf Wednesday, November 10, 2010 48. Major CollectionYoung Generation EdenS1S2 Old Generationhttp://www.devx.com/Java/Article/21977/0http://www.austinjug.org/presentations/JDK6PerfUpdate_Dec2009.pdfhttp://java.sun.com/j2se/reference/whitepapers/memorymanagement_whitepaper.pdf Wednesday, November 10, 2010 49. Major CollectionYoung Generation EdenS1S2 Old Generationhttp://www.devx.com/Java/Article/21977/0http://www.austinjug.org/presentations/JDK6PerfUpdate_Dec2009.pdfhttp://java.sun.com/j2se/reference/whitepapers/memorymanagement_whitepaper.pdf Wednesday, November 10, 2010 50. Major CollectionYoung Generation EdenS1S2 Old Generationhttp://www.devx.com/Java/Article/21977/0http://www.austinjug.org/presentations/JDK6PerfUpdate_Dec2009.pdfhttp://java.sun.com/j2se/reference/whitepapers/memorymanagement_whitepaper.pdf Wednesday, November 10, 2010 51. Major CollectionYoung Generation EdenS1S2 Old Generationhttp://www.devx.com/Java/Article/21977/0http://www.austinjug.org/presentations/JDK6PerfUpdate_Dec2009.pdfhttp://java.sun.com/j2se/reference/whitepapers/memorymanagement_whitepaper.pdf Wednesday, November 10, 2010 52. Major CollectionYoung Generation EdenS1S2 Old Generationhttp://www.devx.com/Java/Article/21977/0http://www.austinjug.org/presentations/JDK6PerfUpdate_Dec2009.pdfhttp://java.sun.com/j2se/reference/whitepapers/memorymanagement_whitepaper.pdf Wednesday, November 10, 2010 53. Major CollectionYoung Generation EdenS1S2 Old Generationhttp://www.devx.com/Java/Article/21977/0http://www.austinjug.org/presentations/JDK6PerfUpdate_Dec2009.pdfhttp://java.sun.com/j2se/reference/whitepapers/memorymanagement_whitepaper.pdf Wednesday, November 10, 2010 54. Major CollectionYoung Generation EdenS1S2 Old Generationhttp://www.devx.com/Java/Article/21977/0http://www.austinjug.org/presentations/JDK6PerfUpdate_Dec2009.pdfhttp://java.sun.com/j2se/reference/whitepapers/memorymanagement_whitepaper.pdf Wednesday, November 10, 2010 55. Serial Mark Parallel MarkSweep & CompactSweep & Compact Application Thread GC Thread http://www.devx.com/Java/Article/21977/0/page/3http://www.austinjug.org/presentations/JDK6PerfUpdate_Dec2009.pdf Wednesday, November 10, 2010 56. Serial Mark Parallel MarkSweep & CompactSweep & Compact Application Thread GC Thread http://www.devx.com/Java/Article/21977/0/page/3http://www.austinjug.org/presentations/JDK6PerfUpdate_Dec2009.pdf Wednesday, November 10, 2010 57. Serial Mark Parallel MarkSweep & CompactSweep & Compact Concurrent Mark & Sweep Application Thread GC Thread http://www.devx.com/Java/Article/21977/0/page/3http://www.austinjug.org/presentations/JDK6PerfUpdate_Dec2009.pdf Wednesday, November 10, 2010 58. Serial Mark Parallel MarkSweep & CompactSweep & Compact Concurrent Mark & SweepConcurrentMarking RemarkConcurrentSweep Application Thread GC Thread http://www.devx.com/Java/Article/21977/0/page/3http://www.austinjug.org/presentations/JDK6PerfUpdate_Dec2009.pdf Wednesday, November 10, 2010 59. Demo Wednesday, November 10, 2010 60. Permanent Generation Young Generation Eden S1S2Old Generation http://opensource.atlassian.com/conuence/spring/pages/viewpage.action?pageId=2669 http://dow.ngra.de/2009/06/15/classloaderlocal-how-to-avoid-classloader-leaks-on-application-redeploy/ Wednesday, November 10, 2010 61. Permanent Generation Young Generation Eden S1S2Old Generation Permanent Generationhttp://opensource.atlassian.com/conuence/spring/pages/viewpage.action?pageId=2669 http://dow.ngra.de/2009/06/15/classloaderlocal-how-to-avoid-classloader-leaks-on-application-redeploy/ Wednesday, November 10, 2010 62. Permanent Generation Young Generation Eden S1S2Old Generation Permanent GenerationBootstrap App Server Web Application http://opensource.atlassian.com/conuence/spring/pages/viewpage.action?pageId=2669 http://dow.ngra.de/2009/06/15/classloaderlocal-how-to-avoid-classloader-leaks-on-application-redeploy/ Wednesday, November 10, 2010 63. Permanent Generation Young Generation Eden S1S2Old Generation Permanent GenerationBootstrap App Server Web Application http://opensource.atlassian.com/conuence/spring/pages/viewpage.action?pageId=2669 http://dow.ngra.de/2009/06/15/classloaderlocal-how-to-avoid-classloader-leaks-on-application-redeploy/ Wednesday, November 10, 2010 64. Permanent Generation Young Generation Eden S1S2Old Generation Permanent GenerationBootstrap App Server Web Application http://opensource.atlassian.com/conuence/spring/pages/viewpage.action?pageId=2669 http://dow.ngra.de/2009/06/15/classloaderlocal-how-to-avoid-classloader-leaks-on-application-redeploy/ Wednesday, November 10, 2010 65. Permanent Generation Young Generation Eden S1S2Old Generation Permanent GenerationBootstrap App Server Web Application http://opensource.atlassian.com/conuence/spring/pages/viewpage.action?pageId=2669 http://dow.ngra.de/2009/06/15/classloaderlocal-how-to-avoid-classloader-leaks-on-application-redeploy/ Wednesday, November 10, 2010 66. Permanent Generation Young Generation Eden S1S2Old Generation Permanent GenerationBootstrap App Server http://opensource.atlassian.com/conuence/spring/pages/viewpage.action?pageId=2669 http://dow.ngra.de/2009/06/15/classloaderlocal-how-to-avoid-classloader-leaks-on-application-redeploy/ Wednesday, November 10, 2010 67. Demo Wednesday, November 10, 2010 68. Java 6 Collectors ParallelParallelYoung SerialNew ScavengeSerial Old Concurrent Parallel Old(Mark Sweep Mark &OldCompact)Sweephttp://www.petefreitag.com/articles/gctuning/ http://blogs.sun.com/jonthecollector/entry/our_collectors http://openjdk.java.net/groups/hotspot/docs/HotSpotGlossary.html Wednesday, November 10, 2010 69. Java 6 Collectors -XX:+UseSerialGC ParallelParallelYoung SerialNew ScavengeSerial Old Concurrent Parallel Old(Mark Sweep Mark &OldCompact)Sweephttp://www.petefreitag.com/articles/gctuning/ http://blogs.sun.com/jonthecollector/entry/our_collectors http://openjdk.java.net/groups/hotspot/docs/HotSpotGlossary.html Wednesday, November 10, 2010 70. Java 6 Collectors -XX:+UseParNewGC ParallelParallelYoung SerialNew ScavengeSerial Old Concurrent Parallel Old(Mark Sweep Mark &OldCompact)Sweephttp://www.petefreitag.com/articles/gctuning/ http://blogs.sun.com/jonthecollector/entry/our_collectors http://openjdk.java.net/groups/hotspot/docs/HotSpotGlossary.html Wednesday, November 10, 2010 71. Java 6 Collectors-XX:+UseParallelGC ParallelParallelYoung SerialNew ScavengeSerial Old Concurrent Parallel Old(Mark Sweep Mark &OldCompact)Sweephttp://www.petefreitag.com/articles/gctuning/ http://blogs.sun.com/jonthecollector/entry/our_collectors http://openjdk.java.net/groups/hotspot/docs/HotSpotGlossary.html Wednesday, November 10, 2010 72. Java 6 Collectors-XX:+UseConcMarkSweepGC ParallelParallelYoung SerialNew ScavengeSerial Old Concurrent Parallel Old(Mark Sweep Mark &OldCompact)Sweephttp://www.petefreitag.com/articles/gctuning/ http://blogs.sun.com/jonthecollector/entry/our_collectors http://openjdk.java.net/groups/hotspot/docs/HotSpotGlossary.html Wednesday, November 10, 2010 73. Java 6 Collectors -XX:+UseParallelOldGC ParallelParallelYoung SerialNew ScavengeSerial Old Concurrent Parallel Old(Mark Sweep Mark &OldCompact)Sweephttp://www.petefreitag.com/articles/gctuning/ http://blogs.sun.com/jonthecollector/entry/our_collectors http://openjdk.java.net/groups/hotspot/docs/HotSpotGlossary.html Wednesday, November 10, 2010 74. Java 6 Collectors ParallelParallelYoung SerialNew ScavengeSerial Old Concurrent Parallel Old(Mark Sweep Mark &OldCompact)Sweephttp://www.petefreitag.com/articles/gctuning/ http://blogs.sun.com/jonthecollector/entry/our_collectors http://openjdk.java.net/groups/hotspot/docs/HotSpotGlossary.html Wednesday, November 10, 2010 75. Java 6 Collectors ParallelParallelYoung SerialNew Scavenge G1 Serial Old Concurrent Parallel Old(Mark Sweep Mark &OldCompact)Sweephttp://www.petefreitag.com/articles/gctuning/ http://blogs.sun.com/jonthecollector/entry/our_collectors http://openjdk.java.net/groups/hotspot/docs/HotSpotGlossary.html Wednesday, November 10, 2010 76. G1 - Garbage FirstHeaphttp://developers.sun.com/learning/javaoneonline/2008/pdf/TS-5419.pdf Wednesday, November 10, 2010 77. G1 - Garbage First http://developers.sun.com/learning/javaoneonline/2008/pdf/TS-5419.pdf Wednesday, November 10, 2010 78. G1 - Garbage FirstUnused http://developers.sun.com/learning/javaoneonline/2008/pdf/TS-5419.pdf Wednesday, November 10, 2010 79. G1 - Garbage FirstUnused Young http://developers.sun.com/learning/javaoneonline/2008/pdf/TS-5419.pdf Wednesday, November 10, 2010 80. G1 - Garbage FirstUnused Young Old http://developers.sun.com/learning/javaoneonline/2008/pdf/TS-5419.pdf Wednesday, November 10, 2010 81. G1 - Minor CollectionUnused Young Old Wednesday, November 10, 2010 82. G1 - Minor CollectionUnused Young Old Wednesday, November 10, 2010 83. G1 - Minor CollectionUnused Young Old Wednesday, November 10, 2010 84. G1 - Minor CollectionUnused Young Old Wednesday, November 10, 2010 85. G1 - Minor CollectionUnused Young Old Wednesday, November 10, 2010 86. G1 - Minor CollectionUnused Young Old Wednesday, November 10, 2010 87. G1 - Minor CollectionUnused Young Old Wednesday, November 10, 2010 88. G1 - Minor CollectionUnused Young Old Wednesday, November 10, 2010 89. G1 - Minor CollectionUnused Young Old Wednesday, November 10, 2010 90. G1 - Major CollectionUnused Young Old Wednesday, November 10, 2010 91. G1 - Major CollectionUnused Young Old Wednesday, November 10, 2010 92. G1 - Major CollectionUnused Young Old Wednesday, November 10, 2010 93. G1 - Major CollectionUnused Young Old Wednesday, November 10, 2010 94. G1 - Major CollectionUnused Young Old Wednesday, November 10, 2010 95. G1 - Major CollectionUnused Young Old Wednesday, November 10, 2010 96. G1 - Major CollectionUnused Young Old Wednesday, November 10, 2010 97. G1 - Major CollectionUnused Young Old Wednesday, November 10, 2010 98. G1 - Major CollectionUnused Young Old Wednesday, November 10, 2010 99. Break Wednesday, November 10, 2010 100. HotSpot Optimizations Wednesday, November 10, 2010 101. HotSpot OptimizationsCompiler OptimizationsRuntime Optimizations Wednesday, November 10, 2010 102. Class File Format & Byte Code Wednesday, November 10, 2010 103. Class File Format & Byte CodeClass File Layout & PartsIntroduction to Byte CodeExamples of Java Compiled to Byte Code Wednesday, November 10, 2010 104. Class File FormatCAFE BABEMinor Version Major VersionConstant PoolFlagsThis Class Super Class InterfacesFieldsMethods Attributes http://java.sun.com/docs/books/jvms/second_edition/ClassFileFormat-Java5.pdf Wednesday, November 10, 2010 105. Class File FormatCAFE BABEMinor Version Major VersionConstant PoolFlagsThis Class Super Class InterfacesFieldsMethods Attributes http://java.sun.com/docs/books/jvms/second_edition/ClassFileFormat-Java5.pdf Wednesday, November 10, 2010 106. Class File FormatCAFE BABEMinor Version Major VersionConstant PoolFlagsThis Class Super Class InterfacesFieldsMethods Attributes http://java.sun.com/docs/books/jvms/second_edition/ClassFileFormat-Java5.pdf Wednesday, November 10, 2010 107. Class File FormatCAFE BABEMinor Version Major VersionConstant PoolFlagsThis Class Super Class InterfacesFieldsMethods Attributes http://java.sun.com/docs/books/jvms/second_edition/ClassFileFormat-Java5.pdf Wednesday, November 10, 2010 108. Class File FormatCAFE BABEMinor Version Major VersionConstant PoolnFlagsThis Class Super Classpu te d tioce iva te er ct ta ab tfppr ec int rafa ic umpr ic no Interfacesstblric ot al at en ann stst FieldsMethods Attributes http://java.sun.com/docs/books/jvms/second_edition/ClassFileFormat-Java5.pdf Wednesday, November 10, 2010 109. Class File FormatCAFE BABEMinor Version Major VersionConstant PoolFlagsThis Class Super Class InterfacesFieldsMethods Attributes http://java.sun.com/docs/books/jvms/second_edition/ClassFileFormat-Java5.pdf Wednesday, November 10, 2010 110. Class File FormatCAFE BABEMinor Version Major VersionConstant PoolFlagsThis Class Super Class InterfacesFieldsMethods Attributes http://java.sun.com/docs/books/jvms/second_edition/ClassFileFormat-Java5.pdf Wednesday, November 10, 2010 111. Class File FormatCAFE BABEMinor Version Major VersionConstant PoolFlagsThis Class Super Class InterfacesFieldsMethods Attributes http://java.sun.com/docs/books/jvms/second_edition/ClassFileFormat-Java5.pdf Wednesday, November 10, 2010 112. Class File FormatCAFE BABEMinor Version Major VersionConstant PoolFlagsThis Class Super Class InterfacesFieldsMethods Attributes http://java.sun.com/docs/books/jvms/second_edition/ClassFileFormat-Java5.pdf Wednesday, November 10, 2010 113. Class File FormatCAFE BABEMinor Version Major VersionConstant PoolFlagsThis Class Super Class InterfacesFieldsMethods Attributes http://java.sun.com/docs/books/jvms/second_edition/ClassFileFormat-Java5.pdf Wednesday, November 10, 2010 114. Class File FormatCAFE BABEMinor Version Major VersionConstant PoolFlagsThis Class Super Class InterfacesFieldsMethods Attributes http://java.sun.com/docs/books/jvms/second_edition/ClassFileFormat-Java5.pdf Wednesday, November 10, 2010 115. Field FormatFlags NameDescriptorAttributes Wednesday, November 10, 2010 116. Field FormatFlags NameDescriptor pu te d lat ntiva te ile vo ie pr ec ic pr icnsAttributes blotalat tra n Wednesday, November 10, 2010st 117. Field FormatFlags NameDescriptor nameAttributes Wednesday, November 10, 2010 118. Field FormatFlags NameDescriptor Ljava/lang/String;Attributes Wednesday, November 10, 2010 119. Field FormatFlags NameDescriptorAttributes Wednesday, November 10, 2010 120. Field FormatFlags NameDescriptorAttributes ConstantValue Wednesday, November 10, 2010 121. Method FormatFlags NameDescriptorAttributes Wednesday, November 10, 2010 122. Wednesday, November 10, 2010NameFlagsst Method FormatrictfpAttributesnativva e ra rgsDescriptorsy ncn hr al onstize atdpr ic otpr ec iva tepu te dbl ic 123. Method FormatFlags NameDescriptormainAttributes Wednesday, November 10, 2010 124. Method FormatFlags NameDescriptor ([Ljava/lang/String;)VAttributes Wednesday, November 10, 2010 125. Method FormatFlags NameDescriptorAttributes Wednesday, November 10, 2010 126. Method FormatFlags NameDescriptorAttributes Exceptions Wednesday, November 10, 2010 127. Method FormatFlags NameDescriptorAttributes Exceptions Code Wednesday, November 10, 2010 128. Browsing Class File Format JClassLib Viewer http://www.ej-technologies.com/products/jclasslib/overview.html JAD http://www.varaneckas.com/jad Wednesday, November 10, 2010 129. Byte Code Wednesday, November 10, 2010 130. Stack Based Virtual Machine0 iconst_10 1 2 31 iconst_22 iadd3 istore_04 iload_0 Wednesday, November 10, 2010 131. Stack Based Virtual Machine0 iconst_10 1 2 31 iconst_22 iadd3 istore_04 iload_01 Wednesday, November 10, 2010 132. Stack Based Virtual Machine0 iconst_10 1 2 31 iconst_22 iadd3 istore_04 iload_021 Wednesday, November 10, 2010 133. Stack Based Virtual Machine0 iconst_10 1 2 31 iconst_22 iadd3 istore_04 iload_01+2 Wednesday, November 10, 2010 134. Stack Based Virtual Machine0 iconst_10 1 2 31 iconst_22 iadd3 istore_04 iload_03 Wednesday, November 10, 2010 135. Stack Based Virtual Machine0 iconst_10 1 2 31 iconst_232 iadd3 istore_04 iload_0 Wednesday, November 10, 2010 136. Stack Based Virtual Machine0 iconst_10 1 2 31 iconst_232 iadd3 istore_04 iload_03 Wednesday, November 10, 2010 137. Demo Wednesday, November 10, 2010 138. Operation Types Load and Store Arithmetic and Logic Type Conversion Control Transfer Object Creation and Manipulation Operand Stack Method Invocation Wednesday, November 10, 2010 139. Data Typesxre alsns de P ray Locac tsBy tureSt tanCok/ na teSigCoArboolean ZInteger Types byteB bcharC cshort S sint I ilongJ loatF fdoubleD dreference L avoidV Wednesday, November 10, 2010 140. Parameters and Local Variables static int volume( int width, int depth, int height ) { int area = width * depth; int volume = area * height; return volume; } Wednesday, November 10, 2010 141. Parameters and Local Variables static int volume( 0 iload_0 int width, 1 iload_1 int depth, int height ) 2 imul {3 istore_3 int area = width * depth;4 iload_3 int volume = area * height; return volume; 5 iload_2 }6 imul7 istore 49 iload4 11ireturnWednesday, November 10, 2010 142. Parameters and Local Variables static int volume( 0 iload_0 int width, 1 iload_1 int depth, int height ) 2 imul e th lum igh h ptadt { are3 istore_3 de he wi vo 01 2 3 4 int area = width * depth;4 iload_3 int volume = area * height; return volume; 5 iload_2 }6 imul7 istore 49 iload4 11ireturnWednesday, November 10, 2010 143. Parameters and Local Variables static int volume( 0 iload_0 int width, 1 iload_1 int depth, int height ) 2 imul e th lum igh h ptadt { are3 istore_3 de he wi vo 0 1 2 3 4 int area = width * depth; int volume = area * height;4 iload_31 2 3 return volume; 5 iload_2 }6 imul7 istore 49 iload4 11ireturnWednesday, November 10, 2010 144. Parameters and Local Variables static int volume( 0 iload_0 int width, 1 iload_1 int depth, int height ) 2 imul e th lum igh h ptadt { are3 istore_3 de he wi vo 0 1 2 3 4 int area = width * depth; int volume = area * height;4 iload_31 2 3 return volume; 5 iload_2 }6 imul7 istore 49 iload4 11ireturn 1 Wednesday, November 10, 2010 145. Parameters and Local Variables static int volume( 0 iload_0 int width, 1 iload_1 int depth, int height ) 2 imul e th lum igh h ptadt { are3 istore_3 de he wi vo 0 1 2 3 4 int area = width * depth; int volume = area * height;4 iload_31 2 3 return volume; 5 iload_2 }6 imul7 istore 49 iload4 2 11ireturn 1 Wednesday, November 10, 2010 146. Parameters and Local Variables static int volume( 0 iload_0 int width, 1 iload_1 int depth, int height ) 2 imul e th lum igh h ptadt { are3 istore_3 de he wi vo 0 1 2 3 4 int area = width * depth; int volume = area * height;4 iload_31 2 3 return volume; 5 iload_2 }6 imul7 istore 49 iload4 11ireturn 2 Wednesday, November 10, 2010 147. Parameters and Local Variables static int volume( 0 iload_0 int width, 1 iload_1 int depth, int height ) 2 imul e th lum igh h ptadt { are3 istore_3 de he wi vo 0 1 2 3 4 int area = width * depth; int volume = area * height;4 iload_31 2 3 2 return volume; 5 iload_2 }6 imul7 istore 49 iload4 11ireturnWednesday, November 10, 2010 148. Parameters and Local Variables static int volume( 0 iload_0 int width, 1 iload_1 int depth, int height ) 2 imul e th lum igh h ptadt { are3 istore_3 de he wi vo 0 1 2 3 4 int area = width * depth; int volume = area * height;4 iload_31 2 3 2 return volume; 5 iload_2 }6 imul7 istore 49 iload4 11ireturn 2 Wednesday, November 10, 2010 149. Parameters and Local Variables static int volume( 0 iload_0 int width, 1 iload_1 int depth, int height ) 2 imul e th lum igh h ptadt { are3 istore_3 de he wi vo 0 1 2 3 4 int area = width * depth; int volume = area * height;4 iload_31 2 3 2 return volume; 5 iload_2 }6 imul7 istore 49 iload4 3 11ireturn 2 Wednesday, November 10, 2010 150. Parameters and Local Variables static int volume( 0 iload_0 int width, 1 iload_1 int depth, int height ) 2 imul e th lum igh h ptadt { are3 istore_3 de he wi vo 0 1 2 3 4 int area = width * depth; int volume = area * height;4 iload_31 2 3 2 return volume; 5 iload_2 }6 imul7 istore 49 iload4 11ireturn 6 Wednesday, November 10, 2010 151. Parameters and Local Variables static int volume( 0 iload_0 int width, 1 iload_1 int depth, int height ) 2 imul e th lum igh h ptadt { are3 istore_3 de he wi vo 0 1 2 3 4 int area = width * depth; int volume = area * height;4 iload_31 2 3 2 6 return volume; 5 iload_2 }6 imul7 istore 49 iload4 11ireturnWednesday, November 10, 2010 152. Parameters and Local Variables static int volume( 0 iload_0 int width, 1 iload_1 int depth, int height ) 2 imul e th lum igh h ptadt { are3 istore_3 de he wi vo 0 1 2 3 4 int area = width * depth; int volume = area * height;4 iload_31 2 3 2 6 return volume; 5 iload_2 }6 imul7 istore 49 iload4 11ireturn 6 Wednesday, November 10, 2010 153. Parameters and Local Variables static int volume( 0 iload_0 int width, 1 iload_1 int depth, int height ) 2 imul e th lum igh h ptadt { are3 istore_3 de he wi vo 0 1 2 3 4 int area = width * depth; int volume = area * height;4 iload_31 2 3 2 6 return volume; 5 iload_2 }6 imul7 istore 49 iload4 11ireturnWednesday, November 10, 2010 154. Static vs Virtual Methodsstatic int volume(0 iload_0 int width, 1 iload_1 int depth,2 imule int height ) are thlumhigh pta dt {3 istore_3 de he wi vo 01 2 3 4 5 int area = width * depth;4 iload_3 int volume = area * height; return volume; 5 iload_2 }6 imul7 istore 49 iload4 11 ireturnWednesday, November 10, 2010 155. Static vs Virtual Methodsint volume( 0 iload_0 int width, 1 iload_1 int depth,2 imule int height ) are thlumhigh pta dt {3 istore_3 de he wi vo 01 2 3 4 5 int area = width * depth;4 iload_3 int volume = area * height; return volume; 5 iload_2 }6 imul7 istore 49 iload4 11 ireturnWednesday, November 10, 2010 156. Static vs Virtual Methodsint volume( 0 iload_0 int width, 1 iload_1 int depth,2 imule int height ) are t he hlumhigh pta dt s {3 istore_3 de thi wi vo 0 1 2 3 4 5 int area = width * depth;4 iload_3 int volume = area * height; return volume; 5 iload_2 }6 imul7 istore 49 iload4 11 ireturnWednesday, November 10, 2010 157. Static vs Virtual Methodsint volume( 0 iload_1 int width, 1 iload_2 int depth,2 imul e int height )are the h lum h ighpt adts {3 istore4dethiwivo0 1 2 3 4 5 int area = width * depth;5 iload 4 int volume = area * height; return volume; 7 iload_3 }8 imul9 istore5 11 iload 5 13 ireturnWednesday, November 10, 2010 158. Hello World System.out.println( Hello World ); Wednesday, November 10, 2010 159. Hello World System.out.println( Hello World );0 getstaticSystem.out3 ldcHello World5 invokevirtual PrintStream.println8 return Wednesday, November 10, 2010 160. Hello World System.out.println( Hello World );0 1 23 0 getstaticSystem.out3 ldcHello World5 invokevirtual PrintStream.printlnHello World 8 return System.out Wednesday, November 10, 2010 161. Hello World System.out.println( Hello World );0 1 23 0 getstaticSystem.out3 ldcHello World5 invokevirtual PrintStream.printlnHello World 8 return System.out Wednesday, November 10, 2010 162. Hello World System.out.println( Hello World );0 1 23 0 getstaticSystem.out3 ldcHello World5 invokevirtual PrintStream.printlnHello World 8 return System.out Wednesday, November 10, 2010 163. Hello World g smsthi System.out.println( Hello World );0 12 3 0 getstaticSystem.out3 ldcHello World5 invokevirtual PrintStream.printlnHello World 8 return System.out Wednesday, November 10, 2010 164. Types of Method Invocations invokestatic - invoke static methods invokevirtual - invoke instance method from class invokeinterface - invoke instance method from interface invokespecial - invoke / invoke super method Wednesday, November 10, 2010 165. New Objectreturn new BigDecimal(2.0); Wednesday, November 10, 2010 166. New Objectreturn new BigDecimal(2.0);0 newBigDecimal3 dup4 ldc2.06 invokespecialBigDecimal.9 areturn Wednesday, November 10, 2010 167. New Objectreturn new BigDecimal(2.0);0 123 0 newBigDecimal3 dup4 ldc2.02.0 6 invokespecialBigDecimal.9 areturn Wednesday, November 10, 2010 168. New Objectreturn new BigDecimal(2.0);0 1 2 3 0 newBigDecimal3 dup4 ldc2.02.0 6 invokespecialBigDecimal.9 areturn BigDecimal Wednesday, November 10, 2010 169. New Objectreturn new BigDecimal(2.0);0 1 2 3 0 newBigDecimal3 dup4 ldc2.02.0 6 invokespecialBigDecimal.9 areturn BigDecimal Wednesday, November 10, 2010 170. New Objectreturn new BigDecimal(2.0);0 1 2 3 0 newBigDecimal3 dup4 ldc2.02.0 6 invokespecialBigDecimal.9 areturn BigDecimal Wednesday, November 10, 2010 171. New Objectreturn new BigDecimal(2.0);0 1 2 3 0 newBigDecimal3 dup4 ldc2.02.0 6 invokespecialBigDecimal.9 areturn BigDecimal Wednesday, November 10, 2010 172. Demo Wednesday, November 10, 2010 173. If / Else static boolean isPositive( int val ){ if ( val > 0 ) { return true; } else { return false; } } Wednesday, November 10, 2010 174. If / Else static boolean isPositive( int val ){0 iload_0 test if ( val > 0 ) { 1 ie+5 //6 return true;4 iconst_1 } else { if return false;5 ireturn }6 iconst_0 else }7 ireturn Wednesday, November 10, 2010 175. If / Else static boolean isPositive( int val ){0 iload_0 test if ( val > 0 ) { 1 ie+5 //6 return true;4 iconst_1 } else { if return false;5 ireturn }6 iconst_0 else }7 ireturn Wednesday, November 10, 2010 176. If / Else static boolean isPositive( int val ){0 iload_0 test if ( val > 0 ) { 1 ie+5 //6 return true;4 iconst_1 } else { if return false;5 ireturn }6 iconst_0 else }7 ireturn Wednesday, November 10, 2010 177. If / Else static boolean isPositive( int val ){0 iload_0 test if ( val > 0 ) { 1 ie+5 //6 return true;4 iconst_1 } else { if return false;5 ireturn }6 iconst_0 else }7 ireturn Wednesday, November 10, 2010 178. If / Else static boolean isPositive( int val ){0 iload_0 test if ( val > 0 ) { 1 ie+5 //6 return true;4 iconst_1 } else { if return false;5 ireturn }6 iconst_0 else }7 ireturnstatic boolean isPositive( int val ){ return ( val > 0 ); } Wednesday, November 10, 2010 179. If / Else static boolean isPositive( int val ){ if ( val > 0 ) { return true; } else { return false; } }static boolean isPositive( int val ){ return ( val > 0 ); } Wednesday, November 10, 2010 180. If / Else static boolean isPositive( int val ){0 iload_0 test if ( val > 0 ) { 1 ie+5 //6 return true;4 iconst_1 } else { if return false;5 ireturn }6 iconst_0 else }7 ireturnstatic boolean isPositive( int val ){ return ( val > 0 ); } Wednesday, November 10, 2010 181. For Loop static int sum( int min, int max ){ int sum = 0; for ( int i=min; i= nums.length ) { throw new ArrayIndexOutOfBoundsException();}System.out.println( nums[ + i + ]= + nums[ i ] );} http://www.cs.umd.edu/~vibha/330/array-bounds.pdf Wednesday, November 10, 2010 205. Loop Invariant Hoistingfor ( int i = 0; i < nums.length; ++i ) {...} http://java.sun.com/products/hotspot/docs/whitepaper/Java_Hotspot_v1.4.1/Java_HSpot_WP_v1.4.1_1002_4.html Wednesday, November 10, 2010 206. Loop Invariant Hoistingfor ( int i = 0; i < nums.length; ++i ) {...}int length = nums.length;for ( int i = 0; i < length; ++i ) {...}http://java.sun.com/products/hotspot/docs/whitepaper/Java_Hotspot_v1.4.1/Java_HSpot_WP_v1.4.1_1002_4.html Wednesday, November 10, 2010 207. Loop Unrollingint sum = 0;for ( int i = 0; i < 10; ++i ) {sum += i;} Wednesday, November 10, 2010 208. Loop Unrollingint sum = 0;for ( int i = 0; i < 10; ++i ) {sum += i;} int sum = 0;sum += 1;...sum += 9;Wednesday, November 10, 2010 209. Method InliningVector vector = ...double magnitude = vector.magnitude(); http://www.ibm.com/developerworks/library/j-jtp12214/ http://openjdk.java.net/groups/hotspot/docs/HotSpotGlossary.html http://blog.headius.com/2009/01/my-favorite-hotspot-jvm-ags.html http://java.sun.com/developer/technicalArticles/Networking/HotSpot/inlining.html Wednesday, November 10, 2010 210. Method InliningVector vector = ...double magnitude = vector.magnitude();Vector vector = ...double magnitude = Math.sqrt( vector.u*vector.u + vector.v*vector.v ); http://www.ibm.com/developerworks/library/j-jtp12214/ http://openjdk.java.net/groups/hotspot/docs/HotSpotGlossary.html http://blog.headius.com/2009/01/my-favorite-hotspot-jvm-ags.html http://java.sun.com/developer/technicalArticles/Networking/HotSpot/inlining.html Wednesday, November 10, 2010 211. Method InliningVector vector = ...double magnitude = vector.magnitude();Vector vector = ...double magnitude = Math.sqrt( vector.u*vector.u + vector.v*vector.v ); Vector vector = ...double magnitude;if ( vector instance of Vector2D ) {magnitude = Math.sqrt( vector.u*vector.u + vector.v*vector.v );} else {magnitude = vector.magnitude();}http://www.ibm.com/developerworks/library/j-jtp12214/ http://openjdk.java.net/groups/hotspot/docs/HotSpotGlossary.html http://blog.headius.com/2009/01/my-favorite-hotspot-jvm-ags.html http://java.sun.com/developer/technicalArticles/Networking/HotSpot/inlining.html Wednesday, November 10, 2010 212. Method InliningVector vector = ...double magnitude = vector.magnitude();Vector vector = ...static alwaysdouble magnitude = Math.sqrt(nal alwaysvector.u*vector.u + vector.v*vector.v ); privatealwaysVector vector = ...virtualoftendouble magnitude; reectivesometimesif ( vector instance of Vector2D ) {magnitude = Math.sqrt( dynamicoften vector.u*vector.u + vector.v*vector.v );} else {magnitude = vector.magnitude();}http://www.ibm.com/developerworks/library/j-jtp12214/ http://openjdk.java.net/groups/hotspot/docs/HotSpotGlossary.html http://blog.headius.com/2009/01/my-favorite-hotspot-jvm-ags.html http://java.sun.com/developer/technicalArticles/Networking/HotSpot/inlining.html Wednesday, November 10, 2010 213. Lock CoarseningStringBuffer buffer = ...buffer.append( Hello );buffer.append( name );buffer.append( n ); http://java.sun.com/performance/reference/whitepapers/6_performance.html#2.1 Wednesday, November 10, 2010 214. Lock CoarseningStringBuffer buffer = ...buffer.append( Hello );buffer.append( name );buffer.append( n ); StringBuffer buffer = ...lock( buffer ); buffer.append( Hello ); unlock( buffer );lock( buffer ); buffer.append( name ); unlock( buffer );lock( buffer ); buffer.append( n ); unlock( buffer ); http://java.sun.com/performance/reference/whitepapers/6_performance.html#2.1 Wednesday, November 10, 2010 215. Lock CoarseningStringBuffer buffer = ...buffer.append( Hello );buffer.append( name );buffer.append( n ); StringBuffer buffer = ...lock( buffer ); buffer.append( Hello ); unlock( buffer );lock( buffer ); buffer.append( name ); unlock( buffer );lock( buffer ); buffer.append( n ); unlock( buffer ); StringBuffer buffer = ...lock( buffer );buffer.append( Hello );buffer.append( name );buffer.append( n );unlock( buffer ); http://java.sun.com/performance/reference/whitepapers/6_performance.html#2.1 Wednesday, November 10, 2010 216. Other Lock Optimizations Biased Locking Adaptive Locking - Thread sleep vs. Spin lock http://java.sun.com/performance/reference/whitepapers/6_performance.html#2.1 Wednesday, November 10, 2010 217. Escape AnalysisPoint p1 = new Point( x1, y1 ), p2 = new Point( x2, y2 );synchronized ( p1 ) {synchronized ( p2 ) {double dx = p1.getX() - p2.getX();double dy = p1.getY() - p2.getY();double distance = Math.sqrt( dx*dx + dy*dy );}} Wednesday, November 10, 2010 218. Escape Analysis Point p1 = new Point( x1, y1 ), p2 = new Point( x2, y2 ); double dx = p1.getX() - p2.getX(); double dy = p1.getY() - p2.getY(); double distance = Math.sqrt( dx*dx + dy*dy ); Wednesday, November 10, 2010 219. Escape Analysis Point p1 = new Point( x1, y1 ), p2 = new Point( x2, y2 ); double dx = p1.getX() - p2.getX(); double dy = p1.getY() - p2.getY(); double distance = Math.sqrt( dx*dx + dy*dy );double dx = x1 - x2;double dx = y1 - y2;double distance = Math.sqrt( dx*dx + dy*dy ); Wednesday, November 10, 2010 220. Run Time Demo Wednesday, November 10, 2010 221. Is This Optimized?double sumU = 0, sumV = 0;for ( int i = 0; i < 100; ++i ) {Vector2D vector = new Vector2D( i, i );synchronized ( vector ) { sumU += vector.getU(); sumV += vector.getV();}}Wednesday, November 10, 2010 222. Is This Optimized?double sumU = 0, sumV = 0;for ( int i = 0; i < 100; ++i ) {Vector2D vector = new Vector2D( i, i );synchronized ( vector ) { sumU += vector.getU(); How many...? sumV += vector.getV(); Loop Iterations 0}Heap Allocations0} Method Invocations 0 Lock Acquisitions0Wednesday, November 10, 2010