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