SHEEP CLONING Paley Li, Nicholas Cameron, and James Noble 2 Object - - PowerPoint PPT Presentation

sheep cloning
SMART_READER_LITE
LIVE PREVIEW

SHEEP CLONING Paley Li, Nicholas Cameron, and James Noble 2 Object - - PowerPoint PPT Presentation

1 SHEEP CLONING Paley Li, Nicholas Cameron, and James Noble 2 Object cloning How do you do object cloning? 3 Shallow cloning Copies an object and alias the references in that object. 3 Shallow cloning Copies an object and alias


slide-1
SLIDE 1

SHEEP CLONING

Paley Li, Nicholas Cameron, and James Noble

1

slide-2
SLIDE 2

Object cloning

  • How do you do object cloning?

2

slide-3
SLIDE 3

Shallow cloning

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

3

slide-4
SLIDE 4

Shallow cloning

3

foo a b

  • Copies an object and alias the references in that object.
slide-5
SLIDE 5

Shallow cloning

3

foo’ b a foo a b

  • Copies an object and alias the references in that object.
slide-6
SLIDE 6

Deep cloning

  • Copies the object and its referenced objects.

4

slide-7
SLIDE 7

Deep cloning

4

  • Copies the object and its referenced objects.

foo a b

slide-8
SLIDE 8

Deep cloning

  • Copies the object and its referenced objects.

4

a foo b a foo’ b

slide-9
SLIDE 9
  • Shallow cloning is too shallow

9

displayWindow

5

scrollBar

slide-10
SLIDE 10
  • Shallow cloning is too shallow

10

displayWindow

5

scrollBar displayWindow’

slide-11
SLIDE 11

11 6

  • Shallow cloning is too shallow

displayWindow displayWindow’

slide-12
SLIDE 12

7

  • Deep cloning is too deep

displayWindow imageDatabase

slide-13
SLIDE 13

7

  • Deep cloning is too deep

displayWindow imageDatabase displayWindow’ imageDatabase’

slide-14
SLIDE 14

8

  • Deep cloning is too deep

displayWindow displayWindow’

slide-15
SLIDE 15

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

slide-16
SLIDE 16

Common practices

10

  • Cloning in C++ :
  • Copy constructors and assignment operators.
  • Cloning in Eiffel :
  • Inherit shallow and deep cloning from the

ANY class.

slide-17
SLIDE 17

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

slide-18
SLIDE 18
  • 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
slide-19
SLIDE 19

Ownership Types

  • Ownership types enforce a hierarchical topology over the

heap.

13

slide-20
SLIDE 20
  • 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

slide-21
SLIDE 21
  • 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 =

slide-22
SLIDE 22

Deep Ownership

15

  • All reference paths to an object must pass through that
  • bject’s owner.
  • Also known as owners-as-dominators.

X X

slide-23
SLIDE 23

Deep Ownership

15

  • All reference paths to an object must pass through that
  • bject’s owner.
  • Also known as owners-as-dominators.
slide-24
SLIDE 24

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

slide-25
SLIDE 25

17

  • Sheep cloning is just right!

displayWindow

slide-26
SLIDE 26

17

  • Sheep cloning is just right!

displayWindow displayWindow’

slide-27
SLIDE 27

17

  • Sheep cloning is just right!

displayWindow displayWindow’

slide-28
SLIDE 28

17

  • Sheep cloning is just right!

displayWindow displayWindow’

slide-29
SLIDE 29

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

slide-30
SLIDE 30

A touch of formal

19

slide-31
SLIDE 31

A touch of formal

19

slide-32
SLIDE 32

A touch of formal

19

slide-33
SLIDE 33

A touch of formal

19

slide-34
SLIDE 34

A touch of formal

19

slide-35
SLIDE 35

A touch of formal

19

slide-36
SLIDE 36

A touch of formal

19

slide-37
SLIDE 37

A touch of formal

19

slide-38
SLIDE 38

A touch of formal

19

slide-39
SLIDE 39

A touch of formal

20

slide-40
SLIDE 40

A touch of formal

21

slide-41
SLIDE 41

A touch of formal

21

Original object

slide-42
SLIDE 42

A touch of formal

21

Original object

slide-43
SLIDE 43

A touch of formal

21

Original object

slide-44
SLIDE 44

A touch of formal

21

Original heap

slide-45
SLIDE 45

A touch of formal

21

Map

slide-46
SLIDE 46

A touch of formal

21

Sheep clone

slide-47
SLIDE 47

A touch of formal

21

New heap (containing the Sheep clone)

slide-48
SLIDE 48

A touch of formal

22

  • SheepAux function:
  • R-SheepInside: Copies the object if it is inside the original
  • bject.
  • R-SheepOutside: Creates an alias to the object if the object is
  • utside the original object.
  • R-SheepRef: Creates a reference to an existing Sheep clone of an
  • bject using the Map.
  • R-SheepNull: Returns a null, when Sheep cloning a null.
slide-49
SLIDE 49

Can we clone it?

23

B A C D

  • Lets Sheep clone object A.
slide-50
SLIDE 50

Can we clone it?

23

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

B A C D A’ Map: A A’

slide-51
SLIDE 51

Can we clone it?

23

  • R-SheepOutside creates an alias to D.

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

slide-52
SLIDE 52

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’

slide-53
SLIDE 53

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’

slide-54
SLIDE 54

…. Yes we can!

23

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

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

slide-55
SLIDE 55

Proving the formalism

24

slide-56
SLIDE 56

Proving the formalism

24

slide-57
SLIDE 57

Proving the formalism

25

slide-58
SLIDE 58

Proving the formalism

25

slide-59
SLIDE 59

Proving the formalism

25

slide-60
SLIDE 60

Proving the formalism

25

slide-61
SLIDE 61

Correctness of the formalism

26

B A C D A’ B’ C’ = A Where: = A’

slide-62
SLIDE 62

Correctness of the formalism

26

B A C D A’ B’ C’ = A Where: = A’

slide-63
SLIDE 63

Correctness of the formalism

27

B A C D A’ B’ C’

slide-64
SLIDE 64

Correctness of the formalism

27

B A C D A’ B’ C’

slide-65
SLIDE 65

Correctness of the formalism

27

B A C D A’ B’ C’

slide-66
SLIDE 66

Correctness of the formalism

28

B A C D A’ B’ C’

slide-67
SLIDE 67

Correctness of the formalism

28

B A C D A’ B’ C’ A’’ A’

slide-68
SLIDE 68

Correctness of the formalism

28

B A C D A’ B’ C’ B’ A’, C’’ A’

slide-69
SLIDE 69

Correctness of the formalism

29

B A C D A’ B’ C’ A ’ D

slide-70
SLIDE 70

Correctness of the formalism

29

B A C D A’ B’ C’ A’ D

slide-71
SLIDE 71

Correctness of the formalism

30

B A C A’ B’ C’ D

slide-72
SLIDE 72

Correctness of the formalism

30

B A C A’ B’ C’ A ’ D D

slide-73
SLIDE 73

Correctness of the formalism

31

B A C D A’ B’ C’ A’ ’ D

slide-74
SLIDE 74

Correctness of the formalism

31

B A C A’ B’ C’ D A’ ’ D

slide-75
SLIDE 75

Correctness of the formalism

32

B A C D A’ B’ C’

slide-76
SLIDE 76

Correctness of the formalism

32

B A C D A’ B’ C’

slide-77
SLIDE 77

Correctness of the formalism

32

B A C D A’ B’ C’

slide-78
SLIDE 78

Summary

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

33

slide-79
SLIDE 79

Thank you. Questions?

34