{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

cool-runtime - The Cool Runtime System 1 Introduction The...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
The Cool Runtime System 1 Introduction The runtime system consists of a set of hand-coded assembly language functions that are used as sub- routines by Cool programs. Under spim the runtime system is in the file trap.handler . The use of the runtime system is a concern only for code generation, which must adhere to the interface provided by the runtime system. The runtime system contains four classes of routines: 1. startup code, which invokes the main method of the main program; 2. the code for methods of predefined classes ( Object , IO , String ); 3. a few special procedures needed by Cool programs to test objects for equality and handle runtime errors; 4. the garbage collector. The Cool runtime system is in the file /usr/class/cs143/lib/trap.handler ; it is loaded automatically whenever spim / xspim is invoked. Comments in the file explain how the pre-defined functions are called. The following sections describe what the Cool runtime system assumes about the generated code and what the runtime system provides to the generated code. However, additional restrictions must be placed on the generated code for use with Coolaid , a debugging tool for Cool compilers based on program verification (see the Coolaid Reference Manual). Coolaid specific restrictions are marked in this manner. This document does not describe the expected behavior of Cool programs; refer to Section 13 of the Cool Reference Manual for a formal description of the execution semantics of Cool programs. 2 Objects The object layout describes the location of attributes, as well as the meta-data that must be associated with each object. Modified from Section 7 of A Tour of the Cool Support Code ( c circlecopyrt 1995-1996 by Alex Aiken). Last modified on Wed Nov 10 04:34:45 PST 2004. 1
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
offset -4 Garbage Collector Tag offset 0 Class tag offset 4 Object size (in 32-bit words) offset 8 Dispatch pointer offset 12 . . . Attributes Figure 1: Object layout. 2.1 Object Layout The first three 32-bit words of each object are assumed to contain a class tag, the object size, and a pointer for dispatch information. In addition, the garbage collector requires that the word immediately before an object contain -1; this word is not part of the object. Figure 1 shows the layout of a Cool object; the offsets are given in numbers of bytes. The garbage collection tag is -1. The class tag is a 32-bit integer identifying the class of the object and thus should be unique for each class. The runtime system uses the class tag in equality comparisons between objects of the basic classes and in the abort functions to index a table containing the name of each class. The object size field and garbage collector tag are maintained by the runtime system; only the runtime system should create new objects. However, prototype objects (see below) must be coded directly by the code generator in the static data area, so the code generator should initialize the object size field and garbage collector tag of prototypes properly. Any statically generated objects must also initialize these fields.
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern