Maestro
Sang Shin
Technology Evangelist Sun Microsystems, Inc. www.javapassion.com
1
Agenda
Why you care on GC (as a developer)? What is and Why Generational GC? GC Performance Metrics GC Algorithms Types of Collectors > Serial collector > Parallel collector > Parallel compact collector > Concurrent Mark-Sweep (CMS) collector: regular, incremental • Ergonomics • •• • •
2
Why you care on GC?
• In general, the default setting should work fine for most applications • For GC sensitive applications, however, choosing a wrong GC scheme could result in a less than desirable performance
3
What is and Why Generational GC?
Issues of Non-Generational GC
• Most straightforward GC will just iterate over every object in the heap and determine if anyother objects reference it
> This is the behavior of Non-generational GC > This gets really slow as the number of objects in the
heap increases > This does not take advantage of the characteristics of typical objects
• Hence the reason for Generational GC
5
Behavior of Typical Java Objects
• Typical object (Young object) is most likely to die shortly after it was created
> It iscalled “high infant mortality” > Example: Local objects
• Objects that have been around for a while (Old objects) will likely stay around for a while
> Example: Objects initialized at the time of application
startup
• Only a few references from old objects to young objects exist
6
Empirical Statistics
• Most objects are very short lived
> 80-98% of all newly allocated objectsdie shortly after they are created > 80-98% of all newly allocated objects die before another megabyte has been allocated
7
Heap Space With Generations
• Heap space is organized into “generations”
> Young generation (for young objects) > Old (or Tenured) generation (for old objects) > Perm generation (meta data, classes, etc.)
Young Generation Old Generation Permanent Generation
8Principles of Generational GC
• Keep young and old objects separate
> Mixing them in a single space would result in inefficient
GC
• Use different GC algorithms for different generation heap spaces
> Objects in each generation have different life-cycle
tendencies > “Use the right tool for the job”
9
Characteristics of Young Generation Heap Space
• GC's occur relativelyfrequently • GC's are efficient and fast because young generation space is usually small and likely to contain a lot of objects that are no longer referenced • Objects that survive some number of young generation collections are promoted, or tenured, to old generation heap space
10
Characteristics of Old Generational Heap Space
• Typically larger than young generation heap space • Its occupancygrows more slowly • GC's are infrequent but takes significantly longer time to complete
11
Generational GC
12
Young Generation Space Layout
• Made of an area called Eden plus two smaller survival spaces • Most objects are initially allocated in Eden • One of the two survival spaces hold objects that survived at least one young generation GC while the other is empty
13
GCAlgorithms Used
• Young generation
> Algorithms used emphasize speed since young
generation GC's are frequent
• Old generation
> Algorithms used emphasize efficient space since old
generation takes up most of the heap space and have to work with low garbage densities
14
When Does GC Occur?
When GC Occurs
• When the young generation fills up, a young generation GC occurs
> Younggeneration GC is called minor GC
• When the old generation does not have enough space for the objects that are being promoted, a Full GC occurs
> Full GC is also called major GC
16
GC Performance Metric
Important GC Performance Metric
• Throughput
> The percentage of total time not spent in garbage
collection, considered over long periods of time.
• Pause time
> The length...
Regístrate para leer el documento completo.