Abstract:
A method for exactly tracking the amount of free space in an independently collectable memory region is described. This enables more accurate decisions about the utility of collecting each individual region. The method uses zombie multiobjects (special multiobject descriptors denoting inaccessible space) to track which inaccessible areas have already been added to a region&#39;s free space counters.

Description:
CROSS-REFERENCE TO RELATED APPLICATIONS 
       [0001]    Not Applicable 
       INCORPORATION-BY-REFERENCE OF MATERIAL SUBMITTED ON ATTACHED MEDIA 
       [0002]    Not Applicable 
       TECHNICAL FIELD 
       [0003]    The present invention relates to garbage collection techniques for memory management in a data processing device. 
       BACKGROUND OF THE INVENTION 
       [0004]    Various garbage collection methods are described in the book R. Jones &amp; R. Lins: Garbage Collection: Algorithms for Automatic Dynamic Memory Management, Wiley, 1996. 
         [0005]    An example of a region-based garbage collector is provided in D. Detlefs et al: Garbage-First Garbage Collection, ISMM&#39; 04, ACM, 2004, pp. 37-48. They use approximate tracking of free space. A much earlier example of a region-based garbage collector can be found in P. Bishop: Computer Systems with a Very Large Address Space and Garbage Collection, MIT/LCS/TR-178, MIT, 1977 (NTIS ADA040601). Bishop calls regions areas and the collection priority/utility is called gc_index. 
         [0006]    The use of subordinate multiobjects for garbage collection is described in the co-owned U.S. patent application Ser. No. 12/432,779 by the same inventor, which is incorporated herein by reference. 
         [0007]    In systems with very large memories using a global tracing algorithm (as in Detlefs et al) to estimate the utility of collecting each region may result in severely out-of-date information, as tracing hundreds of gigabytes may take a long time and cannot be performed very frequently. Similar considerations apply in mobile devices for power consumption reasons. Especially younger data structures may evolve very quickly, leading to grossly inaccurate estimates. 
         [0008]    Inaccurate estimation of the gc_index (priority of collecting a region) results in wasted work and may lead to significant (temporary) memory leakage due to some regions with lots of free space not being collected as soon as possible. Accurate tracking of free space in each region would make the garbage collector more robust and more efficient. 
       BRIEF SUMMARY OF THE INVENTION 
       [0009]    The present invention adds exact tracking of free space in each region to multiobject-based garbage collection using subordinate multiobjects. 
         [0010]    The basic idea is to have a field indicating the amount of unused (free) space in the descriptor data structure of each independently collectable memory region, and whenever a multiobject is freed or a section of a multiobject is rendered inaccessible by a write, add the number of new unused bytes (or cells) to this field. 
         [0011]    However, it is common for writes to occur in a sequence such that the old values are successive nodes of a list (or tree). As the list (or tree) is linearized in a multiobject, the ranges of the subtrees rooted at the old values very significantly overlap. It is quite possible in such sequences to get estimates of freed space that approach N̂2 even if only N bytes are actually freed. 
         [0012]    The solution is to add a new type of subordinate multiobject, called the zombie multiobject, to indicate space that has already been added to the number of unused bytes in the region. 
         [0013]    There are two main cases where unused space is created:
       freeing a top-level or detached subordinate multiobject, and   the old value of a written cell becoming inaccessible.       
 
         [0016]    When freeing a top-level multiobject or a detached subordinate, the amount of space freed is essentially the size of the freed multiobject minus the sum of the sizes of all of its direct subordinates (assuming previously freed areas are indicated by zombie multiobjects). (No space becomes unused by freeing an attached subordinate, as its root has an implicit reference from the containing multiobject.) 
         [0017]    As for the old value of a written cell, if it is not the root of a multiobject, that object and any other objects within the same top-level multiobject that are not within subordinate multiobjects become unused space. The unused space increases by the size of the subtree rooted at the old value minus the sum of the sizes of all direct subordinates of the multiobject containing the object pointed to by the old value in the range of the subtree. A zombie multiobject is created in this case for the address range of the subtree, and any subordinate multiobjects in that range are made direct subordinates of the zombie. 
         [0018]    Whenever a zombie multiobject would be a direct subordinate of another zombie multiobject, they can be combined (essentially freeing the smaller zombie; this only results in preparenting its immediate subordinates, as the space indicated by zombies has already been freed and zombies have no exits and cannot have attached subordinates). 
         [0019]    Depending on the embodiment, it may or may not be desirable to leave a zombie when freeing a top-level multiobject. In the preferred embodiment the subordinates of a freed top-level multiobject are simply promoted to top-level multiobjects (and direct zombie subordinates freed). 
         [0020]    Whenever the amount of unused space in a region changes, its gc_index can be updated accordingly. 
     
    
     
       BRIEF DESCRIPTION OF THE SEVERAL VIEWS OF THE DRAWING(S) 
         [0021]      FIG. 1  illustrates a top-level multiobject with several subordinate multiobjects and a zombie multiobject. 
           [0022]      FIG. 2  illustrates freeing a multiobject. 
           [0023]      FIG. 3  illustrates processing the address range rooted at the old value of a written cell. 
           [0024]      FIG. 4  illustrates a data processing device according to the an embodiment of the invention. 
       
    
    
     DETAILED DESCRIPTION OF THE INVENTION 
       [0025]      FIG. 1  illustrates a top-level multiobject with several subordinate multiobjects. In the figure, memory addresses run from left to right. ( 100 ) illustrates the address range of the top-level multiobject. ( 101 ) illustrate attached subordinate multiobjects. ( 102 ) illustrates an implicit pointer contained somewhere (exact position generally not known) in the containing multiobject, in this case the top-level multiobject. ( 103 ) illustrates space rendered inaccessible by a write to within the multiobject (somewhere outside the shaded area). ( 104 ) illustrates a detached subordinate multiobject contained within the inaccessible space (the detached subordinate is accessible if it is still referenced from some live multiobject; however, there is no implicit pointer to it). ( 105 ) illustrates a zombie multiobject whose address range equals the shaded free space range ( 103 ), representing space whose free space has already been considered in the region&#39;s unused space. 
         [0026]    In the description below it is assumed that zombie multiobjects never have another zombie as an immediate subordinate. Such zombie chains should be eliminated by the zombie eliminator discussed below. However, one skilled in the art could also construct embodiments where such chains are allowed, without deviating from the spirit of the invention. In an actual implementation the zombie elimination might not be a separate step but might be implemented as additional cases in the flowcharts so that the redundant zombies are never created in the first place. Presenting their elimination as a separate step simplifies the description. 
         [0027]      FIG. 2  illustrates freeing a multiobject by a free handler. Only additional steps relating to tracking unused space are shown; these steps would be combined with the steps for normal multiobject freeing, as described in the referenced earlier disclosure. These steps could go before, after, or interleaved with the other freeing related steps. (Freeing zombies is not shown here, as they are not explicitly freed in most embodiments.) The flow chart is shown assuming that no top-level zombies are created (some embodiments might want to create zombies also for top-level multiobjects). 
         [0028]    The unused space tracking related freeing actions start at ( 200 ). At ( 201 ) it may be checked if the multiobject is an attached sub; no space is freed by freeing such multiobjects. At ( 202 ) the size of the multiobject being freed is added to unused space (size can be computed by subtracting the start address of its range from the end address of its range). At ( 203 ) the sizes of all of its direct subordinates (whether attached, detached, or zombie) are subtracted from the unused space (the addition/subtractions in steps ( 202 ) and ( 203 ) can be made either directly to the region&#39;s field, or to some local variable and finally adding the result to the region&#39;s field, or in some other suitable manner). 
         [0029]    At ( 204 ) it is checked if the multiobject being freed is a top-level multiobject. If so, it is simply freed (its subordinates would usually be promoted before freeing it). At ( 206 ) the multiobject being freed is turned into a zombie (preferably by just changing its type field, but it is also possible to create a new multiobject descriptor and free the old one). 
         [0030]    Step ( 207 ) illustrates eliminating redundant zombie multiobjects. A zombie multiobject is redundant if it is a direct subordinate of another zombie multiobject or if it is a top-level multiobject. ( 208 ) indicates the end of the unused space tracking actions. 
         [0031]    One possible way of implementing redundant zombie elimination is to free any direct zombie subordinates after step ( 203 ). 
         [0032]      FIG. 3  illustrates processing the old value after a write (typically the written address and the old value are obtained from a write barrier buffer). 
         [0033]    Processing the old value begins at ( 300 ). If the old value refers to a multiobject root at ( 301 ), then nothing needs to be done to update unused space (if the multiobject whose root it refers to is no longer reachable, then it will be freed separately later). Not shown in the figure is that if the old value does not contain a pointer to an object in the multiobject space, also then nothing needs to be done. 
         [0034]    At ( 302 ) the address range of the subtree rooted at the object pointed to by the old value is determined (in many embodiments, the range as it was when the top-level multiobject was created). At ( 303 ) the size of the range is added to unused space. At ( 304 ) the sizes of all direct subordinate multiobjects of the multiobject within which the object at the old value is directly contained in the address range are subtracted from unused space. (The computation could also be done using a local variable, and then adding the final result to unused space.) 
         [0035]    At ( 305 ) a new zombie multiobject is created for the address range. At ( 306 ) the direct subordinate multiobjects are preparented to be direct subordinates of the new zombie multiobject. 
         [0036]    At ( 307 ) redundant zombies are eliminated. They could also be eliminated by freeing any direct zombie subordinates after step ( 304 ). At ( 308 ) the processing of the value is complete. 
         [0037]    In some embodiments the write barrier buffer will deliver written addresses in random order. It is possible in some embodiments that the direct containing multiobject of the object pointed to by the old value is already a zombie. In that case the space freed by the latter write has already been counted as free by the write that created the parent zombie, and no unused space needs to be added. 
         [0038]      FIG. 4  illustrates a data processing device according to an embodiment of the invention. ( 401 ) represents one or more processors, ( 402 ) represents one or more memory devices, ( 403 ) represents an I/O subsystem (typically comprising non-volatile storage), ( 404 ) represents a communications network (such as Internet, cluster interconnect, or telephone network, possibly wireless). ( 405 ) illustrates one or more nursery memory areas where new objects are created. ( 406 ) illustrates one or more multiobject spaces comprising multiobjects (in the preferred embodiment no other data is stored in the multiobject space). ( 407 ) illustrates a top-level multiobject. ( 408 ) illustrates a zombie multiobject. ( 409 ) illustrates a detached subordinate multiobject. ( 410 ) illustrates a free handler for performing unused free space tracking; it is a component of the mechanism for freeing multiobjects. ( 411 ) illustrates a write handler, a component used for handling free space tracking when cells within existing multiobjects have been written. ( 412 ) illustrates a zombie eliminator, illustrating a component for eliminating redundant zombies (in many embodiments its functionality may be integrated into the free handler and write handler components). 
         [0039]    An aspect of the present invention is a method of tracking unused space in a memory region in a data processing device comprising a free handler adapted to creating zombie multiobjects, the method comprising:
       creating at least one zombie multiobject; and   using at least one zombie multiobject in tracking unused space in a memory region.       
 
         [0042]    Another aspect of the present invention is a data processing device comprising:
       a multiobject space; and   a free handler adapted to creating zombie multiobjects when multiobjects are freed from the multiobject space, and using at least one zombie multiobject in tracking unused space in at least one portion of the multiobject space.       
 
         [0045]    A further aspect of the present invention is a computer program product operable to cause a data processing device to:
       comprise a multiobject space;   comprise a free handler adapted to creating multiobjects; and   use at least one zombie multiobject in tracking unused space in at least one portion of the multiobject space.       
 
         [0049]    Such a computer program product could be stored on a computer readable medium or transmitted as computer interpretable signals. 
         [0050]    Even though the invention was described as using a count of unused space associated with each independently collectable region, it could equivalently be used with used space counts (essentially just swapping addition and subtraction; unused space basically equals region size minus used space). The granularity at which the counts are maintained could vary; they could equally well be at sub-region granularity or collectively for several regions. The counts need not be stored in the region&#39;s descriptor; they could be in separate memory locations associated with the regions (or whatever is the granularity of tracking; basically any portion of the multiobject space could be tracked individually). The counts may be in any appropriate units, such as bytes, words, cells, or object alignment units. Even though it was described that the sizes of all direct subordinate multiobjects be subtracted from the unused count, in some embodiments there could be multiobject types whose values should not be subtracted (e.g., special multiobjects describing popularity statistics for a particular object in anticipation of promoting it to be a popular object). 
         [0051]    The exact semantics of zombie multiobjects could be varied by one skilled in the art, with corresponding changes in how the space used by subordinate multiobjects is taken into account. Even though multiobjects were described as forming a strict hierarchy, they could also be arranged on a linear axis (e.g., by memory addresses). As an alternative to having nested multiobjects, one could have discontiguous multiobjects, in which case a multiobject would be split if another multiobject was created within it. Such multiobjects could be merged when a multiobject between such parts is freed. Such approaches would still be essentially equivalent with the present invention. 
         [0052]    Many variations of the present invention will be within reach of an ordinary person skilled in the art. Many of the steps in the methods could be rearranged, or operations grouped differently into components of a data processing device, without deviating from the spirit of the invention. When an element or step is mentioned in the claims, the intention is to mean that one or more such elements may be present. When multiple steps are listed, the intention is to say that the steps may take place in any order or possibly simultaneously, subject only to data flow constraints (i.e., the values used by a step must be available before they are used by the step). When a known computing method or algorithm is mentioned in the description or claims, the intention is that any known or future variant or known algorithm for solving the same problem can be used, any specific algorithm variant mentioned serving only as an example. 
         [0053]    It is to be understood that the aspects and embodiments of the invention described herein may be used in any combination with each other. Several of the aspects and embodiments may be combined together to form a further embodiment of the invention. A method, a data processing device, or a computer program product which is an aspect of the invention may comprise any number of the embodiments or elements of the invention described herein.