Mercurial > hg > graal-compiler
annotate src/share/vm/gc_implementation/g1/heapRegion.cpp @ 806:821269eca479
6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
Summary: Short-circuit gc-a-lot attempts by non-JavaThreads; SkipGCALot c'tor to elide re-entrant gc-a-lot attempts.
Reviewed-by: apetrusenko, jcoomes, jmasa, kamg
author | ysr |
---|---|
date | Thu, 11 Jun 2009 12:40:00 -0700 |
parents | 29e7d79232b9 |
children | 830ca2573896 |
rev | line source |
---|---|
342 | 1 /* |
470 | 2 * Copyright 2001-2008 Sun Microsystems, Inc. All Rights Reserved. |
342 | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
20 * CA 95054 USA or visit www.sun.com if you need additional information or | |
21 * have any questions. | |
22 * | |
23 */ | |
24 | |
25 #include "incls/_precompiled.incl" | |
26 #include "incls/_heapRegion.cpp.incl" | |
27 | |
28 HeapRegionDCTOC::HeapRegionDCTOC(G1CollectedHeap* g1, | |
29 HeapRegion* hr, OopClosure* cl, | |
30 CardTableModRefBS::PrecisionStyle precision, | |
31 FilterKind fk) : | |
32 ContiguousSpaceDCTOC(hr, cl, precision, NULL), | |
33 _hr(hr), _fk(fk), _g1(g1) | |
34 {} | |
35 | |
36 FilterOutOfRegionClosure::FilterOutOfRegionClosure(HeapRegion* r, | |
37 OopClosure* oc) : | |
38 _r_bottom(r->bottom()), _r_end(r->end()), | |
39 _oc(oc), _out_of_region(0) | |
40 {} | |
41 | |
42 class VerifyLiveClosure: public OopClosure { | |
43 G1CollectedHeap* _g1h; | |
44 CardTableModRefBS* _bs; | |
45 oop _containing_obj; | |
46 bool _failures; | |
47 int _n_failures; | |
48 public: | |
49 VerifyLiveClosure(G1CollectedHeap* g1h) : | |
50 _g1h(g1h), _bs(NULL), _containing_obj(NULL), | |
51 _failures(false), _n_failures(0) | |
52 { | |
53 BarrierSet* bs = _g1h->barrier_set(); | |
54 if (bs->is_a(BarrierSet::CardTableModRef)) | |
55 _bs = (CardTableModRefBS*)bs; | |
56 } | |
57 | |
58 void set_containing_obj(oop obj) { | |
59 _containing_obj = obj; | |
60 } | |
61 | |
62 bool failures() { return _failures; } | |
63 int n_failures() { return _n_failures; } | |
64 | |
65 virtual void do_oop(narrowOop* p) { | |
66 guarantee(false, "NYI"); | |
67 } | |
68 | |
69 void do_oop(oop* p) { | |
70 assert(_containing_obj != NULL, "Precondition"); | |
71 assert(!_g1h->is_obj_dead(_containing_obj), "Precondition"); | |
72 oop obj = *p; | |
73 if (obj != NULL) { | |
74 bool failed = false; | |
75 if (!_g1h->is_in_closed_subset(obj) || _g1h->is_obj_dead(obj)) { | |
76 if (!_failures) { | |
77 gclog_or_tty->print_cr(""); | |
78 gclog_or_tty->print_cr("----------"); | |
79 } | |
80 if (!_g1h->is_in_closed_subset(obj)) { | |
81 gclog_or_tty->print_cr("Field "PTR_FORMAT | |
82 " of live obj "PTR_FORMAT | |
83 " points to obj "PTR_FORMAT | |
84 " not in the heap.", | |
85 p, (void*) _containing_obj, (void*) obj); | |
86 } else { | |
87 gclog_or_tty->print_cr("Field "PTR_FORMAT | |
88 " of live obj "PTR_FORMAT | |
89 " points to dead obj "PTR_FORMAT".", | |
90 p, (void*) _containing_obj, (void*) obj); | |
91 } | |
92 gclog_or_tty->print_cr("Live obj:"); | |
93 _containing_obj->print_on(gclog_or_tty); | |
94 gclog_or_tty->print_cr("Bad referent:"); | |
95 obj->print_on(gclog_or_tty); | |
96 gclog_or_tty->print_cr("----------"); | |
97 _failures = true; | |
98 failed = true; | |
99 _n_failures++; | |
100 } | |
101 | |
102 if (!_g1h->full_collection()) { | |
103 HeapRegion* from = _g1h->heap_region_containing(p); | |
104 HeapRegion* to = _g1h->heap_region_containing(*p); | |
105 if (from != NULL && to != NULL && | |
106 from != to && | |
107 !to->isHumongous()) { | |
108 jbyte cv_obj = *_bs->byte_for_const(_containing_obj); | |
109 jbyte cv_field = *_bs->byte_for_const(p); | |
110 const jbyte dirty = CardTableModRefBS::dirty_card_val(); | |
111 | |
112 bool is_bad = !(from->is_young() | |
113 || to->rem_set()->contains_reference(p) | |
114 || !G1HRRSFlushLogBuffersOnVerify && // buffers were not flushed | |
115 (_containing_obj->is_objArray() ? | |
116 cv_field == dirty | |
117 : cv_obj == dirty || cv_field == dirty)); | |
118 if (is_bad) { | |
119 if (!_failures) { | |
120 gclog_or_tty->print_cr(""); | |
121 gclog_or_tty->print_cr("----------"); | |
122 } | |
123 gclog_or_tty->print_cr("Missing rem set entry:"); | |
124 gclog_or_tty->print_cr("Field "PTR_FORMAT | |
125 " of obj "PTR_FORMAT | |
126 ", in region %d ["PTR_FORMAT | |
127 ", "PTR_FORMAT"),", | |
128 p, (void*) _containing_obj, | |
129 from->hrs_index(), | |
130 from->bottom(), | |
131 from->end()); | |
132 _containing_obj->print_on(gclog_or_tty); | |
133 gclog_or_tty->print_cr("points to obj "PTR_FORMAT | |
134 " in region %d ["PTR_FORMAT | |
135 ", "PTR_FORMAT").", | |
136 (void*) obj, to->hrs_index(), | |
137 to->bottom(), to->end()); | |
138 obj->print_on(gclog_or_tty); | |
139 gclog_or_tty->print_cr("Obj head CTE = %d, field CTE = %d.", | |
140 cv_obj, cv_field); | |
141 gclog_or_tty->print_cr("----------"); | |
142 _failures = true; | |
143 if (!failed) _n_failures++; | |
144 } | |
145 } | |
146 } | |
147 } | |
148 } | |
149 }; | |
150 | |
151 template<class ClosureType> | |
152 HeapWord* walk_mem_region_loop(ClosureType* cl, G1CollectedHeap* g1h, | |
153 HeapRegion* hr, | |
154 HeapWord* cur, HeapWord* top) { | |
155 oop cur_oop = oop(cur); | |
156 int oop_size = cur_oop->size(); | |
157 HeapWord* next_obj = cur + oop_size; | |
158 while (next_obj < top) { | |
159 // Keep filtering the remembered set. | |
160 if (!g1h->is_obj_dead(cur_oop, hr)) { | |
161 // Bottom lies entirely below top, so we can call the | |
162 // non-memRegion version of oop_iterate below. | |
163 cur_oop->oop_iterate(cl); | |
164 } | |
165 cur = next_obj; | |
166 cur_oop = oop(cur); | |
167 oop_size = cur_oop->size(); | |
168 next_obj = cur + oop_size; | |
169 } | |
170 return cur; | |
171 } | |
172 | |
173 void HeapRegionDCTOC::walk_mem_region_with_cl(MemRegion mr, | |
174 HeapWord* bottom, | |
175 HeapWord* top, | |
176 OopClosure* cl) { | |
177 G1CollectedHeap* g1h = _g1; | |
178 | |
179 int oop_size; | |
180 | |
181 OopClosure* cl2 = cl; | |
182 FilterIntoCSClosure intoCSFilt(this, g1h, cl); | |
183 FilterOutOfRegionClosure outOfRegionFilt(_hr, cl); | |
184 switch (_fk) { | |
185 case IntoCSFilterKind: cl2 = &intoCSFilt; break; | |
186 case OutOfRegionFilterKind: cl2 = &outOfRegionFilt; break; | |
187 } | |
188 | |
189 // Start filtering what we add to the remembered set. If the object is | |
190 // not considered dead, either because it is marked (in the mark bitmap) | |
191 // or it was allocated after marking finished, then we add it. Otherwise | |
192 // we can safely ignore the object. | |
193 if (!g1h->is_obj_dead(oop(bottom), _hr)) { | |
194 oop_size = oop(bottom)->oop_iterate(cl2, mr); | |
195 } else { | |
196 oop_size = oop(bottom)->size(); | |
197 } | |
198 | |
199 bottom += oop_size; | |
200 | |
201 if (bottom < top) { | |
202 // We replicate the loop below for several kinds of possible filters. | |
203 switch (_fk) { | |
204 case NoFilterKind: | |
205 bottom = walk_mem_region_loop(cl, g1h, _hr, bottom, top); | |
206 break; | |
207 case IntoCSFilterKind: { | |
208 FilterIntoCSClosure filt(this, g1h, cl); | |
209 bottom = walk_mem_region_loop(&filt, g1h, _hr, bottom, top); | |
210 break; | |
211 } | |
212 case OutOfRegionFilterKind: { | |
213 FilterOutOfRegionClosure filt(_hr, cl); | |
214 bottom = walk_mem_region_loop(&filt, g1h, _hr, bottom, top); | |
215 break; | |
216 } | |
217 default: | |
218 ShouldNotReachHere(); | |
219 } | |
220 | |
221 // Last object. Need to do dead-obj filtering here too. | |
222 if (!g1h->is_obj_dead(oop(bottom), _hr)) { | |
223 oop(bottom)->oop_iterate(cl2, mr); | |
224 } | |
225 } | |
226 } | |
227 | |
228 void HeapRegion::reset_after_compaction() { | |
229 G1OffsetTableContigSpace::reset_after_compaction(); | |
230 // After a compaction the mark bitmap is invalid, so we must | |
231 // treat all objects as being inside the unmarked area. | |
232 zero_marked_bytes(); | |
233 init_top_at_mark_start(); | |
234 } | |
235 | |
236 DirtyCardToOopClosure* | |
237 HeapRegion::new_dcto_closure(OopClosure* cl, | |
238 CardTableModRefBS::PrecisionStyle precision, | |
239 HeapRegionDCTOC::FilterKind fk) { | |
240 return new HeapRegionDCTOC(G1CollectedHeap::heap(), | |
241 this, cl, precision, fk); | |
242 } | |
243 | |
244 void HeapRegion::hr_clear(bool par, bool clear_space) { | |
355 | 245 _humongous_type = NotHumongous; |
342 | 246 _humongous_start_region = NULL; |
247 _in_collection_set = false; | |
248 _is_gc_alloc_region = false; | |
249 | |
250 // Age stuff (if parallel, this will be done separately, since it needs | |
251 // to be sequential). | |
252 G1CollectedHeap* g1h = G1CollectedHeap::heap(); | |
253 | |
254 set_young_index_in_cset(-1); | |
255 uninstall_surv_rate_group(); | |
256 set_young_type(NotYoung); | |
257 | |
258 // In case it had been the start of a humongous sequence, reset its end. | |
259 set_end(_orig_end); | |
260 | |
261 if (!par) { | |
262 // If this is parallel, this will be done later. | |
263 HeapRegionRemSet* hrrs = rem_set(); | |
264 if (hrrs != NULL) hrrs->clear(); | |
355 | 265 _claimed = InitialClaimValue; |
342 | 266 } |
267 zero_marked_bytes(); | |
268 set_sort_index(-1); | |
269 | |
270 _offsets.resize(HeapRegion::GrainWords); | |
271 init_top_at_mark_start(); | |
356 | 272 if (clear_space) clear(SpaceDecorator::Mangle); |
342 | 273 } |
274 | |
275 // <PREDICTION> | |
276 void HeapRegion::calc_gc_efficiency() { | |
277 G1CollectedHeap* g1h = G1CollectedHeap::heap(); | |
278 _gc_efficiency = (double) garbage_bytes() / | |
279 g1h->predict_region_elapsed_time_ms(this, false); | |
280 } | |
281 // </PREDICTION> | |
282 | |
283 void HeapRegion::set_startsHumongous() { | |
355 | 284 _humongous_type = StartsHumongous; |
342 | 285 _humongous_start_region = this; |
286 assert(end() == _orig_end, "Should be normal before alloc."); | |
287 } | |
288 | |
289 bool HeapRegion::claimHeapRegion(jint claimValue) { | |
290 jint current = _claimed; | |
291 if (current != claimValue) { | |
292 jint res = Atomic::cmpxchg(claimValue, &_claimed, current); | |
293 if (res == current) { | |
294 return true; | |
295 } | |
296 } | |
297 return false; | |
298 } | |
299 | |
300 HeapWord* HeapRegion::next_block_start_careful(HeapWord* addr) { | |
301 HeapWord* low = addr; | |
302 HeapWord* high = end(); | |
303 while (low < high) { | |
304 size_t diff = pointer_delta(high, low); | |
305 // Must add one below to bias toward the high amount. Otherwise, if | |
306 // "high" were at the desired value, and "low" were one less, we | |
307 // would not converge on "high". This is not symmetric, because | |
308 // we set "high" to a block start, which might be the right one, | |
309 // which we don't do for "low". | |
310 HeapWord* middle = low + (diff+1)/2; | |
311 if (middle == high) return high; | |
312 HeapWord* mid_bs = block_start_careful(middle); | |
313 if (mid_bs < addr) { | |
314 low = middle; | |
315 } else { | |
316 high = mid_bs; | |
317 } | |
318 } | |
319 assert(low == high && low >= addr, "Didn't work."); | |
320 return low; | |
321 } | |
322 | |
323 void HeapRegion::set_next_on_unclean_list(HeapRegion* r) { | |
324 assert(r == NULL || r->is_on_unclean_list(), "Malformed unclean list."); | |
325 _next_in_special_set = r; | |
326 } | |
327 | |
328 void HeapRegion::set_on_unclean_list(bool b) { | |
329 _is_on_unclean_list = b; | |
330 } | |
331 | |
356 | 332 void HeapRegion::initialize(MemRegion mr, bool clear_space, bool mangle_space) { |
333 G1OffsetTableContigSpace::initialize(mr, false, mangle_space); | |
342 | 334 hr_clear(false/*par*/, clear_space); |
335 } | |
336 #ifdef _MSC_VER // the use of 'this' below gets a warning, make it go away | |
337 #pragma warning( disable:4355 ) // 'this' : used in base member initializer list | |
338 #endif // _MSC_VER | |
339 | |
340 | |
341 HeapRegion:: | |
342 HeapRegion(G1BlockOffsetSharedArray* sharedOffsetArray, | |
343 MemRegion mr, bool is_zeroed) | |
344 : G1OffsetTableContigSpace(sharedOffsetArray, mr, is_zeroed), | |
345 _next_fk(HeapRegionDCTOC::NoFilterKind), | |
346 _hrs_index(-1), | |
355 | 347 _humongous_type(NotHumongous), _humongous_start_region(NULL), |
342 | 348 _in_collection_set(false), _is_gc_alloc_region(false), |
349 _is_on_free_list(false), _is_on_unclean_list(false), | |
350 _next_in_special_set(NULL), _orig_end(NULL), | |
355 | 351 _claimed(InitialClaimValue), _evacuation_failed(false), |
342 | 352 _prev_marked_bytes(0), _next_marked_bytes(0), _sort_index(-1), |
353 _young_type(NotYoung), _next_young_region(NULL), | |
796
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
751
diff
changeset
|
354 _next_dirty_cards_region(NULL), |
342 | 355 _young_index_in_cset(-1), _surv_rate_group(NULL), _age_index(-1), |
356 _rem_set(NULL), _zfs(NotZeroFilled) | |
357 { | |
358 _orig_end = mr.end(); | |
359 // Note that initialize() will set the start of the unmarked area of the | |
360 // region. | |
356 | 361 this->initialize(mr, !is_zeroed, SpaceDecorator::Mangle); |
362 set_top(bottom()); | |
363 set_saved_mark(); | |
342 | 364 |
365 _rem_set = new HeapRegionRemSet(sharedOffsetArray, this); | |
366 | |
367 assert(HeapRegionRemSet::num_par_rem_sets() > 0, "Invariant."); | |
368 // In case the region is allocated during a pause, note the top. | |
369 // We haven't done any counting on a brand new region. | |
370 _top_at_conc_mark_count = bottom(); | |
371 } | |
372 | |
373 class NextCompactionHeapRegionClosure: public HeapRegionClosure { | |
374 const HeapRegion* _target; | |
375 bool _target_seen; | |
376 HeapRegion* _last; | |
377 CompactibleSpace* _res; | |
378 public: | |
379 NextCompactionHeapRegionClosure(const HeapRegion* target) : | |
380 _target(target), _target_seen(false), _res(NULL) {} | |
381 bool doHeapRegion(HeapRegion* cur) { | |
382 if (_target_seen) { | |
383 if (!cur->isHumongous()) { | |
384 _res = cur; | |
385 return true; | |
386 } | |
387 } else if (cur == _target) { | |
388 _target_seen = true; | |
389 } | |
390 return false; | |
391 } | |
392 CompactibleSpace* result() { return _res; } | |
393 }; | |
394 | |
395 CompactibleSpace* HeapRegion::next_compaction_space() const { | |
396 G1CollectedHeap* g1h = G1CollectedHeap::heap(); | |
397 // cast away const-ness | |
398 HeapRegion* r = (HeapRegion*) this; | |
399 NextCompactionHeapRegionClosure blk(r); | |
400 g1h->heap_region_iterate_from(r, &blk); | |
401 return blk.result(); | |
402 } | |
403 | |
404 void HeapRegion::set_continuesHumongous(HeapRegion* start) { | |
405 // The order is important here. | |
406 start->add_continuingHumongousRegion(this); | |
355 | 407 _humongous_type = ContinuesHumongous; |
342 | 408 _humongous_start_region = start; |
409 } | |
410 | |
411 void HeapRegion::add_continuingHumongousRegion(HeapRegion* cont) { | |
412 // Must join the blocks of the current H region seq with the block of the | |
413 // added region. | |
414 offsets()->join_blocks(bottom(), cont->bottom()); | |
415 arrayOop obj = (arrayOop)(bottom()); | |
416 obj->set_length((int) (obj->length() + cont->capacity()/jintSize)); | |
417 set_end(cont->end()); | |
418 set_top(cont->end()); | |
419 } | |
420 | |
421 void HeapRegion::save_marks() { | |
422 set_saved_mark(); | |
423 } | |
424 | |
425 void HeapRegion::oops_in_mr_iterate(MemRegion mr, OopClosure* cl) { | |
426 HeapWord* p = mr.start(); | |
427 HeapWord* e = mr.end(); | |
428 oop obj; | |
429 while (p < e) { | |
430 obj = oop(p); | |
431 p += obj->oop_iterate(cl); | |
432 } | |
433 assert(p == e, "bad memregion: doesn't end on obj boundary"); | |
434 } | |
435 | |
436 #define HeapRegion_OOP_SINCE_SAVE_MARKS_DEFN(OopClosureType, nv_suffix) \ | |
437 void HeapRegion::oop_since_save_marks_iterate##nv_suffix(OopClosureType* cl) { \ | |
438 ContiguousSpace::oop_since_save_marks_iterate##nv_suffix(cl); \ | |
439 } | |
440 SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES(HeapRegion_OOP_SINCE_SAVE_MARKS_DEFN) | |
441 | |
442 | |
443 void HeapRegion::oop_before_save_marks_iterate(OopClosure* cl) { | |
444 oops_in_mr_iterate(MemRegion(bottom(), saved_mark_word()), cl); | |
445 } | |
446 | |
447 #ifdef DEBUG | |
448 HeapWord* HeapRegion::allocate(size_t size) { | |
449 jint state = zero_fill_state(); | |
450 assert(!G1CollectedHeap::heap()->allocs_are_zero_filled() || | |
451 zero_fill_is_allocated(), | |
452 "When ZF is on, only alloc in ZF'd regions"); | |
453 return G1OffsetTableContigSpace::allocate(size); | |
454 } | |
455 #endif | |
456 | |
457 void HeapRegion::set_zero_fill_state_work(ZeroFillState zfs) { | |
458 assert(top() == bottom() || zfs == Allocated, | |
459 "Region must be empty, or we must be setting it to allocated."); | |
460 assert(ZF_mon->owned_by_self() || | |
461 Universe::heap()->is_gc_active(), | |
462 "Must hold the lock or be a full GC to modify."); | |
463 _zfs = zfs; | |
464 } | |
465 | |
466 void HeapRegion::set_zero_fill_complete() { | |
467 set_zero_fill_state_work(ZeroFilled); | |
468 if (ZF_mon->owned_by_self()) { | |
469 ZF_mon->notify_all(); | |
470 } | |
471 } | |
472 | |
473 | |
474 void HeapRegion::ensure_zero_filled() { | |
475 MutexLockerEx x(ZF_mon, Mutex::_no_safepoint_check_flag); | |
476 ensure_zero_filled_locked(); | |
477 } | |
478 | |
479 void HeapRegion::ensure_zero_filled_locked() { | |
480 assert(ZF_mon->owned_by_self(), "Precondition"); | |
481 bool should_ignore_zf = SafepointSynchronize::is_at_safepoint(); | |
482 assert(should_ignore_zf || Heap_lock->is_locked(), | |
483 "Either we're in a GC or we're allocating a region."); | |
484 switch (zero_fill_state()) { | |
485 case HeapRegion::NotZeroFilled: | |
486 set_zero_fill_in_progress(Thread::current()); | |
487 { | |
488 ZF_mon->unlock(); | |
489 Copy::fill_to_words(bottom(), capacity()/HeapWordSize); | |
490 ZF_mon->lock_without_safepoint_check(); | |
491 } | |
492 // A trap. | |
493 guarantee(zero_fill_state() == HeapRegion::ZeroFilling | |
494 && zero_filler() == Thread::current(), | |
495 "AHA! Tell Dave D if you see this..."); | |
496 set_zero_fill_complete(); | |
497 // gclog_or_tty->print_cr("Did sync ZF."); | |
498 ConcurrentZFThread::note_sync_zfs(); | |
499 break; | |
500 case HeapRegion::ZeroFilling: | |
501 if (should_ignore_zf) { | |
502 // We can "break" the lock and take over the work. | |
503 Copy::fill_to_words(bottom(), capacity()/HeapWordSize); | |
504 set_zero_fill_complete(); | |
505 ConcurrentZFThread::note_sync_zfs(); | |
506 break; | |
507 } else { | |
508 ConcurrentZFThread::wait_for_ZF_completed(this); | |
509 } | |
510 case HeapRegion::ZeroFilled: | |
511 // Nothing to do. | |
512 break; | |
513 case HeapRegion::Allocated: | |
514 guarantee(false, "Should not call on allocated regions."); | |
515 } | |
516 assert(zero_fill_state() == HeapRegion::ZeroFilled, "Post"); | |
517 } | |
518 | |
519 HeapWord* | |
520 HeapRegion::object_iterate_mem_careful(MemRegion mr, | |
521 ObjectClosure* cl) { | |
522 G1CollectedHeap* g1h = G1CollectedHeap::heap(); | |
523 // We used to use "block_start_careful" here. But we're actually happy | |
524 // to update the BOT while we do this... | |
525 HeapWord* cur = block_start(mr.start()); | |
526 mr = mr.intersection(used_region()); | |
527 if (mr.is_empty()) return NULL; | |
528 // Otherwise, find the obj that extends onto mr.start(). | |
529 | |
530 assert(cur <= mr.start() | |
531 && (oop(cur)->klass() == NULL || | |
532 cur + oop(cur)->size() > mr.start()), | |
533 "postcondition of block_start"); | |
534 oop obj; | |
535 while (cur < mr.end()) { | |
536 obj = oop(cur); | |
537 if (obj->klass() == NULL) { | |
538 // Ran into an unparseable point. | |
539 return cur; | |
540 } else if (!g1h->is_obj_dead(obj)) { | |
541 cl->do_object(obj); | |
542 } | |
543 if (cl->abort()) return cur; | |
544 // The check above must occur before the operation below, since an | |
545 // abort might invalidate the "size" operation. | |
546 cur += obj->size(); | |
547 } | |
548 return NULL; | |
549 } | |
550 | |
551 HeapWord* | |
552 HeapRegion:: | |
553 oops_on_card_seq_iterate_careful(MemRegion mr, | |
554 FilterOutOfRegionClosure* cl) { | |
555 G1CollectedHeap* g1h = G1CollectedHeap::heap(); | |
556 | |
557 // If we're within a stop-world GC, then we might look at a card in a | |
558 // GC alloc region that extends onto a GC LAB, which may not be | |
559 // parseable. Stop such at the "saved_mark" of the region. | |
560 if (G1CollectedHeap::heap()->is_gc_active()) { | |
561 mr = mr.intersection(used_region_at_save_marks()); | |
562 } else { | |
563 mr = mr.intersection(used_region()); | |
564 } | |
565 if (mr.is_empty()) return NULL; | |
566 // Otherwise, find the obj that extends onto mr.start(). | |
567 | |
568 // We used to use "block_start_careful" here. But we're actually happy | |
569 // to update the BOT while we do this... | |
570 HeapWord* cur = block_start(mr.start()); | |
571 assert(cur <= mr.start(), "Postcondition"); | |
572 | |
573 while (cur <= mr.start()) { | |
574 if (oop(cur)->klass() == NULL) { | |
575 // Ran into an unparseable point. | |
576 return cur; | |
577 } | |
578 // Otherwise... | |
579 int sz = oop(cur)->size(); | |
580 if (cur + sz > mr.start()) break; | |
581 // Otherwise, go on. | |
582 cur = cur + sz; | |
583 } | |
584 oop obj; | |
585 obj = oop(cur); | |
586 // If we finish this loop... | |
587 assert(cur <= mr.start() | |
588 && obj->klass() != NULL | |
589 && cur + obj->size() > mr.start(), | |
590 "Loop postcondition"); | |
591 if (!g1h->is_obj_dead(obj)) { | |
592 obj->oop_iterate(cl, mr); | |
593 } | |
594 | |
595 HeapWord* next; | |
596 while (cur < mr.end()) { | |
597 obj = oop(cur); | |
598 if (obj->klass() == NULL) { | |
599 // Ran into an unparseable point. | |
600 return cur; | |
601 }; | |
602 // Otherwise: | |
603 next = (cur + obj->size()); | |
604 if (!g1h->is_obj_dead(obj)) { | |
605 if (next < mr.end()) { | |
606 obj->oop_iterate(cl); | |
607 } else { | |
608 // this obj spans the boundary. If it's an array, stop at the | |
609 // boundary. | |
610 if (obj->is_objArray()) { | |
611 obj->oop_iterate(cl, mr); | |
612 } else { | |
613 obj->oop_iterate(cl); | |
614 } | |
615 } | |
616 } | |
617 cur = next; | |
618 } | |
619 return NULL; | |
620 } | |
621 | |
622 void HeapRegion::print() const { print_on(gclog_or_tty); } | |
623 void HeapRegion::print_on(outputStream* st) const { | |
624 if (isHumongous()) { | |
625 if (startsHumongous()) | |
626 st->print(" HS"); | |
627 else | |
628 st->print(" HC"); | |
629 } else { | |
630 st->print(" "); | |
631 } | |
632 if (in_collection_set()) | |
633 st->print(" CS"); | |
634 else if (is_gc_alloc_region()) | |
635 st->print(" A "); | |
636 else | |
637 st->print(" "); | |
638 if (is_young()) | |
639 st->print(is_scan_only() ? " SO" : (is_survivor() ? " SU" : " Y ")); | |
640 else | |
641 st->print(" "); | |
642 if (is_empty()) | |
643 st->print(" F"); | |
644 else | |
645 st->print(" "); | |
646 st->print(" %d", _gc_time_stamp); | |
647 G1OffsetTableContigSpace::print_on(st); | |
648 } | |
649 | |
650 #define OBJ_SAMPLE_INTERVAL 0 | |
651 #define BLOCK_SAMPLE_INTERVAL 100 | |
652 | |
653 // This really ought to be commoned up into OffsetTableContigSpace somehow. | |
654 // We would need a mechanism to make that code skip dead objects. | |
655 | |
656 void HeapRegion::verify(bool allow_dirty) const { | |
657 G1CollectedHeap* g1 = G1CollectedHeap::heap(); | |
658 HeapWord* p = bottom(); | |
659 HeapWord* prev_p = NULL; | |
660 int objs = 0; | |
661 int blocks = 0; | |
662 VerifyLiveClosure vl_cl(g1); | |
663 while (p < top()) { | |
664 size_t size = oop(p)->size(); | |
665 if (blocks == BLOCK_SAMPLE_INTERVAL) { | |
666 guarantee(p == block_start_const(p + (size/2)), | |
667 "check offset computation"); | |
668 blocks = 0; | |
669 } else { | |
670 blocks++; | |
671 } | |
672 if (objs == OBJ_SAMPLE_INTERVAL) { | |
673 oop obj = oop(p); | |
674 if (!g1->is_obj_dead(obj, this)) { | |
675 obj->verify(); | |
676 vl_cl.set_containing_obj(obj); | |
677 obj->oop_iterate(&vl_cl); | |
678 if (G1MaxVerifyFailures >= 0 | |
679 && vl_cl.n_failures() >= G1MaxVerifyFailures) break; | |
680 } | |
681 objs = 0; | |
682 } else { | |
683 objs++; | |
684 } | |
685 prev_p = p; | |
686 p += size; | |
687 } | |
688 HeapWord* rend = end(); | |
689 HeapWord* rtop = top(); | |
690 if (rtop < rend) { | |
691 guarantee(block_start_const(rtop + (rend - rtop) / 2) == rtop, | |
692 "check offset computation"); | |
693 } | |
694 if (vl_cl.failures()) { | |
695 gclog_or_tty->print_cr("Heap:"); | |
696 G1CollectedHeap::heap()->print(); | |
697 gclog_or_tty->print_cr(""); | |
698 } | |
751 | 699 if (VerifyDuringGC && |
342 | 700 G1VerifyConcMarkPrintReachable && |
701 vl_cl.failures()) { | |
702 g1->concurrent_mark()->print_prev_bitmap_reachable(); | |
703 } | |
745
2b6c55e36143
6829013: G1: set the default value of G1VerifyConcMarkPrintRechable to false
tonyp
parents:
677
diff
changeset
|
704 guarantee(!vl_cl.failures(), "region verification failed"); |
342 | 705 guarantee(p == top(), "end of last object must match end of space"); |
706 } | |
707 | |
708 // G1OffsetTableContigSpace code; copied from space.cpp. Hope this can go | |
709 // away eventually. | |
710 | |
356 | 711 void G1OffsetTableContigSpace::initialize(MemRegion mr, bool clear_space, bool mangle_space) { |
342 | 712 // false ==> we'll do the clearing if there's clearing to be done. |
356 | 713 ContiguousSpace::initialize(mr, false, mangle_space); |
342 | 714 _offsets.zero_bottom_entry(); |
715 _offsets.initialize_threshold(); | |
356 | 716 if (clear_space) clear(mangle_space); |
342 | 717 } |
718 | |
356 | 719 void G1OffsetTableContigSpace::clear(bool mangle_space) { |
720 ContiguousSpace::clear(mangle_space); | |
342 | 721 _offsets.zero_bottom_entry(); |
722 _offsets.initialize_threshold(); | |
723 } | |
724 | |
725 void G1OffsetTableContigSpace::set_bottom(HeapWord* new_bottom) { | |
726 Space::set_bottom(new_bottom); | |
727 _offsets.set_bottom(new_bottom); | |
728 } | |
729 | |
730 void G1OffsetTableContigSpace::set_end(HeapWord* new_end) { | |
731 Space::set_end(new_end); | |
732 _offsets.resize(new_end - bottom()); | |
733 } | |
734 | |
735 void G1OffsetTableContigSpace::print() const { | |
736 print_short(); | |
737 gclog_or_tty->print_cr(" [" INTPTR_FORMAT ", " INTPTR_FORMAT ", " | |
738 INTPTR_FORMAT ", " INTPTR_FORMAT ")", | |
739 bottom(), top(), _offsets.threshold(), end()); | |
740 } | |
741 | |
742 HeapWord* G1OffsetTableContigSpace::initialize_threshold() { | |
743 return _offsets.initialize_threshold(); | |
744 } | |
745 | |
746 HeapWord* G1OffsetTableContigSpace::cross_threshold(HeapWord* start, | |
747 HeapWord* end) { | |
748 _offsets.alloc_block(start, end); | |
749 return _offsets.threshold(); | |
750 } | |
751 | |
752 HeapWord* G1OffsetTableContigSpace::saved_mark_word() const { | |
753 G1CollectedHeap* g1h = G1CollectedHeap::heap(); | |
754 assert( _gc_time_stamp <= g1h->get_gc_time_stamp(), "invariant" ); | |
755 if (_gc_time_stamp < g1h->get_gc_time_stamp()) | |
756 return top(); | |
757 else | |
758 return ContiguousSpace::saved_mark_word(); | |
759 } | |
760 | |
761 void G1OffsetTableContigSpace::set_saved_mark() { | |
762 G1CollectedHeap* g1h = G1CollectedHeap::heap(); | |
763 unsigned curr_gc_time_stamp = g1h->get_gc_time_stamp(); | |
764 | |
765 if (_gc_time_stamp < curr_gc_time_stamp) { | |
766 // The order of these is important, as another thread might be | |
767 // about to start scanning this region. If it does so after | |
768 // set_saved_mark and before _gc_time_stamp = ..., then the latter | |
769 // will be false, and it will pick up top() as the high water mark | |
770 // of region. If it does so after _gc_time_stamp = ..., then it | |
771 // will pick up the right saved_mark_word() as the high water mark | |
772 // of the region. Either way, the behaviour will be correct. | |
773 ContiguousSpace::set_saved_mark(); | |
353
9bb2c10ac07b
6723570: G1: assertion failure: p == current_top or oop(p)->is_oop(),"p is not a block start" (revisited!)
iveresov
parents:
342
diff
changeset
|
774 _gc_time_stamp = curr_gc_time_stamp; |
9bb2c10ac07b
6723570: G1: assertion failure: p == current_top or oop(p)->is_oop(),"p is not a block start" (revisited!)
iveresov
parents:
342
diff
changeset
|
775 OrderAccess::fence(); |
342 | 776 } |
777 } | |
778 | |
779 G1OffsetTableContigSpace:: | |
780 G1OffsetTableContigSpace(G1BlockOffsetSharedArray* sharedOffsetArray, | |
781 MemRegion mr, bool is_zeroed) : | |
782 _offsets(sharedOffsetArray, mr), | |
783 _par_alloc_lock(Mutex::leaf, "OffsetTableContigSpace par alloc lock", true), | |
784 _gc_time_stamp(0) | |
785 { | |
786 _offsets.set_space(this); | |
356 | 787 initialize(mr, !is_zeroed, SpaceDecorator::Mangle); |
342 | 788 } |
789 | |
790 size_t RegionList::length() { | |
791 size_t len = 0; | |
792 HeapRegion* cur = hd(); | |
793 DEBUG_ONLY(HeapRegion* last = NULL); | |
794 while (cur != NULL) { | |
795 len++; | |
796 DEBUG_ONLY(last = cur); | |
797 cur = get_next(cur); | |
798 } | |
799 assert(last == tl(), "Invariant"); | |
800 return len; | |
801 } | |
802 | |
803 void RegionList::insert_before_head(HeapRegion* r) { | |
804 assert(well_formed(), "Inv"); | |
805 set_next(r, hd()); | |
806 _hd = r; | |
807 _sz++; | |
808 if (tl() == NULL) _tl = r; | |
809 assert(well_formed(), "Inv"); | |
810 } | |
811 | |
812 void RegionList::prepend_list(RegionList* new_list) { | |
813 assert(well_formed(), "Precondition"); | |
814 assert(new_list->well_formed(), "Precondition"); | |
815 HeapRegion* new_tl = new_list->tl(); | |
816 if (new_tl != NULL) { | |
817 set_next(new_tl, hd()); | |
818 _hd = new_list->hd(); | |
819 _sz += new_list->sz(); | |
820 if (tl() == NULL) _tl = new_list->tl(); | |
821 } else { | |
822 assert(new_list->hd() == NULL && new_list->sz() == 0, "Inv"); | |
823 } | |
824 assert(well_formed(), "Inv"); | |
825 } | |
826 | |
827 void RegionList::delete_after(HeapRegion* r) { | |
828 assert(well_formed(), "Precondition"); | |
829 HeapRegion* next = get_next(r); | |
830 assert(r != NULL, "Precondition"); | |
831 HeapRegion* next_tl = get_next(next); | |
832 set_next(r, next_tl); | |
833 dec_sz(); | |
834 if (next == tl()) { | |
835 assert(next_tl == NULL, "Inv"); | |
836 _tl = r; | |
837 } | |
838 assert(well_formed(), "Inv"); | |
839 } | |
840 | |
841 HeapRegion* RegionList::pop() { | |
842 assert(well_formed(), "Inv"); | |
843 HeapRegion* res = hd(); | |
844 if (res != NULL) { | |
845 _hd = get_next(res); | |
846 _sz--; | |
847 set_next(res, NULL); | |
848 if (sz() == 0) _tl = NULL; | |
849 } | |
850 assert(well_formed(), "Inv"); | |
851 return res; | |
852 } |