121 #endif // !PRODUCT
122
123 void CollectionSetChooser::sort_regions() {
124 // First trim any unused portion of the top in the parallel case.
125 if (_first_par_unreserved_idx > 0) {
126 assert(_first_par_unreserved_idx <= regions_length(),
127 "Or we didn't reserved enough length");
128 regions_trunc_to(_first_par_unreserved_idx);
129 }
130 _regions.sort(order_regions);
131 assert(_end <= regions_length(), "Requirement");
132 #ifdef ASSERT
133 for (uint i = 0; i < _end; i++) {
134 assert(regions_at(i) != NULL, "Should be true by sorting!");
135 }
136 #endif // ASSERT
137 if (log_is_enabled(Trace, gc, liveness)) {
138 G1PrintRegionLivenessInfoClosure cl("Post-Sorting");
139 for (uint i = 0; i < _end; ++i) {
140 HeapRegion* r = regions_at(i);
141 cl.doHeapRegion(r);
142 }
143 }
144 verify();
145 }
146
147 void CollectionSetChooser::add_region(HeapRegion* hr) {
148 assert(!hr->is_pinned(),
149 "Pinned region shouldn't be added to the collection set (index %u)", hr->hrm_index());
150 assert(!hr->is_young(), "should not be young!");
151 _regions.append(hr);
152 _end++;
153 _remaining_reclaimable_bytes += hr->reclaimable_bytes();
154 hr->calc_gc_efficiency();
155 }
156
157 void CollectionSetChooser::push(HeapRegion* hr) {
158 assert(hr != NULL, "Can't put back a NULL region");
159 assert(_front >= 1, "Too many regions have been put back");
160 _front--;
161 regions_at_put(_front, hr);
203 }
204 }
205
206 void CollectionSetChooser::clear() {
207 _regions.clear();
208 _front = 0;
209 _end = 0;
210 _remaining_reclaimable_bytes = 0;
211 }
212
213 class ParKnownGarbageHRClosure: public HeapRegionClosure {
214 G1CollectedHeap* _g1h;
215 CSetChooserParUpdater _cset_updater;
216
217 public:
218 ParKnownGarbageHRClosure(CollectionSetChooser* hrSorted,
219 uint chunk_size) :
220 _g1h(G1CollectedHeap::heap()),
221 _cset_updater(hrSorted, true /* parallel */, chunk_size) { }
222
223 bool doHeapRegion(HeapRegion* r) {
224 // Do we have any marking information for this region?
225 if (r->is_marked()) {
226 // We will skip any region that's currently used as an old GC
227 // alloc region (we should not consider those for collection
228 // before we fill them up).
229 if (_cset_updater.should_add(r) && !_g1h->is_old_gc_alloc_region(r)) {
230 _cset_updater.add_region(r);
231 }
232 }
233 return false;
234 }
235 };
236
237 class ParKnownGarbageTask: public AbstractGangTask {
238 CollectionSetChooser* _hrSorted;
239 uint _chunk_size;
240 G1CollectedHeap* _g1;
241 HeapRegionClaimer _hrclaimer;
242
243 public:
|
121 #endif // !PRODUCT
122
123 void CollectionSetChooser::sort_regions() {
124 // First trim any unused portion of the top in the parallel case.
125 if (_first_par_unreserved_idx > 0) {
126 assert(_first_par_unreserved_idx <= regions_length(),
127 "Or we didn't reserved enough length");
128 regions_trunc_to(_first_par_unreserved_idx);
129 }
130 _regions.sort(order_regions);
131 assert(_end <= regions_length(), "Requirement");
132 #ifdef ASSERT
133 for (uint i = 0; i < _end; i++) {
134 assert(regions_at(i) != NULL, "Should be true by sorting!");
135 }
136 #endif // ASSERT
137 if (log_is_enabled(Trace, gc, liveness)) {
138 G1PrintRegionLivenessInfoClosure cl("Post-Sorting");
139 for (uint i = 0; i < _end; ++i) {
140 HeapRegion* r = regions_at(i);
141 cl.do_heap_region(r);
142 }
143 }
144 verify();
145 }
146
147 void CollectionSetChooser::add_region(HeapRegion* hr) {
148 assert(!hr->is_pinned(),
149 "Pinned region shouldn't be added to the collection set (index %u)", hr->hrm_index());
150 assert(!hr->is_young(), "should not be young!");
151 _regions.append(hr);
152 _end++;
153 _remaining_reclaimable_bytes += hr->reclaimable_bytes();
154 hr->calc_gc_efficiency();
155 }
156
157 void CollectionSetChooser::push(HeapRegion* hr) {
158 assert(hr != NULL, "Can't put back a NULL region");
159 assert(_front >= 1, "Too many regions have been put back");
160 _front--;
161 regions_at_put(_front, hr);
203 }
204 }
205
206 void CollectionSetChooser::clear() {
207 _regions.clear();
208 _front = 0;
209 _end = 0;
210 _remaining_reclaimable_bytes = 0;
211 }
212
213 class ParKnownGarbageHRClosure: public HeapRegionClosure {
214 G1CollectedHeap* _g1h;
215 CSetChooserParUpdater _cset_updater;
216
217 public:
218 ParKnownGarbageHRClosure(CollectionSetChooser* hrSorted,
219 uint chunk_size) :
220 _g1h(G1CollectedHeap::heap()),
221 _cset_updater(hrSorted, true /* parallel */, chunk_size) { }
222
223 bool do_heap_region(HeapRegion* r) {
224 // Do we have any marking information for this region?
225 if (r->is_marked()) {
226 // We will skip any region that's currently used as an old GC
227 // alloc region (we should not consider those for collection
228 // before we fill them up).
229 if (_cset_updater.should_add(r) && !_g1h->is_old_gc_alloc_region(r)) {
230 _cset_updater.add_region(r);
231 }
232 }
233 return false;
234 }
235 };
236
237 class ParKnownGarbageTask: public AbstractGangTask {
238 CollectionSetChooser* _hrSorted;
239 uint _chunk_size;
240 G1CollectedHeap* _g1;
241 HeapRegionClaimer _hrclaimer;
242
243 public:
|