snu ee shin jin woo
DESCRIPTION
The Java Virtual Machine (Design & APIs). SNU EE Shin Jin Woo. 2005. 10. 19. Table of Contents. What is JVM? Terminologies The Java Class Files Data Types in JVM Runtime Data Area Java Instruction Set Verification of Class Files Java APIs. 1. What is a Java Virtual Machine?. - PowerPoint PPT PresentationTRANSCRIPT
Java Virtual MachineJava Virtual Machine22
1. What is JVM?
2. Terminologies
3. The Java Class Files
4. Data Types in JVM
5. Runtime Data Area
6. Java Instruction Set
7. Verification of Class Files
8. Java APIs
Table of Contents
Java Virtual MachineJava Virtual Machine33
1. What is a Java Virtual Machine?
Module 1
• an abstract computing machine
Java Virtual Machine
• own instruction set(Java ISA) • memory manipulation at runtime
classloader
executionengine
Host OS
The Java API’s class file
user class files
JVM
bytecodes
native method invocation
Java Virtual MachineJava Virtual Machine44
2. Terminologies
JRE(Java Runtime Environment)
• : contains the Java virtual machine, classes comprising the Java 2 Platform API, and supporting files
JDK(Java Development Kit)
• : JRE, Development Tools(compiler, debugger), additional library
compile-time environment run-time environment
a.java b.java c.java
a.class b.class c.class
a.class b.class c.class
Object.class String.class
Javacompiler JVM
Java Virtual MachineJava Virtual Machine55
3. What is a Class File?
Java Class Files- precisely defined binary file format for Java
programs- put only one class or interface in a single class
file- primary vehicle for delivering program to JVM
Java LanguageProgram
C LanguageProgram
Compiler
Compiler
Java Class File
Java Class File
Java Virtual MachineJava Virtual Machine66
3. What is a Class File?
What is in Class Files
Magic NumberVersion InformationConstant Pool size
Constant PoolAccess Flags
This ClassSuper Class
0xCAFEBABE, 4byte
Interface CountInterfaces
Field CountField Information
Method CountMethods
Attributes CountAttributes
Java Virtual MachineJava Virtual Machine77
4. Data Type in JVM
- int - char- byte- short- float- double- returnAddress : used by subroutine mechanism
jsr places return address on operand stack
Primitive Data Types
Reference Data Types
- reference : points to an object stored in memory
Java Virtual MachineJava Virtual Machine88
5. Runtime Data Areas
PC Registers
: each JVM thread has its own program counter: the index in bytecode of the instruction
Java Virtual Machine Stacks: each JVM thread has its own stacks: invoke method -> new frame is allocated on
stack: store operand stack, local variables, state
variables
Thread 1
Thread 2
foo()
draw()
boo()Local VariablesOperand Stacks
Local VariablesOperand Stacks
Local VariablesOperand Stacks
Java Virtual MachineJava Virtual Machine99
5. Runtime Data Areas
The Operand Stack
- used to pass arguments- receive return results- interpreter is responsible for transferring
return result to the caller operand stack
Local Variables
- number of local variables in stack is determined at compile time- local variables are numbered ex) dconst_0 dstore 1
Java Virtual MachineJava Virtual Machine1010
5. Runtime Data Areas
Heap
- one heap per one JVM- created on VM start-up- all class instance and arrays are allocated in heap- objects are never deallocated
Method Area
- one M.A for one JVM- created on VM start-up- analogous to ‘text’ segment- stores constant pool, field and method data, code
for method
Java Virtual MachineJava Virtual Machine1111
Constant Pool
- analogous to ‘symbol table’- a collection of all symbolic data need by a class- each constant pool is private to its class
5. Runtime Data Areas
:5: add g0, FSIZE(class)+GC_HEAD, it06: call 07: sethi %hi(class->dtable), rt28: or r3, rt2, %lo(class->itable)
:
Java Virtual MachineJava Virtual Machine1212
6. Java Instruction Sets
Java Instruction Sets
- opcode is just one byte (256 combination possible) - additional index bytes- additional date bytes
opcode
opcode index1 index2
opcode date
Java Virtual MachineJava Virtual Machine1313
6. Java Instruction Sets
Data Movement Instructions
1. stack manipulation instructions iconst_1, bipush, pop, dup, swap
ex) bipush 10 bipush 20 swap pop dup pop2
10
20
20
10
20 20
20
Java Virtual MachineJava Virtual Machine1414
6. Java Instruction Sets
Type Conversion
- convert one type of item on the stack to another ex) i2f, i2d, i2l, f2i, f2l…
Functional Instructions
- operands are always taken from the stack and results are placed on the stack
ex) iadd, iand
Control Flow Instructions
- conditional branches ex) ifeq, if_icmpeq- unconditional branches ex) jsr, ret returnAddress type used
Java Virtual MachineJava Virtual Machine1515
7. Verification of Class Files
Module 1
pass 1 – ensure that the file has the basic format of a class file
Verification of Class Files
It is done at Linking Time
pass 2 – verification without looking at actual codepass 3 – verifier checks the code array -> operand
stack tracking
Java Virtual MachineJava Virtual Machine1616
8. Java APIs
Java Platforms
- J2SE, J2EE, J2ME
Java APIs
java.lang
: core API package : have Obejct class
java.awt
: contains classes for constructing GUIs
java.io
: manage data stream, file I/O
Java Virtual MachineJava Virtual Machine1717
8. Java APIs
Serialization & Reflection
- Serialization : make a implementation independent form of objects
In Java implement Serializable interface to do this
- Reflection : find all of objects members
network
storage
platform 1 platform 2
platformindependent
form