src/share/vm/gc_implementation/g1/g1MarkSweep.cpp

Print this page
rev 6069 : 8029075: String deduplication in G1
Implementation of JEP 192, http://openjdk.java.net/jeps/192


  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/javaClasses.hpp"
  27 #include "classfile/symbolTable.hpp"
  28 #include "classfile/systemDictionary.hpp"
  29 #include "classfile/vmSymbols.hpp"
  30 #include "code/codeCache.hpp"
  31 #include "code/icBuffer.hpp"
  32 #include "gc_implementation/g1/g1Log.hpp"
  33 #include "gc_implementation/g1/g1MarkSweep.hpp"

  34 #include "gc_implementation/shared/gcHeapSummary.hpp"
  35 #include "gc_implementation/shared/gcTimer.hpp"
  36 #include "gc_implementation/shared/gcTrace.hpp"
  37 #include "gc_implementation/shared/gcTraceTime.hpp"
  38 #include "memory/gcLocker.hpp"
  39 #include "memory/genCollectedHeap.hpp"
  40 #include "memory/modRefBarrierSet.hpp"
  41 #include "memory/referencePolicy.hpp"
  42 #include "memory/space.hpp"
  43 #include "oops/instanceRefKlass.hpp"
  44 #include "oops/oop.inline.hpp"
  45 #include "prims/jvmtiExport.hpp"
  46 #include "runtime/biasedLocking.hpp"
  47 #include "runtime/fprofiler.hpp"
  48 #include "runtime/synchronizer.hpp"
  49 #include "runtime/thread.hpp"
  50 #include "runtime/vmThread.hpp"
  51 #include "utilities/copy.hpp"
  52 #include "utilities/events.hpp"
  53 


 144     rp->process_discovered_references(&GenMarkSweep::is_alive,
 145                                       &GenMarkSweep::keep_alive,
 146                                       &GenMarkSweep::follow_stack_closure,
 147                                       NULL,
 148                                       gc_timer());
 149   gc_tracer()->report_gc_reference_stats(stats);
 150 
 151 
 152   // This is the point where the entire marking should have completed.
 153   assert(GenMarkSweep::_marking_stack.is_empty(), "Marking should have completed");
 154 
 155   // Unload classes and purge the SystemDictionary.
 156   bool purged_class = SystemDictionary::do_unloading(&GenMarkSweep::is_alive);
 157 
 158   // Unload nmethods.
 159   CodeCache::do_unloading(&GenMarkSweep::is_alive, purged_class);
 160 
 161   // Prune dead klasses from subklass/sibling/implementor lists.
 162   Klass::clean_weak_klass_links(&GenMarkSweep::is_alive);
 163 



 164   // Delete entries for dead interned string and clean up unreferenced symbols in symbol table.
 165   G1CollectedHeap::heap()->unlink_string_and_symbol_table(&GenMarkSweep::is_alive);
 166 
 167   if (VerifyDuringGC) {
 168     HandleMark hm;  // handle scope
 169     COMPILER2_PRESENT(DerivedPointerTableDeactivate dpt_deact);
 170     Universe::heap()->prepare_for_verify();
 171     // Note: we can verify only the heap here. When an object is
 172     // marked, the previous value of the mark word (including
 173     // identity hash values, ages, etc) is preserved, and the mark
 174     // word is set to markOop::marked_value - effectively removing
 175     // any hash values from the mark word. These hash values are
 176     // used when verifying the dictionaries and so removing them
 177     // from the mark word can make verification of the dictionaries
 178     // fail. At the end of the GC, the original mark word values
 179     // (including hash values) are restored to the appropriate
 180     // objects.
 181     if (!VerifySilently) {
 182       gclog_or_tty->print(" VerifyDuringGC:(full)[Verifying ");
 183     }


 300   GCTraceTime tm("phase 3", G1Log::fine() && Verbose, true, gc_timer());
 301   GenMarkSweep::trace("3");
 302 
 303   SharedHeap* sh = SharedHeap::heap();
 304 
 305   // Need cleared claim bits for the strong roots processing
 306   ClassLoaderDataGraph::clear_claimed_marks();
 307 
 308   sh->process_strong_roots(true,  // activate StrongRootsScope
 309                            SharedHeap::SO_AllClasses | SharedHeap::SO_Strings | SharedHeap::SO_AllCodeCache,
 310                            &GenMarkSweep::adjust_pointer_closure,
 311                            &GenMarkSweep::adjust_klass_closure);
 312 
 313   assert(GenMarkSweep::ref_processor() == g1h->ref_processor_stw(), "Sanity");
 314   g1h->ref_processor_stw()->weak_oops_do(&GenMarkSweep::adjust_pointer_closure);
 315 
 316   // Now adjust pointers in remaining weak roots.  (All of which should
 317   // have been cleared if they pointed to non-surviving objects.)
 318   sh->process_weak_roots(&GenMarkSweep::adjust_pointer_closure);
 319 



 320   GenMarkSweep::adjust_marks();
 321 
 322   G1AdjustPointersClosure blk;
 323   g1h->heap_region_iterate(&blk);
 324 }
 325 
 326 class G1SpaceCompactClosure: public HeapRegionClosure {
 327 public:
 328   G1SpaceCompactClosure() {}
 329 
 330   bool doHeapRegion(HeapRegion* hr) {
 331     if (hr->isHumongous()) {
 332       if (hr->startsHumongous()) {
 333         oop obj = oop(hr->bottom());
 334         if (obj->is_gc_marked()) {
 335           obj->init_mark();
 336         } else {
 337           assert(hr->is_empty(), "Should have been cleared in phase 2.");
 338         }
 339         hr->reset_during_compaction();




  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/javaClasses.hpp"
  27 #include "classfile/symbolTable.hpp"
  28 #include "classfile/systemDictionary.hpp"
  29 #include "classfile/vmSymbols.hpp"
  30 #include "code/codeCache.hpp"
  31 #include "code/icBuffer.hpp"
  32 #include "gc_implementation/g1/g1Log.hpp"
  33 #include "gc_implementation/g1/g1MarkSweep.hpp"
  34 #include "gc_implementation/g1/stringDedup.hpp"
  35 #include "gc_implementation/shared/gcHeapSummary.hpp"
  36 #include "gc_implementation/shared/gcTimer.hpp"
  37 #include "gc_implementation/shared/gcTrace.hpp"
  38 #include "gc_implementation/shared/gcTraceTime.hpp"
  39 #include "memory/gcLocker.hpp"
  40 #include "memory/genCollectedHeap.hpp"
  41 #include "memory/modRefBarrierSet.hpp"
  42 #include "memory/referencePolicy.hpp"
  43 #include "memory/space.hpp"
  44 #include "oops/instanceRefKlass.hpp"
  45 #include "oops/oop.inline.hpp"
  46 #include "prims/jvmtiExport.hpp"
  47 #include "runtime/biasedLocking.hpp"
  48 #include "runtime/fprofiler.hpp"
  49 #include "runtime/synchronizer.hpp"
  50 #include "runtime/thread.hpp"
  51 #include "runtime/vmThread.hpp"
  52 #include "utilities/copy.hpp"
  53 #include "utilities/events.hpp"
  54 


 145     rp->process_discovered_references(&GenMarkSweep::is_alive,
 146                                       &GenMarkSweep::keep_alive,
 147                                       &GenMarkSweep::follow_stack_closure,
 148                                       NULL,
 149                                       gc_timer());
 150   gc_tracer()->report_gc_reference_stats(stats);
 151 
 152 
 153   // This is the point where the entire marking should have completed.
 154   assert(GenMarkSweep::_marking_stack.is_empty(), "Marking should have completed");
 155 
 156   // Unload classes and purge the SystemDictionary.
 157   bool purged_class = SystemDictionary::do_unloading(&GenMarkSweep::is_alive);
 158 
 159   // Unload nmethods.
 160   CodeCache::do_unloading(&GenMarkSweep::is_alive, purged_class);
 161 
 162   // Prune dead klasses from subklass/sibling/implementor lists.
 163   Klass::clean_weak_klass_links(&GenMarkSweep::is_alive);
 164 
 165   // Delete dead entries in string deduplication queue/table
 166   StringDedup::unlink(&GenMarkSweep::is_alive);
 167 
 168   // Delete entries for dead interned string and clean up unreferenced symbols in symbol table.
 169   G1CollectedHeap::heap()->unlink_string_and_symbol_table(&GenMarkSweep::is_alive);
 170 
 171   if (VerifyDuringGC) {
 172     HandleMark hm;  // handle scope
 173     COMPILER2_PRESENT(DerivedPointerTableDeactivate dpt_deact);
 174     Universe::heap()->prepare_for_verify();
 175     // Note: we can verify only the heap here. When an object is
 176     // marked, the previous value of the mark word (including
 177     // identity hash values, ages, etc) is preserved, and the mark
 178     // word is set to markOop::marked_value - effectively removing
 179     // any hash values from the mark word. These hash values are
 180     // used when verifying the dictionaries and so removing them
 181     // from the mark word can make verification of the dictionaries
 182     // fail. At the end of the GC, the original mark word values
 183     // (including hash values) are restored to the appropriate
 184     // objects.
 185     if (!VerifySilently) {
 186       gclog_or_tty->print(" VerifyDuringGC:(full)[Verifying ");
 187     }


 304   GCTraceTime tm("phase 3", G1Log::fine() && Verbose, true, gc_timer());
 305   GenMarkSweep::trace("3");
 306 
 307   SharedHeap* sh = SharedHeap::heap();
 308 
 309   // Need cleared claim bits for the strong roots processing
 310   ClassLoaderDataGraph::clear_claimed_marks();
 311 
 312   sh->process_strong_roots(true,  // activate StrongRootsScope
 313                            SharedHeap::SO_AllClasses | SharedHeap::SO_Strings | SharedHeap::SO_AllCodeCache,
 314                            &GenMarkSweep::adjust_pointer_closure,
 315                            &GenMarkSweep::adjust_klass_closure);
 316 
 317   assert(GenMarkSweep::ref_processor() == g1h->ref_processor_stw(), "Sanity");
 318   g1h->ref_processor_stw()->weak_oops_do(&GenMarkSweep::adjust_pointer_closure);
 319 
 320   // Now adjust pointers in remaining weak roots.  (All of which should
 321   // have been cleared if they pointed to non-surviving objects.)
 322   sh->process_weak_roots(&GenMarkSweep::adjust_pointer_closure);
 323 
 324   // Adjust pointers in the string deduplication queue/table
 325   StringDedup::oops_do(&GenMarkSweep::adjust_pointer_closure);
 326 
 327   GenMarkSweep::adjust_marks();
 328 
 329   G1AdjustPointersClosure blk;
 330   g1h->heap_region_iterate(&blk);
 331 }
 332 
 333 class G1SpaceCompactClosure: public HeapRegionClosure {
 334 public:
 335   G1SpaceCompactClosure() {}
 336 
 337   bool doHeapRegion(HeapRegion* hr) {
 338     if (hr->isHumongous()) {
 339       if (hr->startsHumongous()) {
 340         oop obj = oop(hr->bottom());
 341         if (obj->is_gc_marked()) {
 342           obj->init_mark();
 343         } else {
 344           assert(hr->is_empty(), "Should have been cleared in phase 2.");
 345         }
 346         hr->reset_during_compaction();