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 |

Our valued sponsors who help make this site possible
AppDynamics: Get complete browser to backend visibility. Monitor Now! 

New Relic: Try free w/ production profiling and get a free shirt! 

ManageEngine's Site24x7: End-to-End analysis on Java EE web transactions. Sign up for FREE! 

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

JProfiler
Get rid of your performance problems and memory leaks!

Chart Java Jitter with jHiccup
Monitor and identify pauses in your Java apps. Download now

Why is my application so slow?
Learn 3 ways to detect Java Application Performance Trends


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

See Your Message Here
You could have your tool advertised here, to be seen by thousands of potential customers

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:


AppDynamics
AppDynamics: Get complete browser to backend visibility. Monitor Now!

New Relic
New Relic: Try free w/ production profiling and get a free shirt!

ManageEngine
ManageEngine's Site24x7: End-to-End analysis on Java EE web transactions. Sign up for FREE!


JProfiler
Get rid of your performance problems and memory leaks!

Chart Java Jitter with jHiccup
Monitor and identify pauses in your Java apps. Download now

Why is my application so slow?
Learn 3 ways to detect Java Application Performance Trends


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 JavaPerformanceTuning.com team

Back to newsletter 026 contents


Last Updated: 2014-09-29
Copyright © 2000-2014 Fasterj.com. All Rights Reserved.
All trademarks and registered trademarks appearing on JavaPerformanceTuning.com are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries. JavaPerformanceTuning.com is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.
URL: http://www.JavaPerformanceTuning.com/news/qotm026.shtml
RSS Feed: http://www.JavaPerformanceTuning.com/newsletters.rss
Trouble with this page? Please contact us