Immersion dans Hotspot
Options de GC dans les fichers source du dossier hotspot
../hotspot/src/share/vm/gc_implementation/g1/g1_globals.hpp dans la repo Hotspot
../hotspot/src/share/vm/runtime/globals.hpp dans la repo Hotspot
Astucieux bloc de code d'HotSpot - observez comment se produit le switch en fonction du type de GC sélectionné
Type de GC | Jeune Génération | Vieille Génération |
---|---|---|
SerialGC (-XX:+UseSerialGC) | Série | Série |
ParallGC (-XX:+UseParallelGC) | Parallèle | Série |
Parallel Compacting(-XX:+UseParallelOldGC) | Parallèle | Parallèle |
Concurrent Mark Sweep GC (-XX:+UseConcMarkSweepGC) | Parallèle | CMS |
Extrait de ./hotspot/src/share/vm/memory/universe.cpp
.
.
.
Universe::initialize_heap()
if (UseParallelGC) {
#ifndef SERIALGC
Universe::_collectedHeap = new ParallelScavengeHeap();
#else // SERIALGC
fatal("UseParallelGC not supported in this VM.");
#endif // SERIALGC
} else if (UseG1GC) {
#ifndef SERIALGC
G1CollectorPolicy* g1p = new G1CollectorPolicy();
G1CollectedHeap* g1h = new G1CollectedHeap(g1p);
Universe::_collectedHeap = g1h;
#else // SERIALGC
fatal("UseG1GC not supported in java kernel vm.");
#endif // SERIALGC
} else {
GenCollectorPolicy* gc_policy;
if (UseSerialGC) {
gc_policy = new MarkSweepPolicy();
} else if (UseConcMarkSweepGC) {
#ifndef SERIALGC
if (UseAdaptiveSizePolicy) {
gc_policy = new ASConcurrentMarkSweepPolicy();
} else {
gc_policy = new ConcurrentMarkSweepPolicy();
}
#else // SERIALGC
fatal("UseConcMarkSweepGC not supported in this VM.");
#endif // SERIALGC
} else { // default old generation
gc_policy = new MarkSweepPolicy();
}
Universe::_collectedHeap = new GenCollectedHeap(gc_policy);
}
SERIALGC switched ON - platforms that only support SERIAL GC?
.
.
.
Universe::initialize_heap()
if (UseParallelGC) {
fatal("UseParallelGC not supported in this VM.");
} else if (UseG1GC) {
fatal("UseG1GC not supported in java kernel vm.");
} else {
GenCollectorPolicy* gc_policy;
if (UseSerialGC) {
gc_policy = new MarkSweepPolicy();
} else if (UseConcMarkSweepGC) {
fatal("UseConcMarkSweepGC not supported in this VM.");
} else { // default old generation
gc_policy = new MarkSweepPolicy();
}
Universe::_collectedHeap = new GenCollectedHeap(gc_policy);
}
.
.
.
SERIALGC switched OFF - platforms that support both types of GC?
.
.
.
Universe::initialize_heap()
if (UseParallelGC) {
Universe::_collectedHeap = new ParallelScavengeHeap();
} else if (UseG1GC) {
G1CollectorPolicy* g1p = new G1CollectorPolicy();
G1CollectedHeap* g1h = new G1CollectedHeap(g1p);
Universe::_collectedHeap = g1h;
} else {
GenCollectorPolicy* gc_policy;
if (UseSerialGC) {
gc_policy = new MarkSweepPolicy();
} else if (UseConcMarkSweepGC) {
if (UseAdaptiveSizePolicy) {
gc_policy = new ASConcurrentMarkSweepPolicy();
} else {
gc_policy = new ConcurrentMarkSweepPolicy();
}
} else { // default old generation
gc_policy = new MarkSweepPolicy();
}
Universe::_collectedHeap = new GenCollectedHeap(gc_policy);
}
.
.
.