• An introduction
> Enabled with -XX:+UseSerialGC
> Single threaded young generation collector (stops all
application threads)
> Single threaded tenured generation collector (stops all
application threads)
• Suitability
> Well suited for single processor core machines
> Well suited for configurations of one-to-one JVM to
The Java™ SE Performance Tuning
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Revision A 188
Garbage Collectors: Serial Collector
• Comparing serial and throughput collectors
> Serial collector can work better on applications with small
young generation heaps versus parallel throughput collector.
>Throughput collector's parallel GC threads may compete
for work in small young generation heaps resulting in thrashing.
> For small Java™ heaps, or small young generation Java™
heaps, try both, serial collector and parallel throughput collector.
Garbage Collectors: Serial Collector
• Events which initiate a serial collector garbage collection
> Eden space is unable to satisfy an object
allocation request. Results in a minor garbage collection event.
> Tenured generation space is unable to satisfy
an object promotion coming from young generation.
The Java™ SE Performance Tuning
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Revision A 190
Garbage Collectors: Serial Collector
• Good throughput performance can be realized with the serial collector if:
> Well tuned Java™ heap spaces on Java™ applications with small Java™ heaps, (i.e. smaller than 100mb heaps) > Target platform has small number of virtual
processors
> The number of JVMs deployed on a multi-core
processor platform equals the number of multi- core processors
>Bind JVMs to processors or processor sets for
Garbage Collectors: Throughput Collector
• An introduction
> Multi-threaded young generation space
collectors enabled with -XX:+UseParallelGC
> JDK 5.0_06 introduced multi-threaded tenured
generation space collector enabled with - XX:+UseParallelOldGC (also enables - XX:+UseParallelGC)
• Suitability
> Can significantly reduce garbage collection
The Java™ SE Performance Tuning
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Revision A 192
Garbage Collectors: Throughput Collector
• Managing collector threads
> Number parallel throughput collector threads
controlled by -XX:ParallelGCThreads=<N>
>Defaults to Runtime.availableProcessors(). In
a JDK 6 update release, 5/8ths available processors if > 8
>In multiple JVM per machine configurations,
setting -XX:ParallelGCThreads=<N> lower will likely yield better results
>Reducing number of parallel gc threads can
also reduce fragmentation effect in promotion buffers in tenured space.
Garbage Collectors: Throughput Collector
• Multiple JVM strategies
> Bind JVMs to processor sets
>Works well for JVMs which tend to have
equal load since idle processors outside a
processor set are not available to other JVMs outside the processor set
>Note: Runtime.availableProcessors() reports
number of processors in processor set
The Java™ SE Performance Tuning
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Revision A 194
Garbage Collectors: Throughput Collector
• Events which initiate a minor garbage collection
> Eden space is unable to satisfy an object
allocation request. Results in a minor garbage collection event.
• Events which might initiate a full garbage collection
> Tenured generation space unable to satisfy an
object promotion coming from young generation.
Garbage Collectors: Throughput Collector
• Good throughput performance can be realized with the throughput collector if:
> Pause time requirements are less important than throughput > Java™ heap spaces are well tuned
> Application runs on multi-core system
>Bind JVMs to processor sets in multiple JVM
configurations for best results
>Consider -XX:+BindGCTaskThreadsToCPUs or
-XX:+AggressiveOpts when scaling across multiple cores
The Java™ SE Performance Tuning
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Revision A 196
Garbage Collectors: Throughput Collector
• Good throughput performance can be realized with the throughput collector if:
> Use of -XX:+UseParallelGC, the multi-threaded young generation
collector, and young generation heap is sized so that only long lived objects are tenured to old generation and Full GC events can be avoided.
> If Full GC events cannot be avoided, a multi-threaded old
generation collector can reduce length of Full GC events, -XX:+UseParallelOldGC.
Garbage Collectors: Concurrent Collector
• An Introduction
> Single threaded tenured space collector which
runs mostly concurrent with Java™ application threads and is enabled with -
XX:+UseConcMarkSweepGC
> Parallel, multi-threaded young generation
collector enabled by default.
• Suitability
> Well suited when application responsiveness is
The Java™ SE Performance Tuning
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Revision A 198
Garbage Collectors: Concurrent Collector
• Issues to be aware of
> Cost of the concurrent collections is the
additional overhead of more memory and CPU cycles
> Concurrent mode failure can occur when
objects are copied to the tenured space faster than the concurrent collector can collect them. (“loses the race”)
> Concurrent mode failure can also occur from
tenured space fragmentation.
> Corrective action by the JVM is to perform a full
garbage collection which will block all Java application threads.
Garbage Collectors: Concurrent Collector
• Concurrent collector cycle contains the following phases > Initial mark > Concurrent mark > Remark > Concurrent sweep > Concurrent reset
• During a concurrent collector cycle, a Java™
The Java™ SE Performance Tuning
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Revision A 200
Garbage Collectors: Concurrent Collector
• Initial mark phase
> Objects in the tenured generation are “marked”
as reachable including those objects which may be reachable from young generation.
> Pause time is typically short in duration relative
to minor collection pause times.
• Concurrent mark phase
> Traverses the tenured generation object graph
for reachable objects concurrently while Java™ application threads are executing.