A Single Intermediate Language That Supports Multiple Implemtntation of Exceptions Delvin Defoe Washington University in Saint Louis Department of Computer.

Slides:



Advertisements
Similar presentations
Operating Systems Components of OS
Advertisements

Programming Languages and Paradigms
Department of Computer Science and Engineering University of Washington Brian N. Bershad, Stefan Savage, Przemyslaw Pardyak, Emin Gun Sirer, Marc E. Fiuczynski,
CPSC Compiler Tutorial 8 Code Generator (unoptimized)
1 Handling nested procedures Method 1 : static (access) links –Reference to the frame of the lexically enclosing procedure –Static chains of such links.
CS 536 Spring Intermediate Code. Local Optimizations. Lecture 22.
Java for High Performance Computing Jordi Garcia Almiñana 14 de Octubre de 1998 de la era post-internet.
Programming Language Semantics Java Threads and Locks Informal Introduction The Java Specification Language Chapter 17.
Run time vs. Compile time
Chapter 9: Subprogram Control
1 Run time vs. Compile time The compiler must generate code to handle issues that arise at run time Representation of various data types Procedure linkage.
Chapter 8 :: Subroutines and Control Abstraction
High level & Low level language High level programming languages are more structured, are closer to spoken language and are more intuitive than low level.
ICOM 5995: Performance Instrumentation and Visualization for High Performance Computer Systems Lecture 7 October 16, 2002 Nayda G. Santiago.
CS 403: Programming Languages Lecture 2 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
CS 363 Comparative Programming Languages
CSc 453 Runtime Environments Saumya Debray The University of Arizona Tucson.
Copyright © 2005 Elsevier Chapter 8 :: Subroutines and Control Abstraction Programming Language Pragmatics Michael L. Scott.
Activation Records (in Tiger) CS 471 October 24, 2007.
Processes Introduction to Operating Systems: Module 3.
Virtual Machines, Interpretation Techniques, and Just-In-Time Compilers Kostis Sagonas
RUN-Time Organization Compiler phase— Before writing a code generator, we must decide how to marshal the resources of the target machine (instructions,
Lecture 5: Threads process as a unit of scheduling and a unit of resource allocation processes vs. threads what to program with threads why use threads.
Chapter 1 Introduction. Chapter 1 -- Introduction2  Def: Compiler --  a program that translates a program written in a language like Pascal, C, PL/I,
Assembly Language Co-Routines
LECTURE 19 Subroutines and Parameter Passing. ABSTRACTION Recall: Abstraction is the process by which we can hide larger or more complex code fragments.
RealTimeSystems Lab Jong-Koo, Lim
C-- by Aksel Gresvig. Outline ● What is C--? How does it work? ● What C-- is not ● Relationship to C ● What does it look like? Examples ● Elements of.
Sung-Dong Kim, Dept. of Computer Engineering, Hansung University Java - Introduction.
Code Generation Instruction Selection Higher level instruction -> Low level instruction Register Allocation Which register to assign to hold which items?
Introduction to Operating Systems Concepts
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Lecture 3 Translation.
Object Oriented Programming in
Advanced Computer Systems
Visit for more Learning Resources
Computer Science 210 Computer Organization
Names and Attributes Names are a key programming language feature
Computer Architecture Instruction Set Architecture
Compiler Construction (CS-636)
System Programming and administration
C Language VIVA Questions with Answers
课程名 编译原理 Compiling Techniques
C language IT-1 (Batch-A) Name: EnNo: Arshad Muthalif
Introduction to Compilers Tim Teitelbaum
Hierarchical Architecture
The HP OpenVMS Itanium® Calling Standard
Chapter 9 :: Subroutines and Control Abstraction
Code Generation.
Chap. 8 :: Subroutines and Control Abstraction
Chap. 8 :: Subroutines and Control Abstraction
Control Flow.
CSE401 Introduction to Compiler Construction
Lesson Objectives Aims Key Words Compiler, interpreter, assembler
Closure Representations in Higher-Order Programming Languages
Computer Organization and Design Assembly & Compilation
Architectural Support for OS
CSE 451: Operating Systems Autumn 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 596 Allen Center 1.
Languages and Compilers (SProg og Oversættere)
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Architectural Support for OS
Chapter 1 Introduction.
Lecture 4: Instruction Set Design/Pipelining
Reasons To Study Programming Languages
Procedure Linkages Standard procedure linkage Procedure has
Review: What is an activation record?
CSc 453 Interpreters & Interpretation
Dynamic Binary Translators and Instrumenters
Running & Testing Programs :: Translators
Presentation transcript:

A Single Intermediate Language That Supports Multiple Implemtntation of Exceptions Delvin Defoe Washington University in Saint Louis Department of Computer Science April 3, 2002 Center for Distributed Object Computing Department of Computer Science Washington University By Norman Ramsey, & Simon Peyton Jones

April 3, Overview Motivation - Goal of C-- What does this paper attempt to explain? Survey of well know exception mechanisms So what’s the problem? How does C– attempt to solve the problem? Overview of C-- / Example Implementing high-level Exception is C-- / Example Related work Conclusions

April 3, The Goal of the authors To present a compiler target - language C-- –4 of the best known techniques for implementing exceptions within a single framework –Exceptions do not require special treatment in optimizer –Allows a single optimizer to handle a variety of implementation techniques Overall Goal –Allow a source language the freedom to choose its exception handling policy –For C-- to be independent of source programming languages and target architecture

April 3, What C-- is Not Universal Intermediate Language –Does not works for all Write once run anywhere Language –Not like Java One Implementation Different platforms

April 3, What C-- really is Encapsulates compilation techniques –These are well understood but difficult to implement –These techniques include: Instruction selection Register allocation Instruction Scheduling Scalar optimizations of imperative code with loops What does C-- do beyond this? –C-- encapsulates architecture-specific run-time support for high-level run-time services Garbage collection Concurrency

April 3, What C-- really is (continued) What does C-- do beyond this? –C-- encapsulates architecture-specific run-time support for high-level run-time services Debugging Exception Dispatch

April 3, What does this paper explain? How C-- encapsulates techniques compilers use to support exception dispatch Presents 2 mechanisms C-- uses to specify interprocedural control flow –Weak continuations that do not outlive their procedure activation –Call site annotations C-- also supports continuation-passing style – a 4 th implementation technique Abstract C-- is used to to define these mechanisms precisely

April 3, Survey of Exception Mechanisms Stack cutting –Set stack pointer and PC to point directly to handler –In native compiler, fast but does not restore callee- saves registers –This techniques is used in Common Lisp and pre- Scheme Lisp Run-time stack unwinding –Use the run-time system to unwind the stack frames until the handle is reached –Run-time system restores callee-saves registers –Operating systems like Digital Unix provide support for run-time stack unwinding –The JVM and C++ compilers use this technique

April 3, Survey of Exception Mechanisms (cont.) Native-code stack unwinding –Use specialized code in each procedure to unwind stack When nonlocal return Exceptional termination is called for –Self compiler uses this technique Continuation passing style –Exception continuation represent Potential exception handlers –Generated code raises exception by making tail call to continuation –Continuation decides which handler applies –Standard ML of NJ uses this technique

April 3, So what’s the problem? Correct exception dispatch depends on factors –Semantics of exception in source language –Representation of call stack on target machine Compiler optimization is fundamentally affected by exceptions So what is the easy way out? –Code-generator know language-specific details of exception semantics –Run-time system know code-generator’s stack layout –Run-time system know code-generator’s register- saving protocols

April 3, So what’s the role of C--? To show how a reusable code-generator does the following: –Cooperate with front ends at arm’s length –Still support a variety of exception semantics in architecture-independent way Can a language alone provide sufficiently flexible interface? –No –C– contains a language which cooperates with source language compiler –Run-time system which cooperates with the same for source language

April 3, Overview of the C-- language C-- has parameterized procedures with declared local variables –Body of procedure consists of sequence of statement, which include Assignments Conditionals Gotos Calls Jumps (tail calls) C-- maps source language local and global variables to machine registers, not memory locations

April 3, Example Code

April 3, The C-- Language 2 Features common to assemblers but not programming languages –Procedures return multiple values –Procedures explicitly tail call other procedures Type system is extremely modest –Only types are words and floating point values of various sizes e.g. Bits8, bits16, bits32, bits64 Float32, float64 –For each target architecture, each implementation of C-- designates one of the bitsn types as The native data pointer type And 1 as the native code pointer type

April 3, C-- run time system Assumption: executable program is built by linking 3 parts, which may be found in Object files, or Libraries –Front end translates high level source programs into C– modules –C– compiler translates modules into generated object code –Front end comes with front end run-time system –Run-time system implements policy and mechanism of source Include garbage collection Exception dispatch Thread scheduler, etc. C-- implementation comes with a C-- run-time system –Encapsulates architecture-specific mechanisms –Provides services to front end run-time system through C run time interface Main service provided by C-- run-time interface is to represent the state of a C-- thread as a stack of abstract activations

April 3, C-- run time system The table above give lists the operations to: –Walk down the stack –Get stack info from an activation –Make a particular activation become the topmost one –Change resumption point of topmost activation

April 3, Implementing High-Level Exceptions in C-- Things to note: –Exceptions change flow of control –Exception Handler – destination of exception control transfer –Exception dispatch – transferring of control to exception handler –C-- models exception handlers as continuations Label with parameters Declarable only inside a procedure Denotes a value which can be used to transfer control to it – encaps. a stack pointer and a PC –C-- uses annotations on call sites to tell optimizer what exception control transfers can take place

April 3, Example

April 3, Transferring control to a continuation

April 3, Related Work

April 3, Discussion