comparison src/share/vm/gc_implementation/g1/g1MarkSweep.cpp @ 677:96b229c54d1e

6543938: G1: remove the concept of popularity Reviewed-by: iveresov, tonyp
author apetrusenko
date Wed, 25 Mar 2009 13:10:54 -0700
parents ad8c8ca4ab0f
children 20c6f43950b5
comparison
equal deleted inserted replaced
649:59f139e8a8d1 677:96b229c54d1e
155 } 155 }
156 156
157 class G1PrepareCompactClosure: public HeapRegionClosure { 157 class G1PrepareCompactClosure: public HeapRegionClosure {
158 ModRefBarrierSet* _mrbs; 158 ModRefBarrierSet* _mrbs;
159 CompactPoint _cp; 159 CompactPoint _cp;
160 bool _popular_only;
161 160
162 void free_humongous_region(HeapRegion* hr) { 161 void free_humongous_region(HeapRegion* hr) {
163 HeapWord* bot = hr->bottom(); 162 HeapWord* bot = hr->bottom();
164 HeapWord* end = hr->end(); 163 HeapWord* end = hr->end();
165 assert(hr->startsHumongous(), 164 assert(hr->startsHumongous(),
170 // compaction. 169 // compaction.
171 _mrbs->clear(MemRegion(hr->compaction_top(), hr->end())); 170 _mrbs->clear(MemRegion(hr->compaction_top(), hr->end()));
172 } 171 }
173 172
174 public: 173 public:
175 G1PrepareCompactClosure(CompactibleSpace* cs, bool popular_only) : 174 G1PrepareCompactClosure(CompactibleSpace* cs) :
176 _cp(NULL, cs, cs->initialize_threshold()), 175 _cp(NULL, cs, cs->initialize_threshold()),
177 _mrbs(G1CollectedHeap::heap()->mr_bs()), 176 _mrbs(G1CollectedHeap::heap()->mr_bs())
178 _popular_only(popular_only)
179 {} 177 {}
180 bool doHeapRegion(HeapRegion* hr) { 178 bool doHeapRegion(HeapRegion* hr) {
181 if (_popular_only && !hr->popular())
182 return true; // terminate early
183 else if (!_popular_only && hr->popular())
184 return false; // skip this one.
185
186 if (hr->isHumongous()) { 179 if (hr->isHumongous()) {
187 if (hr->startsHumongous()) { 180 if (hr->startsHumongous()) {
188 oop obj = oop(hr->bottom()); 181 oop obj = oop(hr->bottom());
189 if (obj->is_gc_marked()) { 182 if (obj->is_gc_marked()) {
190 obj->forward_to(obj); 183 obj->forward_to(obj);
201 _mrbs->clear(MemRegion(hr->compaction_top(), hr->end())); 194 _mrbs->clear(MemRegion(hr->compaction_top(), hr->end()));
202 } 195 }
203 return false; 196 return false;
204 } 197 }
205 }; 198 };
206 // Stolen verbatim from g1CollectedHeap.cpp 199
200 // Finds the first HeapRegion.
207 class FindFirstRegionClosure: public HeapRegionClosure { 201 class FindFirstRegionClosure: public HeapRegionClosure {
208 HeapRegion* _a_region; 202 HeapRegion* _a_region;
209 bool _find_popular;
210 public: 203 public:
211 FindFirstRegionClosure(bool find_popular) : 204 FindFirstRegionClosure() : _a_region(NULL) {}
212 _a_region(NULL), _find_popular(find_popular) {}
213 bool doHeapRegion(HeapRegion* r) { 205 bool doHeapRegion(HeapRegion* r) {
214 if (r->popular() == _find_popular) { 206 _a_region = r;
215 _a_region = r; 207 return true;
216 return true;
217 } else {
218 return false;
219 }
220 } 208 }
221 HeapRegion* result() { return _a_region; } 209 HeapRegion* result() { return _a_region; }
222 }; 210 };
223 211
224 void G1MarkSweep::mark_sweep_phase2() { 212 void G1MarkSweep::mark_sweep_phase2() {
240 228
241 EventMark m("2 compute new addresses"); 229 EventMark m("2 compute new addresses");
242 TraceTime tm("phase 2", PrintGC && Verbose, true, gclog_or_tty); 230 TraceTime tm("phase 2", PrintGC && Verbose, true, gclog_or_tty);
243 GenMarkSweep::trace("2"); 231 GenMarkSweep::trace("2");
244 232
245 // First we compact the popular regions. 233 FindFirstRegionClosure cl;
246 if (G1NumPopularRegions > 0) {
247 CompactibleSpace* sp = g1h->first_compactible_space();
248 FindFirstRegionClosure cl(true /*find_popular*/);
249 g1h->heap_region_iterate(&cl);
250 HeapRegion *r = cl.result();
251 assert(r->popular(), "should have found a popular region.");
252 assert(r == sp, "first popular heap region should "
253 "== first compactible space");
254 G1PrepareCompactClosure blk(sp, true/*popular_only*/);
255 g1h->heap_region_iterate(&blk);
256 }
257
258 // Now we do the regular regions.
259 FindFirstRegionClosure cl(false /*find_popular*/);
260 g1h->heap_region_iterate(&cl); 234 g1h->heap_region_iterate(&cl);
261 HeapRegion *r = cl.result(); 235 HeapRegion *r = cl.result();
262 assert(!r->popular(), "should have founda non-popular region.");
263 CompactibleSpace* sp = r; 236 CompactibleSpace* sp = r;
264 if (r->isHumongous() && oop(r->bottom())->is_gc_marked()) { 237 if (r->isHumongous() && oop(r->bottom())->is_gc_marked()) {
265 sp = r->next_compaction_space(); 238 sp = r->next_compaction_space();
266 } 239 }
267 240
268 G1PrepareCompactClosure blk(sp, false/*popular_only*/); 241 G1PrepareCompactClosure blk(sp);
269 g1h->heap_region_iterate(&blk); 242 g1h->heap_region_iterate(&blk);
270 243
271 CompactPoint perm_cp(pg, NULL, NULL); 244 CompactPoint perm_cp(pg, NULL, NULL);
272 pg->prepare_for_compaction(&perm_cp); 245 pg->prepare_for_compaction(&perm_cp);
273 } 246 }