Fun piece of GC code from Hotspot!

Showing 1-1 of 1 messages
Fun piece of GC code from Hotspot! mani 2/12/13 4:08 PM
Hi All,

I came across this block of code on one of the Hotspot mailing list:

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();  
<=== that's shining new in the GC!
       } 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);
   }

You can see how GC policy is decided from the above block of code, some non-scary easy to read C/C++ code after all! The only tiny bits of dust there are the block of code are the compiler directives!

I'll soon let you out on a bit of C/C++ hacking I'm working on with Hotspot! Stay tuned!

Regards,
mani

--
Twitter: @theNeomatrix369
JUG activity: LJC Advocate

Don't chase success, rather aim for "Excellence", and success will come chasing after you!