< prev index next >

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

Print this page

  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 "gc/shared/markBitMap.inline.hpp"
 27 #include "gc/shenandoah/shenandoahHeap.inline.hpp"
 28 #include "gc/shenandoah/shenandoahHeapRegion.inline.hpp"
 29 #include "gc/shenandoah/shenandoahMarkingContext.hpp"
 30 #include "gc/shenandoah/shenandoahTaskqueue.inline.hpp"
 31 #include "utilities/stack.inline.hpp"
 32 
 33 ShenandoahMarkingContext::ShenandoahMarkingContext(MemRegion heap_region, MemRegion bitmap_region, size_t num_regions, uint max_queues) :
 34   _mark_bit_map(heap_region, bitmap_region),
 35   _top_bitmaps(NEW_C_HEAP_ARRAY(HeapWord*, num_regions, mtGC)),
 36   _top_at_mark_starts_base(NEW_C_HEAP_ARRAY(HeapWord*, num_regions, mtGC)),
 37   _top_at_mark_starts(_top_at_mark_starts_base -
 38                       ((uintx) heap_region.start() >> ShenandoahHeapRegion::region_size_bytes_shift())),
 39   _task_queues(new ShenandoahObjToScanQueueSet(max_queues)) {
 40   assert(max_queues > 0, "At least one queue");
 41   for (uint i = 0; i < max_queues; ++i) {
 42     ShenandoahObjToScanQueue* task_queue = new ShenandoahObjToScanQueue();
 43     _task_queues->register_queue(i, task_queue);
 44   }
 45 }
 46 
 47 ShenandoahMarkingContext::~ShenandoahMarkingContext() {
 48   for (uint i = 0; i < _task_queues->size(); ++i) {
 49     ShenandoahObjToScanQueue* q = _task_queues->queue(i);
 50     delete q;
 51   }
 52   delete _task_queues;
 53 }
 54 
 55 bool ShenandoahMarkingContext::is_bitmap_clear() const {
 56   ShenandoahHeap* heap = ShenandoahHeap::heap();
 57   size_t num_regions = heap->num_regions();
 58   for (size_t idx = 0; idx < num_regions; idx++) {
 59     ShenandoahHeapRegion* r = heap->get_region(idx);
 60     if (heap->is_bitmap_slice_committed(r) && !is_bitmap_clear_range(r->bottom(), r->end())) {
 61       return false;
 62     }
 63   }
 64   return true;
 65 }
 66 
 67 bool ShenandoahMarkingContext::is_bitmap_clear_range(HeapWord* start, HeapWord* end) const {
 68   return _mark_bit_map.get_next_marked_addr(start, end) == end;











 69 }
 70 
 71 void ShenandoahMarkingContext::initialize_top_at_mark_start(ShenandoahHeapRegion* r) {
 72   size_t idx = r->index();
 73   HeapWord *bottom = r->bottom();

 74   _top_at_mark_starts_base[idx] = bottom;
 75   _top_bitmaps[idx] = bottom;








 76 }
 77 
 78 void ShenandoahMarkingContext::clear_bitmap(ShenandoahHeapRegion* r) {
 79   HeapWord* bottom = r->bottom();
 80   HeapWord* top_bitmap = _top_bitmaps[r->index()];
 81   if (top_bitmap > bottom) {
 82     _mark_bit_map.clear_range_large(MemRegion(bottom, top_bitmap));
 83     _top_bitmaps[r->index()] = bottom;









 84   }
 85   assert(is_bitmap_clear_range(bottom, r->end()),
 86          "Region " SIZE_FORMAT " should have no marks in bitmap", r->index());
 87 }
 88 
 89 bool ShenandoahMarkingContext::is_complete() {
 90   return _is_complete.is_set();
 91 }
 92 
 93 void ShenandoahMarkingContext::mark_complete() {
 94   _is_complete.set();
 95 }
 96 
 97 void ShenandoahMarkingContext::mark_incomplete() {
 98   _is_complete.unset();
 99 }

  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 "gc/shared/markBitMap.inline.hpp"
 27 #include "gc/shenandoah/shenandoahHeap.inline.hpp"

 28 #include "gc/shenandoah/shenandoahMarkingContext.hpp"


 29 
 30 ShenandoahMarkingContext::ShenandoahMarkingContext(MemRegion heap_region, MemRegion bitmap_region, size_t num_regions) :
 31   _mark_bit_map(heap_region, bitmap_region),
 32   _top_bitmaps(NEW_C_HEAP_ARRAY(HeapWord*, num_regions, mtGC)),
 33   _top_at_mark_starts_base(NEW_C_HEAP_ARRAY(HeapWord*, num_regions, mtGC)),
 34   _top_at_mark_starts(_top_at_mark_starts_base -
 35                       ((uintx) heap_region.start() >> ShenandoahHeapRegion::region_size_bytes_shift())) {














 36 }
 37 
 38 bool ShenandoahMarkingContext::is_bitmap_clear() const {
 39   ShenandoahHeap* heap = ShenandoahHeap::heap();
 40   size_t num_regions = heap->num_regions();
 41   for (size_t idx = 0; idx < num_regions; idx++) {
 42     ShenandoahHeapRegion* r = heap->get_region(idx);
 43     if ((r->affiliation() != FREE) && heap->is_bitmap_slice_committed(r) && !is_bitmap_clear_range(r->bottom(), r->end())) {
 44       return false;
 45     }
 46   }
 47   return true;
 48 }
 49 
 50 bool ShenandoahMarkingContext::is_bitmap_clear_range(const HeapWord* start, const HeapWord* end) const {
 51   if (start < end) {
 52     ShenandoahHeap* heap = ShenandoahHeap::heap();
 53     size_t start_idx = heap->heap_region_index_containing(start);
 54     size_t end_idx = heap->heap_region_index_containing(end - 1);
 55     while (start_idx <= end_idx) {
 56       ShenandoahHeapRegion* r = heap->get_region(start_idx);
 57       if (!heap->is_bitmap_slice_committed(r))
 58         return true;
 59       start_idx++;
 60     }
 61   }
 62   return _mark_bit_map.is_bitmap_clear_range(start, end);
 63 }
 64 
 65 void ShenandoahMarkingContext::initialize_top_at_mark_start(ShenandoahHeapRegion* r) {
 66   size_t idx = r->index();
 67   HeapWord *bottom = r->bottom();
 68 
 69   _top_at_mark_starts_base[idx] = bottom;
 70   // Arrange that the first time we use this bitmap, we clean from bottom to end.
 71   _top_bitmaps[idx] = r->end();
 72 
 73   log_debug(gc)("SMC:initialize_top_at_mark_start for Region " SIZE_FORMAT ", TAMS: " PTR_FORMAT ", TopOfBitMap: " PTR_FORMAT,
 74                 r->index(), p2i(bottom), p2i(r->end()));
 75 }
 76 
 77 HeapWord* ShenandoahMarkingContext::top_bitmap(ShenandoahHeapRegion* r) {
 78   return _top_bitmaps[r->index()];
 79 }
 80 
 81 void ShenandoahMarkingContext::clear_bitmap(ShenandoahHeapRegion* r) {
 82   HeapWord* bottom = r->bottom();
 83   HeapWord* top_bitmap = _top_bitmaps[r->index()];
 84 
 85   log_debug(gc)("SMC:clear_bitmap for %s Region " SIZE_FORMAT ", top_bitmap: " PTR_FORMAT,
 86                 affiliation_name(r->affiliation()), r->index(), p2i(top_bitmap));
 87 
 88   if (r->affiliation() != FREE) {
 89     if (top_bitmap > bottom) {
 90       _mark_bit_map.clear_range_large(MemRegion(bottom, top_bitmap));
 91       _top_bitmaps[r->index()] = bottom;
 92     }
 93     r->clear_live_data();
 94     assert(is_bitmap_clear_range(bottom, r->end()),
 95            "Region " SIZE_FORMAT " should have no marks in bitmap", r->index());
 96   }
 97   // heap iterators include FREE regions, which don't need to be cleared.
 98   // TODO: would be better for certain iterators to not include FREE regions.
 99 }
100 
101 bool ShenandoahMarkingContext::is_complete() {
102   return _is_complete.is_set();
103 }
104 
105 void ShenandoahMarkingContext::mark_complete() {
106   _is_complete.set();
107 }
108 
109 void ShenandoahMarkingContext::mark_incomplete() {
110   _is_complete.unset();
111 }
< prev index next >