SlideShare a Scribd company logo
JVM Bytecodes
~ Anvay Patil
We spend 90% of our time in developing/maintaining
10% of code.
From the book:
Screenshot from Chapter 5
JVM=J+VM
Let’s get little curious here
What is VM?
A Virtual Machine is a high level abstraction on top of native operating system
that emulates a physical machine.
Two types of Virtual Machines:
1. Process Virtual Machine.
2. System Virtual Machine.
JVM -> Process Virtual Machine
A Process Virtual machine enables the same platform/environment for execution on
multiple operating systems and different hardware architectures.
They could be of two type:
1. Stack Based Process Virtual machine (HotSpot Virtual machine/ Primary JVM)
2. Register Based Process Virtual machine (Android’s Dalvik Virtual machine)
Stack Based
vs
Register based
Virtual Machine
Types
Now few questions?
1. Stack based vs register based Virtual machine, does it affect bytecodes which is
generated by Java Compiler ?
2. What makes Java achieve platform independency ?
3. Is platform independency, for only Java language or it is true for other JVM languages
too ?
Bytecodes
So what is the Magic behind the bytecodes?
What exactly are bytecodes?
Why should i be aware about it?
Bytecode?
JVM
➔ one byte instruction set
➔ 256 possible opcodes (unsigned bytecode)
➔ 200 in use on current
Instruction sets designed for efficient
execution by software interpreter which can
do suitable further compilation into
machine code may be at runtime.
Microsoft CLR
➔ 2 bytes instruction sets
➔ Stack based VM
Why know JVM Bytecodes?
1. Can give deep understanding about the
platform
2. Can read the byte code
3. Can modify the bytecode
4. Can build own language?
5. Use libraries which can generate bytecodes.
Java -VM
Android’s
Dalvik -VM
Jython VM
CPython
x=7,y=8
print x+y
Jython
Compiler
CPython
Compiler
Cpython
Interpreter
Jython
Interpreter15
CPython VM Java VM
CPython Bytecode Java Bytecode
Python source code
JVM Languages: < OMG :-O >
Jython
Mirah
JRuby
MicroFocus Visual COBOL
JScheme
Javascal/Pascal4J
Javascal
JTclJawk
JLua
Erjang
Jaskell
JPerl
JPerl Groovy
Clojure
Xtend Ceylon Kotlin
More than 800 implementations of JVM and more than 250 JVM languages
Scala
Fhatom
Gosu
Processing
Drools
Frink Open-XION
Redline SmallTalk
Ioke Nashorn JS
JudoScript
LolCode
NestVM JPC
PizzaNoop
jvm.go
JVM=Polyglot-VM
Simple Program
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, world");
}
}
> javac HelloWorld.java
> javap -c HelloWorld.class
> javap -verbose HelloWorld.class
javap
● Java Class File disassembler
● Basic operations and class structure
○ javap HelloWorld.class
● -c flag include bytecodes
○ javap -c HelloWorld.class
● -public -private -protected option
○ javap -private HelloWorld.class
○ javap -public HelloWorld.class
○ javap -protected HelloWorld.class
● -verbose for stack size, locals, args etc.
○ javap -verbose HelloWorld.class
Instruction set:
● Stack instruction, since stack based machine
● Basic operations
● Flow control
● Class structures
● Exception Handling
Stack Manipulation:
Typed Opcodes:
b byte
s short
c char
i int
l long
f float
d double
a reference
<type> <operation>
Constant Values
Local vars (load, store)
Array Operations (aload, astore)
Math ops (add, sub, mul, div)
Boolean bitwise
Comparisons
Conversions
Type
Operations
There is no instruction for boolean, and can play with 0 or 1
Constant Values:
Local variables:
Arrays:
Math Operations:
Boolean and Bitwise Operations:
Conversions:
Compare operations:
Flow Control:
More Flow Control:
Instructions for Classes
Instructions for Classes
Let’s execute HelloWorld
stack=2, locals=1, args_size=1
0: getstatic #2 // Field java/lang/System.out:Ljava/io/PrintStream;
3: ldc #3 // String Hello Java User Group
5: invokevirtual #4 // Method java/io/PrintStream.println:(Ljava/lang/String;)V
8: return
Q & A :)
References
● Java Virtual Machine Specification
● Inside JVM
● JVM Programming Languages
Thank you :)

More Related Content

What's hot (20)

PPTX
Forseti driven javascript
Pavneet Singh Saund
 
PDF
Why JVM will outlive java?
Ram Lakshmanan
 
PDF
Java interview questions
Java2Blog
 
PPS
Linkedin Search_GK
Gopinath Karunamoorthy
 
PDF
Introduction to java
Levent YILDIZ
 
PPTX
2. hello java
Indu Sharma Bhardwaj
 
PPTX
Migration Spring PetClinic to Quarkus
Jonathan Vila
 
PPTX
Scalable Real Time Chat (Text, Audio, Video) - Implemented using XMPP
Udaya Kiran
 
PPTX
HOW AND WHY GRAALVM IS QUICKLY BECOMING RELEVANT FOR YOU
Lucas Jellema
 
PPTX
JVM ecosystem languages and the future of JVM
Mizanur Rahman Khan
 
PDF
Jvm ecosystem languages and the future of jvm
JUGBD
 
PPTX
JVM Ecosystem Languages And The Future of JVM
Sazzadur Rahaman
 
PDF
How to meets Async and Task
Kouji Matsui
 
PPTX
intoduction to java
SIVASHANKARIRAJAN
 
PDF
Testing your app with Selenium on Travis CI
Yusuke Ando
 
PDF
Venkat Subramaniam Building DSLs In Groovy
deimos
 
Forseti driven javascript
Pavneet Singh Saund
 
Why JVM will outlive java?
Ram Lakshmanan
 
Java interview questions
Java2Blog
 
Linkedin Search_GK
Gopinath Karunamoorthy
 
Introduction to java
Levent YILDIZ
 
2. hello java
Indu Sharma Bhardwaj
 
Migration Spring PetClinic to Quarkus
Jonathan Vila
 
Scalable Real Time Chat (Text, Audio, Video) - Implemented using XMPP
Udaya Kiran
 
HOW AND WHY GRAALVM IS QUICKLY BECOMING RELEVANT FOR YOU
Lucas Jellema
 
JVM ecosystem languages and the future of JVM
Mizanur Rahman Khan
 
Jvm ecosystem languages and the future of jvm
JUGBD
 
JVM Ecosystem Languages And The Future of JVM
Sazzadur Rahaman
 
How to meets Async and Task
Kouji Matsui
 
intoduction to java
SIVASHANKARIRAJAN
 
Testing your app with Selenium on Travis CI
Yusuke Ando
 
Venkat Subramaniam Building DSLs In Groovy
deimos
 

Similar to JVM Bytecodes (20)

PPTX
JAVA BYTE CODE
Javed Ahmed Samo
 
PPT
introduction to java
Azaz Maverick
 
PPTX
How to implement a simple dalvik virtual machine
Chun-Yu Wang
 
PDF
College Project - Java Disassembler - Description
Ganesh Samarthyam
 
PPTX
Java byte code & virtual machine
Laxman Puri
 
PPTX
Jvm2
Mykola Bova
 
PPTX
Dvm
Shivam Sharma
 
PPTX
Java Virtual Machine
profbnk
 
PPTX
How to build a virtual machine
Terence Parr
 
PPT
Java Virtual Machine
Taha Malampatti
 
KEY
JavaOne 2011 - JVM Bytecode for Dummies
Charles Nutter
 
PPT
CS Lesson: Introduction to the Java virtual Machine
Katrin Becker
 
PDF
Understanding the Dalvik Virtual Machine
National Cheng Kung University
 
PDF
What is Java
3trg
 
PDF
Java introduction
Kuppusamy P
 
PDF
Lecture java01
jawidAhmadRohani
 
PPTX
Java introduction
The icfai university jaipur
 
PPTX
CSE 116 OOP Educational Materials of United International University
MdMirajulIslam21
 
PDF
Introduction to the Java bytecode - So@t - 20130924
yohanbeschi
 
JAVA BYTE CODE
Javed Ahmed Samo
 
introduction to java
Azaz Maverick
 
How to implement a simple dalvik virtual machine
Chun-Yu Wang
 
College Project - Java Disassembler - Description
Ganesh Samarthyam
 
Java byte code & virtual machine
Laxman Puri
 
Java Virtual Machine
profbnk
 
How to build a virtual machine
Terence Parr
 
Java Virtual Machine
Taha Malampatti
 
JavaOne 2011 - JVM Bytecode for Dummies
Charles Nutter
 
CS Lesson: Introduction to the Java virtual Machine
Katrin Becker
 
Understanding the Dalvik Virtual Machine
National Cheng Kung University
 
What is Java
3trg
 
Java introduction
Kuppusamy P
 
Lecture java01
jawidAhmadRohani
 
Java introduction
The icfai university jaipur
 
CSE 116 OOP Educational Materials of United International University
MdMirajulIslam21
 
Introduction to the Java bytecode - So@t - 20130924
yohanbeschi
 
Ad

Recently uploaded (20)

PPTX
The Role of Information Technology in Environmental Protectio....pptx
nallamillisriram
 
PPTX
DATA BASE MANAGEMENT AND RELATIONAL DATA
gomathisankariv2
 
PDF
Viol_Alessandro_Presentazione_prelaurea.pdf
dsecqyvhbowrzxshhf
 
PPTX
artificial intelligence applications in Geomatics
NawrasShatnawi1
 
PPTX
Element 11. ELECTRICITY safety and hazards
merrandomohandas
 
PDF
Design Thinking basics for Engineers.pdf
CMR University
 
DOC
MRRS Strength and Durability of Concrete
CivilMythili
 
PPTX
美国电子版毕业证南卡罗莱纳大学上州分校水印成绩单USC学费发票定做学位证书编号怎么查
Taqyea
 
PPTX
Damage of stability of a ship and how its change .pptx
ehamadulhaque
 
PPTX
Lecture 1 Shell and Tube Heat exchanger-1.pptx
mailforillegalwork
 
PDF
MAD Unit - 1 Introduction of Android IT Department
JappanMavani
 
PDF
Ethics and Trustworthy AI in Healthcare – Governing Sensitive Data, Profiling...
AlqualsaDIResearchGr
 
PDF
Pressure Measurement training for engineers and Technicians
AIESOLUTIONS
 
PPTX
Element 7. CHEMICAL AND BIOLOGICAL AGENT.pptx
merrandomohandas
 
PPTX
fatigue in aircraft structures-221113192308-0ad6dc8c.pptx
aviatecofficial
 
PPTX
Arduino Based Gas Leakage Detector Project
CircuitDigest
 
PPTX
Mechanical Design of shell and tube heat exchangers as per ASME Sec VIII Divi...
shahveer210504
 
PDF
Biomechanics of Gait: Engineering Solutions for Rehabilitation (www.kiu.ac.ug)
publication11
 
PDF
PORTFOLIO Golam Kibria Khan — architect with a passion for thoughtful design...
MasumKhan59
 
PDF
International Journal of Information Technology Convergence and services (IJI...
ijitcsjournal4
 
The Role of Information Technology in Environmental Protectio....pptx
nallamillisriram
 
DATA BASE MANAGEMENT AND RELATIONAL DATA
gomathisankariv2
 
Viol_Alessandro_Presentazione_prelaurea.pdf
dsecqyvhbowrzxshhf
 
artificial intelligence applications in Geomatics
NawrasShatnawi1
 
Element 11. ELECTRICITY safety and hazards
merrandomohandas
 
Design Thinking basics for Engineers.pdf
CMR University
 
MRRS Strength and Durability of Concrete
CivilMythili
 
美国电子版毕业证南卡罗莱纳大学上州分校水印成绩单USC学费发票定做学位证书编号怎么查
Taqyea
 
Damage of stability of a ship and how its change .pptx
ehamadulhaque
 
Lecture 1 Shell and Tube Heat exchanger-1.pptx
mailforillegalwork
 
MAD Unit - 1 Introduction of Android IT Department
JappanMavani
 
Ethics and Trustworthy AI in Healthcare – Governing Sensitive Data, Profiling...
AlqualsaDIResearchGr
 
Pressure Measurement training for engineers and Technicians
AIESOLUTIONS
 
Element 7. CHEMICAL AND BIOLOGICAL AGENT.pptx
merrandomohandas
 
fatigue in aircraft structures-221113192308-0ad6dc8c.pptx
aviatecofficial
 
Arduino Based Gas Leakage Detector Project
CircuitDigest
 
Mechanical Design of shell and tube heat exchangers as per ASME Sec VIII Divi...
shahveer210504
 
Biomechanics of Gait: Engineering Solutions for Rehabilitation (www.kiu.ac.ug)
publication11
 
PORTFOLIO Golam Kibria Khan — architect with a passion for thoughtful design...
MasumKhan59
 
International Journal of Information Technology Convergence and services (IJI...
ijitcsjournal4
 
Ad

JVM Bytecodes

  • 2. We spend 90% of our time in developing/maintaining 10% of code.
  • 3. From the book: Screenshot from Chapter 5
  • 5. What is VM? A Virtual Machine is a high level abstraction on top of native operating system that emulates a physical machine. Two types of Virtual Machines: 1. Process Virtual Machine. 2. System Virtual Machine.
  • 6. JVM -> Process Virtual Machine A Process Virtual machine enables the same platform/environment for execution on multiple operating systems and different hardware architectures. They could be of two type: 1. Stack Based Process Virtual machine (HotSpot Virtual machine/ Primary JVM) 2. Register Based Process Virtual machine (Android’s Dalvik Virtual machine)
  • 8. Now few questions? 1. Stack based vs register based Virtual machine, does it affect bytecodes which is generated by Java Compiler ? 2. What makes Java achieve platform independency ? 3. Is platform independency, for only Java language or it is true for other JVM languages too ?
  • 9. Bytecodes So what is the Magic behind the bytecodes? What exactly are bytecodes? Why should i be aware about it?
  • 10. Bytecode? JVM ➔ one byte instruction set ➔ 256 possible opcodes (unsigned bytecode) ➔ 200 in use on current Instruction sets designed for efficient execution by software interpreter which can do suitable further compilation into machine code may be at runtime. Microsoft CLR ➔ 2 bytes instruction sets ➔ Stack based VM
  • 11. Why know JVM Bytecodes? 1. Can give deep understanding about the platform 2. Can read the byte code 3. Can modify the bytecode 4. Can build own language? 5. Use libraries which can generate bytecodes.
  • 14. JVM Languages: < OMG :-O > Jython Mirah JRuby MicroFocus Visual COBOL JScheme Javascal/Pascal4J Javascal JTclJawk JLua Erjang Jaskell JPerl JPerl Groovy Clojure Xtend Ceylon Kotlin More than 800 implementations of JVM and more than 250 JVM languages Scala Fhatom Gosu Processing Drools Frink Open-XION Redline SmallTalk Ioke Nashorn JS JudoScript LolCode NestVM JPC PizzaNoop jvm.go
  • 16. Simple Program public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, world"); } } > javac HelloWorld.java > javap -c HelloWorld.class > javap -verbose HelloWorld.class
  • 17. javap ● Java Class File disassembler ● Basic operations and class structure ○ javap HelloWorld.class ● -c flag include bytecodes ○ javap -c HelloWorld.class ● -public -private -protected option ○ javap -private HelloWorld.class ○ javap -public HelloWorld.class ○ javap -protected HelloWorld.class ● -verbose for stack size, locals, args etc. ○ javap -verbose HelloWorld.class
  • 18. Instruction set: ● Stack instruction, since stack based machine ● Basic operations ● Flow control ● Class structures ● Exception Handling
  • 20. Typed Opcodes: b byte s short c char i int l long f float d double a reference <type> <operation> Constant Values Local vars (load, store) Array Operations (aload, astore) Math ops (add, sub, mul, div) Boolean bitwise Comparisons Conversions Type Operations There is no instruction for boolean, and can play with 0 or 1
  • 25. Boolean and Bitwise Operations:
  • 32. Let’s execute HelloWorld stack=2, locals=1, args_size=1 0: getstatic #2 // Field java/lang/System.out:Ljava/io/PrintStream; 3: ldc #3 // String Hello Java User Group 5: invokevirtual #4 // Method java/io/PrintStream.println:(Ljava/lang/String;)V 8: return
  • 33. Q & A :)
  • 34. References ● Java Virtual Machine Specification ● Inside JVM ● JVM Programming Languages