81 // Note: containing object is allocated on C heap since it is CHeapObj. |
81 // Note: containing object is allocated on C heap since it is CHeapObj. |
82 // |
82 // |
83 _regions((ResourceObj::set_allocation_type((address) &_regions, |
83 _regions((ResourceObj::set_allocation_type((address) &_regions, |
84 ResourceObj::C_HEAP), |
84 ResourceObj::C_HEAP), |
85 100), true /* C_Heap */), |
85 100), true /* C_Heap */), |
86 _curr_index(0), _length(0), _first_par_unreserved_idx(0), |
86 _front(0), _end(0), _first_par_unreserved_idx(0), |
87 _region_live_threshold_bytes(0), _remaining_reclaimable_bytes(0) { |
87 _region_live_threshold_bytes(0), _remaining_reclaimable_bytes(0) { |
88 _region_live_threshold_bytes = |
88 _region_live_threshold_bytes = |
89 HeapRegion::GrainBytes * (size_t) G1MixedGCLiveThresholdPercent / 100; |
89 HeapRegion::GrainBytes * (size_t) G1MixedGCLiveThresholdPercent / 100; |
90 } |
90 } |
91 |
91 |
92 #ifndef PRODUCT |
92 #ifndef PRODUCT |
93 void CollectionSetChooser::verify() { |
93 void CollectionSetChooser::verify() { |
94 guarantee(_length <= regions_length(), |
94 guarantee(_end <= regions_length(), |
95 err_msg("_length: %u regions length: %u", _length, regions_length())); |
95 err_msg("_end: %u regions length: %u", _end, regions_length())); |
96 guarantee(_curr_index <= _length, |
96 guarantee(_front <= _end, |
97 err_msg("_curr_index: %u _length: %u", _curr_index, _length)); |
97 err_msg("_front: %u _end: %u", _front, _end)); |
98 uint index = 0; |
98 uint index = 0; |
99 size_t sum_of_reclaimable_bytes = 0; |
99 size_t sum_of_reclaimable_bytes = 0; |
100 while (index < _curr_index) { |
100 while (index < _front) { |
101 guarantee(regions_at(index) == NULL, |
101 guarantee(regions_at(index) == NULL, |
102 "all entries before _curr_index should be NULL"); |
102 "all entries before _front should be NULL"); |
103 index += 1; |
103 index += 1; |
104 } |
104 } |
105 HeapRegion *prev = NULL; |
105 HeapRegion *prev = NULL; |
106 while (index < _length) { |
106 while (index < _end) { |
107 HeapRegion *curr = regions_at(index++); |
107 HeapRegion *curr = regions_at(index++); |
108 guarantee(curr != NULL, "Regions in _regions array cannot be NULL"); |
108 guarantee(curr != NULL, "Regions in _regions array cannot be NULL"); |
109 guarantee(!curr->is_young(), "should not be young!"); |
109 guarantee(!curr->is_young(), "should not be young!"); |
110 guarantee(!curr->is_pinned(), |
110 guarantee(!curr->is_pinned(), |
111 err_msg("Pinned region should not be in collection set (index %u)", curr->hrm_index())); |
111 err_msg("Pinned region should not be in collection set (index %u)", curr->hrm_index())); |
130 assert(_first_par_unreserved_idx <= regions_length(), |
130 assert(_first_par_unreserved_idx <= regions_length(), |
131 "Or we didn't reserved enough length"); |
131 "Or we didn't reserved enough length"); |
132 regions_trunc_to(_first_par_unreserved_idx); |
132 regions_trunc_to(_first_par_unreserved_idx); |
133 } |
133 } |
134 _regions.sort(order_regions); |
134 _regions.sort(order_regions); |
135 assert(_length <= regions_length(), "Requirement"); |
135 assert(_end <= regions_length(), "Requirement"); |
136 #ifdef ASSERT |
136 #ifdef ASSERT |
137 for (uint i = 0; i < _length; i++) { |
137 for (uint i = 0; i < _end; i++) { |
138 assert(regions_at(i) != NULL, "Should be true by sorting!"); |
138 assert(regions_at(i) != NULL, "Should be true by sorting!"); |
139 } |
139 } |
140 #endif // ASSERT |
140 #endif // ASSERT |
141 if (G1PrintRegionLivenessInfo) { |
141 if (G1PrintRegionLivenessInfo) { |
142 G1PrintRegionLivenessInfoClosure cl(gclog_or_tty, "Post-Sorting"); |
142 G1PrintRegionLivenessInfoClosure cl(gclog_or_tty, "Post-Sorting"); |
143 for (uint i = 0; i < _length; ++i) { |
143 for (uint i = 0; i < _end; ++i) { |
144 HeapRegion* r = regions_at(i); |
144 HeapRegion* r = regions_at(i); |
145 cl.doHeapRegion(r); |
145 cl.doHeapRegion(r); |
146 } |
146 } |
147 } |
147 } |
148 verify(); |
148 verify(); |
152 void CollectionSetChooser::add_region(HeapRegion* hr) { |
152 void CollectionSetChooser::add_region(HeapRegion* hr) { |
153 assert(!hr->is_pinned(), |
153 assert(!hr->is_pinned(), |
154 err_msg("Pinned region shouldn't be added to the collection set (index %u)", hr->hrm_index())); |
154 err_msg("Pinned region shouldn't be added to the collection set (index %u)", hr->hrm_index())); |
155 assert(!hr->is_young(), "should not be young!"); |
155 assert(!hr->is_young(), "should not be young!"); |
156 _regions.append(hr); |
156 _regions.append(hr); |
157 _length++; |
157 _end++; |
158 _remaining_reclaimable_bytes += hr->reclaimable_bytes(); |
158 _remaining_reclaimable_bytes += hr->reclaimable_bytes(); |
159 hr->calc_gc_efficiency(); |
159 hr->calc_gc_efficiency(); |
|
160 } |
|
161 |
|
162 void CollectionSetChooser::push(HeapRegion* hr) { |
|
163 assert(hr != NULL, "Can't put back a NULL region"); |
|
164 assert(_front >= 1, "Too many regions have been put back"); |
|
165 _front--; |
|
166 regions_at_put(_front, hr); |
|
167 _remaining_reclaimable_bytes += hr->reclaimable_bytes(); |
160 } |
168 } |
161 |
169 |
162 void CollectionSetChooser::prepare_for_par_region_addition(uint n_threads, |
170 void CollectionSetChooser::prepare_for_par_region_addition(uint n_threads, |
163 uint n_regions, |
171 uint n_regions, |
164 uint chunk_size) { |
172 uint chunk_size) { |
191 if (region_num > 0) { |
199 if (region_num > 0) { |
192 assert(reclaimable_bytes > 0, "invariant"); |
200 assert(reclaimable_bytes > 0, "invariant"); |
193 // We could have just used atomics instead of taking the |
201 // We could have just used atomics instead of taking the |
194 // lock. However, we currently don't have an atomic add for size_t. |
202 // lock. However, we currently don't have an atomic add for size_t. |
195 MutexLockerEx x(ParGCRareEvent_lock, Mutex::_no_safepoint_check_flag); |
203 MutexLockerEx x(ParGCRareEvent_lock, Mutex::_no_safepoint_check_flag); |
196 _length += region_num; |
204 _end += region_num; |
197 _remaining_reclaimable_bytes += reclaimable_bytes; |
205 _remaining_reclaimable_bytes += reclaimable_bytes; |
198 } else { |
206 } else { |
199 assert(reclaimable_bytes == 0, "invariant"); |
207 assert(reclaimable_bytes == 0, "invariant"); |
200 } |
208 } |
201 } |
209 } |
202 |
210 |
203 void CollectionSetChooser::clear() { |
211 void CollectionSetChooser::clear() { |
204 _regions.clear(); |
212 _regions.clear(); |
205 _curr_index = 0; |
213 _front = 0; |
206 _length = 0; |
214 _end = 0; |
207 _remaining_reclaimable_bytes = 0; |
215 _remaining_reclaimable_bytes = 0; |
208 }; |
216 }; |