< prev index next >

src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp

Print this page

  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  *
  24  */
  25 
  26 #include "precompiled.hpp"
  27 #include "memory/allocation.hpp"
  28 #include "memory/universe.hpp"
  29 
  30 #include "gc/shared/gcArguments.hpp"

  31 #include "gc/shared/gcTimer.hpp"
  32 #include "gc/shared/gcTraceTime.inline.hpp"
  33 #include "gc/shared/locationPrinter.inline.hpp"
  34 #include "gc/shared/memAllocator.hpp"
  35 #include "gc/shared/plab.hpp"
  36 #include "gc/shared/tlab_globals.hpp"
  37 
  38 #include "gc/shenandoah/shenandoahBarrierSet.hpp"
  39 #include "gc/shenandoah/shenandoahClosures.inline.hpp"
  40 #include "gc/shenandoah/shenandoahCollectionSet.hpp"
  41 #include "gc/shenandoah/shenandoahCollectorPolicy.hpp"
  42 #include "gc/shenandoah/shenandoahConcurrentMark.hpp"
  43 #include "gc/shenandoah/shenandoahMarkingContext.inline.hpp"
  44 #include "gc/shenandoah/shenandoahControlThread.hpp"
  45 #include "gc/shenandoah/shenandoahFreeSet.hpp"
  46 #include "gc/shenandoah/shenandoahPhaseTimings.hpp"
  47 #include "gc/shenandoah/shenandoahHeap.inline.hpp"
  48 #include "gc/shenandoah/shenandoahHeapRegion.inline.hpp"
  49 #include "gc/shenandoah/shenandoahHeapRegionSet.hpp"
  50 #include "gc/shenandoah/shenandoahInitLogger.hpp"

 386     ShenandoahSATBMarkQueueSet& satbqs = ShenandoahBarrierSet::satb_mark_queue_set();
 387     satbqs.set_process_completed_buffers_threshold(20); // G1SATBProcessCompletedThreshold
 388     satbqs.set_buffer_enqueue_threshold_percentage(60); // G1SATBBufferEnqueueingThresholdPercent
 389   }
 390 
 391   _monitoring_support = new ShenandoahMonitoringSupport(this);
 392   _phase_timings = new ShenandoahPhaseTimings(max_workers());
 393   ShenandoahCodeRoots::initialize();
 394 
 395   if (ShenandoahPacing) {
 396     _pacer = new ShenandoahPacer(this);
 397     _pacer->setup_for_idle();
 398   } else {
 399     _pacer = nullptr;
 400   }
 401 
 402   _control_thread = new ShenandoahControlThread();
 403 
 404   ShenandoahInitLogger::print();
 405 


 406   return JNI_OK;
 407 }
 408 
 409 void ShenandoahHeap::initialize_mode() {
 410   if (ShenandoahGCMode != nullptr) {
 411     if (strcmp(ShenandoahGCMode, "satb") == 0) {
 412       _gc_mode = new ShenandoahSATBMode();
 413     } else if (strcmp(ShenandoahGCMode, "iu") == 0) {
 414       _gc_mode = new ShenandoahIUMode();
 415     } else if (strcmp(ShenandoahGCMode, "passive") == 0) {
 416       _gc_mode = new ShenandoahPassiveMode();
 417     } else {
 418       vm_exit_during_initialization("Unknown -XX:ShenandoahGCMode option");
 419     }
 420   } else {
 421     vm_exit_during_initialization("Unknown -XX:ShenandoahGCMode option (null)");
 422   }
 423   _gc_mode->initialize_flags();
 424   if (_gc_mode->is_diagnostic() && !UnlockDiagnosticVMOptions) {
 425     vm_exit_during_initialization(

 932   // Expand and retry allocation
 933   result = loader_data->metaspace_non_null()->expand_and_allocate(size, mdtype);
 934   if (result != nullptr) {
 935     return result;
 936   }
 937 
 938   // Out of memory
 939   return nullptr;
 940 }
 941 
 942 class ShenandoahConcurrentEvacuateRegionObjectClosure : public ObjectClosure {
 943 private:
 944   ShenandoahHeap* const _heap;
 945   Thread* const _thread;
 946 public:
 947   ShenandoahConcurrentEvacuateRegionObjectClosure(ShenandoahHeap* heap) :
 948     _heap(heap), _thread(Thread::current()) {}
 949 
 950   void do_object(oop p) {
 951     shenandoah_assert_marked(nullptr, p);
 952     if (!p->is_forwarded()) {
 953       _heap->evacuate_object(p, _thread);
 954     }
 955   }
 956 };
 957 
 958 class ShenandoahEvacuationTask : public WorkerTask {
 959 private:
 960   ShenandoahHeap* const _sh;
 961   ShenandoahCollectionSet* const _cs;
 962   bool _concurrent;
 963 public:
 964   ShenandoahEvacuationTask(ShenandoahHeap* sh,
 965                            ShenandoahCollectionSet* cs,
 966                            bool concurrent) :
 967     WorkerTask("Shenandoah Evacuation"),
 968     _sh(sh),
 969     _cs(cs),
 970     _concurrent(concurrent)
 971   {}
 972 

1274  * wiped the bitmap in preparation for next marking).
1275  *
1276  * For all those reasons, we implement object iteration as a single marking traversal, reporting
1277  * objects as we mark+traverse through the heap, starting from GC roots. JVMTI IterateThroughHeap
1278  * is allowed to report dead objects, but is not required to do so.
1279  */
1280 void ShenandoahHeap::object_iterate(ObjectClosure* cl) {
1281   // Reset bitmap
1282   if (!prepare_aux_bitmap_for_iteration())
1283     return;
1284 
1285   ShenandoahScanObjectStack oop_stack;
1286   ObjectIterateScanRootClosure oops(&_aux_bit_map, &oop_stack);
1287   // Seed the stack with root scan
1288   scan_roots_for_iteration(&oop_stack, &oops);
1289 
1290   // Work through the oop stack to traverse heap
1291   while (! oop_stack.is_empty()) {
1292     oop obj = oop_stack.pop();
1293     assert(oopDesc::is_oop(obj), "must be a valid oop");

1294     cl->do_object(obj);
1295     obj->oop_iterate(&oops);
1296   }
1297 
1298   assert(oop_stack.is_empty(), "should be empty");
1299   // Reclaim bitmap
1300   reclaim_aux_bitmap_for_iteration();
1301 }
1302 
1303 bool ShenandoahHeap::prepare_aux_bitmap_for_iteration() {
1304   assert(SafepointSynchronize::is_at_safepoint(), "safe iteration is only available during safepoints");
1305 
1306   if (!_aux_bitmap_region_special && !os::commit_memory((char*)_aux_bitmap_region.start(), _aux_bitmap_region.byte_size(), false)) {
1307     log_warning(gc)("Could not commit native memory for auxiliary marking bitmap for heap iteration");
1308     return false;
1309   }
1310   // Reset bitmap
1311   _aux_bit_map.clear();
1312   return true;
1313 }

  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  *
  24  */
  25 
  26 #include "precompiled.hpp"
  27 #include "memory/allocation.hpp"
  28 #include "memory/universe.hpp"
  29 
  30 #include "gc/shared/gcArguments.hpp"
  31 #include "gc/shared/gcForwarding.hpp"
  32 #include "gc/shared/gcTimer.hpp"
  33 #include "gc/shared/gcTraceTime.inline.hpp"
  34 #include "gc/shared/locationPrinter.inline.hpp"
  35 #include "gc/shared/memAllocator.hpp"
  36 #include "gc/shared/plab.hpp"
  37 #include "gc/shared/tlab_globals.hpp"
  38 
  39 #include "gc/shenandoah/shenandoahBarrierSet.hpp"
  40 #include "gc/shenandoah/shenandoahClosures.inline.hpp"
  41 #include "gc/shenandoah/shenandoahCollectionSet.hpp"
  42 #include "gc/shenandoah/shenandoahCollectorPolicy.hpp"
  43 #include "gc/shenandoah/shenandoahConcurrentMark.hpp"
  44 #include "gc/shenandoah/shenandoahMarkingContext.inline.hpp"
  45 #include "gc/shenandoah/shenandoahControlThread.hpp"
  46 #include "gc/shenandoah/shenandoahFreeSet.hpp"
  47 #include "gc/shenandoah/shenandoahPhaseTimings.hpp"
  48 #include "gc/shenandoah/shenandoahHeap.inline.hpp"
  49 #include "gc/shenandoah/shenandoahHeapRegion.inline.hpp"
  50 #include "gc/shenandoah/shenandoahHeapRegionSet.hpp"
  51 #include "gc/shenandoah/shenandoahInitLogger.hpp"

 387     ShenandoahSATBMarkQueueSet& satbqs = ShenandoahBarrierSet::satb_mark_queue_set();
 388     satbqs.set_process_completed_buffers_threshold(20); // G1SATBProcessCompletedThreshold
 389     satbqs.set_buffer_enqueue_threshold_percentage(60); // G1SATBBufferEnqueueingThresholdPercent
 390   }
 391 
 392   _monitoring_support = new ShenandoahMonitoringSupport(this);
 393   _phase_timings = new ShenandoahPhaseTimings(max_workers());
 394   ShenandoahCodeRoots::initialize();
 395 
 396   if (ShenandoahPacing) {
 397     _pacer = new ShenandoahPacer(this);
 398     _pacer->setup_for_idle();
 399   } else {
 400     _pacer = nullptr;
 401   }
 402 
 403   _control_thread = new ShenandoahControlThread();
 404 
 405   ShenandoahInitLogger::print();
 406 
 407   GCForwarding::initialize(_heap_region, ShenandoahHeapRegion::region_size_words());
 408 
 409   return JNI_OK;
 410 }
 411 
 412 void ShenandoahHeap::initialize_mode() {
 413   if (ShenandoahGCMode != nullptr) {
 414     if (strcmp(ShenandoahGCMode, "satb") == 0) {
 415       _gc_mode = new ShenandoahSATBMode();
 416     } else if (strcmp(ShenandoahGCMode, "iu") == 0) {
 417       _gc_mode = new ShenandoahIUMode();
 418     } else if (strcmp(ShenandoahGCMode, "passive") == 0) {
 419       _gc_mode = new ShenandoahPassiveMode();
 420     } else {
 421       vm_exit_during_initialization("Unknown -XX:ShenandoahGCMode option");
 422     }
 423   } else {
 424     vm_exit_during_initialization("Unknown -XX:ShenandoahGCMode option (null)");
 425   }
 426   _gc_mode->initialize_flags();
 427   if (_gc_mode->is_diagnostic() && !UnlockDiagnosticVMOptions) {
 428     vm_exit_during_initialization(

 935   // Expand and retry allocation
 936   result = loader_data->metaspace_non_null()->expand_and_allocate(size, mdtype);
 937   if (result != nullptr) {
 938     return result;
 939   }
 940 
 941   // Out of memory
 942   return nullptr;
 943 }
 944 
 945 class ShenandoahConcurrentEvacuateRegionObjectClosure : public ObjectClosure {
 946 private:
 947   ShenandoahHeap* const _heap;
 948   Thread* const _thread;
 949 public:
 950   ShenandoahConcurrentEvacuateRegionObjectClosure(ShenandoahHeap* heap) :
 951     _heap(heap), _thread(Thread::current()) {}
 952 
 953   void do_object(oop p) {
 954     shenandoah_assert_marked(nullptr, p);
 955     if (!ShenandoahForwarding::is_forwarded(p)) {
 956       _heap->evacuate_object(p, _thread);
 957     }
 958   }
 959 };
 960 
 961 class ShenandoahEvacuationTask : public WorkerTask {
 962 private:
 963   ShenandoahHeap* const _sh;
 964   ShenandoahCollectionSet* const _cs;
 965   bool _concurrent;
 966 public:
 967   ShenandoahEvacuationTask(ShenandoahHeap* sh,
 968                            ShenandoahCollectionSet* cs,
 969                            bool concurrent) :
 970     WorkerTask("Shenandoah Evacuation"),
 971     _sh(sh),
 972     _cs(cs),
 973     _concurrent(concurrent)
 974   {}
 975 

1277  * wiped the bitmap in preparation for next marking).
1278  *
1279  * For all those reasons, we implement object iteration as a single marking traversal, reporting
1280  * objects as we mark+traverse through the heap, starting from GC roots. JVMTI IterateThroughHeap
1281  * is allowed to report dead objects, but is not required to do so.
1282  */
1283 void ShenandoahHeap::object_iterate(ObjectClosure* cl) {
1284   // Reset bitmap
1285   if (!prepare_aux_bitmap_for_iteration())
1286     return;
1287 
1288   ShenandoahScanObjectStack oop_stack;
1289   ObjectIterateScanRootClosure oops(&_aux_bit_map, &oop_stack);
1290   // Seed the stack with root scan
1291   scan_roots_for_iteration(&oop_stack, &oops);
1292 
1293   // Work through the oop stack to traverse heap
1294   while (! oop_stack.is_empty()) {
1295     oop obj = oop_stack.pop();
1296     assert(oopDesc::is_oop(obj), "must be a valid oop");
1297     shenandoah_assert_not_in_cset_except(NULL, obj, cancelled_gc());
1298     cl->do_object(obj);
1299     obj->oop_iterate(&oops);
1300   }
1301 
1302   assert(oop_stack.is_empty(), "should be empty");
1303   // Reclaim bitmap
1304   reclaim_aux_bitmap_for_iteration();
1305 }
1306 
1307 bool ShenandoahHeap::prepare_aux_bitmap_for_iteration() {
1308   assert(SafepointSynchronize::is_at_safepoint(), "safe iteration is only available during safepoints");
1309 
1310   if (!_aux_bitmap_region_special && !os::commit_memory((char*)_aux_bitmap_region.start(), _aux_bitmap_region.byte_size(), false)) {
1311     log_warning(gc)("Could not commit native memory for auxiliary marking bitmap for heap iteration");
1312     return false;
1313   }
1314   // Reset bitmap
1315   _aux_bit_map.clear();
1316   return true;
1317 }
< prev index next >