< prev index next >

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

Print this page

  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 "memory/allocation.hpp"
  27 #include "memory/universe.hpp"
  28 
  29 #include "gc/shared/gcArguments.hpp"
  30 #include "gc/shared/gcTimer.hpp"
  31 #include "gc/shared/gcTraceTime.inline.hpp"
  32 #include "gc/shared/locationPrinter.inline.hpp"
  33 #include "gc/shared/memAllocator.hpp"
  34 #include "gc/shared/plab.hpp"

  35 #include "gc/shared/tlab_globals.hpp"
  36 
  37 #include "gc/shenandoah/shenandoahBarrierSet.hpp"
  38 #include "gc/shenandoah/shenandoahClosures.inline.hpp"
  39 #include "gc/shenandoah/shenandoahCollectionSet.hpp"
  40 #include "gc/shenandoah/shenandoahCollectorPolicy.hpp"
  41 #include "gc/shenandoah/shenandoahConcurrentMark.hpp"
  42 #include "gc/shenandoah/shenandoahControlThread.hpp"
  43 #include "gc/shenandoah/shenandoahFreeSet.hpp"
  44 #include "gc/shenandoah/shenandoahPhaseTimings.hpp"
  45 #include "gc/shenandoah/shenandoahHeap.inline.hpp"
  46 #include "gc/shenandoah/shenandoahHeapRegion.inline.hpp"
  47 #include "gc/shenandoah/shenandoahHeapRegionSet.hpp"
  48 #include "gc/shenandoah/shenandoahInitLogger.hpp"
  49 #include "gc/shenandoah/shenandoahMarkingContext.inline.hpp"
  50 #include "gc/shenandoah/shenandoahMemoryPool.hpp"
  51 #include "gc/shenandoah/shenandoahMetrics.hpp"
  52 #include "gc/shenandoah/shenandoahMonitoringSupport.hpp"
  53 #include "gc/shenandoah/shenandoahOopClosures.inline.hpp"
  54 #include "gc/shenandoah/shenandoahPacer.inline.hpp"

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


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

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

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

1304     cl->do_object(obj);
1305     obj->oop_iterate(&oops);
1306   }
1307 
1308   assert(oop_stack.is_empty(), "should be empty");
1309   // Reclaim bitmap
1310   reclaim_aux_bitmap_for_iteration();
1311 }
1312 
1313 bool ShenandoahHeap::prepare_aux_bitmap_for_iteration() {
1314   assert(SafepointSynchronize::is_at_safepoint(), "safe iteration is only available during safepoints");
1315 
1316   if (!_aux_bitmap_region_special && !os::commit_memory((char*)_aux_bitmap_region.start(), _aux_bitmap_region.byte_size(), false)) {
1317     log_warning(gc)("Could not commit native memory for auxiliary marking bitmap for heap iteration");
1318     return false;
1319   }
1320   // Reset bitmap
1321   _aux_bit_map.clear();
1322   return true;
1323 }

  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 "memory/allocation.hpp"
  27 #include "memory/universe.hpp"
  28 
  29 #include "gc/shared/gcArguments.hpp"
  30 #include "gc/shared/gcTimer.hpp"
  31 #include "gc/shared/gcTraceTime.inline.hpp"
  32 #include "gc/shared/locationPrinter.inline.hpp"
  33 #include "gc/shared/memAllocator.hpp"
  34 #include "gc/shared/plab.hpp"
  35 #include "gc/shared/slidingForwarding.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/shenandoahControlThread.hpp"
  44 #include "gc/shenandoah/shenandoahFreeSet.hpp"
  45 #include "gc/shenandoah/shenandoahPhaseTimings.hpp"
  46 #include "gc/shenandoah/shenandoahHeap.inline.hpp"
  47 #include "gc/shenandoah/shenandoahHeapRegion.inline.hpp"
  48 #include "gc/shenandoah/shenandoahHeapRegionSet.hpp"
  49 #include "gc/shenandoah/shenandoahInitLogger.hpp"
  50 #include "gc/shenandoah/shenandoahMarkingContext.inline.hpp"
  51 #include "gc/shenandoah/shenandoahMemoryPool.hpp"
  52 #include "gc/shenandoah/shenandoahMetrics.hpp"
  53 #include "gc/shenandoah/shenandoahMonitoringSupport.hpp"
  54 #include "gc/shenandoah/shenandoahOopClosures.inline.hpp"
  55 #include "gc/shenandoah/shenandoahPacer.inline.hpp"

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

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

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