C++ Exception Handling for IA-64 Unix

Slides:



Advertisements
Similar presentations
More on Processes Chapter 3. Process image _the physical representation of a process in the OS _an address space consisting of code, data and stack segments.
Advertisements

Procedures in more detail. CMPE12cGabriel Hugh Elkaim 2 Why use procedures? –Code reuse –More readable code –Less code Microprocessors (and assembly languages)
Operating Systems Lecture 10 Issues in Paging and Virtual Memory Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard. Zhiqing.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 18.
Chapter 9 Subprogram Control Consider program as a tree- –Each parent calls (transfers control to) child –Parent resumes when child completes –Copy rule.
1 Storage Registers vs. memory Access to registers is much faster than access to memory Goal: store as much data as possible in registers Limitations/considerations:
Procedures in more detail. CMPE12cCyrus Bazeghi 2 Procedures Why use procedures? Reuse of code More readable Less code Microprocessors (and assembly languages)
The Procedure Abstraction Part III: Allocating Storage & Establishing Addressability Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all.
Run-Time Storage Organization
Run time vs. Compile time
CS-3013 & CS-502, Summer 2006 Memory Management1 CS-3013 & CS-502 Summer 2006.
The environment of the computation Declarations introduce names that denote entities. At execution-time, entities are bound to values or to locations:
Compiler Summary Mooly Sagiv html://
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
Chapter 7: Runtime Environment –Run time memory organization. We need to use memory to store: –code –static data (global variables) –dynamic data objects.
Runtime Environments What is in the memory? Runtime Environment2 Outline Memory organization during program execution Static runtime environments.
Runtime Environments Compiler Construction Chapter 7.
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.
Hardware process When the computer is powered up, it begins to execute fetch-execute cycle for the program that is stored in memory at the boot strap entry.
COP4020 Programming Languages Subroutines and Parameter Passing Prof. Xin Yuan.
Run-Time Storage Organization Compiler Design Lecture (03/23/98) Computer Science Rensselaer Polytechnic.
COMP3190: Principle of Programming Languages
RUN-Time Organization Compiler phase— Before writing a code generator, we must decide how to marshal the resources of the target machine (instructions,
Lecture 3 Classes, Structs, Enums Passing by reference and value Arrays.
Processes CS 6560: Operating Systems Design. 2 Von Neuman Model Both text (program) and data reside in memory Execution cycle Fetch instruction Decode.
CSC 8505 Compiler Construction Runtime Environments.
CS212: Object Oriented Analysis and Design Lecture 19: Exception Handling.
RUNTIME ENVIRONMENT AND VARIABLE BINDINGS How to manage local variables.
LECTURE 19 Subroutines and Parameter Passing. ABSTRACTION Recall: Abstraction is the process by which we can hide larger or more complex code fragments.
Run-Time Environments Presented By: Seema Gupta 09MCA102.
Code Generation Instruction Selection Higher level instruction -> Low level instruction Register Allocation Which register to assign to hold which items?
A Single Intermediate Language That Supports Multiple Implemtntation of Exceptions Delvin Defoe Washington University in Saint Louis Department of Computer.
WORKING OF SCHEDULER IN OS
Lecture 3 Translation.
Storage Classes There are three places in memory where data may be placed: In Data section declared with .data in assembly language in C - Static) On the.
CS212: Object Oriented Analysis and Design
The Procedure Abstraction Part III: Symbol Tables, Storage
Process Realization In OS
The Procedure Abstraction Part IV: Allocating Storage & Establishing Addressability Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights.
Henk Corporaal TUEindhoven 2009
The HP OpenVMS Itanium® Calling Standard
Structure of Processes
Chapter 9 :: Subroutines and Control Abstraction
Activation Records and Function Calls
Chap. 8 :: Subroutines and Control Abstraction
Chap. 8 :: Subroutines and Control Abstraction
Stack Frame Linkage.
MIPS Instructions.
CS399 New Beginnings Jonathan Walpole.
Closure Representations in Higher-Order Programming Languages
PZ09A - Activation records
Code Shape IV Procedure Calls & Dispatch
UNIT V Run Time Environments.
Run Time Environments 薛智文
Runtime Environments What is in the memory?.
Where is all the knowledge we lost with information? T. S. Eliot
Structure of Processes
Procedure Linkages Standard procedure linkage Procedure has
Exceptions.
Dynamic Binary Translators and Instrumenters
Activation records Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Run-time environments
CSE 542: Operating Systems
Overview of Exception Handling Implementation in Open64
Runtime Stack Activation record for hanoi;
Exception Delivery Requirement
Presentation transcript:

C++ Exception Handling for IA-64 Unix By Priti Shrivastav 11/22/2018 Intel Confidential

C++ EH Overview C++ EH uses static model to avoid runtime overhead for functions with try/throw/catch statements. Destructor thunks are separate functions. Try and Catch blocks are generated inline within the function’s body. Three tables are generated by the compiler backend for each routine and for each catch routine. Function Table Try region Table ( C++ EH tables ) Unwind descriptors table 11/22/2018 Intel Confidential

Compiler and C++ EH Runtime Catch blocks stay mainline code. They need to be separate entry points. Runtime will allocate exception objects on the regular heap. At start-up runtime will pre-allocate enough space to process one out-of-memory exception. Runtime allocates the object on heap before branching to catch block. Runtime will pass in r8 the destructor thunk which frees the object to catch. Catch will call the destructor thunk before leaving the catch block. If the object to catch is passed by value, two copies of the objects will be allocated by the runtime and the destructor thunk will have to know to free both. 11/22/2018 Intel Confidential

Function,Try Region and Unwind Tables Runtime function table is created for every executable image. A function table entry is created for every function. typedef struct _RUNTIME_FUNCTION { ULONGLONG BeginAddress; ULONGLONG EndAddress; ULONGLONG UnwindInfo; // unwind information block } RUNTIME_FUNCTION, *PRUNTIME_FUNCTION; 11/22/2018 Intel Confidential

Function,Try Region and Unwind Tables (Continued) The unwindinfo field points to a structure which contains the unwind information for the function The Unwind table typedef struct _UNWIND_INFO { USHORT version; USHORT Flags; // try/except or try/finally indicator UINT DataLength; // length of the unwind descriptors UCHAR Descriptors[]; // unwind descriptors PEXCEPTION_ROUTINE ExceptionHandler; // personality routine TRY_REGION_TABLE TryRegionInfo; // Try Region Table CLEANUP_TABLE ObjectCleanupInfo; // Object Cleanup Table } UNWIND_INFO, *PUNWIND_INFO; 11/22/2018 Intel Confidential

Function,Try Region and Unwind Tables (Continued) The TryRegionInfo points to the try region table whose entries define the try regions in the function. The table is used by the C++ exception handler to determine the active regions in the function at the time of exception. The entries for nested scopes are PC-mapped and are ordered from inner to outer scopes. The try region table typedef struct _TRY_REGION_TABLE { UINT NumberOfTryEntries; struct { UINT BeginAddress; // begin of a try region UINT EndAddress; // next bundle after the end of try UINT CatchHandlerInfo; // catch address table } TryRegionTableEntry[ ]; } TRY_REGION_TABLE, *PTRY_REGION_TABLE; 11/22/2018 Intel Confidential

Function,Try Region and Unwind Tables (Continued) The ObjectCleanupInfo points to the object cleanup table whose entries define the cleanup action required in the function. The table is used by the C++ exception handler to determine the active cleanup regions in the function at the time of exception. The entries for nested scopes are PC-mapped and are in reverse order of creation. The object cleanup table typedef struct _OBJ_CLEANUP_TABLE { UINT NumberOfCleanupEntries; struct { UINT BeginAddress; // begin of a cleanup region UINT EndAddress; // next bundle after the end of region UINT CleanupFunctionAddress; // destructor ’s address } ObjectCleanupEntry[ ]; } CLEANUP_TABLE, *PCLEAUP_TABLE; 11/22/2018 Intel Confidential

Unwind support in EM compiler Unwind descriptor region header records are created for prolog,body and epilog regions Descriptors for updating special and preserved registers in prolog regions are generated. Unwind mechanism handles shrink-wrap regions In case of multiple prologs, either a matching epilog region header record for each prolog is created or epilog region header records specify the number of prolog regions to pop. Each region header record specifies region length which helps determine which are the active regions for a given IP. All the spill code for saving the preserved registers must be in the prolog region. For this post-pass scheduling must be prevented for the prolog. Previous sp value is saved in a stacked register for variable size frames. 11/22/2018 Intel Confidential

IA-64 Unwind Scheme No Yes Call unwind (target sp, target bsp, target IP) Unwind to the previous call frame Lookup Funtion Table Entry Unwinder Process descriptors to set the call frame (sp,bsp) Unwinder No Yes Resume execution at the target IP Personality Routine Cleanup the objects Target Frame? 11/22/2018 Intel Confidential