Académique Documents
Professionnel Documents
Culture Documents
Contents
Introduction of HLL VM The Pascal P-code VM Object-Oriented HLL VM Java VM Architecture
Modify source code ( e.g., system call ) Painful for S/W venders
Employ process VM to avoid porting Emulating applications ISA and OS calls Difficult to emulate some OS interfaces completely High-performance is hard to achieve
3
HLL VM
New design of ISA/interface with VM-based portability
Generic ISA free of implementation-specific features Abstracted system interface easily supported by OS Support for target HLL such as OO languages Compared to process VM,
Supports virtual ISA (V-ISA) Interface based on standard libraries (API) for network, file, graphics
HLL program
Compiler frontend
Intermediate code
Compiler backend
Memory image
Host instruction
Overview
Source code is translated into an intermediate representation, (IR) The IR can be processed in these different ways:
1. compile-time (static) translation to machine code 2. emulation of the IR using an interpreter 3. run-time (dynamic) translation to machine code = JIT (Just-In-Time) compiling
Examples:Language IR Implementation(s)
Language
IR
Implementation
Java C#
Pascal
C, C++
--
10
JVM
Major components
Class loader subsystem Memory system
Including garbage-collected heap
Emulation engine
11
Java VM Architecture
Java VM is for executing Java programs
Usually referred to as Java Runtime Environment (JRE) Contains the Java virtual machine, classes comprising the Java 2 Platform API, and supporting files JDK (Java development kit): JRE, Development Tools (compiler, debugger), additional library
a.java
c.java
a.class
b.class
c.class
JVM
c.class Object.class String.class
12
a.class
b.class
Data accessing
13
14
15
16
Memory regions
Each time a class is loaded, info about the class is copied into t he method area. While a program is running, all instantiated objects (instances of classes, arrays) are allocated on the heap. When a new thread comes into existence, it gets its own Java stack and its own pc register. The pc register indicates which JVM instruction to execute next in a methods bytecode. The Java stack contains all the state information for a thread The state of native method invocations is held in a native method stack.
17
19
Class loaders
Primordial class loader
Defined as part of the JVM specification Trusted JVM component
For security
Separate namespace
Barrier between the different namespaces Tag loaded classes
20
The Heap
One entry for each object Increases with each instance creation Decreases with garbage collection (mec hanism not specified) Object information: instance field values, pointer to class Shared by all threads.
22
Java Stack
JVM pushes and pops frames onto this stack Each frame corresponds to the invocation of a method Call a method push its frame onto the stack Return from a method pop its frame Frame holds parameter values, local variables, intermediate values etc.
23
Garbage collector
Reclaim heap memory no longer needed Included in most JVM implementations
Emulation engine
Supported by the native method interface & implied registers Can be interpreter or translator
24
To bridge the gap between the platformindependent and platform-dependent parts of the overall system
25
Example
Consider a bytecode sequence that corresponds to i = (j + 2) * (k - 2); The byecode is similar to this (using symbolic names and constant values instead of indexes):
iload j ldc 2 iadd iload k ldc 2 isub imul istore i
26
Example Contd
27
Data Types
Primitive data types
int, char, byte, short, float, double
Reference type
Hold a reference value or null
Objects
Carry data declared by the class Composed of primitive data or references to other objects array is a special object with ISA support
28
Data types
29
Arithmetic Operations
Operands are normally taken from operan d stack and the result pushed back there
iadd, ladd, fadd, dadd isub ... imul ... idiv ...
31
HLL VM Examples
Pascal VM with a V-ISA called P-code Java VM with a V-ISA called bytecode Common language infrastructure (CLI) in .NET platform with a V-ISA called MSIL
32
Memory Architecture
Program memory, constant area, stack, and heap
All data areas are divided into cells,
Each cell can hold a single value Actual size of cell is implementation dependent but large enough
No garbage collection
34
Memory Architecture
MP EP
function value static link dynamic link previous EP return address parameters locals operand stack
NP
function value static link dynamic link previous EP return address parameters
MP
mark stack
SP EP
MP : beginning of the stack frame EP : maximum extent of current frame NP : maximum extent of the heap SP : current top of the operand stack 35
P-code
Basis for later HLL VMs V-ISA
Stack ISA with minimum registers is easily portable to any ISA Stack ISA leads to small binaries Cell-based memory model whose details are not part of ISA Interface to OS is through libraries only
Minimum libraries common to all platforms lead to weak I/O
36
Transformation done by VM
Machine Independent Program File Virtual Machine Implementation Loader Metadata Interpreter Code Native Code Internal Data Structures
Translator
37
Access to local files Prevent application from accessing memory and code that is outside the sandbox, even though they are shared with VM
Static checking by a trusted loader Dynamic checks by a trusted emulation engine
38
Robustness : Object-Orientation
Class and objects Inheritance, Methods, Polymorphism Objects can only be accessed via references
Array is also intrinsic form of object in JVM and CLI
39
Garbage Collection
Objects are created and float in memory space Garbage During program execution, many objects are created then abandoned, so become garbage Collection Due to limited memory, we collect garbage To improve robustness, make the VM collect garbage automatically
40
Performance Issues
OO languages are slower than non-OO languages VM-based HLL are even slower than native execution CPU speed increases can reduce performance issues But most VMs employ high-performance techniques
Most emulation techniques can be used Interpretation, dynamic binary translation, static translation
.NET FRAMEWORK
42
CLR
Manages running code
Verifies type safety Provides garbage collection, error handling Code access security for semi-trusted code
44
46
47
48
49
50
51
Garbage collection
Object oriented programming environment
Problem
Objects are freely created
Not destroyed explicitly in Java
Solution
Garbage collection
Garbage : objects that are no longer accessible
Root set
Set of references point to objects held in the global memory heap Garbage
Cannot be reached through a sequence of references beginning with the root set
53
54
Garbage collector
Essential part of JVM implementation Find inaccessible garbage objects
Beginning with the root set
55
Mark-and-sweep collectors
Mark stage Start with the root references Mark all reachable objects Sweep stage All unmarked objects are collected Combining garbage into a linked list of free objects Relatively fast Memory fragmentation problem Free objects of varying size are scattered Fixed size chunks can be used
56
Compacting collectors
Free F
E D
C B A
57
Compute the new locations for the live objects Move objects Update all references to point to the new locations
Too much overhead Handle pool
Good for updating on garbage collection
58
59
60
61
Generational collectors
Object lifetimes : bimodal distribution
Very short lifetime vs. very long lifetime
62
Solution
Incremental collection Concurrent collection
When multiple processors are available
Synchronization is required
Ex) write barriers
63
Summary
64