This invention relates to garbage collection in a managed runtime computer environment.
In the field of this invention it is known that garbage collection (e.g., as relied on in the Java (Java and all Java-based trademarks are trademarks of Sun Microsystems, Inc. in the United States, other countries, or both) programming language) is a part of a programming language's runtime system, or an add-on library, perhaps assisted by the compiler, the hardware, the operating system, or any combination of the three, that automatically determines what memory a program is no longer using, and recycles it for other use. It is also known as “automatic storage (or memory) reclamation”.
Garbage collection is preferred to manual memory management, which is (programmer-)time consuming, and error prone, since most programs still contain leaks (particularly programs using exception-handling and/or threads). The benefits of garbage collection are increased reliability, decoupling of memory management from class interface design, and less developer time spent chasing memory management errors. However, garbage collection is not without its costs, including performance impact, pauses, configuration complexity, and nondeterministic finalization.
A common method of garbage collection is mark-sweep, where allocated memory is marked and a collector sweeps the heap and collects unmarked memory for re-allocation. An entire collection may be performed at once while the user program is suspended (so-called ‘stop-the-world’ collection). Alternatively, the collector may run incrementally (the entire heap not being collected at once, resulting in shorter collection pauses), or a user program may run concurrent collectors.
However, these approaches have the disadvantages that the sweep phase of garbage collection can take a significant part of the pause time (greater than 50%), whereas Concurrent Sweep (a known solution to this problem) has the drawback of decreasing throughput.
A need therefore exists for garbage collection wherein the above mentioned disadvantage(s) may be alleviated.
In accordance with a first aspect of the present invention there is provided an arrangement, for use in garbage collection in a computer system, as claimed in claim 1.
In accordance with a second aspect of the present invention there is provided a method, for use in garbage collection in a computer system, as claimed in claim 10.
One arrangement and method for optimising garbage collection stop-the-world sweep time utilising the present invention will now be described, by way of example only, with reference to the accompanying drawings, in which:
As is well known, a mark-map is typically is used to determine live/dead objects in the memory heap in garbage collection in a computer system, e.g., a Java Virtual Machine.
The mark-map is a bit-vector such that there is 1 bit for every object_grain_size bytes of heap, i.e., 1 byte (8 bits) for each (8* object_grain_size) bytes of heap. Thus, the size of the mark-map in bytes is:
((heap size in bytes)/(8*object_grain_size)).
For example, assuming object_grain_size=4 bytes and a heap of 1000 MB in size, the mark-map will have a size of 1000 MB/(8*4)=31.250 MB.
Conventionally, in garbage collection using such a mark-map, the majority of stop-the-world sweep time is spent in touching and walking over this large mark-map (31.250 MB).
Referring now to
As illustrated in
In the meta-mark-map 300 and the mark-map 200: a hatched box represents a set bit and un-hatched box represents an unset bit. Vertical hatching indicates a physically set bit, and horizontal hatching indicates a logically set bit, using the following scheme. In the present example, a bit is set (here called a physical bit) only for the start of an object in the mark-map (e.g., bit 3 in
Thus, it can be seen that the marked or set objects depicted in boxes 1-36 of the heap 100 as illustrated in
Referring now also to
Referring now also to
In practice, in order to use the meta-mark-map 300, there must be decided:
Concerning decision A (the value for N), an optimal value for N would be:
((minimum_size_for_a_freelist_candidate in bytes/2)/object_grain_size in bytes).
For example, assuming minimum_size_for_a_freelist_candidate=512 bytes for the earlier example, this would give N=((512/2)/4)=64. This would give a meta-mark-map of size (31.250 MB/64)=0.488 MB.
Concerning decision B (the meaning of set and unset bits in the meta-mark-map), the following meaning is chosen:
Concerning decision C (building meta-mark-map for relatively negligible cost—in terms of pause time):
It will be understood that the benefits of using the meta-mark-map 300 can be summarised as follows:
The meta-mark-map 300 is much smaller, and so can be touched and walked over much more quickly, than the mark-map 200. In an ideal scenario, 0.488 MB is much less memory to touch and walk over than 31.250 MB; in a realistic scenario, overall memory touched and walked is significantly less than 31.250 MB.
The meta-mark-map 300 can be read one word at a time (like mark-map 200 heretofore). This is an added advantage, since N*object_grain_size*word_size bytes of heap can be scanned with a single register comparison operation (or 64*4*32 bytes=8,096 bytes in the earlier example for a 32-bit system with word_size=32); this compares to a scan of (object_grain_size*word_size) with a single register comparison operation for the existing implementation (or 4*32 bytes=128 bytes in the earlier example). Therefore, a complete scan of heap needs much fewer register comparison operations.
The main benefit will be for large heaps, but performance improvements should also be seen on smaller heaps.
It will be understood that a further optimisation would be to have a hierarchy of meta-mark maps depending on the size of the heap, units of a mark-map higher in the hierarchy representing respectively pluralities of units of a mark-map lower in the hierarchy.
It will also be understood that a further optimisation would use the meta-mark-map scheme described above for stop-the-world mark phase when running without concurrent functionality.
It will be appreciated that the novel garbage collection scheme using the meta-mark-map described above is carried out in software running on a processor in one or more computers, and that the software may be provided as a computer program element carried on any suitable data carrier (not shown) such as a magnetic or optical computer disc.
It will be understood that further modifications to the example described above may be made by a person of ordinary skill in the art without departing from the scope of the present invention.
Number | Date | Country | Kind |
---|---|---|---|
0512809.5 | Jun 2005 | GB | national |