Dynamic Compilation in an OOL: The Deutsch-Schiffman Smalltalk-80 Implementation “Efficient Implementation of the Smalltalk-80 System” L. Peter Deutsch.

Slides:



Advertisements
Similar presentations
Lecture 10: Part 1: OO Issues CS 540 George Mason University.
Advertisements

The Last Lecture Copyright 2011, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in Comp 512 at Rice University have explicit permission.
(1) ICS 313: Programming Language Theory Chapter 10: Implementing Subprograms.
Introduction to Code Optimization Comp 412 Copyright 2010, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice.
Code Shape IV Procedure Calls & Dispatch Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412.
Intermediate Representations Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice University.
The Procedure Abstraction Part III: Allocating Storage & Establishing Addressability Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all.
Memory Management and Paging CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han.
Previous finals up on the web page use them as practice problems look at them early.
The Procedure Abstraction Part IV: Run-time Structures for OOLs Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students.
The Procedure Abstraction Part I: Basics Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412.
Memory Management 2010.
Introduction to Optimization Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved.
Building An Interpreter After having done all of the analysis, it’s possible to run the program directly rather than compile it … and it may be worth it.
COP4020 Programming Languages
1.3 Executing Programs. How is Computer Code Transformed into an Executable? Interpreters Compilers Hybrid systems.
Session-02. Objective In this session you will learn : What is Class Loader ? What is Byte Code Verifier? JIT & JAVA API Features of Java Java Environment.
Reduced Instruction Set Computers (RISC) Computer Organization and Architecture.
Dynamic Optimization as typified by the Dynamo System See “Dynamo: A Transparent Dynamic Optimization System”, V. Bala, E. Duesterwald, and S. Banerjia,
CH13 Reduced Instruction Set Computers {Make hardware Simpler, but quicker} Key features  Large number of general purpose registers  Use of compiler.
The Procedure Abstraction Part I: Basics Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412.
Code Optimization, Part III Global Methods Comp 412 Copyright 2010, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in Comp 412.
JIT in webkit. What’s JIT See time_compilation for more info. time_compilation.
Overview of the Course Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice University.
Lexical Analysis - An Introduction Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at.
University of Houston-Clear Lake Proprietary© 1997 Evolution of Programming Languages Basic cycle of improvement –Experience software difficulties –Theory.
The Procedure Abstraction, Part VI: Inheritance in OOLs Comp 412 Copyright 2010, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled.
Procedure Abstraction VI Run-time structures for OOLs ( II ) and Wrap-up Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved.
The Procedure Abstraction, Part V: Support for OOLs Comp 412 Copyright 2010, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in.
July 30, 2001Systems Architecture II1 Systems Architecture II (CS ) Lecture 8: Exploiting Memory Hierarchy: Virtual Memory * Jeremy R. Johnson Monday.
IT253: Computer Organization
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-8 Memory Management (2) Department of Computer Science and Software.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 9.
By Teacher Asma Aleisa Year 1433 H.   Goals of memory management  To provide a convenient abstraction for programming.  To allocate scarce memory.
Implementing Subprograms What actions must take place when subprograms are called and when they terminate? –calling a subprogram has several associated.
COMP3190: Principle of Programming Languages
1. 2 Preface In the time since the 1986 edition of this book, the world of compiler design has changed significantly 3.
Operating Systems Lecture 14 Segments Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard. Zhiqing Liu School of Software Engineering.
Introduction to Code Generation Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
CS 598 Scripting Languages Design and Implementation 14. Self Compilers.
CS 598 Scripting Languages Design and Implementation 13. The Deutsch-Schiffman Smalltalk- 80 Implementation.
Boolean & Relational Values Control-flow Constructs Comp 412 Copyright 2010, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in.
1 Structure of Compilers Lexical Analyzer (scanner) Modified Source Program Parser Tokens Semantic Analysis Syntactic Structure Optimizer Code Generator.
Profile-Guided Code Positioning See paper of the same name by Karl Pettis & Robert C. Hansen in PLDI 90, SIGPLAN Notices 25(6), pages 16–27 Copyright 2011,
Programming Language Concepts (CIS 635) Elsa L Gunter 4303 GITC NJIT,
ISBN Chapter 12 Support for Object-Oriented Programming.
Smalltalk Implementation Harry Porter, October 2009 Smalltalk Implementation: Optimization Techniques Prof. Harry Porter Portland State University 1.
Introduction to Optimization
Compiler Construction (CS-636)
“Efficient Implementation of the Smalltalk-80 System”
The Procedure Abstraction Part IV: Allocating Storage & Establishing Addressability Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights.
Design III Chapter 13 9/20/2018 Crowley OS Chap. 13.
Chapter 9 :: Subroutines and Control Abstraction
Introduction to Optimization
Intermediate Representations
Introduction to Code Generation
Wrapping Up Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice University have explicit.
The Procedure Abstraction Part V: Run-time Structures for OOLs
The Procedure Abstraction Part I: Basics
Intermediate Representations
The Last Lecture COMP 512 Rice University Houston, Texas Fall 2003
Code Shape IV Procedure Calls & Dispatch
Morgan Kaufmann Publishers Memory Hierarchy: Virtual Memory
Activation records Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Introduction to Optimization
RUN-TIME STORAGE Chuen-Liang Chen Department of Computer Science
CSc 453 Interpreters & Interpretation
Activation records Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Presentation transcript:

Dynamic Compilation in an OOL: The Deutsch-Schiffman Smalltalk-80 Implementation “Efficient Implementation of the Smalltalk-80 System” L. Peter Deutsch and Allan M. Schiffman, POPL COMP 512, Rice University Copyright 2011, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in Comp 512 at Rice University have explicit permission to make copies of these materials for their personal use. Faculty from other educational institutions may use these materials for nonprofit educational purposes, provided this copyright notice is preserved. Comp 512 Spring 2011

COMP 512, Rice University2 Smalltalk-80 The System ( Learning Research Group at P ARC ) Object-oriented language Dynamic class structure ( changeable at any point ) Defined with interpretive semantics and “feel” Aimed at rapid prototyping Distributed as monolithic bytecode image Prior Art Smalltalk-80 ran on a Dorado ( $172 K microcoded ECL engine ) Strictly interpretive system ( +, -, x ) Custom microcode supporting the bytecode interpreter High-performance interpreter  custom hardware

COMP 512, Rice University3 Smalltalk-80 The Language Object-oriented language ( everything is an object ) Simple, selector-oriented syntax Complete, hierarchical class structure with single inheritance Dynamic class structure ( can change at run-time ) Every object has local, protected storage ( instance variables ) No declarations Dynamic binding Small procedures ( methods ) Frequent, expensive calls ( message sends ) Smalltalk-80 was an attempt to create a Smalltalk for the masses

COMP 512, Rice University4 Smalltalk-80 The Environment All tools written in Smalltalk-80 ( > decade of work ) Bytecode image includes all tools, in malleable, source form Whole system compiles to bytecode Implementation consists of virtual machine + bytecode image The Philosophy ( pseudo-religious tenet ) No changes allowed in the bytecode image Series of books on aspects of system

COMP 512, Rice University5 Smalltalk-80 What’s the problem? System was slow, except on a Dorado Response time was critical to Smalltalk’s “feel” All the classic problems of an interpreter  Fetch-decode-execute in software  Stack-based virtual machine running on CISC hardware  No cross-operation optimization All the classic problems of a dynamic OOL  Dynamic class structure  full lookup on every call  Deallocation via reference counting Deutsch’s target was a $7,000 S UN Workstation ( 10M HZ ) Wanted to make it compete with a Dorado ( at least, a Dolphin )

COMP 512, Rice University6 Brief Interlude What’s hard about compiling an OOL ? Eliminating the overhead of method lookup To attack this, people have tried  Static analysis to predict class type  Inline substitution to create cases that can be analyzed  Languages where most methods are statically predictable In Smalltalk-80, all message sends required the full lookup  Class structure can change at run-time In Smalltalk-80, activation records are objects ( ref. counted ) These guys solved many of the real problems in 1984

COMP 512, Rice University7 Smalltalk-80 Goal: efficient bytecode execution Strategy Overcome interpreter overhead by compiling Use multiple representations for high-impact run-time structures Capitalize on data & code locality Tactics On-the-fly translation of v-code into n-code Implement contexts ( AR s) based on use Clever method caching to speed lookups Extend scope of translation across multiple bytecodes Virtual machine code (bytecode) Native code (68010)

COMP 512, Rice University8 Overhead of Interpretation Dynamic Translation Every bytecode needs a fetch-decode-execute cycle Virtual machine is a stack machine ( code size ) No cross-bytecode optimization Key Insights It can be faster to generate native code & execute it than to interpret bytecodes ( with the appropriate tricks ) Performs fetch-decode-execute in hardware ( not software ) If compiling is a priori profitable, can discard code as needed Once the system is compiling, it can perform minor optimization An object can only be accessed from code visible to its class

COMP 512, Rice University9 Overhead of Interpretation Dynamic Translation Always compile before execution Simple, fast translation 5x code expansion ( still faster to execute ) Cache code when memory is available Discard code when memory is needed ( discard rather than page ) Simplified mapping v-address  n-address ( limited breakpoints ) Code quality Cross-bytecode optimization helps Example: eliminating reference count updates This system is one of the first JITs ! Deutsch & Bobrow already showed how to eliminate ref counts on locals

COMP 512, Rice University10 Access to High-impact Run-time Structures Contexts ( activation records ) are heavily accessed 85% of contexts are created by a call, never explicitly referenced, and freed by a return Use three representations Stack-based ( or volatile ) representation for executing methods Smalltalk-80 virtual machine form ( or stable ) for direct access Hybrid form that is visible, but not accessible Implementation Translate between them as needed Use classes to set run-time traps Less than 10% of contexts ever take non-volatile form Only reference count non-volatile All closures are created stable

COMP 512, Rice University11 Capitalizing on Locality Prior Art Single-probe, hashed “method cache” Attains 85 to 90% hit ratio, for improvements of 20 to 30% Inline method caches Single-element cache at each send site  Last receiver class + code pointer  Class changes  perform full lookup Attains 95% hit ratio, for 9 to 11% improvement over global cache Mechanism Generate sends unlinked First call does lookup & link Method checks stored class & invokes full lookup on miss They kept the global cache to speed full lookups Self modifying code -- store last class & last method inline

COMP 512, Rice University12 Results On “Krasner” Benchmarks Interpreter  straight forward implementation Simple translator  macro expansion into n-code Optimizing translator  peephole optimization, TOS in register 48.5% 18% ~ 9% *

COMP 512, Rice University13 Summary Compiler Throw-away generation of native code (JIT) Applies a couple of carefully chosen ideas Evaluation Made Smalltalk-80 practical on a SUN 1.5 Near-Dorado performance Beginning of the end for custom hardware “We have achieved this performance by careful optimization of the observed common cases and by plentiful use of caches and other changes of representation” p. 301

COMP 512, Rice University14 The Experience Papers ( Fortran H, PL.8, Smalltalk-80 ) What did these systems have in common? Understanding of the problem Clear goals Addressed specific inefficiencies Focused on high-payoff areas Limited repertoire of transformations All three were successful systems that we remember decades later  You don’t have to do every transformation in the literature *