1 / 79

Sheep Cloning

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.

ossie
Download Presentation

Sheep Cloning

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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.

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

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

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

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

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

  9. 5 - Shallow cloning is too shallow scrollBar displayWindow

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

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

  12. - Deep cloning is too deep imageDatabase displayWindow

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

  14. - Deep cloning is too deep displayWindow displayWindow’

  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.

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

  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?

  18. - 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. • Only copy those “important” areas.

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

  20. 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. 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. Deep Ownership • All reference paths to an object must pass through that object’s owner. • Also known as owners-as-dominators. X X

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

  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.

  25. - Sheep cloning is just right! displayWindow

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

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

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

  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.

  30. A touch of formal

  31. A touch of formal

  32. A touch of formal

  33. A touch of formal

  34. A touch of formal

  35. A touch of formal

  36. A touch of formal

  37. A touch of formal

  38. A touch of formal

  39. A touch of formal

  40. A touch of formal

  41. A touch of formal Original object

  42. A touch of formal Original object

  43. A touch of formal Original object

  44. A touch of formal Original heap

  45. A touch of formal Map

  46. A touch of formal Sheep clone

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

  48. 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. Can we clone it? • Lets Sheep clone object A. A B D C

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

More Related