SlideShare a Scribd company logo
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

More Related Content

What's hot

Java Advanced Features
Java Advanced FeaturesJava Advanced Features
Java Advanced Features
Michael Redlich
 
Core Java Basics
Core Java BasicsCore Java Basics
Core Java Basics
mhtspvtltd
 
9781439035665 ppt ch08
9781439035665 ppt ch089781439035665 ppt ch08
9781439035665 ppt ch08
Terry Yoast
 
Chap01
Chap01Chap01
Chap01
Jotham Gadot
 
Fundamentals of oop lecture 2
Fundamentals of oop lecture 2Fundamentals of oop lecture 2
Fundamentals of oop lecture 2
miiro30
 
Ifi7184 lesson7
Ifi7184 lesson7Ifi7184 lesson7
Ifi7184 lesson7
Sónia
 
Java IO Package and Streams
Java IO Package and StreamsJava IO Package and Streams
Java IO Package and Streams
babak 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, JVM
manish 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
 

What's hot (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?
 

Similar to Let's talk about java class file

บทที่4
บทที่4บทที่4
บทที่4
Waritsara Sonchan
 
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
Marc Tritschler
 
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
marctritschler
 
Java Day-6
Java Day-6Java Day-6
Java Day-6
People Strategists
 
บทที่ 4 การเพิ่มข้อมูลลงฐานข้อมูล
บทที่ 4 การเพิ่มข้อมูลลงฐานข้อมูลบทที่ 4 การเพิ่มข้อมูลลงฐานข้อมูล
บทที่ 4 การเพิ่มข้อมูลลงฐานข้อมูล
Priew Chakrit
 
4.เพิ่มข้อมูลลง DB ด้วย JSP&SQL
4.เพิ่มข้อมูลลง DB ด้วย JSP&SQL4.เพิ่มข้อมูลลง DB ด้วย JSP&SQL
4.เพิ่มข้อมูลลง DB ด้วย JSP&SQL
squall1735
 
บท4
บท4บท4
บท4
kiddy67
 
บท4
บท4บท4
บท4
bank_b
 
Introduction_to_Java.ppt
Introduction_to_Java.pptIntroduction_to_Java.ppt
Introduction_to_Java.ppt
HemantSharma134028
 
Java input output package
Java input output packageJava input output package
Java input output package
Sujit Kumar
 
Java quick reference v2
Java quick reference v2Java quick reference v2
Java quick reference v2
Christopher Akinlade
 
java training faridabad
java training faridabadjava training faridabad
java training faridabad
Woxa Technologies
 
Java quickref
Java quickrefJava quickref
Java quickref
Arduino Aficionado
 
Harder Faster Stronger
Harder Faster StrongerHarder Faster Stronger
Harder Faster Stronger
snyff
 
Java14
Java14Java14
Java14
aiter2002
 
Java Tutorials
Java Tutorials Java Tutorials
Java Tutorials
Woxa Technologies
 
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
DataWorks 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 2013
Owen O'Malley
 
Scala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud FoundryScala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud Foundry
Pray Desai
 
Lecture 8 strings and characters
Lecture 8  strings and charactersLecture 8  strings and characters
Lecture 8 strings and characters
alvin567
 

Similar to 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
 

More from Yongqiang Li

Why Kotlin?
Why Kotlin?Why Kotlin?
Why Kotlin?
Yongqiang Li
 
How to Recognize Henry's Face
How to Recognize Henry's FaceHow to Recognize Henry's Face
How to Recognize Henry's Face
Yongqiang Li
 
Introduction to Boost regex
Introduction to Boost regexIntroduction to Boost regex
Introduction to Boost regex
Yongqiang 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 loader
Yongqiang Li
 
Brief introduction to domain-driven design
Brief introduction to domain-driven designBrief introduction to domain-driven design
Brief introduction to domain-driven design
Yongqiang 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 VM
Yongqiang Li
 
Let's talk about jni
Let's talk about jniLet's talk about jni
Let's talk about jni
Yongqiang Li
 

More from 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
 

Recently uploaded

Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
Digital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Digital Banking in the Cloud: How Citizens Bank Unlocked Their MainframeDigital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Digital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Precisely
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
Edge AI and Vision Alliance
 
Public CyberSecurity Awareness Presentation 2024.pptx
Public CyberSecurity Awareness Presentation 2024.pptxPublic CyberSecurity Awareness Presentation 2024.pptx
Public CyberSecurity Awareness Presentation 2024.pptx
marufrahmanstratejm
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-EfficiencyFreshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
ScyllaDB
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
Jakub Marek
 
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectorsConnector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
DianaGray10
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
saastr
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
Postman
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
MichaelKnudsen27
 
Leveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and StandardsLeveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and Standards
Neo4j
 
Y-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PPY-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PP
c5vrf27qcz
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
Apps Break Data
Apps Break DataApps Break Data
Apps Break Data
Ivo Velitchkov
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
AstuteBusiness
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 

Recently uploaded (20)

Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
Digital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Digital Banking in the Cloud: How Citizens Bank Unlocked Their MainframeDigital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Digital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
 
Public CyberSecurity Awareness Presentation 2024.pptx
Public CyberSecurity Awareness Presentation 2024.pptxPublic CyberSecurity Awareness Presentation 2024.pptx
Public CyberSecurity Awareness Presentation 2024.pptx
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-EfficiencyFreshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
 
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectorsConnector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
 
Leveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and StandardsLeveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and Standards
 
Y-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PPY-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PP
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
Apps Break Data
Apps Break DataApps Break Data
Apps Break Data
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 

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 虚拟机》