Parallel garbage collection and serialization without per-object synchronization
Parallel garbage collection, tracing, copying, and/or serialization of source memory areas is achieved without per-object synchronization instructions by dividing a source memory area into non-overlapping partitions, accessing each partition by only one thread at a time, and using a combination of global and thread-local data structures to minimize synchronization overhead and maximize achievable parallelism, while providing a full solution for handling pointers that cross partition boundaries.
1 . A method for implementing garbage collection or serialization in a multiprocessor computer system, comprising:
partitioning a source memory area into at least two non-overlapping partitions
designating one or more objects in one or more of the partitions as entry points
using more than one thread executing in parallel to analyze the partitions, each partition being worked on by at most one thread at a time, the thread at least partially determining which objects in that partition are reachable from the entry points designated for the partition
adding at least one new entry point to at least one other partition after a thread completes analyzing a first partition, the new entry point identifying an object in the other partition referenced from the first partition; and
if analyzing a partition has already completed when a new entry point is added to it, causing a thread to analyze any new entry points added to the partition.
2 . The method of claim 1 , wherein the analysis step comprises traversing the object graphs rooted at the object identified by each entry point to the partition to the extent such object graphs are located within the partition.
3 . The method of claim 1 , wherein the source memory area comprises the nursery.
4 . The method of claim 1 , further comprising:
allocating TLABs in mutators in such a way that the most recently allocated TLABs end up in different partitions in the partitioning step.
5 . The method of claim 1 , wherein the partitioning is such that partitions comprising the youngest objects are smaller than partitions comprising the oldest objects.
6 . The method of claim 1 , wherein the partitions are processed by the threads starting from the partitions comprising the youngest objects.
7 . The method of claim 1 , wherein the data structure maintained for each partition comprises:
a lock
a head pointer and a tail pointer for a singly linked list containing any entry points for the partition that have not yet been taken for processing by a thread; and
wherein each entry point node comprises a ‘next’ field used as the forward pointer in the list, access to this list by the threads processing partitions is protected by the lock, and designating an object as an entry point for a partition means adding the entry point node on this list.
8 . The method of claim 1 , wherein analyzing a partition by a thread also comprises:
copying at least one object reached during traversal to a new memory location.
9 . The method of claim 1 , further comprising:
while analyzing a partition by a thread, determining which objects have more than one reference, and recording such objects in a data structure; and
copying trees of objects rooted by objects having more than one reference.
10 . The method of claim 9 , wherein the copying is performed as a separate step after all partitions have been analyzed and multiple objects are copied simultaneously using more than one thread to perform the copying.
11 . The method of claim 9 , wherein objects having more than one reference are added to the same list that contains processed entry points without any synchronization.
12 . The method of claim 1 , wherein a plurality of new entry points are added to a referenced partition in a single synchronized operation.
13 . The method of claim 12 , further comprising:
while a thread is analyzing a partition, collecting references to objects in other partitions in a data structure that is local to that thread
adding new entry points to one or more other partitions by moving all entry points collected in the local data structure that belong to the other partition in a single synchronized operation.
14 . The method of claim 12 , wherein adding the plurality of new entry points to a partition comprises:
taking a singly linked list with head and tail pointers for the partition from the thread-local data of the current thread
locking data structures for the partition
joining said list into the pending list for the partition
unlocking data structures for the partition.
15 . The method of claim 1 , wherein at least some new entry points are added to the respective partition as soon as the boundary crossing reference has been discovered, and the partition is queued for processing if the referenced partition did not previously have any entry points.
16 . The method of claim 1 , wherein causing new entry points in a partition to be processed comprises:
checking a ‘done’ field in the data structure for the partition
if the ‘done’ field indicates that the partition is currently not in the work queue, adding the partition to the work queue, and if less than the maximum number of threads are currently processing partitions from the queue, starting or waking up a thread for processing them.
17 . A multiprocessor computer system comprising a garbage collection or serialization means comprising:
a partitioning means ( 120 )
a designating means ( 121 )
an analyzing means ( 122 )
a new entry point adding means ( 123 )
wherein the analyzing means utilizes more than one thread executing in parallel, each partition is processed by at most one thread at a time, the analyzing means at least partially determines which objects in each partition are reachable from entry points designated for each partition by the designating means or entry points discovered by the analyzing means, and the new entry point adding means at least in some situations causes the analyzing means to process new entry points added to a partition even if processing of previously added entry points in that partition has already completed.
18 . The computer system of claim 17 , further comprising a means for maximizing the spread of parallelism.
19 . The computer system of claim 17 , further comprising:
a means for recording discovered boundary crossing references in a thread-local data structure stored in memory device; and
a means for atomically adding more than one object pointed to by a recorded boundary crossing reference as new entry points in their respective regions.
20 . The computer system of claim 17 , further comprising:
a means for copying objects to a new memory location.
21 . The computer system of claim 20 , wherein the means for copying objects to a new memory location comprises:
a means for determining which objects have more than one reference; and
a means for copying trees of objects rooted at objects having more than one reference.
22 . A computer program product, stored on a machine-readable medium, the computer program product being operable to perform garbage collection or serialization in a multiprocessor computer, causing the computer to:
comprise a partitioning means ( 120 )
comprise a designating means ( 121 )
comprise an analyzing means ( 122 )
comprise a new entry point adding means ( 123 )
analyze more than one partition in parallel using more than one thread executing in parallel, however each partition being analyzed by only one thread at any given time
determine which objects in each partition are reachable from entry points designated for the partition or from new entry points added to the partition
schedule the processing of a partition if a new entry point is added to it after the processing of previously added entry points in it has already completed; and
copy a plurality of objects.