+ All Categories
Home > Documents > 1 DC3: More on Naming (Chapter 5) Deleting Objects.

1 DC3: More on Naming (Chapter 5) Deleting Objects.

Date post: 14-Dec-2015
Category:
Upload: madeline-partney
View: 221 times
Download: 4 times
Share this document with a friend
Popular Tags:
25
1 DC3: More on Naming (Chapter 5) Deleting Objects
Transcript
Page 1: 1 DC3: More on Naming (Chapter 5) Deleting Objects.

1

DC3: More on Naming

(Chapter 5)

Deleting Objects

Page 2: 1 DC3: More on Naming (Chapter 5) Deleting Objects.

2

Topics

• Distributed garbage collection– Skeletons and Proxies– Unreferenced and Unreachable

• Centralized Solutions– Mark and Sweep– Reference Counting

• Distributed GC– Distributed reference counting– Advanced reference counting– Generation reference counting

Page 3: 1 DC3: More on Naming (Chapter 5) Deleting Objects.

3

Removing Objects no Longer Needed

• Called Distributed Garbage Collection

• Many 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.

Page 4: 1 DC3: More on Naming (Chapter 5) Deleting Objects.

4

The Problem of Unreferenced Objects

An example of a graph representing objects containing references to each other.

Page 5: 1 DC3: More on Naming (Chapter 5) Deleting Objects.

5

Garbage – Unreferenced Memory

Unreferenced memoryint * p1; int * p2;p1 = new int;p1 = new int;

p1

p1

Page 6: 1 DC3: More on Naming (Chapter 5) Deleting Objects.

6

Garbage – Unreachable Objects

p1

Unneeded memory not referenced by objects currently active in the program

p2

p3

Page 7: 1 DC3: More on Naming (Chapter 5) Deleting Objects.

7

Garbage Collection in a Centralized System – Mark and Sweep

Simple solution: stop allocation of new objects and deallocation.

• Mark all objects as unreferenced

• Go 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.

Page 8: 1 DC3: More on Naming (Chapter 5) Deleting Objects.

8

Mark and Sweep - 1

p1

p2

p3

p4

p5

Mark all objects as

unreferenced

Page 9: 1 DC3: More on Naming (Chapter 5) Deleting Objects.

9

Mark and Sweep - 2

p1

p2

p3

p4

p5

Go through program and unmark referenced

objects

Page 10: 1 DC3: More on Naming (Chapter 5) Deleting Objects.

10

Mark and Sweep - 3

p1

p4

p5

Delete unreferenced objects

Page 11: 1 DC3: More on Naming (Chapter 5) Deleting Objects.

11

A 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.

Page 12: 1 DC3: More on Naming (Chapter 5) Deleting Objects.

12

Distributed 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.

Page 13: 1 DC3: More on Naming (Chapter 5) Deleting Objects.

13

Proxies and Skeletons

proxyskeleton

process object

Page 14: 1 DC3: More on Naming (Chapter 5) Deleting Objects.

14

Distributed 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.

Page 15: 1 DC3: More on Naming (Chapter 5) Deleting Objects.

15

Distributed Reference Counting (2)

The problem of maintaining a proper reference count in the presence of unreliable communication.

Page 16: 1 DC3: More on Naming (Chapter 5) Deleting Objects.

16

Reference Counting (3)

(a) Copying a reference to another process and incrementing the counter too late.

(b) A solution, but increased message traffic.

+1

Page 17: 1 DC3: More on Naming (Chapter 5) Deleting Objects.

17

Advanced 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.

Page 18: 1 DC3: More on Naming (Chapter 5) Deleting Objects.

18

Advanced 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.

Page 19: 1 DC3: More on Naming (Chapter 5) Deleting Objects.

19

Advanced Referencing Counting (3)

(a) The initial assignment of weights in weighted reference counting

(b) Weight assignment when creating a new reference.

Page 20: 1 DC3: More on Naming (Chapter 5) Deleting Objects.

20

Advanced Referencing Counting (4)

c) Weight assignment when copying a reference from P1 for P2.

Page 21: 1 DC3: More on Naming (Chapter 5) Deleting Objects.

21

Advanced 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.

Page 22: 1 DC3: More on Naming (Chapter 5) Deleting Objects.

22

Advanced Referencing Counting (6)

Creating an indirection when the partial weight of a reference has reached 1.

Page 23: 1 DC3: More on Naming (Chapter 5) Deleting Objects.

23

Generation 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.

Page 24: 1 DC3: More on Naming (Chapter 5) Deleting Objects.

24

Generation 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.

Page 25: 1 DC3: More on Naming (Chapter 5) Deleting Objects.

25

Generation Referencing Counting (3)

Creating and copying a remote reference in generation reference counting.


Recommended