< prev index next >

src/share/vm/gc_implementation/shenandoah/shenandoahCollectionSet.cpp

Print this page
rev 10542 : [backport] Constify ShHeapRegionSet and ShCollectionSet
rev 10543 : [backport] Application pacing precision fixes
rev 10598 : [backport] Shenandoah changes to allow enabling -Wreorder


  15  * 2 along with this work; if not, write to the Free Software Foundation,
  16  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  17  *
  18  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  19  * or visit www.oracle.com if you need additional information or have any
  20  * questions.
  21  *
  22  */
  23 
  24 #include "precompiled.hpp"
  25 #include "gc_implementation/shenandoah/shenandoahCollectionSet.hpp"
  26 #include "gc_implementation/shenandoah/shenandoahCollectionSet.inline.hpp"
  27 #include "gc_implementation/shenandoah/shenandoahHeap.hpp"
  28 #include "gc_implementation/shenandoah/shenandoahHeap.inline.hpp"
  29 #include "gc_implementation/shenandoah/shenandoahHeapRegion.hpp"
  30 #include "gc_implementation/shenandoah/shenandoahHeapRegionSet.hpp"
  31 #include "runtime/atomic.hpp"
  32 #include "utilities/copy.hpp"
  33 
  34 ShenandoahCollectionSet::ShenandoahCollectionSet(ShenandoahHeap* heap, HeapWord* heap_base) :
  35         _garbage(0), _live_data(0), _heap(heap), _region_count(0),
  36         _map_size(heap->num_regions()), _current_index(0) {








  37   // Use 1-byte data type
  38   STATIC_ASSERT(sizeof(jbyte) == 1);
  39 
  40   _cset_map = NEW_C_HEAP_ARRAY(jbyte, _map_size, mtGC);
  41   // Bias cset map's base address for fast test if an oop is in cset
  42   _biased_cset_map = _cset_map - ((uintx)heap_base >> ShenandoahHeapRegion::region_size_bytes_shift());
  43 
  44   // Initialize cset map
  45   Copy::zero_to_bytes(_cset_map, _map_size);
  46 }
  47 
  48 void ShenandoahCollectionSet::add_region(ShenandoahHeapRegion* r) {
  49   assert(ShenandoahSafepoint::is_at_shenandoah_safepoint(), "Must be at a safepoint");
  50   assert(Thread::current()->is_VM_thread(), "Must be VMThread");
  51   assert(!is_in(r), "Already in collection set");
  52   _cset_map[r->region_number()] = 1;
  53   _region_count ++;
  54   _garbage += r->garbage();
  55   _live_data += r->get_live_data_bytes();

  56 }
  57 
  58 void ShenandoahCollectionSet::remove_region(ShenandoahHeapRegion* r) {
  59   assert(ShenandoahSafepoint::is_at_shenandoah_safepoint(), "Must be at a safepoint");
  60   assert(Thread::current()->is_VM_thread(), "Must be VMThread");
  61   assert(is_in(r), "Not in collection set");
  62   _cset_map[r->region_number()] = 0;
  63   _region_count --;
  64 }
  65 
  66 void ShenandoahCollectionSet::update_region_status() {
  67   for (size_t index = 0; index < _heap->num_regions(); index ++) {
  68     ShenandoahHeapRegion* r = _heap->get_region(index);
  69     if (is_in(r)) {
  70       r->make_cset();
  71     } else {
  72       assert (!r->is_cset(), "should not be cset");
  73     }
  74   }
  75 }
  76 
  77 void ShenandoahCollectionSet::clear() {
  78   assert(ShenandoahSafepoint::is_at_shenandoah_safepoint(), "Must be at a safepoint");
  79   Copy::zero_to_bytes(_cset_map, _map_size);
  80 
  81 #ifdef ASSERT
  82   for (size_t index = 0; index < _heap->num_regions(); index ++) {
  83     assert (!_heap->get_region(index)->is_cset(), "should have been cleared before");
  84   }
  85 #endif
  86 
  87   _garbage = 0;
  88   _live_data = 0;

  89 
  90   _region_count = 0;
  91   _current_index = 0;
  92 }
  93 
  94 ShenandoahHeapRegion* ShenandoahCollectionSet::claim_next() {
  95   size_t num_regions = _heap->num_regions();
  96   if (_current_index >= (jint)num_regions) {
  97     return NULL;
  98   }
  99 
 100   jint saved_current = _current_index;
 101   size_t index = (size_t)saved_current;
 102 
 103   while(index < num_regions) {
 104     if (is_in(index)) {
 105       jint cur = Atomic::cmpxchg((jint)(index + 1), &_current_index, saved_current);
 106       assert(cur >= (jint)saved_current, "Must move forward");
 107       if (cur == saved_current) {
 108         assert(is_in(index), "Invariant");




  15  * 2 along with this work; if not, write to the Free Software Foundation,
  16  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  17  *
  18  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  19  * or visit www.oracle.com if you need additional information or have any
  20  * questions.
  21  *
  22  */
  23 
  24 #include "precompiled.hpp"
  25 #include "gc_implementation/shenandoah/shenandoahCollectionSet.hpp"
  26 #include "gc_implementation/shenandoah/shenandoahCollectionSet.inline.hpp"
  27 #include "gc_implementation/shenandoah/shenandoahHeap.hpp"
  28 #include "gc_implementation/shenandoah/shenandoahHeap.inline.hpp"
  29 #include "gc_implementation/shenandoah/shenandoahHeapRegion.hpp"
  30 #include "gc_implementation/shenandoah/shenandoahHeapRegionSet.hpp"
  31 #include "runtime/atomic.hpp"
  32 #include "utilities/copy.hpp"
  33 
  34 ShenandoahCollectionSet::ShenandoahCollectionSet(ShenandoahHeap* heap, HeapWord* heap_base) :
  35   _map_size(heap->num_regions()),
  36   _region_size_bytes_shift(ShenandoahHeapRegion::region_size_bytes_shift()),
  37   _cset_map(NEW_C_HEAP_ARRAY(jbyte, _map_size, mtGC)),
  38   _biased_cset_map(_cset_map - ((uintx)heap_base >> _region_size_bytes_shift)),
  39   _heap(heap),
  40   _garbage(0),
  41   _live_data(0),
  42   _used(0),
  43   _region_count(0),
  44   _current_index(0) {
  45   // Use 1-byte data type
  46   STATIC_ASSERT(sizeof(jbyte) == 1);
  47 




  48   // Initialize cset map
  49   Copy::zero_to_bytes(_cset_map, _map_size);
  50 }
  51 
  52 void ShenandoahCollectionSet::add_region(ShenandoahHeapRegion* r) {
  53   assert(ShenandoahSafepoint::is_at_shenandoah_safepoint(), "Must be at a safepoint");
  54   assert(Thread::current()->is_VM_thread(), "Must be VMThread");
  55   assert(!is_in(r), "Already in collection set");
  56   _cset_map[r->region_number()] = 1;
  57   _region_count ++;
  58   _garbage += r->garbage();
  59   _live_data += r->get_live_data_bytes();
  60   _used += r->used();
  61 }
  62 
  63 void ShenandoahCollectionSet::remove_region(ShenandoahHeapRegion* r) {
  64   assert(ShenandoahSafepoint::is_at_shenandoah_safepoint(), "Must be at a safepoint");
  65   assert(Thread::current()->is_VM_thread(), "Must be VMThread");
  66   assert(is_in(r), "Not in collection set");
  67   _cset_map[r->region_number()] = 0;
  68   _region_count --;
  69 }
  70 
  71 void ShenandoahCollectionSet::update_region_status() {
  72   for (size_t index = 0; index < _heap->num_regions(); index ++) {
  73     ShenandoahHeapRegion* r = _heap->get_region(index);
  74     if (is_in(r)) {
  75       r->make_cset();
  76     } else {
  77       assert (!r->is_cset(), "should not be cset");
  78     }
  79   }
  80 }
  81 
  82 void ShenandoahCollectionSet::clear() {
  83   assert(ShenandoahSafepoint::is_at_shenandoah_safepoint(), "Must be at a safepoint");
  84   Copy::zero_to_bytes(_cset_map, _map_size);
  85 
  86 #ifdef ASSERT
  87   for (size_t index = 0; index < _heap->num_regions(); index ++) {
  88     assert (!_heap->get_region(index)->is_cset(), "should have been cleared before");
  89   }
  90 #endif
  91 
  92   _garbage = 0;
  93   _live_data = 0;
  94   _used = 0;
  95 
  96   _region_count = 0;
  97   _current_index = 0;
  98 }
  99 
 100 ShenandoahHeapRegion* ShenandoahCollectionSet::claim_next() {
 101   size_t num_regions = _heap->num_regions();
 102   if (_current_index >= (jint)num_regions) {
 103     return NULL;
 104   }
 105 
 106   jint saved_current = _current_index;
 107   size_t index = (size_t)saved_current;
 108 
 109   while(index < num_regions) {
 110     if (is_in(index)) {
 111       jint cur = Atomic::cmpxchg((jint)(index + 1), &_current_index, saved_current);
 112       assert(cur >= (jint)saved_current, "Must move forward");
 113       if (cur == saved_current) {
 114         assert(is_in(index), "Invariant");


< prev index next >