System and method for computer automatic memory management

Information

  • Patent Application
  • 20070203960
  • Publication Number
    20070203960
  • Date Filed
    January 22, 2007
    18 years ago
  • Date Published
    August 30, 2007
    18 years ago
Abstract
The present invention is a method and system of automatic memory management (garbage collection). An application automatically marks up objects referenced from the “extended root set”. At garbage collection, the system starts traversal from the marked-up objects. It can conduct accurate garbage collection in a non-GC language, such as C++. It provides a deterministic reclamation feature. An object and its resources are released immediately when the last reference is dropped. Application codes automatically become entirely GC-safe and interruptible. A concurrent collector can be pause-less and with predictable worst-case latency of micro-second level. Memory usage is efficient and the cost of reference counting is significantly reduced.
Description

BRIEF DESCIPTION OF THE DRAWINGS


FIG. 1 is a block diagram of a platform supporting the embodiments of the present invention;



FIG. 2 is a block diagram of embodiment 1 of automatic memory management;



FIG. 3A is a view of the structure of a managed object;



FIG. 3B is a schematic representation of a managed object;



FIG. 3C is a relationship graph of several objects;



FIG. 4 is a flowchart of stop-the-world tracing garbage collector;



FIG. 5A is a view showing the initial state of an object before an assignment;



FIG. 5B is a view showing the state of an object after an assignment;



FIG. 5C is a view showing the state of an object after removal of source reference;



FIG. 6 is a pseudo code of an original program;



FIG. 7 is a pseudo code section of modified portion;



FIG. 8 is a pseudo code of the final program;



FIG. 9A is a view showing the original state before returning an object reference;



FIG. 9B is a view showing the state after returning an object reference;



FIG. 10A is a flowchart of an incremental garbage collector;



FIG. 10B is a flowchart of a subroutine of AddRootObjects;



FIG. 11 is a block diagram of main structure of embodiment 2;



FIG. 12A is a flowchart of the mark phase of concurrent collector;



FIG. 12B is a object relationship representation viewed from the concurrent collector;



FIG. 13 is a detailed block diagram of the mark phase of the concurrent collector;



FIG. 14 is a flowchart of the mark phase of the concurrent collector;



FIG. 15 is a flowchart of the mutator procedure of assignment operation;



FIG. 16 is a flowchart of the mutator procedure to create new objects;


Claims
  • 1. A method of garbage collection of memory, said method comprising: identifying objects referenced by pointers in “extended root set” during the execution of application program; anddistinguishing those identified objects, traversing them and their descendants during a tracing garbage collection.
  • 2. A method as claimed in claim 1 further comprising: using a reference counting technique to identify or mark out objects referenced by pointers in “extended root set”;maintaining a lock-counter reflecting the number of references from “extended root set” for each managed object;distinguishing objects of non-zero lock-counter; andtraversing the objects and their descendants during a tracing garbage collection.
  • 3. A method as claimed in claim 1 further comprising: maintaining a collection of objects or associated data structures, describing status that objects are referenced by pointers in “extended root set”; wherein the collection may include, but is not limited to, list, array, vector, set, graph, hash tables or combinations of them; andtraversing objects in the collection and descendants of these objects during a tracing garbage collection.
  • 4. A method as claimed in claim 2 further comprising: maintaining a collection of objects or associated data structures, of which the lock-counter has non-zero value; andtraversing objects in the collection and descendants of these objects during a tracing garbage collection.
  • 5. A method as claimed in claim 2 further comprising: dividing pointers to the same type of objects into classes according to their places and purposes;using pointer class “CLockedPtr” in “extended root set” to keep objects alive, and acting as “move reference” between two “CLockedPtr” pointers;using raw pointer as input type of function parameter; andusing “CLockedPtr” as output type of function parameter or return type of function.
  • 6. A method as claimed in claim 2 further comprising: maintaining an extra-counter reflecting the number of references originating from locations other than “extended root set” for each managed object;reclaiming objects with both zero value of lock-counter and extra-counter; andcollecting circular referenced garbage by tracing collector.
  • 7. A method of tracing garbage collection as claimed in claim 1 further comprising: using incremental or concurrent tracing garbage collection; andapplying read/write barrier or multi-threading synchronization mechanism in the course of lock-counter maintenance operation, or just before or just after the operation.
  • 8. A method as claimed in claim 7 further comprising: scanning managed objects and converting marked-out “white” objects to “grey”;converting a “white” object into “grey” if a new effective reference is created to the object during tracing garbage collection;handling objects created during tracing garbage collection as “black” objects; andfinishing the job of identifying unreachable objects when there is no “grey” object after all marked-out objects are converted to “grey”.
  • 9. A garbage collection system for performing concurrent automatic memory management, the system comprising: application threads automatically identifying objects which are referenced from the “extended root set”;during the tracing garbage collection, if application threads change the reference relationship of managed objects then a related code of the collector will be executed concurrently against a collector thread in a way of multi-threading synchronization mechanism;an incremental or concurrent tracing collector distinguishes marked-out objects from other managed objects, without the need to scan root set for references to objects, and without the need to suspend the application thread to determine the end of traversal; anda reference counting module can reclaim zero-referenced objects immediately even during the tracing garbage collection period.
  • 10. A garbage collection system as in claim 9 further comprising: the application threads using reference counting to mark out objects which are referenced by the “extended root set”;during the tracing garbage collection, if an application thread adds a new reference to a “white” object, then the object is recorded down; andthe tracing collector converts the recorded-down object from “white” to “grey”, converts marked-out object from “white” to “grey”, marks newly created object to “black”, traverses “grey” objects and descendants until no more “grey” objects, then finishes the job of identifying unreachable objects.
Priority Claims (1)
Number Date Country Kind
200610034590.5 Mar 2006 CN national
Provisional Applications (1)
Number Date Country
60767005 Feb 2006 US