Runtime Support for OOLs Object Records, Code Vectors, Inheritance Comp 412

Similar documents
What about Object-Oriented Languages?

Naming in OOLs and Storage Layout Comp 412

Runtime Support for Algol-Like Languages Comp 412

Procedure and Function Calls, Part II. Comp 412 COMP 412 FALL Chapter 6 in EaC2e. target code. source code Front End Optimizer Back End

The Procedure Abstraction

Arrays and Functions

Optimizer. Defining and preserving the meaning of the program

Object Oriented Languages. Hwansoo Han

Handling Assignment Comp 412

The Software Stack: From Assembly Language to Machine Code

Register Allocation. Note by Baris Aktemur: Our slides are adapted from Cooper and Torczon s slides that they prepared for COMP 412 at Rice.

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

The Processor Memory Hierarchy

CS415 Compilers. Procedure Abstractions. These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University

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

Runtime Support for OOLs Part II Comp 412

CSE 504: Compiler Design. Runtime Environments

Code Shape Comp 412 COMP 412 FALL Chapters 4, 5, 6 & 7 in EaC2e. source code. IR IR target. code. Front End Optimizer Back End

Instruction Selection: Preliminaries. Comp 412

Intermediate Representations

The Procedure Abstraction Part I: Basics

Sustainable Memory Use Allocation & (Implicit) Deallocation (mostly in Java)

Computing Inside The Parser Syntax-Directed Translation. Comp 412 COMP 412 FALL Chapter 4 in EaC2e. source code. IR IR target.

Parsing II Top-down parsing. Comp 412

Local Optimization: Value Numbering The Desert Island Optimization. Comp 412 COMP 412 FALL Chapter 8 in EaC2e. target code

Run Time Environment. Implementing Object-Oriented Languages

Code Shape Comp 412 COMP 412 FALL Chapters 4, 5, 6 & 7 in EaC2e. source code. IR IR target. code. Front End Optimizer Back End

Procedure and Object- Oriented Abstraction

Computing Inside The Parser Syntax-Directed Translation, II. Comp 412

Intermediate Representations

Computing Inside The Parser Syntax-Directed Translation. Comp 412

The Procedure Abstraction Part I Basics

Runtime management. CS Compiler Design. The procedure abstraction. The procedure abstraction. Runtime management. V.

Just-In-Time Compilers & Runtime Optimizers

Data Abstraction. Hwansoo Han

Implementing Object-Oriented Languages - 2

Lecture 13: Object orientation. Object oriented programming. Introduction. Object oriented programming. OO and ADT:s. Introduction

Code Shape II Expressions & Assignment

Computing Inside The Parser Syntax-Directed Translation, II. Comp 412 COMP 412 FALL Chapter 4 in EaC2e. source code. IR IR target.

Every language has its own scoping rules. For example, what is the scope of variable j in this Java program?

Syntax Analysis, III Comp 412

Chapter 1: Object-Oriented Programming Using C++

Syntax Analysis, III Comp 412

Week 7. Statically-typed OO languages: C++ Closer look at subtyping

CPS 506 Comparative Programming Languages. Programming Language

More On inheritance. What you can do in subclass regarding methods:

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

CS 406/534 Compiler Construction Intermediate Representation and Procedure Abstraction

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

Introduction to Programming Using Java (98-388)

Local Register Allocation (critical content for Lab 2) Comp 412

Short Notes of CS201

Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice University have explicit

Chapter 6 Introduction to Defining Classes

CS201 - Introduction to Programming Glossary By

UNIT 3 ARRAYS, RECURSION, AND COMPLEXITY CHAPTER 11 CLASSES CONTINUED

Run Time Environment. Activation Records Procedure Linkage Name Translation and Variable Access

Programming II (CS300)

Object-Oriented Design

Inheritance, Polymorphism and the Object Memory Model

Run Time Environment. Procedure Abstraction. The Procedure as a Control Abstraction. The Procedure as a Control Abstraction

Lecture 15: Object-Oriented Programming

Implementing Control Flow Constructs Comp 412

CSE 307: Principles of Programming Languages

ECE 3574: Dynamic Polymorphism using Inheritance

CS558 Programming Languages Winter 2013 Lecture 8

UG3 Compiling Techniques Overview of the Course

CS415 Compilers. Intermediate Represeation & Code Generation

The Java Programming Language

Supporting Class / C++ Lecture Notes

Run-time Environments - 2

Building a Parser Part III

Habanero Extreme Scale Software Research Project

CSE 504: Compiler Design. Intermediate Representations Symbol Table

! Those values must be stored somewhere! Therefore, variables must somehow be bound. ! How?

Compiling Java For High Performance on Servers

Subtyping (Dynamic Polymorphism)

C++ Inheritance and Encapsulation

Lab 3, Tutorial 1 Comp 412

Lecture 7: Binding Time and Storage

Syntax Analysis, V Bottom-up Parsing & The Magic of Handles Comp 412

Lecture 02, Fall 2018 Friday September 7

The So'ware Stack: From Assembly Language to Machine Code

Java Object Oriented Design. CSC207 Fall 2014

Chapter 5. Names, Bindings, and Scopes

The compilation process is driven by the syntactic structure of the program as discovered by the parser

Programming Language Concepts Scoping. Janyl Jumadinova January 31, 2017

Loops and Locality. with an introduc-on to the memory hierarchy. COMP 506 Rice University Spring target code. source code OpJmizer

Semantics. Names. Binding Time

Cunning Plan. One-Slide Summary. Functional Programming. Functional Programming. Introduction to COOL #1. Classroom Object-Oriented Language

Object typing and subtypes

What is Inheritance?

Inheritance and Polymorphism

Inheritance: Develop solutions by abstracting real-world object and their interaction into code to develop software solutions. Layering: Organization

Example: Fibonacci Numbers

Global Register Allocation via Graph Coloring

COP 3330 Final Exam Review

CMSC131. Inheritance. Object. When we talked about Object, I mentioned that all Java classes are "built" on top of that.

Declaration Syntax. Declarations. Declarators. Declaration Specifiers. Declaration Examples. Declaration Examples. Declarators include:

Special Topics: Programming Languages

Transcription:

COMP 412 FALL 2017 Runtime Support for OOLs Object Records, Code Vectors, Inheritance Comp 412 source IR Front End Optimizer Back End IR target Copyright 2017, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice University have eplicit permission to make copies of these materials for their personal use. Faculty from other educational institutions may use these materials for nonprofit educational purposes, provided this copyright notice is preserved. Chapter 6 & 7 in EaC2e

Support for Name Spaces In an ALL, the compiler needs Compile-time mechanism for name resolution Runtime mechanism to compute an address from a name Compiler must emit that builds & maintains the runtime structures for addressability In an OOL, the compiler needs Compile-time mechanism for name resolution Runtime mechanism to compute an address from a name Compiler must emit that builds & maintains the runtime structures for addressability This lecture focuses on runtime support for OOLs. COMP 412, Fall 2017 1

Runtime Support for OOLs Where are we? We have seen: Symbol tables for leically-scoped ALLs Symbol tables & object tables for OOLs Linkage conventions for procedure calls (in ALLs and OOLs) Access links & displays to provide runtime support for leical scopes ALL addressability relies on the ARP and name mangled labels An OOL adds addresses that are relative to the receiving object Today: runtime structures to support addressability in an OOL In essence, given an object fee, how do we find fee.method() and fee.member COMP 412, Fall 2017 2

From the lecture on naming Compile-time Structures for OOLs Java To compile method M of object O in C, the compiler needs: 1. Leically scoped symbol table for the current block and its surrounding scopes in M Just like an ALL inner declarations hide outer declarations 2. Chain of symbol tables for inheritance Class C and all of its superes Need to find methods and instance variables in any super 3. Symbol tables for all global es (package scope) Entries for all members with visibility Need to construct symbol tables for imported packages and link them into the structure in appropriate places Three sets of tables are needed for name resolution. In an ALL, we could combine 1 & 3 for a single unified set of tables. In Java, we need to split them so that the compiler can check the inheritance hierarchy between the leical hierarchy & the global name space. COMP 412, Fall 2017 3

From the lecture on naming Compile-time Structures for OOLs Java Conceptually Leical Hierarchy Class Hierarchy Global Scope Search Order: leical hieraracy, hierarchy, global scope COMP 412, Fall 2017 Note the sheaf of tables model. 4

The Java Name Space Class Point { public int, y; public void draw(); } Class ColorPoint etends Point { Color c; public void draw() { } public void test() { y = ; draw(); } } Class C { int, y; public void m() { Point p = new ColorPoint(); y = p.; p.draw(); } } The ic eample for discussing inheritance. We will use & etend it. // inherits, y, & draw() from Point // local data // override (hide) Point s draw // local // independent of Point & ColorPoint // local data // local // uses ColorPoint, and, by inheritance // the definitions from Point This slide appeared gratuitously & COMP 412, Fall 2017 pointlessly in an earlier lecture. 5

Runtime Structures for OOLs This discussion is generic rather than Java-specific. Object lifetimes are independent Each object needs an object record (OR) to hold its state Independent allocation and deallocation Think heap We will talk of OR pointers, much like AR pointers We won t call them ORPs Classes are objects, too ORs of es instantiate the hierarchy Object Records Distinct static storage for data members Need fast, consistent access Known constant offsets from OR pointer Linguistic provision for initialization of method lifetimes, of lifetimes of other objects The Concept an object s data area fee() fie() foe() count 0 4 8 12 The Heap address polynomial for a vector, similar COMP 412, Fall 2017 to fields in an activation record. 6

Review What is an Object? The Concept: An object is an abstract data type that encapsulates data, operations and internal state behind a simple, consistent interface. Data Code Data Code Elaborating the concepts: Each object has internal state Data members are static (lifetime of object ) Eternal access is through members Each object has a set of associated procedures, or methods Some methods are public, others are private Locating a procedure by name is more comple than in an ALL Comple behavior arises from objects internal states y z Data Code To avoid ecess copies, keep in es Ideas COMP go 412, back Fall to 2017 Simula 67, & data-abstraction languages such as CLU & Alphard 7

Runtime Structures for OOLs From Concept to Implementation Members of a should share members Replication would waste space Replication would be a nightmare This discussion is generic rather than Java-specific. fee() fie() foe() count 0 4 8 12 The Concept y count data 1 data count 2 The Implementation fee() fie() foe() The Implementation Single copy of the for each method Class has a vector of pointers Place vector @ fied offset in OR COMP 412, Fall 2017 8

Runtime Structures for OOLs From Concept to Implementation Members of a should share members Replication would waste space Replication would be a nightmare This discussion is generic rather than Java-specific. fee() fie() foe() count 0 4 8 12 The Concept y count data 1 data 2 count The Implementation fee() fie() foe() The Implementation Single copy of the for each method Class has a vector of pointers Place vector @ fied offset in OR At offset 0 for efficiency (?) COMP 412, Fall 2017 9

Runtime Structures for OOLs From Concept to Implementation Members of a should share members Replication would waste space Replication would be a nightmare This discussion is generic rather than Java-specific. fee() fie() foe() count 0 4 8 12 The Concept y count data 1 data 2 fee() fie() The Implementation Single copy of the for each method Move pointer into object for faster access One more slot in the OR count Reality foe() One less indirection in each call COMP 412, Fall 2017 10

OR Layout Assume single inheritance Inheritance has a strong impact on OR Layout OR needs slots for each declared member, all the way up the hierarchy (, super, super-super, ) Each object needs an instance variable that points to its Each needs an instance variable that points to its super Can use prefiing of storage to lay out the OR Back to Our Java Eample Class Point Class Point { public int, y; } Class ColorPoint etends Point { Color c; } OR for a Point What happens if we cast a ColorPoint to a Point? COMP A Point 412, to Fall a ColorPoint? 2017 Take the word etends literally. 11 self self OR for a ColorPoint y y c

Open World versus Closed World Compile-time prefiing assumes that the structure is known when layout is performed. Two common cases occur in OO language design. Closed-World Assumption Class structure is known and closed prior to runtime Can lay out ORs in the compiler and/or the linker (Compile time) Open-World Assumption Class structure can change at runtime Cannot lay out ORs until they are allocated Walk hierarchy at allocation Need the compile-time data structures at runtime (Interpreter or JIT) C++ has a closed structure. Java as an open structure. STOP COMP 412, Fall 2017 12