3333ShenandoahHeapRegionSetIterator::ShenandoahHeapRegionSetIterator (const ShenandoahHeapRegionSet* const set) :
3434 _set(set), _heap(ShenandoahHeap::heap()), _current_index(0 ) {}
3535
36- void ShenandoahHeapRegionSetIterator::reset (const ShenandoahHeapRegionSet* const set) {
37- _set = set;
38- _current_index = 0 ;
39- }
40-
4136ShenandoahHeapRegionSet::ShenandoahHeapRegionSet () :
4237 _heap(ShenandoahHeap::heap()),
4338 _map_size(_heap->num_regions ()),
44- _region_size_bytes_shift(ShenandoahHeapRegion::region_size_bytes_shift()),
4539 _set_map(NEW_C_HEAP_ARRAY(jbyte, _map_size, mtGC)),
46- _biased_set_map(_set_map - ((uintx)_heap->base() >> _region_size_bytes_shift)),
4740 _region_count(0 )
4841{
4942 // Use 1-byte data type
@@ -58,83 +51,40 @@ ShenandoahHeapRegionSet::~ShenandoahHeapRegionSet() {
5851}
5952
6053void ShenandoahHeapRegionSet::add_region (ShenandoahHeapRegion* r) {
61- assert (!is_in (r), " Already in collection set" );
54+ assert (!is_in (r), " Already in region set" );
6255 _set_map[r->index ()] = 1 ;
6356 _region_count++;
6457}
6558
66- bool ShenandoahHeapRegionSet::add_region_check_for_duplicates (ShenandoahHeapRegion* r) {
67- if (!is_in (r)) {
68- add_region (r);
69- return true ;
70- } else {
71- return false ;
72- }
73- }
74-
7559void ShenandoahHeapRegionSet::remove_region (ShenandoahHeapRegion* r) {
7660 assert (ShenandoahSafepoint::is_at_shenandoah_safepoint (), " Must be at a safepoint" );
7761 assert (Thread::current ()->is_VM_thread (), " Must be VMThread" );
7862 assert (is_in (r), " Not in region set" );
7963 _set_map[r->index ()] = 0 ;
80- _region_count --;
64+ _region_count--;
8165}
8266
8367void ShenandoahHeapRegionSet::clear () {
8468 assert (ShenandoahSafepoint::is_at_shenandoah_safepoint (), " Must be at a safepoint" );
8569 Copy::zero_to_bytes (_set_map, _map_size);
86-
8770 _region_count = 0 ;
8871}
8972
90- ShenandoahHeapRegion* ShenandoahHeapRegionSetIterator::claim_next () {
91- size_t num_regions = _heap->num_regions ();
92- if (_current_index >= (jint)num_regions) {
93- return NULL ;
94- }
95-
96- jint saved_current = _current_index;
97- size_t index = (size_t )saved_current;
98-
99- while (index < num_regions) {
100- if (_set->is_in (index)) {
101- jint cur = Atomic::cmpxchg (&_current_index, saved_current, (jint)(index + 1 ));
102- assert (cur >= (jint)saved_current, " Must move forward" );
103- if (cur == saved_current) {
104- assert (_set->is_in (index), " Invariant" );
105- return _heap->get_region (index);
106- } else {
107- index = (size_t )cur;
108- saved_current = cur;
109- }
110- } else {
111- index ++;
112- }
113- }
114- return NULL ;
115- }
116-
11773ShenandoahHeapRegion* ShenandoahHeapRegionSetIterator::next () {
118- size_t num_regions = _heap->num_regions ();
119- for (size_t index = (size_t )_current_index; index < num_regions; index ++) {
74+ for (size_t index = _current_index; index < _heap->num_regions (); index++) {
12075 if (_set->is_in (index)) {
121- _current_index = (jint)( index + 1 ) ;
76+ _current_index = index + 1 ;
12277 return _heap->get_region (index);
12378 }
12479 }
125-
12680 return NULL ;
12781}
12882
12983void ShenandoahHeapRegionSet::print_on (outputStream* out) const {
13084 out->print_cr (" Region Set : " SIZE_FORMAT " " , count ());
131-
132- debug_only (size_t regions = 0 ;)
133- for (size_t index = 0 ; index < _heap->num_regions (); index ++) {
85+ for (size_t index = 0 ; index < _heap->num_regions (); index++) {
13486 if (is_in (index)) {
13587 _heap->get_region (index)->print_on (out);
136- debug_only (regions ++;)
13788 }
13889 }
139- assert (regions == count (), " Must match" );
14090}
0 commit comments