Java Performance Tuning

Java(TM) - see bottom of page

|home |services |training |newsletter |tuning tips |tool reports |articles |resources |about us |site map |contact us |
Tools: | GC log analysers| Multi-tenancy tools| Books| SizeOf| Thread analysers| Heap dump analysers|

Our valued sponsors who help make this site possible
JProfiler: Get rid of your performance problems and memory leaks! 

Training online: Concurrency, Threading, GC, Advanced Java and more ... 

Question of the month: 1.4.1 Garbage collection algorithms, January 29th, 2003

Get rid of your performance problems and memory leaks!

Modern Garbage Collection Tuning
Shows tuning flow chart for GC tuning

Java Performance Training Courses
COURSES AVAILABLE NOW. We can provide training courses to handle all your Java performance needs

Java Performance Tuning, 2nd ed
The classic and most comprehensive book on tuning Java

Java Performance Tuning Newsletter
Your source of Java performance news. Subscribe now!
Enter email:

Training online
Threading Essentials course

Get rid of your performance problems and memory leaks!

Back to newsletter 026 contents

What is the difference between the various garbage collectors in 1.4.1?

The 1.4.1 SDK was released with at least six different garbage collection algorithms. To understand the differences between these algorithms, you first need to understand that in 1.4.1 (and previous JVMs since one of the 1.2 releases) the JVM heap is divided into two main areas: the young generation and the old generation. First, a digression on why there are these two areas of heap. (Note that the following explanations are simplified, avoiding complexities such as that the heap has more areas like Perm space, and that objects too large for the young generation are created in the old generation.)

Analysis of object lifecycles in many object-oriented programs shows that most objects tend to have very short lifetimes, with fewer objects having intermediate length lives and some objects being very long-lived. Garbage collection of short-lived objects can be achieved efficiently using a copying collector, whereas a mark-and-sweep collector is more useful for the full heap because this collector avoids object leaks. In their most basic terms, a copying collector copies all live objects from area1 to area2, which then leaves area1 free to reuse for new objects or the next copy collection. A mark-and-sweep collector finds all objects that can be reached from the JVM roots by traversing all object nodes (instance variables and array elements), marking all reached objects as "alive", then sweeping away all remaining objects (the dead objects). Copy collection time is roughly proportional to the number of live objects, mark-and-sweep collection is roughly proportional to the size of the heap.

So the heap is split into the young generation and the old generation so that a copying collection algorithm can be used in the young generation and a mark-and-sweep collection algorithm can be used in the old generation. Objects are created in the young generation, most live and die in that heap space and are efficiently collected without forcing a full mark-and-sweep collection. Some objects get moved over to the old generation because they live too long, and if the old generation gets full enough, a mark-and-sweep collection must run.

Okay, now you are armed with sufficient knowledge to understand the six 1.4.1 garbage collectors that I know about. There are three available for the young generation, and three for the old generation. Collectors labelled "parallel" use multiple threads to parallelize the collection and hence shorten the time taken on multiple-CPU machines. Collectors labelled "concurrent" allow application processing to proceed concurrently while the collection is executing, thus reducing or eliminating pauses in the application caused by garbage collection.

Young generation garbage collection algorithms

Old generation garbage collection algorithms

The team

Back to newsletter 026 contents

Last Updated: 2024-06-30
Copyright © 2000-2024 All Rights Reserved.
All trademarks and registered trademarks appearing on are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries. is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.
RSS Feed:
Trouble with this page? Please contact us