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.
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