< prev index next >

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

Print this page
@@ -23,69 +23,81 @@
   */
  
  #include "precompiled.hpp"
  #include "gc/shared/markBitMap.inline.hpp"
  #include "gc/shenandoah/shenandoahHeap.inline.hpp"
- #include "gc/shenandoah/shenandoahHeapRegion.inline.hpp"
  #include "gc/shenandoah/shenandoahMarkingContext.hpp"
- #include "gc/shenandoah/shenandoahTaskqueue.inline.hpp"
- #include "utilities/stack.inline.hpp"
  
- ShenandoahMarkingContext::ShenandoahMarkingContext(MemRegion heap_region, MemRegion bitmap_region, size_t num_regions, uint max_queues) :
+ ShenandoahMarkingContext::ShenandoahMarkingContext(MemRegion heap_region, MemRegion bitmap_region, size_t num_regions) :
    _mark_bit_map(heap_region, bitmap_region),
    _top_bitmaps(NEW_C_HEAP_ARRAY(HeapWord*, num_regions, mtGC)),
    _top_at_mark_starts_base(NEW_C_HEAP_ARRAY(HeapWord*, num_regions, mtGC)),
    _top_at_mark_starts(_top_at_mark_starts_base -
-                       ((uintx) heap_region.start() >> ShenandoahHeapRegion::region_size_bytes_shift())),
-   _task_queues(new ShenandoahObjToScanQueueSet(max_queues)) {
-   assert(max_queues > 0, "At least one queue");
-   for (uint i = 0; i < max_queues; ++i) {
-     ShenandoahObjToScanQueue* task_queue = new ShenandoahObjToScanQueue();
-     _task_queues->register_queue(i, task_queue);
-   }
- }
- 
- ShenandoahMarkingContext::~ShenandoahMarkingContext() {
-   for (uint i = 0; i < _task_queues->size(); ++i) {
-     ShenandoahObjToScanQueue* q = _task_queues->queue(i);
-     delete q;
-   }
-   delete _task_queues;
+                       ((uintx) heap_region.start() >> ShenandoahHeapRegion::region_size_bytes_shift())) {
  }
  
  bool ShenandoahMarkingContext::is_bitmap_clear() const {
    ShenandoahHeap* heap = ShenandoahHeap::heap();
    size_t num_regions = heap->num_regions();
    for (size_t idx = 0; idx < num_regions; idx++) {
      ShenandoahHeapRegion* r = heap->get_region(idx);
-     if (heap->is_bitmap_slice_committed(r) && !is_bitmap_clear_range(r->bottom(), r->end())) {
+     if ((r->affiliation() != FREE) && heap->is_bitmap_slice_committed(r) && !is_bitmap_clear_range(r->bottom(), r->end())) {
        return false;
      }
    }
    return true;
  }
  
- bool ShenandoahMarkingContext::is_bitmap_clear_range(HeapWord* start, HeapWord* end) const {
-   return _mark_bit_map.get_next_marked_addr(start, end) == end;
+ bool ShenandoahMarkingContext::is_bitmap_clear_range(const HeapWord* start, const HeapWord* end) const {
+   if (start < end) {
+     ShenandoahHeap* heap = ShenandoahHeap::heap();
+     size_t start_idx = heap->heap_region_index_containing(start);
+     size_t end_idx = heap->heap_region_index_containing(end - 1);
+     while (start_idx <= end_idx) {
+       ShenandoahHeapRegion* r = heap->get_region(start_idx);
+       if (!heap->is_bitmap_slice_committed(r))
+         return true;
+       start_idx++;
+     }
+   }
+   return _mark_bit_map.is_bitmap_clear_range(start, end);
  }
  
  void ShenandoahMarkingContext::initialize_top_at_mark_start(ShenandoahHeapRegion* r) {
    size_t idx = r->index();
    HeapWord *bottom = r->bottom();
+ 
    _top_at_mark_starts_base[idx] = bottom;
-   _top_bitmaps[idx] = bottom;
+   // Arrange that the first time we use this bitmap, we clean from bottom to end.
+   _top_bitmaps[idx] = r->end();
+ 
+   log_debug(gc)("SMC:initialize_top_at_mark_start for Region " SIZE_FORMAT ", TAMS: " PTR_FORMAT ", TopOfBitMap: " PTR_FORMAT,
+                 r->index(), p2i(bottom), p2i(r->end()));
+ }
+ 
+ HeapWord* ShenandoahMarkingContext::top_bitmap(ShenandoahHeapRegion* r) {
+   return _top_bitmaps[r->index()];
  }
  
  void ShenandoahMarkingContext::clear_bitmap(ShenandoahHeapRegion* r) {
    HeapWord* bottom = r->bottom();
    HeapWord* top_bitmap = _top_bitmaps[r->index()];
-   if (top_bitmap > bottom) {
-     _mark_bit_map.clear_range_large(MemRegion(bottom, top_bitmap));
-     _top_bitmaps[r->index()] = bottom;
+ 
+   log_debug(gc)("SMC:clear_bitmap for %s Region " SIZE_FORMAT ", top_bitmap: " PTR_FORMAT,
+                 affiliation_name(r->affiliation()), r->index(), p2i(top_bitmap));
+ 
+   if (r->affiliation() != FREE) {
+     if (top_bitmap > bottom) {
+       _mark_bit_map.clear_range_large(MemRegion(bottom, top_bitmap));
+       _top_bitmaps[r->index()] = bottom;
+     }
+     r->clear_live_data();
+     assert(is_bitmap_clear_range(bottom, r->end()),
+            "Region " SIZE_FORMAT " should have no marks in bitmap", r->index());
    }
-   assert(is_bitmap_clear_range(bottom, r->end()),
-          "Region " SIZE_FORMAT " should have no marks in bitmap", r->index());
+   // heap iterators include FREE regions, which don't need to be cleared.
+   // TODO: would be better for certain iterators to not include FREE regions.
  }
  
  bool ShenandoahMarkingContext::is_complete() {
    return _is_complete.is_set();
  }
< prev index next >