Newsletter sign-up
View all newsletters

Sign up for our technology specific newsletters.

Enterprise Java
Email Address:

J2SE 1.4.1 boosts garbage collection

Three new algorithms target near real-time applications

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone

Page 3 of 5

Garbage collection can also be triggered if the heap's subregions are nearly full. In this case, the garbage collection thread's priority increases, thus increasing the chance that the garbage collection will run to completion. If the new generation is full, a minor collection is triggered; if the old generation is full, a major collection is triggered. The steps in a minor collection are:

  1. Copy objects from Eden to survivor space (1 or 2).
  2. Copy from survivor space 1 to survivor space 2, or vice versa. After a certain number of copies (controllable from the command line), an object becomes tenured, that is, a candidate for old object space.
  3. Tenured objects move from survivor space 1 or 2 to old object space.


A major collection uses the old generation garbage collector (mark-compact for J2SE 1.3) to reclaim old objects.

Garbage collection in J2SE 1.4.1

Some applications can't tolerate even the short pauses from incremental garbage collection. Examples include near real-time applications and applications that must service large transaction volumes. The new 1.4.1 algorithms were created to fill this gap.

The new algorithms are based on the observation that many machines used for low-pause or high-throughput applications have large amounts of memory and multiple processors. The algorithms are optimized to take advantage of the extra resources. Table 1 shows the new algorithms.





Table 1. The complete set of GC algorithms (* = new in 1.4.1)

  Young Old Stop the world Multithreaded Concurrent
Copying X   X    
*Parallel copying X   X X  
*Parallel scavenging X   X X  
Incremental 1 (see note below)   X    
Mark-compact   X X    
*Concurrent   X 2 (see note below)   X
Note 1: Subdivides the new generation to create an additional middle generation
Note 2: Uses stop-the-world approach for two of its six phases


The parallel (multithreaded) algorithms are optimized for machines with multiple CPUs. In J2SE 1.4.1, they are only used in the young generation. Using multiple threads allows garbage collection to proceed in parallel with the application thread, so the application can proceed without perceptible pauses. By default, the parallel collectors allocate one thread per processor. Note: If you have a single-processor machine, these algorithms will probably not help with application performance and could potentially diminish it.

The parallel scavenging collector is optimized for very large (gigabyte) heaps. It should provide very fast throughput with minimal pauses. It requires using mark-compact for the old generation.

The concurrent collector works with the old generation. It divides garbage collection into six phases:

  1. Initial mark
  2. Mark
  3. Precleaning
  4. Remark
  5. Sweep
  6. Reset


The first (initial-mark) and fourth (remark) phases are stop-the-world techniques; the others can proceed in parallel with application threads. The multistep garbage collection allows the stop-the-world phase to be as short as possible, which means that application pauses for garbage collection should be minimized.

Controlling 1.4.1 garbage collection

To select a particular garbage collection algorithm you will need to use a command-line switch. The switches are listed in Table 2:

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone
Comments (2)
Login
Forgot your account info?

Metaphor chosen was well-thought & helpful to understand...By Anonymous on April 29, 2009, 7:56 amMetaphor chosen was well-thought & helpful to understand. Thanks for this nice article. Ananth

Reply | Read entire comment

thanks so muchBy Anonymous on January 23, 2009, 4:02 pmthanks so much

Reply | Read entire comment

View all comments

Add comment
Anonymous comments subject to approval. Register here for member benefits.
Have a JavaWorld account? Log in here. Register now for a free account.
Resources