Java and The JVM: Martin Schöberl
Java and The JVM: Martin Schöberl
Martin Schberl
Overview
History and Java features Java technology The Java language A first look into the JVM Disassembling of .class files
Java features
Portability
Java compiler generates bytecodes Runtime systems for various platforms Size and behavior of basic data types defined
Availability
Windows, Linux, Solaris, Embedded systems Compiler and runtime are free Free IDEs: Eclipse, Netbeans Rich class library Part of the definition Standard GUI toolkit
Java and the JVM 5
Library
Threads at the language level Synchronization Libraries are thread-safe No Pointer! Extensive compile-time checking Runtime checking Automatic memory management GC
Java and the JVM 6
Safety
Java Technology
The Java programming language The library (JDK) The Java virtual machine (JVM)
double
Objects
No global variables
Namespace for objects Single inheritance Interfaces Allocated on the heap Shared among threads No free() garbage collector
Java and the JVM 10
A virtual machine (VM) is an abstract computer architecture Software on top of a real hardware Can run the same application on different machines where the VM is available
11
An instruction set and the meaning of those instructions the bytecodes A binary format the class file format An algorithm to verify the class file
12
JVM cont.
Runtime environment for Java Implementation NOT defined Runs Java .class files Has to conform to Suns specification
13
Interpreter
Just-in-time compilation
Our topic!
Java and the JVM 14
Method area
Class description Code Constant pool Objects and Arrays Shared by all threads Garbage collected
Java and the JVM 16
Heap
Stack
Not necessary a single stack Local variables and operand stack are accessed frequently
Java and the JVM 17
32 (64) bit stack machine Variable length instruction set Simple to very complex instructions Symbolic references Only relative branches
18
Load and store Arithmetic Type conversion Object creation and manipulation Operand stack manipulation Control transfer Method invocation and return
Java and the JVM 19
Dissassembling Java
Compile
javac Hello.java
Run
java Hello
javap -c Hello
Dissassemble
20
A Bytecode Example
public class X { public static void main(String[] args) { add(1, 2); } public static void main(java.lang.String[]); Code: 0: iconst_1 1: iconst_2 //Method add:(II)I 2: invokestatic #2; 5: pop 6: return public static int add(int,int); Code: 0: iload_0 1: iload_1 2: iadd 3: ireturn
Java and the JVM 21
22
23
Summary Java/JVM
Java language definition Class library The Java virtual machine (JVM)
An instruction set the bytecodes A binary format the class file An algorithm to verify the class file
25
Safe OO Language
Built in model for concurrency Platform independent Very rich standard library
Java and the JVM 26
More Information
Java
James Gosling, Bill Joy, Guy Steele, and Gilad Bracha. The Java Language Specification, Addison-Wesley, 2000, JavaSpec. Tim Lindholm and Frank Yellin. The Java Virtual Machine Specification. Addison-Wesley, 1999, JVMSpec.
JVM
27