SlideShare a Scribd company logo
1 of 33
JVM byte code
jvm commands

Nick Bova
Sep 1 2013
About myself
• In IT since 2000
• 6 years with mainframes
• Refactoring FinExpert virtual machine and finex
programming language
• Many assemblers in institute
•
•
•
•
•

Skype – mykola_bova
Twitter – mykola_bova
Facebook - FB/myk.bova
LinkedIn – ua.linkedin.com/in/mykbova
E-mail – bova.mykola@gmail.com
Why JVM byte code?
• A key to JVM internals and Java itself
• Practical understanding –key
for solving difficult problems
• A way to understand how it “really” works
What will be / will not be here?
• JVM and JVM byte code (JVM spec)
• “Touch” JVM byte code on practice
(reJ, ClassEditor)

• Libraries for byte code manipulation? – No
• Am I JVM / JVM byte code expert? - No
Special thanks
@Anton Arhipov
http://arhipov.blogspot.com/
Books
1) Inside the Java Virtual Machine
Bill Venners
2) Programming for the Java™ Virtual Machine
Joshua Engel
3) The Well-Grounded Java Developer
Vital techniques of Java 7 and polyglot
programming.
Benjamin J. Evans
Martijn Verburg
Articles (1)
1) JVM Internals
Douglas Q. Hawkins
http://www.dougqh.net/
3) Lifting The Veil – Reading Java Byte Code
Alexander Shopov
3) Java bytecode:
Understanding bytecode makes you a better programmer
Peter Haggar
http://www.ibm.com/developerworks/ibm/library/ithaggar_bytecode/
Articles (2)
4) Looking "Under the Hood" with javap
by Corey McGlone
http://www.javaranch.com/journal/200408/ScjpTip
Line-javap.html
5) Understanding JVM Internals
http://www.cubrid.org/blog/devplatform/understanding-jvm-internals/
6) Java Bytecode Fundamentals
http://arhipov.blogspot.com/2011/01/javabytecode-fundamentals.html
Simple byte code example
Method variables
0

Iconst_1

1

Iconst_2

2

iadd

3

Istore_0

4

Iload_0

0

2
1
0
Stack

1

2
Simple byte code example
Method variables
0

Iconst_1

1

Iconst_2

2

iadd

3

Istore_0

4

Iload_0

0

2
1
0

1
Stack

1

2
Simple byte code example
Method variables
0

Iconst_1

1

Iconst_2

2

iadd

3

Istore_0

4

Iload_0

0

2
1

2

0

1
Stack

1

2
Simple byte code example
Method variables
0

Iconst_1

1

Iconst_2

2

iadd

3

Istore_0

4

Iload_0

0

2
1
0

1+2
Stack

1

2
Simple byte code example
Method variables
0

Iconst_1

1

Iconst_2

2

iadd

3

Istore_0

4

Iload_0

0

2
1
0

3
Stack

1

2
Simple byte code example
Method variables
0

Iconst_1

1

Iconst_2

2

iadd

3

Istore_0

4

Iload_0

0
3

2
1
0
Stack

1

2
1. No variables
Bytecode employs an Assembly-like register
stack known as the locals stack to hold
variables.
Values of fields, functions and of binary
operations (+, -, * ..) are held in a stack known as
the operand stack.
2. No binary logical operators
No built-in support for &&, ||, ^
Compilers implement these using jump
instructions.
(Examples in files HelloWorld_AND.javap and
HelloWorld_OR.javap)
3. No loop constructs
There’s no built-in support for while, for, foreach loops.
Compilers implement these using jump
instructions.
(Example in file HelloWorld_FOR.javap)
4. No String support
Like in C, there’s no built-in support for
strings, only char arrays.
Compilers usually use StringBuilder to
compensate.
No penalty for concatenating different data
types
(Example in file HelloWorld_STRING.javap)
JavaC uses java.lang.StringBuilder to combine (+)strings.
Different overloads of the .append() method are used to
concat different data types.
5. Only 4 primitive types
Bytecode only operates on 4 primitives types
int, float, double, long vs. the 8 Java primitives.
char, bool, byte, short are treated as ints
(Example in file HelloWorld_INT.javap)
6. Only 4 primitive types
Bytecode only operates on 4 primitives types
Compilers will add synthetic $this fields.
If you’re not making calls to your outer-class don’t forget to add a static modifier.
(Example in file HelloWorld_NESTED.javap)
8 Using nested classes (2)?
Bytecode only operates on 4 primitives types
• Try and avoid implicitly creating bridge
methods by invoking private members (use
protected)
(Example in file HelloWorld_BRIDGE.javap)
9. Boxing and unboxing
Boxing is added by the Java/Scala compiler.
There’s no such concept in bytecode or in the
JVM.
Watch out for NullPointerExceptions
(Example in file HelloWorld_BOXING.javap)
Main bytecode uses

-

Building a compiler
Static analysis
JVM bytecode instrumentation
?
Different types are supported in the
JVM instruction set
-

opcode - Taload
byte - baload
short - saload
int - iaload
long - laload
float - faload
double - daload
char - caload
reference - aaload
Load and Store Instructions
• Load a local variable onto the operand stack:
iload
• Store a value from the operand stack into a
local variable: istore
• Load a constant on to the operand stack: ldc
• Gain access to more local variables using a
wider index, or to a larger immediate
operand: wide
Arithmetic Instructions
• Add: iadd
• Subtract: isub
• Multiply: imul
• Divide: idiv
• Remainder: irem
• Negate: ineg
• Shift: ishl
• Bitwise OR: ior
• Bitwise AND: iand
• Bitwise exclusive OR: ixor
• Local variable increment: iinc.
• Comparison: dcmpg
Type Conversion Instructions

• widening numeric conversions: i2l
• narrowing numeric conversions: l2i
Object Creation and Manipulation
• Create a new class instance: new
• Create a new array: newarray
• Access fields of classes and fields of class
instances : getfield, putfield, getstatic, putstatic
• Load an array component onto the operand stack:
baload
• Store a value from the operand stack as an array
component: bastore
• Get the length of array: arraylength.
• Check properties of class instances or arrays:
instanceof, checkcast
Operand Stack Management
Instructions

• pop, dup, swap
Control Transfer Instructionsstructions

• Conditional branch:
ifeq, ifneifge, ifnull, ifnonnull, if_icmpeq
• Compound conditional branch:
tableswitch, lookupswitch.
• Unconditional branch: goto, jsr, ret.
Method Invocation and Return
Instructions
• invokevirtual invokes an instance method of an
object, dispatching on the
(virtual) type of the object
• invokeinterface invokes an interface method
• invokespecial invokes an instance method requiring
special handling, whether an
instance initialization method, a private method, or a
superclass method.
• invokestatic invokes a class (static) method in a named
class.
• The method return instructions, which are distinguished
by return type: ireturn
Method Invocation and Return
Instructions (invokedynamic)
javac won’t emit invokedynamic
There is no direct Java language support for invokedynamic in Java 7—
no Java
expression will be directly compiled into an invokedynamic bytecode
by javac. Java 8
is expected to add more language constructs (such as default methods)
that will
make use of the dynamic capabilities.
Instead, invokedynamic is an improvement that is squarely targeted at
non-Java languages.
The bytecode has been added for dynamic languages to make use of
when
targeting the Java 7 VM (but some clever Java frameworks have found
ways to make
it work for them too).
Throwing Exceptions

• An exception is thrown programmatically using
the athrow instruction.

More Related Content

What's hot

Effective Scala (JavaDay Riga 2013)
Effective Scala (JavaDay Riga 2013)Effective Scala (JavaDay Riga 2013)
Effective Scala (JavaDay Riga 2013)
mircodotta
 
Денис Лебедев, Swift
Денис Лебедев, SwiftДенис Лебедев, Swift
Денис Лебедев, Swift
Yandex
 
Python introduction
Python introductionPython introduction
Python introduction
Roger Xia
 
Effective Scala (SoftShake 2013)
Effective Scala (SoftShake 2013)Effective Scala (SoftShake 2013)
Effective Scala (SoftShake 2013)
mircodotta
 

What's hot (18)

Effective Scala (JavaDay Riga 2013)
Effective Scala (JavaDay Riga 2013)Effective Scala (JavaDay Riga 2013)
Effective Scala (JavaDay Riga 2013)
 
Perl On The JVM (London.pm Talk 2009-04)
Perl On The JVM (London.pm Talk 2009-04)Perl On The JVM (London.pm Talk 2009-04)
Perl On The JVM (London.pm Talk 2009-04)
 
Java Closures
Java ClosuresJava Closures
Java Closures
 
A Tale of Two Rubies
A Tale of Two RubiesA Tale of Two Rubies
A Tale of Two Rubies
 
From Ruby to Scala
From Ruby to ScalaFrom Ruby to Scala
From Ruby to Scala
 
Денис Лебедев, Swift
Денис Лебедев, SwiftДенис Лебедев, Swift
Денис Лебедев, Swift
 
TypeScript
TypeScriptTypeScript
TypeScript
 
04 inheritance
04 inheritance04 inheritance
04 inheritance
 
Swift Basics
Swift BasicsSwift Basics
Swift Basics
 
Functional OOP, Clojure style
Functional OOP, Clojure styleFunctional OOP, Clojure style
Functional OOP, Clojure style
 
March2004-CPerlRun
March2004-CPerlRunMarch2004-CPerlRun
March2004-CPerlRun
 
Introduction to Kotlin Language and its application to Android platform
Introduction to Kotlin Language and its application to Android platformIntroduction to Kotlin Language and its application to Android platform
Introduction to Kotlin Language and its application to Android platform
 
Compiler2016 by abcdabcd987
Compiler2016 by abcdabcd987Compiler2016 by abcdabcd987
Compiler2016 by abcdabcd987
 
What is Python?
What is Python?What is Python?
What is Python?
 
Python introduction
Python introductionPython introduction
Python introduction
 
Codegeneration Goodies
Codegeneration GoodiesCodegeneration Goodies
Codegeneration Goodies
 
Scala Refactoring for Fun and Profit (Japanese subtitles)
Scala Refactoring for Fun and Profit (Japanese subtitles)Scala Refactoring for Fun and Profit (Japanese subtitles)
Scala Refactoring for Fun and Profit (Japanese subtitles)
 
Effective Scala (SoftShake 2013)
Effective Scala (SoftShake 2013)Effective Scala (SoftShake 2013)
Effective Scala (SoftShake 2013)
 

Viewers also liked

Viewers also liked (6)

AWS Paris Summit 2014 - T4 - Créez votre PaaS avec AWS
AWS Paris Summit 2014 - T4 - Créez votre PaaS avec AWSAWS Paris Summit 2014 - T4 - Créez votre PaaS avec AWS
AWS Paris Summit 2014 - T4 - Créez votre PaaS avec AWS
 
groovy & grails - lecture 7
groovy & grails - lecture 7groovy & grails - lecture 7
groovy & grails - lecture 7
 
Scale and Reach: Always Up - Always On - AWS Symposium 2014 - Washington D.C....
Scale and Reach: Always Up - Always On - AWS Symposium 2014 - Washington D.C....Scale and Reach: Always Up - Always On - AWS Symposium 2014 - Washington D.C....
Scale and Reach: Always Up - Always On - AWS Symposium 2014 - Washington D.C....
 
Journey Through the Cloud - Digital Media
Journey Through the Cloud - Digital MediaJourney Through the Cloud - Digital Media
Journey Through the Cloud - Digital Media
 
AWS Summit London 2014 | Introduction to Amazon EC2 (100)
AWS Summit London 2014 | Introduction to Amazon EC2 (100)AWS Summit London 2014 | Introduction to Amazon EC2 (100)
AWS Summit London 2014 | Introduction to Amazon EC2 (100)
 
AWS Webcast - Explore the AWS Cloud
AWS Webcast - Explore the AWS CloudAWS Webcast - Explore the AWS Cloud
AWS Webcast - Explore the AWS Cloud
 

Similar to Jvm2

Java basics with datatypes, object oriented programming
Java basics with datatypes, object oriented programmingJava basics with datatypes, object oriented programming
Java basics with datatypes, object oriented programming
kalirajonline
 

Similar to Jvm2 (20)

ppt_on_java.pptx
ppt_on_java.pptxppt_on_java.pptx
ppt_on_java.pptx
 
Session 05 - Strings in Java
Session 05 - Strings in JavaSession 05 - Strings in Java
Session 05 - Strings in Java
 
Strings in Java
Strings in Java Strings in Java
Strings in Java
 
JAVA BYTE CODE
JAVA BYTE CODEJAVA BYTE CODE
JAVA BYTE CODE
 
Learning core java
Learning core javaLearning core java
Learning core java
 
Presentation on java
Presentation  on  javaPresentation  on  java
Presentation on java
 
java02.ppt
java02.pptjava02.ppt
java02.ppt
 
lecture-a-java-review.ppt
lecture-a-java-review.pptlecture-a-java-review.ppt
lecture-a-java-review.ppt
 
lecture-a-java-review.ppt
lecture-a-java-review.pptlecture-a-java-review.ppt
lecture-a-java-review.ppt
 
lecture-a-java-review.ppt
lecture-a-java-review.pptlecture-a-java-review.ppt
lecture-a-java-review.ppt
 
Java basics with datatypes, object oriented programming
Java basics with datatypes, object oriented programmingJava basics with datatypes, object oriented programming
Java basics with datatypes, object oriented programming
 
lecture-a-java-review.ppt
lecture-a-java-review.pptlecture-a-java-review.ppt
lecture-a-java-review.ppt
 
lecture-a-java-review.ppt
lecture-a-java-review.pptlecture-a-java-review.ppt
lecture-a-java-review.ppt
 
lecture-a-java-review.ppt
lecture-a-java-review.pptlecture-a-java-review.ppt
lecture-a-java-review.ppt
 
GOTO Night with Charles Nutter Slides
GOTO Night with Charles Nutter SlidesGOTO Night with Charles Nutter Slides
GOTO Night with Charles Nutter Slides
 
Scala-Ls1
Scala-Ls1Scala-Ls1
Scala-Ls1
 
Java
JavaJava
Java
 
Java online training from hyderabad
Java online training from hyderabadJava online training from hyderabad
Java online training from hyderabad
 
Java
Java Java
Java
 
java training faridabad
java training faridabadjava training faridabad
java training faridabad
 

More from Mykola Bova

backbase-cxp-datasheet
backbase-cxp-datasheetbackbase-cxp-datasheet
backbase-cxp-datasheet
Mykola Bova
 
inside dvm internals
inside dvm internalsinside dvm internals
inside dvm internals
Mykola Bova
 
Inside Dvm tools
Inside Dvm toolsInside Dvm tools
Inside Dvm tools
Mykola Bova
 
Inside Dvm basics
Inside Dvm basicsInside Dvm basics
Inside Dvm basics
Mykola Bova
 
Dvm internals intro
Dvm internals introDvm internals intro
Dvm internals intro
Mykola Bova
 

More from Mykola Bova (6)

backbase-cxp-datasheet
backbase-cxp-datasheetbackbase-cxp-datasheet
backbase-cxp-datasheet
 
inside dvm internals
inside dvm internalsinside dvm internals
inside dvm internals
 
Inside Dvm tools
Inside Dvm toolsInside Dvm tools
Inside Dvm tools
 
Inside Dvm basics
Inside Dvm basicsInside Dvm basics
Inside Dvm basics
 
Dvm internals intro
Dvm internals introDvm internals intro
Dvm internals intro
 
Jvm1
Jvm1Jvm1
Jvm1
 

Recently uploaded

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Recently uploaded (20)

Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
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
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
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
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
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...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
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
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
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
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 

Jvm2

  • 1. JVM byte code jvm commands Nick Bova Sep 1 2013
  • 2. About myself • In IT since 2000 • 6 years with mainframes • Refactoring FinExpert virtual machine and finex programming language • Many assemblers in institute • • • • • Skype – mykola_bova Twitter – mykola_bova Facebook - FB/myk.bova LinkedIn – ua.linkedin.com/in/mykbova E-mail – bova.mykola@gmail.com
  • 3. Why JVM byte code? • A key to JVM internals and Java itself • Practical understanding –key for solving difficult problems • A way to understand how it “really” works
  • 4. What will be / will not be here? • JVM and JVM byte code (JVM spec) • “Touch” JVM byte code on practice (reJ, ClassEditor) • Libraries for byte code manipulation? – No • Am I JVM / JVM byte code expert? - No
  • 6. Books 1) Inside the Java Virtual Machine Bill Venners 2) Programming for the Java™ Virtual Machine Joshua Engel 3) The Well-Grounded Java Developer Vital techniques of Java 7 and polyglot programming. Benjamin J. Evans Martijn Verburg
  • 7. Articles (1) 1) JVM Internals Douglas Q. Hawkins http://www.dougqh.net/ 3) Lifting The Veil – Reading Java Byte Code Alexander Shopov 3) Java bytecode: Understanding bytecode makes you a better programmer Peter Haggar http://www.ibm.com/developerworks/ibm/library/ithaggar_bytecode/
  • 8. Articles (2) 4) Looking "Under the Hood" with javap by Corey McGlone http://www.javaranch.com/journal/200408/ScjpTip Line-javap.html 5) Understanding JVM Internals http://www.cubrid.org/blog/devplatform/understanding-jvm-internals/ 6) Java Bytecode Fundamentals http://arhipov.blogspot.com/2011/01/javabytecode-fundamentals.html
  • 9. Simple byte code example Method variables 0 Iconst_1 1 Iconst_2 2 iadd 3 Istore_0 4 Iload_0 0 2 1 0 Stack 1 2
  • 10. Simple byte code example Method variables 0 Iconst_1 1 Iconst_2 2 iadd 3 Istore_0 4 Iload_0 0 2 1 0 1 Stack 1 2
  • 11. Simple byte code example Method variables 0 Iconst_1 1 Iconst_2 2 iadd 3 Istore_0 4 Iload_0 0 2 1 2 0 1 Stack 1 2
  • 12. Simple byte code example Method variables 0 Iconst_1 1 Iconst_2 2 iadd 3 Istore_0 4 Iload_0 0 2 1 0 1+2 Stack 1 2
  • 13. Simple byte code example Method variables 0 Iconst_1 1 Iconst_2 2 iadd 3 Istore_0 4 Iload_0 0 2 1 0 3 Stack 1 2
  • 14. Simple byte code example Method variables 0 Iconst_1 1 Iconst_2 2 iadd 3 Istore_0 4 Iload_0 0 3 2 1 0 Stack 1 2
  • 15. 1. No variables Bytecode employs an Assembly-like register stack known as the locals stack to hold variables. Values of fields, functions and of binary operations (+, -, * ..) are held in a stack known as the operand stack.
  • 16. 2. No binary logical operators No built-in support for &&, ||, ^ Compilers implement these using jump instructions. (Examples in files HelloWorld_AND.javap and HelloWorld_OR.javap)
  • 17. 3. No loop constructs There’s no built-in support for while, for, foreach loops. Compilers implement these using jump instructions. (Example in file HelloWorld_FOR.javap)
  • 18. 4. No String support Like in C, there’s no built-in support for strings, only char arrays. Compilers usually use StringBuilder to compensate. No penalty for concatenating different data types (Example in file HelloWorld_STRING.javap) JavaC uses java.lang.StringBuilder to combine (+)strings. Different overloads of the .append() method are used to concat different data types.
  • 19. 5. Only 4 primitive types Bytecode only operates on 4 primitives types int, float, double, long vs. the 8 Java primitives. char, bool, byte, short are treated as ints (Example in file HelloWorld_INT.javap)
  • 20. 6. Only 4 primitive types Bytecode only operates on 4 primitives types Compilers will add synthetic $this fields. If you’re not making calls to your outer-class don’t forget to add a static modifier. (Example in file HelloWorld_NESTED.javap)
  • 21. 8 Using nested classes (2)? Bytecode only operates on 4 primitives types • Try and avoid implicitly creating bridge methods by invoking private members (use protected) (Example in file HelloWorld_BRIDGE.javap)
  • 22. 9. Boxing and unboxing Boxing is added by the Java/Scala compiler. There’s no such concept in bytecode or in the JVM. Watch out for NullPointerExceptions (Example in file HelloWorld_BOXING.javap)
  • 23. Main bytecode uses - Building a compiler Static analysis JVM bytecode instrumentation ?
  • 24. Different types are supported in the JVM instruction set - opcode - Taload byte - baload short - saload int - iaload long - laload float - faload double - daload char - caload reference - aaload
  • 25. Load and Store Instructions • Load a local variable onto the operand stack: iload • Store a value from the operand stack into a local variable: istore • Load a constant on to the operand stack: ldc • Gain access to more local variables using a wider index, or to a larger immediate operand: wide
  • 26. Arithmetic Instructions • Add: iadd • Subtract: isub • Multiply: imul • Divide: idiv • Remainder: irem • Negate: ineg • Shift: ishl • Bitwise OR: ior • Bitwise AND: iand • Bitwise exclusive OR: ixor • Local variable increment: iinc. • Comparison: dcmpg
  • 27. Type Conversion Instructions • widening numeric conversions: i2l • narrowing numeric conversions: l2i
  • 28. Object Creation and Manipulation • Create a new class instance: new • Create a new array: newarray • Access fields of classes and fields of class instances : getfield, putfield, getstatic, putstatic • Load an array component onto the operand stack: baload • Store a value from the operand stack as an array component: bastore • Get the length of array: arraylength. • Check properties of class instances or arrays: instanceof, checkcast
  • 30. Control Transfer Instructionsstructions • Conditional branch: ifeq, ifneifge, ifnull, ifnonnull, if_icmpeq • Compound conditional branch: tableswitch, lookupswitch. • Unconditional branch: goto, jsr, ret.
  • 31. Method Invocation and Return Instructions • invokevirtual invokes an instance method of an object, dispatching on the (virtual) type of the object • invokeinterface invokes an interface method • invokespecial invokes an instance method requiring special handling, whether an instance initialization method, a private method, or a superclass method. • invokestatic invokes a class (static) method in a named class. • The method return instructions, which are distinguished by return type: ireturn
  • 32. Method Invocation and Return Instructions (invokedynamic) javac won’t emit invokedynamic There is no direct Java language support for invokedynamic in Java 7— no Java expression will be directly compiled into an invokedynamic bytecode by javac. Java 8 is expected to add more language constructs (such as default methods) that will make use of the dynamic capabilities. Instead, invokedynamic is an improvement that is squarely targeted at non-Java languages. The bytecode has been added for dynamic languages to make use of when targeting the Java 7 VM (but some clever Java frameworks have found ways to make it work for them too).
  • 33. Throwing Exceptions • An exception is thrown programmatically using the athrow instruction.