src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp
changeset 54047 0a9cb99a98a0
parent 54046 f02c6b980c04
child 54093 9d02451b536e
equal deleted inserted replaced
54046:f02c6b980c04 54047:0a9cb99a98a0
   171   //
   171   //
   172 
   172 
   173   ReservedSpace heap_rs = Universe::reserve_heap(max_byte_size, heap_alignment);
   173   ReservedSpace heap_rs = Universe::reserve_heap(max_byte_size, heap_alignment);
   174   initialize_reserved_region((HeapWord*)heap_rs.base(), (HeapWord*) (heap_rs.base() + heap_rs.size()));
   174   initialize_reserved_region((HeapWord*)heap_rs.base(), (HeapWord*) (heap_rs.base() + heap_rs.size()));
   175   _heap_region = MemRegion((HeapWord*)heap_rs.base(), heap_rs.size() / HeapWordSize);
   175   _heap_region = MemRegion((HeapWord*)heap_rs.base(), heap_rs.size() / HeapWordSize);
       
   176   _heap_region_special = heap_rs.special();
   176 
   177 
   177   assert((((size_t) base()) & ShenandoahHeapRegion::region_size_bytes_mask()) == 0,
   178   assert((((size_t) base()) & ShenandoahHeapRegion::region_size_bytes_mask()) == 0,
   178          "Misaligned heap: " PTR_FORMAT, p2i(base()));
   179          "Misaligned heap: " PTR_FORMAT, p2i(base()));
   179 
   180 
   180   ReservedSpace sh_rs = heap_rs.first_part(max_byte_size);
   181   ReservedSpace sh_rs = heap_rs.first_part(max_byte_size);
   181   os::commit_memory_or_exit(sh_rs.base(), _initial_size, heap_alignment, false,
   182   if (!_heap_region_special) {
   182                             "Cannot commit heap memory");
   183     os::commit_memory_or_exit(sh_rs.base(), _initial_size, heap_alignment, false,
       
   184                               "Cannot commit heap memory");
       
   185   }
   183 
   186 
   184   //
   187   //
   185   // Reserve and commit memory for bitmap(s)
   188   // Reserve and commit memory for bitmap(s)
   186   //
   189   //
   187 
   190 
   212             _bitmap_bytes_per_slice, bitmap_page_size);
   215             _bitmap_bytes_per_slice, bitmap_page_size);
   213 
   216 
   214   ReservedSpace bitmap(_bitmap_size, bitmap_page_size);
   217   ReservedSpace bitmap(_bitmap_size, bitmap_page_size);
   215   MemTracker::record_virtual_memory_type(bitmap.base(), mtGC);
   218   MemTracker::record_virtual_memory_type(bitmap.base(), mtGC);
   216   _bitmap_region = MemRegion((HeapWord*) bitmap.base(), bitmap.size() / HeapWordSize);
   219   _bitmap_region = MemRegion((HeapWord*) bitmap.base(), bitmap.size() / HeapWordSize);
       
   220   _bitmap_region_special = bitmap.special();
   217 
   221 
   218   size_t bitmap_init_commit = _bitmap_bytes_per_slice *
   222   size_t bitmap_init_commit = _bitmap_bytes_per_slice *
   219                               align_up(num_committed_regions, _bitmap_regions_per_slice) / _bitmap_regions_per_slice;
   223                               align_up(num_committed_regions, _bitmap_regions_per_slice) / _bitmap_regions_per_slice;
   220   bitmap_init_commit = MIN2(_bitmap_size, bitmap_init_commit);
   224   bitmap_init_commit = MIN2(_bitmap_size, bitmap_init_commit);
   221   os::commit_memory_or_exit((char *)_bitmap_region.start(), bitmap_init_commit, bitmap_page_size, false,
   225   if (!_bitmap_region_special) {
   222                             "Cannot commit bitmap memory");
   226     os::commit_memory_or_exit((char *) _bitmap_region.start(), bitmap_init_commit, bitmap_page_size, false,
       
   227                               "Cannot commit bitmap memory");
       
   228   }
   223 
   229 
   224   _marking_context = new ShenandoahMarkingContext(_heap_region, _bitmap_region, _num_regions);
   230   _marking_context = new ShenandoahMarkingContext(_heap_region, _bitmap_region, _num_regions);
   225 
   231 
   226   if (ShenandoahVerify) {
   232   if (ShenandoahVerify) {
   227     ReservedSpace verify_bitmap(_bitmap_size, bitmap_page_size);
   233     ReservedSpace verify_bitmap(_bitmap_size, bitmap_page_size);
   228     os::commit_memory_or_exit(verify_bitmap.base(), verify_bitmap.size(), bitmap_page_size, false,
   234     if (!verify_bitmap.special()) {
   229                               "Cannot commit verification bitmap memory");
   235       os::commit_memory_or_exit(verify_bitmap.base(), verify_bitmap.size(), bitmap_page_size, false,
       
   236                                 "Cannot commit verification bitmap memory");
       
   237     }
   230     MemTracker::record_virtual_memory_type(verify_bitmap.base(), mtGC);
   238     MemTracker::record_virtual_memory_type(verify_bitmap.base(), mtGC);
   231     MemRegion verify_bitmap_region = MemRegion((HeapWord *) verify_bitmap.base(), verify_bitmap.size() / HeapWordSize);
   239     MemRegion verify_bitmap_region = MemRegion((HeapWord *) verify_bitmap.base(), verify_bitmap.size() / HeapWordSize);
   232     _verification_bit_map.initialize(_heap_region, verify_bitmap_region);
   240     _verification_bit_map.initialize(_heap_region, verify_bitmap_region);
   233     _verifier = new ShenandoahVerifier(this, &_verification_bit_map);
   241     _verifier = new ShenandoahVerifier(this, &_verification_bit_map);
   234   }
   242   }
   235 
   243 
   236   // Reserve aux bitmap for use in object_iterate(). We don't commit it here.
   244   // Reserve aux bitmap for use in object_iterate(). We don't commit it here.
   237   ReservedSpace aux_bitmap(_bitmap_size, bitmap_page_size);
   245   ReservedSpace aux_bitmap(_bitmap_size, bitmap_page_size);
   238   MemTracker::record_virtual_memory_type(aux_bitmap.base(), mtGC);
   246   MemTracker::record_virtual_memory_type(aux_bitmap.base(), mtGC);
   239   _aux_bitmap_region = MemRegion((HeapWord*) aux_bitmap.base(), aux_bitmap.size() / HeapWordSize);
   247   _aux_bitmap_region = MemRegion((HeapWord*) aux_bitmap.base(), aux_bitmap.size() / HeapWordSize);
       
   248   _aux_bitmap_region_special = aux_bitmap.special();
   240   _aux_bit_map.initialize(_heap_region, _aux_bitmap_region);
   249   _aux_bit_map.initialize(_heap_region, _aux_bitmap_region);
   241 
   250 
   242   //
   251   //
   243   // Create regions and region sets
   252   // Create regions and region sets
   244   //
   253   //
   404   _committed(0),
   413   _committed(0),
   405   _bytes_allocated_since_gc_start(0),
   414   _bytes_allocated_since_gc_start(0),
   406   _max_workers(MAX2(ConcGCThreads, ParallelGCThreads)),
   415   _max_workers(MAX2(ConcGCThreads, ParallelGCThreads)),
   407   _workers(NULL),
   416   _workers(NULL),
   408   _safepoint_workers(NULL),
   417   _safepoint_workers(NULL),
       
   418   _heap_region_special(false),
   409   _num_regions(0),
   419   _num_regions(0),
   410   _regions(NULL),
   420   _regions(NULL),
   411   _update_refs_iterator(this),
   421   _update_refs_iterator(this),
   412   _control_thread(NULL),
   422   _control_thread(NULL),
   413   _shenandoah_policy(policy),
   423   _shenandoah_policy(policy),
   429   _ref_processor(NULL),
   439   _ref_processor(NULL),
   430   _marking_context(NULL),
   440   _marking_context(NULL),
   431   _bitmap_size(0),
   441   _bitmap_size(0),
   432   _bitmap_regions_per_slice(0),
   442   _bitmap_regions_per_slice(0),
   433   _bitmap_bytes_per_slice(0),
   443   _bitmap_bytes_per_slice(0),
       
   444   _bitmap_region_special(false),
       
   445   _aux_bitmap_region_special(false),
   434   _liveness_cache(NULL),
   446   _liveness_cache(NULL),
   435   _collection_set(NULL)
   447   _collection_set(NULL)
   436 {
   448 {
   437   log_info(gc, init)("GC threads: " UINT32_FORMAT " parallel, " UINT32_FORMAT " concurrent", ParallelGCThreads, ConcGCThreads);
   449   log_info(gc, init)("GC threads: " UINT32_FORMAT " parallel, " UINT32_FORMAT " concurrent", ParallelGCThreads, ConcGCThreads);
   438   log_info(gc, init)("Reference processing: %s", ParallelRefProcEnabled ? "parallel" : "serial");
   450   log_info(gc, init)("Reference processing: %s", ParallelRefProcEnabled ? "parallel" : "serial");
  1314  * objects as we mark+traverse through the heap, starting from GC roots. JVMTI IterateThroughHeap
  1326  * objects as we mark+traverse through the heap, starting from GC roots. JVMTI IterateThroughHeap
  1315  * is allowed to report dead objects, but is not required to do so.
  1327  * is allowed to report dead objects, but is not required to do so.
  1316  */
  1328  */
  1317 void ShenandoahHeap::object_iterate(ObjectClosure* cl) {
  1329 void ShenandoahHeap::object_iterate(ObjectClosure* cl) {
  1318   assert(SafepointSynchronize::is_at_safepoint(), "safe iteration is only available during safepoints");
  1330   assert(SafepointSynchronize::is_at_safepoint(), "safe iteration is only available during safepoints");
  1319   if (!os::commit_memory((char*)_aux_bitmap_region.start(), _aux_bitmap_region.byte_size(), false)) {
  1331   if (!_aux_bitmap_region_special && !os::commit_memory((char*)_aux_bitmap_region.start(), _aux_bitmap_region.byte_size(), false)) {
  1320     log_warning(gc)("Could not commit native memory for auxiliary marking bitmap for heap iteration");
  1332     log_warning(gc)("Could not commit native memory for auxiliary marking bitmap for heap iteration");
  1321     return;
  1333     return;
  1322   }
  1334   }
  1323 
  1335 
  1324   // Reset bitmap
  1336   // Reset bitmap
  1341     obj->oop_iterate(&oops);
  1353     obj->oop_iterate(&oops);
  1342   }
  1354   }
  1343 
  1355 
  1344   assert(oop_stack.is_empty(), "should be empty");
  1356   assert(oop_stack.is_empty(), "should be empty");
  1345 
  1357 
  1346   if (!os::uncommit_memory((char*)_aux_bitmap_region.start(), _aux_bitmap_region.byte_size())) {
  1358   if (!_aux_bitmap_region_special && !os::uncommit_memory((char*)_aux_bitmap_region.start(), _aux_bitmap_region.byte_size())) {
  1347     log_warning(gc)("Could not uncommit native memory for auxiliary marking bitmap for heap iteration");
  1359     log_warning(gc)("Could not uncommit native memory for auxiliary marking bitmap for heap iteration");
  1348   }
  1360   }
  1349 }
  1361 }
  1350 
  1362 
  1351 void ShenandoahHeap::safe_object_iterate(ObjectClosure* cl) {
  1363 void ShenandoahHeap::safe_object_iterate(ObjectClosure* cl) {
  2268 }
  2280 }
  2269 
  2281 
  2270 bool ShenandoahHeap::commit_bitmap_slice(ShenandoahHeapRegion* r) {
  2282 bool ShenandoahHeap::commit_bitmap_slice(ShenandoahHeapRegion* r) {
  2271   assert_heaplock_owned_by_current_thread();
  2283   assert_heaplock_owned_by_current_thread();
  2272 
  2284 
       
  2285   // Bitmaps in special regions do not need commits
       
  2286   if (_bitmap_region_special) {
       
  2287     return true;
       
  2288   }
       
  2289 
  2273   if (is_bitmap_slice_committed(r, true)) {
  2290   if (is_bitmap_slice_committed(r, true)) {
  2274     // Some other region from the group is already committed, meaning the bitmap
  2291     // Some other region from the group is already committed, meaning the bitmap
  2275     // slice is already committed, we exit right away.
  2292     // slice is already committed, we exit right away.
  2276     return true;
  2293     return true;
  2277   }
  2294   }
  2286   return true;
  2303   return true;
  2287 }
  2304 }
  2288 
  2305 
  2289 bool ShenandoahHeap::uncommit_bitmap_slice(ShenandoahHeapRegion *r) {
  2306 bool ShenandoahHeap::uncommit_bitmap_slice(ShenandoahHeapRegion *r) {
  2290   assert_heaplock_owned_by_current_thread();
  2307   assert_heaplock_owned_by_current_thread();
       
  2308 
       
  2309   // Bitmaps in special regions do not need uncommits
       
  2310   if (_bitmap_region_special) {
       
  2311     return true;
       
  2312   }
  2291 
  2313 
  2292   if (is_bitmap_slice_committed(r, true)) {
  2314   if (is_bitmap_slice_committed(r, true)) {
  2293     // Some other region from the group is still committed, meaning the bitmap
  2315     // Some other region from the group is still committed, meaning the bitmap
  2294     // slice is should stay committed, exit right away.
  2316     // slice is should stay committed, exit right away.
  2295     return true;
  2317     return true;