140 likes | 356 Views
Introduction to JVM. Based on material produced by Bill Venners. The Java programming environment. The Java platform. byte code generated by the Java front-end is an intermediate representation (IR) clean and compact platform-independent. The role of the virtual machime. Local or
E N D
Introduction to JVM Based on material produced by Bill Venners
The Java platform • byte code generated by the Java front-end is an intermediate representation (IR) • clean and compact • platform-independent
The role of the virtual machime Local or Remote
Java bytecode format • void spin () { int i; for (i = 0; i < 100; i++) {;} } 0 iconst_0 // push int constant 0 1 istore_1 // store into var 1 "i=0"2 goto 8 // first time: don't incr5 iinc 1 1 // incr var 1 by 1 "i++"8 iload_1 // push local var 1 "i"9 bipush 100 // push byte const "100"11 if_icmplt 5 // loop if less "i < 100"14 return // return void when done • branch instructions use relative displacement, i.e., add/subtract from PC => easy combination • disassembled code uses absolute pseudo-labels
Java bytecode basics • no run-time tag checking (but objects have metadata) • "untyped" local variables, reused for different types • type tags are carried along the instructions • the verification phase of class loading ensures validity: types are OK, no operand stack overflow.. • bytecode categories • arithmetic: add, sub, mul, rem, div (typed versions) • operand stack management: load/store, dup, swap • control transfer: goto <offset>, if_icmpeq, ifeq, .. • type conversions: i2l, i2f, l2f, f2i, d2i, int2byte, etc. • method invocation and return: invokevirtual, invokestatic, ireturn, lreturn, return, etc. • throwing exceptions, monitors, etc..
Back-end transformation and execution (1) simple JVM • byte code interpretation, including resolution of symbolic references: • finding the entity identified by a text symbol and replacing it with a direct reference (2) JIT (Just-In-Time) compiler • method byte codes are compiled into native machine code the first time they are invoked • the machine code is cached for subsequent invocation • compilation overhead & requires more memory (3) adaptive optimization: the interpreter monitors the program, compiling only heavily used parts..
Shared data areas • each JVM has one of each: • method area: byte code and class (static) data storage • heap: object storage
Example representation of objects in heap: • the heap is garbage collected • each JVM has its own heap - supports isolation • or can use handle ptrs pointing to an inderect handle pool
Thread data areas • every thread has its own stack of call frames • in a frame, a fixed-sized stack for expr evaluation Frame in Execution