The present invention generally relates to systems and method for garbage collection in a memory management system, and more particularly, to systems and techniques which provide load balancing of asynchronous concurrent marking of objects in a marking phase of garbage collection.
A key feature of some modern programming languages such as Java is its garbage-collection process. Such a process takes care of releasing dynamically allocated memory that is no longer referenced. Because the heap is garbage-collected, programmers don't have to directly release allocated memory.
The name garbage collection implies that objects that are no longer needed by the program are “garbage” and can be thrown away. A more precise characterization might be recycling memory. In this manner, when an object is no longer referenced by the program, it may be recycled for further use as another object. The garbage collector must somehow determine which objects are no longer referenced by the program and make available the heap space occupied by such un-referenced objects.
Historically a single thread is used to perform garbage collection. When one thread performs garbage collection, there can be pauses or long waits while the collection is performed. In order to reduce the amount of time that a program pauses while garbage collection is performed, a plurality of thread may perform garbage collection to distribute the garbage collection work load. Concurrent garbage collection trades processor resources (which would otherwise be available to the application) for shorter collection pause times. Typically on an N processor system when the concurrent part of the collection is running, it will be using 1/Nth of the available processor power. On a uni-processor machine it would be fortuitous if it provided any advantage. The concurrent garbage collector also has some additional overhead costs that will take away from the throughput of the applications, such as the synchronization required between garbage collection threads. On a two processor machine there is a processor available for application threads while the concurrent part of the collection is running, so running the concurrent garbage collector thread does not “pause” the application. There may be reduced pause times as intended for the concurrent collector but again less processor resources are available to the application and some slowdown of the application should be expected.
Garbage collection may use several different methods to locate the objects to be processed. One such method is mark and sweep. Marking involves determining all the currently live (e.g. referenced) objects. Sweeping is the returning to the heap those objects which are no longer references on the stack or by other objects which are in turn referenced by some root object or the stack.
A problem with concurrent garbage collection in a system such as a Java Virtual Machine (JVM) is that whenever a plurality of threads work on data structures, those data structures that may simultaneously be accessed must use some type of synchronization to prevent data corruption. Synchronization of threads requires considerable overhead and can cause multiple threads to run sequentially. Additionally, when multiple threads work on separate lists of work to be performed, the amount of work for each thread is balanced in relation to the other threads. Further, there are cases where marking of objects may need to be performed by threads other than garbage collection threads.
The present invention addresses these and other issues concerning the incompatibilities and difficulties encountered by using a matrix which points to linked lists of marked objects. Objects when initially added to a linked list of work “to do” (graying) mainly be added on a row of matrix of linked lists by a thread that corresponds to the row. When processing objects on the “to do” list (blackening) a thread may only process a column of the matrix that correspond to the thread.
More specifically, the present invention provides mechanisms and techniques that allow for asynchronously graying and blackening objects in the marking phase of parallel garbage collection. The system and method use a matrix to control a series of linked lists of work to be grayed and blackened. The threads of the garbage collector are each assigned entries within the matrix upon which they may either gray an entry in the linked list or blacken an entry on the linked list. Further restrictions upon the use of the matrix allow a non-garbage collection thread to asynchronously or synchronously add objects to be processed by the garbage collector.
According to one embodiment of the invention, a method is provided for facilitating in a memory management system asynchronously marking objects during multi-threaded garbage collection. The method comprises the steps of adding to a head of a linked list an object to be worked on by a garbage collection thread, the linked list determined by iterating a row of a matrix corresponding to the garbage collection thread to find a matrix entry; and finding work to be performed by the first thread by iterating across a column of the matrix corresponding to the garbage collection thread and updating a worked on position indicator of objects in the link list indicated by a linked list referenced by a matrix entry. Further, only the garbage collection thread may add objects in the link list referenced by matrix entries in the row corresponding to the garbage collection thread, and only the garbage collection thread may find objects in the link list referenced by matrix entries in the column corresponding to the garbage collection thread. The number of rows and number of columns of the matrix equals the number of garbage collection threads. Further, the garbage collection thread adds to the head of the linked list, the garbage collection thread omits matrix entries where the column corresponds to the garbage collection thread. The method further comprises adding the object to the linked list by another than garbage collection thread, the link list referenced by a matrix entry, wherein an index to determine the matrix is the same for both the column and the row. Further in the step of finding work to be performed further performs the step of: searching for further object references in the object; and adding the further object referenced to the head of a linked list an object to be worked on. Further in an embodiment threads other than garbage collection thread is a plurality of threads, synchronization is performed when updating the head of a list.
Another embodiment includes a method of facilitating in a memory management system marking objects during multi-threaded garbage collection, the method comprising: adding asynchronously to a head of a linked list an object to be worked on by a garbage collection thread, the linked list determined by iterating a row of a matrix corresponding to the garbage collection thread to find a matrix entry; finding work to be performed by the first thread by iterating across a column of the matrix corresponding to the garbage collection thread and updating asynchronously a worked on position indicator of objects in the link list indicated by a linked list referenced by a matrix entry; and finding additional work to be performed by a first thread by iterating across a column unassigned to any to any garbage collection thread and updating synchronously a worked on position indicator of objects in the link list indicated by a linked list referenced by a matrix entry.
Another embodiment includes a method of facilitating in a memory management system marking objects during multi-threaded garbage collection, the method comprising: adding asynchronously to a head of a linked list an object to be worked on by a garbage collection thread, the linked list determined by iterating a row of a matrix corresponding to the garbage collection thread to find a matrix entry; finding work to be performed by the first thread by iterating across a column of the matrix corresponding to the garbage collection thread and updating synchronously a worked on position indicator of objects in the link list indicated by a linked list referenced by a matrix entry; and finding, upon exhaustion of work to be performed by the first thread by iterating across a column of the matrix corresponding to the garbage collection thread, other work to be performed by the first thread by iterating across a column of the matrix corresponding to another garbage collection thread and updating synchronously a worked on position indicator of objects in the link list indicated by a linked list referenced by a matrix entry.
Other embodiments include a computer system configured as a management station to perform all of the aforementioned methods via software control, or via hardware and/or software configured to perform those methods and the techniques disclosed herein as the invention.
One such embodiment includes a memory management system asynchronously marking objects during multi-threaded garbage collection, the system comprising: a processor operatively coupled to a memory, the processor configured to implement computer-readable code, the computer-readable code configured to: adding to a head of a linked list an object to be worked on by a garbage collection thread, the linked list determined by iterating a row of a matrix corresponding to the garbage collection thread to find a matrix entry; and finding work to be performed by the first thread by iterating across a column of the matrix corresponding to the garbage collection thread and updating a worked on position indicator of objects in the link list indicated by a linked list referenced by a matrix entry.
Other embodiments of the invention that are disclosed herein include software programs to perform the operations summarized above and disclosed in detail below. More particularly, a computer program product is disclosed which has a computer-readable medium including computer program logic encoded thereon to provide the methods for facilitating in a memory management system asynchronously marking objects during multi-threaded garbage collection according to this invention and its associated operations. The computer program logic, when executed on at least one processor within a computing system, causes the processor to perform the operations (e.g., the method embodiments above, and described in detail later) indicated herein. This arrangement of the invention is typically provided as software on a computer readable medium such as an optical medium (e.g., CD-ROM), floppy or hard disk or other such medium such as firmware in one or more ROM or RAM or PROM chips or as an Application Specific Integrated Circuit (ASIC). The software or firmware or other such configurations can be installed onto a computer system to cause the computer system to perform the techniques explained herein as the invention.
It is to be understood that the system of the invention can be embodied strictly as a software program, as software and hardware, or as hardware alone. Is also to be understood that the methods of this invention typically performs (e.g., executes, runs, or is otherwise operated) on a computer system coupled to a data storage or other type of network. The computer system is generally networked but is typically a dedicated computer system, personal computer or workstation operated by a network or systems administrator or manager. In alternative arrangements however, the computer of this invention may reside on a computer system located elsewhere on the network and the user (e.g., systems manager) that run the program requiring garbage collection may be located elsewhere on the network and may be communicating with the program over a network connection (e.g., WWW or other browser-type interface, command-line interface, messaging interface, E-Mail, or another protocol or interface).
It is to be understood that the system disclosed herein may be embodied strictly as a software program, as software and hardware, or as hardware alone. The embodiments disclosed herein, may be employed in data communications devices and other computerized devices and software systems for such devices such as those manufactured by Sun Microsystems, Inc. of Santa Clara, Calif.
The foregoing and other objects, features and advantages of the invention will be apparent from the following more particular description of preferred embodiments of the invention, as illustrated in the accompanying drawings in which like reference characters refer to the same parts throughout the different views. The drawings are not necessarily to scale, with emphasis instead being placed upon illustrating the embodiments, principles and concepts of the invention.
a shows a representation of a linked list with no entries.
b shows a representation of a linked list with a single entry added.
c shows a representation of a linked list with a second entry added.
a shows a representation of a linked list in which an entry is blackened.
b shows a representation of a linked list in which an entry is added and another entry is blackened.
The present invention provides techniques and mechanisms that allow asynchronous parallel processing of objects added to a “to do” list for garbage collection. The process has two phases that may be processed concurrently. The first phase is the graying of an object that consists of adding an object to a list of work to be processed. The second is the blackening of the object by adding objects that the first object references to the list of work to do.
Matrix entry 112 is representative of each matrix entry in matrix 110. The matrix entry contains both a head_field and scanned_up_to field. A thread of the present garbage collector when adding work to a linked list of objects only adds entries to linked lists in the row corresponding to that thread. Thus, when thread 101 wants to add work to a linked list, it does so by iterating across row 0 of matrix 110, the corresponding row for thread 101, when the next entry is reached it adds the object to the linked list pointed to by that entry. Likewise, thread 102 iterates across row 1 of matrix 110, thread 103 across row 2 of matrix 110 and thread 104 across row 3 of matrix 110. By enforcing such a rule that a thread may only iterate across it corresponding row, the head_field manipulated when adding an element to a linked list of work need not be protected from interference by other threads, as only one thread ever updates these fields.
A further restriction is to not allow a thread to update a linked list referenced by the matrix entry where the column corresponds to the thread. Thus, when thread 101 iterates across row 0 of matrix 110, it never accesses the entry in column 0. Likewise, thread 102 never updates matrix entry [1:1] of matrix 110, thread 103 never updates matrix entry [2:2] of matrix 110 and thread 104 never updates matrix entry [3:3] of matrix 110.
a-3c illustrate the adding of two objects to a linked list. Thread 101 of
In
In
For the sake of brevity, two entries were shown being added to linked list 301 to illustrate the workings of the linked list. In one embodiment of the present the second object 307 would have been added as the first entry to the link list pointed to by the matrix entry [0:2] after iterating to the next matrix entry of matrix 110. By advancing to the next matrix entry and adding the object to the list there, the linked lists of matrix 110 grow in an evenly distributed manner.
a and b illustrate the blackening and graying of entries in a list.
b illustrates what the linked list 301 looks like after another entry is added according to the process of
Those skilled in the art will understand that there can be many variations made to the operations of the parallel garbage collector explained above while still achieving the same objectives of the invention. For instance, the structures of the present invention could be implemented where the thread graying an object could work on columns rather rows as described above. In such an embodiment, the thread blackening an object would iterate rows not column. Such variations are intended to be covered by the scope of this invention. As such, the foregoing description of embodiments of the invention are not intended to be limiting. Rather, any limitations to embodiments of the invention are presented in the following claims.
Number | Name | Date | Kind |
---|---|---|---|
5842016 | Toutonghi et al. | Nov 1998 | A |
6253215 | Agesen et al. | Jun 2001 | B1 |
6341293 | Hennessey | Jan 2002 | B1 |
20070136402 | Grose et al. | Jun 2007 | A1 |
Number | Date | Country | |
---|---|---|---|
20090204654 A1 | Aug 2009 | US |