Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does pointer reversal in mark and sweep garbage collection buy you?

I feel like I am missing something painfully simple but I am trying to understand mark and sweep garbage collection per Andrew Appel's Modern Compiler Implementation in ML book and there's a small paragraph inside the Mark and Sweep section titled Pointer Reversal (270).

At this point I think I understand how it works. In a nutshell, as you traverse the graph you flip all the pointers so that your predecessor is inside your set of fields. Then when you are done with a given element, you flip the pointers back so they point at the right place again.

If that is correct, what exactly does it buy you? Appel attempts to explain this but I don't fully grok his wording.

like image 229
yarian Avatar asked Apr 23 '12 16:04

yarian


People also ask

What is Mark and sweep algorithm for garbage collection?

The mark-and-sweep algorithm is called a tracing garbage collector because it traces out the entire collection of objects that are directly or indirectly accessible by the program. Example: A. All the objects have their marked bits set to false.

How does Concurrent Mark and Sweep work?

The Concurrent Mark Sweep (CMS) collector is designed for applications that prefer shorter garbage collection pauses and that can afford to share processor resources with the garbage collector while the application is running.

How does generational garbage collection work?

The Generational Garbage Collection ProcessBoth survivor spaces start out empty. When the eden space fills up, a minor garbage collection is triggered. Referenced objects are moved to the first survivor space. Unreferenced objects are deleted when the eden space is cleared.

What are the disadvantages of generational garbage collection?

Generational Garbage Collection. One of the limitations of simple garbage collection algorithms is that the system has to analyze all the data in heap. For example, a Copying Algorithm has to copy all the live data every time it used. This may cause significant increases in execution time.


1 Answers

During marking, objects fall into three categories:

  1. Objects that have not been marked
  2. Objects that have been marked, but can point to unmarked objects
  3. Objects that have been marked and point to marked objects only

As marking proceeds, objects change state from category 1 to category 2, and from category 2 to category 3. The garbage collector has to keep track of all objects in category 2 so that it can find all unmarked objects. But where does it store that information? Garbage collection may be running when memory is completely full, so it cannot dynamically allocate a data structure. It should build a data structure holding objects in category 2, using the memory that is already allocated. Pointer reversal is an algorithm for building a linked list of these objects without allocating memory.

like image 100
Heatsink Avatar answered Nov 05 '22 02:11

Heatsink