Per thread garbage collection is disclosed. objects associated only with a thread that created them are tracked. At a garbage collection time for a particular thread, it is determined which objects associated only with that thread remain reachable from a restricted root set associated with the thread. Any thread-only objects that are not determined to be reachable are garbage collected.
|
24. A method for managing memory, comprising:
determining which, if any, objects included in a set of objects associated with a first thread included in a plurality of threads associated with a heap are no longer reachable;
garbage collecting any objects of the set that are not determined to be reachable;
keeping track of which objects stored in the heap are included in the set of objects associated with the first thread; and
removing an object from the set of objects associated with the first thread if a removal criteria/on is/are satisfied, wherein removing includes removing from the set the object and recursively all objects referenced directly or indirectly by the object.
1. A method for managing memory, comprising:
determining which, if any, objects included in a set of objects associated with a first thread included in a plurality of threads associated with a heap are no longer reachable;
garbage collecting any objects of the set that are not determined to be reachable;
keeping track of which objects stored in the heap are included in the set of objects associated with the first thread; and
removing an object from the set of objects associated with the first thread if a removal criteria/on is/are satisfied, wherein the removal criteria/on includes receiving an indication that a reference to the object in the set has been or is being written into an object not included in the set.
26. A computer program product for managing memory, the computer program product being embodied in a computer readable storage medium and comprising computer instructions for:
determining which, if any, objects included in a set of objects associated with a first thread included in a plurality of threads associated with a heap are no longer reachable;
garbage collecting any objects of the set that are not determined to be reachable;
keeping track of which objects stored in the heap are included in the set of objects associated with the first thread; and
removing an object from the set of objects associated with the first thread if a removal criteria/on is/are satisfied, wherein removing includes removing from the set the object and recursively all objects referenced directly or indirectly by the object.
25. A computer system, comprising:
a memory comprising a heap with which a plurality of processing threads are associated; and
a processor coupled to the memory and configured to:
determine which, if any, objects included in a set of objects associated with a first thread included in a plurality of threads associated with the heap are no longer reachable; and
garbage collect any objects of the set that are not determined to be reachable;
keep track of which objects stored in the heap are included in the set of objects associated with the first thread; and
remove an object from the set of objects associated with the first thread if a removal criteria/on is/are satisfied, wherein removing includes removing from the set the object and recursively all objects referenced directly or indirectly by the object.
20. A computer program product for managing memory, the computer program product being embodied in a computer readable storage medium and comprising computer instructions for:
determining which, if any, objects included in a set of objects associated with a first thread included in a plurality of threads associated with a heap are no longer reachable;
garbage collecting any objects of the set that are not determined to be reachable;
keeping track of which objects stored in the heap are included in the set of objects associated with the first thread; and
removing an object from the set of objects associated with the first thread if a removal criteria/on is/are satisfied, wherein the removal criteria/on includes receiving an indication that a reference to the object in the set has been or is being written into an object not included in the set.
17. A computer system, comprising:
a memory comprising a heap with which a plurality of processing threads are associated; and
a processor coupled to the memory and configured to:
determine which, if any, objects included in a set of objects associated with a first thread included in a plurality of threads associated with the heap are no longer reachable;
garbage collect any objects of the set that are not determined to be reachable;
keep track of which objects stored in the heap are included in the set of objects associated with the first thread; and
remove an object from the set of objects associated with the first thread if a removal criteria/on is/are satisfied, wherein the removal criteria/on includes receiving an indication that a reference to the object in the set has been or is being written into an object not included in the set.
2. The method of
3. The method of
4. The method of
5. The method of
6. The method of
7. The method of
8. The method of
9. The method of
10. The method of
11. The method of
12. The method of
13. The method of
14. The method of
15. The method of
16. The method of
19. The computer system of
21. The computer program product of
22. The computer program product of
23. The computer program product of
|
In computing, “garbage collection” refers to a technique used to manage in an automated fashion memory blocks that have been allocated for use by programs using objects associated with a runtime system, without requiring that the programs themselves or other application code with which such memory blocks are associated keep track of and when finished de-allocate said memory blocks. Blocks that are roots (e.g., stack local variables and global variables and those registered as being held externally) and/or that are reachable from a root block via a chain of one or more explicit or “strong” references are kept alive, while blocks that are no longer reachable, indicating they are no longer in use (i.e., referenced by) by any live object, are “garbage collected”, that is, de-allocated and returned to the runtime system, thus making available for other use the memory allocated previously to such objects. Providing a “garbage collected” runtime system simplifies the task of application developers and avoids problems, such as “memory leaks”, crashes due to stale references to prematurely de-allocated blocks, and other related failures, that can occur if memory resources allocated to application objects are not released when and only when such objects are no longer in use.
Garbage collection typically has been performed by a central garbage collection or thread for all threads associated with objects stored in a memory “heap”. In so-called “generational” garbage collection, allocation of memory to new objects and the writing into relatively old objects of references to such new objects are tracked, which allows for a quicker but not comprehensive garbage collection to be performed with respect to newer objects that are no longer reachable, since many objects (e.g., temporary objects) are created, used, and no longer referenced and/or needed very shortly after their creation, such that by finding and collecting only those relatively newer objects that are no longer reachable memory associated with a good proportion of unreachable objects can be recovered than would be possible if older objects had to be checked as well. In both traditional and generational garbage collection, typically a set of objects that spans across all threads are checked for reachable and objects that are not determined to be reachable are garbage collected. Some garbage collectors may move objects that are not garbage collected, for example to defragment the heap, which requires that all references to such objects be updated. A “conservative” or “non-moving” garbage collector, on the other hand, is one that does not move objects found to be reachable. A “concurrent” garbage collector is one that does not require that all threads be halted while garbage collection is being performed.
Various embodiments of the invention are disclosed in the following detailed description and the accompanying drawings.
The invention can be implemented in numerous ways, including as a process, an apparatus, a system, a composition of matter, a computer readable medium such as a computer readable storage medium or a computer network wherein program instructions are sent over optical or communication links. In this specification, these implementations, or any other form that the invention may take, may be referred to as techniques. A component such as a processor or a memory described as being configured to perform a task includes both a general component that is temporarily configured to perform the task at a given time or a specific component that is manufactured to perform the task. In general, the order of the steps of disclosed processes may be altered within the scope of the invention. As used herein, the term ‘processor’ refers to one or more devices, circuits, and/or processing cores configured to process data, such as computer program instructions.
A detailed description of one or more embodiments of the invention is provided below along with accompanying figures that illustrate the principles of the invention. The invention is described in connection with such embodiments, but the invention is not limited to any embodiment. The scope of the invention is limited only by the claims and the invention encompasses numerous alternatives, modifications and equivalents. Numerous specific details are set forth in the following description in order to provide a thorough understanding of the invention. These details are provided for the purpose of example and the invention may be practiced according to the claims without some or all of these specific details. For the purpose of clarity, technical material that is known in the technical fields related to the invention has not been described in detail so that the invention is not unnecessarily obscured.
Per thread garbage collection is disclosed. In some embodiments, per thread garbage collection is performed in the context of a conservative collector, such as a conservative, generational, concurrent collector. For each of a plurality of threads associated with a heap or other shared memory pool, a set of objects associated only with that thread is tracked. Objects created by the thread are added to the set, and an object is removed from the set—and recursively all objects in the set that are referenced by an object that is removed from the set—if a reference to the hitherto thread-only object is written into an object that is not in that thread-only set, or is written to global storage such that other threads might access it, or otherwise made available to other threads as provided by the garbage collection system, for example if the object is marked as having references stored externally, or if references to the object are registered with a weak reference system. Periodically, or upon occurrence of pre-configured or other event, a per thread garbage collection is performed. Objects in the thread-only set for that thread are checked to determine which remain reachable from a reduced root set that includes only references from entities associated only with that thread, excluding, e.g., global variables, local variables associated with other threads, etc. Objects in the thread-only set that are not determined to be reachable are garbage collected. In various embodiments, finalization may be performed, if needed, e.g., by the thread itself or a separate finalization process common to all threads. In some embodiments, space associated with a thread-only object that is garbage collected in a per thread garbage collection may be reclaimed and/or reused by the thread itself, without returning the memory locations to a central pool. In various embodiments, per thread garbage collection allows for garbage collection to be performed relatively quickly, because only the thread-only set is traversed. In some embodiments, per thread garbage collection is performed in the context of a generational conservative collector, i.e., one that treats relatively newer objects differently than older ones (generational) and that does not copy objects from their initial location to a better one over time (conservative).
Performing garbage collection on a per thread basis, as described herein, in a typical case will allow a substantial proportion of objects that are no longer in use to be garbage collected in relatively quick cycles (due to the reduced root set and reduced set of nodes traversed in each per thread cycle, i.e., just the thread-only objects) with each thread being diverted only at a time that is opportune for that thread and only so long as needed to perform garbage collection with respect to that thread's thread-only objects.
Although the foregoing embodiments have been described in some detail for purposes of clarity of understanding, the invention is not limited to the details provided. There are many alternative ways of implementing the invention. The disclosed embodiments are illustrative and not restrictive.
Garst, Jr., Gerald Blaine, Beard, Patrick C., Parker, Gregory Robert, Behnke, Douglas Joshua
Patent | Priority | Assignee | Title |
8140597, | Aug 29 2007 | International Business Machines Corporation | Computer system memory management |
Patent | Priority | Assignee | Title |
5088036, | Jan 17 1989 | HEWLETT-PACKARD DEVELOPMENT COMPANY, L P | Real time, concurrent garbage collection system and method |
5842016, | May 29 1997 | Microsoft Technology Licensing, LLC | Thread synchronization in a garbage-collected system using execution barriers |
6304949, | Aug 22 1997 | U S PHILIPS CORPORATION; Pace Micro Technology PLC | Data processor with localized memory reclamation |
6341293, | Jul 13 1994 | Apple Inc | Real-time computer "garbage collector" |
6349312, | Jul 24 1998 | Oracle America, Inc | Method and apparatus for performing pre-allocation of memory to avoid triggering garbage collection operations |
6353838, | Dec 19 1997 | Microsoft Technology Licensing, LLC | Incremental garbage collection |
6490599, | Oct 07 1998 | International Business Machines Corporation | On-the-fly garbage collector |
6671707, | Oct 19 1999 | INTEL CORPORATION, A CORPORATION OF DELAWARE | Method for practical concurrent copying garbage collection offering minimal thread block times |
6978285, | Aug 22 2002 | Intel Corporation | Methods and apparatus for concurrent enumeration of an object reference root set |
7058670, | Dec 20 2002 | Oracle America, Inc | Scalable, space-efficient, parallel remembered-sets |
7672983, | Dec 19 2005 | Oracle America, Inc | Method and apparatus for tracking activity of a garbage collector with a plurality of threads that operate concurrently with an application program |
Executed on | Assignor | Assignee | Conveyance | Frame | Reel | Doc |
May 16 2008 | GARST, GERALD BLAINE JR | Apple Inc | ASSIGNMENT OF ASSIGNORS INTEREST SEE DOCUMENT FOR DETAILS | 021038 | /0459 | |
May 16 2008 | PARKER, GREGORY ROBERT | Apple Inc | ASSIGNMENT OF ASSIGNORS INTEREST SEE DOCUMENT FOR DETAILS | 021038 | /0459 | |
May 16 2008 | BEHNKE, DOUGLAS JOSHUA | Apple Inc | ASSIGNMENT OF ASSIGNORS INTEREST SEE DOCUMENT FOR DETAILS | 021038 | /0459 | |
May 16 2008 | BEARD, PATRICK C | Apple Inc | ASSIGNMENT OF ASSIGNORS INTEREST SEE DOCUMENT FOR DETAILS | 021038 | /0459 | |
May 21 2008 | Apple Inc. | (assignment on the face of the patent) | / |
Date | Maintenance Fee Events |
Jun 17 2011 | ASPN: Payor Number Assigned. |
Jan 14 2015 | M1551: Payment of Maintenance Fee, 4th Year, Large Entity. |
Jan 17 2019 | M1552: Payment of Maintenance Fee, 8th Year, Large Entity. |
Jan 18 2023 | M1553: Payment of Maintenance Fee, 12th Year, Large Entity. |
Date | Maintenance Schedule |
Aug 02 2014 | 4 years fee payment window open |
Feb 02 2015 | 6 months grace period start (w surcharge) |
Aug 02 2015 | patent expiry (for year 4) |
Aug 02 2017 | 2 years to revive unintentionally abandoned end. (for year 4) |
Aug 02 2018 | 8 years fee payment window open |
Feb 02 2019 | 6 months grace period start (w surcharge) |
Aug 02 2019 | patent expiry (for year 8) |
Aug 02 2021 | 2 years to revive unintentionally abandoned end. (for year 8) |
Aug 02 2022 | 12 years fee payment window open |
Feb 02 2023 | 6 months grace period start (w surcharge) |
Aug 02 2023 | patent expiry (for year 12) |
Aug 02 2025 | 2 years to revive unintentionally abandoned end. (for year 12) |