Presentation is loading. Please wait.

Presentation is loading. Please wait.

Aarhus University, 2005Esmertec AG1 Implementing Object-Oriented Virtual Machines Lars Bak & Kasper Lund Esmertec AG

Similar presentations


Presentation on theme: "Aarhus University, 2005Esmertec AG1 Implementing Object-Oriented Virtual Machines Lars Bak & Kasper Lund Esmertec AG"— Presentation transcript:

1 Aarhus University, 2005Esmertec AG1 Implementing Object-Oriented Virtual Machines Lars Bak & Kasper Lund Esmertec AG {lbak,klund}@esmertec.com

2 Aarhus University, 2005 Esmertec AG 2 What Is A Virtual Machine? A virtual machine is a software abstraction layer implemented on top of a "real" hardware platform and operating system

3 Aarhus University, 2005 Esmertec AG 3 Why Are VMs Interesting? Platform independence Code migration Works for small embedded systems and large server systems Most modern programming languages are expecting a virtual machine Enables aggressive optimization

4 Aarhus University, 2005 Esmertec AG 4 What Is Performance? Fast execution Fast startup time Fast warm-up time Small pauses Scalable Heap size CPUs

5 Aarhus University, 2005 Esmertec AG 5 Obstacles To Performance? Platform independent byte codes Object-oriented Virtual calls are the default High call frequency High allocation rate Garbage collection Synchronization in language Dynamic class loading

6 Aarhus University, 2005 Esmertec AG 6 … But That Is Not Enough Preserve the illusion of bytecode interpretation Important for platform independent debugging Provides serviceability for systems in production systems

7 Aarhus University, 2005 Esmertec AG 7 The Agenda Fast virtual dispatch Runtime compilation Adaptive compilation Applying aggressive optimizations OSVM + demonstration

8 Aarhus University, 2005 Esmertec AG 8 Our Background Beta runtime system Self virtual machine and IDE Strongtalk virtual machine Java HotSpot virtual machine CLDC HI virtual machine OSVM embedded platform 20+ years of experience in designing and implementing object oriented virtual machines

9 Aarhus University, 2005 Esmertec AG 9 Dynamic Dispatch Core part of execution in most OO systems Target method at a call site depends on receiver type Runtime lookup is needed to find the method

10 Aarhus University, 2005 Esmertec AG 10 Lookup Function f(receiver type, name) -> method Implementation techniques for making the lookup function efficient Virtual dispatch tables Inline caches Hash table

11 Aarhus University, 2005 Esmertec AG 11 Virtual Dispatch Tables Indirect method table Often used in statically typed languages like Java and C++ Technique Object points to dispatch table Method gets index in table of defining class Call vtbl = obj->vtable() target = vtbl[index] call target

12 Aarhus University, 2005 Esmertec AG 12 Problems With Vtable Indirect calls are very expensive on modern CPUs Can only handle single inheritance in strongly typed systems Does not work with interface calls Makes incremental execution very hard

13 Aarhus University, 2005 Esmertec AG 13 Inline Caching Save the result from last lookup Deusch-Schiffman Smalltalk, 1984 >85% of all calls are monomorphic in most object oriented systems Use self modifying code for implementation Where should the cache result reside?

14 Aarhus University, 2005 Esmertec AG 14 Inline Caching Call site has several modes Empty (no targets) Monomorphic (one target) Megamorphic Inline caching used in monomorphic case

15 Aarhus University, 2005 Esmertec AG 15 Code For Inline Cache Caller // receiver is in ecx move eax, call target Callee cmp eax, ecx[class offset] bne _inline_cache_miss … code for callee method …

16 Aarhus University, 2005 Esmertec AG 16 Inline Caching Fast on modern CPUs Used in most OO systems where self modifying code is permissible Side benefit: type information is collected

17 Aarhus University, 2005 Esmertec AG 17 Hash Tables Often needed with dynamic typing Used in Smalltalk and Self Cache for f(receiver type, name) -> method Used as secondary lookup for inline cache

18 Aarhus University, 2005 Esmertec AG 18 Hash Table Problems Many collisions result in slow down But, what about a 2-way associative cache Hard to update in multi threaded execution Use thread local cache

19 Aarhus University, 2005 Esmertec AG 19 Combined Solutions Inline caching + hash table Self + Smalltalk Inline caching + virtual table Java

20 Aarhus University, 2005 Esmertec AG 20 Dynamic Compilation The process of compiling at runtime Goals Fast startup Great performance Good interactive performance Minimize memory footprint

21 Aarhus University, 2005 Esmertec AG 21 Execution Model Interpreter and compiled code combination Allows the systems to decide: When to compile? What to compile?

22 Aarhus University, 2005 Esmertec AG 22 Adaptive Compilation Interpreter bytecoded methods compiled methods Profiler / Recompiler Compiler

23 Aarhus University, 2005 Esmertec AG 23 Should We Compile That Method? Compile the method if the total execution time is reduced How do we predict if it is beneficial? Use the past to predict the future

24 Aarhus University, 2005 Esmertec AG 24 Learning From The Past Maintain a sliding window of the past to answer: What to compile? When to compile? Two approaches: Invocation counters Sample based profiling

25 Aarhus University, 2005 Esmertec AG 25 Why We Need Inlining Too many dynamic dispatch Inlining will: Create bigger basic blocks Give compiler more to work on Might avoid allocation

26 Aarhus University, 2005 Esmertec AG 26 Aggressive Inlining Use class hierarchy analysis if language has static types Inline based on the current state of the class hierarchy Back out if class loading violates assumptions Use deoptimization as described later

27 Aarhus University, 2005 Esmertec AG 27 Deoptimization The act of converting a compiled activation into a set of interpreter activations Allow the system to Back out of inlining decisions Preserve the bytecode illusion

28 Aarhus University, 2005 Esmertec AG 28 Needed Information Debugging information stored with compiled code Enough information to reconstruct the interpreter state at each interrupt points Access to compiled frames

29 Aarhus University, 2005 Esmertec AG 29 What Can Deoptimization Be Used For? Backing out of aggressive inlining Source level inspection Support for source code level debugging Support for incremental execution

30 Aarhus University, 2005 Esmertec AG 30 The Process Of Deoptimization 1)Identify activations to deoptimize 2)Transform the compiled activations into an off- stack interpreter based representation 3)Insert trap and remove compiled method 4)When returning to activation unpack the off- stack representation to the stack 5)Continue execution in interpreter

31 Aarhus University, 2005 Esmertec AG 31 Virtual Machine Performance Summary Object oriented optimizations Agressive inlining Subtype check (instanceof & cast) Efficient memory management system Fast allocation Efficient garbage collection Ultra fast synchronization... and a good compiler

32 Aarhus University, 2005 Esmertec AG 32 The OSVM Product OSVM IDE OSVM Embedded Platform A middleware platform for creating secure, object-oriented, real-time software for embedded devices Always-on platform Requires minimal memory Increases development productivity Enables analysis and correction of software problems in the field Enables minimal updates of deployed software

33 Aarhus University, 2005 Esmertec AG 33 OSVM Components OSVM IDE Plugin to Eclipse 3.0 Integrated with CVS Configuration of services Complete tool chain OSVM Libraries Core classes Debugging and reflection OSVM Virtual Machine Executes platform-independent code Runs on various platforms OSVM RTOS Small hard real time operating system Allows tight hardware integration

34 Aarhus University, 2005 Esmertec AG 34 OSVM Demonstration Intelligent tank demonstration OSVM IDE

35 Aarhus University, 2005 Esmertec AG 35 Summary Discussed various virtual machine optimizations However, the real reason for being here: Hire part time student programmers for our cool project


Download ppt "Aarhus University, 2005Esmertec AG1 Implementing Object-Oriented Virtual Machines Lars Bak & Kasper Lund Esmertec AG"

Similar presentations


Ads by Google