Download - Sheep Cloning
![Page 1: Sheep Cloning](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/1.jpg)
1
SHEEP CLONING
Paley Li, Nicholas Cameron, and James Noble
![Page 2: Sheep Cloning](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/2.jpg)
2
Object cloning• How do you do object cloning?
![Page 3: Sheep Cloning](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/3.jpg)
3
Shallow cloning• Copies an object and alias the references in that object.
![Page 4: Sheep Cloning](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/4.jpg)
Shallow cloning
3
foo a
b
• Copies an object and alias the references in that object.
![Page 5: Sheep Cloning](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/5.jpg)
Shallow cloning
3
foo’
b
afoo
a
b
• Copies an object and alias the references in that object.
![Page 6: Sheep Cloning](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/6.jpg)
Deep cloning• Copies the object and its referenced objects.
4
![Page 7: Sheep Cloning](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/7.jpg)
Deep cloning
4
• Copies the object and its referenced objects.
foo a
b
![Page 8: Sheep Cloning](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/8.jpg)
Deep cloning• Copies the object and its referenced objects.
4
afoo
b
afoo’
b
![Page 9: Sheep Cloning](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/9.jpg)
- Shallow cloning is too shallow
9
displayWindow
5
scrollBar
![Page 10: Sheep Cloning](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/10.jpg)
- Shallow cloning is too shallow
10
displayWindow
5
scrollBar
displayWindow’
![Page 11: Sheep Cloning](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/11.jpg)
11
6
- Shallow cloning is too shallow
displayWindow displayWindow’
![Page 12: Sheep Cloning](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/12.jpg)
7
- Deep cloning is too deep
displayWindow
imageDatabase
![Page 13: Sheep Cloning](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/13.jpg)
7
- Deep cloning is too deep
displayWindow
imageDatabase
displayWindow’
imageDatabase’
![Page 14: Sheep Cloning](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/14.jpg)
8
- Deep cloning is too deep
displayWindow displayWindow’
![Page 15: Sheep Cloning](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/15.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/16.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/17.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/18.jpg)
• 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](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/19.jpg)
Ownership Types• Ownership types enforce a hierarchical topology over the
heap.
13
![Page 20: Sheep Cloning](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/20.jpg)
• 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](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/21.jpg)
• 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](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/22.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/23.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/24.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/25.jpg)
17
- Sheep cloning is just right!
displayWindow
![Page 26: Sheep Cloning](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/26.jpg)
17
- Sheep cloning is just right!
displayWindow displayWindow’
![Page 27: Sheep Cloning](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/27.jpg)
17
- Sheep cloning is just right!
displayWindow displayWindow’
![Page 28: Sheep Cloning](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/28.jpg)
17
- Sheep cloning is just right!
displayWindow displayWindow’
![Page 29: Sheep Cloning](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/29.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/30.jpg)
A touch of formal
19
![Page 31: Sheep Cloning](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/31.jpg)
A touch of formal
19
![Page 32: Sheep Cloning](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/32.jpg)
A touch of formal
19
![Page 33: Sheep Cloning](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/33.jpg)
A touch of formal
19
![Page 34: Sheep Cloning](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/34.jpg)
A touch of formal
19
![Page 35: Sheep Cloning](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/35.jpg)
A touch of formal
19
![Page 36: Sheep Cloning](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/36.jpg)
A touch of formal
19
![Page 37: Sheep Cloning](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/37.jpg)
A touch of formal
19
![Page 38: Sheep Cloning](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/38.jpg)
A touch of formal
19
![Page 39: Sheep Cloning](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/39.jpg)
A touch of formal
20
![Page 40: Sheep Cloning](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/40.jpg)
A touch of formal
21
![Page 41: Sheep Cloning](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/41.jpg)
A touch of formal
21
Original object
![Page 42: Sheep Cloning](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/42.jpg)
A touch of formal
21
Original object
![Page 43: Sheep Cloning](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/43.jpg)
A touch of formal
21
Original object
![Page 44: Sheep Cloning](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/44.jpg)
A touch of formal
21
Original heap
![Page 45: Sheep Cloning](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/45.jpg)
A touch of formal
21
Map
![Page 46: Sheep Cloning](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/46.jpg)
A touch of formal
21
Sheep clone
![Page 47: Sheep Cloning](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/47.jpg)
A touch of formal
21
New heap (containing the Sheep clone)
![Page 48: Sheep Cloning](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/48.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/49.jpg)
Can we clone it?
23
B
A
C
D
• Lets Sheep clone object A.
![Page 50: Sheep Cloning](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/50.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/51.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/52.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/53.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/54.jpg)
…. 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](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/55.jpg)
Proving the formalism
24
![Page 56: Sheep Cloning](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/56.jpg)
Proving the formalism
24
![Page 57: Sheep Cloning](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/57.jpg)
Proving the formalism
25
![Page 58: Sheep Cloning](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/58.jpg)
Proving the formalism
25
![Page 59: Sheep Cloning](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/59.jpg)
Proving the formalism
25
![Page 60: Sheep Cloning](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/60.jpg)
Proving the formalism
25
![Page 61: Sheep Cloning](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/61.jpg)
Correctness of the formalism
26
B
A
C
D
A’
B’C’
= AWhere:= A’
![Page 62: Sheep Cloning](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/62.jpg)
Correctness of the formalism
26
B
A
C
D
A’
B’C’
= AWhere:= A’
![Page 63: Sheep Cloning](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/63.jpg)
Correctness of the formalism
27
B
A
C
D
A’
B’C’
![Page 64: Sheep Cloning](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/64.jpg)
Correctness of the formalism
27
B
A
C
D
A’
B’C’
![Page 65: Sheep Cloning](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/65.jpg)
Correctness of the formalism
27
B
A
C
D
A’
B’C’
![Page 66: Sheep Cloning](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/66.jpg)
Correctness of the formalism
28
B
A
C
D
A’
B’C’
![Page 67: Sheep Cloning](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/67.jpg)
Correctness of the formalism
28
B
A
C
D
A’
B’C’
A’’ A’
![Page 68: Sheep Cloning](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/68.jpg)
Correctness of the formalism
28
B
A
C
D
A’
B’C’
B’ A’, C’’ A’
![Page 69: Sheep Cloning](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/69.jpg)
Correctness of the formalism
29
B
A
C
D
A’
B’C’
A ’ D
![Page 70: Sheep Cloning](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/70.jpg)
Correctness of the formalism
29
B
A
C
D
A’
B’C’
A’ D
![Page 71: Sheep Cloning](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/71.jpg)
Correctness of the formalism
30
B
A
C
A’
B’C’
D
![Page 72: Sheep Cloning](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/72.jpg)
Correctness of the formalism
30
B
A
C
A’
B’C’
A ’ D
D
![Page 73: Sheep Cloning](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/73.jpg)
Correctness of the formalism
31
B
A
C
D
A’
B’C’
A’ ’ D
![Page 74: Sheep Cloning](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/74.jpg)
Correctness of the formalism
31
B
A
C
A’
B’C’
D
A’ ’ D
![Page 75: Sheep Cloning](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/75.jpg)
Correctness of the formalism
32
B
A
C
D
A’
B’C’
![Page 76: Sheep Cloning](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/76.jpg)
Correctness of the formalism
32
B
A
C
D
A’
B’C’
![Page 77: Sheep Cloning](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/77.jpg)
Correctness of the formalism
32
B
A
C
D
A’
B’C’
![Page 78: Sheep Cloning](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/78.jpg)
Summary• Shallow is too shallow.• Deep is too deep.• Sheep = shallow + deep.• Formalised sheep cloning.• Proved soundness and correctness.
33
![Page 79: Sheep Cloning](https://reader036.vdocument.in/reader036/viewer/2022062310/56815f01550346895dcdbee1/html5/thumbnails/79.jpg)
Thank you.
Questions?
34