sheep cloning

79
SHEEP CLONING Paley Li, Nicholas Cameron, and James Noble 1

Upload: ossie

Post on 15-Feb-2016

73 views

Category:

Documents


0 download

DESCRIPTION

Sheep Cloning. Paley Li, Nicholas Cameron, and James Noble. Object cloning. How do you do object cloning?. Shallow cloning. Copies an object and alias the references in that object. Shallow cloning. Copies an object and alias the references in that object. foo . a. b. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Sheep Cloning

1

SHEEP CLONING

Paley Li, Nicholas Cameron, and James Noble

Page 2: Sheep Cloning

2

Object cloning• How do you do object cloning?

Page 3: Sheep Cloning

3

Shallow cloning• Copies an object and alias the references in that object.

Page 4: Sheep Cloning

Shallow cloning

3

foo a

b

• Copies an object and alias the references in that object.

Page 5: Sheep Cloning

Shallow cloning

3

foo’

b

afoo

a

b

• Copies an object and alias the references in that object.

Page 6: Sheep Cloning

Deep cloning• Copies the object and its referenced objects.

4

Page 7: Sheep Cloning

Deep cloning

4

• Copies the object and its referenced objects.

foo a

b

Page 8: Sheep Cloning

Deep cloning• Copies the object and its referenced objects.

4

afoo

b

afoo’

b

Page 9: Sheep Cloning

- Shallow cloning is too shallow

9

displayWindow

5

scrollBar

Page 10: Sheep Cloning

- Shallow cloning is too shallow

10

displayWindow

5

scrollBar

displayWindow’

Page 11: Sheep Cloning

11

6

- Shallow cloning is too shallow

displayWindow displayWindow’

Page 12: Sheep Cloning

7

- Deep cloning is too deep

displayWindow

imageDatabase

Page 13: Sheep Cloning

7

- Deep cloning is too deep

displayWindow

imageDatabase

displayWindow’

imageDatabase’

Page 14: Sheep Cloning

8

- Deep cloning is too deep

displayWindow displayWindow’

Page 15: Sheep Cloning

Common practices• Cloning in Java (Cloneable) and C# (ICloneable):

• Default clone() method is shallow. • Defining deep cloning is inconvenient and prone to bugs.• Requires type casting.

9

Page 16: Sheep Cloning

Common practices

10

• Cloning in C++ :• Copy constructors and assignment operators.

• Cloning in Eiffel :• Inherit shallow and deep cloning from the

ANY class.

Page 17: Sheep Cloning

Common practices • Most practices still suffer from the flaws of shallow and

deep cloning.• Not automated.

• “Programmer knows best” - they have to define their own cloning.• What if we have the information to produce more sensible

clones, but had overlooked it?

11

Page 18: Sheep Cloning

• We aim to formalise a cloning model that is just right. • It needs to be able to identify areas that are “important” to

an object. • Only copy those “important” areas.

12

- The ideal model

Page 19: Sheep Cloning

Ownership Types• Ownership types enforce a hierarchical topology over the

heap.

13

Page 20: Sheep Cloning

• Context is the formal set of objects owned by an object.• Representation is the set of objects which are

conceptually part of an object.

14

Ownership Types

Page 21: Sheep Cloning

• Context is the formal set of objects owned by an object.• Representation is the set of objects which are

conceptually part of an object.

14

Ownership Types

Representation = context =

Page 22: Sheep Cloning

Deep Ownership

15

• All reference paths to an object must pass through that object’s owner.

• Also known as owners-as-dominators.

X

X

Page 23: Sheep Cloning

Deep Ownership

15

• All reference paths to an object must pass through that object’s owner.

• Also known as owners-as-dominators.

Page 24: Sheep Cloning

Sheep = Shallow + Deep• Utilises ownership types to identify the “important bits” of

each object.• Cloning an object’s representation:

• Copies every object inside the object’s context. • Aliases every reference to objects outside the object’s context.

16

Page 25: Sheep Cloning

17

- Sheep cloning is just right!

displayWindow

Page 26: Sheep Cloning

17

- Sheep cloning is just right!

displayWindow displayWindow’

Page 27: Sheep Cloning

17

- Sheep cloning is just right!

displayWindow displayWindow’

Page 28: Sheep Cloning

17

- Sheep cloning is just right!

displayWindow displayWindow’

Page 29: Sheep Cloning

Sheep cloning• We have formalised sheep cloning in an ownership

system with deep ownership.• We have proved soundness and an assortment of

correctness property of our formalism.

18

Page 30: Sheep Cloning

A touch of formal

19

Page 31: Sheep Cloning

A touch of formal

19

Page 32: Sheep Cloning

A touch of formal

19

Page 33: Sheep Cloning

A touch of formal

19

Page 34: Sheep Cloning

A touch of formal

19

Page 35: Sheep Cloning

A touch of formal

19

Page 36: Sheep Cloning

A touch of formal

19

Page 37: Sheep Cloning

A touch of formal

19

Page 38: Sheep Cloning

A touch of formal

19

Page 39: Sheep Cloning

A touch of formal

20

Page 40: Sheep Cloning

A touch of formal

21

Page 41: Sheep Cloning

A touch of formal

21

Original object

Page 42: Sheep Cloning

A touch of formal

21

Original object

Page 43: Sheep Cloning

A touch of formal

21

Original object

Page 44: Sheep Cloning

A touch of formal

21

Original heap

Page 45: Sheep Cloning

A touch of formal

21

Map

Page 46: Sheep Cloning

A touch of formal

21

Sheep clone

Page 47: Sheep Cloning

A touch of formal

21

New heap (containing the Sheep clone)

Page 48: Sheep Cloning

A touch of formal

22

• SheepAux function:• R-SheepInside: Copies the object if it is inside the original

object.

• R-SheepOutside: Creates an alias to the object if the object is outside the original object.

• R-SheepRef: Creates a reference to an existing Sheep clone of an object using the Map.

• R-SheepNull: Returns a null, when Sheep cloning a null.

Page 49: Sheep Cloning

Can we clone it?

23

B

A

C

D

• Lets Sheep clone object A.

Page 50: Sheep Cloning

Can we clone it?

23

• R-SheepInside creates the object A’ by copying A.

B

A

C

D

A’

Map: A A’

Page 51: Sheep Cloning

Can we clone it?

23

• R-SheepOutside creates an alias to D.

B

A

C

D

A’

Map: A A’ D D

Page 52: Sheep Cloning

Can we clone it?

23

• R-SheepInside creates the object B’ by copying B.

B

A

C

D

A’

Map: A A’ D D B B’

B’

Page 53: Sheep Cloning

Can we clone it?

23

• R-SheepInside creates the object C’ by copying C.

B

A

C

D

A’

B’C’

Map: A A’ D D B B’ C C’

Page 54: Sheep Cloning

…. Yes we can!

23

• R-SheepRef creates the reference from object C’ to object B’ using the map.

B

A

C

D

A’

B’C’

Map: A A’ D D B B’ C C’

Page 55: Sheep Cloning

Proving the formalism

24

Page 56: Sheep Cloning

Proving the formalism

24

Page 57: Sheep Cloning

Proving the formalism

25

Page 58: Sheep Cloning

Proving the formalism

25

Page 59: Sheep Cloning

Proving the formalism

25

Page 60: Sheep Cloning

Proving the formalism

25

Page 61: Sheep Cloning

Correctness of the formalism

26

B

A

C

D

A’

B’C’

= AWhere:= A’

Page 62: Sheep Cloning

Correctness of the formalism

26

B

A

C

D

A’

B’C’

= AWhere:= A’

Page 63: Sheep Cloning

Correctness of the formalism

27

B

A

C

D

A’

B’C’

Page 64: Sheep Cloning

Correctness of the formalism

27

B

A

C

D

A’

B’C’

Page 65: Sheep Cloning

Correctness of the formalism

27

B

A

C

D

A’

B’C’

Page 66: Sheep Cloning

Correctness of the formalism

28

B

A

C

D

A’

B’C’

Page 67: Sheep Cloning

Correctness of the formalism

28

B

A

C

D

A’

B’C’

A’’ A’

Page 68: Sheep Cloning

Correctness of the formalism

28

B

A

C

D

A’

B’C’

B’ A’, C’’ A’

Page 69: Sheep Cloning

Correctness of the formalism

29

B

A

C

D

A’

B’C’

A ’ D

Page 70: Sheep Cloning

Correctness of the formalism

29

B

A

C

D

A’

B’C’

A’ D

Page 71: Sheep Cloning

Correctness of the formalism

30

B

A

C

A’

B’C’

D

Page 72: Sheep Cloning

Correctness of the formalism

30

B

A

C

A’

B’C’

A ’ D

D

Page 73: Sheep Cloning

Correctness of the formalism

31

B

A

C

D

A’

B’C’

A’ ’ D

Page 74: Sheep Cloning

Correctness of the formalism

31

B

A

C

A’

B’C’

D

A’ ’ D

Page 75: Sheep Cloning

Correctness of the formalism

32

B

A

C

D

A’

B’C’

Page 76: Sheep Cloning

Correctness of the formalism

32

B

A

C

D

A’

B’C’

Page 77: Sheep Cloning

Correctness of the formalism

32

B

A

C

D

A’

B’C’

Page 78: Sheep Cloning

Summary• Shallow is too shallow.• Deep is too deep.• Sheep = shallow + deep.• Formalised sheep cloning.• Proved soundness and correctness.

33

Page 79: Sheep Cloning

Thank you.

Questions?

34