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

Print this page
rev 6083 : 8029075: String deduplication in G1
Implementation of JEP 192, http://openjdk.java.net/jeps/192
   1 /*
   2  * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  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 


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




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


   1 /*
   2  * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  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/g1StringDedup.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 


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