SlideShare uma empresa Scribd logo
1 de 36
Let’s Talk about
Java Class File
Yongqiang Li
Outlines
 Brief
      Introduction to Java Class File
 Java Class Format and Layout
 References
Brief Introduction to Java Class
 File
 Has  .class extension
 Compiled from java source files (.java)
 Platform-independent
 Machine-readable
 Stores so-called “bytecodes”
Java Source File (ClassA.java)

                                      javac ClassA.java




     Java Class File (ClassA.class)
 Bytecode
 Only   “javac” can generate class file?

          JRuby                   Clojure




Jython             Java Class


          Groovy                   Scala
Java Class Format and Layout
   Class File contains different sections.
       Magic Number
       Version of Class File Format
       Constant Pool
       Access Flags
       This Class
       Super Class
       Interfaces
       Fields
       Methods
       Attributes
Magic Number
4 bytes
 Always “CAFEBABE” ( 咖啡宝贝 )
Version of Class File Format

  2  bytes for minor version
   2 bytes for major version
   Java major version starts from 45 (JDK 1.1)
   Java SE 5 is 49, SE 6 is 50 (0x32), SE 7 is 51.
Constant Pool
2  bytes used to store constant count
 Index of constant starts from 1 not 0.
Tag Byte   Constant Type           Additional Bytes
0x01       UTF8-String             2+x
0x03       Integer                 4 (Big endian)
0x04       Float                   4 (IEEE 754 floating-
                                   point)
0x05       Long                    8 (Big endian)

0x06       Double                  8 (IEEE 754 floating-
                                   point)
0x07       Class Reference         2
0x08       String Reference        2
0x09       Field Reference         2+2 (first 2 for class
                                   Ref)
0x0A       Method Reference        2+2 (first 2 for class
                                   Ref)
0x0B       Interface Method Ref.   2+2 (first 2 for class
                                   Ref)
0x0C       Name and Type Ref.      2+2
 Constant    Count




 0x0021(hex) = 33 (dec)
 Double




           • 0x06: Double Tag
           • 0x4000 1893 74bc 6a7f: 2.012
• 0x01: UTF-8 Tag
 UTF-8   • 0x0006: “String” has 6 char.
          • 0x5374 7269 6367: “String”
 More   Strings
    Field/Method
     Name
    Field/Method
     Type
    Attribute Name
 Class   Reference




                      • 0x07: Class Ref Tag
                      • 0x0002: Constant Index
Access Flags

 For Class
 2 Bytes
This and Super
  Both  are 2 bytes
  Direct to Class Reference in Constant
   Pool.




This Ref: 0x0001
Super Ref: 0x0003
Interfaces
2  bytes for count of interfaces
 2 * interfaces_count bytes
Fields
2  bytes for fields count
 field_info * fields_count
 Attribute   Structure
 Field   Access
     2 bytes
•   0x0001: Only 1 Field
•   0x0019: public static final
•   0x0005: “obj”
•   0x0006: Descriptor “Ljava/lang/Object;”
•   0x0002: 2 Attributes
     • 1st: 0x0007 (Deprecated)
     • 2nd: 0x0008 (RuntimeVisibleAnnotations)
Methods
2 bytes for methods count
 method_info * methods_count

                          Method Access Flags
 Method Attributes
 CodeAttributes
•   Max Stack: 2
•   Max Locals: 3
•   Args Size: 2
•   Code:
 JVM   Opcode
    Based on stack
     not register
    About 200
     opcode in JVM 6
 0: push the integer in
  slot 0 to stack
 1: push the integer in
  slot 1 to stack
 2: add first 2 integers in
  stack and result will be
  push into stack
 3: load the integer
  from stack top to
  integer in slot 2
 4: push the integer in
  slot 2 to stack
 5: return an integer
 Exception   Attributes
Who can help me on this?
 Magic Number
 Version of Class File Format
 Constant Pool
 Access Flags
 This Class
 Super Class
 Interfaces
 Fields
 Methods
 Attributes
References
 JVM
    6 Specification
 《深入浅出 Java 虚拟机》
Let's talk about java class file

Mais conteúdo relacionado

Mais procurados

Core Java Basics
Core Java BasicsCore Java Basics
Core Java Basicsmhtspvtltd
 
9781439035665 ppt ch08
9781439035665 ppt ch089781439035665 ppt ch08
9781439035665 ppt ch08Terry Yoast
 
Fundamentals of oop lecture 2
Fundamentals of oop lecture 2Fundamentals of oop lecture 2
Fundamentals of oop lecture 2miiro30
 
Ifi7184 lesson7
Ifi7184 lesson7Ifi7184 lesson7
Ifi7184 lesson7Sónia
 
Java IO Package and Streams
Java IO Package and StreamsJava IO Package and Streams
Java IO Package and Streamsbabak danyal
 
Lecture - 2 Environment setup & JDK, JRE, JVM
Lecture - 2 Environment setup & JDK, JRE, JVMLecture - 2 Environment setup & JDK, JRE, JVM
Lecture - 2 Environment setup & JDK, JRE, JVMmanish kumar
 
Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)arvind pandey
 
What is java input and output stream?
What is java input and output stream?What is java input and output stream?
What is java input and output stream?kanchanmahajan23
 

Mais procurados (10)

Java Advanced Features
Java Advanced FeaturesJava Advanced Features
Java Advanced Features
 
Core Java Basics
Core Java BasicsCore Java Basics
Core Java Basics
 
9781439035665 ppt ch08
9781439035665 ppt ch089781439035665 ppt ch08
9781439035665 ppt ch08
 
Chap01
Chap01Chap01
Chap01
 
Fundamentals of oop lecture 2
Fundamentals of oop lecture 2Fundamentals of oop lecture 2
Fundamentals of oop lecture 2
 
Ifi7184 lesson7
Ifi7184 lesson7Ifi7184 lesson7
Ifi7184 lesson7
 
Java IO Package and Streams
Java IO Package and StreamsJava IO Package and Streams
Java IO Package and Streams
 
Lecture - 2 Environment setup & JDK, JRE, JVM
Lecture - 2 Environment setup & JDK, JRE, JVMLecture - 2 Environment setup & JDK, JRE, JVM
Lecture - 2 Environment setup & JDK, JRE, JVM
 
Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)
 
What is java input and output stream?
What is java input and output stream?What is java input and output stream?
What is java input and output stream?
 

Semelhante a Let's talk about java class file

Java user group 2015 02-09-java8
Java user group 2015 02-09-java8Java user group 2015 02-09-java8
Java user group 2015 02-09-java8marctritschler
 
Java user group 2015 02-09-java8
Java user group 2015 02-09-java8Java user group 2015 02-09-java8
Java user group 2015 02-09-java8Marc Tritschler
 
บทที่ 4 การเพิ่มข้อมูลลงฐานข้อมูล
บทที่ 4 การเพิ่มข้อมูลลงฐานข้อมูลบทที่ 4 การเพิ่มข้อมูลลงฐานข้อมูล
บทที่ 4 การเพิ่มข้อมูลลงฐานข้อมูลPriew Chakrit
 
4.เพิ่มข้อมูลลง DB ด้วย JSP&SQL
4.เพิ่มข้อมูลลง DB ด้วย JSP&SQL4.เพิ่มข้อมูลลง DB ด้วย JSP&SQL
4.เพิ่มข้อมูลลง DB ด้วย JSP&SQLsquall1735
 
บท4
บท4บท4
บท4bank_b
 
Java input output package
Java input output packageJava input output package
Java input output packageSujit Kumar
 
Harder Faster Stronger
Harder Faster StrongerHarder Faster Stronger
Harder Faster Strongersnyff
 
ORC File & Vectorization - Improving Hive Data Storage and Query Performance
ORC File & Vectorization - Improving Hive Data Storage and Query PerformanceORC File & Vectorization - Improving Hive Data Storage and Query Performance
ORC File & Vectorization - Improving Hive Data Storage and Query PerformanceDataWorks Summit
 
ORC File and Vectorization - Hadoop Summit 2013
ORC File and Vectorization - Hadoop Summit 2013ORC File and Vectorization - Hadoop Summit 2013
ORC File and Vectorization - Hadoop Summit 2013Owen O'Malley
 
Scala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud FoundryScala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud FoundryPray Desai
 
Lecture 8 strings and characters
Lecture 8  strings and charactersLecture 8  strings and characters
Lecture 8 strings and charactersalvin567
 

Semelhante a Let's talk about java class file (20)

บทที่4
บทที่4บทที่4
บทที่4
 
Java user group 2015 02-09-java8
Java user group 2015 02-09-java8Java user group 2015 02-09-java8
Java user group 2015 02-09-java8
 
Java user group 2015 02-09-java8
Java user group 2015 02-09-java8Java user group 2015 02-09-java8
Java user group 2015 02-09-java8
 
Java Day-6
Java Day-6Java Day-6
Java Day-6
 
บทที่ 4 การเพิ่มข้อมูลลงฐานข้อมูล
บทที่ 4 การเพิ่มข้อมูลลงฐานข้อมูลบทที่ 4 การเพิ่มข้อมูลลงฐานข้อมูล
บทที่ 4 การเพิ่มข้อมูลลงฐานข้อมูล
 
4.เพิ่มข้อมูลลง DB ด้วย JSP&SQL
4.เพิ่มข้อมูลลง DB ด้วย JSP&SQL4.เพิ่มข้อมูลลง DB ด้วย JSP&SQL
4.เพิ่มข้อมูลลง DB ด้วย JSP&SQL
 
บท4
บท4บท4
บท4
 
บท4
บท4บท4
บท4
 
Introduction_to_Java.ppt
Introduction_to_Java.pptIntroduction_to_Java.ppt
Introduction_to_Java.ppt
 
Java input output package
Java input output packageJava input output package
Java input output package
 
Java quick reference v2
Java quick reference v2Java quick reference v2
Java quick reference v2
 
java training faridabad
java training faridabadjava training faridabad
java training faridabad
 
Java quickref
Java quickrefJava quickref
Java quickref
 
Harder Faster Stronger
Harder Faster StrongerHarder Faster Stronger
Harder Faster Stronger
 
Java14
Java14Java14
Java14
 
Java Tutorials
Java Tutorials Java Tutorials
Java Tutorials
 
ORC File & Vectorization - Improving Hive Data Storage and Query Performance
ORC File & Vectorization - Improving Hive Data Storage and Query PerformanceORC File & Vectorization - Improving Hive Data Storage and Query Performance
ORC File & Vectorization - Improving Hive Data Storage and Query Performance
 
ORC File and Vectorization - Hadoop Summit 2013
ORC File and Vectorization - Hadoop Summit 2013ORC File and Vectorization - Hadoop Summit 2013
ORC File and Vectorization - Hadoop Summit 2013
 
Scala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud FoundryScala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud Foundry
 
Lecture 8 strings and characters
Lecture 8  strings and charactersLecture 8  strings and characters
Lecture 8 strings and characters
 

Mais de Yongqiang Li

How to Recognize Henry's Face
How to Recognize Henry's FaceHow to Recognize Henry's Face
How to Recognize Henry's FaceYongqiang Li
 
Introduction to Boost regex
Introduction to Boost regexIntroduction to Boost regex
Introduction to Boost regexYongqiang Li
 
Let's talk about java class loader
Let's talk about java class loaderLet's talk about java class loader
Let's talk about java class loaderYongqiang Li
 
Brief introduction to domain-driven design
Brief introduction to domain-driven designBrief introduction to domain-driven design
Brief introduction to domain-driven designYongqiang Li
 
Eclipse GEF (Part I)
Eclipse GEF (Part I)Eclipse GEF (Part I)
Eclipse GEF (Part I)Yongqiang Li
 
Garbage Collection of Java VM
Garbage Collection of Java VMGarbage Collection of Java VM
Garbage Collection of Java VMYongqiang Li
 
Let's talk about jni
Let's talk about jniLet's talk about jni
Let's talk about jniYongqiang Li
 

Mais de Yongqiang Li (8)

Why Kotlin?
Why Kotlin?Why Kotlin?
Why Kotlin?
 
How to Recognize Henry's Face
How to Recognize Henry's FaceHow to Recognize Henry's Face
How to Recognize Henry's Face
 
Introduction to Boost regex
Introduction to Boost regexIntroduction to Boost regex
Introduction to Boost regex
 
Let's talk about java class loader
Let's talk about java class loaderLet's talk about java class loader
Let's talk about java class loader
 
Brief introduction to domain-driven design
Brief introduction to domain-driven designBrief introduction to domain-driven design
Brief introduction to domain-driven design
 
Eclipse GEF (Part I)
Eclipse GEF (Part I)Eclipse GEF (Part I)
Eclipse GEF (Part I)
 
Garbage Collection of Java VM
Garbage Collection of Java VMGarbage Collection of Java VM
Garbage Collection of Java VM
 
Let's talk about jni
Let's talk about jniLet's talk about jni
Let's talk about jni
 

Último

Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...apidays
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 

Último (20)

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 

Let's talk about java class file

  • 1. Let’s Talk about Java Class File Yongqiang Li
  • 2. Outlines  Brief Introduction to Java Class File  Java Class Format and Layout  References
  • 3. Brief Introduction to Java Class File  Has .class extension  Compiled from java source files (.java)  Platform-independent  Machine-readable  Stores so-called “bytecodes”
  • 4. Java Source File (ClassA.java) javac ClassA.java Java Class File (ClassA.class)
  • 6.  Only “javac” can generate class file? JRuby Clojure Jython Java Class Groovy Scala
  • 7. Java Class Format and Layout  Class File contains different sections.  Magic Number  Version of Class File Format  Constant Pool  Access Flags  This Class  Super Class  Interfaces  Fields  Methods  Attributes
  • 8.
  • 9. Magic Number 4 bytes  Always “CAFEBABE” ( 咖啡宝贝 )
  • 10. Version of Class File Format 2 bytes for minor version  2 bytes for major version  Java major version starts from 45 (JDK 1.1)  Java SE 5 is 49, SE 6 is 50 (0x32), SE 7 is 51.
  • 11. Constant Pool 2 bytes used to store constant count  Index of constant starts from 1 not 0.
  • 12. Tag Byte Constant Type Additional Bytes 0x01 UTF8-String 2+x 0x03 Integer 4 (Big endian) 0x04 Float 4 (IEEE 754 floating- point) 0x05 Long 8 (Big endian) 0x06 Double 8 (IEEE 754 floating- point) 0x07 Class Reference 2 0x08 String Reference 2 0x09 Field Reference 2+2 (first 2 for class Ref) 0x0A Method Reference 2+2 (first 2 for class Ref) 0x0B Interface Method Ref. 2+2 (first 2 for class Ref) 0x0C Name and Type Ref. 2+2
  • 13.  Constant Count 0x0021(hex) = 33 (dec)
  • 14.  Double • 0x06: Double Tag • 0x4000 1893 74bc 6a7f: 2.012
  • 15. • 0x01: UTF-8 Tag  UTF-8 • 0x0006: “String” has 6 char. • 0x5374 7269 6367: “String”
  • 16.  More Strings  Field/Method Name  Field/Method Type  Attribute Name
  • 17.  Class Reference • 0x07: Class Ref Tag • 0x0002: Constant Index
  • 18. Access Flags  For Class  2 Bytes
  • 19. This and Super  Both are 2 bytes  Direct to Class Reference in Constant Pool. This Ref: 0x0001 Super Ref: 0x0003
  • 20. Interfaces 2 bytes for count of interfaces  2 * interfaces_count bytes
  • 21. Fields 2 bytes for fields count  field_info * fields_count
  • 22.  Attribute Structure
  • 23.  Field Access  2 bytes
  • 24. 0x0001: Only 1 Field • 0x0019: public static final • 0x0005: “obj” • 0x0006: Descriptor “Ljava/lang/Object;” • 0x0002: 2 Attributes • 1st: 0x0007 (Deprecated) • 2nd: 0x0008 (RuntimeVisibleAnnotations)
  • 25. Methods 2 bytes for methods count  method_info * methods_count Method Access Flags
  • 26.  Method Attributes  CodeAttributes
  • 27. Max Stack: 2 • Max Locals: 3 • Args Size: 2 • Code:
  • 28.  JVM Opcode  Based on stack not register  About 200 opcode in JVM 6
  • 29.
  • 30.  0: push the integer in slot 0 to stack  1: push the integer in slot 1 to stack  2: add first 2 integers in stack and result will be push into stack  3: load the integer from stack top to integer in slot 2  4: push the integer in slot 2 to stack  5: return an integer
  • 31.
  • 32.  Exception Attributes
  • 33. Who can help me on this?  Magic Number  Version of Class File Format  Constant Pool  Access Flags  This Class  Super Class  Interfaces  Fields  Methods  Attributes
  • 34.
  • 35. References  JVM 6 Specification  《深入浅出 Java 虚拟机》