External Uniqueness Presented by Nir Atias Dave Clarke Tobias Wrigstad Encapsulation Seminar 2006.

Slides:



Advertisements
Similar presentations
A Framework for describing recursive data structures Kenneth Roe Scott Smith.
Advertisements

Containers CMPS Reusable containers Simple data structures in almost all nontrivial programs Examples: vectors, linked lists, stacks, queues, binary.
Intermediate Code Generation
Programming Languages and Paradigms
CS412/413 Introduction to Compilers Radu Rugina Lecture 37: DU Chains and SSA Form 29 Apr 02.
Portability and Safety Mahdi Milani Fard Dec, 2006 Java.
Abstract Data Types Data abstraction, or abstract data types, is a programming methodology where one defines not only the data structure to be used, but.
CS 211 Inheritance AAA.
Ownership, Encapsulation and the Disjointness of Type and Effect Dave Clarke, Sophia Drossopoulou/2002 Encapsulation seminar Dec Sharon Goldschlager.
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
Cse321, Programming Languages and Compilers 1 6/12/2015 Lecture #17, March 12, 2007 Procedure Abstraction, Name Spaces, Scoping Rules, Activation Records,
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
Alias Annotations for Program Understanding Jonathan Aldrich Valentin Kostadinov Craig Chambers University of Washington.
1 Chapter 6 Inheritance, Interfaces, and Abstract Classes.
Data Flow Analysis Compiler Design October 5, 2004 These slides live on the Web. I obtained them from Jeff Foster and he said that he obtained.
1 Islands : Aliasing Protection In Object-Oriented Languages By : John Hogg OOPSLA 91 Aharon Abadi.
CSC 395 – Software Engineering Lecture 21: Overview of the Term & What Goes in a Data Dictionary.
Abstract Data Types and Encapsulation Concepts
Ownership Types for Object Encapsulation Authors:Chandrasekhar Boyapati Barbara Liskov Liuba Shrira Presented by: Charles Lin Course: CMSC 631.
Chapter TwelveModern Programming Languages1 Memory Locations For Variables.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
1 Abstraction  Identify important aspects and ignore the details  Permeates software development programming languages are abstractions built on hardware.
An Improved Algorithm to Accelerate Regular Expression Evaluation Author: Michela Becchi, Patrick Crowley Publisher: 3rd ACM/IEEE Symposium on Architecture.
The Procedure Abstraction, Part V: Support for OOLs Comp 412 Copyright 2010, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in.
Existential Quantification for Variant Ownership Nicholas Cameron Sophia Drossopoulou Imperial College London (Victoria University of Wellington)‏
CS212: Object Oriented Analysis and Design Lecture 9: Function Overloading in C++
OOP: Encapsulation,Abstraction & Polymorphism. What is Encapsulation Described as a protective barrier that prevents the code and data being randomly.
Data Structures Using C++ 2E1 Inheritance An “is-a” relationship –Example: “every employee is a person” Allows new class creation from existing classes.
PowerPoint Presentation for Dennis & Haley Wixom, Systems Analysis and Design, 2 nd Edition Copyright 2003 © John Wiley & Sons, Inc. All rights reserved.
A Universe-Type-Based Verification Technique for Mutable Static Fields and Methods Alexander J Summers Sophia Drossopoulou Imperial College London Peter.
Object Oriented Software Development
08 Encapsulation and Abstraction. 2 Contents Defining Abstraction Levels of Abstraction Class as Abstraction Defining a Java Class Instantiating a Class.
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
Featherweight Generic Ownership Alex Potanin, James Noble Victoria University of Wellington Dave Clarke CWI, Netherlands Robert Biddle Carlton University.
Introduction to Object-Oriented Programming Lesson 2.
Chapter 5 Classes and Methods II Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin, D. Mickunas, E.
1 CS Programming Languages Class 22 November 14, 2000.
1 Copyright © 1998 by Addison Wesley Longman, Inc. Chapter 10 Abstraction - The concept of abstraction is fundamental in programming - Nearly all programming.
Chapter 3: Introducing the UML
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
PROGRAMMING PRE- AND POSTCONDITIONS, INVARIANTS AND METHOD CONTRACTS B MODULE 2: SOFTWARE SYSTEMS 13 NOVEMBER 2013.
Singleton Pattern Presented By:- Navaneet Kumar ise
The const Keyword Extreme Encapsulation. Humble Beginnings There are often cases in coding where it is helpful to use a const variable in a method or.
Singleton Pattern. Problem Want to ensure a single instance of a class, shared by all uses throughout a program Context Need to address initialization.
Chapter 7 Classes and Methods III: Static Methods and Variables Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition)
1 Verification of object-oriented programs with invariants Mike Barnett, Robert DeLine, Manuel Fahndrich, K. Rustan M. Leino, Wolfram Schulte ECOOP 2003.
Recap Introduction to Inheritance Inheritance in C++ IS-A Relationship Polymorphism in Inheritance Classes in Inheritance Visibility Rules Constructor.
Internet Computing Module II. Syllabus Creating & Using classes in Java – Methods and Classes – Inheritance – Super Class – Method Overriding – Packages.
CPSC 252 ADTs and C++ Classes Page 1 Abstract data types (ADTs) An abstract data type is a user-defined data type that has: private data hidden inside.
Classes CS 162 (Summer 2009). Parts of a Class Instance Fields Methods.
Eine By: Avinash Reddy 09/29/2016.
DDC 2423 DATA STRUCTURE Main text:
Abstract Data Types and Encapsulation Concepts
The Lifetime of a Variable
Multi-Methods in Cecil
Corky Cartwright January 18, 2017
Abstract Data Types and Encapsulation Concepts
Names, Binding, and Scope
Abstract Data Types and Encapsulation Concepts
Lecture 15 (Notes by P. N. Hilfinger and R. Bodik)
Data Flow Analysis Compiler Design
CISC/CMPE320 - Prof. McLeod
UNIT V Run Time Environments.
Objects Managing a Resource
COMPILERS Semantic Analysis
Object Encapsulation CSC 422 Dr. Spiegel.
11.1 The Concept of Abstraction
Chapter 5 Classes.
Chapter 11 Abstraction - The concept of abstraction is fundamental in
Presentation transcript:

External Uniqueness Presented by Nir Atias Dave Clarke Tobias Wrigstad Encapsulation Seminar 2006

What are we doing here What is uniqueness? Problems with current approaches Forming a solution External Uniqueness Samples & patterns Conclusions Beyond External Uniqueness

Uniqueness Problem We want to ensure only one reference to an object exists (no aliasing) Solution Annotate a reference as unique and restrict operations on that reference Introduce a mechanism to work with the reference (borrowing)

Problems Abstraction Changes to the implementation of an object require changes in its interface Orthogonality The operations on borrowed unique references are limited Definitional What happens when an object is borrowed

Abstraction In existing proposals: Methods are annotated with respect of consuming unique pointers Islands Effects systems Changes in implementation requires changes in signature Change is propagated in the program

Orthogonality Borrowing mechanism places restrictions on the borrowed reference Don’t want the original object to loose its uniqueness property after borrowing has ceased This implies that borrowed references have their own rules

Definitional What happens when a reference is borrowed? Allow both borrowed reference and unique reference, thus weakening reasoning power Nullify the original reference during borrowing, risk race conditions and NullPointerException Ensure that when unique reference is used, all aliases and borrowed references are dead.

The Main Idea Introduce a new type of uniqueness: External Uniqueness A reference is externally unique if it is the only external reference to an object Internal aliasing is allowed

Forming a solution Use ownership types to determine aggregate scope Ownership types distinguish between the inside and the outside of an object Ownership types allow reasoning about aggregates Nullify unique reference while borrowing (simplicity)

Ownership Types Are you in or out? Distinction between the inside and outside of an object An object cannot be accessed from outside of its owner Owner as permission to access an object Owners-as-dominators property owners are on all paths from the root to an object in the object graph

Ownership Types – cont. Parameterize classes by owners Additional owner parameters are allowed ( owner <* p i ) this can be used as an owner for owned objects ( this <* owner ) An object may refer only to objects it owns objects that are owned by its parameters

External Uniqueness A reference is externally unique if it is the only external reference to an object In object graph representation, we have dominating edge property Refine the owners-as-dominators property The edge is on all paths from the root to an object in the object graph Allow to move aggregates

Dominating Edge In red we have the ownership tree In blue we have the object graph If a reference is unique then we have dominating edge

Ownership and Uniqueness unique is part of the type A unique reference has a movement bound that acts as an owner If p is the movement bound of a unique reference we will depict the reference as unique p Movement bound can change While regular owner is invariant Movement bound can be declared by the programmer

Externally Unique References Movement Allow destructive read operation Possibly loosing uniqueness Cannot assign owner with not enough permissions

Externally Unique References Borrowing Unique references can be treated as ordinary references (temporarily) Type system ensures that when the borrowing has finished no additional references remain The original reference (or other) is restored to the place from where it was borrowed

Borrowing Operation

So what do we have? Only one of the following One active reference Dominating edge property ensures that there is only one active reference to an object Internal references are active only while borrowing Many references with limited scope Borrowing is limited in scope Original unique reference is invalidated

Some more info Constructors are viewed as (almost) regular method calls Parameters cannot have owner in the type (except as a movement bound) As a result: this cannot be assigned to an external (pre- existing) object Methods can be parameterized by owners Cannot capture argument whose owner is a parameter

Samples Common scenarios & Addressing known issues

Borrowing Accessing methods and fields requires borrowing External Uniqueness The bus is externally unique but have multiple references from owned Clients class Server { unique Bus bus; this ServerSocket ss; void accept() { while (true) { unique Socket s = ss.accept(); borrow bus as b { b.add(new unique Client(s--)); } } } } class Client { owner Bus bus; unique Socket s; Client( unique Socket s ) { this.s = s--; } } class Bus { this ClientList clients; void add( unique Client c ) { this Client current = c--; clients.add(current); current.bus = this; } }

Simulating Borrowing Owner-polymorphic methods (guarantees not to create heap-level aliases) can be called with unique references class Printer { static void print(o Printable p ) {... } } unique B b; // implements Printable borrow b as b1 { Printer.print (b1); }

Orthogonality Scoped regions enables construction of temporary heap objects, that referes to existing objects Existing objects might be unique No aliasing outside of scope because of deep-ownership class Printer { static void print(o Printable p ) { (a) { // temporary owner a LayoutManager lm; lm = new a LayoutManager (p); lm.addBorder(); lm.print( "....." ); } } } unique B b; // implements Printable borrow b as b1 { Printer.print (b1); }

External Initialization Problematic with ownership types (static owners) The movement bound changes (downwards in the object graph) class Lexer { this InputStream stream; Lexer( unique InputStream s) { stream = s--; } } void lexerClient() { unique InputStream stream; unique Lexer l; stream = new FileInputStream(file); l = new Lexer(stream--); }

Transfer of Ownership Important pattern in concurrent programming Movement-bound of B is D, so no references to A are allowed in B B can be a complex aggregate class TokenRing { owner TokenRing next; unique Token token; void give() { next.recieve(token--); } void recieve(unique Token tkn) { token = tkn--; } }

Merging Representations Merging (without copying) linked data structures Without breaking encapsulation In the sample: bh can change while borrowed class Link { data Object data; owner Link next, prev; } class List { unique Link head; void append( owner List other ) { borrow head as bh { ho Link ohead = other.head--; if( bh==null ) { bh = ohead; } else if( ohead!=null ) { ho Link h = bh; while( h.next != null ) { h = h.next; } h.next = ohead; h.next.prev = h; } } } }

Conclusions Abstraction All classes can be used as unique references Regardless of class declaration Methods are not annotated with reference consumption information

Conclusions Orthogonality Using several mechanism: Borrowing Owner polymorphic methods Scoped regions After borrowing, a unique reference can be used as a regular reference No restrictions on borrowed references No concept of borrowed reference in the language

Conclusions Definitional Original reference is nullified Reinstatement of borrowed value adds power Prone to race conditions A better solution Exists but much more complicated (invalidate the borrowed references when the original is accessed)

Anything else? Reentrancy Once borrowed, a unique object can only be reentered from a local (nested) object Therefore it cannot be reentered from an external object An object referred to uniquely can only be entered by one thread

Some more… Object model Ownership types model IS-PART-OF relationship All references to an owned object are confined within it owner Lifetime management Further work required

Beyond External Uniqueness Iterator Pattern Or how to publish an object with knowledge of implementation Break the encapsulation in a given scope  Inner classes  Package Primary owners Exception Handling How does it fit with ownership types languages? Static methods

The End Hope you had some fun