JVM Overview References Virtual Machine Background JVM: operational view JVM: structural view Concluding remarks
Reading List Primary: LY99 Chapter 3. Structure of the Java Virtual Machine Venners98 Chapter 5. The Java Virtual Machine GJS96 Chapter 12: Execution Other references Survey of VM Research 1974 “ 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…” Inferno Virtual Machine Oak Intermediate Bytecode Variety of web-sites
What is a virtual machine? David Gelernter: Truth, beauty, and VMs “ 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.” an operating system a control program to run multiple operating systems
Design Goals abstract enough close enough to the hardware question: what is the intended use? Inferno: run OS code JVM: run application code
What is the JVM?
Key Distinction what is the specification? what is the implementation? object layout is not part of the specification garbage collection is not part of the spec
JVM: View  from the language point of view trace the lifetime of a virtual machine invocation, loading-linking, object lifetime, exit
VM in action invoked “java Test args” attempts to find class Test VM uses the class loader Link Initialize Invoke Test.main
Loading check whether already loaded if not, invoke the appropriate loader.loadClass internal table is part of the specification? class loader flexibility: prefetch, load a bunch prefetching can be non-transparent! errors, however, need to be reported separately class loader hooks: defineClass, findSystemClass, resolveClass
Link Link = verification, preparation, resolution Verification: semantic checks, proper symbol table proper opcodes, good branch targets conservation of stack depth Preparation: allocation of storage (method tables) Resolution: resolve symbol references, check access, check concreteness Resolution: eager vs lazy strategy
Initialization initialize class variables, static initializers direct superclass need to be initialized prior happens on direct use: method invocation, construction, field access synchronized initializations: state in Class object check for recursive initializations
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); } }
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); } }
Creation of new instances instance creation expressions: new Class.newInstance() string literals, concatenation operations order: default field values invoke constructor invoke another constructor of this class invoke super’s constructors initialize instance variables execute rest of the constructor
Finalization invoked just before garbage collection language does not specify when it is invoked also does not specify which thread no automatic invocation of super’s finalizers very tricky! void finalize() { classVariable = field;  //  field is now reachable }
VM Exit classFinalize similar to object finalization class can be unloaded when no instances exist class object is unreachable VM exits when: all its threads terminate Runtime.exit or System.exit assuming it is secure finalizers can be optionally invoked on all objects just before exit

testing ppt

  • 1.
    JVM Overview ReferencesVirtual Machine Background JVM: operational view JVM: structural view Concluding remarks
  • 2.
    Reading List Primary:LY99 Chapter 3. Structure of the Java Virtual Machine Venners98 Chapter 5. The Java Virtual Machine GJS96 Chapter 12: Execution Other references Survey of VM Research 1974 “ 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…” Inferno Virtual Machine Oak Intermediate Bytecode Variety of web-sites
  • 3.
    What is avirtual machine? David Gelernter: Truth, beauty, and VMs “ 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.” an operating system a control program to run multiple operating systems
  • 4.
    Design Goals abstractenough close enough to the hardware question: what is the intended use? Inferno: run OS code JVM: run application code
  • 5.
  • 6.
    Key Distinction whatis the specification? what is the implementation? object layout is not part of the specification garbage collection is not part of the spec
  • 7.
    JVM: View from the language point of view trace the lifetime of a virtual machine invocation, loading-linking, object lifetime, exit
  • 8.
    VM in actioninvoked “java Test args” attempts to find class Test VM uses the class loader Link Initialize Invoke Test.main
  • 9.
    Loading check whetheralready loaded if not, invoke the appropriate loader.loadClass internal table is part of the specification? class loader flexibility: prefetch, load a bunch prefetching can be non-transparent! errors, however, need to be reported separately class loader hooks: defineClass, findSystemClass, resolveClass
  • 10.
    Link Link =verification, preparation, resolution Verification: semantic checks, proper symbol table proper opcodes, good branch targets conservation of stack depth Preparation: allocation of storage (method tables) Resolution: resolve symbol references, check access, check concreteness Resolution: eager vs lazy strategy
  • 11.
    Initialization initialize classvariables, static initializers direct superclass need to be initialized prior happens on direct use: method invocation, construction, field access synchronized initializations: state in Class object check 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 newinstances instance creation expressions: new Class.newInstance() string literals, concatenation operations order: default field values invoke constructor invoke another constructor of this class invoke super’s constructors initialize instance variables execute rest of the constructor
  • 15.
    Finalization invoked justbefore garbage collection language does not specify when it is invoked also does not specify which thread no automatic invocation of super’s finalizers very tricky! void finalize() { classVariable = field; // field is now reachable }
  • 16.
    VM Exit classFinalizesimilar to object finalization class can be unloaded when no instances exist class object is unreachable VM exits when: all its threads terminate Runtime.exit or System.exit assuming it is secure finalizers can be optionally invoked on all objects just before exit