This document generally relates to the management of memory in a computer system, and more particularly, to the management of memory in support of garbage collection.
Garbage collection, also commonly referred to as automatic memory management, attempts to automatically recycle dynamically allocated memory. Dynamically allocated memory is memory that is created at runtime and that is stored in an area of memory commonly referred to as the heap. There are several techniques that have been developed to perform garbage collection.
One technique is full garbage collection. During full garbage collection, the entire heap is analyzed to determine which memory to recycle. A disadvantage with this technique is that as the heap becomes larger and larger, garbage collection causes a significant delay to programs that are executing. This delay prohibits utilizing full garbage collection when the heap becomes too large.
Another type of garbage collection, commonly referred to as an incremental, generational, or ephemeral garbage collection, attempts to overcome this execution delay by dividing the heap into two or more generations. Newly created objects are allocated in the “youngest” generation. Ephemeral garbage collection then analyzes the “youngest” generation frequently in order to collect and recycle these objects. The older generations are analyzed less frequently, and, when recycled, all of the objects in the older generation are recycled together. Objects in the “youngest” generation that survive a certain number of collections may be “promoted” to the next older generation. Because the ephemeral garbage collection is typically performed on a small portion of the entire heap, ephemeral garbage collection does not impact the execution of programs in a significant manner.
However, even though ephemeral garbage collection does not directly impact the execution of programs in a significant manner, it does cause other problems. One problem occurs when older generations contain pointers that reference younger generations. Without scanning all the older generations, objects in the younger generation may be erroneously recycled. However, if all the generations are scanned, then the benefits of having multiple generations disappear. Fortunately, techniques have been developed to overcome this problem.
One technique, commonly referred to as card marking, divides the heap into cards of equal size. The size of the card may vary, but it is typically bigger than a word and smaller than a page. There are various acceptable methods of marking objects. For example, a single bit within a card bitmap can be changed to indicate when the memory associated with the card has been “touched” or accessed (e.g., written to). Thus, when performing ephemeral garbage collection, the objects in the youngest generation and the objects in each of the cards in the older generations that are indicated as being written into are analyzed. The term “written card” is used through-out this document to refer to a card that contains memory locations that have been “touched”. While card marking greatly reduces the amount of heap that is analyzed during garbage collection, the efficiency of card marking is dependent on the size of the heap. For example, if the card size becomes too large, the cost of analyzing each of the objects in each of the marked cards becomes prohibitive. On the other hand, if the card size is too small and there are numerous cards, the overhead of having so many cards becomes prohibitive. Thus, the benefit of ephemeral garbage collection employing card marking also decreases as the size of the heap increases.
Recently, a new technique has emerged that helps minimize the dependency of ephemeral garbage collection on the heap size. This new technique implements a hierarchy of bundles where each bundle is associated with multiple cards. A bundle bit map is employed where each bit represents one of the bundles. During garbage collection, the bundle bit map is checked to determine which bundles have objects that have been accessed. If the bundle bit map indicates that an object within the bundle has been accessed, each card in that bundle is checked to see if it has been accessed. If it has, then each of its objects is checked. While this technique improves the efficiency of the ephemeral garbage collection, the cost of executing the program is doubled. For example, turning to
Thus, until now, there has not been a satisfactory solution for ephemeral garbage collection of a large heap.
The techniques and mechanisms described herein are directed to a system for performing garbage collection on a large heap. The heap is divided into cards, which are grouped into bundles. Briefly stated, the techniques include initiating a write-watch mechanism to track accesses to specified cards. The write-watch mechanism provides a list of the written cards to a garbage collection process which determines marked (accessed) bundles based on the list. For each marked bundle, the marked cards within the marked bundle are scanned to identify the accessed objects. The accessed objects are then collected. Because determining the marked bundles is performed at the start of the garbage collection process and not whenever the cards within the bundle are accessed, the present technique reduces the overhead associated with bundle marking and allows the efficiency of the garbage collection process to be less dependent on heap size.
Non-limiting and non-exhaustive embodiments are described with reference to the following figures, wherein like reference numerals refer to like parts throughout the various views unless otherwise specified.
Briefly, the present system and method minimize the overhead required in implementing bundle and card marking in ephemeral garbage collection. This is achieved by utilizing a memory management feature known as “write-watch” that is responsible for tracking modifications to specified memory locations. The “write-watch” information is used by the ephemeral garbage collection process to determine which bundles in the older generations have objects that need to be collected. The “write-watch” mechanism tracks the first access to specified memory locations and does not track subsequent accesses to the specified memory locations. As will be described in detail below, the present ephemeral garbage collection process allows the program to execute more efficiently without adding unnecessary overhead. These and other advantages will become clear after reading the following detailed description.
Exemplary Operating Environment
During runtime, application 206 is executed by utilizing framework 208, runtime environment 210, and operating system 212. Framework 208 may be a set of libraries or other services. Runtime environment is responsible for performing many services, such as encryption, security, Just-in-Time (JIT) compilation, and others. One service pertinent to the present technique is garbage collection 220. Briefly, garbage collection 220, described below in conjunction with the flow diagram in
Exemplary Computing Environment
The various embodiments of the present ephemeral garbage collection may be implemented in different computer environments. The computer environment shown in
With reference to
Computing device 300 may have additional features or functionality. For example, computing device 300 may also include additional data storage devices (removable and/or non-removable) such as, for example, magnetic disks, optical disks, or tape. Such additional storage is illustrated in
Computing device 300 may also contain communication connections 316 that allow the device to communicate with other computing devices 318, such as over a network. Communication connection(s) 316 is one example of communication media. Communication media may typically be embodied by computer readable instructions, data structures, program modules, or other data in a modulated data signal, such as a carrier wave or other transport mechanism, and includes any information delivery media. The term “modulated data signal” means a signal that has one or more of its characteristics set or changed in such a manner as to encode information in the signal. By way of example, and not limitation, communication media includes wired media such as a wired network or direct-wired connection, and wireless media such as acoustic, RF, infrared and other wireless media. The term computer readable media as used herein includes both storage media and communication media.
Various modules and techniques may be described herein in the general context of computer-executable instructions, such as program modules, executed by one or more computers or other devices. Generally, program modules include routines, programs, objects, components, data structures, etc. for performing particular tasks or implement particular abstract data types. These program modules and the like may be executed as native code or may be downloaded and executed, such as in a virtual machine or other just-in-time compilation execution environment. Typically, the functionality of the program modules may be combined or distributed as desired in various embodiments.
An implementation of these modules and techniques may be stored on or transmitted across some form of computer readable media. Computer readable media can be any available media that can be accessed by a computer. By way of example, and not limitation, computer readable media may comprise “computer storage media” and “communications media.”
The garbage collector 222 is responsible for reclaiming memory from memory heap 402. The memory heap 402 includes memory allocated for static objects, global objects, local variables, pointers, and such for each application 206 that is executing or that has executed. In addition, the memory heap 402 includes objects allocated for the operating system and the runtime environment. Typically, the objects allocated for the operating system and the runtime environment are considered long-lived objects and are not necessarily collected during the ephemeral garbage collection.
In order to separate long-lived objects from the short-lived objects, the memory heap 402 is divided into one or more generations (e.g., generations 410-416). The size of each generation 410-416 is configurable and is, typically, a contiguous range of bytes in the system memory 304. However, the size of each generation may not be identical. For example, because the ephemeral generation (e.g., generation 410) contains short lived objects which are garbage collected more frequently, the ephemeral generation may be considerably smaller than older generations (e.g., generations 410-416), which hold long-lived objects. Each of the generations are further divided into a pre-determined number of cards (e.g., cards 420-434), where the card size is typically the same and range from a byte to a page in size. A pre-determined number of cards (e.g., 420-424) are grouped into a plurality of bundles (e.g., bundle 440). While
In order to aid in the ephemeral garbage collection process, the program data 307 also includes a card table 404. The card table identifies which cards in the generations 410-416 have an object that has been accessed (e.g., written to). When there are multiple generations (e.g., generations 412-416), there may be one card table for each generation or one card table may handle all the cards for all the generations. In one implementation, the card table may be a bit map having one bit for each card. The bit for each card indicates which cards are associated with an object that has been accessed. The bit may indicate this by being set or by being clear. In other implementation, multiple bits may be used to indicate the status of each card. As shown in
The program data 307 also includes a bundle table 406 and write-watch information 408. The write-watch information 408 contains information describing the cards that have been written to since the garbage collection process was last performed. The bundle table 406 maintains information for each bundle (e.g., bundle 440). There may be one bundle table for the entire heap, multiple bundle tables based on the number of generations, multiple bundle tables based on the heap size, or the like. In one implementation, the size of memory associated with each bundle is a page of card table memory. As will be explained later in conjunction with
At block 504, each statement in the program is processed for execution. If the statement is executable code, the statements do not need additional compilation. However, if the program is an assembly, a JIT compiler may need to perform additional compilation on the statements before the statements are considered executable statements. Processing continues at decision block 506.
At decision block 506, a determination is made whether the statement includes a store operator, such as an equal (“=”). If the statement does not have a store operator, the statement is executed at block 508 using processing known to those skilled in the art. Otherwise, processing continues at block 510.
At block 510, a value specified in the statement is stored at a location specified in the statement. Thus, the value is stored somewhere in the memory heap. Processing continues at decision block 512.
At decision block 512, a determination is made whether the location is within the ephemeral generation. Because locations within the ephemeral generation are already collected during the ephemeral garbage collection, additional processing is not necessary. If the location is within the ephemeral generation, processing continues to block 504 where the next statement is retrieved. Otherwise, processing continues at block 514.
At block 514, a card associated with the location is set. This may involve setting a bit in the card bitmap table associated with the location. As mentioned above, the processing performed in block 514 is considered overhead for executing the store operator. Thus, the execution of the program will incur a delay in execution. After the card is set (or cleared) in block 514, processing then continues to block 504 until each of the statements in the program have been processed.
Of interest, one will note that even though the present ephemeral garbage collection process utilizes both bundles and cards, the bundles are not set while processing each statement of the program. Thus, the additional overhead statement (e.g., statement 108 in
At block 604, the bundle table is updated based on the write-watch information. The bundle table is updated by marking each bundle that has one of its cards identified within the list. Marking of the bundle table may be performed in various ways. One technique is to set or clear a bit in a bitmap, where each bit is associated with a particular bundle. As illustrated in
At block 606, the bundle tables(s) are scanned to determine which bundles indicate that one of the cards associated with the bundle have been accessed. For each bundle that indicates that the bundle has been accessed, processing of “For” loop 608-609 is performed. Within “For” loop 608-609, at block 610, the card table is scanned to determine which cards in the bundle have been set. For any card in the bundle that is set, “For” loop 612-613 is performed.
In “For” loop 612-613, at block 614, each object in the card is scanned. The processing performed in block 614 may use conventional garbage collection processing utilized with card-marking. Once all the object have been identified in block 614, at block 616, the objects in the card that have been accessed may be collected in various manners that are known to those skilled in the art. For example, the accessed objects may be moved to the ephemeral generation or the like. Once each object in each card of each bundle that has been set has been processed, the ephemeral process 600 may reset the card table and the bundle table as needed.
Thus, as illustrated in
The 4 giga-byte memory heap may be divided into 1,048,576 (i.e., 1M) worth of pages (4 Gbytes/4K). Thus, 128*1M cards covers the entire 4 Gbytes of memory heap. Thus, 16 Mbytes ((16 bytes/128 cards)*(128*1M cards)) of card table memory is utilized to cover the 4 Gbytes of memory heap. The write-watch mechanism may then be set to monitor the 16 Mbytes of card table memory, which effectively tracks the entire 4 Gbytes of memory.
By instructing the write-watch mechanism to track updates to the card table, the present ephemeral garbage collection process may utilize the existing code that performs the card-marking function for the garbage collection process without modifying or re-testing the code. In addition, the write-watch mechanism does not add additional costs to implement or adversely affect run-time performance for implementing bundles in the present ephemeral garbage collection process.
Reference has been made throughout this specification to “one embodiment,” “an embodiment,” or “an example embodiment” meaning that a particular described feature, structure, or characteristic is included in at least one embodiment of the present invention. Thus, usage of such phrases may refer to more than just one embodiment. Furthermore, the described features, structures, or characteristics may be combined in any suitable manner in one or more embodiments.
One skilled in the relevant art may recognize, however, that the invention may be practiced without one or more of the specific details, or with other methods, resources, materials, etc. In other instances, well known structures, resources, or operations have not been shown or described in detail merely to avoid obscuring aspects of the invention.
While example embodiments and applications have been illustrated and described, it is to be understood that the invention is not limited to the precise configuration and resources described above. Various modifications, changes, and variations apparent to those skilled in the art may be made in the arrangement, operation, and details of the methods and systems of the present invention disclosed herein without departing from the scope of the claimed invention.
| Number | Name | Date | Kind |
|---|---|---|---|
| 4296476 | Mayer et al. | Oct 1981 | A |
| 4432067 | Nielsen | Feb 1984 | A |
| 4905280 | Wiedemer | Feb 1990 | A |
| 4989134 | Shaw | Jan 1991 | A |
| 5237673 | Orbits et al. | Aug 1993 | A |
| 5382983 | Kwoh et al. | Jan 1995 | A |
| 5459487 | Bouton | Oct 1995 | A |
| 5550575 | West et al. | Aug 1996 | A |
| 5551701 | Bouton et al. | Sep 1996 | A |
| 5558339 | Perlman | Sep 1996 | A |
| 5592651 | Rackman | Jan 1997 | A |
| 5598276 | Cookson et al. | Jan 1997 | A |
| 5634849 | Abecassis | Jun 1997 | A |
| 5649862 | Sakaguchi et al. | Jul 1997 | A |
| 5716273 | Yuen | Feb 1998 | A |
| 5752883 | Butcher et al. | May 1998 | A |
| 5791992 | Crump et al. | Aug 1998 | A |
| 5842016 | Toutonghi et al. | Nov 1998 | A |
| 5845298 | O'Connor et al. | Dec 1998 | A |
| 5848423 | Ebrahim et al. | Dec 1998 | A |
| 5857210 | Tremblay et al. | Jan 1999 | A |
| 5873104 | Tremblay et al. | Feb 1999 | A |
| 5873105 | Tremblay et al. | Feb 1999 | A |
| 5876286 | Lee | Mar 1999 | A |
| 5878134 | Handelman et al. | Mar 1999 | A |
| 5896125 | Niedzwiecki | Apr 1999 | A |
| 5900001 | Wolczko et al. | May 1999 | A |
| 5903899 | Steele, Jr. | May 1999 | A |
| 5903900 | Knippel et al. | May 1999 | A |
| 5909579 | Agesen et al. | Jun 1999 | A |
| 5911144 | Schwartz et al. | Jun 1999 | A |
| 5915255 | Schwartz et al. | Jun 1999 | A |
| 5917256 | Broadbent, II | Jun 1999 | A |
| 5920876 | Ungar et al. | Jul 1999 | A |
| 5930807 | Ebrahim et al. | Jul 1999 | A |
| 5953736 | O'Connor et al. | Sep 1999 | A |
| 5969283 | Looney et al. | Oct 1999 | A |
| 5973683 | Cragun et al. | Oct 1999 | A |
| 5978920 | Lee | Nov 1999 | A |
| 5993319 | Aoyama | Nov 1999 | A |
| 6001015 | Nishiumi et al. | Dec 1999 | A |
| 6009433 | Kurano et al. | Dec 1999 | A |
| 6025869 | Stas et al. | Feb 2000 | A |
| 6049810 | Schwartz et al. | Apr 2000 | A |
| 6065020 | Dussud | May 2000 | A |
| 6115079 | McRae | Sep 2000 | A |
| 6115782 | Wolczko et al. | Sep 2000 | A |
| 6148309 | Azagury et al. | Nov 2000 | A |
| 6148310 | Azagury et al. | Nov 2000 | A |
| 6161185 | Guthrie et al. | Dec 2000 | A |
| 6173294 | Azagury et al. | Jan 2001 | B1 |
| 6185581 | Garthwaite | Feb 2001 | B1 |
| 6224485 | Dickinson et al. | May 2001 | B1 |
| 6226653 | Alpern et al. | May 2001 | B1 |
| 6230320 | Gakumura | May 2001 | B1 |
| 6249793 | Printezis et al. | Jun 2001 | B1 |
| 6280327 | Leifer et al. | Aug 2001 | B1 |
| 6280329 | Kondo et al. | Aug 2001 | B1 |
| 6298441 | Handelman et al. | Oct 2001 | B1 |
| 6299535 | Tanaka | Oct 2001 | B1 |
| 6308185 | Grarup et al. | Oct 2001 | B1 |
| 6309301 | Sano | Oct 2001 | B1 |
| 6312336 | Handelman et al. | Nov 2001 | B1 |
| 6317756 | Kolodner et al. | Nov 2001 | B1 |
| 6320320 | Bailey, III et al. | Nov 2001 | B1 |
| 6393430 | Van Ryzin | May 2002 | B1 |
| 6396531 | Gerszberg et al. | May 2002 | B1 |
| 6464585 | Miyamoto et al. | Oct 2002 | B1 |
| 6468160 | Eliott | Oct 2002 | B2 |
| 6470361 | Alpern et al. | Oct 2002 | B1 |
| 6490599 | Kolodner et al. | Dec 2002 | B2 |
| 6502111 | Dussud | Dec 2002 | B1 |
| 6510440 | Alpern et al. | Jan 2003 | B1 |
| 6520890 | Hsu | Feb 2003 | B2 |
| 6529919 | Agesen et al. | Mar 2003 | B1 |
| 6535269 | Sherman et al. | Mar 2003 | B2 |
| 6599194 | Smith et al. | Jul 2003 | B1 |
| 6601171 | Carter et al. | Jul 2003 | B1 |
| 6712704 | Eliott | Mar 2004 | B2 |
| 6738875 | Wang | May 2004 | B1 |
| 6769989 | Smith et al. | Aug 2004 | B2 |
| 6829686 | Mathiske et al. | Dec 2004 | B2 |
| 6845347 | Yang et al. | Jan 2005 | B1 |
| 6845437 | Borman et al. | Jan 2005 | B2 |
| 6928460 | Nagarajan et al. | Aug 2005 | B2 |
| 7065617 | Wang | Jun 2006 | B2 |
| 20010004609 | Walker et al. | Jun 2001 | A1 |
| 20020077177 | Elliott | Jun 2002 | A1 |
| 20030008715 | Huber et al. | Jan 2003 | A1 |
| 20040003014 | Nagarajan et al. | Jan 2004 | A1 |
| 20040162137 | Eliot | Aug 2004 | A1 |
| 20040187102 | Garthwaite | Sep 2004 | A1 |
| 20040199742 | Wang | Oct 2004 | A1 |
| Number | Date | Country |
|---|---|---|
| 100 46 437 | Apr 2002 | DE |
| 0 809 214 | Nov 1997 | EP |
| 0 889 420 | Jan 1999 | EP |
| 0 998 966 | May 2000 | EP |
| 1 035 706 | Sep 2000 | EP |
| 1 126 425 | Aug 2001 | EP |
| 2 743 434 | Jul 1997 | FR |
| WO 9848353 | Oct 1998 | WO |
| WO 0040027 | Jul 2000 | WO |
| WO 0051036 | Aug 2000 | WO |
| WO 0105477 | Jan 2001 | WO |
| WO 0108148 | Feb 2001 | WO |
| WO 0184768 | Nov 2001 | WO |
| Number | Date | Country | |
|---|---|---|---|
| 20050235120 A1 | Oct 2005 | US |