Simple Dynamic Compilation with GOO. Jonathan Bachrach. MIT AI Lab 01MAR02 GOO 1

Similar documents
CS558 Programming Languages

Implementing Object-Oriented Languages. Implementing instance variable access. Implementing dynamic dispatching (virtual functions)

Parameterized Types for GOO. James Knight

Partial Dispatch: Optimizing Dynamically-Dispatched Multimethod Calls with Compile-Time Types and Runtime Feedback

CSE 501: Compiler Construction. Course outline. Goals for language implementation. Why study compilers? Models of compilation

CS 565: Programming Languages. Spring 2008 Tu, Th: 16:30-17:45 Room LWSN 1106

Running R Faster. Tomas Kalibera

Compiling Java For High Performance on Servers

Traditional Smalltalk Playing Well With Others Performance Etoile. Pragmatic Smalltalk. David Chisnall. August 25, 2011

SABLEJIT: A Retargetable Just-In-Time Compiler for a Portable Virtual Machine p. 1

Just-In-Time Compilers & Runtime Optimizers

Subtyping. Lecture 13 CS 565 3/27/06

BEAMJIT: An LLVM based just-in-time compiler for Erlang. Frej Drejhammar

COMMOM OBJECT ORIENTED LISP SYSTEMS

Language Translation. Compilation vs. interpretation. Compilation diagram. Step 1: compile. Step 2: run. compiler. Compiled program. program.

CS558 Programming Languages

BEAMJIT, a Maze of Twisty Little Traces

Intermediate Code, Object Representation, Type-Based Optimization

CS4215 Programming Language Implementation

JOVE. An Optimizing Compiler for Java. Allen Wirfs-Brock Instantiations Inc.

CSc 453 Interpreters & Interpretation

Overview. Rationale Division of labour between script and C++ Choice of language(s) Interfacing to C++

Interprocedural Type Specialization of JavaScript Programs Without Type Analysis

Sista: Improving Cog s JIT performance. Clément Béra

Object Oriented Paradigm

CS-XXX: Graduate Programming Languages. Lecture 23 Types for OOP; Static Overloading and Multimethods. Dan Grossman 2012

Dynamic Languages. CSE 501 Spring 15. With materials adopted from John Mitchell

Trace Compilation. Christian Wimmer September 2009

CS 415 Midterm Exam Fall 2003

Combined Object-Lambda Architectures

COP4020 Programming Languages. Compilers and Interpreters Robert van Engelen & Chris Lacher

Building a Runnable Program and Code Improvement. Dario Marasco, Greg Klepic, Tess DiStefano

Efficient Multiple Dispatching Using Nested Transition-Arrays

The Java Language Implementation

xtc Robert Grimm Making C Safely Extensible New York University

Multi-Methods in Racket

CS152: Programming Languages. Lecture 23 Advanced Concepts in Object-Oriented Programming. Dan Grossman Spring 2011

CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 17: Types and Type-Checking 25 Feb 08

How We Refactor, and How We Know It

Field Analysis. Last time Exploit encapsulation to improve memory system performance

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring

Interprocedural Analysis with Data-Dependent Calls. Circularity dilemma. A solution: optimistic iterative analysis. Example

Implementing Symmetric Multiprocessing in LispWorks

Common Lisp. In Practical Usage

Overview. Constructors and destructors Virtual functions Single inheritance Multiple inheritance RTTI Templates Exceptions Operator Overloading

Overview. Rationale Division of labour between script and C++ Choice of language(s) Interfacing to C++ Performance, memory

Compilers. Type checking. Yannis Smaragdakis, U. Athens (original slides by Sam

OOPLs - call graph construction Compile-time analysis of reference variables and fields. Example

Lecture 9 Dynamic Compilation

Chapter 2. Operating-System Structures

OOPLs - call graph construction. Example executed calls

The Procedure Abstraction

Some possible directions for the R engine

COMPUTER SCIENCE TRIPOS

Parley: Federated Virtual Machines

Outline. Unresolved references

Design issues for objectoriented. languages. Objects-only "pure" language vs mixed. Are subclasses subtypes of the superclass?

Efficient Separate Compilation of Object-Oriented Languages

An Introduction to Tilde

An Overview to Compiler Design. 2008/2/14 \course\cpeg421-08s\topic-1a.ppt 1

Static Semantics. Winter /3/ Hal Perkins & UW CSE I-1

MetaRTL: Raising the Abstraction Level of RTL Design

Object Model. Object Oriented Programming Spring 2015

Polymorphism. Miri Ben-Nissan (Kopel) Miri Kopel, Bar-Ilan University

Efficient Separate Compilation of Object-Oriented Languages

Interprocedural Analysis with Data-Dependent Calls. Circularity dilemma. A solution: optimistic iterative analysis. Example

Lecture 4 Processes. Dynamic Analysis. GDB

Lectures 5-6: Introduction to C

Double-precision General Matrix Multiply (DGEMM)

CSE P 501 Compilers. Dynamic Languages Hal Perkins Winter UW CSE P 501 Winter 2016 X2-1

Grade Weights. Language Design and Overview of COOL. CS143 Lecture 2. Programming Language Economics 101. Lecture Outline

Java On Steroids: Sun s High-Performance Java Implementation. History

Generating Code for Assignment Statements back to work. Comp 412 COMP 412 FALL Chapters 4, 6 & 7 in EaC2e. source code. IR IR target.

Comp 311 Principles of Programming Languages Lecture 21 Semantics of OO Languages. Corky Cartwright Mathias Ricken October 20, 2010

What about Object-Oriented Languages?

Optimization Techniques

Announcements. My office hours are today in Gates 160 from 1PM-3PM. Programming Project 3 checkpoint due tomorrow night at 11:59PM.

Publications related to Chez Scheme

(just another operator) Ambiguous scalars or aggregates go into memory

Subtyping (Dynamic Polymorphism)

Lecture 7: Type Systems and Symbol Tables. CS 540 George Mason University

CPS 506 Comparative Programming Languages. Programming Language

Computer Components. Software{ User Programs. Operating System. Hardware

Static Analysis of Embedded C

Interface evolution via public defender methods

Principles of Programming Languages. Lecture Outline

Performance of Non-Moving Garbage Collectors. Hans-J. Boehm HP Labs

CSE 303: Concepts and Tools for Software Development

Separate compilation. Topic 6: Runtime Environments p.1/21. CS 526 Topic 6: Runtime Environments The linkage convention

Obfuscating Transformations. What is Obfuscator? Obfuscation Library. Obfuscation vs. Deobfuscation. Summary

What are compilers? A Compiler

A Status Update of BEAMJIT, the Just-in-Time Compiling Abstract Machine. Frej Drejhammar and Lars Rasmusson

Type-indexed functions in Generic Haskell

COMPLEX SYSTEMS. Today. Complex Systems. Kinds of Systems. Embedded Systems. Software Engineering. Lectures 20: Engineering Complex Systems

Administration CS 412/413. Why build a compiler? Compilers. Architectural independence. Source-to-source translator

CS577 Modern Language Processors. Spring 2018 Lecture Interpreters

Dynamic Dispatch and Duck Typing. L25: Modern Compiler Design

Refinement Types for TypeScript

Processors, Performance, and Profiling

Advances in Memory Management and Symbol Lookup in pqr

Transcription:

Simple Dynamic Compilation with GOO Jonathan Bachrach MIT AI Lab 01MAR02 GOO 1

GOO Talk Preliminary work Introduce challenge Present GOO Introduce language Sketch implementation Report status Request Quick C features 01MAR02 GOO 2

Scripting Languages Can Be: Fast, Clean, Safe, Powerful, and of course Fun Don t have to trade off fun for speed etc. Don t need complicated implementation Requires forced rethinking and reevaluation of Technologies - faster, bigger, cheaper Architecture - dynamic compilation Assumptions - 01MAR02 GOO 3

GOO Art / Science / Education Research/Teaching vehicle For rethinking language design and implementation Reaction to a Reaction Targetted for high-performance/interactive software development for Embedded systems Electronic music 01MAR02 GOO 4

GOO Power Features Pure object-oriented Multimethods Slot accessors as well Dynamic types Ext. param types Modules Macros Restartable exceptions Builds on Proto Dylan Cecil CLOS Scheme Smalltalk 01MAR02 GOO 5

GOO Simplicity PLDI Core Wars 10K Lines Implementation * 10 Page Manual ** Hard Limit pressure makes pearls Interpreter Semantics Speed through partial evaluation Implementation Serendipity 01MAR02 GOO 6

Complexity is Dangerous to Your Health Complexity will bite you at every turn Minimize number of moving parts Complexity can be exponential in part count unless extreme vigilance is applied But vigilance is costly especially reactive Apply vigilance towards minimizing part count instead 01MAR02 GOO 7

Simplified Design Simplification No sealing Dynamic typing No databases Type-based opts only No static modeling Prefix syntax No VM Recover x with Global info / d-comp Type inference Save-image C (C--) backend Use real world Short + nesting ops (Obfuscated) Source 01MAR02 GOO 8

Goal: To Develop Simple, Powerful, and Useful Techniques Motivated from Lightweight Languages conference at MIT 2001 Understandable Adoptable Leveragable 01MAR02 GOO 9

GOO: Speed and Interactivity Always optimized Always malleable 01MAR02 GOO 10

Related Work Lisp Machine Progress Report, 1977, MIT Harlequin and Apple Dylan, 1990, Moon et al Adaptive Optimization For Self: Reconciling High Performance With Exploratory Programming (1994), Urs Holzle Java optimization in the face of class loading, 2001,??? Specialized hardware Reduced interactivity Increased complexity Reduced interactivity 01MAR02 GOO 11

Incremental Global Optimization Always compiled Dependency tracks assumptions during compilation Reoptimizes dependents upon change Knob for adjusting number of dependents to make recompilation times acceptable 01MAR02 GOO 12

Managing Complexity 1. Dynamic compilation 2. Dependency Tracking 3. Type-based optimizations 4. Subclass? tests 5. Multimethod dispatch 01MAR02 GOO 13

Complexity Example One: Dynamic Compilation So you want a dynamic compiler? Throw away interpreter Allow for more global optimizations But what about the ensuing complexity? Use source instead of VM Cut out the middle man Use C back-end and shared libraries (e.g., MathMap) More realistically C-- Trigger compiler By global optimization dependencies Not profile information 01MAR02 GOO 14

Using C for Simple Dynamic Compilation Procedure Emit C code with g2c Compile C code with gcc Dynamically link with ld Load into running image with dlopen Run top level initialization code with dlvar and apply Lazily resolve variables within running image Fast Turnaround Typical interactive definitions take less than a second 01MAR02 GOO 15

Complexity Example Two: Dependency Tracking Assumptions All optimization information is derived from bindings While compiling definition Establish current dependent Log binding accesses Trigger selective recompilation when Dependent binding properties change Can decrease recompilation by Recording compilation stage Rerunning recorded stage and beyond 01MAR02 GOO 16

Complexity Example Three: Type-based Optimizations First compile loosely Don t look at binding values Execute resulting changes on image Building objects Recompile with optimizations Consult actual world for object properties Log dependencies 01MAR02 GOO 17

Complexity Example Four: Fast Subclass? Tests Crucial for the performance of languages Especially languages with dynamic typing Used for typechecks downcasts typecase method selection Used in Compiler - static analysis Runtime 01MAR02 GOO 18

Important Subclass? Measures The predicate speed The subclass data initialization speed The space of subclass data The cost of incremental changes Could be full reinitialization if fast enough 01MAR02 GOO 19

Longstanding Problem Choose either Simple algorithm with O(n^2) space or Complicated slower to initialize algorithm with better space properties: PE Vitek, Horspool, and Krall OOPSLA-97 PQE Zibin and Gil OOPSLA-01 01MAR02 GOO 20

PVE Algorithm Blindingly fast to construct Fast enough for incremental changes One page of code to implement Comparable to PE on wide range of real-world hierarchies E.g. 95% compression on 5500 class flavors hierarchy (4MB bit matrix) Exhibits approximately n log n space Paper available: www.jbot.org/pve 01MAR02 GOO 21

Complexity Example Five: Dispatch For a given generic function and arguments choose the most applicable method Example: Gen: (+ x y) Mets: num+ int+ flo+ Args: 1 2 Met: int+ Typical solution is method cache Concrete argument classes are keys 01MAR02 GOO 22

Subtype? Based Dispatch Methodology Steps Dynamic subtype? based decision tree Choose more specific specializers first Choose unrelated specializers with stats Inline small methods Inline decision trees into call-sites Examples (fun (x y) (if (isa? x <int>)...))) Discriminate int+ and flo+ before num+ Discriminate int+ before flo+ int+ (and slot accessors) (+ x 1) (allowing partial evaluation at call-site) 01MAR02 GOO 23

Subtype? Based Dispatch Few moving parts Happy Synergies tag-checked arithmetic for free Static dispatch for free One arg case comparable to vtable speed Fewer indirect jumps Dynamic type-check insensitive to class numbering 01MAR02 GOO 24

GOO Status Working Fully bootstrapped Linux and Win32 Ports Runtime system tuned C based dynamic compiler SWIG backend + GTK In progress Decision tree generation Dependency tracking Fast subclass? Type inference Parameterized types GUI 01MAR02 GOO 25

Challenges Live update of objects after class redefinition Patching of pending functions Incremental interprocedural analysis Smart inlining 01MAR02 GOO 26

GOO Credits Etc Thanks to Craig Chambers Eric Kidd, James Knight, and Andrew Sutherland Greg Sullivan Howie Shrobe (and DARPA) for funding To be open sourced in the coming weeks: www.jbot.org/goo/ 01MAR02 GOO 27

Quick C--C Requests Dynamic Compilation Debugging GC Profiling 01MAR02 GOO 28

Dynamic Compilation Support In memory code generator In memory linker Relocatable code Integration with gc 01MAR02 GOO 29

C-- Debugging Support Source locations Stack walking Live local variables Execute within a frame Switch threads Force threads to safe points 01MAR02 GOO 30

GC Support Precise GC Find all references for live patching 01MAR02 GOO 31

Profiling Support Low overhead Reasonably precise 01MAR02 GOO 32

More Information Dynamic Languages Group www.ai.mit.edu/projects/dynlangs 08FEB02: MAST: A dynamic language for active network programming, Dimitris Vyzovitis, MIT Media Lab GOO www.jbot.org/goo 01MAR02 GOO 33