Implementing Object-Oriented Languages. Implementing instance variable access. Implementing dynamic dispatching (virtual functions)

Size: px
Start display at page:

Download "Implementing Object-Oriented Languages. Implementing instance variable access. Implementing dynamic dispatching (virtual functions)"

Transcription

1 Implementing Object-Oriented Languages Implementing instance variable access Ke features: inheritance (possibl multiple) subtping & subtpe polmorphism message passing, dnamic binding, run-time tpe testing Subtpe polmorphism is the ke problem support uniform representation of data (analogous to boing for polmorphic data) store the class of each object at a fied offset organize laout of data to make instance variable access and method lookup & invocation fast code compiled epecting an instance of a superclass still works if run on an instance of a subclass multiple inheritance complicates this perform static analsis to bound polmorphism perform transformations to reduce polmorphism Ke problem: subtpe polmorphism Solution: prefiing laout of subclass has laout of superclass as a prefi code that accesses a superclass will access the superclass part of an subclass properl, transparentl + access is just a load or store at a constant offset etends Point { // OK: subclass polmorphism Point p = new ColorPoint(3,4,Blue); // OK: and have same offsets in allpoint subclasses int manhattan_distance = p. + p.; Craig Chambers 232 CSE 501 Craig Chambers 233 CSE 501 Implementing dnamic dispatching (virtual functions) Virtual function s How to find the right method to invoke for a dnamicall dispatched messagercvr.message(arg1, )? Observation: in Option 3, all instances of a given class will have identical method addresses Option 1: search inheritance hierarch, starting from run-time class ofrcvr ver slow, penalizes deep inheritance hierarchies Option 2: use a hash can act like a cache on the front of Option 1 still significantl slower than a direct procedure call but used in earl Smalltalk sstems! Option 3: store method addresses in the receiver objects, as if the were instance variables each message/generic function declares an instance variable each inheriting object stores an address in that instance variable invocation = load + indirect jump! + good, constant-time invocation, independent of inheritance structure, overriding, much bigger objects Option 4: factor out class-invariant parts into shared object instance variables whose values are common across all instances of a class (e.g. method addresses) are moved out to a separate object historicall called a virtual function (vtbl) each instance contains a single pointer to the vtbl combine with (or replace) class pointer laout of subclass s vtbl has laout of superclass s vtbl as a prefi + dnamic dispatching is fast & constant-time but an etra load + no space cost in object aside from vtbl/class pointer Craig Chambers 234 CSE 501 Craig Chambers 235 CSE 501

2 Eample of virtual function s Multiple inheritance int distance2origin(); Point:: Point:: Problem: prefiing doesn t work with multiple inheritance etends Point { void reverse_video(); ColorPt:: ColorPt:: etends Point, ColoredThing { ColorPoint cp = new ColorPoint(3, 4, Blue); Point p = cp; // OK ColoredThing t = cp; // OK ColorPoint cp2 = new ColorPoint(p., p., t.); // breaks? Craig Chambers 236 CSE 501 Craig Chambers 237 CSE 501 Some solutions Another solution Option 1: stick with single inheritance [e.g. Smalltalk] some eamples reall benefit from MI Option 2: distinguish classes from interfaces [e.g. Java, C#] onl single inheritance below classes ifrcvr staticall of class tpe, then can eploit prefiing for its instance variable accesses and message sends disallow instance variables in interfaces no problems accessing them! onl messages to receivers of interface tpe are unresolved much smaller problem; can use e.g. hashing Option 3: compute offset of a field inrcvr b sendingrcvr a message [Cecil/Vorte] reduced problem to dnamic dispatching appl CHA etc. to optimize (all) dispatches for fields whose offsets never change, static binding + inlining reduces dispatches to constant Option 4: embedding + pointer shifting [C++] concatenate superclass laouts, etend with subclass data when upcasting to a superclass, shift pointer to point to where superclass is embedded downcasting does the reverse virtual function calls ma need to shift rcvr pointers "trampolines" ma get inserted + gets back to constant-time access in most cases ver complicated, lots of little details some things (e.g. casting) ma now have run-time cost does poorl if using "virtual base classes", i.e., diamondshaped inheritance hierarchies some sensible programs now disallowed e.g. casting through void*, downcasting from virtual base class interior pointers ma complicate GC, equalit testing, debugging, etc. Craig Chambers 238 CSE 501 Craig Chambers 239 CSE 501

3 Eample etends Point, ColoredThing { ColorPoint cp = new ColorPoint(3, 4, Blue); Point p = cp; // OK ColoredThing t = cp; // OK: adds 8 tocp // now this works: ColorPoint cp2 = new ColorPoint(p., p., t.); cp // this works, too: ColorPoint cp3 = (ColorPoint) t; // subtracts 8 fromt p t Eample of virtual function s int (); p t void reverse_video(); etends Point, ColoredThing { ColorPt:: this = this + 12; jump CT::; Craig Chambers 240 CSE 501 Craig Chambers 241 CSE 501 Limitations of -based techniques Dnamic -based implementations Table-based techniques onl work well when: have static tpe information to use to map message/ instance variable names to offsets in s/objects not true in dnamicall tped languages cannot etend classes with new operations ecept via subclassing not true in languages with open classes (e.g. MultiJava [Clifton et al. 00]) or multiple dispatching (e.g. CLOS, Dlan, Cecil) cannot modif classes dnamicall not true in full reflective languages (e.g. Smalltalk, Self, CLOS) Standard implementation: global hash in runtime sstem indeed b class msg filled dnamicall as program runs can be flushed after reflective operations + reasonable space cost + incremental fair average-case dispatch time, poor worst-case time Refinement: hash per message name each call site knows staticall which to consult + faster dispatching memor loads and indirect jumps are inepensive ma not be true with heavil pipelined hardware Craig Chambers 242 CSE 501 Craig Chambers 243 CSE 501

4 Inline caching Eample of inline caching Give each dnamicall-dispatched call site its own small method lookup cache + call site knows its message name + cache is isolated from other call sites Trick: use machine call instruction itself as a one-element cache initiall: call runtime sstem slookup routine Lookup routine patches call instruction to branch to invoked method record receiver class net time through, jump directl to epected target method method checks whether current receiver class is same as last receiver class if so, then cache hit (90-95% frequenc, for Smalltalk) if not, then calllookup and rebind cache + fast dispatch sequence if cache hit ( 4 instructions plus call) + hardware call prefetching works well eploits self-modifing code low performance if not a cache hit Initiall: msg: class: After caching target method: msg: class: CPt ColorPoint::() if cache.class self.class then regular code [Deutsch & Schiffman 84] Craig Chambers 244 CSE 501 Craig Chambers 245 CSE 501 Polmorphic inline caching (PIC) Eample of polmorphic inline caching Idea: support a multi-element cache b generating a call-site-specific dispatcher stub + fast dispatching even if several classes are common still slow performance if man classes equall common some space cost Foreshadowing: dispatching stubs record dnamic profile data of which receiver classes occur at which call sites [Hölzle et al. 91] After a few receiver classes: msg: switch (self.class) { case ColorPt: case ColorPt3D: case Point: default: ColorPt::() Point::() Craig Chambers 246 CSE 501 Craig Chambers 247 CSE 501

5 Implementing the dispatcher stub switch Handling multiple dispatching In original PIC design, switch implemented with a linear chain of class identit tests Alternativel, can implement with a binar search, eploiting ordering of integer class IDs or addresses + avoid worst-case behavior of long linear searches + a single test can direct man classes to same target method requires global knowledge to construct dispatchers In traditional compilers, switch implemented with a jump, akin to C++ dispatch s Can blend -based lookups, linear search, and binar search [Chambers & Chen 99] eploit available static analsis of possible receiver classes, profile information of likel receiver classes construct dispatcher best balancing epected dispatching speed against dispatch space cost Languages with multimethods (e.g. CLOS, Dlan, Cecil) allow methods to dispatch on the run-time classes of an of the arguments call sites do not know staticall which arguments ma be dispatched upon Implementation schemes: hash indeed b N kes [Kiczales & Rodriguez 89] N-deep tree of hash s, each indeed b 1 ke [Dussud 89] can stop dispatching at an subtree if all remaining arguments undispatched N-deep DAG of 1-ke dispatches [Chen & Turau 94, Chambers & Chen 99] compressed N+1-dimensional dispatch [Amiel et al. 94, Pang et al. 99] Probabl more efficient to support multimethods directl than if simulated with double-dispatching [Ingalls 86] or visitor pattern [Gamma et al. 95] Craig Chambers 248 CSE 501 Craig Chambers 249 CSE 501

Object Oriented Languages. Hwansoo Han

Object Oriented Languages. Hwansoo Han Object Oriented Languages Hwansoo Han Object-Oriented Languages An object is an abstract data tpe Encapsulates data, operations and internal state behind a simple, consistent interface. z Data Code Data

More information

Classes. Compiling Methods. Code Generation for Objects. Implementing Objects. Methods. Fields

Classes. Compiling Methods. Code Generation for Objects. Implementing Objects. Methods. Fields Classes Implementing Objects Components fields/instance variables values differ from to usuall mutable methods values shared b all s of a class usuall immutable component visibilit: public/private/protected

More information

Announcements. CSCI 334: Principles of Programming Languages. Lecture 19: C++

Announcements. CSCI 334: Principles of Programming Languages. Lecture 19: C++ Announcements CSCI 4: Principles of Programming Languages Lecture 19: C++ HW8 pro tip: the HW7 solutions have a complete, correct implementation of the CPS version of bubble sort in SML. All ou need to

More information

Winter Compiler Construction T9 IR part 2 + Runtime organization. Announcements. Today. Know thy group s code

Winter Compiler Construction T9 IR part 2 + Runtime organization. Announcements. Today. Know thy group s code Winter 26-27 Compiler Construction T9 IR part 2 + Runtime organization Mool Sagiv and Roman Manevich School of Computer Science Tel-Aviv Universit Announcements What is epected in PA3 documentation (5

More information

Bidirectional Object Layout for Separate Compilation

Bidirectional Object Layout for Separate Compilation Proceedings of the 1995 AM onference on Object-Oriented Programming Sstems, Languages, and Applications (OOPSLA) Bidirectional Object Laout for Separate ompilation Andrew. Mers MI Laborator for omputer

More information

Typical Compiler. Ahead- of- time compiler. Compilers... that target interpreters. Interpreter 12/9/15. compile time. run time

Typical Compiler. Ahead- of- time compiler. Compilers... that target interpreters. Interpreter 12/9/15. compile time. run time Ahead- of- time Tpical Compiler compile time C source C 86 assembl 86 assembler 86 machine Source Leical Analzer Snta Analzer Semantic Analzer Analsis Intermediate Code Generator Snthesis run time 86 machine

More information

Object typing and subtypes

Object typing and subtypes CS 242 2012 Object typing and subtypes Reading Chapter 10, section 10.2.3 Chapter 11, sections 11.3.2 and 11.7 Chapter 12, section 12.4 Chapter 13, section 13.3 Subtyping and Inheritance Interface The

More information

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

Week 7. Statically-typed OO languages: C++ Closer look at subtyping C++ & Subtyping Week 7 Statically-typed OO languages: C++ Closer look at subtyping Why talk about C++? C++ is an OO extension of C Efficiency and flexibility from C OO program organization from Simula

More information

Classes. Code Generation for Objects. Compiling Methods. Dynamic Dispatch. The Need for Dispatching CS412/CS413

Classes. Code Generation for Objects. Compiling Methods. Dynamic Dispatch. The Need for Dispatching CS412/CS413 Classes CS4/CS43 Introduction to Comilers Tim Teitelbaum Lecture : Imlementing Objects 8 March 5 Comonents ields/instance variables values ma dier rom object to object usuall mutable methods values shared

More information

Semantics. Names. Binding Time

Semantics. Names. Binding Time /24/ CSE 3302 Programming Languages Semantics Chengkai Li, Weimin He Spring Names Names: identif language entities variables, procedures, functions, constants, data tpes, Attributes: properties of names

More information

Semantics (cont.) Symbol Table. Static Scope. Static Scope. Static Scope. CSE 3302 Programming Languages. Static vs. Dynamic Scope

Semantics (cont.) Symbol Table. Static Scope. Static Scope. Static Scope. CSE 3302 Programming Languages. Static vs. Dynamic Scope -2-1 CSE 3302 Programming Languages Semantics (cont.) Smbol Table Smbol Table: maintain bindings. Can be viewed as functions that map names to their attributes. Names SmbolTable Attributes Chengkai Li,

More information

Simple Dynamic Compilation with GOO. Jonathan Bachrach. MIT AI Lab 01MAR02 GOO 1

Simple Dynamic Compilation with GOO. Jonathan Bachrach. MIT AI Lab 01MAR02 GOO 1 Simple Dynamic Compilation with GOO Jonathan Bachrach MIT AI Lab 01MAR02 GOO 1 GOO Talk Preliminary work Introduce challenge Present GOO Introduce language Sketch implementation Report status Request Quick

More information

Programming Language Dilemma Fall 2002 Lecture 1 Introduction to Compilation. Compilation As Translation. Starting Point

Programming Language Dilemma Fall 2002 Lecture 1 Introduction to Compilation. Compilation As Translation. Starting Point Programming Language Dilemma 6.035 Fall 2002 Lecture 1 Introduction to Compilation Martin Rinard Laborator for Computer Science Massachusetts Institute of Technolog Stored program computer How to instruct

More information

Run Time Environment. Implementing Object-Oriented Languages

Run Time Environment. Implementing Object-Oriented Languages Run Time Environment Implementing Objet-Oriented Languages Copright 2017, Pedro C. Diniz, all rights reserved. Students enrolled in the Compilers lass at the Universit of Southern California have epliit

More information

Module Mechanisms CS412/413. Modules + abstract types. Abstract types. Multiple Implementations. How to type-check?

Module Mechanisms CS412/413. Modules + abstract types. Abstract types. Multiple Implementations. How to type-check? CS412/413 Introduction to Compilers and Translators Andrew Mers Cornell Universit Lecture 19: ADT mechanisms 10 March 00 Module Mechanisms Last time: modules, was to implement ADTs Module collection of

More information

Compiler construction

Compiler construction This lecture Compiler construction Lecture 5: Project etensions Magnus Mreen Spring 2018 Chalmers Universit o Technolog Gothenburg Universit Some project etensions: Arras Pointers and structures Object-oriented

More information

Interprocedural Analysis with Data-Dependent Calls. Circularity dilemma. A solution: optimistic iterative analysis. Example

Interprocedural Analysis with Data-Dependent Calls. Circularity dilemma. A solution: optimistic iterative analysis. Example Interprocedural Analysis with Data-Dependent Calls Circularity dilemma In languages with function pointers, first-class functions, or dynamically dispatched messages, callee(s) at call site depend on data

More information

CS S-11 Memory Management 1

CS S-11 Memory Management 1 CS414-2017S-11 Management 1 11-0: Three places in memor that a program can store variables Call stack Heap Code segment 11-1: Eecutable Code Code Segment Static Storage Stack Heap 11-2: Three places in

More information

VIRTUAL FUNCTIONS Chapter 10

VIRTUAL FUNCTIONS Chapter 10 1 VIRTUAL FUNCTIONS Chapter 10 OBJECTIVES Polymorphism in C++ Pointers to derived classes Important point on inheritance Introduction to virtual functions Virtual destructors More about virtual functions

More information

CS152: Programming Languages. Lecture 23 Advanced Concepts in Object-Oriented Programming. Dan Grossman Spring 2011

CS152: Programming Languages. Lecture 23 Advanced Concepts in Object-Oriented Programming. Dan Grossman Spring 2011 CS152: Programming Languages Lecture 23 Advanced Concepts in Object-Oriented Programming Dan Grossman Spring 2011 So far... The difference between OOP and records of functions with shared private state

More information

Intermediate Code, Object Representation, Type-Based Optimization

Intermediate Code, Object Representation, Type-Based Optimization CS 301 Spring 2016 Meetings March 14 Intermediate Code, Object Representation, Type-Based Optimization Plan Source Program Lexical Syntax Semantic Intermediate Code Generation Machine- Independent Optimization

More information

Dynamic Languages. CSE 501 Spring 15. With materials adopted from John Mitchell

Dynamic Languages. CSE 501 Spring 15. With materials adopted from John Mitchell Dynamic Languages CSE 501 Spring 15 With materials adopted from John Mitchell Dynamic Programming Languages Languages where program behavior, broadly construed, cannot be determined during compila@on Types

More information

Partial Dispatch: Optimizing Dynamically-Dispatched Multimethod Calls with Compile-Time Types and Runtime Feedback

Partial Dispatch: Optimizing Dynamically-Dispatched Multimethod Calls with Compile-Time Types and Runtime Feedback Partial Dispatch: Optimizing Dynamically-Dispatched Multimethod Calls with Compile-Time Types and Runtime Feedback Jonathan Bachrach Artificial Intelligence Laboratory Massachussetts Institute of Technology

More information

The code generator must statically assign a location in the AR for each temporary add $a0 $t1 $a0 ; $a0 = e 1 + e 2 addiu $sp $sp 4 ; adjust $sp (!

The code generator must statically assign a location in the AR for each temporary add $a0 $t1 $a0 ; $a0 = e 1 + e 2 addiu $sp $sp 4 ; adjust $sp (! Lecture Outline Code Generation (II) Adapted from Lectures b Profs. Ale Aiken and George Necula (UCB) Allocating temporaries in the Activation Record Let s optimie cgen a little Code generation for OO

More information

Object Oriented Programming. Spring 2008

Object Oriented Programming. Spring 2008 Dynamic Binding Implementation Object Oriented Programming 236703 Spring 2008 1 Implementation of Virtual Functions class Ellipse { //... public: E 1 virtual void draw() const; draw E + virtual void hide()

More information

History C++ Design Goals. How successful? Significant constraints. Overview of C++

History C++ Design Goals. How successful? Significant constraints. Overview of C++ 1 CS 242 History C++ John Mitchell C++ is an object-oriented extension of C C was designed by Dennis Ritchie at Bell Labs used to write Unix based on BCPL C++ designed by Bjarne Stroustrup at Bell Labs

More information

Method Resolution Approaches. Dynamic Dispatch

Method Resolution Approaches. Dynamic Dispatch Method Resolution Approaches Static - procedural languages (w/o fcn ptrs) Dynamically determined by data values C with function pointers Compile-time analysis can estimate possible callees Dynamically

More information

Dynamic Dispatch and Duck Typing. L25: Modern Compiler Design

Dynamic Dispatch and Duck Typing. L25: Modern Compiler Design Dynamic Dispatch and Duck Typing L25: Modern Compiler Design Late Binding Static dispatch (e.g. C function calls) are jumps to specific addresses Object-oriented languages decouple method name from method

More information

Lecture 16 Notes AVL Trees

Lecture 16 Notes AVL Trees Lecture 16 Notes AVL Trees 15-122: Principles of Imperative Computation (Fall 2015) Frank Pfenning 1 Introduction Binar search trees are an ecellent data structure to implement associative arras, maps,

More information

Runtime Support for OOLs Part II Comp 412

Runtime Support for OOLs Part II Comp 412 COMP 412 FALL 2017 Runtime Support for OOLs Part II Comp 412 soure IR Front End Optimizer Bak End IR target Copright 2017, Keith D. Cooper & Linda Torzon, all rights reserved. Students enrolled in Comp

More information

Today. CSE341: Programming Languages. Late Binding in Ruby Multiple Inheritance, Interfaces, Mixins. Ruby instance variables and methods

Today. CSE341: Programming Languages. Late Binding in Ruby Multiple Inheritance, Interfaces, Mixins. Ruby instance variables and methods Today CSE341: Programming Languages Late Binding in Ruby Multiple Inheritance, Interfaces, Mixins Alan Borning Spring 2018 Dynamic dispatch aka late binding aka virtual method calls Call to self.m2() in

More information

Interprocedural Analysis with Data-Dependent Calls. Circularity dilemma. A solution: optimistic iterative analysis. Example

Interprocedural Analysis with Data-Dependent Calls. Circularity dilemma. A solution: optimistic iterative analysis. Example Interprocedural Analysis with Data-Dependent Calls Circularity dilemma In languages with function pointers, first-class functions, or dynamically dispatched messages, callee(s) at call site depend on data

More information

The Procedure Abstraction

The Procedure Abstraction The Procedure Abstraction Procedure Abstraction Begins Chapter 6 in EAC The compiler must deal with interface between compile time and run time Most of the tricky issues arise in implementing procedures

More information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

Last Class: Multiple Inheritance. Implementing Polymorphism. Criteria. Problem. Smalltalk Message Passing. Smalltalk

Last Class: Multiple Inheritance. Implementing Polymorphism. Criteria. Problem. Smalltalk Message Passing. Smalltalk Last lass: Multiple Inheritance Multiple Inheritance Renaming Delegation Tricky cases in inheritance (stretchable circles) Implementing Polymorphism Not in the book... Problem How to efficiently find and

More information

CSE P 501 Compilers. Java Implementation JVMs, JITs &c Hal Perkins Winter /11/ Hal Perkins & UW CSE V-1

CSE P 501 Compilers. Java Implementation JVMs, JITs &c Hal Perkins Winter /11/ Hal Perkins & UW CSE V-1 CSE P 501 Compilers Java Implementation JVMs, JITs &c Hal Perkins Winter 2008 3/11/2008 2002-08 Hal Perkins & UW CSE V-1 Agenda Java virtual machine architecture.class files Class loading Execution engines

More information

CSE 401/M501 Compilers

CSE 401/M501 Compilers CSE 401/M501 Compilers Code Shape II Objects & Classes Hal Perkins Autumn 2018 UW CSE 401/M501 Autumn 2018 L-1 Administrivia Semantics/type check due next Thur. 11/15 How s it going? Reminder: if you want

More information

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

Runtime Support for OOLs Object Records, Code Vectors, Inheritance Comp 412 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

More information

Efficient Multiple Dispatching Using Nested Transition-Arrays

Efficient Multiple Dispatching Using Nested Transition-Arrays Efficient Multiple Dispatching Using Nested Transition-Arrays Weimin Chen, Karl Aberer GMD-IPSI, Dolivostr. 15, 64293 Darmstadt, Germany E-mail: {chen, aberer}@darmstadt.gmd.de Phone: +49-6151-869941 FAX:

More information

C++ Yanyan SHEN. slide 1

C++ Yanyan SHEN. slide 1 C++ Yanyan SHEN slide 1 History C++ is an object-oriented extension of C Designed by Bjarne Stroustrup at Bell Labs His original interest at Bell Labs was research on simulation Early extensions to C are

More information

Java and C CSE 351 Spring

Java and C CSE 351 Spring Java and C CSE 351 Spring 2018 https://xkcd.com/801/ Roadmap C: car *c = malloc(sizeof(car)); c->miles = 100; c->gals = 17; float mpg = get_mpg(c); free(c); Assembly language: Machine code: get_mpg: pushq

More information

What about Object-Oriented Languages?

What about Object-Oriented Languages? What about Object-Oriented Languages? What is an OOL? A language that supports object-oriented programming How does an OOL differ from an ALL? (ALGOL-Like Language) Data-centric name scopes for values

More information

CS558 Programming Languages Winter 2013 Lecture 8

CS558 Programming Languages Winter 2013 Lecture 8 OBJECT-ORIENTED PROGRAMMING CS558 Programming Languages Winter 2013 Lecture 8 Object-oriented programs are structured in terms of objects: collections of variables ( fields ) and functions ( methods ).

More information

CS107 Handout 37 Spring 2007 May 25, 2007 Introduction to Inheritance

CS107 Handout 37 Spring 2007 May 25, 2007 Introduction to Inheritance CS107 Handout 37 Spring 2007 May 25, 2007 Introduction to Inheritance Handout written by Julie Zelenski, updated by Jerry. Inheritance is a language property most gracefully supported by the object-oriented

More information

Comp 311 Principles of Programming Languages Lecture 21 Semantics of OO Languages. Corky Cartwright Mathias Ricken October 20, 2010

Comp 311 Principles of Programming Languages Lecture 21 Semantics of OO Languages. Corky Cartwright Mathias Ricken October 20, 2010 Comp 311 Principles of Programming Languages Lecture 21 Semantics of OO Languages Corky Cartwright Mathias Ricken October 20, 2010 Overview I In OO languages, data values (except for designated non-oo

More information

EECS1022 Winter 2018 Additional Notes Tracing Point, PointCollector, and PointCollectorTester

EECS1022 Winter 2018 Additional Notes Tracing Point, PointCollector, and PointCollectorTester EECS1022 Winter 2018 Additional Notes Tracing, Collector, and CollectorTester Chen-Wei Wang Contents 1 Class 1 2 Class Collector 2 Class CollectorTester 7 1 Class 1 class { 2 double ; double ; 4 (double

More information

Data Abstraction. Hwansoo Han

Data Abstraction. Hwansoo Han Data Abstraction Hwansoo Han Data Abstraction Data abstraction s roots can be found in Simula67 An abstract data type (ADT) is defined In terms of the operations that it supports (i.e., that can be performed

More information

JOVE. An Optimizing Compiler for Java. Allen Wirfs-Brock Instantiations Inc.

JOVE. An Optimizing Compiler for Java. Allen Wirfs-Brock Instantiations Inc. An Optimizing Compiler for Java Allen Wirfs-Brock Instantiations Inc. Object-Orient Languages Provide a Breakthrough in Programmer Productivity Reusable software components Higher level abstractions Yield

More information

Purely Functional Data structures (3) Purely Functional Data structures (4) Numerical Representations (1)

Purely Functional Data structures (3) Purely Functional Data structures (4) Numerical Representations (1) MGS 2011: FUN Lecture 2 Purel Functional Data Structures Henrik Nilsson Universit of Nottingham, UK Purel Functional Data structures (3) Linked list: After insert, if persistent: 1 2 3 1 7 Numerical Representations

More information

CS 314H Honors Data Structures Fall 2017 Programming Assignment #6 Treaps Due November 12/15/17, 2017

CS 314H Honors Data Structures Fall 2017 Programming Assignment #6 Treaps Due November 12/15/17, 2017 CS H Honors Data Structures Fall 207 Programming Assignment # Treaps Due November 2//7, 207 In this assignment ou will work individuall to implement a map (associative lookup) using a data structure called

More information

2.2 Absolute Value Functions

2.2 Absolute Value Functions . Absolute Value Functions 7. Absolute Value Functions There are a few was to describe what is meant b the absolute value of a real number. You ma have been taught that is the distance from the real number

More information

Absolute C++ Walter Savitch

Absolute C++ Walter Savitch Absolute C++ sixth edition Walter Savitch Global edition This page intentionally left blank Absolute C++, Global Edition Cover Title Page Copyright Page Preface Acknowledgments Brief Contents Contents

More information

Naming in OOLs and Storage Layout Comp 412

Naming in OOLs and Storage Layout Comp 412 COMP 412 FALL 2018 Naming in OOLs and Storage Layout Comp 412 source IR IR target Front End Optimizer Back End Copyright 2018, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in

More information

Agenda. CSE P 501 Compilers. Java Implementation Overview. JVM Architecture. JVM Runtime Data Areas (1) JVM Data Types. CSE P 501 Su04 T-1

Agenda. CSE P 501 Compilers. Java Implementation Overview. JVM Architecture. JVM Runtime Data Areas (1) JVM Data Types. CSE P 501 Su04 T-1 Agenda CSE P 501 Compilers Java Implementation JVMs, JITs &c Hal Perkins Summer 2004 Java virtual machine architecture.class files Class loading Execution engines Interpreters & JITs various strategies

More information

Polymorphism. Zimmer CSCI 330

Polymorphism. Zimmer CSCI 330 Polymorphism Polymorphism - is the property of OOP that allows the run-time binding of a function's name to the code that implements the function. (Run-time binding to the starting address of the code.)

More information

Java Inheritance. Written by John Bell for CS 342, Spring Based on chapter 6 of Learning Java by Niemeyer & Leuck, and other sources.

Java Inheritance. Written by John Bell for CS 342, Spring Based on chapter 6 of Learning Java by Niemeyer & Leuck, and other sources. Java Inheritance Written by John Bell for CS 342, Spring 2018 Based on chapter 6 of Learning Java by Niemeyer & Leuck, and other sources. Review Which of the following is true? A. Java classes may either

More information

CSE 504. Expression evaluation. Expression Evaluation, Runtime Environments. One possible semantics: Problem:

CSE 504. Expression evaluation. Expression Evaluation, Runtime Environments. One possible semantics: Problem: Expression evaluation CSE 504 Order of evaluation For the abstract syntax tree + + 5 Expression Evaluation, Runtime Environments + + x 3 2 4 the equivalent expression is (x + 3) + (2 + 4) + 5 1 2 (. Contd

More information

Objects, Encapsulation, Inheritance (2)

Objects, Encapsulation, Inheritance (2) CS 242 2012 Objects, Encapsulation, Inheritance (2) Reading (two lectures) Chapter 10, except section 10.4 Chapter 11, sections 11.1, 11.2, 11.3.1 and 11.4., 11.5, 11.6 only Chapter 12, sections 12.1,

More information

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring Java Outline Java Models for variables Types and type checking, type safety Interpretation vs. compilation Reasoning about code CSCI 2600 Spring 2017 2 Java Java is a successor to a number of languages,

More information

OOPLs - call graph construction Compile-time analysis of reference variables and fields. Example

OOPLs - call graph construction Compile-time analysis of reference variables and fields. Example OOPLs - call graph construction Compile-time analysis of reference variables and fields Determines to which objects (or types of objects) a reference variable may refer during execution Primarily hierarchy-based

More information

G Programming Languages - Fall 2012

G Programming Languages - Fall 2012 G22.2110-003 Programming Languages - Fall 2012 Lecture 4 Thomas Wies New York University Review Last week Control Structures Selection Loops Adding Invariants Outline Subprograms Calling Sequences Parameter

More information

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

Grade Weights. Language Design and Overview of COOL. CS143 Lecture 2. Programming Language Economics 101. Lecture Outline Grade Weights Language Design and Overview of COOL CS143 Lecture 2 Project 0% I, II 10% each III, IV 1% each Midterm 1% Final 2% Written Assignments 10% 2.% each Prof. Aiken CS 143 Lecture 2 1 Prof. Aiken

More information

Java and C I. CSE 351 Spring Instructor: Ruth Anderson

Java and C I. CSE 351 Spring Instructor: Ruth Anderson Java and C I CSE 351 Spring 2017 Instructor: Ruth Anderson Teaching Assistants: Dylan Johnson Kevin Bi Linxing Preston Jiang Cody Ohlsen Yufang Sun Joshua Curtis Administrivia Homework 5 Due TONIGHT Wed

More information

Francesco Nidito. Programmazione Avanzata AA 2007/08

Francesco Nidito. Programmazione Avanzata AA 2007/08 Francesco Nidito Programmazione Avanzata AA 2007/08 Outline 1 2 3 4 Reference: Micheal L. Scott, Programming Languages Pragmatics, Chapter 10 , type systems and type checking A type type is an abstraction

More information

G Programming Languages - Fall 2012

G Programming Languages - Fall 2012 G22.2110-003 Programming Languages - Fall 2012 Lecture 12 Thomas Wies New York University Review Last lecture Modules Outline Classes Encapsulation and Inheritance Initialization and Finalization Dynamic

More information

Introduction to Shape and Pointer Analysis

Introduction to Shape and Pointer Analysis Introduction to Shape and Pointer Analsis CS 502 Lecture 11 10/30/08 Some slides adapted from Nielson, Nielson, Hankin Principles of Program Analsis Analsis of the Heap Thus far, we have focussed on control

More information

Francesco Nidito. Programmazione Avanzata AA 2007/08

Francesco Nidito. Programmazione Avanzata AA 2007/08 Francesco Nidito Programmazione Avanzata AA 2007/08 Outline 1 2 3 4 Reference: Micheal L. Scott, Programming Languages Pragmatics, Chapter 10 , type systems and type checking A type type is an abstraction

More information

Derived and abstract data types. TDT4205 Lecture 15

Derived and abstract data types. TDT4205 Lecture 15 1 Derived and abstract data types TDT4205 Lecture 15 2 Where we were We ve looked at static semantics for primitive types and how it relates to type checking We ve hinted at derived types using a multidimensional

More information

C++ Important Questions with Answers

C++ Important Questions with Answers 1. Name the operators that cannot be overloaded. sizeof,.,.*,.->, ::,? 2. What is inheritance? Inheritance is property such that a parent (or super) class passes the characteristics of itself to children

More information

CS 314H Algorithms and Data Structures Fall 2012 Programming Assignment #6 Treaps Due November 11/14/16, 2012

CS 314H Algorithms and Data Structures Fall 2012 Programming Assignment #6 Treaps Due November 11/14/16, 2012 CS H Algorithms and Data Structures Fall 202 Programming Assignment # Treaps Due November //, 202 In this assignment ou will work in pairs to implement a map (associative lookup) using a data structure

More information

Lecture Notes on AVL Trees

Lecture Notes on AVL Trees Lecture Notes on AVL Trees 15-122: Principles of Imperative Computation Frank Pfenning Lecture 19 March 28, 2013 1 Introduction Binar search trees are an ecellent data structure to implement associative

More information

EDAN65: Compilers, Lecture 13 Run;me systems for object- oriented languages. Görel Hedin Revised:

EDAN65: Compilers, Lecture 13 Run;me systems for object- oriented languages. Görel Hedin Revised: EDAN65: Compilers, Lecture 13 Run;me systems for object- oriented languages Görel Hedin Revised: 2014-10- 13 This lecture Regular expressions Context- free grammar ATribute grammar Lexical analyzer (scanner)

More information

CSE341: Programming Languages Lecture 23 Multiple Inheritance, Mixins, Interfaces, Abstract Methods. Dan Grossman Autumn 2018

CSE341: Programming Languages Lecture 23 Multiple Inheritance, Mixins, Interfaces, Abstract Methods. Dan Grossman Autumn 2018 CSE341: Programming Languages Lecture 23 Multiple Inheritance, Mixins, Interfaces, Abstract Methods Dan Grossman Autumn 2018 What next? Have used classes for OOP's essence: inheritance, overriding, dynamic

More information

CS 403 Compiler Construction Lecture 8 Syntax Tree and Intermediate Code Generation [Based on Chapter 6 of Aho2] This Lecture

CS 403 Compiler Construction Lecture 8 Syntax Tree and Intermediate Code Generation [Based on Chapter 6 of Aho2] This Lecture CS 403 Compiler Construction Lecture 8 Snta Tree and Intermediate Code Generation [Based on Chapter 6 of Aho2] 1 This Lecture 2 1 Remember: Phases of a Compiler This lecture: Intermediate Code This lecture:

More information

The Java Programming Language

The Java Programming Language The Java Programming Language Slide by John Mitchell (http://www.stanford.edu/class/cs242/slides/) Outline Language Overview History and design goals Classes and Inheritance Object features Encapsulation

More information

Wednesday, February 19, 2014

Wednesday, February 19, 2014 Wednesda, Februar 19, 2014 Topics for toda Solutions to HW #2 Topics for Eam #1 Chapter 6: Mapping High-level to assembl-level The Pep/8 run-time stack Stack-relative addressing (,s) SP manipulation Stack

More information

Section 2.2: Absolute Value Functions, from College Algebra: Corrected Edition by Carl Stitz, Ph.D. and Jeff Zeager, Ph.D. is available under a

Section 2.2: Absolute Value Functions, from College Algebra: Corrected Edition by Carl Stitz, Ph.D. and Jeff Zeager, Ph.D. is available under a Section.: Absolute Value Functions, from College Algebra: Corrected Edition b Carl Stitz, Ph.D. and Jeff Zeager, Ph.D. is available under a Creative Commons Attribution-NonCommercial-ShareAlike.0 license.

More information

CS-XXX: Graduate Programming Languages. Lecture 23 Types for OOP; Static Overloading and Multimethods. Dan Grossman 2012

CS-XXX: Graduate Programming Languages. Lecture 23 Types for OOP; Static Overloading and Multimethods. Dan Grossman 2012 CS-XXX: Graduate Programming Languages Lecture 23 Types for OOP; Static Overloading and Multimethods Dan Grossman 2012 So far... Last lecture (among other things): The difference between OOP and records

More information

Project 6 Due 11:59:59pm Thu, Dec 10, 2015

Project 6 Due 11:59:59pm Thu, Dec 10, 2015 Project 6 Due 11:59:59pm Thu, Dec 10, 2015 Updates None yet. Introduction In this project, you will add a static type checking system to the Rube programming language. Recall the formal syntax for Rube

More information

C++ Part 2 <: <: C++ Run-Time Representation. Smalltalk vs. C++ Dynamic Dispatch. Smalltalk vs. C++ Dynamic Dispatch

C++ Part 2 <: <: C++ Run-Time Representation. Smalltalk vs. C++ Dynamic Dispatch. Smalltalk vs. C++ Dynamic Dispatch C++ Run-Time Representation Point object Point vtable Code for move C++ Part x y CSCI 4 Stephen Freund ColorPoint object x 4 y 5 c red ColorPoint vtable Code for move Code for darken Data at same offset

More information

Design Patterns: State, Bridge, Visitor

Design Patterns: State, Bridge, Visitor Design Patterns: State, Bridge, Visitor State We ve been talking about bad uses of case statements in programs. What is one example? Another way in which case statements are sometimes used is to implement

More information

Monday, September 28, 2015

Monday, September 28, 2015 Monda, September 28, 2015 Topics for toda Chapter 6: Mapping High-level to assembl-level The Pep/8 run-time stack (6.1) Stack-relative addressing (,s) SP manipulation Stack as scratch space Global variables

More information

CSc 520. Principles of Programming Languages 45: OO Languages Introduction

CSc 520. Principles of Programming Languages 45: OO Languages Introduction CSc 520 Principles of Programming Languages 45: OO Languages Introduction Christian Collberg Department of Computer Science University of Arizona collberg@cs.arizona.edu Copyright c 2005 Christian Collberg

More information

Subtyping (Dynamic Polymorphism)

Subtyping (Dynamic Polymorphism) Fall 2018 Subtyping (Dynamic Polymorphism) Yu Zhang Course web site: http://staff.ustc.edu.cn/~yuzhang/tpl References PFPL - Chapter 24 Structural Subtyping - Chapter 27 Inheritance TAPL (pdf) - Chapter

More information

Object Model. Object Oriented Programming Spring 2015

Object Model. Object Oriented Programming Spring 2015 Object Model Object Oriented Programming 236703 Spring 2015 Class Representation In Memory A class is an abstract entity, so why should it be represented in the runtime environment? Answer #1: Dynamic

More information

Chapter 5 Object-Oriented Programming

Chapter 5 Object-Oriented Programming Chapter 5 Object-Oriented Programming Develop code that implements tight encapsulation, loose coupling, and high cohesion Develop code that demonstrates the use of polymorphism Develop code that declares

More information

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

Design issues for objectoriented. languages. Objects-only pure language vs mixed. Are subclasses subtypes of the superclass? Encapsulation Encapsulation grouping of subprograms and the data they manipulate Information hiding abstract data types type definition is hidden from the user variables of the type can be declared variables

More information

MultiJava: Modular Open Classes and Symmetric Multiple Dispatch for Java

MultiJava: Modular Open Classes and Symmetric Multiple Dispatch for Java MultiJava: Modular Open Classes and Symmetric Multiple Dispatch for Java Curtis Clifton, Gary T. Leavens, Craig Chambers, and Todd Millstein TR #00-06a April 2000, Revised July 2000 An earlier version

More information

CSE 5311 Notes 9: Hashing

CSE 5311 Notes 9: Hashing CSE 53 Notes 9: Hashing (Last updated 7/5/5 :07 PM) CLRS, Chapter Review: 2: Chaining - related to perfect hashing method 3: Hash functions, skim universal hashing 4: Open addressing COLLISION HANDLING

More information

Type Hierarchy. Lecture 6: OOP, autumn 2003

Type Hierarchy. Lecture 6: OOP, autumn 2003 Type Hierarchy Lecture 6: OOP, autumn 2003 The idea Many types have common behavior => type families share common behavior organized into a hierarchy Most common on the top - supertypes Most specific at

More information

Building Interpreters

Building Interpreters Building Interpreters Mool Sagiv html://www.cs.tau.ac.il/~msagiv/courses/wcc13.html Chapter 4 1 Structure of a simple compiler/interpreter Leical analsis Snta analsis Runtime Sstem Design Intermediate

More information

Relationships Between Real Things. CSE 143 Java. Common Relationship Patterns. Composition: "has a" CSE143 Sp Student.

Relationships Between Real Things. CSE 143 Java. Common Relationship Patterns. Composition: has a CSE143 Sp Student. CSE 143 Java Object & Class Relationships Inheritance Reading: Ch. 9, 14 Relationships Between Real Things Man walks dog Dog strains at leash Dog wears collar Man wears hat Girl feeds dog Girl watches

More information

Semantic Analysis. CSE 307 Principles of Programming Languages Stony Brook University

Semantic Analysis. CSE 307 Principles of Programming Languages Stony Brook University Semantic Analysis CSE 307 Principles of Programming Languages Stony Brook University http://www.cs.stonybrook.edu/~cse307 1 Role of Semantic Analysis Syntax vs. Semantics: syntax concerns the form of a

More information

What are the rules of elementary algebra

What are the rules of elementary algebra What are the rules of elementar algebra James Davenport & Chris Sangwin Universities of Bath & Birmingham 7 Jul 2010 Setting A relativel traditional mathematics course, at, sa first-ear undergraduate level.

More information

CSE 401/M501 Compilers

CSE 401/M501 Compilers CSE 401/M501 Compilers ASTs, Modularity, and the Visitor Pattern Hal Perkins Autumn 2018 UW CSE 401/M501 Autumn 2018 H-1 Agenda Today: AST operations: modularity and encapsulation Visitor pattern: basic

More information

Inheritance, Polymorphism and the Object Memory Model

Inheritance, Polymorphism and the Object Memory Model Inheritance, Polymorphism and the Object Memory Model 1 how objects are stored in memory at runtime? compiler - operations such as access to a member of an object are compiled runtime - implementation

More information

Search Trees. Chapter 11

Search Trees. Chapter 11 Search Trees Chapter 6 4 8 9 Outline Binar Search Trees AVL Trees Spla Trees Outline Binar Search Trees AVL Trees Spla Trees Binar Search Trees A binar search tree is a proper binar tree storing ke-value

More information

Java and C. CSE 351 Autumn 2018

Java and C. CSE 351 Autumn 2018 Java and C CSE 351 Autumn 2018 Instructor: Teaching Assistants: Justin Hsia Akshat Aggarwal An Wang Andrew Hu Brian Dai Britt Henderson James Shin Kevin Bi Kory Watson Riley Germundson Sophie Tian Teagan

More information

Introducing C++ David Chisnall. March 15, 2011

Introducing C++ David Chisnall. March 15, 2011 Introducing C++ David Chisnall March 15, 2011 Why Learn C++? Lots of people used it to write huge, unmaintainable code......which someone then gets paid a lot to maintain. C With Classes Predecessor of

More information

C++ Programming: Polymorphism

C++ Programming: Polymorphism C++ Programming: Polymorphism 2018 년도 2 학기 Instructor: Young-guk Ha Dept. of Computer Science & Engineering Contents Run-time binding in C++ Abstract base classes Run-time type identification 2 Function

More information