Presentation is loading. Please wait.

Presentation is loading. Please wait.

JVM Overview References Virtual Machine Background JVM: operational view JVM: structural view Concluding remarks.

Similar presentations


Presentation on theme: "JVM Overview References Virtual Machine Background JVM: operational view JVM: structural view Concluding remarks."— Presentation transcript:

1 JVM Overview References Virtual Machine Background JVM: operational view JVM: structural view Concluding remarks

2 Reading List zPrimary: yLY99 Chapter 3. Structure of the Java Virtual Machine yVenners98 Chapter 5. The Java Virtual Machine yGJS96 Chapter 12: Execution zOther references ySurvey of VM Research 1974 x“Virtual machines have finally arrived. Dismissed for a number of years as academic curiosities, they are now seen as cost effective techniques for organizing computer systems…” yInferno Virtual Machine yOak Intermediate Bytecode yVariety of web-sites

3 What is a virtual machine? zDavid Gelernter: Truth, beauty, and VMs y“A running program is often referred to as a VM -- a machine that doesn’t exist as a matter of actual physical reality. The virtual machine idea is … most elegant in the history of technology … a crucial step in the evolution of ideas about software.” zan operating system za control program to run multiple operating systems

4 Design Goals zabstract enough zclose enough to the hardware zquestion: what is the intended use? zInferno: run OS code zJVM: run application code

5 What is the JVM?

6 Key Distinction zwhat is the specification? zwhat is the implementation? yobject layout is not part of the specification ygarbage collection is not part of the spec

7 JVM: View 1 zfrom the language point of view ztrace the lifetime of a virtual machine zinvocation, loading-linking, object lifetime, exit

8 VM in action zinvoked “java Test args” zattempts to find class Test zVM uses the class loader zLink zInitialize zInvoke Test.main

9 Loading zcheck whether already loaded zif not, invoke the appropriate loader.loadClass zinternal table is part of the specification? zclass loader flexibility: prefetch, load a bunch zprefetching can be non-transparent! zerrors, however, need to be reported separately zclass loader hooks: defineClass, findSystemClass, resolveClass

10 Link zLink = verification, preparation, resolution zVerification: semantic checks, proper symbol table yproper opcodes, good branch targets yconservation of stack depth zPreparation: allocation of storage (method tables) zResolution: resolve symbol references, check access, check concreteness zResolution: eager vs lazy strategy

11 Initialization zinitialize class variables, static initializers zdirect superclass need to be initialized prior zhappens on direct use: method invocation, construction, field access zsynchronized initializations: state in Class object ycheck for recursive initializations

12 Example class Super { static { System.out.print(“Super “); } class One { static { System.out.print(“One “); } class Two extends Super { static { System.out.print(“Two “); } class Test { public static void main(String[] args) { One o = null; Two t = new Two(); System.out.println((Object)o == (Object)t); }

13 Example class Super { static int taxi = 1729; } class Sub extends Super { static { System.out.print(“Sub “); } class Test { public static void main(String[] args) { System.out.println(Sub.taxi); }

14 Creation of new instances zinstance creation expressions: new zClass.newInstance() zstring literals, concatenation operations zorder: ydefault field values yinvoke constructor yinvoke another constructor of this class yinvoke super’s constructors yinitialize instance variables yexecute rest of the constructor

15 Finalization zinvoked just before garbage collection zlanguage does not specify when it is invoked zalso does not specify which thread zno automatic invocation of super’s finalizers zvery tricky! void finalize() { classVariable = field; // field is now reachable }

16 State Machine

17 VM Exit zclassFinalize similar to object finalization zclass can be unloaded when yno instances exist yclass object is unreachable zVM exits when: yall its threads terminate yRuntime.exit or System.exit assuming it is secure zfinalizers can be optionally invoked on all objects just before exit

18 JVM: View 2 zdata types, values zruntime data areas zexceptions zinstruction set zobject management zsupport for special libraries

19 Data types and values zcorresponds to Java language types ybyte, short, int, long, char, float, double, boolean yreturnAddress type is only exception yreferences: concrete value of null left to implementation zinteger sizes: is it too constraining? zfloating point values: standard and extended zno runtime type information zinstruction specifies the type of operands yiadd as opposed to fadd

20 Object Representation zleft to the implementation zadd extra level of indirection ymake garbage collection easier zneed pointers to instance data and class data zmutex lock zGC state (flags)

21 Runtime Data Areas zper-thread vs. VM wide zpc register: per thread, undefined while executing native methods zVM stack (per-thread) ylocal variables, partial results ymethod invocation, return ycan be heap allocated as well as non-contiguous ysize can be manipulated by the programmer yStackOverflowError vs OutOfMemoryError

22 Runtime Data Areas zHeap (VM wide) yfor storing objects yassumes no particular GC method yheap size can expand, user control exists ymight cause OutOfMemoryError zMethod area (VM wide) yruntime constant pool yfield and method data ycode ylogically part of the heap zNative method stacks: how to catch exceptions?

23 VM Stack Frames zcreated and destroyed with method invocations zlocal variable array, own operand stack zlocal variable array elements can store a float/int yover-specification? yused for parameter passing yinstance methods pass “this” as 0th argument zoperand stack: depth determined at compile-time yelements can hold any type zreference to the class’s runtime constant pool ysymbolic references for dynamic linking

24 Initialization Methods zspecially named z for instances yinvokespecial instruction ycan be invoked only on uninitialized instances z for classes yimplicitly invoked

25 Exceptions zeach catch/finally clause is represented as an exception handler zassociated with each handler is the code extent zexception handler table is ordered by the compiler zJVM does not enforce strict nesting

26 Instruction set zvariable size instruction zone-byte opcode followed by arguments zbyte aligned except for operands of tableswitch and lookupswitch zcompactness vs. performance ztypes part of the instruction (iload, fload) zuse int operations for byte, char, short, int, reference zsome are type-independent (pop, swap)

27 Instructions zload/store zarithmetic zconversion zobject creation, access fields, load/store array elements, get array length, type checks zoperand stack management zcontrol transfer, method invocation, throw zmonitor entry/exit

28 Threads znotion of priorities zdoes not specify time-slicing zcomplex specification of consistency model yvolatiles yworking memory vs. general store ynon-atomic longs and doubles zT.start() is native, invokes T.run()

29 Summary zissues where implementation is not constrained yloading of classes -- bad? yfinalization of objects -- bad? yobject representation -- good zissues where implementation is over-constrained yinteger representations? yimplementation of local variables, expression stacks? clearly, a JIT does not conform to these specifications zwhat really is the specification of the JVM yis it the bytecode and class-file format?


Download ppt "JVM Overview References Virtual Machine Background JVM: operational view JVM: structural view Concluding remarks."

Similar presentations


Ads by Google