Download presentation
Presentation is loading. Please wait.
Published byChristian Stevens Modified over 8 years ago
1
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
2
April 3, 2002 2 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
3
April 3, 2002 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
4
April 3, 2002 4 What C-- is Not Universal Intermediate Language –Does not works for all Write once run anywhere Language –Not like Java One Implementation Different platforms
5
April 3, 2002 5 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
6
April 3, 2002 6 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
7
April 3, 2002 7 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
8
April 3, 2002 8 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
9
April 3, 2002 9 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
10
April 3, 2002 10 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
11
April 3, 2002 11 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
12
April 3, 2002 12 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
13
April 3, 2002 13 Example Code
14
April 3, 2002 14 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
15
April 3, 2002 15 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
16
April 3, 2002 16 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
17
April 3, 2002 17 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
18
April 3, 2002 18 Example
19
April 3, 2002 19 Transferring control to a continuation
20
April 3, 2002 20 Related Work
21
April 3, 2002 21 Discussion
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.