1. JVM Internals
Douglas Q. Hawkins - dougqh@gmail.com
http://www.dougqh.net/
Wednesday, November 10, 2010
2. JVM Internals
Douglas Q. Hawkins - dougqh@gmail.com
http://www.dougqh.net/
http://www.meetup.com/boston-java
Wednesday, November 10, 2010
3. JVM Internals
HotSpot Garbage Collector
HotSpot Optimizations
Class File Format & Byte Code
Compile Time
Run Time
Demos
Presentation Materials
http://www.slideshare.net/dougqh
https://github.com/dougqh
Wednesday, November 10, 2010
5. Garbage Collection
Current HotSpot Collectors
Demos
Garbage First (G1) Collector
Wednesday, November 10, 2010
6. Generational Hypothesis
Generational Hypothesis
92 to 98% objects die young
Few references exist from old objects to new objects
http://www.devx.com/Java/Article/21977
http://www.ibm.com/developerworks/java/library/j-jtp09275.html
http://java.sun.com/j2se/reference/whitepapers/memorymanagement_whitepaper.pdf
Wednesday, November 10, 2010
8. HotSpot Garbage Collector
Young Generation
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
9. HotSpot Garbage Collector
Young Generation
Eden
S1 S2
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 Allocation
Young Generation
Eden
S1 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 Allocation
Young Generation
Eden
S1 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 Allocation
Young Generation
Eden
S1 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 Allocation
Young Generation
Eden
S1 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 Allocation
Young Generation
Eden
S1 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 Allocation
Young Generation
Eden
S1 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 Allocation
Young Generation
Eden
S1 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 Allocation
Young Generation
Eden
S1 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
TLAB
Young Generation
Eden
S1 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
TLAB
Young Generation
Eden
S1 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
TLAB
Young Generation
Eden
S1 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
TLAB
Young Generation
Eden
S1 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
TLAB
Young Generation
Eden
S1 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
TLAB
Young Generation
Eden
S1 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
TLAB
Young Generation
Eden
S1 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
TLAB
Young Generation
Eden
S1 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
TLAB
Young Generation
Eden
S1 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 Collection
TLAB
Young Generation
Eden
S1 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 Collection
TLAB
Young Generation
Eden
S1 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 Collection
TLAB
Young Generation
Eden
S1 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 Collection
Young Generation
Eden
S1 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 Collection
Young Generation
Eden
S1 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 Collection
Young Generation
Eden
S1 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 Collection
Young Generation
Eden
S1 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 Collection
Young Generation
Eden
S1 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 Collection
Young Generation
Eden
S1 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 Collection
Young Generation
Eden
S1 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 Collection
Young Generation
Eden
S1 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 Thread
http://www.austinjug.org/presentations/JDK6PerfUpdate_Dec2009.pdf
Wednesday, November 10, 2010
39. Stop the World!
Application Thread GC Thread
http://www.austinjug.org/presentations/JDK6PerfUpdate_Dec2009.pdf
Wednesday, November 10, 2010
40. Application Thread GC Thread
http://www.austinjug.org/presentations/JDK6PerfUpdate_Dec2009.pdf
Wednesday, November 10, 2010
41. Serial
Application Thread GC Thread
http://www.austinjug.org/presentations/JDK6PerfUpdate_Dec2009.pdf
Wednesday, November 10, 2010
42. Serial Parallel
Application Thread GC Thread
http://www.austinjug.org/presentations/JDK6PerfUpdate_Dec2009.pdf
Wednesday, November 10, 2010
44. Major Collection
Young Generation
Eden
S1 S2
Old Generation
http://www.devx.com/Java/Article/21977/0
http://www.austinjug.org/presentations/JDK6PerfUpdate_Dec2009.pdf
http://java.sun.com/j2se/reference/whitepapers/memorymanagement_whitepaper.pdf
Wednesday, November 10, 2010
45. Major Collection
Young Generation
Eden
S1 S2
Old Generation
http://www.devx.com/Java/Article/21977/0
http://www.austinjug.org/presentations/JDK6PerfUpdate_Dec2009.pdf
http://java.sun.com/j2se/reference/whitepapers/memorymanagement_whitepaper.pdf
Wednesday, November 10, 2010
46. Major Collection
Young Generation
Eden
S1 S2
Old Generation
http://www.devx.com/Java/Article/21977/0
http://www.austinjug.org/presentations/JDK6PerfUpdate_Dec2009.pdf
http://java.sun.com/j2se/reference/whitepapers/memorymanagement_whitepaper.pdf
Wednesday, November 10, 2010
47. Major Collection
Young Generation
Eden
S1 S2
Old Generation
http://www.devx.com/Java/Article/21977/0
http://www.austinjug.org/presentations/JDK6PerfUpdate_Dec2009.pdf
http://java.sun.com/j2se/reference/whitepapers/memorymanagement_whitepaper.pdf
Wednesday, November 10, 2010
48. Major Collection
Young Generation
Eden
S1 S2
Old Generation
http://www.devx.com/Java/Article/21977/0
http://www.austinjug.org/presentations/JDK6PerfUpdate_Dec2009.pdf
http://java.sun.com/j2se/reference/whitepapers/memorymanagement_whitepaper.pdf
Wednesday, November 10, 2010
49. Major Collection
Young Generation
Eden
S1 S2
Old Generation
http://www.devx.com/Java/Article/21977/0
http://www.austinjug.org/presentations/JDK6PerfUpdate_Dec2009.pdf
http://java.sun.com/j2se/reference/whitepapers/memorymanagement_whitepaper.pdf
Wednesday, November 10, 2010
50. Major Collection
Young Generation
Eden
S1 S2
Old Generation
http://www.devx.com/Java/Article/21977/0
http://www.austinjug.org/presentations/JDK6PerfUpdate_Dec2009.pdf
http://java.sun.com/j2se/reference/whitepapers/memorymanagement_whitepaper.pdf
Wednesday, November 10, 2010
51. Major Collection
Young Generation
Eden
S1 S2
Old Generation
http://www.devx.com/Java/Article/21977/0
http://www.austinjug.org/presentations/JDK6PerfUpdate_Dec2009.pdf
http://java.sun.com/j2se/reference/whitepapers/memorymanagement_whitepaper.pdf
Wednesday, November 10, 2010
52. Major Collection
Young Generation
Eden
S1 S2
Old Generation
http://www.devx.com/Java/Article/21977/0
http://www.austinjug.org/presentations/JDK6PerfUpdate_Dec2009.pdf
http://java.sun.com/j2se/reference/whitepapers/memorymanagement_whitepaper.pdf
Wednesday, November 10, 2010
53. Major Collection
Young Generation
Eden
S1 S2
Old Generation
http://www.devx.com/Java/Article/21977/0
http://www.austinjug.org/presentations/JDK6PerfUpdate_Dec2009.pdf
http://java.sun.com/j2se/reference/whitepapers/memorymanagement_whitepaper.pdf
Wednesday, November 10, 2010
54. Major Collection
Young Generation
Eden
S1 S2
Old Generation
http://www.devx.com/Java/Article/21977/0
http://www.austinjug.org/presentations/JDK6PerfUpdate_Dec2009.pdf
http://java.sun.com/j2se/reference/whitepapers/memorymanagement_whitepaper.pdf
Wednesday, November 10, 2010
55. Serial Mark Parallel Mark
Sweep & Compact Sweep & Compact
Application Thread GC Thread
http://www.devx.com/Java/Article/21977/0/page/3
http://www.austinjug.org/presentations/JDK6PerfUpdate_Dec2009.pdf
Wednesday, November 10, 2010
56. Serial Mark Parallel Mark
Sweep & Compact Sweep & Compact
Application Thread GC Thread
http://www.devx.com/Java/Article/21977/0/page/3
http://www.austinjug.org/presentations/JDK6PerfUpdate_Dec2009.pdf
Wednesday, November 10, 2010
57. Serial Mark Parallel Mark
Sweep & Compact Sweep & Compact
Concurrent Mark & Sweep
Application Thread GC Thread
http://www.devx.com/Java/Article/21977/0/page/3
http://www.austinjug.org/presentations/JDK6PerfUpdate_Dec2009.pdf
Wednesday, November 10, 2010
58. Serial Mark Parallel Mark
Sweep & Compact Sweep & Compact
Concurrent Mark & Sweep
Concurrent
Marking
Remark
Concurrent
Sweep
Application Thread GC Thread
http://www.devx.com/Java/Article/21977/0/page/3
http://www.austinjug.org/presentations/JDK6PerfUpdate_Dec2009.pdf
Wednesday, November 10, 2010
60. Permanent Generation
Young Generation
Eden
S1 S2
Old Generation
http://opensource.atlassian.com/confluence/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
S1 S2
Old Generation
Permanent Generation
http://opensource.atlassian.com/confluence/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
S1 S2
Old Generation
Permanent Generation
Bootstrap App Server Web Application
http://opensource.atlassian.com/confluence/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
S1 S2
Old Generation
Permanent Generation
Bootstrap App Server Web Application
http://opensource.atlassian.com/confluence/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
S1 S2
Old Generation
Permanent Generation
Bootstrap App Server Web Application
http://opensource.atlassian.com/confluence/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
S1 S2
Old Generation
Permanent Generation
Bootstrap App Server Web Application
http://opensource.atlassian.com/confluence/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
S1 S2
Old Generation
Permanent Generation
Bootstrap App Server
http://opensource.atlassian.com/confluence/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
68. Java 6 Collectors
Parallel Parallel
Young Serial
New Scavenge
Serial Old Concurrent
Parallel
Old (Mark Sweep Mark &
Old
Compact) Sweep
http://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
Parallel Parallel
Young Serial
New Scavenge
Serial Old Concurrent
Parallel
Old (Mark Sweep Mark &
Old
Compact) Sweep
http://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
Parallel Parallel
Young Serial
New Scavenge
Serial Old Concurrent
Parallel
Old (Mark Sweep Mark &
Old
Compact) Sweep
http://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
Parallel Parallel
Young Serial
New Scavenge
Serial Old Concurrent
Parallel
Old (Mark Sweep Mark &
Old
Compact) Sweep
http://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
Parallel Parallel
Young Serial
New Scavenge
Serial Old Concurrent
Parallel
Old (Mark Sweep Mark &
Old
Compact) Sweep
http://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
Parallel Parallel
Young Serial
New Scavenge
Serial Old Concurrent
Parallel
Old (Mark Sweep Mark &
Old
Compact) Sweep
http://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
Parallel Parallel
Young Serial
New Scavenge
Serial Old Concurrent
Parallel
Old (Mark Sweep Mark &
Old
Compact) Sweep
http://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
Parallel Parallel
Young Serial
New Scavenge
G1
Serial Old Concurrent
Parallel
Old (Mark Sweep Mark &
Old
Compact) Sweep
http://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 First
Heap
http://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 First
Unused
http://developers.sun.com/learning/javaoneonline/2008/pdf/TS-5419.pdf
Wednesday, November 10, 2010
79. G1 - Garbage First
Unused Young
http://developers.sun.com/learning/javaoneonline/2008/pdf/TS-5419.pdf
Wednesday, November 10, 2010
80. G1 - Garbage First
Unused Young Old
http://developers.sun.com/learning/javaoneonline/2008/pdf/TS-5419.pdf
Wednesday, November 10, 2010
81. G1 - Minor Collection
Unused Young Old
Wednesday, November 10, 2010
82. G1 - Minor Collection
Unused Young Old
Wednesday, November 10, 2010
83. G1 - Minor Collection
Unused Young Old
Wednesday, November 10, 2010
84. G1 - Minor Collection
Unused Young Old
Wednesday, November 10, 2010
85. G1 - Minor Collection
Unused Young Old
Wednesday, November 10, 2010
86. G1 - Minor Collection
Unused Young Old
Wednesday, November 10, 2010
87. G1 - Minor Collection
Unused Young Old
Wednesday, November 10, 2010
88. G1 - Minor Collection
Unused Young Old
Wednesday, November 10, 2010
89. G1 - Minor Collection
Unused Young Old
Wednesday, November 10, 2010
90. G1 - Major Collection
Unused Young Old
Wednesday, November 10, 2010
91. G1 - Major Collection
Unused Young Old
Wednesday, November 10, 2010
92. G1 - Major Collection
Unused Young Old
Wednesday, November 10, 2010
93. G1 - Major Collection
Unused Young Old
Wednesday, November 10, 2010
94. G1 - Major Collection
Unused Young Old
Wednesday, November 10, 2010
95. G1 - Major Collection
Unused Young Old
Wednesday, November 10, 2010
96. G1 - Major Collection
Unused Young Old
Wednesday, November 10, 2010
97. G1 - Major Collection
Unused Young Old
Wednesday, November 10, 2010
98. G1 - Major Collection
Unused Young Old
Wednesday, November 10, 2010
103. Class File Format & Byte Code
Class File Layout & Parts
Introduction to Byte Code
Examples of Java Compiled to Byte Code
Wednesday, November 10, 2010
104. Class File Format
CA FE BA BE Minor Version Major Version
Constant Pool
Flags This Class Super Class
Interfaces
Fields
Methods
Attributes
http://java.sun.com/docs/books/jvms/second_edition/ClassFileFormat-Java5.pdf
Wednesday, November 10, 2010
105. Class File Format
CA FE BA BE Minor Version Major Version
Constant Pool
Flags This Class Super Class
Interfaces
Fields
Methods
Attributes
http://java.sun.com/docs/books/jvms/second_edition/ClassFileFormat-Java5.pdf
Wednesday, November 10, 2010
106. Class File Format
CA FE BA BE Minor Version Major Version
Constant Pool
Flags This Class Super Class
Interfaces
Fields
Methods
Attributes
http://java.sun.com/docs/books/jvms/second_edition/ClassFileFormat-Java5.pdf
Wednesday, November 10, 2010
107. Class File Format
CA FE BA BE Minor Version Major Version
Constant Pool
Flags This Class Super Class
Interfaces
Fields
Methods
Attributes
http://java.sun.com/docs/books/jvms/second_edition/ClassFileFormat-Java5.pdf
Wednesday, November 10, 2010
108. Class File Format
CA FE BA BE Minor Version Major Version
Constant Pool
n
Flags This Class Super Class
pu te d
tio
ce
iva te
er ct
ta
ab tfp
pr ec
int ra
fa
ic
um
pr ic
no
Interfaces
st
bl
ric
ot
al
at
en
an
fin
st
st
Fields
Methods
Attributes
http://java.sun.com/docs/books/jvms/second_edition/ClassFileFormat-Java5.pdf
Wednesday, November 10, 2010
109. Class File Format
CA FE BA BE Minor Version Major Version
Constant Pool
Flags This Class Super Class
Interfaces
Fields
Methods
Attributes
http://java.sun.com/docs/books/jvms/second_edition/ClassFileFormat-Java5.pdf
Wednesday, November 10, 2010
110. Class File Format
CA FE BA BE Minor Version Major Version
Constant Pool
Flags This Class Super Class
Interfaces
Fields
Methods
Attributes
http://java.sun.com/docs/books/jvms/second_edition/ClassFileFormat-Java5.pdf
Wednesday, November 10, 2010
111. Class File Format
CA FE BA BE Minor Version Major Version
Constant Pool
Flags This Class Super Class
Interfaces
Fields
Methods
Attributes
http://java.sun.com/docs/books/jvms/second_edition/ClassFileFormat-Java5.pdf
Wednesday, November 10, 2010
112. Class File Format
CA FE BA BE Minor Version Major Version
Constant Pool
Flags This Class Super Class
Interfaces
Fields
Methods
Attributes
http://java.sun.com/docs/books/jvms/second_edition/ClassFileFormat-Java5.pdf
Wednesday, November 10, 2010
113. Class File Format
CA FE BA BE Minor Version Major Version
Constant Pool
Flags This Class Super Class
Interfaces
Fields
Methods
Attributes
http://java.sun.com/docs/books/jvms/second_edition/ClassFileFormat-Java5.pdf
Wednesday, November 10, 2010
114. Class File Format
CA FE BA BE Minor Version Major Version
Constant Pool
Flags This Class Super Class
Interfaces
Fields
Methods
Attributes
http://java.sun.com/docs/books/jvms/second_edition/ClassFileFormat-Java5.pdf
Wednesday, November 10, 2010
115. Field Format
Flags Name Descriptor
Attributes
Wednesday, November 10, 2010
116. Field Format
Flags Name Descriptor
pu te d
lat nt
iva te
ile
vo ie
pr ec
ic
pr ic
ns
Attributes
bl
ot
al
at
tra
fin
Wednesday, November 10, 2010 st
117. Field Format
Flags Name Descriptor
“name”
Attributes
Wednesday, November 10, 2010
118. Field Format
Flags Name Descriptor “Ljava/lang/String;”
Attributes
Wednesday, November 10, 2010
119. Field Format
Flags Name Descriptor
Attributes
Wednesday, November 10, 2010
120. Field Format
Flags Name Descriptor
Attributes
ConstantValue
Wednesday, November 10, 2010
121. Method Format
Flags Name Descriptor
Attributes
Wednesday, November 10, 2010
122. Wednesday, November 10, 2010
Name Flags
st
Method Format
ric
tfp
Attributes
na
tiv
va e
ra
rg
s
Descriptor
sy
nc
fin hr
al on
st ize
at d
pr ic
ot
pr ec
iva te
pu te d
bl
ic
123. Method Format
Flags Name Descriptor
“main”
Attributes
Wednesday, November 10, 2010
124. Method Format
Flags Name Descriptor “([Ljava/lang/String;)V”
Attributes
Wednesday, November 10, 2010
125. Method Format
Flags Name Descriptor
Attributes
Wednesday, November 10, 2010
126. Method Format
Flags Name Descriptor
Attributes
Exceptions
Wednesday, November 10, 2010
127. Method Format
Flags Name Descriptor
Attributes
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
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 Types
x
refi
als
ns de P
ray Loc
ac ts
By ture
St tan
Co
k/
na
te
Sig
Co
Ar
boolean Z
Integer Types
byte B b
char C c
short S s
int I i
long J l
float F f
double D d
reference L a
void V
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 imul
7 istore 4
9 iload 4
11ireturn
Wednesday, 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
t
h
lum
igh
h
pt
a
dt
{
are
3 istore_3
de
he
wi
vo
0 1 2 3 4
int area = width * depth;
4 iload_3
int volume = area * height;
return volume; 5 iload_2
}
6 imul
7 istore 4
9 iload 4
11ireturn
Wednesday, 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
t
h
lum
igh
h
pt
a
dt
{
are
3 istore_3
de
he
wi
vo
0 1 2 3 4
int area = width * depth;
int volume = area * height;
4 iload_3 1 2 3
return volume; 5 iload_2
}
6 imul
7 istore 4
9 iload 4
11ireturn
Wednesday, 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
t
h
lum
igh
h
pt
a
dt
{
are
3 istore_3
de
he
wi
vo
0 1 2 3 4
int area = width * depth;
int volume = area * height;
4 iload_3 1 2 3
return volume; 5 iload_2
}
6 imul
7 istore 4
9 iload 4
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
t
h
lum
igh
h
pt
a
dt
{
are
3 istore_3
de
he
wi
vo
0 1 2 3 4
int area = width * depth;
int volume = area * height;
4 iload_3 1 2 3
return volume; 5 iload_2
}
6 imul
7 istore 4
9 iload 4 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
t
h
lum
igh
h
pt
a
dt
{
are
3 istore_3
de
he
wi
vo
0 1 2 3 4
int area = width * depth;
int volume = area * height;
4 iload_3 1 2 3
return volume; 5 iload_2
}
6 imul
7 istore 4
9 iload 4
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
t
h
lum
igh
h
pt
a
dt
{
are
3 istore_3
de
he
wi
vo
0 1 2 3 4
int area = width * depth;
int volume = area * height;
4 iload_3 1 2 3 2
return volume; 5 iload_2
}
6 imul
7 istore 4
9 iload 4
11ireturn
Wednesday, 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
t
h
lum
igh
h
pt
a
dt
{
are
3 istore_3
de
he
wi
vo
0 1 2 3 4
int area = width * depth;
int volume = area * height;
4 iload_3 1 2 3 2
return volume; 5 iload_2
}
6 imul
7 istore 4
9 iload 4
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
t
h
lum
igh
h
pt
a
dt
{
are
3 istore_3
de
he
wi
vo
0 1 2 3 4
int area = width * depth;
int volume = area * height;
4 iload_3 1 2 3 2
return volume; 5 iload_2
}
6 imul
7 istore 4
9 iload 4 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
t
h
lum
igh
h
pt
a
dt
{
are
3 istore_3
de
he
wi
vo
0 1 2 3 4
int area = width * depth;
int volume = area * height;
4 iload_3 1 2 3 2
return volume; 5 iload_2
}
6 imul
7 istore 4
9 iload 4
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
t
h
lum
igh
h
pt
a
dt
{
are
3 istore_3
de
he
wi
vo
0 1 2 3 4
int area = width * depth;
int volume = area * height;
4 iload_3 1 2 3 2 6
return volume; 5 iload_2
}
6 imul
7 istore 4
9 iload 4
11ireturn
Wednesday, 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
t
h
lum
igh
h
pt
a
dt
{
are
3 istore_3
de
he
wi
vo
0 1 2 3 4
int area = width * depth;
int volume = area * height;
4 iload_3 1 2 3 2 6
return volume; 5 iload_2
}
6 imul
7 istore 4
9 iload 4
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
t
h
lum
igh
h
pt
a
dt
{
are
3 istore_3
de
he
wi
vo
0 1 2 3 4
int area = width * depth;
int volume = area * height;
4 iload_3 1 2 3 2 6
return volume; 5 iload_2
}
6 imul
7 istore 4
9 iload 4
11ireturn
Wednesday, November 10, 2010
154. Static vs Virtual Methods
static int volume( 0 iload_0
int width, 1 iload_1
int depth,
2 imul
e
int height )
are t
h
lum
h
igh
pt
a
dt
{ 3 istore_3
de
he
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 imul
7 istore 4
9 iload 4
11 ireturn
Wednesday, November 10, 2010
155. Static vs Virtual Methods
int volume( 0 iload_0
int width, 1 iload_1
int depth,
2 imul
e
int height )
are t
h
lum
h
igh
pt
a
dt
{ 3 istore_3
de
he
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 imul
7 istore 4
9 iload 4
11 ireturn
Wednesday, November 10, 2010
156. Static vs Virtual Methods
int volume( 0 iload_0
int width, 1 iload_1
int depth,
2 imul
e
int height )
are t
he h
lum
h
igh
pt
a
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 imul
7 istore 4
9 iload 4
11 ireturn
Wednesday, November 10, 2010
157. Static vs Virtual Methods
int volume( 0 iload_1
int width, 1 iload_2
int depth,
2 imul
e
int height )
are t
he h
lum
h
igh
pt
a
dt
s
{ 3 istore 4
de
thi
wi
vo
0 1 2 3 4 5
int area = width * depth;
5 iload 4
int volume = area * height;
return volume; 7 iload_3
} 8 imul
9 istore 5
11 iload 5
13 ireturn
Wednesday, November 10, 2010
158. Hello World
System.out.println( “Hello World” );
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 ifle +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 ifle +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 ifle +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 ifle +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 ifle +5 //6
return true;
4 iconst_1
} else {
if
return false; 5 ireturn
} 6 iconst_0
else
} 7 ireturn
static 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 ifle +5 //6
return true;
4 iconst_1
} else {
if
return false; 5 ireturn
} 6 iconst_0
else
} 7 ireturn
static 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<max; ++i ){
sum += i;
}
return sum;
}
Wednesday, November 10, 2010
182. before
0 iconst_0
For Loop
init & test loop
1 istore_2
2 iload_1
static int sum( int min, int max ){ 3 istore_3
int sum = 0; 4 goto +10 //14
for ( int i=min; i<max; ++i ){ 7 iload_2
loop body
sum += i; 8 iload_3
} 9 iadd
return sum;
10 istore_2
}
inc
11 iinc 3 by 1
14 iload_3
test 15 iload_1
16 if_icmplt -9 //7
19 iload_2
after
loop
20 ireturn
Wednesday, November 10, 2010
183. before
0 iconst_0
For Loop
init & test loop
1 istore_2
2 iload_1
static int sum( int min, int max ){ 3 istore_3
int sum = 0; 4 goto +10 //14
for ( int i=min; i<max; ++i ){ 7 iload_2
loop body
sum += i; 8 iload_3
} 9 iadd
return sum;
10 istore_2
}
inc
11 iinc 3 by 1
14 iload_3
test 15 iload_1
16 if_icmplt -9 //7
19 iload_2
after
loop
20 ireturn
Wednesday, November 10, 2010
184. before
0 iconst_0
For Loop
init & test loop
1 istore_2
2 iload_1
static int sum( int min, int max ){ 3 istore_3
int sum = 0; 4 goto +10 //14
for ( int i=min; i<max; ++i ){ 7 iload_2
loop body
sum += i; 8 iload_3
} 9 iadd
return sum;
10 istore_2
}
inc
11 iinc 3 by 1
14 iload_3
test 15 iload_1
16 if_icmplt -9 //7
19 iload_2
after
loop
20 ireturn
Wednesday, November 10, 2010
185. before
0 iconst_0
For Loop
init & test loop
1 istore_2
2 iload_1
static int sum( int min, int max ){ 3 istore_3
int sum = 0; 4 goto +10 //14
for ( int i=min; i<max; ++i ){ 7 iload_2
loop body
sum += i; 8 iload_3
} 9 iadd
return sum;
10 istore_2
}
inc
11 iinc 3 by 1
14 iload_3
test 15 iload_1
16 if_icmplt -9 //7
19 iload_2
after
loop
20 ireturn
Wednesday, November 10, 2010
186. before
0 iconst_0
For Loop
init & test loop
1 istore_2
2 iload_1
static int sum( int min, int max ){ 3 istore_3
int sum = 0; 4 goto +10 //14
for ( int i=min; i<max; ++i ){ 7 iload_2
loop body
sum += i; 8 iload_3
} 9 iadd
return sum;
10 istore_2
}
inc
11 iinc 3 by 1
14 iload_3
test 15 iload_1
16 if_icmplt -9 //7
19 iload_2
after
loop
20 ireturn
Wednesday, November 10, 2010
187. before
0 iconst_0
For Loop
init & test loop
1 istore_2
2 iload_1
static int sum( int min, int max ){ 3 istore_3
int sum = 0; 4 goto +10 //14
for ( int i=min; i<max; ++i ){ 7 iload_2
loop body
sum += i; 8 iload_3
} 9 iadd
return sum;
10 istore_2
}
inc
11 iinc 3 by 1
14 iload_3
test 15 iload_1
16 if_icmplt -9 //7
19 iload_2
after
loop
20 ireturn
Wednesday, November 10, 2010
188. before
0 iconst_0
For Loop
init & test loop
1 istore_2
2 iload_1
static int sum( int min, int max ){ 3 istore_3
int sum = 0; 4 goto +10 //14
for ( int i=min; i<max; ++i ){ 7 iload_2
loop body
sum += i; 8 iload_3
} 9 iadd
return sum;
10 istore_2
}
inc
11 iinc 3 by 1
14 iload_3
test 15 iload_1
16 if_icmplt -9 //7
19 iload_2
after
loop
20 ireturn
Wednesday, November 10, 2010
189. Exception Handling
static int read( InputStream in ) {
try {
return in.read();
} catch ( IOException e ) {
return -1;
} finally {
IoUtils.closeQuietly( in );
}
}
Wednesday, November 10, 2010