Low-latency garbage collection using fork

Hi,

Here is a simple way to do garbage collection without pausing the program. A fork command is used to create a copy of the current process. Then the marking phase is done in the forked process. After that the list of marked objects is returned to the original process and the sweep phase is done. The forked process is then killed. This should enable zero-latency garbage collection when using mark-and-sweep alogrithm. The only downside is the increased memory consumption because of the need to fork the process. In the worst case the memory requirement is doubled. However, since modern unixes do fork very efficently the need of extra memory is in most cases well below 100%. Has Sun considered this algorithm or something similiar?

this is stupid.
a) it WILL double the memory requirements. you need to copy the WHOLE data, which may well take longer than a full gc.
b) you’ll only have 5% of your cpu. most of it will be used by the gc.

No, modern unixes (and other modern operating systems) can do a copy-on-write operation. This means that the copying is not done until the memory is written to. Before that both processes share the same physical memory. Only the page tables need to be copied, which is only a fraction of the actual memory usage. Only the pages (a page is a 4kB block of memory) that are written to during the mark phase need to be copied. For an average program this is very likely only a fraction of the total used memory.

won’t this lead to inconsistent states? in process a, an object is used, and in process b, it’s about to be collected?

Sun has had this for ages. It’s called the CMS collector (Concurrent Mark Sweep)
See appropriate HotSpot docs for how to enable it.

http://java.sun.com/developer/technicalArticles/Programming/turbo/#The_new_GC.html