Featherweight Generic Ownership Alex Potanin, James Noble Victoria University of Wellington Dave Clarke CWI, Netherlands Robert Biddle Carlton University.

Slides:



Advertisements
Similar presentations
Chapter 13 Abstraction and inheritance. This chapter discusses n Implementing abstraction. u extension u inheritance n Polymorphism/dynamic binding. n.
Advertisements

Lists and the Collection Interface Chapter 4. Chapter Objectives To become familiar with the List interface To understand how to write an array-based.
Taming Wildcards in Javas Type System Ross Tate Alan Leung Sorin Lerner University of California, San Diego.
1 Mooly Sagiv and Greta Yorsh School of Computer Science Tel-Aviv University Modern Compiler Design.
Lecture 10: Part 1: OO Issues CS 540 George Mason University.
Portability and Safety Mahdi Milani Fard Dec, 2006 Java.
Object and Reference Immutability using Java Generics Yoav Zibin, Alex Potanin(*), Mahmood Ali, Shay Artzi, Adam Kiezun, and Michael D. Ernst MIT Computer.
Generics and the ArrayList Class
Objectives Introduction to Inheritance and Composition (Subclasses and SuperClasses) Overriding (and extending), and inheriting methods and constructors.
Ownership, Encapsulation and the Disjointness of Type and Effect Dave Clarke, Sophia Drossopoulou/2002 Encapsulation seminar Dec Sharon Goldschlager.
ITEC200 – Week03 Inheritance and Class Hierarchies.
Java Generics.
© 2006 Pearson Addison-Wesley. All rights reserved9 A-1 Chapter 9 Advanced Java Topics.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Confined Types Encapsulation and modularity Seminar November, 2005 presented by: Guy Gueta.
Alias Annotations for Program Understanding Jonathan Aldrich Valentin Kostadinov Craig Chambers University of Washington.
The Procedure Abstraction Part IV: Run-time Structures for OOLs Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students.
1 Evan Korth New York University Inheritance and Polymorphism Professor Evan Korth New York University.
1 Introduction to CS Agenda Syllabus Schedule Lecture: the management of complexity.
Lists and the Collection Interface Chapter 4. Chapter 4: Lists and the Collection Interface2 Chapter Objectives To become familiar with the List interface.
Lecture 32 Inheritance COMP1681 / SE15 Introduction to Programming.
Chapter 14 Generics and the ArrayList Class Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
1 Evan Korth New York University Inheritance and Polymorphism Professor Evan Korth New York University.
Feather-Weight Java COS 441 Princeton University Fall 2004.
Data Abstraction and Object- Oriented Programming CS351 – Programming Paradigms.
A Seminar on Encapsulation Noam Rinetzky Mooly Sagiv Summary.
Ownership Types for Object Encapsulation Authors:Chandrasekhar Boyapati Barbara Liskov Liuba Shrira Presented by: Charles Lin Course: CMSC 631.
Javari: Adding Reference Immutability to Java Matthew Tschantz and Michael Ernst MIT CSAIL.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 17 Animated Version Generics and Type Safety.
OOP Languages: Java vs C++
Java Implementation: Part 3 Software Construction Lecture 8.
Generalized Containers CSIS 3701: Advanced Object Oriented Programming.
Effective Java: Generics Last Updated: Spring 2009.
The Procedure Abstraction, Part VI: Inheritance in OOLs Comp 412 Copyright 2010, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled.
Self Type Constructors Atsushi Igarashi Kyoto University Joint work with Chieri Saito 1.
Generic Ownership for Generic Java Alex Potanin, Dave Clarke (CWI) James Noble, Robert Biddle (Carleton)
Ownership and Immutability in Generic Java (OIGJ) Yoav Zibin +, Alex Potanin * Paley Li *, Mahmood Ali ^, and Michael Ernst $ Presenter: Yossi Gil + +
Existential Quantification for Variant Ownership Nicholas Cameron Sophia Drossopoulou Imperial College London (Victoria University of Wellington)‏
Java 5 Part 1 CSE301 University of Sunderland Harry Erwin, PhD.
An Object-Oriented Approach to Programming Logic and Design Chapter 3 Using Methods and Parameters.
Dynamic Data Structures and Generics Chapter 10. Outline Vectors Linked Data Structures Introduction to Generics.
Types in programming languages1 What are types, and why do we need them?
Center for Software Sciences Northeastern University A domain specific language for Traversal Specification Johan Ovlinger Mitchell Wand Northeastern.
Lecture 4 Generic programming Advanced Java Programming 1 dr hab. Szymon Grabowski dr inż. Wojciech Bieniecki
SPL/2010 Synchronization 1. SPL/2010 Overview ● synchronization mechanisms in modern RTEs ● concurrency issues ● places where synchronization is needed.
Modularly Typesafe Interface Dispatch in JPred Christopher Frost and Todd Millstein University of California, Los Angeles
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 9 Inheritance and.
Object Oriented Programming
Polymorphism (generics) CSE 331 University of Washington.
Just Enough Type Theory or, Featherweight Java A Simple Formal Model of Objects Jonathan Aldrich
Application development with Java Lecture 21. Inheritance Subclasses Overriding Object class.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Types and Interfaces COMP.
Encoding Ownership Types in Java Nicholas Cameron James Noble Victoria University of Wellington, New Zealand.
Inherited Classes in Java CSCI 392 Ch 6 in O’Reilly Adapted from Dannelly.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Inheritance and Class Hierarchies Chapter 3. Chapter Objectives  To understand inheritance and how it facilitates code reuse  To understand how Java.
COMP 412, FALL Type Systems II C OMP 412 Rice University Houston, Texas Fall 2000 Copyright 2000, Robert Cartwright, all rights reserved. Students.
ENEE150 – 0102 ANDREW GOFFIN Abstract Data Types.
Java Bytecode Verification Types Chris Male, David J. Pearce, Alex Potanin and Constantine Dymnikov Victoria University of Wellington, New.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 10 Java Fundamentals Objects/ClassesMethods.
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
Java Programming: Guided Learning with Early Objects Chapter 9 Inheritance and Polymorphism.
Sections Inheritance and Abstract Classes
Nicholas Cameron James Noble Victoria University of Wellington
Module Road Map Refactoring Why Refactoring? Examples
Formal Models for Programming Languages
The Procedure Abstraction Part V: Run-time Structures for OOLs
Object and Reference Immutability using Java Generics
Object Encapsulation CSC 422 Dr. Spiegel.
Generics, Lambdas and Reflection
Presentation transcript:

Featherweight Generic Ownership Alex Potanin, James Noble Victoria University of Wellington Dave Clarke CWI, Netherlands Robert Biddle Carlton University 19/7/2005 Encapsulation Seminar TAU 2006 Presented by Ziv Haddad

Outline Introduction FGO formal model and Guarantees OGJ Implementation Conclusion

A Java implementation of a Map class public class Map { private Vector nodes; void put(Comparable key, Object value) { nodes.add(new Node(key, value)); } Object get(Comparable k) { Iterator i = nodes.iterator(); while (i.hasNext()) { Node mn = (Node) i.next(); if (((Comparable) mn.key).equals(k)) return mn.value; } return null; } class Node { public Object key; public Object value; Node(Object key, Object value) { this.key = key; this.value = value; }

A Generic implementation of a Map class public class Map { private Vector > nodes; void put(Key key, Value value) { nodes.add(new Node (key, value)); } Value get(Key k) { Iterator > I = nodes.iterator(); while (i.hasNext()) { Node mn = i.next(); if (mn.key.equals(k)) return mn.value; } return null; } class Node { public Key key; public Value value; Node(Key key, Value value) { this.key = key; this.value = value; }

An Ownership Types implementation of a Map class public class Map { private Vector nodes; void put(Comparable key, Object value) { nodes.add(new Node (key, value)); } Object get(Comparable key) { Iterator i = nodes.iterator(); while (i.hasNext()) { Node mn = (Node ) i.next(); if (mn.key.equals(key)) return mn.value; } return null; } class Node public Comparable key; public Object value; Node(Comparable key, Object value) { this.key = key; this.value = value; }

A combined generic and ownership types implementation of a Map class public class Map [Key extends Comparable,Value ] { private Vector [Nodes [Key,Value ]] nodes; void put(Key key, Value value) { nodes.add(new Node [Key, Value ](key, value)); } Value get(Key key) { Iterator [Nodes [Key,Value ]] i = nodes.iterator(); while(i.hasNext()) { Node [Key,Value ] mn = i.next(); if (mn.key.equals(k)) return mn.value; } return null; } class Node [Key extends Comparable,Value ] { public Key key; public Value value; Node(Key key, Value value) { this.key = key; this.value = value; }

Generic Ownership A new linguistic mechanism that combines genericity and ownership into a simple language Treats ownership as an additional kind of generic type information Existing generic type systems can be extended to carry ownership information with only minimal changes Ownership Generic Java (OGJ) – Implemented as an extension to Java 5

Generic Ownership Implementation of map class public class Map { private Vector,This> nodes; public void put(Key key, Value value) { nodes.add(new Node (key, value)); } public Value get(Key key) { Iterator, This> i= nodes.iterator(); while (i.hasNext()) { Node mn = i.next(); if (mn.key.equals(key)) return mn.value; } return null; } class Node<Key extends Comparable, Value, Owner extends World> { public Key key; public Value value; Node(Key key, Value value) { this.key = key; this.value = value; }

Featherweight (Generic) Java A minimal core calculus for modeling Java’s type systems The design of FJ favors compactness over completeness Supports only five forms of expressions: object creation, method invocation, field access, casting and variables Featherweight Generic java adds generic types for FJ

FJ – Program Example

FJ – Syntax, Subtyping, and Auxiliary functions

Formalizing Generic Ownership Generic Ownership is formalized as an imperative extension of Featherweight Generic Java Last type parameter is used to record an object’s owner All FGO classes descend from a new parameterized root Object

Another Example class m.Main extends Object { m.Main() { super(); } p.OwnedStack,World> public() { return new p.OwnedStack,World>; } p.OwnedStack,M> confined() { return new p.OwnedStack,M>; } p.OwnedStack,This> private() { return new p.OwnedStack,This>; }

Manifest Ownership Manifest Ownership allow classes without explicit owner type parameters A manifest FGO class owner is fixed (all objects) class PublicStack extends p.OwnedStack {} Manifest ownership allows us to fit existing FGJ classes into the FGO class hierarchy class Object extends Object {} class Stack extends Object {}

FGO Classes and Owner Classes

Different Kinds of Ownership FGO supports deep ownership In addition FGO also support static (package) ownership – via package owner classes. FGO can be adjusted to support shallow ownership instead of deep ownership

FGO Type System

Ownership syntax Auxiliary Functions

FGO Judgments

Owner Lookup In the case of a manifest class the owner is found by traversing the class hierarchy

this Function Replaces occurrences of This. Used extensively during the typing of FGO expressions, to enforce valid use of owner classes. There are two use case for the this function

Class PhoneBook { … void fill(PhoneBook otherPhoneBook) { … otherPhoneBook.addRecord(new Record (…)); … } this Function – First use Used during the validation of class declaration Every expression containing a method call or a field access is checked to see if any of the types involved contain This as an owner class. If they do then the method call or field access is only allowed on this.

this Function – Second use Used during reduction of FGO expressions. The permission P given to this is the current location l Any occurrence of class This is replaced by a more appropriate location-specific This l.

Subtyping and Well formedness Highlighted bit is essential for deep ownership. Intuition: class MyList, P> extends List - OK class MyList, World> extends List - NOT OK

Visibility Rules FGO contributes FGJ a set of visibility rules which define owner and type visibility

Class and Method Typing rules

Type Soundness Proof: Using structural induction on the reduction rules Proof: Based on all the possible expression types. The Type Soundness is immediate from the Preservation and Progress Theorem.

Ownership Invariance Proof: By induction on the depth of the subtype hierarchy. By FGO class typing rules a FGO class has the same owner parameter as its superclass

Deep Ownership Invariance Proof (Sketch): Consider a class C and a variable v:T in that class. Owner(T) can be one of the following: This, World one of the formal method parameters one of the owners of the type parameters of C This < Owner < World For each owner O of one of the type parameters: Owner <: O Formal method parameters are enforced in the same way as type parameters

OGJ Implementation Implemented as an extension to Java 5 compiler. The extension includes added ownership domains and FGO formal system constraints enforcement The compiler creates owner classes automatically and disposes them when type checking is complete. Owner classes: World, This, Package, Class To implement confinement the compiler replaces every occurrence of ownership domain name with the appropriate owner class

OGJ Implementation – cont The compiler ensures that only expressions referring to the current instance can access types whose owner is a This domain owner class The compiler ensure that ownership information cannot be lost. Only preserving ownership type-casts are allowd.

Future Work and Conclusion Contribution summary: Generic Ownership, FGO formal model, Ownership Generic Java Implementation Programs using GO are slightly more complex than programs using just generic types In the future authors plan to develop a set of design patterns for programmers whishing to make use of ownership in their programs

The End