Virtual Machines (December 12, 2016) assignment 6 due Friday final exam next Tuesday 12:30-3:30 here ** course evaluations available on line; please complete! ** -------- Library is preexisting code you can call. Run-time system is library that makes assumptions about how the compiler works may use tables generated by the compiler may examine or manipulate heap or stack layout e.g., GC requires help finding root pointers and type descriptors; needs compiler to generate write barriers Virtual machine is run-time system that provides/specifies everything the program needs, including instruction set -------- Java Virtual Machine (JVM) recall how Java works compiler translates Java source to Java byte code (JBC) byte code runs on virtual machine virtual machine may be implemented via interpretation, JIT compilation, or some combination of the two machine architecture has all & only Java's built-in types (but invokedynamic added to JVM for Java 7, to support Java lambdas & dynamic languages) type safety definite assignment garbage collection threads global _constant pool_, per-thread stacks, heap, method (code) area [each stack frame contains array of locals & formals each slot 32 bits wide (longs and doubles take 2) can be reused for temporally disjoint data of different types expression evaluation stack (sized to accommodate largest expression in the method)] implicit references to the current program counter, frame, top of operand stack within frame, symbol table info in constant pool defines format of .class files at start-up, JVM loads given class file (which must have a main()) verifies that it satisfies various invariants type safety no operand stack overflow or underflow all references to the constant pool and the locals array are within bounds all constant pool entries are well formed no inheritance from a final class definite assignment several of these require data flow analysis allocates and initializes static data links to library classes calls main in a single thread JBC load-store back and forth between local variable array and operand stack arithmetic all done implicitly on the operand stack type conversion object mgmt new, field and array element access, reflection push, pop, dup, swap branches, switch specify targets as indices in instruction array of current method static and virtual method calls specify target symbolically by name (index in constant pool) throw exception monitor enter, exit (wait, notify, notifyAll are method calls) << see list insertion example in the text >> Lazy binding of machine code JIT tradeoff between load time and optimization quality HotSpot has "client" and "server" modes faster than you might think (heavy lifting done by javac) incremental compilation compilation of hot methods in parallel with interpretation caching of machine code across runs dynamic inlining binary translation FX!32 (x86 -> Alpha) Apple Rosetta (PowerPC -> x86) challenges: where are the function boundaries? what are types of data in memory? what locations are targets of branches? self-modifying code dynamically generated code introspection binary rewriting trace scheduling HP Dynamo (PA-RISC) & DynamoRIO (x86), late 1990s instrumentation statistics gathering simulate new architectures insert dynamic semantic checks (Valgrind) sandboxing Pin tool trace-based