Multiple Ownership Nicholas Cameron Sophia Drossopoulou James Noble Matthew Smith.

Post on 17-Jan-2016

215 views 0 download

Tags:

Transcript of Multiple Ownership Nicholas Cameron Sophia Drossopoulou James Noble Matthew Smith.

Multiple Ownership

Nicholas CameronSophia Drossopoulou

James NobleMatthew Smith

ncameron@doc.ic.ac.uk 2

• Background – Ownership Types

• Multiple Ownership• Objects in Boxes• Variance - ?• MOJO

• Effects

ncameron@doc.ic.ac.uk 3

Background

ncameron@doc.ic.ac.uk 4

Ownership Types

• The heap is messy:

ncameron@doc.ic.ac.uk 5

Ownership Types

• Organise it:

ncameron@doc.ic.ac.uk 6

Ownership Types

• Give each object an owner:

ncameron@doc.ic.ac.uk 7

Ownership Types

class Project<o> { Task<this> t1; Task<this> t2; List<this, o> clients;}

ncameron@doc.ic.ac.uk 8

Our Work

ncameron@doc.ic.ac.uk 9

The Objects In Boxes Model

ncameron@doc.ic.ac.uk 10

A Box is a Set of Objects

ncameron@doc.ic.ac.uk 11

Objects in Boxes

• Single owner interpretation:

• An object is in its owner’s box

ncameron@doc.ic.ac.uk 12

Programs are not Trees

ncameron@doc.ic.ac.uk 13

One Owner is not Enough

• 75% of ownership structures require multiple ownership• [34] Mitchell, ECOOP, ’06

• Trees can not describe non-hierarchical structures

ncameron@doc.ic.ac.uk 14

Objects in Boxes

• Multiple Ownership: objects may be in more than one box

• An object with multiple owners is in the intersection of their boxes:

ncameron@doc.ic.ac.uk 15

Objects in Boxes

ncameron@doc.ic.ac.uk 16

A Descriptive System

• Describes the heap• Does not restrict

references etc.

ncameron@doc.ic.ac.uk 17

MOJO

ncameron@doc.ic.ac.uk 18

MOJO

• Class declarations have the usual, formal ownership parameters:

class C<o, d> …

ncameron@doc.ic.ac.uk 19

MOJO

• Class declarations have the usual, formal ownership parameters:

class C<o, d> …• Types may have multiple corresponding

actual owner parameters:

C<b, c>

ncameron@doc.ic.ac.uk 20

MOJO

• Class declarations have the usual, formal ownership parameters:

class C<o, d> …• Types may have multiple corresponding

actual owner parameters:

C<b, c>

C<a & b, c >

ncameron@doc.ic.ac.uk 21

MOJO

• Class declarations have the usual, formal ownership parameters:

class C<o, d> …• Types may have multiple corresponding

actual owner parameters:

C<b, c>

C<a & b, c >

C<a & b & ?, c & a>

ncameron@doc.ic.ac.uk 22

MOJO

class Connection<o> { … }

class Client<o, s> { Connection<this & s> c;}

class Server<o> { Connection<this & ?> c;}

ncameron@doc.ic.ac.uk 23

Variance

ncameron@doc.ic.ac.uk 24

Variance

• Connection<this & ?>• Some owner

ncameron@doc.ic.ac.uk 25

Variance

• Connection<this & ?>• Some box

• May be the intersection of several boxes

• Variance in the number of owners

ncameron@doc.ic.ac.uk 26

Subtyping

• Subtyping with wildcards is variant with respect to owners:

C<a> <: C<?>

ncameron@doc.ic.ac.uk 27

Subtyping

• Subtyping with wildcards is variant with respect to owners:

C<a> <: C<?>

C<a> <: C<a & ?>

ncameron@doc.ic.ac.uk 28

Subtyping

• Subtyping with wildcards is variant with respect to owners:

C<a> <: C<?>

C<a> <: C<a & ?>

C<a & b & ?> <: C<a & ?>

ncameron@doc.ic.ac.uk 29

Subtyping

• Subtyping with wildcards is variant with respect to owners:

C<a> <: C<?>

C<a> <: C<a & ?>

C<a & b & ?> <: C<a & ?>

C<?> </: C<a>

C<a> </: C<a & b>

ncameron@doc.ic.ac.uk 30

Constraints

class C<a, b, c> a intersects b, b disjoint c{ … }

ncameron@doc.ic.ac.uk 31

Constraintsclass D<a, b> a intersects b { D<a, b>

}

class E<a, b> a disjoint b { }

ncameron@doc.ic.ac.uk 32

Constraintsclass D<a, b> a intersects b { D<a, b> }

class E<a, b> a disjoint b { D<a, b> }

ncameron@doc.ic.ac.uk 33

Constraintsclass D<a, b> a intersects b { D<a, b> Object<a & b> }

class E<a, b> a disjoint b { D<a, b> }

ncameron@doc.ic.ac.uk 34

Typing - strict

• Strict method sends and assignments to deal with variance of owners:class C<o> { C<o> f;}

C<a> ca; C<a & ?> c1; C<a & ?> c2;

ca.f = ca;

ncameron@doc.ic.ac.uk 35

Typing - strict

• Strict method sends and assignments to deal with variance of owners:class C<o> { C<o> f;}

C<a> ca; C<a & ?> c1; C<a & ?> c2;

ca.f = ca; c1.f = c2;

ncameron@doc.ic.ac.uk 36

Typing - strict

ncameron@doc.ic.ac.uk 37

Effects

ncameron@doc.ic.ac.uk 38

Effects

ncameron@doc.ic.ac.uk 39

Effects

Task<x> t1;Task<y> t2;…t1.f; // reads x / writes ε

ncameron@doc.ic.ac.uk 40

Effects

Task<x> t1;Task<y> t2;…t1.f; // reads x / writes εt1.f = t2.f; // reads x,y / writes x

ncameron@doc.ic.ac.uk 41

Effects with Multiple Owners

Task<x & ?> t1;Task<y & z> t2;…t1.f; // reads x & ? / writes ε

ncameron@doc.ic.ac.uk 42

Effects with Multiple Owners

Task<x & ?> t1;Task<y & z> t2;…t1.f; // reads x & ? / writes εt1.f = t2.f; // reads x & ?,y & z/ writes x & ?

ncameron@doc.ic.ac.uk 43

Effects with Multiple Ownerst1.f = t2.f; // reads x & ?,y & z/ writes x & ?

ncameron@doc.ic.ac.uk 44

Disjointness

• Two expressions are disjoint if their effects do not overlap

• Complicated by ? – but & = intersection

ncameron@doc.ic.ac.uk 45

Future Work

ncameron@doc.ic.ac.uk 46

Future Work

• Explore variant owners using existential types

class TaskList<o, d> { Task<d & ?> datum; TaskList<o, d> next;}

ncameron@doc.ic.ac.uk 47

Future Work

• Reference and modification control

ncameron@doc.ic.ac.uk 48

Future Work

• Constraints• Topology - inside• Unary - may read, may write• Binary – may point to, may modify

ncameron@doc.ic.ac.uk 49

Summary

• Ownership Types• Multiple Ownership

• Objects in Boxes• Variance• MOJO

• Effects

• Thank you!• Any questions?