sheep cloning
play

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


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

  2. 2 Object cloning • How do you do object cloning?

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

  4. 3 Shallow cloning • Copies an object and alias the references in that object. foo a b

  5. 3 Shallow cloning • Copies an object and alias the references in that object. foo ’ foo a a b b

  6. 4 Deep cloning • Copies the object and its referenced objects.

  7. 4 Deep cloning • Copies the object and its referenced objects. foo a b

  8. 4 Deep cloning • Copies the object and its referenced objects. foo ’ foo a a b b

  9. 5 - Shallow cloning is too shallow displayWindow scrollBar 9

  10. 5 - Shallow cloning is too shallow displayWindow ’ displayWindow scrollBar 10

  11. 6 - Shallow cloning is too shallow displayWindow ’ displayWindow 11

  12. 7 - Deep cloning is too deep displayWindow imageDatabase

  13. 7 - Deep cloning is too deep displayWindow ’ displayWindow imageDatabase’ imageDatabase

  14. 8 - Deep cloning is too deep displayWindow ’ displayWindow

  15. 9 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.

  16. 10 Common practices • Cloning in C++ : • Copy constructors and assignment operators. • Cloning in Eiffel : • Inherit shallow and deep cloning from the ANY class.

  17. 11 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?

  18. 12 - The ideal model • 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. • O nly copy those “important” areas.

  19. 13 Ownership Types • Ownership types enforce a hierarchical topology over the heap.

  20. 14 Ownership Types • Context is the formal set of objects owned by an object. • Representation is the set of objects which are conceptually part of an object.

  21. 14 Ownership Types • Context is the formal set of objects owned by an object. • Representation is the set of objects which are conceptually part of an object. Representation = context =

  22. 15 Deep Ownership • All reference paths to an object must pass through that object’s owner. • Also known as owners-as-dominators. X X

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

  24. 16 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.

  25. 17 - Sheep cloning is just right! displayWindow

  26. 17 - Sheep cloning is just right! displayWindow ’ displayWindow

  27. 17 - Sheep cloning is just right! displayWindow ’ displayWindow

  28. 17 - Sheep cloning is just right! displayWindow ’ displayWindow

  29. 18 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.

  30. 19 A touch of formal

  31. 19 A touch of formal

  32. 19 A touch of formal

  33. 19 A touch of formal

  34. 19 A touch of formal

  35. 19 A touch of formal

  36. 19 A touch of formal

  37. 19 A touch of formal

  38. 19 A touch of formal

  39. 20 A touch of formal

  40. 21 A touch of formal

  41. 21 A touch of formal Original object

  42. 21 A touch of formal Original object

  43. 21 A touch of formal Original object

  44. 21 A touch of formal Original heap

  45. 21 A touch of formal Map

  46. 21 A touch of formal Sheep clone

  47. 21 A touch of formal New heap (containing the Sheep clone)

  48. 22 A touch of formal • 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.

  49. 23 Can we clone it? • Lets Sheep clone object A. D A C B

  50. 23 Can we clone it? • R-SheepInside creates the object A ’ by copying A. D A ’ A C B Map: A A ’

  51. 23 Can we clone it? • R-SheepOutside creates an alias to D. D A ’ A C B Map: A A ’ D D

  52. 23 Can we clone it? • R-SheepInside creates the object B ’ by copying B. D A ’ A C B ’ B Map: A A ’ D D B B ’

  53. 23 Can we clone it? • R-SheepInside creates the object C ’ by copying C. D A ’ A C ’ C B ’ B Map: A A ’ D D B B ’ C C ’

  54. 23 …. Yes we can! • R-SheepRef creates the reference from object C ’ to object B ’ using the map. D A ’ A C ’ C B ’ B Map: A A ’ D D B B ’ C C ’

  55. 24 Proving the formalism

  56. 24 Proving the formalism

  57. 25 Proving the formalism

  58. 25 Proving the formalism

  59. 25 Proving the formalism

  60. 25 Proving the formalism

  61. 26 Correctness of the formalism Where: = A = A ’ D A ’ A C ’ C B ’ B

  62. 26 Correctness of the formalism Where: = A = A ’ D A ’ A C ’ C B ’ B

  63. 27 Correctness of the formalism D A ’ A C ’ C B ’ B

  64. 27 Correctness of the formalism D A ’ A C ’ C B ’ B

  65. 27 Correctness of the formalism D A ’ A C ’ C B ’ B

  66. 28 Correctness of the formalism D A ’ A C ’ C B ’ B

  67. 28 Correctness of the formalism A ’ ’ A ’ D A ’ A C ’ C B ’ B

  68. 28 Correctness of the formalism B ’ A ’ , C ’ ’ A ’ D A ’ A C ’ C B ’ B

  69. 29 Correctness of the formalism A ’ D D A ’ A C ’ C B ’ B

  70. 29 Correctness of the formalism A ’ D D A ’ A C ’ C B ’ B

  71. 30 Correctness of the formalism D A ’ A C ’ C B ’ B

  72. 30 Correctness of the formalism A ’ D D A ’ A C ’ C B ’ B

  73. 31 Correctness of the formalism A ’ ’ D D A ’ A C ’ C B ’ B

  74. 31 Correctness of the formalism A ’ ’ D D A ’ A C ’ C B ’ B

  75. 32 Correctness of the formalism D A ’ A C ’ C B ’ B

  76. 32 Correctness of the formalism D A ’ A C ’ C B ’ B

  77. 32 Correctness of the formalism D A ’ A C ’ C B ’ B

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

  79. 34 Thank you. Questions?

Recommend


More recommend