Class Note for EECS 700 with Professor Kulkarni at KU (2)
Class Note for EECS 700 with Professor Kulkarni at KU (2)
Popular in Course
Popular in Department
This 53 page Class Notes was uploaded by an elite notetaker on Friday February 6, 2015. The Class Notes belongs to a course at Kansas taught by a professor in Fall. Since its upload, it has received 18 views.
Reviews for Class Note for EECS 700 with Professor Kulkarni at KU (2)
Report this Material
What is Karma?
Karma is the currency of StudySoup.
You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!
Date Created: 02/06/15
HighLevel Language VM Outline 0 Introduction Virtualizing conventional ISA Vs HLL VM ISA Pascal P code virtual machine OO HLL virtual machines properties architecture terms Implementation of HLL virtual machine class loading security GC JNI 19 Introduction HLL PVM similar to a conventional PVM VISA not designed for a real hardware processor HULL l irggwem iHilLiL Compiler frontend Compiler Intermediate Code Portable Code Virtual ISA Compiler backend r j VM loader Loader Traditional HLL VV Virtualizing Conventional ISA Vs HighLeveILanguage VM ISA Drawbacks of virtualizing a conventional ISA not developed for being virtualized operating system dependencies issues with fixedsize address space pagesize memory address formation maintaining precise exceptions instruction set features instruction discovery during indirectjumps selfmodifying and selfreferencing code 3 CISA Not for Being Virtualized Conventional ISA after the fact solution for portability no builtin ISA support for virtualization High level language V ISA VM based portability is a primary design goal generous use of metadata metadata allows better typesafe code verification interoperability and performance 3 Operating System Dependencies Conventional ISA most difficult to emulate exact emulation may be impossible different OS High level language V ISA find a least common denominator set of functions programs interact with the library API library interface is higher level than conventional OS interface 3 Memory Architecture Conventional ISA fixedsize address spaces specific addresses visible to user programs High level language V ISA abstract memory model of indefinite size memory regions allocated based on need actual memory addresses are never visible outof memory error reported if process requests more that is available of platform 3 Memory Address Formation Conventional ISA unrestricted address computation difficult to protect runtime from unauthorized guest program accesses High level language V ISA pointer arithmetic not permitted memory access only through explicit memory pointers staticdynamic type checking employed J Precise Exceptions Conventional ISA many instructions trap precise state needed global flags enabledisable exceptions High level language V ISA few instructions trap test for exception encoded in the program requirements for precise exceptions are relaxed 3 Instruction Set Features Conventional ISA guest ISA registers gt host registers is a problem ISAs with condition codes are difficult to emulate High level language V ISA stackoriented condition codes are avoided 3 Instruction Discovery Conventional ISA indirect jumps to potentially arbitrary locations variablelength instruction embedded data padding High level language V ISA restricted indirectjumps no mixing of code and data variablelength instructions permitted 10 5 SelfModifyingReferencing Code Conventional ISA pose problems for translated code High level language V ISA selfmodifying and selfreferencing code not permitted 11 g Pascal Pcode Popularized the Pascal language simplified porting of a Pascal compiler Introduced several concepts used in HLL VMs stackbased instruction set memory architecture is implementation independent undefined stack and heap sizes standard libraries used to interface with the OS Objective was compiler portability not application portability 12 g Pascal PCode 2 Protection via trusted interpreter 0 Advantages porting is simplified don39t have to develop compilers for all platforms VM implementation is smallersimpler than a compiler VM provides concise definition of semantics Disadvantages achieving OS independence reduces API functionality to least common denominator tendency to add platformspecific API extensions 13 Object Oriented HLL Virtual Machines Used in a networked computing environment Important features of HLL VMs security and protection protect remote resources local files VM runtime robustness OOP model provides componentbased programming strong typechecking and garbage collection networking incremental loading and small codesize performance easy code discovery allows entire method compilation 14 3 Terminology Java Virtual Machine Architecture ltigt CLI analogous to an ISA 0 Java Virtual Machine Implementation gtCLR analogous to a computer implementation 0 Java bytecodes ltigt Microsoft Intermediate Language MSIL CIL IL the instruction part of the ISA Java Platform ltigt NET framework ISA Libraries a higher level ABI 15 6 Modern HLL VM 0 Compiler frontend produces binary files standard format common to all architectures Binary files contain both code and metadata Virtual Machine Implementation Machine Independent Program File 5 Security Remote System A key aspect of modern network oriented Vms quotprotection sandbox 0 Must protect remote resources files local files runtime Java39s first generation AaaliQEFIT 13quot security method still the default 17 3 Protection Sandbox 39 Remote FESOUFCES a g a protected by remote system 0 Local resources protected by security manager VM software protected via v staticdynamic checking E m l mm iEE JQJf iE 18 9 Java 11 Security Signing Identifies source of the input program can implement different security policies for programs from different vendors match gt signature OK private key public key 19 3 Java 2 Security Stack Walking Ins ect rivile es p p g Method 1 System Full of all methods on W39teA pe a i32 fl 39 39 stack MethodZ Untruste only Pr 39 39e append method Method3 System Full permISSIons method 4 attempts Method 4 Untruste Igspeit t to write file B Vla ac i0 m eth 0d 5 anneitgfpf System Full call fails since methodz does not Check Method System Full have privileges principal permissions 20 5 Garbage Collection Issues with traditional mallocfree newdelete explicit memory allocation places burden on programmer dangling pointer double free errors Garbage collection objects with no references are garbage must be collected to free up memory for future object allocation OS limits memory use by a process eliminates programmer pointer errors 21 3 Network Friendliness Support dynamic class loading on demand load classes only when needed spread loading over time 0 Compact instruction encoding zeroaddress stackbased bytecode to reduce code size contain significant metadata maybe a slight code size win over RISC fixedwidth ISAs 22 5 Java ISA Formalized in classfile specification 0 Includes instruction definitions bytecodes Includes data definitions and interrelationships metadata 23 5 Java Architected State 0 Implied registers program counter local variable pointer operand stack pointer current frame pointer constant pool base Stack arguments locals and operands Heap objects and arrays implementationdependent object representation Class file content constant pool holds immediates and other constant information 24 5 Data Items Types are defined in specification implementation free to choose representation reference pointers and primitive byte int etc types 0 Range of values that can be held are given eg byte is between 127 and 128 data is located via references as fields of objects in heap offsets using constant pool pointer stack pointer 25 Data Accessing Instruction stream od ode od ode ode ode 0 ran 0 ode 26 I9 Instruction Set Bytecodes single byte opcode zero or more operands 0 Can access operands from instruction current constant pool current frame local variables values on operand stack 27 Instruction Types Pushing constants onto the stack Moving local variable contents to and from the stack Managing arrays Generic stack instructions dup swap pop amp nop Arithmetic and logical instructions Conversion instructions Control transfer and function return Manipulating object fields Method invocation Miscellaneous operations Monitors 28 5 Stack Tracking 0 At any point in program operand stack has same number of operands of same types and in same order regardless of the control path getting there Helps with static type checking 29 3 Stack Tracking Example Valid bytecode sequence iload A llpush int A from local mem iload B llpush int B from local mem lfcmpne 0 else ll branch if B ne 0 iload C II push int C from local mem goto endelse else iload F llpush F endelse add ll add from stack result to stack istore D II pop sum to D 30 3 Stack Tracking Example 0 Invalid bytecode sequence stack at skip1 depends on controlflow path iload B ll push int B from local mem fcmpne 0 skip1 ll branch if B ne 0 iload C II push int C from local mem skip1 iload D II push D iload E II push E ifcmpne o skipz ll branch if E ne 0 add ll add stack result to stack skip2 istore F ll pop to F 31 5 Exception Table 0 Exceptions identified by table in class file address Range where checking is in effect target if exception is thrown operand stack is emptied 0 If no table entry in current method pop stack frame and check calling method default handlers at main From To Target Type 8 12 96 Arithmetic Exception 32 39 0 Magic number and header 0 Regions preceded by counts constant pool interfaces field information methods attributes Binary Class Format Fi flfdlfcfou rft i i quotv v furH 7 rRt tFi39b T tegiGm t 39I 33 5 Java Virtual Machine Abstract entity that gives meaning to class files 0 Has many concrete implementations hardware interpreter JlT compiler Persistence an instance is created when an application starts terminates when the application finishes 34 9 JVM Implementation 0 A typical JVM implementation consists of class loader subsystem memory subsystem emulation execution engine garbage collector class les addresses native method libraries 35 5 Class Loader Functions find the binary class convert class data into implementationdependent memory image verify correctness and consistency of the loaded classes Security checks checks class magic number component sizes are as indicated in class file checks numbertypes of arguments verify integrity of the bytecode program 36 Protection Sandbox L al l s mm WWW Store must be to reference and field with correct types Load type determin d from referencefield t pe Array stores are range checked Array loads are range checked Move to local storage must be to a location with correct type Move to operand stroage type determined from local storage type tracked types 37 Protection Sandbox Security Manager A trusted class containing check methods a attached when Java program starts cannot be removed or changed 0 User specifies checks to be made files types of access etc Operation native methods that involve resource accesses eg IO first call check methods 38 5 Verification Class files are checked when loaded to ensure security and protection 0 Internal Checks checks for magic number checks for truncation or extra bytes each component specifies a length make sure components are wellformed 39 5 Verification 2 Bytecode checks check valid opcodes perform full path analysis regardless of path to an instruction contents of operand stack must have same number and types of items checks arguments of each bytecode check no local variables are accessed before assigned makes sure fields are assigned values of proper type 40 5 Java Native Interface JNI Allows java code and native code to interoperate access legacy code system calls from Java access Java API from native functions see figure on next slide each side compiles to its own binary format differentjava and native stacks maintained arguments can be passed valuesexceptions returned 41 Java Native Interface JNI Java Side Native Side Byt c de Nature Machine code Methods 1 k A getfielgi r i loadstore putfield ff 39 H z rs 42 Garbage Collector Provides implicit heap object space reclamation policy Collects objects that have all their references removed or destroyed Invoked at regular intervals or when low on memory see figure on next slide root set point to objects in heap objects not reachable from root set are garbage 43 Garbage Collector 2 5 Types of Collectors 0 Reference count collectors keep a count of the number of references to each object 0 Tracing collectors using the root set of references 45 3 Mark and Sweep Collector Basic tracing collector start with root set of references trace and mark all reachable objects sweep through heap collecting marked objects Advantages does not require moving objectpointers Disadvantages garbage objects combined into a linked list leads to fragmentation segregated freelists can be used consolidation of free space can improve efficiency 46 3 Compacting Collector 0 Make free space con guous multiple passes through heap lot of object movement many pointer updates 47 g Copying Collector 0 Divide heap into halves collect when one half full mugail copy into unused half during sweep phase Reduces passes through heap Wastes halfthe heap u lt iuiletg l 9 Simplifying Pointer Updates Add level of indirection GI b IH use handle pool a eap object moves update handle pool 0 Makes every object access slow 49 5 Generational Collectors Reduce number of objects moved during each collection cycle 0 Exploit the bi modal distribution of object lifetimes 0 Divide heap into two sub heaps nursery for newly created objects tenured for older objects Collect a smaller portion ofthe heap each time 50 5 Generational Collectors 2 Stoptheworld collectors time consuming long pauses unsuitable for realtime applications 51 5 Concurrent Collectors 2 GC concurrently with application execution partially collected heap may be unstable see figure synchronization needed between the application mutator and the collector ROOt set1 ROOt set 52 5 JVM Bytecode Emulation 0 Interpretation simple fast startup slow steadystate Just ln Time JIT compilation compile each method on first invocation simple optimizations slow startu p fast steadystate Hot spot compilation compile frequently executed code can apply more aggressive optimizations moderate startup fast steadystate 53
Are you sure you want to buy this material for
You're already Subscribed!
Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'