Login| Sign Up| Help| Contact|

Patent Searching and Data


Title:
INCREMENTAL CLASS UNLOADING IN A TRAIN-ALGORITHM-BASED GARBAGE COLLECTOR
Document Type and Number:
WIPO Patent Application WO/2001/061472
Kind Code:
A2
Abstract:
A garbage collector collects a train-managed heap in accordance with the train algorithm. In doing so, it concentrates into a respective train the heap-located objects that belong to garbage cycles even if those cycles additionally include certain types of objects that are outside the train-managed heap. It does so by using objects within the heap as proxies for those extra-heap objects, and it evacuates into a proxy object's train any collection-set objects referred to by the extra-heap objects for which the proxy object is a proxy. The objects in those garbage cycles containing the extra-heap objects can thereby be collected incrementally despite the extra-heap references to them.

Inventors:
GARTHWAITE ALEXANDER T
AGESEN OLE
Application Number:
PCT/US2001/004806
Publication Date:
August 23, 2001
Filing Date:
February 14, 2001
Export Citation:
Click for automatic bibliography generation   Help
Assignee:
SUN MICROSYSTEMS INC (US)
International Classes:
G06F9/44; G06F12/02; (IPC1-7): G06F9/00
Foreign References:
EP0940755A11999-09-08
Other References:
B. VENNERS: "Inside the Java 2 Virtual Machine" [Online] , ADDISON-WESLEY , 12-99 XP002174290 Retrieved from the Internet: [retrieved on 2001-08-08] Chapter 9 Part 9-16
HUDSON ET AL: "Incremental Collection of Mature Objects" MEMORY MANAGEMENT. INTERNATIONAL WORKSHOP IWMM. PROCEEDINGS, XX, XX, September 1992 (1992-09), pages 388-406, XP002105707
SELIGMAN ET AL: "Incremental Mature Garbage Collection Using the Train Algorithm" ECOOP. EUROPEAN CONFERENCE ON OBJECT-ORIENTED PROGRAMMING, XX, XX, vol. 952, 26 March 1995 (1995-03-26), pages 235-252, XP002105706
Attorney, Agent or Firm:
Born, Joseph H. (LLP 88 Black Falcon Avenue Boston, MA, US)
Download PDF:
Claims:
What is claimed is: CLAIMS
1. A method of garbage collection in which a trainalgorithmmanaged gen eration containing objects located in car sections is collected in accordance with the train algorithm, in collection cycles for which respective collection sets of the car sections are established, by repeatedly establishing new trains, so evacuat ing from the collection sets objects referred to from outside the collection sets as to place objects thus evacuated into the youngest trains containing objects that refer to them, and reclaiming the car sections that remain in the collection set, wherein the method further includes : A) associating a proxy object in the trainalgorithmmanaged genera tion with respective external objects outside the generation; and B) evacuating from the collection set those of its objects that are re ferred to by external objects associated with proxy objects not in the collection set, the trains into which the objects thus evacuated are placed when the respective proxy objects are in the train managed generation being the trains to which the respective proxy objects belong or to which the respective proxy objects are cur rently destined for evacuation.
2. A method as defined in claim 1 that further includes reclaiming the exter nal objects with which are associated proxy objects that remain in the collection set after evacuation.
3. A method as defined in claim 1 wherein the external objects associated with the proxy objects represent object classes.
4. A method as defined in claim 3 that further includes reclaiming the exter nal objects with which are associated proxy objects that remain in the collection set after evacuation.
5. A method as defined in claim 3 wherein the method includes evacuating from the collection set any proxy object with which is an associated external ob ject that represents a class of which an instance exists outside the collection set.
6. A method as defined in claim 5 that further includes reclaiming the exter nal objects with which are associated proxy objects that remain in the collection set after evacuation.
7. A method as defined in claim 5 wherein the method includes, when the collection set contains proxy objects with which are associated external objects that represent classes of which instances exist in trains within the garbage collected generation, evacuating those proxy objects into the trains that contain those instances.
8. A method as defined in claim 7 that further includes reclaiming the exter nal objects with which are associated proxy objects that remain in the collection set after evacuation.
9. A method as defined in claim 7 wherein the trains into which are evacu ated proxy objects when the collection sets contain proxy objects with which are associated external objects that represent classes of which instances exist in trains within the garbagecollected generation are the youngest trains that con tain those instances.
10. A method as defined in claim 9 that further includes reclaiming the exter nal objects with which are associated proxy objects that remain in the collection set after evacuation.
11. A method as defined in claim 9 further comprising: maintaining for each class represented by an external structure associated with a proxy object in the trainalgorithmmanaged generation a youngesttrain identifier of the youngest train containing an instance of that class ; and evacuating proxy objects from the collection sets in accordance with youngesttrain identifier maintained for the classes represented by the external structures with which those proxy objects are associated.
12. A method as defined in claim 11 wherein the method includes maintaining, for each car section that contains a proxy object associated with an external ob ject that represents a class of which a younger train contains an instance, a re membered set containing the youngesttrain identifier for each such class.
13. A method as defined in claim 12 that further includes reclaiming the exter nal objects with which are associated proxy objects that remain in the collection set after evacuation.
14. A method as defined in claim 12 wherein: A) the method includes maintaining for each car section a regular re membered set containing entries corresponding to references into the car section from younger car sections; and B) objects are evacuated from car sections in accordance with the contents of those car sections'regular remembered sets.
15. A method as defined in claim 1 wherein: A) the external objects contain information on which objects in the trainmanaged generation depend; and B) the method further includes evacuating from the collection set those of its proxy objects that are associated with the external objects that contain in formation on which depend objects outside the collection set.
16. A method as defined in claim 15 that further includes reclaiming the exter nal objects with which are associated proxy objects that remain in the collection set after evacuation.
17. A method as defined in claim 15 wherein the train into which is evacuated a proxy object from the collection set if that proxy object is associated with an external object containing information on which an object in a train within the garbagecollected generation depends is least as young as the youngest train that contains an object that depends on that external object.
18. A method as defined in claim 17 that further includes reclaiming the exter nal objects with which are associated proxy objects that remain in the collection set after evacuation.
19. A garbage collector that employs the train algorithm to collect a train algorithmmanaged generation containing objects located in car sections, in col lection cycles for which respective collection sets of the car sections are estab lished, by repeatedly establishing new trains, so evacuating from the collection sets objects referred to from outside the collection sets as to place objects thus evacuated into the youngest trains containing objects that refer to them, and re claiming the car sections that remain in the collection set, wherein the garbage collector : A) associates a proxy object in the trainalgorithmmanaged genera tion with respective external objects outside the generation; and B) evacuates from the collection set those of its objects that are re ferred to by external objects associated with proxy objects not in the collection set, the trains into which the objects thus evacuated are placed when the respective proxy objects are in the train managed generation being the trains to which the respective proxy objects belong or to which the respective proxy objects are cur rently destined for evacuation.
20. A garbage collector as defined in claim 19 that additionally reclaims the external objects with which are associated proxy objects that remain in the col lection set after evacuation.
21. A garbage collector as defined in claim 19 wherein the external objects associated with the proxy objects represent object classes.
22. A garbage collector as defined in claim 21 that additionally reclaims the external objects with which are associated proxy objects that remain in the col lection set after evacuation.
23. A garbage collector as defined in claim 21 that additionally evacuates from the collection set any proxy object with which is an associated external object that represents a class of which an instance exists outside the collection set.
24. A garbage collector as defined in claim 23 that additionally reclaims the external objects with which are associated proxy objects that remain in the col lection set after evacuation.
25. A garbage collector as defined in claim 23 that, when the collection set contains proxy objects with which are associated external objects that represent classes of which instances exist in trains within the garbagecollected generation, evacuates those proxy objects into the trains that contain those instances.
26. A garbage collector as defined in claim 25 that additionally reclaims the external objects with which are associated proxy objects that remain in the col lection set after evacuation.
27. A garbage collector as defined in claim 25 wherein the trains into which are evacuated proxy objects when the collection sets contain proxy objects with which are associated external objects that represent classes of which instances exist in trains within the garbagecollected generation are the youngest trains that contain those instances.
28. A garbage collector as defined in claim 27 that additionally reclaims the external objects with which are associated proxy objects that remain in the col lection set after evacuation.
29. A garbage collector as defined in claim 27 that additionally : maintains for each class represented by an external structure associated with a proxy object in the trainalgorithmmanaged generation a youngesttrain identifier of the youngest train containing an instance of that class ; and evacuates proxy objects from the collection sets in accordance with youngesttrain identifier maintained for the classes represented by the external structures with which those proxy objects are associated.
30. A garbage collector as defined in claim 29 wherein the garbage collector maintains, for each car section that contains a proxy object associated with an external object that represents a class of which a younger train contains an in stance, a remembered set containing the youngesttrain identifier for each such class.
31. A garbage collector as defined in claim 30 that additionally reclaims the external objects with which are associated proxy objects that remain in the col lection set after evacuation.
32. A garbage collector as defined in claim 30 wherein: the garbage collector maintains for each car section a regular remem bered set containing entries corresponding to references into the car section from younger car sections; and objects are evacuated from car sections in accordance with the contents of those car sections'regular remembered sets.
Description:
INCREMENTAL CLASS UNLOADING IN A TRAIN- ALGORITHM-BASED GARBAGE COLLECTOR

BACKGROUND OF THE INVENTION Field of the Invention The present invention is directed to memory management. It particularly concerns what has come to be known as"garbage collection." Background Information In the field of computer systems, considerable effort has been expended on the task of allocating memory to data objects. For the purposes of this dis- cussion, the term object refers to a data structure represented in a computer system's memory. Other terms sometimes used for the same concept are rec- ord and structure. An object may be identified by a reference, a relatively small amount of information that can be used to access the object. A reference can be represented as a"pointer"or a"machine address,"which may require, for instance, only sixteen, thirty-two, or sixty-four bits of information, although there are other ways to represent a reference.

In some systems, which are usually known as"object oriented,"objects may have associated methods, which are routines that can be invoked by ref- erence to the object. They also may belong to a class, which is an organiza- tional entity that may contain method code or other information shared by all objects belonging to that class. In the discussion that follows, though, the term object will not be limited to such structures; it will additionally include structures with which methods and classes are not associated.

The invention to be described below is applicable to systems that allo- cate memory to objects dynamically. Not all systems employ dynamic alloca- tion. In some computer languages, source programs can be so written that all objects to which the program's variables refer are bound to storage locations at compile time. This storage-allocation approach, sometimes referred to as "static allocation,"is the policy traditionally used by the Fortran programming language, for example.

Even for compilers that are thought of as allocating objects only stati- cally, of course, there is often a certain level of abstraction to this binding of objects to storage locations. Consider the typical computer system 10 depicted in Fig. 1, for example. Data, and instructions for operating on them, that a mi- croprocessor 11 uses may reside in on-board cache memory or be received from further cache memory 12, possibly through the mediation of a cache con- troller 13. That controller 13 can in turn receive such data from system read/write memory ("RAM") 14 through a RAM controller 15 or from various pe- ripheral devices through a system bus 16. The memory space made available to an application program may be"virtual"in the sense that it may actually be considerably larger than RAM 14 provides. So the RAM contents will be swapped to and from a system disk 17.

Additionally, the actual physical operations performed to access some of the most-recently visited parts of the process's address space often will actually be performed in the cache 12 or in a cache on board microprocessor 11 rather than on the RAM 14, with which those caches swap data and instructions just as RAM 14 and system disk 17 do with each other.

A further level of abstraction results from the fact that an application will often be run as one of many processes operating concurrently with the support of an underlying operating system. As part of that system's memory manage- ment, the application's memory space may be moved among different actual physical locations many times in order to allow different processes to employ shared physical memory devices. That is, the location specified in the applica- tion's machine code may actually result in different physical locations at differ-

ent times because the operating system adds different offsets to the machine- language-specified location.

Despite these expedients, the use of static memory allocation in writing certain long-lived applications makes it difficult to restrict storage requirements to the available memory space. Abiding by space limitations is easier when the platform provides for dynamic memory allocation, i. e., when memory space to be allocated to a given object is determined only at run time.

Dynamic allocation has a number of advantages, among which is that the run-time system is able to adapt allocation to run-time conditions. For ex- ample, the programmer can specify that space should be allocated for a given object only in response to a particular run-time condition. The C-language li- brary function malloc () is often used for this purpose. Conversely, the pro- grammer can specify conditions under which memory previously allocated to a given object can be reclaimed for reuse. The C-language library function free () results in such memory reclamation.

Because dynamic allocation provides for memory reuse, it facilitates generation of large or long-lived applications, which over the course of their lifetimes may employ objects whose total memory requirements would greatly exceed the available memory resources if they were bound to memory loca- tions statically.

Particularly for long-lived applications, though, allocation and reclama- tion of dynamic memory must be performed carefully. If the application fails to reclaim unused memory-or, worse, loses track of the address of a dynamically allocated segment of memory-its memory requirements will grow over time to exceed the system's available memory. This kind of error is known as a "memory leak." Another kind of error occurs when an application reclaims memory for reuse even though it still maintains a reference to that memory. If the re- claimed memory is reallocated for a different purpose, the application may in- advertently manipulate the same memory in multiple inconsistent ways. This

kind of error is known as a"dangling reference,"because an application should not retain a reference to a memory location once that location is reclaimed.

Explicit dynamic-memory management by using interfaces like malloc ()/free () often leads to these problems.

A way of reducing the likelihood of such leaks and related errors is to provide memory-space reclamation in a more-automatic manner. Techniques used by systems that reclaim memory space automatically are commonly re- ferred to as"garbage collection."Garbage collectors operate by reclaiming space that they no longer consider"reachable."Statically allocated objects represented by a program's global variables are normally considered reachable throughout a program's life. Such objects are not ordinarily stored in the gar- bage collector's managed memory space, but they may contain references to dynamically allocated objects that are, and such objects are considered reach- able. Clearly, an object referred to in the processor's call stack is reachable, as is an object referred to by register contents. And an object referred to by any reachable object is also reachable.

The use of garbage collectors is advantageous because, whereas a programmer working on a particular sequence of code can perform his task creditably in most respects with only local knowledge of the application at any given time, memory allocation and reclamation require a global knowledge of the program. Specifically, a programmer dealing with a given sequence of code does tend to know whether some portion of memory is still in use for that sequence of code, but it is considerably more difficult for him to know what the rest of the application is doing with that memory. By tracing references from some conservative notion of a"root set,"e. g., global variables, registers, and the call stack, automatic garbage collectors obtain global knowledge in a me- thodical way. By using a garbage collector, the programmer is relieved of the need to worry about the application's global state and can concentrate on local- state issues, which are more manageable. The result is applications that are more robust, having no dangling references and fewer memory leaks.

Garbage-collection mechanisms can be implemented by various parts and levels of a computing system. One approach is simply to provide them as part of a batch compiler's output. Consider Fig. 2's simple batch-compiler op- eration, for example. A computer system executes in accordance with compiler object code and therefore acts as a compiler 20. The compiler object code is typically stored on a medium such as Fig. 1's system disk 17 or some other machine-readable medium, and it is loaded into RAM 14 to configure the com- puter system to act as a compiler. In some cases, though, the compiler object code's persistent storage may instead be provided in a server system remote from the machine that performs the compiling. The electrical signals that carry the digital data by which the computer systems exchange that code are exem- plary forms of carrier waves transporting the information.

The input to the compiler is the application source code, and the end product of the compiler process is application object code. This object code defines an application 21, which typically operates on input such as mouse clicks, etc., to generate a display or some other type of output. This object code implements the relationship that the programmer intends to specify by his application source code. In one approach to garbage collection, the com- piler 20, without the programmer's explicit direction, additionally generates code that automatically reclaims unreachable memory space.

Even in this simple case, though, there is a sense in which the applica- tion does not itself provide the entire garbage collector. Specifically, the appli- cation will typically call upon the underlying operating system's memory- allocation functions. And the operating system may in turn take advantage of various hardware that lends itself particularly to use in garbage collection. So even a very simple system may disperse the garbage-collection mechanism over a number of computer-system layers.

To get some sense of the variety of system components that can be used to implement garbage collection, consider Fig. 3's example of a more complex way in which various levels of source code can result in the machine instructions that a processor executes. In the Fig. 3 arrangement, the human

applications programmer produces source code 22 written in a high-level lan- guage. A compiler 23 typically converts that code into"class files."These files include routines written in instructions, called"byte codes"24, for a"virtual ma- chine"that various processors can be configured to emulate. This conversion into byte codes is almost always separated in time from those codes'execu- tion, so Fig. 3 divides the sequence into a"compile-time environment"25 sepa- rate from a"run-time environment"26, in which execution occurs. One exam- ple of a high-level-language environment for which compilers are available to produce such virtual-machine instructions is the Java TM platform. (Java is a trademark or registered trademark of Sun Microsystems, Inc., in the Unites States and other countries.) Most typically, the class files'byte-code routines are executed by a processor under control of a virtual-machine process 27. That process emu- lates a virtual machine from whose instruction set the byte codes are drawn.

As is true of the compiler 23, the virtual-machine process 27 may be specified by code stored on a local disk or some other machine-readable medium from which it is read into Fig. 1's RAM 14 to configure the computer system to act as a virtual machine and implement the garbage collector. Again, though, that code's persistent storage may instead be provided by a server system remote from the processor that implements the virtual machine, in which case the code would be transmitted electrically or optically to the virtual-machine- implementing processor.

In most implementations, much of the virtual machine's action in exe- cuting these byte codes is most like what those skilled in the art refer to as"in- terpreting,"and Fig. 3 shows that the virtual machine includes an"inter- preter"28 for that purpose. The resultant instructions typically invoke calls to a run-time system 29, which handles matters such as loading new class files as they are needed and, of particular interest in the present connection, perform- ing garbage collection.

In addition to running an interpreter, many virtual-machine implementa- tions also actually compile the byte codes concurrently with the resultant object

code's execution, so Fig. 3 depicts the virtual machine as additionally including a"just-in-time"compiler 30.

The arrangement of Fig. 3 differs from Fig. 2 in that the compiler 23 for converting the human programmer's code does not contribute to providing the garbage-collection function; that results largely from the virtual machine 27's operation. Although the Fig. 3 arrangement is a popular one, it is by no means universal, and many further implementation types can be expected. Proposals have even been made to implement the virtual machine 27's behavior in a hardware processor, in which case the hardware itself would provide some or all of the garbage-collection function.

In short, garbage collectors can be implemented in a wide range of combinations of hardware and/or software. As is true of most of the garbage- collection techniques described in the literature, the invention to be described below is applicable to most such systems.

By implementing garbage collection, a computer system can greatly re- duce the occurrence of memory leaks and other software deficiencies in which human programming frequently results. But it can also have significant ad- verse performance effects if it is not implemented carefully. To distinguish the part of the program that does"useful"work from that which does the garbage collection, the term mutator is sometimes used in discussions of these effects; from the collector's point of view, what the mutator does is mutate active data structures'connectivity.

Some garbage-collection approaches rely heavily on interleaving gar- bage-collection steps among mutator steps. In one type of garbage-collection approach, for instance, the mutator operation of writing a reference is followed immediately by garbage-collector steps used to maintain a reference count in that object's header, and code for subsequent new-object storage includes steps for finding space occupied by objects whose reference count has fallen to zero. Obviously, such an approach can slow mutator operation significantly.

Other approaches therefore interleave very few garbage-collector- related instructions into the main mutator process but instead interrupt it from time to time to perform garbage-collection cycles, in which the garbage collec- tor finds unreachable objects and reclaims their memory space for reuse. Such an approach will be assumed in discussing Fig. 4's depiction of a simple gar- bage-collection operation. Within the memory space allocated to a given appli- cation is a part 40 managed by automatic garbage collection. In the following discussion, this will be referred to as the"heap,"although in other contexts that term refers to all dynamically allocated memory. During the course of the ap- plication's execution, space is allocated for various objects 42,44,46,48, and 50. Typically, the mutator allocates space within the heap by invoking the garbage collector, which at some level manages access to the heap. Basically, the mutator asks the garbage collector for a pointer to a heap region where it can safely place the object's data. The garbage collector keeps track of the fact that the thus-allocated region is occupied. It will refrain from allocating that region in response to any other request until it determines that the mutator no longer needs the region allocated to that object.

Garbage collectors vary as to which objects they consider reachable and unreachable. For the present discussion, though, an object will be considered "reachable"if it is referred to, as object 42 is, by a reference in the root set 52.

The root set consists of reference values stored in the mutator's threads'call stacks, the CPU registers, and global variables outside the garbage-collected heap. An object is also reachable if it is referred to, as object 46 is, by another reachable object (in this case, object 42). Objects that are not reachable can no longer affect the program, so it is safe to re-allocate the memory spaces that they occupy.

A typical approach to garbage collection is therefore to identify all reach- able objects and reclaim any previously allocated memory that the reachable objects do not occupy. A typical garbage collector may identify reachable ob- jects by tracing references from the root set 52. For the sake of simplicity, Fig. 4 depicts only one reference from the root set 52 into the heap 40. (Those

skilled in the art will recognize that there are many ways to identify references, or at least data contents that may be references.) The collector notes that the root set points to object 42, which is therefore reachable, and that reachable object 42 points to object 46, which therefore is also reachable. But those reachable objects point to no other objects, so objects 44,48, and 50 are all unreachable, and their memory space may be reclaimed.

To avoid excessive heap fragmentation, some garbage collectors addi- tionally relocate reachable objects. Fig. 5 shows a typical approach. The heap is partitioned into two halves, hereafter called"semi-spaces."For one garbage- collection cycle, all objects are allocated in one semi-space 54, leaving the other semi-space 56 free. When the garbage-collection cycle occurs, objects identified as reachable are"evacuated"to the other semi-space 56, so all of semi-space 54 is then considered free. Once the garbage-collection cycle has occurred, all new objects are allocated in the lower semi-space 56 until yet an- other garbage-collection cycle occurs, at which time the reachable objects are evacuated back to the upper semi-space 54.

Although this relocation requires the extra steps of copying the reach- able objects and updating references to them, it tends to be quite efficient, since most new objects quickly become unreachable, so most of the current semi-space is actually garbage. That is, only a relatively few, reachable ob- jects need to be relocated, after which the entire semi-space contains only gar- bage and can be pronounced free for reallocation.

In one sense, the approach of interrupting the mutator occasionally for garbage collection can increase an application's responsiveness, because the main mutator operation ordinarily proceeds relatively unburdened by garbage- collection overhead. In interactive systems, moreover, interruptions for gar- bage collection can sometimes be scheduled opportunistically so as to reduce the likelihood that they will result in much overall speed reduction. Garbage collection can be triggered when the system is waiting for user input, for in- stance.

So it may often be true that the garbage-collection operation's effect on performance can depend less on the total collection time than on when collec- tions actually occur. But another factor that often is even more determinative is the duration of any single collection cycle, i. e., how long the mutator must re- main quiescent at any one time. In an interactive system, for instance, a user may never notice hundred-millisecond interruptions for garbage collection, whereas most users would find interruptions lasting for two seconds to be an- noying. Many garbage collectors therefore operate incrementally. That is, they perform less than a complete collection in any single interruption of the main application.

A way of not only reducing collection-cycle length but also increasing overall efficiency is to segregate the heap into one or more parts, called gen- erations, that are subject to different collection policies. New objects are allo- cated in a"young"generation, and older objects are promoted from younger generations to older or more"mature"generations. Collecting the younger generations more frequently than the others yields greater efficiency because the younger generations tend to accumulate garbage faster; newly allocated objects tend to"die,"while older objects tend to"survive." But generational collection greatly increases what is effectively the root set for a given generation. Consider Fig. 6, which depicts a heap as organized into three generations 58,60, and 62. Assume that generation 60 is to be col- lected. The process for this individual generation may be more or less the same as that described in connection with Figs. 4 and 5 for the entire heap, with one major exception. In the case of a single generation, the root set must be considered to include not only the call stack, registers, and global variables represented by set 52 but also objects in the other generations 58 and 62, which themselves may contain references to objects in generation 60. So pointers must be traced not only from the basic root set 52 but also from ob- jects within the other generations.

One could perform this tracing by simply inspecting all references in all other generations at the beginning of every collection cycle, and it turns out that

this approach is actually feasible in some situations. But it takes too long in other situations, so workers in this field have employed a number of ap- proaches to expediting reference tracing. One approach is to include so-called write barriers in the mutator process. A write barrier is code added to a write operation to record information from which the collector can determine where references were or may have been written since the last collection cycle. A reference list can then be maintained by taking such a list as it existed at the end of the previous collection cycle and updating it by inspecting only locations identified by the write barrier as possibly modified since the last collection cy- cle.

One of the many such implementations commonly used by workers in this art employs what has been referred to as the"card table."Fig. 6 depicts the various generations as being divided into smaller sections, known for this purpose as"cards."Card tables 64,66, and 68 associated with respective generations contain an entry for each of their cards. Each card-table entry in- cludes some summary of its associated card's inter-generational-reference content. This summary may be no more than a binary indication of whether such a reference exists, but it preferably includes a list of offsets that indicate such references'locations in the card. Part of entry 69, for instance, may be an offset that indicates the location of an inter-generational reference 70 within the corresponding card 72. For the sake of concreteness, we will assume that the summaries are maintained by steps that occur principally at the beginning of each collection cycle.

Of course, the card-table approach is only one of many that can be em- ployed to detect inter-generational pointers. Indeed, it is typical for an individ- ual garbage collector to use more than one approach. Although there is no reason in principle to favor any particular number of generations, and although Fig. 6 shows three, most generational garbage collectors have only two gen- erations, of which one is the young generation and the other is the mature gen- eration. Moreover, although Fig. 6 shows the generations as being of the same size, a more-typical configuration is for the young generation to be considerably

smaller. Finally, although we assumed for the sake of simplicity that collection during a given cycle was limited to only one generation, a more-typical ap- proach is actually to collect the whole young generation at every cycle but to collect the mature one less frequently.

To collect the young generation, it is preferable to employ the card table to identify pointers into the young generation; laboriously scanning the entire mature generation would take too long. On the other hand, since the young generation is collected in every cycle and can therefore be collected before mature-generation processing, it takes little time to scan the few remaining, live objects in the young generation for pointers into the mature generation in order to process that generation. For this reason, the card table will typically be so maintained as only to identify the regions occupied by references into younger generations and not into older ones.

Now, although it typically takes very little time to collect the young gen- eration, it may take more time than is acceptable within a single garbage- collection cycle to collect the entire mature generation. So some garbage col- lectors may collect the mature generation incremental ; that is, they may per- form only a part of the mature generation's collection during any particular col- lection cycle. Incremental collection presents the problem that, since the gen- eration's objects that are outside a collection cycle's collection set are not proc- essed during that cycle, any such objects that are unreachable are not recog- nized as unreachable, so collection-set objects to which they refer tend not to be, either.

To reduce the adverse effect this would otherwise have on collection ef- ficiency, workers in this field have employed the"train algorithm,"which Fig. 7 depicts. A generation to be collected incrementally is divided into sections, which for reasons about to be described are referred to as"car sections."The generation may be collected incrementally in fixed-size sections, in which case the size may equal that of the generation portion to be collected during one cy- cle. More typically, the fraction of the generation to be collected during any one cycle varies with run-time conditions, in which case the car-section size is often

that of the minimum fraction to be collected in one cycle, although that is not a requirement.

The discussion that follows will occasionally follow the nomenclature in the literature by using the term car instead of car section. But the literature seems to use that term to refer variously not only to memory sections them- selves but also to data structures that the train algorithm employs to manage them when they contain objects, as well as to the more-abstract concept that the car section and managing data structure represent in discussions of the al- gorithm. So the following discussion will more frequently use the expression car section to emphasize the actual sections of memory space for whose man- agement the car concept is employed.

Additionally, the car sections are grouped into"trains,"which are ordered according to age. For example, Fig. 7 shows an oldest train 73 consisting of a generation 74's three car sections described by associated data structures 75, 76, and 78, while a second train 80 consists only of a single car section, repre- sented by structure 82, and the youngest train 84 (referred to as the"allocation train") consists of car sections that data structures 86 and 88 represent. As will be seen below, car sections'train memberships can change, and any car sec- tion added to a train is added to the end of a train. Train size is a matter of de- sign choice, but its purpose is to maximize the probability that garbage refer- ence"cycles"can be reclaimed, as will now be explained.

Although more than one car section may be collected in any given cycle, little generality is lost by considering the situation in which only a single car is collected during any cycle. The car collected in any cycle is the one added least recently to the oldest train. In Fig. 7, that car would be car 75. All of the generation's cars can thus be thought of as waiting for collection in a single long line, in which cars in a given train are farther forward than those in any younger train, and those added to a train more recently are behind those added to it earlier.

As is usual, the way in which reachable objects are identified is to de- termine whether there are references to them in the root set or in any other

object already determined to be reachable. In accordance with the train algo- rithm, the collector additionally performs a test to determine whether there are any references at all from outside the oldest train to objects within it. If there are none, then all cars within the train can be reclaimed, even though not all of those cars are in the collection set. And the train algorithm so operates that inter-car references tend to be grouped into trains, as will now be explained.

To identify references into the car from outside of it, train-algorithm im- plementations typically employ"remembered sets."As card tables are, re- membered sets are used to keep track of references. Whereas a card-table entry contains information about references that the associated card contains, though, a remembered set associated with a given region contains information about references into that region from locations outside of it. In the case of the train algorithm, remembered sets are associated with car sections. Each re- membered set, such as car 75's remembered set 90, lists locations in the gen- eration that contain references into the associated car section. The remem- bered sets for all of a generation's cars are typically updated at the start of each collection cycle, concurrently with card-table updates. For reasons that will become apparent, the collector will typically not bother to place in the re- membered set the locations of references from objects in car sections farther forward in the collection queue, i. e., from objects in older trains or cars added earlier to the same train. For the sake of simplicity, we will continue the as- sumption that only a single car is collected during each collection cycle, al- though we will discuss multiple-car collection sets presently.

When the remembered sets have been updated, the collector reads the remembered set of each car in the collection set to determine the location of each reference from a higher-order car into the collection set. The collector places the address of each reference thereby found into a scratch-pad list as- sociated with the train that contains that reference. (Again, the remembered set lists only reference locations in the same generation.) When the collector has read all references in the remembered set, it evacuates into the youngest train the collection-set-car objects referred to by

the references in the locations that the youngest train's scratch-pad-list entries specify. It also removes those scratch-pad-list entries and updates the refer- ences to which they pointed so that those references reflect the evacuated ob- jects'new locations. Any collection-set objects to which the thus-evacuated objects refer are similarly evacuated to that train, and this continues until that train no longer contains any references into the collection-set car section.

Whenever an object is evacuated, the collector leaves an indication of this fact in the object's previous location, together with the address of its new location. So, if the reference found in the location identified by any subsequent scratch-pad-list entry refers to an already-evacuated object, the collector is ap- prised of this fact and can update the reference without attempting to evacuate the already-evacuated object.

This process is repeated for successively older trains until the collector reaches the oldest train. Before it processes references in that train's scratch- pad list, the collector evacuates any objects referred to from outside the gen- eration. To identify such objects, the collector scans the root set and other generations for references into the collection set. Now, it may not be neces- sary to scan all other generations. A particularly common scheme is not to collect any generation in a collection cycle in which every younger generation is not completely collected, and the policy may be to promote all surviving younger-generation objects into older generations. In such a situation, it is necessary only to scan older generations.

The scanning may actually involve inspecting each surviving object in the other generation, or the collector may expedite the process by using card- table entries. Regardless of which approach it uses, the collector immediately evacuates into another train any collection-set object to which it thereby finds an external reference. The typical policy is to place the evacuated object into the youngest such train. As before, the collector does not attempt to evacuate an object that has already been evacuated, and, when it does evacuate an ob- ject to a train, it evacuates to the same train any objects in the collection-set car

to which the thus-evacuated object refers. In any case, the collector updates the reference to the evacuated object.

When all inter-generationally referred-to objects have been evacuated from the collection-set car the garbage collector then performs the train algo- rithm's central test: it determines whether there are any references into the old- est train from outside that train. If there are none other than those in the col- lection set, the entire train can be reclaimed, even if there are inter-car refer- ences between its individual cars. By evacuating objects into the trains that references to them occupy, the train algorithm tends to group garbage refer- ence cycles into single trains, whose sizes are not limited, as car sizes are, by the need to optimize collection-cycle duration. The train algorithm is thus able to reclaim space occupied by large garbage reference cycles even if the space increments (car sections) that it collects are relatively small. To support this process, a tally of how many references there are from other trains in the same generation is typically maintained in connection with the various remembered- set updates. This tally, together with a tally of extra-generational references developed during the extra-generational scan, yields the indications of whether there are any references into a given train from outside that train.

If references into the oldest train have prevented its car sections from being reclaimed, the collector proceeds to evacuate any collection-set objects referred to by references whose locations the oldest train's scratch-pad list in- cludes. It removes them to younger cars in the oldest train, again updating ref- erences, avoiding duplicate evacuations, and evacuating any collection-set-car objects to which the evacuated objects refer. When this process has been completed, the collection set can be reclaimed, since any reference to any re- maining object must reside in the same car, so all remaining collection-set ob- jects are unreachable.

Figs. 8A-8J illustrate results of using the train algorithm. Fig. 8A repre- sents a generation in which objects have been allocated in nine car sections.

The oldest train has four cars, numbered 1.1 through 1.4. Car 1.1 has two ob- jects, A and B. There is a reference to object B in the root set (which, as was

explained above, includes live objects in the other generations). Object A is referred to by object L, which is in the third train's sole car section. In the gen- eration's remembered sets 92, a reference in object L has therefore been re- corded against car 1.1.

Processing always starts with the oldest train's earliest-added car, so the garbage collector refers to car 1.1's remembered set and finds that there is a reference from object L into the car being processed. It accordingly evacuates object A to the train that object L occupies. The object being evacuated is often placed in one of the selected train's existing cars, but we will assume for pres- ent purposes that there is not enough room. So the garbage collector evacu- ates object A into a new car section and updates appropriate data structures to identify it as the next car in the third train. Fig. 8B depicts the result: a new car has been added to the third train, and object A is placed in it.

Fig. 8B also shows that object B has been evacuated to a new car out- side the first train. This is because object B has an external reference, which, like the reference to object A, is a reference from outside the first train, and one goal of the processing is to form trains into which there are no further refer- ences. Note that, to maintain a reference to the same object, object L's refer- ence to object A has had to be rewritten, and so have object B's reference to object A and the inter-generational pointer to object B. In the illustrated exam- ple, the garbage collector begins a new train for the car into which object B is evacuated, but this is not a necessary requirement of the train algorithm. That algorithm requires only that externally referenced objects be evacuated to a newer train.

Since car 1.1 no longer contains live objects, it can be reclaimed, as Fig. 8B also indicates. Also note that the remembered set for car 2.1 now in- cludes the address of a reference in object A, whereas it did not before. As was stated before, remembered sets in the illustrated embodiment include only references from cars further back in the order than the one with which the re- membered set is associated. The reason for this is that any other cars will al-

ready be reclaimed by the time the car associated with that remembered set is processed, so there is no reason to keep track of references from them.

The next step is to process the next car, the one whose index is 1.2.

The purpose of a generation's division into car sections is to provide for incre- mental collection, so collection of car 1.2 can wait until the collection cycle fol- lowing the one during which car 1.1 is collected. Indeed, the garbage collector can postpone its processing for several collection cycles (during which pre- sumably only younger generations are collected). As was mentioned above, we will assume in this scenario that each car's collection occurs in its own separate collection cycle. And for the sake of simplicity we will assume that the mutator does not change any references into the generation in the interim.

Fig. 8B depicts car 1.2 as containing only a single object, object C, and that car's remembered set contains the address of an inter-car reference from object F. The garbage collector follows that reference to object C. Since this identifies object C as possibly reachable, the garbage collector evacuates it from car set 1.2, which is to be reclaimed. Specifically, the garbage collector removes object C to a new car section, section 1.5, which is linked to the train to which the referring object F's car belongs. Of course, object F's reference needs to be updated to object C's new location. Fig. 8C depicts the evacua- tion's result.

Fig. 8C also indicates that car set 1.2 has been reclaimed, and car 1.3 is next to be processed. The only address in car 1.3's remembered set is that of a reference in object G. Inspection of that reference reveals that it refers to object F. Object F may therefore be reachable, so it must be evacuated before car section 1.3 is reclaimed. On the other hand, there are no references to objects D and E, so they are clearly garbage. Fig. 8D depicts the result of re- claiming car 1.3's space after evacuating possibly reachable object F.

In the state that Fig. 8D depicts, car 1.4 is next to be processed, and its remembered set contains the addresses of references in objects K and C. In- spection of object K's reference reveals that it refers to object H, so object H must be evacuated. Inspection of the other remembered-set entry, the refer-

ence in object C, reveals that it refers to object G, so that object is evacuated, too. As Fig. 8E illustrates, object H must be added to the second train, to which its referring object K belongs. In this case there is room enough in car 2.2, which its referring object K occupies, so evacuation of object H does not re- quire that object K's reference to object H be added to car 2.2's remembered set. Object G is evacuated to a new car in the same train, since that train is where referring object C resides. And the address of the reference in object G to object C is added to car 1.5's remembered set.

Fig. 8E shows that this processing has eliminated all references into the first train, and it is an important part of the train algorithm to test for this condi- tion. That is, even though there are references into both of the train's cars, those cars'contents can be recognized as all garbage because there are no references into the train from outside of it. So all of the first train's cars are re- claimed.

The collector accordingly processes car 2.1 during the next collection cycle, and that car's remembered set indicates that there are two references outside the car that refer to objects within it. Those references are in object K, which is in the same train, and object A, which is not. Inspection of those ref- erences reveals that they refer to objects I and J, which are evacuated.

The result, depicted in Fig. 8F, is that the remembered sets for the cars in the second train reveal no inter-car references, and there are no inter- generational references into it, either. That train's car sections therefore con- tain only garbage, and their memory space can be reclaimed.

So car 3.1 is processed next. Its sole object, object L, is referred to in- ter-generationally as well as by a reference in the fourth train's object M. As Fig. 8G shows, object L is therefore evacuated to the fourth train. And the ad- dress of the reference in object L to object A is placed in the remembered set associated with car 3.2, in which object A resides.

The next car to be processed is car 3.2, whose remembered set in- cludes the addresses of references into it from objects B and L. Inspection of

the reference from object B reveals that it refers to object A, which must there- fore be evacuated to the fifth train before car 3.2 can be reclaimed. Also, we assume that object A cannot fit in car section 5.1, so a new car 5.2 is added to that train, as Fig. 8H shows, and object A is placed in its car section. All re- ferred-to objects in the third train having been evacuated, that (single-car) train can be reclaimed in its entirety.

A further observation needs to be made before we leave Fig. 8G.

Car 3.2's remembered set additionally lists a reference in object L, so the gar- bage collector inspects that reference and finds that it points to the location previously occupied by object A. This brings up a feature of copying-collection techniques such as the typical train-algorithm implementation. When the gar- bage collector evacuates an object from a car section, it marks the location as having been evacuated and leaves the address of the object's new location.

So when the garbage collector traces the reference from object L, it finds that object A has been removed, and it accordingly copies the new location into object L as the new value of its reference to object A.

In the state that Fig. 8H illustrates, car 4.1 is the next to be processed.

Inspection of the fourth train's remembered sets reveals no inter-train refer- ences into it, but the inter-generational scan (possibly performed with the aid of Fig. 6's card tables) reveals inter-generational references into car 4.2. So the fourth train cannot be reclaimed yet. The garbage collector accordingly evacu- ates car 4.1's referred-to objects in the normal manner, with the result that Fig. 81 depicts.

In that state, the next car to be processed has only inter-generational references into it. So, although its referred-to objects must therefore be evacu- ated from the train, they can be placed in any other train. In the illustrated im- plementation, a new train is formed for this purpose, so the result of car 4.2's processing is the state that Fig. 8J depicts.

Processing continues in this same fashion. Of course, subsequent col- lection cycles will not in general proceed, as in the illustrated cycles, without any reference changes by the mutator and without any addition of further ob-

jects. But reflection reveals that the general approach just described still ap- plies when such mutations occur.

One shortcoming of the conventional approach to train-algorithm-based garbage collection is that certain types of objects will not end up being identi- fied as unreachable unless measures are taken that compromise the train algo- rithm's incremental nature. To appreciate this, consider Figs. 9A and 9B, which illustrate a typical approach to memory allocation for class information.

In an object-oriented program, a typical object 100 (Fig. 9B) contains a reference to information about the class to which it belongs. In a dynamically loaded system, such information is often loaded in units of"class files,"of which the drawing gives an example 102 (Fig. 9A). The drawing depicts class file 102 as being stored outside of the train-algorithm-managed heap 104 (Fig. 9B).

This is typical because the collection procedure uses the class file's information about object sizes, etc., and relocating the source of that information as part of the relocation process that depends on it would be complicated. But thus lo- cating such class information outside the train-algorithm-managed heap tends to make it hard to collect some types of objects in an incremental fashion.

To appreciate this, it is helpful to consider a typical organization of class information. It turns out that the class file's organization may not be optimum for a given run-time system to use. So some of that information and/or infor- mation derived from it may be placed in a more-convenient form. To indicate this, the drawings show a"nearClass"structure 106. Its location may be used by object headers to identify the classes to which their objects belong, as the drawing indicates by pointer 107 in object 100's header. Because of such uses, the nearClass structure, too, is located outside of the heap 104.

But not all of the class-related information is located outside the heap 104. In the case of the Java programming language, for instance, it is a requirement that one be able to refer to a class as an object, so there must be an object structure to represent it. Compilers that target the Java virtual ma- chine employ objects of the java. lang. Class class, which the drawing exempli- fies in structure 108. Such objects, which we refer to herein as"proxy objects"

because of a use to which our invention's below-illustrated embodiment puts them, should be located in the heap, as other objects are.

Now, the process of collecting structure 108 presents difficulties be- cause of the types of references to it there tend to be. The class structure 102 itself will typically include a reference 110 to it. It will also be ultimately reach- able from a"class loader."A class loader is a structure, exemplified in the drawings by structure 112, that contains information about how to load a class, such as where to look for its class file. For example, the virtual machine look- ing for"ourFirm. MyClass"may look in the local hard disk if the default loader is specified but instead look to a remote server if a different loader is specified.

The memory allocated to such a structure 112 cannot be reclaimed until the classes loaded in accordance with its contents are no longer reachable, so it contains a list of the classes it has been used to load. The illustrated em- bodiment implements this feature by a reference 114 to a vector structure 116.

In the illustrated embodiment, this structure includes metadata about the vec- tor, including a pointer 118 to structures such as structure 120 that contain the actual list of references to the classes that the loader has loaded. If the class represented by proxy object 108 has been loaded by the loader that struc- ture 112 represents, then the list-containing structure 120 will include a refer- ence 122 to the proxy object 108.

The problem that references of these types cause is that they can form cycles of references that the conventional train-algorithm implementation does not concentrate. As the diagram illustrates, an object such as object 100 of a given class refers to that class's nearClass structure 106, which refers to the class structure 102, which points to the proxy object 108. In the conventional train-algorithm approach, such external references tend to make the proxy ob- ject appear reachable, even though it may actually be part of an unreachable cycle, because the cycle runs through external space.

One can identify such cycles by periodically performing special, whole- heap (non-incremental) collection intervals. But this is unworkable for an appli- cation that cannot tolerate the delays that non-incremental collection often im-

poses. Alternatively, one can simply leave proxy objects uncollected. But this approach is unacceptable for applications that generate large numbers of classes.

SUMMARY OF THE INVENTION We have devised a way of identifying such unreachable cycles, and re- claiming the associated memory resources, as part of the train algorithm's in- cremental collection process. Our approach involves associating various "proxy"objects in the train-managed heap with respective resources outside of it. If all external references to a collection-set object are located in resources associated with proxies in the heap, that object is, in essence, evacuated to the youngest train containing such a proxy, not the youngest train overall. So ob- jects involved in cycles that include external objects can, like those involved in cycles entirely within the heap, be concentrated in single trains so that their re- sources are reclaimed by incremental collection. The external resources in the cycle can be reclaimed at the same time.

BRIEF DESCRIPTION OF THE DRAWINGS The invention description below refers to the accompanying drawings, of which: Fig. 1, discussed above, is a block diagram of a computer system in which the present invention's teachings can be practiced; Fig. 2, discussed above, is a block diagram that illustrates a compiler's basic functions; Fig. 3, discussed above, is a block diagram that illustrates a more- complicated compiler/interpreter organization; Fig. 4, discussed above, is a diagram that illustrates a basic garbage- collection mechanism; Fig. 5, discussed above, is a similar diagram illustrating that garbage- collection approach's relocation operation;

Fig. 6, discussed above, is a diagram that illustrates a garbage-collected heap's organization into generations; Fig. 7, discussed above, is a diagram that illustrates a generation or- ganization employed for the train algorithm ; Figs. 8A-J, discussed above, are diagrams illustrating a collection sce- nario that can result from use of the train algorithm ; Figs. 9A and 9B, discussed above, together form a diagram that illus- trates the relationships among a class instance and the structures that support its class ; and Fig. 10 is a flow chart that illustrates collection-interval operations of par- ticular interest in connection with the present invention.

DETAILED DESCRIPTION OF AN ILLUSTRATIVE EMBODIMENT As was mentioned above, the present invention performs collection in- crementally, but in a way that enables some garbage cycles having external references to be collected. Fig. 10 is a simplified representation of part of a collection interval consistent with the present invention. The patent applica- tions incorporated by reference above describe in detail a number of features that various collectors employing the present invention's teachings may addi- tionally employ. Fig. 10's blocks represent only certain steps selected to illus- trate the present invention's salient features.

Near the beginning of a collection interval, the collector performs an op- eration that Fig. 10's block 124 represents. As will be explained below, steps will be performed during the collection interval to identify classes whose re- sources are still reachable, and the collector must keep track of the resulting determinations in some fashion. In the illustrated embodiment, the collector does so by appropriately marking a reachability field 126 (Fig. 9A) in the class structure 102 of any class thus identified. But no such determinations have yet been made at the beginning of an interval, and the collector resets all class structures'reachability fields in step 124 to reflect this fact.

As blocks 128 and 130 indicate, the collector then forms the collection set and begins processing remembered sets. Remember in this connection that a conventional remembered set records only the locations of intra- generation references to the associated car's objects so that those objects can be evacuated to the trains occupied by objects that refer to them. As was ex- plained above, this type of evacuation tends to concentrate within respective trains the garbage cycles that consist of objects within the generation. But the present invention's purpose is additionally to concentrate within respective trains those objects that are in garbage cycles also containing certain types of extra-generation resources. In the illustrated embodiment the extra-generation resources of interest are those used to support object classes.

To this end, each car that contains a proxy object has a second, class remembered set associated with it as well as the conventional remembered set. Now, the illustrated embodiment uses each class's proxy object in the generation, in a manner that will be described below, as a proxy for that class's extra-generation resources. This means that, if any younger train contains an instance of a class whose proxy object has advanced to the collection set, that proxy object will need to be evacuated to one such younger train, even though that train will not in general have a reference to the proxy object. So, rather than representing, as a normal remembered-set entry does, the location of an object containing a reference into the associated car, each entry in a class re- membered set represents the location of an object that is an instance of a class whose proxy object the associated car contains.

The illustrated embodiment updates class remembered sets on three kinds of occasions. The first kind occurs at the beginning of a collection inter- val (even before any younger generation is collected). The garbage collector identifies all objects directly allocated in the train-managed generation since the previous collection interval. It identifies each such object's class (by, in the il- lustrated embodiment, reading its nearClass field). If the generation contains the proxy object associated with that class, the collector may place into the

class remembered set for the proxy object's car section an entry representing the newly allocated object's location.

That entry will differ from a normal-remembered-set entry. A normal re- membered-set entry is the address of the reference into the car with which the remembered set is associated. The referring object's train can be inferred from the reference's address, and the reference's value is the referred-to object's location. But there is no such referring relationship between a given object and the proxy object representing the class of which the given object is an instance.

So a class-remembered-set entry must contain two items of information rather than one. One item identifies the proxy object. In the illustrated embodiment, that item is a pointer to the class's nearClass object, although other embodi- ments may use some other way of identifying the proxy object.

The other item could identify the object whose recent allocation gave rise to the update; this would parallel the normal-remembered-set entry, which, too, identifies the object that gave rise to the entry. Some implementations of the present invention's teachings may take this approach. But we have taken a different approach.

Our approach arises from the following observation concerning the rela- tionship between a class instance and its corresponding proxy object: unlike other references that an object may include, an object's reference to its class never changes. From this observation one can conclude that, if an instance of the class associated with a proxy object is located in a train younger than the one containing the proxy object, the proxy object will definitely be evacuated to a train at least that young when the proxy object reaches the collection set. So, whereas a normal remembered set must contain an entry for every younger-car object that has a reference to any object in the car associated with the remem- bered set, a class collection set's entries can be restricted to only a single, youngest-train instance of each class of which the associated car contains a proxy. Indeed, the entry need not even identify the class instance that gave rise to it; it need only identify its train.

This is the illustrated embodiment's approach. That is, after it has iden- tified the class remembered set for the car containing the proxy object associ- ated with the newly allocated object's class, the collector adds an entry to that remembered set if the remembered set previously had none for that class (be- cause the generation previously had no instance of the class), or it changes an existing entry if necessary to identify the now-youngest train in which an in- stance resides.

The second type of occasion for class-remembered-set updating occurs if, as is typical, the incremental train-algorithm-based collection within a given collection interval is preceded during the same collection interval by collection of a younger generation. Objects may be"promoted"in that situation from the younger generation into the train-managed generation. When those objects are promoted, the same updating operation occurs for them.

The third type occurs during evacuation of objects from the collection set. When an object previously in the collection set is moved to another train, its class is identified, and the class remembered set of the car that contains that class's proxy object is updated as above if necessary.

Block 130's processing of the thus-updated remembered sets includes preparing the usual per-train scratch-pad lists described above. It also includes preparing a special, class-type scratch-pad list for each train that contains a proxy object or an instance of a class whose proxy object is in the train- algorithm-managed generation. Before we describe the class-type scratch-pad list, though, we will discuss the block-132 step's use of the usual scratch-pad lists in evacuating referred-to collection-set objects.

As block 132 indicates, the collector begins with the youngest train and evacuates into respective trains the collection-set objects to which their respec- tive scratch-pad lists (both usual and class-type) direct it. In a normal scratch- pad list, each entry identifies a collection-set object. The collector removes that object to the train associated with the scratch-pad list, as is conventional. As is also conventional, it additionally removes to that train any other collection-set object to which the thus-removed object refers. It performs this process recur-

sively : any collection-set object referred to by an object thus removed to a train is also removed to the same train.

As was explained above, this tends to concentrate into one train all the objects in a garbage cycle whose objects all reside in the train-managed gen- eration. The resources occupied by those objects can therefore be reclaimed despite the collection process's incremental nature. But the present invention's purpose is also to reclaim the resources of objects in some cycles that addi- tionally include certain extra-generational structures. In the illustrated embodi- ment, the structures of interest are those that are class-based.

So an object's removal to a train may trigger the removal to that train of collection-set objects in addition to those to which the removed object refers.

Specifically, the collector also removes to that train those collection-set objects that are referred to by the extra-generational structures associated with classes determined by the removed objects. For all removed objects, this set of classes includes the ones of which the removed objects are instances. In addi- tion, for a removed proxy object, this set of classes also includes the one for which the removed object is a proxy. Finally, this set includes all classes whose associated structures are reachable from the external structures associ- ated with other classes in the set.

To this end, the illustrated embodiment considers not only the removed object's references to other collection-set objects but also its reference that identifies the class to which it belongs. As was mentioned above, this is a ref- erence to a structure, such as the nearClass structure 106, that is outside the generation. If the external structures are as Figs. 9A and 9B illustrate, the col- lector has to follow the thus-found structure 106's pointer to the associated class structure 102.

Now, the fact that the collector reached the class structure by following pointers from objects evacuated from the collection set means that the class structure is reachable from an object that will not be reclaimed during the cur- rent collection interval. A mark previously made in the class structure's reach-

ability field 126 during the same collection interval may already indicate this fact. If so, the current scratch-pad-list entry's processing is complete.

Otherwise, the collector marks the reachability field 126 to indicate that the class structure 102 cannot be reclaimed, and it then identifies references from the class structure 102 into the collection set. For each such reference, the collector removes the referred-to object to the train associated with the source scratch-pad list. The collector also identifies references, such as refer- ence 132, to other class structures, and it recursively processes them in a similar manner.

As was mentioned above, the collector performs the evacuation process by reference to special, class-type scratch-pad lists as well as to the usual scratch-pad lists whose use was just described. As was also mentioned above, the proxy objects serve in the illustrated embodiment as proxies for the re- sources that support the classes with which they are associated. This means that (in principle) the evacuation process should include evacuating to a train that contains a proxy object those collection-set objects that are referred to by references in extra-generational class structures associated with that proxy object.

Therefore, for at least each class of which the collection set contains an instance, creation of the class-type scratch-pad lists includes placing in each list the identity of the class whose proxy object the associated train contains.

The collector also places in the scratch-pad list for the youngest train the iden- tity of each class that has no proxy in the train-managed generation. For this purpose it may use a class-list structure 124, which an object-oriented program normally maintains to keep track of all its loaded classes. In the illustrated em- bodiment the list entry's identification of a class takes the form of a reference to the class's class structure, such as structure 102. In the evacuation process the collector follows that reference to the class structure and proceeds as was just described to evacuate the collection-set objects referred to by the refer- ences that it contains.

It was stated above that such collection-set objects are"in principle" evacuated to the trains containing the relevant proxy objects. In practice, though, some embodiments will actually employ an optimization that, when the time comes for the proxy object itself to be evacuated, reduces the number of other objects that have to be evacuated with it. In accordance with that optimi- zation the collector in some cases actually evacuates such a collection-set ob- ject to a train that the relevant proxy object does not currently occupy but will eventually be evacuated to if an instance of the relevant class is not allocated beforehand in a still-younger train.

To this end, the collector's creation of the class-type scratch-pad list ad- ditionally includes stepping through each class whose proxy is in the genera- tion, finding the youngest train containing an instance of that class, and placing that class's identity in that train's class scratch-pad list. This means that a col- lection-set object referred to from an extra-generational structure associated with a class of which an instance is located in a train younger than the train containing that class's proxy object will be evacuated to a train containing such an instance rather than to the train containing the proxy object.

Evacuation in accordance with the entries in the scratch-pad lists, both normal and class-type, proceeds from the youngest-train lists to those associ- ated with successively older trains. But evacuation into the oldest train is actu- ally unnecessary if there prove to be no references into the oldest train from outside of it; that train's car sections will all be reclaimed anyway. So some embodiments, such as the illustrated one, will interrupt the evacuation process before the last train in order to perform an operation that enables it to deter- mine whether there are any references into the train from anywhere outside of it other than the collection set. (When they are selected for the collection set, its cars are conventionally thought of as no longer belonging to any train.) Block 134 represents this operation, which involves searching the root set for references. If such a reference refers to a collection-set object, the col- lector removes the referred-to object into the youngest train. (Note that many externally referenced collection-set objects that would conventionally have

been removed at this point will already have been removed to older trains, be- cause the external references to them reside in external resources associated with classes whose proxy objects are in the train-managed generation.) As in the previous evacuations, the collector additionally removes to the youngest train not only any collection-set objects to which the thus-removed object refers but also any collection-set object to which the removed object's class structure refers.

If the referred-to object is not in the collection set but is in the train- managed generation, the collector marks that object's train as having an exter- nal reference into it. This will enable the collector subsequently to identify trains into which there are external references. Using this information together with a check of whether a train has references from other trains enables the collector to detect trains that contain only garbage and can therefore be re- claimed in toto. In some implementations, such as the current one, the exter- nal-reference mark is recorded in the object's car.

Now, when block 134's root-set search begins, any class structure has been marked if it is reachable from an object that is in the generation but out- side the oldest train. Such structures should not be reclaimed. To identify any other reachable class structures, the collector marks any previously unmarked class structures associated with classes of which the root set refers to in- stances. It also marks all previously unmarked class structures associated with classes to which methods referred to in the call stacks'activation records be- long. And it recursively scans any newly marked structure for references into the collection set.

As block 138 indicates, the illustrated embodiment then determines whether there are any non-collection-set references into the train either from within the generation or from outside it. If there are no such references, then all of the oldest train's objects are unreachable, so the collector reclaims all of its car sections, as block 138 indicates. In this situation, most collector imple- mentations will additionally perform the same test on progressively younger trains until they find one into which references from outside of it do exist, and

that train becomes the oldest remaining train. If the collector is a particularly aggressive implementation, it may further determine whether one or more of that oldest remaining train's oldest cars are devoid of references into it. If so, it reclaims that one or more cars'sections, too.

In those cases in which there are non-collection-set references into the train either from within the generation or from outside it, the collector processes the train's scratch-pad-list entries just as it did those of younger trains, and block 140 represents this operation.

A review of the class-structure-marking operations reveals that all of the following are true of any class structure that still remains unmarked after all the above-described operations: there are no references to it from outside the col- lection set, its proxy object is in the collection set, and its class loader is in the collection set. Since all objects to which there are any references from outside the collection set have already been evacuated from it, any unmarked class's proxy, any instances of it, and its class loader are all unreachable. This means that the class can be unloaded. In addition to reclaiming the proxy object, any object instances, and the class loader as part of the collection-set reclamation of block 142, this means that the collector sets the class-table entry for that class to, say, NULL, and reclaims its extra-heap structures, such as the illus- trated embodiment's class and nearClass structures 102 and 106. Block 144 represents this step.

A review of the foregoing example will reveal that the present invention's teachings are not restricted to reclaiming memory that contains class-related structures. In any arrangement in which a garbage cycle can contain objects both within and outside the train-managed heap, objects within the heap can be used as proxies for the extra-heap objects and thus enable the collector to use the train algorithm to reclaim such cycles. As was explained above, this will in many instances enable the collector to reclaim objects whose reclamation would otherwise impose unacceptable delays. So the present invention con- stitutes a significant advance in the art