A computer method and system for memory management

Abstract: A method and system for conservative-stack and generational garbage collection for a computer memory is provided. In a preferred embodiment, the computer memory includes a stack and a heap. The heap comprises a plurality of objects each of which is identified as new or old. During run time, a list of old objects that contain pointers to new objects is maintained. During garbage collection time, each new object that is accessible through an old object in the list is marked as accessible. The stack contains a plurality of stack entry that may be pointers to new objects. During garbage collection time, each stack entry is checked to see if it could point to a new object. Each new object that a stack entry could point to is marked as accessible and each new object that is accessible through the marked objects is also marked as accessible. During memory compaction, the new objects that are not marked as accessible are reclaimed.

Description: Technical Field This invention relates generally to a computer method and system for memory garbage collection and, more particularly, to a method and system for garbage collection that uses a conservative approach to stack pointers and generational approach to reclaim objects. Background of the Invention Computer systems may manage computer memory dynamically. Dynamic memory management refers to the process by which blocks of memory are allocated temporarily for a specific purpose and then deallocated when no longer needed for that purpose. Deallocated blocks are available for reallocation for another purpose. The process that dynamically manages the memory is referred to as the memory manager. The memory that the memory manager manages is referred to as a "heap." When a program needs a block of memory to store data, the program sends a request to the memory manager. The memory manager allocates a block of memory in the heap to satisfy the request and sends a pointer to the block of memory to the program. The program can then access the block of memory through the pointer. In the case of programs written in certain languages, such as C++, blocks of memory (a block of memory is often referred to as an object) can be allocated automatically or dynamically. Automatic objects are automatically allocated when a procedure is entered and automatically deallocated when the procedure is exited. Conversely, dynamic objects are allocated by an explicit call to the memory manager and deallocated by either an explicit call to the memory manager or automatically through a technique known as garbage collection. Typically, automatic objects are stored in a stack and dynamic objects are stored in a heap. A program can only access a dynamic object through a pointer. A pointer is a memory location that contains the address of an object. If the program overwrites the pointer, then the corresponding object becomes "inaccessible" to the program. An object may be pointed to by several pointers. Only when all the pointers are overwritten, or are part of another inaccessible object, does the object become inaccessible. An inaccessible object is one in which the program cannot retrieve data from or write data to. Garbage collection is the process of dynamic memory management that detects and recovers objects that are no longer accessible by the program and thus are candidates for deallocation and subsequent reallocation. There are two basic techniques for determining whether an object is accessible. The reference-counting technique tracks if an object is accessible by incrementing a pointer count in the object every time a new pointer is set to point to the object and decrementing the pointer count every time a pointer that points to the object is overwritten. The reference-counting technique is expensive. In some implementations, it may take an extra 50 bytes of code for every pointer assignment to increment and decrement the pointer count. Also, it may be difficult to identify inaccessible objects in certain situations. For example, if object A contains a pointer to object B, object B contains a pointer to object A, and the pointer count for object A is 1 and for object B is 1, then objects A and B are effectively inaccessible, even though these pointer counts are not 0. The other garbage collection technique for determining which objects are accessible does not track pointers to an object. Rather, when more heap memory is needed for allocation, the garbage collector identifies objects which are accessible by checking all the pointers in the program and marking each object to which a pointer points as accessible. When this marking is complete, all objects that are not marked as accessible are inaccessible and available for deallocation. Typically, the garbage collector checks every pointer in the memory (heap and stack). However, it may be very difficult to identify whether a certain memory location contains a pointer or some other value. For example, the following c++ declaration indicates that an object A may be a pointer to an object some of the time and may be an integer value at other times. A garbage collector would not know whether object A contains a pointer or an integer unless the program set an indicator with each assignment to this object. This type of tracking is very expensive. Without this type of tracking, if object A contained an integer value that happened to contain the same bit pattern as a pointer to an object, then the garbage collector could not be certain whether it is really an integer or a pointer. A memory location that could be a pointer sometimes and not a pointer other times is referred to as a "may-be-pointer." A "conservative" approach to garbage collection does not track each assignment of a may-be-pointer. Rather, it assumes that object A is a pointer and treats the object to which it may point as being accessible. With this approach, the garbage collector may mark an object as accessible when it is really inaccessible. Conservative garbage collectors have problems compacting memory. During memory compaction, all accessible objects are typically moved to one end of the heap (the allocated objects) with free space (the deallocated objects) occupying the other end. When the garbage collector moves an object, it must update all pointers to that object to reflect its new location. However, the conservative garbage collector cannot change the value of a may-be-pointer because if the may-be-pointer really contained a non-pointer value, then the garbage collector would be introducing an error into the program. Consequently, conservative garbage collectors typically do not compact memory. Because garbage collection can be time-consuming, some garbage collectors use a technique called generational collecting. A generational garbage collector divides the objects in the heap into two categories: new objects (recently created) and old objects (not recently created). This technique uses the assumption that recently created objects generally become inaccessible quickly, while older objects typically stay accessible for a while. Thus, a generational garbage collector deallocates new objects, but not old objects. A generational garbage collector trades off completeness of the garbage collection (some old objects may be inaccessible) for a faster garbage collection process. Figures 1A and 1B show a sample stack and heap before and after garbage collection using a conservative approach. Figure 1A shows stack 110 and heap 120 before garbage collection. Stack 110 contains five stack entries 111-115 with values of 4, 23, 12, 64, and 16. Heap 120 contains 8 objects 121-128 at locations 0, 4, 8, 12, 16, 20, 24, and 28 and free space 129 at location 32. Stack entry 111 is defined to be a pointer only; stack entries 112-114 may be a pointer or integer; and stack entry 115 is an integer. Stack entry 111 contains a pointer 118 to object 122. Stack entry 112 does not currently contain a pointer because its value, 23, does not correspond to the address of any object. Stack entry 113 may contain a pointer 116 (indicated by the dashed line) since there is an object at location 12. Stack entry 114 does not currently contain a pointer because its value, 64, would point to an object in free space. Stack entry 115 is not a pointer, even though its value, 16, corresponds to the location of an object. Object 122 in heap 120 contains a field 119 that may be a pointer 117 to object 123 or an integer. Objects 121, 125, 126, 127, and 128 are inaccessible because there are no pointers to these objects. Object 122 is accessible because pointer 118 points to it. Objects 123 and 124 may be accessible because stack entry 113 and field 119 may point to these objects. Figure 1B shows the stack 110 and heap 120 after garbage collection using a conservative approach. In this example, the conservative garbage collector knows whether a memory location contains a pointer, does not contain a pointer, or contains a may-be-pointer. However, it does not track whether a may-be-pointer currently contains a pointer. Heap 120 contains accessible object 122 and the objects that may be accessible, 123 and 124. The inaccessible objects 121, 125-128 have been reclaimed (deallocated) into free spaces 130 and 131. Object 122 has been moved and its corresponding pointer 118, stack entry 111, has been modified to point to the new location. Objects 123 and 124 have not been moved because the garbage collection process could not be sure whether stack entry 113 or field 119 was an integer or a pointer. Figures 2A and 2B show a sample stack and heap before and after garbage collection using a generational approach. Figure 2A shows stack 210 and heap 220 before garbage collection using a generational approach. Stack 210 contains three stack entries 211, 213, 214 that are pointers. Heap 220 contains 8 objects 221-228 and free space 229. Pointer 240 is maintained by the garbage collector and points to the start of the new objects. Stack entry 211 points to object 222; stack entry 213 points to object 227; and stack entry 214 points to object 223. Object 223 contains a field 242 that is a pointer 243 to object 224, and object 227 contains a field 244 that is a pointer 245 to object 228. Objects 221 through 225 are old objects, and objects 226 through 228 are new objects. Objects 222, 223, 224, 227, and 228 are accessible, and objects 221, 225, and 226 are inaccessible. Figure 2B shows stack 210 and heap 220 after garbage collection using a generational approach. Since a generational approach was used, the inaccessible old objects 221 and 225 were not reclaimed (deallocated). Only object 226, which is new and inaccessible, was reclaimed. Stack entry 213 was updated to reflect the new location of object 227, and pointer 247 in field 244 was updated to reflect the new location of object 228. Free space 230 reflects the reclamation of object 226. Pointer 240 was updated to point to the start of the new objects. US patent no. 4,907,151 discloses a system and method for garbage collection with ambiguous roots. A dynamic memory allocation and recovery system and method provide a heap of storage space for storing program objects generated by a task. The heap is divided into pages whose size is independent of physical page sizes. Pages are denoted as unallocated or allocated for storing program objects. A root storage area stores information called hints regarding program objects stored in the heap. The hint can include ambiguous pointers which may or may not point to program objects stored in the heap. Garbage collection is performed by promoting and retaining all pages in the heap which are referenced by hints, and by copying into previously unallocated pages all other accessible program objects in the heap. All pointers to the copied program objects are replaced with pointers to the new copies of those program objects. All program objects are located in pages pointed to by ambiguous pointers are left in their original position, and only the pointers to the copied program objects are replaced with pointers to the new copies of the program objects. European patent application no. 0,430,668 discloses a method and system for reclaiming unreferenced computer memory space, operating in a virtual memory environment wherein user memory space is divided into pages. For each active page, a table stores the age of the oldest object on the page and the age of the youngest object pointed to from that page. A generational partition divides the pages into "safe" pages and "threatened" pages. Rescuer pages, which may contain pointers to threatened pages, are determined by comparing the age of the youngest object pointed to from the page to the generational partition. All potential pointers on the rescuing pages are traced and the object pointed to are marked as reachable. All objects reachable from other reachable objects are also marked. Unmarked threatened objects are deallocated. Johnson, The case for a read barrier, Computer Architecture News, ACM, New York, US, April 1991, vol. 19, no. 2, pages 279 to 287 investigates the performance of two different garbage collection algorithms on a very large and long-running Lisp application. Both algorithms use write barriers for generational collection. Only one algorithm uses a read barrier for incremental collection. Major differences in paging behaviour were identified when a read barrier permitted the garbage collector to work with the virtual memory manager instead of independently. It is the object of the invention to provide an improved method and system for dynamic memory management in a computer system. This object is solved by the methods as claimed in independent claim 1 and the system as claimed in independent claim 14. Preferred embodiments of the invention are subject-matters of dependent claims. This and other objects, which will become apparent as the invention is more fully described below, are obtained by an improved method and system for identifying inaccessible objects in a computer memory. In a preferred embodiment, the memory includes a stack and a heap, the heap includes old and new objects, the objects are identified by pointers, and the stack has stack entries that may be pointers. In a preferred embodiment, when an old object contains a pointer that is set to point to a new object, the old object is added to remember list. During garbage collection, each stack entry is considered a may-be-pointer. Then, each new object that might be pointed to by a stack entry is marked as accessible, each new object that is pointed to by an old object in the remember list is marked as accessible, and each new object that is accessible through a previously marked object is marked accessible. When this process is complete, all the new objects that have not been marked as accessible are inaccessible. Brief Description of the Drawings Figures 1A and 1B show a sample stack and heap before and after garbage collection using a conservative approach. Figures 2A and 2B show a sample stack and heap before and after garbage collection using a generational approach. Figure 3 is an overview flow diagram of the garbage collector procedure in a preferred embodiment. Figure 4 is a flow diagram of routine ProcessStackPointers in a preferred embodiment. Figure 5 is a flow diagram of routine ProcessMaybePointerList in a preferred embodiment. Figure 6 is a flow diagram of routine ProcessRememberList in a preferred embodiment. Figure 7 is a flow diagram of routine CheckEmbeddedPointers in a preferred embodiment. Figure 8A shows a sample new space of a heap after all the accessible objects are marked. Figure 8B shows the sample new space of a heap after compaction. Figure 9 is a flow diagram of a compaction routine in a preferred embodiment of the present invention. Detailed Description of the Invention The present invention provides an improved garbage collection technique that combines conservative and generational garbage collection techniques. In a preferred embodiment, the garbage collector conservatively assumes each stack entry points to an object and uses an exact method to determine whether a global variable is a pointer and whether field within an object in the heap is a pointer. It is also preferred that the garbage collector reclaims only new objects. During run time of the program, a list of old objects that contain a pointer to a new object is maintained. If the object containing the pointer is old and the object pointed to is new, then the old object is added to a remember list. In a preferred embodiment, a compiler generates code that performs this checking and adding to the remember list for each pointer assignment statement. The compiler also generates a virtual function for each class of objects. One of these virtual functions returns a list of the pointers contained in the object, and another returns the size of the object. The compiler generates code to track exactly whether a may-be-pointer in an object currently contains a pointer. In a preferred embodiment, the memory manager logically divides the heap into a new space and an old space. The memory manager allocates new objects from the new space. In a preferred embodiment, the garbage collector is implemented on a processor with a segmented architecture, such as the Intel 80386. Any accessible new object is accessible either through a stack entry or through an old object on the remember list. Thus, by processing the stack entries and the objects in the remember list, the garbage collector can determine which new objects are accessible or might be accessible. In a preferred embodiment, the garbage collector treats each stack entry conservatively, that is, it assumes that each stack entry is a may-be-pointer. The garbage collector marks each new object that may be pointed to by a stack entry as locked and accessible and each new object that is accessible from the locked object as accessible. The garbage collector then processes each object in the remember list by visiting each new object that is accessible through that old object and marking it as accessible. After the marking is complete, the garbage collector compacts the memory in the new segment. Figure 3 is an overview flow diagram of the garbage collector procedure in a preferred embodiment. In step 301, the garbage collector invokes routine ProcessStackPointers to conservatively mark all new objects that may be accessible through the stack entries. In step 302, the garbage collector invokes routine ProcessRememberList to mark all new objects that may be accessible through the old objects in the RememberList. In step 303, the garbage collector compacts the new segment of the heap. Figure 4 is a flow diagram of routine ProcessStackPointers in a preferred embodiment. In steps 401 through 404, the garbage collector processes each stack entry to determine whether it might be a pointer to a new object or whether it is definitely not a pointer to a new object. If it might be a pointer to a new object, the garbage collector adds the stack entry to a list of may-be-pointers for later processing. In step 401, the garbage collector selects the next stack entry starting with the first. In step 402, if all the stack entries have already been selected, then the garbage collector continues at step 405, else the garbage collector continues at step 403. In step 403, if the selected stack entry might be a pointer to a new object, then the garbage collector adds the selected stack entry to the MaybePointerList in step 404 and loops to step 401 to select the next stack entry, else the garbage collector loops to step 401. In a preferred embodiment, new objects are allocated space in a single segment. Thus, the pointers to the new objects have a segment selector equal to that of the new segment. The stack entry might be a pointer to a new object when its selector portion points to the new segment and offset portion is within the limit of the new segment. In step 405, the garbage collector invokes the routine ProcessMaybePointerList to conservatively mark the objects that might be pointed to by the stack entries in the MaybePointerList. The garbage collector then returns. Figure 5 is a flow diagram of routine ProcessMaybePointerList in a preferred embodiment. This routine processes the entries in the MaybePointerList by marking all new objects that might be pointed to as locked and accessible. The routine also marks the new objects that are accessible through these objects as accessible. In step 501, the garbage collector sorts the MaybePointerList. In step 502, the garbage collector selects the next new object in the heap starting with the first new object. In step 503, if all the new objects have already been selected, then the garbage collector returns, else the garbage collector continues at step 504. In step 504, if the MaybePointerList contains a stack entry that would point to the selected object or an object embedded in the selected object if it were a pointer, then the garbage collector continues at step 505, else the garbage collector loops to step 502 to select the next new object. In step 505, the garbage collector marks the selected object as locked. The selected object may have already been marked as accessible because it is accessible through a new object already marked as accessible. It is nevertheless now marked as locked so that it will not be moved during heap compaction. In step 506, if the selected object is already marked as accessible, then the embedded pointers have already been processed to determine which new objects are accessible through them and the garbage collector loops to step 502 to select the next new object, else the garbage collector continues at step 507. In step 507, the garbage collector marks the selected object as accessible. In step 508, the garbage collector invokes routine CheckEmbeddedPointers passing it the selected object and then loops to step 502 to select the next new object. This routine, as explained below in detail, marks all new objects (not already marked as accessible) that are accessible from the passed object (except those new objects that can only be accessed from the passed object through an old object) as accessible. Figure 6 is a flow diagram of routine ProcessRememberList in a preferred embodiment. This routine processes each old object in the RememberList to mark each new object that is accessible through it as accessible. In step 601, the garbage collector selects the next object in the RememberList starting with the first. In step 602, if all the objects in the RememberList have already been selected, then the garbage collector returns, else the garbage collector continues at step 603. In step 603, the garbage collector invokes routine CheckEmbeddedPointers passing it the selected object and then loops to step 601 to select the next object. Figure 7 is a flow diagram of routine CheckEmbeddedPointers in a preferred embodiment. This routine is passed an object and sets each new object (not already marked as accessible) that is accessible through pointers embedded in the passed object (except those new objects that can only be accessed from the passed object through an old object) as accessible. This routine is invoked recursively to process each new object pointed to by the pointers contained in the passed object. One skilled in the art would appreciate that this routine could be implemented in a non-recursive manner. When this routine encounters a pointer to an old object, it does not process the pointers in that old object because if the old object contains a pointer to a new object then the old object is on the RememberList and the garbage collector processes it that way. In step 701, the garbage collector selects the next pointer in the passed object starting with the first. In a preferred embodiment, a virtual function is defined for each class of objects which, when invoked, provides the pointers contained in the object. In step 702, if all the embedded pointers for the passed object have been processed, then the garbage collector returns, else the garbage collector continues at step 703. In step 703, if the object pointed to by the selected pointer is new and not already marked accessible, then the garbage collector continues at step 704, else the garbage collector loops to step 701 to select the next embedded pointer. If the selected pointer is null, then it does not point to a new object. If the object is already marked accessible, then all new objects accessible from it (except those new objects that can only be accessed from the passed object through an old object) have been marked as accessible. In step 704, the garbage collector selects the object pointed to by the selected pointer. In step 705, the garbage collector marks the selected object to accessible. In step 706, the garbage collector recursively invokes routine CheckEmbeddedPointers passing the selected object and then loops to step 701 to select the next embedded pointer. The preferred compaction algorithm of the present invention moves each object that is marked and not locked to one end of the heap. The moved objects retain their relative position to one another. This maintaining of the relative position tends to improve the locality of references. An object generally tends to reference objects that are created about the same time. Thus, the maintaining of the relative position ensures that an object will be spatially near objects created in the same temporal vicinity, except for objects that are locked. Since objects that are locked are not moved, they may become spatially separated from objects created in the same temporal vicinity. The improved locality of references is especially important in reducing page faults in a computer system with virtual memory. When objects are moved, they can be stored near an object that is locked. If the space between an object that is locked and a moved object is not large enough to hold the next object to be moved, then a dummy object is created and moved to that space. A dummy object is large enough to fill that space and has an associated virtual function table. Since no pointer can reference the dummy object, the dummy object is reclaimed during the next garbage collection. When the moving of the objects is complete, a list is made of areas of contiguous sections of free space. The free space would be contiguous except for objects that are marked and locked. The allocation of new objects occurs from this free space. Figure 8A shows a sample new space after all the accessible objects are marked. The objects that are marked and are not locked are M 0 , M 1 , M 2 , M 3 , M 4 , and M 5 . The objects that are marked and are locked are ML 0 , ML 1 , ML 2 , and ML 3 . The objects that are not marked are U 0 , U 1 , U 2 , U 3 , U 4 , U 5 , U 6 , and U 7 . The numbers in the lower right corner of each object represent the size of the object. Figure 8B shows the sample new space of a heap after compaction. The object marked D 0 is a dummy object. The free space is identified by F 0 , F 1 , and F 2 , which are linked together. The pointer TOS indicates the top of the space after the compaction is complete. During the compaction process, it was determined that the object M 2 with a size of 5 would not fit into a space with a size of 2. Consequently, dummy object D 0 with a size of 2 was created and inserted into the space with a size of 2. Although object M 4 with a size of 2 would fit into that space, it was not moved because to do so would change the relative order of the objects that are marked and not locked. Figure 9 is a flow diagram of a compaction routine in a preferred embodiment of the present invention. This routine initializes a top of space (TOS) pointer to point to the first object in the new space . The TOS pointer points to the next location to which an object can be moved. In step 901, the compactor selects the next object in the new space starting with the first. In step 902, if all the objects have already been selected, then the compactor continues at step 911, else _ the compactor continues at step 903. In step 903, if the selected object is marked and is not locked, then the selected object is to be moved and the compactor continues at step 904, else the compactor loops to step 901 to select the next object. In step 904, if there is enough space between the TOS and the next locked object, then the object can be moved to the TOS and the compactor continues at step 908, else the compactor continues at step 905. The next locked object refers to the closest locked object that is between the TOS and the end of the new space . If there is no such locked object, the space is considered to span from the TOS to the end of the new space . In steps 905 through 907, the compactor fills the space between the TOS and the next locked object with a dummy object. If the TOS points to the next locked object, then no dummy object is needed and steps 905 through 907 are skipped. A dummy object has a virtual function that returns the size of the object, and a virtual function that returns an indication that there are no pointers in the object. During the next garbage collection after being created, a dummy object is not marked as accessible (there are no pointers to it) and is therefore reclaimed. In step 905, the compactor creates a dummy object large enough to fill the space between the TOS and the next locked object. In step 906, the compactor stores the dummy object at the TOS. In step 907, the compactor advances the TOS past the next locked object and loops to step 904 to check whether there is enough space between the advanced TOS and the new next locked object. In step 908, the compactor moves the selected object to the TOS. In step 909, the compactor updates the pointers to the moved object. During the process of marking the objects, the garbage collector created a list of all pointers that point to each marked object. In step 910, the compactor advances the TOS past the moved object and loops to step 901 to process the next object. In step 911, the compactor links the free space above the TOS and returns. At completion of the compaction routine, the TOS defines the start of the new space and the end of the old space. The remember list is preferably updated by removing the old objects that no longer point to objects in the new space. One skilled in the art would appreciate that this updating could be performed by the compaction routine when an object is moved. As shown in Figure 8B, since the new space may contain locked objects, e.g., ML 2 and ML 3 , the remember list after compaction may contain old objects that point to these locked objects in the new space. Alternatively, the remember list would not be updated until a new space is defined in such a way that the new space contains no objects. When such a definition occurs, all old objects can be removed from the remember list since there are no objects in the new space to point to. For example, the new space of Figure 8B could be defined to contain no objects by defining the new space to start at object F2 or to start in a different segment when implemented on a computer with a segmented architecture. With such definition, the old space may contain free space. If the new space is defined to start at a location other than TOS, then during the next compaction the compaction routine would preferably move objects to the location pointed to by TOS, rather than resetting TOS to point to the new space. Thus, any free space within the old space would be filled in during compaction. Although the present invention has been described in terms of preferred embodiments, it is not intended that the invention be limited to these embodiments. Modifications of the invention will be apparent to those skilled in the art. The invention is defined by the claims.

Claims: A method, for managing memory in a computer system, said memory having data objects (122; 222, 223,224,227, 228), each object (122; 222, 223,224,227, 228) being identified by a pointer (118; 216, 217, 218, 243, 245), the memory including a stack (110; 210) and a heap (120; 220), the heap (120; 220) having a plurality of old objects (121: 128; 221: 225) and a plurality of new objects (226: 228), the memory including a list of pointers to a plurality of old objects that contain a pointer to a new object, the stack (110; 210) having stack entries (111: 115; 211: 214), each stack entry (111: 115; 211: 214) identifiable as being definitely not a pointer or being possibly a pointer, the method comprising: identifying (403) whether each stack entry (111: 115; 211: 214) is definitely not a pointer or possibly a pointer; for each new object possibly pointed to by a stack entry that is identified as possibly a pointer, marking (404) the new object as accessible and marking each new object that is accessible through the marked object as accessible; and for each old object that is pointed to by a pointer in the list of pointers, marking each new object that is pointed to by a pointer contained in the old object as accessible and marking each new object that is accessible through the marked objects as accessible. The method of claim 1 wherein the steps of marking each new object that is accessible through a marked object as accessible do not mark those new objects that are accessible from the marked object only through an old object. The method of claim 1 or 2 further comprising: for each new object possibly pointed to by a stack entry that is identified as possibly a pointer, marking (505) the new object as locked whereby the object is not moved during memory compaction. The method of claim 1 wherein the memory has a multiplicity of memory locations and a plurality of objects (121: 128; 221: 228) ordered from a first object (121, 221) to a last object (128; 228), each object (121: 128; 221: 228) which has not been marked as accessible being considered inaccessible, each accessible object being locked or not locked, each object that is accessible and not locked having a reference pointer (118; 216, 217, 218, 243, 245) that points to the object, the method further comprising: moving (908) a plurality of accessible and not locked objects wherein the ordering of the accessible and not locked objects is maintained after moving; and adjusting (909) the reference pointer of each moved object to point to the moved to location. The method of claim 4 wherein the step of moving (908) moves the accessible and not locked objects to memory locations previously occupied by an accessible and not locked object already moved or by an inaccessible object. The method of claim 4 or 5 wherein moving the plurality of accessible and not locked objects includes: initializing a memory pointer to point to the first object in the memory; and for each object in the memory, starting with the first object and proceeding in order to the last object, selecting (901) the object; and when the selected object is accessible and not locked (903:Y),when the size of the selected object is such that the selected object can be copied to the memory locations starting at the memory location pointed to by the memory pointer without overwriting a locked object (904:Y); copying (908) the selected object to the memory locations starting with the memory location pointed to by the memory pointer; updating (909) the reference pointer to the selected object, so that the reference pointer points to the copied object; and advancing (910) the memory pointer to point to a memory location after the copied object. The method of claim 6, further comprising: when the size of the selected object is such that the selected object cannot be copied (903:N); storing (906) a dummy object starting at the memory pointed to by the memory pointer, such that the size of the dummy object does not overwrite a locked object; and advancing (907) the memory pointer to point to a location after the locked object. The method of claim 1 wherein the heap (120; 220) includes new objects (226: 228) and old objects (121: 128; 221: 225), the method further comprising: considering inaccessible those objects which have not been marked as accessible; and reclaiming new objects that are not accessible into free spaces (130, 131) of the memory. The method of claim 8 wherein an object contains a data member (119; 242, 244), further comprising: definitely determining whether the data member (119; 242, 244) contains a pointer to a new object. The method of one of claims 8 to 9 wherein the step of reclaiming new objects includes moving new objects that are accessible. The method of claim 10 wherein: the objects of the heap (120; 220) have a relative position to one another; and the step of moving new objects maintains the relative position of the moved objects to one another. The method of claim 10 wherein new objects that are pointed to by a stack entry conservatively determined to be a pointer are not moved. The method of claim 8, further comprising: marking each new object possibly pointed to by a stack entry identified as possibly a pointer as locked, wherein the step of reclaiming includes moving objects that are marked as accessible and that are not locked. A system for memory management of memory data objects in a computer memory according to the managing method of one of claims 1 to 13, said memory having data objects (122; 222, 223,224,227, 228), each object (122; 222, 223,224,227, 228) being identified by a pointer (118; 216, 217, 218, 243, 245), the memory including a stack (110; 210) and a heap (120; 220), the heap (120; 220) having a plurality of old objects (121: 128, 221: 225) and a plurality of new objects (226: 228), the memory including a list of pointers to a plurality of old objects that contain a pointer to a new object, the stack (110; 210) having stack entries (111: 115; 211: 214), each stack entry (111: 115; 211: 214) identifiable as being definitely not a pointer or being possibly a pointer, said system comprising: means for identifying whether an entry (111: 115; 211: 214) of a stack (110; 210) of the computer memory is definitely not a pointer or possibly a pointer to an object stored on a heap (120; 220) of the computer memory, wherein the heap (120; 220) includes a plurality of old objects (121: 128; 221: 225) and new objects (226: 228); means for marking as accessible each new object possibly pointed to by a stack entry that is identified as possibly a pointer and marking as accessible each new object that is accessible through the marked objects; and for each old object that is pointed to by a pointer in the list of pointers, means for marking as accessible each new object that is pointed to by a pointer contained in the old object and marking as accessible each new object that is accessible through the marked objects. The system of claim 14 wherein the means for marking as accessible each new object that is accessible through a marked object do not mark those new objects that are accessible from the marked object only through an old object. The system of claim 14 or 15, further comprising: means for marking as locked each new object possibly pointed to by a stack entry that is identified as possibly a pointer, whereby the object is not moved during memory compaction. The system of claim 14 further comprising: means for considering inaccessible each object which has not been marked as accessible, each accessible object being locked or not locked, each object that is accessible and not locked having a reference pointer (118; 216, 217, 218, 243, 245) that points to the object, the system further comprising means for moving a plurality of accessible and not locked objects in a memory of the computer system, wherein an ordering of the accessible and not locked objects is maintained after moving; and means for adjusting the reference pointer of each moved object to point to the moved to location. The system of claim 17 wherein the means for moving includes means for moving the accessible and not locked objects to memory locations previously occupied by an accessible and not locked object already moved or by an inaccessible object. The system of claim 17 or 18 wherein the means for moving the plurality of accessible and not locked objects includes: means for initializing a memory pointer to point to the first object in the memory; means for selecting each object in the memory, starting with the first object and proceeding in order to the last object; and means for, when the selected object is accessible and not locked, and when the size of the selected object is such that the selected object can be copied to memory locations starting at the memory location pointed to by the memory pointer without overwriting a locked object: copying (908) the selected object to the memory locations starting with the memory location pointed to by the memory pointer; updating (909) the reference pointer to the selected object, so that the reference pointer points to the copied object; and advancing (910) the memory pointer to point to a memory location after the copied object. The system of claim 19, further comprising: means for, when the size of the selected object is such that the selected object cannot be copied: storing (906) a dummy object starting at the memory pointed to by the memory pointer, such that the size of the dummy object does not overwrite a locked object, and advancing (907) the memory pointer to point to a location after the locked object. The system of claim 14 further comprising means for considering inaccessible those objects which have not been marked as accessible; and means for reclaiming new objects that are not accéssible into spaces (130, 131) of the free memory. The system of claim 21 wherein an object contains a data member (119; 242, 244), further comprising: means for definitely determining whether the data member (119; 242, 244) contains a pointer to a new object. The system of claims 21 or 22 wherein the means for reclaiming new objects includes means for moving new objects that are accessible. The system of claim 23 wherein: the objects of the heap (120; 220) have a relative position to one another; and the means for moving new objects maintains the relative position of the moved objects. The system of claim 23 wherein the means for reclaiming new objects does not move new objects that are pointed to by a stack entry conservatively determined to be a pointer.

Inventors: ADCOCK JAMES L, ADCOCK, JAMES L.
Applicants: MICROSOFT CORP, MICROSOFT CORPORATION
Application year: 1993
Main classification: G06F12
IPC codes: G06F12