Presentation on theme: "(Chapter 5) Deleting Objects"— Presentation transcript:
1(Chapter 5) Deleting Objects DC3: More on Naming(Chapter 5)Deleting Objects
2Topics Distributed garbage collection Centralized Solutions Skeletons and ProxiesUnreferenced and UnreachableCentralized SolutionsMark and SweepReference CountingDistributed GCDistributed reference countingAdvanced reference countingGeneration reference counting
3Removing Objects no Longer Needed Called Distributed Garbage CollectionMany languages (Java) and distributed middleware systems provide for the recycling of memory objects that are no longer referenced.Use terminology of Java RMI with skeletons and proxies.
4The Problem of Unreferenced Objects An example of a graph representing objects containing references to each other.
5Garbage – Unreferenced Memory int * p1; int * p2;p1 = new int;p1p1
6Garbage – Unreachable Objects Unneeded memory not referenced by objects currently active in the programp2p1p3
7Garbage Collection in a Centralized System – Mark and Sweep Simple solution: stop allocation of new objects and deallocation.Mark all objects as unreferencedGo through all pointers and mark referenced objects as referenced.Delete unreferenced objects and resume processing.Works if all objects and references are on the same machine, but time consuming.
8Mark all objects as unreferenced Mark and Sweep - 1Mark all objects as unreferencedp2p4p5p1p3
9Go through program and unmark referenced objects Mark and Sweep - 2Go through program and unmark referenced objectsp2p4p5p1p3
10Delete unreferenced objects Mark and Sweep - 3Delete unreferenced objectsp4p5p1
11A Little More Efficient Reference Counting (not distributed)The object maintains a reference counter.When an object is created with a reference pointer, its reference counter is set to one.Reference counter is increased or decreased as additional pointers are created or removed.If the reference counter (RC) goes to zero, the object is GC’ed.Problem with scheme: unreachable objects referencing each other.
12Distributed Garbage Collection In DS the objects and pointers may be on different machines. Difficult to stop processing on one machine, let alone a DS.Proxies and skeletons: When a distributed object is created, a skeleton is created for it. When it is referenced, a proxy is created at the client machine (referencer) to talk to the skeleton at the object site.
14Distributed Reference Counting(1) Where are the reference counters maintained? How to increase and decrease RC from a remote proxy?Solution: The object skeleton will maintain the RC. Messages to the RC must be protected against duplication or loss.
15Distributed Reference Counting (2) The problem of maintaining a proper reference count in the presence of unreliable communication.
16Reference Counting (3)+1(a) Copying a reference to another process and incrementing the counter too late.(b) A solution, but increased message traffic.
17Advanced Reference Counting (1) Idea: Eliminate race between increase and decrease messages by having only messages which decrease the count.Also, make it possible to copy references without communicating with object. This has advantages and disadvantages.
18Advanced Reference Counting (2) 1. When object O is created, it has a TOTAL WEIGHT, TW and PARTIAL WEIGHT, PW. Initially TW = PW = 2^N = 2N.2. When a reference is created half the PW of the object (TW and PW are stored at the skeleton) is assigned to the proxy at process P1.3. If a remote reference is duplicated, half the PW at P1 is passed to P2. (skeleton is not aware of this).4. If remote reference is passed to P2, P2 gets all of the PW. Again, object O doesn’t need to know.5. When reference is destroyed, message is sent to object’s skeleton to decrement TW by process’s PW.6. When O’s TW equals its PW, object can be GC’ed.
19Advanced Referencing Counting (3) (a) The initial assignment of weights in weighted reference counting(b) Weight assignment when creating a new reference.
20Advanced Referencing Counting (4) Weight assignment when copying a reference from P1 for P2.
21Advanced Reference Counting (5) Problem: only a limited number of references (2N-1) can be copied in this way without resorting to an additional scheme.Additional schemes: Existing reference P1 can create its own skeleton so that it can duplicate more references on its own. However, this gives rise to extra indirections which degrade performance.
22Advanced Referencing Counting (6) Creating an indirection when the partial weight of a reference has reached 1.
23Generation Reference Counting (1) This scheme solves problem by allowing a process to create an endless number of copies of references.Advantages: copies can create copies forever without communicating with the object. Reference creating and destruction requires comm with object or creator but not both.Disadvantage: still requires reliable comm.
24Generation Reference Counting (2) Object skeleton keeps a table G where G[ i.] is the number of outstanding references for generation i.When an object is created with a reference, that reference is considered generation 1. Any reference created by the object is generation 1.When a new reference is created, its copy counter is zero and it is told its generation #. If it copies the reference for P2, it increments its copy counter and gives P2 an incremented generation count.When a remote reference is deleted, with copy=X, generation=Y, a message is sent to the object skeleton with X and Y. G[Y] is decremented by one for the removed reference. G[Y+1] is increased by X for the X copies made by the process at generation Y. Note: at any given time, G probably will not accurately reflect reality. Also, the counts may be negative.When all entries G[ i.] are zero, the object can be GC’ed.
25Generation Referencing Counting (3) Creating and copying a remote reference in generation reference counting.