Tue, 20 Sep 2011 09:59:59 -0400
7059019: G1: add G1 support to the SA
Summary: Extend the SA to recognize the G1CollectedHeap and implement any code that's needed by our serviceability tools (jmap, jinfo, jstack, etc.) that depend on the SA.
Reviewed-by: never, poonam, johnc
ysr@777 | 1 | /* |
tonyp@2453 | 2 | * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved. |
ysr@777 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ysr@777 | 4 | * |
ysr@777 | 5 | * This code is free software; you can redistribute it and/or modify it |
ysr@777 | 6 | * under the terms of the GNU General Public License version 2 only, as |
ysr@777 | 7 | * published by the Free Software Foundation. |
ysr@777 | 8 | * |
ysr@777 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
ysr@777 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ysr@777 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ysr@777 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
ysr@777 | 13 | * accompanied this code). |
ysr@777 | 14 | * |
ysr@777 | 15 | * You should have received a copy of the GNU General Public License version |
ysr@777 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
ysr@777 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ysr@777 | 18 | * |
trims@1907 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | * questions. |
ysr@777 | 22 | * |
ysr@777 | 23 | */ |
ysr@777 | 24 | |
stefank@2314 | 25 | #include "precompiled.hpp" |
stefank@2314 | 26 | #include "gc_implementation/g1/g1BlockOffsetTable.inline.hpp" |
stefank@2314 | 27 | #include "gc_implementation/g1/g1CollectedHeap.inline.hpp" |
stefank@2314 | 28 | #include "gc_implementation/g1/g1OopClosures.inline.hpp" |
stefank@2314 | 29 | #include "gc_implementation/g1/heapRegion.inline.hpp" |
stefank@2314 | 30 | #include "gc_implementation/g1/heapRegionRemSet.hpp" |
stefank@2314 | 31 | #include "gc_implementation/g1/heapRegionSeq.inline.hpp" |
stefank@2314 | 32 | #include "memory/genOopClosures.inline.hpp" |
stefank@2314 | 33 | #include "memory/iterator.hpp" |
stefank@2314 | 34 | #include "oops/oop.inline.hpp" |
ysr@777 | 35 | |
tonyp@1377 | 36 | int HeapRegion::LogOfHRGrainBytes = 0; |
tonyp@1377 | 37 | int HeapRegion::LogOfHRGrainWords = 0; |
tonyp@1377 | 38 | int HeapRegion::GrainBytes = 0; |
tonyp@1377 | 39 | int HeapRegion::GrainWords = 0; |
tonyp@1377 | 40 | int HeapRegion::CardsPerRegion = 0; |
tonyp@1377 | 41 | |
ysr@777 | 42 | HeapRegionDCTOC::HeapRegionDCTOC(G1CollectedHeap* g1, |
ysr@777 | 43 | HeapRegion* hr, OopClosure* cl, |
ysr@777 | 44 | CardTableModRefBS::PrecisionStyle precision, |
ysr@777 | 45 | FilterKind fk) : |
ysr@777 | 46 | ContiguousSpaceDCTOC(hr, cl, precision, NULL), |
ysr@777 | 47 | _hr(hr), _fk(fk), _g1(g1) |
ysr@777 | 48 | {} |
ysr@777 | 49 | |
ysr@777 | 50 | FilterOutOfRegionClosure::FilterOutOfRegionClosure(HeapRegion* r, |
ysr@777 | 51 | OopClosure* oc) : |
ysr@777 | 52 | _r_bottom(r->bottom()), _r_end(r->end()), |
ysr@777 | 53 | _oc(oc), _out_of_region(0) |
ysr@777 | 54 | {} |
ysr@777 | 55 | |
ysr@777 | 56 | class VerifyLiveClosure: public OopClosure { |
tonyp@1246 | 57 | private: |
ysr@777 | 58 | G1CollectedHeap* _g1h; |
ysr@777 | 59 | CardTableModRefBS* _bs; |
ysr@777 | 60 | oop _containing_obj; |
ysr@777 | 61 | bool _failures; |
ysr@777 | 62 | int _n_failures; |
johnc@2969 | 63 | VerifyOption _vo; |
ysr@777 | 64 | public: |
johnc@2969 | 65 | // _vo == UsePrevMarking -> use "prev" marking information, |
johnc@2969 | 66 | // _vo == UseNextMarking -> use "next" marking information, |
johnc@2969 | 67 | // _vo == UseMarkWord -> use mark word from object header. |
johnc@2969 | 68 | VerifyLiveClosure(G1CollectedHeap* g1h, VerifyOption vo) : |
ysr@777 | 69 | _g1h(g1h), _bs(NULL), _containing_obj(NULL), |
johnc@2969 | 70 | _failures(false), _n_failures(0), _vo(vo) |
ysr@777 | 71 | { |
ysr@777 | 72 | BarrierSet* bs = _g1h->barrier_set(); |
ysr@777 | 73 | if (bs->is_a(BarrierSet::CardTableModRef)) |
ysr@777 | 74 | _bs = (CardTableModRefBS*)bs; |
ysr@777 | 75 | } |
ysr@777 | 76 | |
ysr@777 | 77 | void set_containing_obj(oop obj) { |
ysr@777 | 78 | _containing_obj = obj; |
ysr@777 | 79 | } |
ysr@777 | 80 | |
ysr@777 | 81 | bool failures() { return _failures; } |
ysr@777 | 82 | int n_failures() { return _n_failures; } |
ysr@777 | 83 | |
ysr@1280 | 84 | virtual void do_oop(narrowOop* p) { do_oop_work(p); } |
ysr@1280 | 85 | virtual void do_oop( oop* p) { do_oop_work(p); } |
ysr@777 | 86 | |
tonyp@1823 | 87 | void print_object(outputStream* out, oop obj) { |
tonyp@1823 | 88 | #ifdef PRODUCT |
tonyp@1823 | 89 | klassOop k = obj->klass(); |
tonyp@1823 | 90 | const char* class_name = instanceKlass::cast(k)->external_name(); |
tonyp@1823 | 91 | out->print_cr("class name %s", class_name); |
tonyp@1823 | 92 | #else // PRODUCT |
tonyp@1823 | 93 | obj->print_on(out); |
tonyp@1823 | 94 | #endif // PRODUCT |
tonyp@1823 | 95 | } |
tonyp@1823 | 96 | |
ysr@1280 | 97 | template <class T> void do_oop_work(T* p) { |
ysr@777 | 98 | assert(_containing_obj != NULL, "Precondition"); |
johnc@2969 | 99 | assert(!_g1h->is_obj_dead_cond(_containing_obj, _vo), |
tonyp@1246 | 100 | "Precondition"); |
ysr@1280 | 101 | T heap_oop = oopDesc::load_heap_oop(p); |
ysr@1280 | 102 | if (!oopDesc::is_null(heap_oop)) { |
ysr@1280 | 103 | oop obj = oopDesc::decode_heap_oop_not_null(heap_oop); |
ysr@777 | 104 | bool failed = false; |
tonyp@1246 | 105 | if (!_g1h->is_in_closed_subset(obj) || |
johnc@2969 | 106 | _g1h->is_obj_dead_cond(obj, _vo)) { |
ysr@777 | 107 | if (!_failures) { |
ysr@777 | 108 | gclog_or_tty->print_cr(""); |
ysr@777 | 109 | gclog_or_tty->print_cr("----------"); |
ysr@777 | 110 | } |
ysr@777 | 111 | if (!_g1h->is_in_closed_subset(obj)) { |
tonyp@1823 | 112 | HeapRegion* from = _g1h->heap_region_containing((HeapWord*)p); |
ysr@777 | 113 | gclog_or_tty->print_cr("Field "PTR_FORMAT |
tonyp@1823 | 114 | " of live obj "PTR_FORMAT" in region " |
tonyp@1823 | 115 | "["PTR_FORMAT", "PTR_FORMAT")", |
tonyp@1823 | 116 | p, (void*) _containing_obj, |
tonyp@1823 | 117 | from->bottom(), from->end()); |
tonyp@1823 | 118 | print_object(gclog_or_tty, _containing_obj); |
tonyp@1823 | 119 | gclog_or_tty->print_cr("points to obj "PTR_FORMAT" not in the heap", |
tonyp@1823 | 120 | (void*) obj); |
ysr@777 | 121 | } else { |
tonyp@1823 | 122 | HeapRegion* from = _g1h->heap_region_containing((HeapWord*)p); |
tonyp@1823 | 123 | HeapRegion* to = _g1h->heap_region_containing((HeapWord*)obj); |
ysr@777 | 124 | gclog_or_tty->print_cr("Field "PTR_FORMAT |
tonyp@1823 | 125 | " of live obj "PTR_FORMAT" in region " |
tonyp@1823 | 126 | "["PTR_FORMAT", "PTR_FORMAT")", |
tonyp@1823 | 127 | p, (void*) _containing_obj, |
tonyp@1823 | 128 | from->bottom(), from->end()); |
tonyp@1823 | 129 | print_object(gclog_or_tty, _containing_obj); |
tonyp@1823 | 130 | gclog_or_tty->print_cr("points to dead obj "PTR_FORMAT" in region " |
tonyp@1823 | 131 | "["PTR_FORMAT", "PTR_FORMAT")", |
tonyp@1823 | 132 | (void*) obj, to->bottom(), to->end()); |
tonyp@1823 | 133 | print_object(gclog_or_tty, obj); |
ysr@777 | 134 | } |
ysr@777 | 135 | gclog_or_tty->print_cr("----------"); |
ysr@777 | 136 | _failures = true; |
ysr@777 | 137 | failed = true; |
ysr@777 | 138 | _n_failures++; |
ysr@777 | 139 | } |
ysr@777 | 140 | |
ysr@777 | 141 | if (!_g1h->full_collection()) { |
ysr@1280 | 142 | HeapRegion* from = _g1h->heap_region_containing((HeapWord*)p); |
ysr@1280 | 143 | HeapRegion* to = _g1h->heap_region_containing(obj); |
ysr@777 | 144 | if (from != NULL && to != NULL && |
ysr@777 | 145 | from != to && |
ysr@777 | 146 | !to->isHumongous()) { |
ysr@777 | 147 | jbyte cv_obj = *_bs->byte_for_const(_containing_obj); |
ysr@777 | 148 | jbyte cv_field = *_bs->byte_for_const(p); |
ysr@777 | 149 | const jbyte dirty = CardTableModRefBS::dirty_card_val(); |
ysr@777 | 150 | |
ysr@777 | 151 | bool is_bad = !(from->is_young() |
ysr@777 | 152 | || to->rem_set()->contains_reference(p) |
ysr@777 | 153 | || !G1HRRSFlushLogBuffersOnVerify && // buffers were not flushed |
ysr@777 | 154 | (_containing_obj->is_objArray() ? |
ysr@777 | 155 | cv_field == dirty |
ysr@777 | 156 | : cv_obj == dirty || cv_field == dirty)); |
ysr@777 | 157 | if (is_bad) { |
ysr@777 | 158 | if (!_failures) { |
ysr@777 | 159 | gclog_or_tty->print_cr(""); |
ysr@777 | 160 | gclog_or_tty->print_cr("----------"); |
ysr@777 | 161 | } |
ysr@777 | 162 | gclog_or_tty->print_cr("Missing rem set entry:"); |
tonyp@2963 | 163 | gclog_or_tty->print_cr("Field "PTR_FORMAT" " |
tonyp@2963 | 164 | "of obj "PTR_FORMAT", " |
tonyp@2963 | 165 | "in region "HR_FORMAT, |
tonyp@2963 | 166 | p, (void*) _containing_obj, |
tonyp@2963 | 167 | HR_FORMAT_PARAMS(from)); |
ysr@777 | 168 | _containing_obj->print_on(gclog_or_tty); |
tonyp@2963 | 169 | gclog_or_tty->print_cr("points to obj "PTR_FORMAT" " |
tonyp@2963 | 170 | "in region "HR_FORMAT, |
tonyp@2963 | 171 | (void*) obj, |
tonyp@2963 | 172 | HR_FORMAT_PARAMS(to)); |
ysr@777 | 173 | obj->print_on(gclog_or_tty); |
ysr@777 | 174 | gclog_or_tty->print_cr("Obj head CTE = %d, field CTE = %d.", |
ysr@777 | 175 | cv_obj, cv_field); |
ysr@777 | 176 | gclog_or_tty->print_cr("----------"); |
ysr@777 | 177 | _failures = true; |
ysr@777 | 178 | if (!failed) _n_failures++; |
ysr@777 | 179 | } |
ysr@777 | 180 | } |
ysr@777 | 181 | } |
ysr@777 | 182 | } |
ysr@777 | 183 | } |
ysr@777 | 184 | }; |
ysr@777 | 185 | |
ysr@777 | 186 | template<class ClosureType> |
ysr@777 | 187 | HeapWord* walk_mem_region_loop(ClosureType* cl, G1CollectedHeap* g1h, |
ysr@777 | 188 | HeapRegion* hr, |
ysr@777 | 189 | HeapWord* cur, HeapWord* top) { |
ysr@777 | 190 | oop cur_oop = oop(cur); |
ysr@777 | 191 | int oop_size = cur_oop->size(); |
ysr@777 | 192 | HeapWord* next_obj = cur + oop_size; |
ysr@777 | 193 | while (next_obj < top) { |
ysr@777 | 194 | // Keep filtering the remembered set. |
ysr@777 | 195 | if (!g1h->is_obj_dead(cur_oop, hr)) { |
ysr@777 | 196 | // Bottom lies entirely below top, so we can call the |
ysr@777 | 197 | // non-memRegion version of oop_iterate below. |
ysr@777 | 198 | cur_oop->oop_iterate(cl); |
ysr@777 | 199 | } |
ysr@777 | 200 | cur = next_obj; |
ysr@777 | 201 | cur_oop = oop(cur); |
ysr@777 | 202 | oop_size = cur_oop->size(); |
ysr@777 | 203 | next_obj = cur + oop_size; |
ysr@777 | 204 | } |
ysr@777 | 205 | return cur; |
ysr@777 | 206 | } |
ysr@777 | 207 | |
ysr@777 | 208 | void HeapRegionDCTOC::walk_mem_region_with_cl(MemRegion mr, |
ysr@777 | 209 | HeapWord* bottom, |
ysr@777 | 210 | HeapWord* top, |
ysr@777 | 211 | OopClosure* cl) { |
ysr@777 | 212 | G1CollectedHeap* g1h = _g1; |
ysr@777 | 213 | |
ysr@777 | 214 | int oop_size; |
ysr@777 | 215 | |
ysr@777 | 216 | OopClosure* cl2 = cl; |
ysr@777 | 217 | FilterIntoCSClosure intoCSFilt(this, g1h, cl); |
ysr@777 | 218 | FilterOutOfRegionClosure outOfRegionFilt(_hr, cl); |
ysr@777 | 219 | switch (_fk) { |
ysr@777 | 220 | case IntoCSFilterKind: cl2 = &intoCSFilt; break; |
ysr@777 | 221 | case OutOfRegionFilterKind: cl2 = &outOfRegionFilt; break; |
ysr@777 | 222 | } |
ysr@777 | 223 | |
ysr@777 | 224 | // Start filtering what we add to the remembered set. If the object is |
ysr@777 | 225 | // not considered dead, either because it is marked (in the mark bitmap) |
ysr@777 | 226 | // or it was allocated after marking finished, then we add it. Otherwise |
ysr@777 | 227 | // we can safely ignore the object. |
ysr@777 | 228 | if (!g1h->is_obj_dead(oop(bottom), _hr)) { |
ysr@777 | 229 | oop_size = oop(bottom)->oop_iterate(cl2, mr); |
ysr@777 | 230 | } else { |
ysr@777 | 231 | oop_size = oop(bottom)->size(); |
ysr@777 | 232 | } |
ysr@777 | 233 | |
ysr@777 | 234 | bottom += oop_size; |
ysr@777 | 235 | |
ysr@777 | 236 | if (bottom < top) { |
ysr@777 | 237 | // We replicate the loop below for several kinds of possible filters. |
ysr@777 | 238 | switch (_fk) { |
ysr@777 | 239 | case NoFilterKind: |
ysr@777 | 240 | bottom = walk_mem_region_loop(cl, g1h, _hr, bottom, top); |
ysr@777 | 241 | break; |
ysr@777 | 242 | case IntoCSFilterKind: { |
ysr@777 | 243 | FilterIntoCSClosure filt(this, g1h, cl); |
ysr@777 | 244 | bottom = walk_mem_region_loop(&filt, g1h, _hr, bottom, top); |
ysr@777 | 245 | break; |
ysr@777 | 246 | } |
ysr@777 | 247 | case OutOfRegionFilterKind: { |
ysr@777 | 248 | FilterOutOfRegionClosure filt(_hr, cl); |
ysr@777 | 249 | bottom = walk_mem_region_loop(&filt, g1h, _hr, bottom, top); |
ysr@777 | 250 | break; |
ysr@777 | 251 | } |
ysr@777 | 252 | default: |
ysr@777 | 253 | ShouldNotReachHere(); |
ysr@777 | 254 | } |
ysr@777 | 255 | |
ysr@777 | 256 | // Last object. Need to do dead-obj filtering here too. |
ysr@777 | 257 | if (!g1h->is_obj_dead(oop(bottom), _hr)) { |
ysr@777 | 258 | oop(bottom)->oop_iterate(cl2, mr); |
ysr@777 | 259 | } |
ysr@777 | 260 | } |
ysr@777 | 261 | } |
ysr@777 | 262 | |
tonyp@1377 | 263 | // Minimum region size; we won't go lower than that. |
tonyp@1377 | 264 | // We might want to decrease this in the future, to deal with small |
tonyp@1377 | 265 | // heaps a bit more efficiently. |
tonyp@1377 | 266 | #define MIN_REGION_SIZE ( 1024 * 1024 ) |
tonyp@1377 | 267 | |
tonyp@1377 | 268 | // Maximum region size; we don't go higher than that. There's a good |
tonyp@1377 | 269 | // reason for having an upper bound. We don't want regions to get too |
tonyp@1377 | 270 | // large, otherwise cleanup's effectiveness would decrease as there |
tonyp@1377 | 271 | // will be fewer opportunities to find totally empty regions after |
tonyp@1377 | 272 | // marking. |
tonyp@1377 | 273 | #define MAX_REGION_SIZE ( 32 * 1024 * 1024 ) |
tonyp@1377 | 274 | |
tonyp@1377 | 275 | // The automatic region size calculation will try to have around this |
tonyp@1377 | 276 | // many regions in the heap (based on the min heap size). |
tonyp@1377 | 277 | #define TARGET_REGION_NUMBER 2048 |
tonyp@1377 | 278 | |
tonyp@1377 | 279 | void HeapRegion::setup_heap_region_size(uintx min_heap_size) { |
tonyp@1377 | 280 | // region_size in bytes |
tonyp@1377 | 281 | uintx region_size = G1HeapRegionSize; |
tonyp@1377 | 282 | if (FLAG_IS_DEFAULT(G1HeapRegionSize)) { |
tonyp@1377 | 283 | // We base the automatic calculation on the min heap size. This |
tonyp@1377 | 284 | // can be problematic if the spread between min and max is quite |
tonyp@1377 | 285 | // wide, imagine -Xms128m -Xmx32g. But, if we decided it based on |
tonyp@1377 | 286 | // the max size, the region size might be way too large for the |
tonyp@1377 | 287 | // min size. Either way, some users might have to set the region |
tonyp@1377 | 288 | // size manually for some -Xms / -Xmx combos. |
tonyp@1377 | 289 | |
tonyp@1377 | 290 | region_size = MAX2(min_heap_size / TARGET_REGION_NUMBER, |
tonyp@1377 | 291 | (uintx) MIN_REGION_SIZE); |
tonyp@1377 | 292 | } |
tonyp@1377 | 293 | |
tonyp@1377 | 294 | int region_size_log = log2_long((jlong) region_size); |
tonyp@1377 | 295 | // Recalculate the region size to make sure it's a power of |
tonyp@1377 | 296 | // 2. This means that region_size is the largest power of 2 that's |
tonyp@1377 | 297 | // <= what we've calculated so far. |
prr@1840 | 298 | region_size = ((uintx)1 << region_size_log); |
tonyp@1377 | 299 | |
tonyp@1377 | 300 | // Now make sure that we don't go over or under our limits. |
tonyp@1377 | 301 | if (region_size < MIN_REGION_SIZE) { |
tonyp@1377 | 302 | region_size = MIN_REGION_SIZE; |
tonyp@1377 | 303 | } else if (region_size > MAX_REGION_SIZE) { |
tonyp@1377 | 304 | region_size = MAX_REGION_SIZE; |
tonyp@1377 | 305 | } |
tonyp@1377 | 306 | |
tonyp@1377 | 307 | // And recalculate the log. |
tonyp@1377 | 308 | region_size_log = log2_long((jlong) region_size); |
tonyp@1377 | 309 | |
tonyp@1377 | 310 | // Now, set up the globals. |
tonyp@1377 | 311 | guarantee(LogOfHRGrainBytes == 0, "we should only set it once"); |
tonyp@1377 | 312 | LogOfHRGrainBytes = region_size_log; |
tonyp@1377 | 313 | |
tonyp@1377 | 314 | guarantee(LogOfHRGrainWords == 0, "we should only set it once"); |
tonyp@1377 | 315 | LogOfHRGrainWords = LogOfHRGrainBytes - LogHeapWordSize; |
tonyp@1377 | 316 | |
tonyp@1377 | 317 | guarantee(GrainBytes == 0, "we should only set it once"); |
tonyp@1377 | 318 | // The cast to int is safe, given that we've bounded region_size by |
tonyp@1377 | 319 | // MIN_REGION_SIZE and MAX_REGION_SIZE. |
tonyp@1377 | 320 | GrainBytes = (int) region_size; |
tonyp@1377 | 321 | |
tonyp@1377 | 322 | guarantee(GrainWords == 0, "we should only set it once"); |
tonyp@1377 | 323 | GrainWords = GrainBytes >> LogHeapWordSize; |
tonyp@1377 | 324 | guarantee(1 << LogOfHRGrainWords == GrainWords, "sanity"); |
tonyp@1377 | 325 | |
tonyp@1377 | 326 | guarantee(CardsPerRegion == 0, "we should only set it once"); |
tonyp@1377 | 327 | CardsPerRegion = GrainBytes >> CardTableModRefBS::card_shift; |
tonyp@1377 | 328 | } |
tonyp@1377 | 329 | |
ysr@777 | 330 | void HeapRegion::reset_after_compaction() { |
ysr@777 | 331 | G1OffsetTableContigSpace::reset_after_compaction(); |
ysr@777 | 332 | // After a compaction the mark bitmap is invalid, so we must |
ysr@777 | 333 | // treat all objects as being inside the unmarked area. |
ysr@777 | 334 | zero_marked_bytes(); |
ysr@777 | 335 | init_top_at_mark_start(); |
ysr@777 | 336 | } |
ysr@777 | 337 | |
ysr@777 | 338 | DirtyCardToOopClosure* |
ysr@777 | 339 | HeapRegion::new_dcto_closure(OopClosure* cl, |
ysr@777 | 340 | CardTableModRefBS::PrecisionStyle precision, |
ysr@777 | 341 | HeapRegionDCTOC::FilterKind fk) { |
ysr@777 | 342 | return new HeapRegionDCTOC(G1CollectedHeap::heap(), |
ysr@777 | 343 | this, cl, precision, fk); |
ysr@777 | 344 | } |
ysr@777 | 345 | |
ysr@777 | 346 | void HeapRegion::hr_clear(bool par, bool clear_space) { |
tonyp@2472 | 347 | assert(_humongous_type == NotHumongous, |
tonyp@2472 | 348 | "we should have already filtered out humongous regions"); |
tonyp@2472 | 349 | assert(_humongous_start_region == NULL, |
tonyp@2472 | 350 | "we should have already filtered out humongous regions"); |
tonyp@2472 | 351 | assert(_end == _orig_end, |
tonyp@2472 | 352 | "we should have already filtered out humongous regions"); |
tonyp@2472 | 353 | |
ysr@777 | 354 | _in_collection_set = false; |
ysr@777 | 355 | |
ysr@777 | 356 | set_young_index_in_cset(-1); |
ysr@777 | 357 | uninstall_surv_rate_group(); |
ysr@777 | 358 | set_young_type(NotYoung); |
tonyp@2715 | 359 | reset_pre_dummy_top(); |
ysr@777 | 360 | |
ysr@777 | 361 | if (!par) { |
ysr@777 | 362 | // If this is parallel, this will be done later. |
ysr@777 | 363 | HeapRegionRemSet* hrrs = rem_set(); |
ysr@777 | 364 | if (hrrs != NULL) hrrs->clear(); |
tonyp@790 | 365 | _claimed = InitialClaimValue; |
ysr@777 | 366 | } |
ysr@777 | 367 | zero_marked_bytes(); |
ysr@777 | 368 | set_sort_index(-1); |
ysr@777 | 369 | |
ysr@777 | 370 | _offsets.resize(HeapRegion::GrainWords); |
ysr@777 | 371 | init_top_at_mark_start(); |
tonyp@791 | 372 | if (clear_space) clear(SpaceDecorator::Mangle); |
ysr@777 | 373 | } |
ysr@777 | 374 | |
tonyp@2849 | 375 | void HeapRegion::par_clear() { |
tonyp@2849 | 376 | assert(used() == 0, "the region should have been already cleared"); |
tonyp@2849 | 377 | assert(capacity() == (size_t) HeapRegion::GrainBytes, |
tonyp@2849 | 378 | "should be back to normal"); |
tonyp@2849 | 379 | HeapRegionRemSet* hrrs = rem_set(); |
tonyp@2849 | 380 | hrrs->clear(); |
tonyp@2849 | 381 | CardTableModRefBS* ct_bs = |
tonyp@2849 | 382 | (CardTableModRefBS*)G1CollectedHeap::heap()->barrier_set(); |
tonyp@2849 | 383 | ct_bs->clear(MemRegion(bottom(), end())); |
tonyp@2849 | 384 | } |
tonyp@2849 | 385 | |
ysr@777 | 386 | // <PREDICTION> |
ysr@777 | 387 | void HeapRegion::calc_gc_efficiency() { |
ysr@777 | 388 | G1CollectedHeap* g1h = G1CollectedHeap::heap(); |
ysr@777 | 389 | _gc_efficiency = (double) garbage_bytes() / |
ysr@777 | 390 | g1h->predict_region_elapsed_time_ms(this, false); |
ysr@777 | 391 | } |
ysr@777 | 392 | // </PREDICTION> |
ysr@777 | 393 | |
tonyp@2453 | 394 | void HeapRegion::set_startsHumongous(HeapWord* new_top, HeapWord* new_end) { |
tonyp@2472 | 395 | assert(!isHumongous(), "sanity / pre-condition"); |
tonyp@2241 | 396 | assert(end() == _orig_end, |
tonyp@2241 | 397 | "Should be normal before the humongous object allocation"); |
tonyp@2241 | 398 | assert(top() == bottom(), "should be empty"); |
tonyp@2453 | 399 | assert(bottom() <= new_top && new_top <= new_end, "pre-condition"); |
tonyp@2241 | 400 | |
tonyp@790 | 401 | _humongous_type = StartsHumongous; |
ysr@777 | 402 | _humongous_start_region = this; |
tonyp@2241 | 403 | |
tonyp@2241 | 404 | set_end(new_end); |
tonyp@2453 | 405 | _offsets.set_for_starts_humongous(new_top); |
tonyp@2241 | 406 | } |
tonyp@2241 | 407 | |
tonyp@2453 | 408 | void HeapRegion::set_continuesHumongous(HeapRegion* first_hr) { |
tonyp@2472 | 409 | assert(!isHumongous(), "sanity / pre-condition"); |
tonyp@2241 | 410 | assert(end() == _orig_end, |
tonyp@2241 | 411 | "Should be normal before the humongous object allocation"); |
tonyp@2241 | 412 | assert(top() == bottom(), "should be empty"); |
tonyp@2453 | 413 | assert(first_hr->startsHumongous(), "pre-condition"); |
tonyp@2241 | 414 | |
tonyp@2241 | 415 | _humongous_type = ContinuesHumongous; |
tonyp@2453 | 416 | _humongous_start_region = first_hr; |
ysr@777 | 417 | } |
ysr@777 | 418 | |
tonyp@2472 | 419 | void HeapRegion::set_notHumongous() { |
tonyp@2472 | 420 | assert(isHumongous(), "pre-condition"); |
tonyp@2472 | 421 | |
tonyp@2472 | 422 | if (startsHumongous()) { |
tonyp@2472 | 423 | assert(top() <= end(), "pre-condition"); |
tonyp@2472 | 424 | set_end(_orig_end); |
tonyp@2472 | 425 | if (top() > end()) { |
tonyp@2472 | 426 | // at least one "continues humongous" region after it |
tonyp@2472 | 427 | set_top(end()); |
tonyp@2472 | 428 | } |
tonyp@2472 | 429 | } else { |
tonyp@2472 | 430 | // continues humongous |
tonyp@2472 | 431 | assert(end() == _orig_end, "sanity"); |
tonyp@2472 | 432 | } |
tonyp@2472 | 433 | |
tonyp@2472 | 434 | assert(capacity() == (size_t) HeapRegion::GrainBytes, "pre-condition"); |
tonyp@2472 | 435 | _humongous_type = NotHumongous; |
tonyp@2472 | 436 | _humongous_start_region = NULL; |
tonyp@2472 | 437 | } |
tonyp@2472 | 438 | |
ysr@777 | 439 | bool HeapRegion::claimHeapRegion(jint claimValue) { |
ysr@777 | 440 | jint current = _claimed; |
ysr@777 | 441 | if (current != claimValue) { |
ysr@777 | 442 | jint res = Atomic::cmpxchg(claimValue, &_claimed, current); |
ysr@777 | 443 | if (res == current) { |
ysr@777 | 444 | return true; |
ysr@777 | 445 | } |
ysr@777 | 446 | } |
ysr@777 | 447 | return false; |
ysr@777 | 448 | } |
ysr@777 | 449 | |
ysr@777 | 450 | HeapWord* HeapRegion::next_block_start_careful(HeapWord* addr) { |
ysr@777 | 451 | HeapWord* low = addr; |
ysr@777 | 452 | HeapWord* high = end(); |
ysr@777 | 453 | while (low < high) { |
ysr@777 | 454 | size_t diff = pointer_delta(high, low); |
ysr@777 | 455 | // Must add one below to bias toward the high amount. Otherwise, if |
ysr@777 | 456 | // "high" were at the desired value, and "low" were one less, we |
ysr@777 | 457 | // would not converge on "high". This is not symmetric, because |
ysr@777 | 458 | // we set "high" to a block start, which might be the right one, |
ysr@777 | 459 | // which we don't do for "low". |
ysr@777 | 460 | HeapWord* middle = low + (diff+1)/2; |
ysr@777 | 461 | if (middle == high) return high; |
ysr@777 | 462 | HeapWord* mid_bs = block_start_careful(middle); |
ysr@777 | 463 | if (mid_bs < addr) { |
ysr@777 | 464 | low = middle; |
ysr@777 | 465 | } else { |
ysr@777 | 466 | high = mid_bs; |
ysr@777 | 467 | } |
ysr@777 | 468 | } |
ysr@777 | 469 | assert(low == high && low >= addr, "Didn't work."); |
ysr@777 | 470 | return low; |
ysr@777 | 471 | } |
ysr@777 | 472 | |
tonyp@791 | 473 | void HeapRegion::initialize(MemRegion mr, bool clear_space, bool mangle_space) { |
tonyp@791 | 474 | G1OffsetTableContigSpace::initialize(mr, false, mangle_space); |
ysr@777 | 475 | hr_clear(false/*par*/, clear_space); |
ysr@777 | 476 | } |
ysr@777 | 477 | #ifdef _MSC_VER // the use of 'this' below gets a warning, make it go away |
ysr@777 | 478 | #pragma warning( disable:4355 ) // 'this' : used in base member initializer list |
ysr@777 | 479 | #endif // _MSC_VER |
ysr@777 | 480 | |
ysr@777 | 481 | |
ysr@777 | 482 | HeapRegion:: |
tonyp@2963 | 483 | HeapRegion(size_t hrs_index, G1BlockOffsetSharedArray* sharedOffsetArray, |
tonyp@2963 | 484 | MemRegion mr, bool is_zeroed) |
ysr@777 | 485 | : G1OffsetTableContigSpace(sharedOffsetArray, mr, is_zeroed), |
tonyp@2963 | 486 | _next_fk(HeapRegionDCTOC::NoFilterKind), _hrs_index(hrs_index), |
tonyp@790 | 487 | _humongous_type(NotHumongous), _humongous_start_region(NULL), |
tonyp@3028 | 488 | _in_collection_set(false), |
ysr@777 | 489 | _next_in_special_set(NULL), _orig_end(NULL), |
tonyp@790 | 490 | _claimed(InitialClaimValue), _evacuation_failed(false), |
ysr@777 | 491 | _prev_marked_bytes(0), _next_marked_bytes(0), _sort_index(-1), |
ysr@777 | 492 | _young_type(NotYoung), _next_young_region(NULL), |
tonyp@2472 | 493 | _next_dirty_cards_region(NULL), _next(NULL), _pending_removal(false), |
tonyp@2472 | 494 | #ifdef ASSERT |
tonyp@2472 | 495 | _containing_set(NULL), |
tonyp@2472 | 496 | #endif // ASSERT |
tonyp@2472 | 497 | _young_index_in_cset(-1), _surv_rate_group(NULL), _age_index(-1), |
tonyp@2472 | 498 | _rem_set(NULL), _recorded_rs_length(0), _predicted_elapsed_time_ms(0), |
johnc@1829 | 499 | _predicted_bytes_to_copy(0) |
ysr@777 | 500 | { |
ysr@777 | 501 | _orig_end = mr.end(); |
ysr@777 | 502 | // Note that initialize() will set the start of the unmarked area of the |
ysr@777 | 503 | // region. |
tonyp@791 | 504 | this->initialize(mr, !is_zeroed, SpaceDecorator::Mangle); |
tonyp@791 | 505 | set_top(bottom()); |
tonyp@791 | 506 | set_saved_mark(); |
ysr@777 | 507 | |
ysr@777 | 508 | _rem_set = new HeapRegionRemSet(sharedOffsetArray, this); |
ysr@777 | 509 | |
ysr@777 | 510 | assert(HeapRegionRemSet::num_par_rem_sets() > 0, "Invariant."); |
ysr@777 | 511 | // In case the region is allocated during a pause, note the top. |
ysr@777 | 512 | // We haven't done any counting on a brand new region. |
ysr@777 | 513 | _top_at_conc_mark_count = bottom(); |
ysr@777 | 514 | } |
ysr@777 | 515 | |
ysr@777 | 516 | class NextCompactionHeapRegionClosure: public HeapRegionClosure { |
ysr@777 | 517 | const HeapRegion* _target; |
ysr@777 | 518 | bool _target_seen; |
ysr@777 | 519 | HeapRegion* _last; |
ysr@777 | 520 | CompactibleSpace* _res; |
ysr@777 | 521 | public: |
ysr@777 | 522 | NextCompactionHeapRegionClosure(const HeapRegion* target) : |
ysr@777 | 523 | _target(target), _target_seen(false), _res(NULL) {} |
ysr@777 | 524 | bool doHeapRegion(HeapRegion* cur) { |
ysr@777 | 525 | if (_target_seen) { |
ysr@777 | 526 | if (!cur->isHumongous()) { |
ysr@777 | 527 | _res = cur; |
ysr@777 | 528 | return true; |
ysr@777 | 529 | } |
ysr@777 | 530 | } else if (cur == _target) { |
ysr@777 | 531 | _target_seen = true; |
ysr@777 | 532 | } |
ysr@777 | 533 | return false; |
ysr@777 | 534 | } |
ysr@777 | 535 | CompactibleSpace* result() { return _res; } |
ysr@777 | 536 | }; |
ysr@777 | 537 | |
ysr@777 | 538 | CompactibleSpace* HeapRegion::next_compaction_space() const { |
ysr@777 | 539 | G1CollectedHeap* g1h = G1CollectedHeap::heap(); |
ysr@777 | 540 | // cast away const-ness |
ysr@777 | 541 | HeapRegion* r = (HeapRegion*) this; |
ysr@777 | 542 | NextCompactionHeapRegionClosure blk(r); |
ysr@777 | 543 | g1h->heap_region_iterate_from(r, &blk); |
ysr@777 | 544 | return blk.result(); |
ysr@777 | 545 | } |
ysr@777 | 546 | |
ysr@777 | 547 | void HeapRegion::save_marks() { |
ysr@777 | 548 | set_saved_mark(); |
ysr@777 | 549 | } |
ysr@777 | 550 | |
ysr@777 | 551 | void HeapRegion::oops_in_mr_iterate(MemRegion mr, OopClosure* cl) { |
ysr@777 | 552 | HeapWord* p = mr.start(); |
ysr@777 | 553 | HeapWord* e = mr.end(); |
ysr@777 | 554 | oop obj; |
ysr@777 | 555 | while (p < e) { |
ysr@777 | 556 | obj = oop(p); |
ysr@777 | 557 | p += obj->oop_iterate(cl); |
ysr@777 | 558 | } |
ysr@777 | 559 | assert(p == e, "bad memregion: doesn't end on obj boundary"); |
ysr@777 | 560 | } |
ysr@777 | 561 | |
ysr@777 | 562 | #define HeapRegion_OOP_SINCE_SAVE_MARKS_DEFN(OopClosureType, nv_suffix) \ |
ysr@777 | 563 | void HeapRegion::oop_since_save_marks_iterate##nv_suffix(OopClosureType* cl) { \ |
ysr@777 | 564 | ContiguousSpace::oop_since_save_marks_iterate##nv_suffix(cl); \ |
ysr@777 | 565 | } |
ysr@777 | 566 | SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES(HeapRegion_OOP_SINCE_SAVE_MARKS_DEFN) |
ysr@777 | 567 | |
ysr@777 | 568 | |
ysr@777 | 569 | void HeapRegion::oop_before_save_marks_iterate(OopClosure* cl) { |
ysr@777 | 570 | oops_in_mr_iterate(MemRegion(bottom(), saved_mark_word()), cl); |
ysr@777 | 571 | } |
ysr@777 | 572 | |
ysr@777 | 573 | HeapWord* |
ysr@777 | 574 | HeapRegion::object_iterate_mem_careful(MemRegion mr, |
ysr@777 | 575 | ObjectClosure* cl) { |
ysr@777 | 576 | G1CollectedHeap* g1h = G1CollectedHeap::heap(); |
ysr@777 | 577 | // We used to use "block_start_careful" here. But we're actually happy |
ysr@777 | 578 | // to update the BOT while we do this... |
ysr@777 | 579 | HeapWord* cur = block_start(mr.start()); |
ysr@777 | 580 | mr = mr.intersection(used_region()); |
ysr@777 | 581 | if (mr.is_empty()) return NULL; |
ysr@777 | 582 | // Otherwise, find the obj that extends onto mr.start(). |
ysr@777 | 583 | |
ysr@777 | 584 | assert(cur <= mr.start() |
ysr@1280 | 585 | && (oop(cur)->klass_or_null() == NULL || |
ysr@777 | 586 | cur + oop(cur)->size() > mr.start()), |
ysr@777 | 587 | "postcondition of block_start"); |
ysr@777 | 588 | oop obj; |
ysr@777 | 589 | while (cur < mr.end()) { |
ysr@777 | 590 | obj = oop(cur); |
ysr@1280 | 591 | if (obj->klass_or_null() == NULL) { |
ysr@777 | 592 | // Ran into an unparseable point. |
ysr@777 | 593 | return cur; |
ysr@777 | 594 | } else if (!g1h->is_obj_dead(obj)) { |
ysr@777 | 595 | cl->do_object(obj); |
ysr@777 | 596 | } |
ysr@777 | 597 | if (cl->abort()) return cur; |
ysr@777 | 598 | // The check above must occur before the operation below, since an |
ysr@777 | 599 | // abort might invalidate the "size" operation. |
ysr@777 | 600 | cur += obj->size(); |
ysr@777 | 601 | } |
ysr@777 | 602 | return NULL; |
ysr@777 | 603 | } |
ysr@777 | 604 | |
ysr@777 | 605 | HeapWord* |
ysr@777 | 606 | HeapRegion:: |
ysr@777 | 607 | oops_on_card_seq_iterate_careful(MemRegion mr, |
johnc@2021 | 608 | FilterOutOfRegionClosure* cl, |
tonyp@2849 | 609 | bool filter_young, |
tonyp@2849 | 610 | jbyte* card_ptr) { |
tonyp@2849 | 611 | // Currently, we should only have to clean the card if filter_young |
tonyp@2849 | 612 | // is true and vice versa. |
tonyp@2849 | 613 | if (filter_young) { |
tonyp@2849 | 614 | assert(card_ptr != NULL, "pre-condition"); |
tonyp@2849 | 615 | } else { |
tonyp@2849 | 616 | assert(card_ptr == NULL, "pre-condition"); |
tonyp@2849 | 617 | } |
ysr@777 | 618 | G1CollectedHeap* g1h = G1CollectedHeap::heap(); |
ysr@777 | 619 | |
ysr@777 | 620 | // If we're within a stop-world GC, then we might look at a card in a |
ysr@777 | 621 | // GC alloc region that extends onto a GC LAB, which may not be |
ysr@777 | 622 | // parseable. Stop such at the "saved_mark" of the region. |
ysr@777 | 623 | if (G1CollectedHeap::heap()->is_gc_active()) { |
ysr@777 | 624 | mr = mr.intersection(used_region_at_save_marks()); |
ysr@777 | 625 | } else { |
ysr@777 | 626 | mr = mr.intersection(used_region()); |
ysr@777 | 627 | } |
ysr@777 | 628 | if (mr.is_empty()) return NULL; |
ysr@777 | 629 | // Otherwise, find the obj that extends onto mr.start(). |
ysr@777 | 630 | |
johnc@2021 | 631 | // The intersection of the incoming mr (for the card) and the |
johnc@2021 | 632 | // allocated part of the region is non-empty. This implies that |
johnc@2021 | 633 | // we have actually allocated into this region. The code in |
johnc@2021 | 634 | // G1CollectedHeap.cpp that allocates a new region sets the |
johnc@2021 | 635 | // is_young tag on the region before allocating. Thus we |
johnc@2021 | 636 | // safely know if this region is young. |
johnc@2021 | 637 | if (is_young() && filter_young) { |
johnc@2021 | 638 | return NULL; |
johnc@2021 | 639 | } |
johnc@2021 | 640 | |
johnc@2060 | 641 | assert(!is_young(), "check value of filter_young"); |
johnc@2060 | 642 | |
tonyp@2849 | 643 | // We can only clean the card here, after we make the decision that |
tonyp@2849 | 644 | // the card is not young. And we only clean the card if we have been |
tonyp@2849 | 645 | // asked to (i.e., card_ptr != NULL). |
tonyp@2849 | 646 | if (card_ptr != NULL) { |
tonyp@2849 | 647 | *card_ptr = CardTableModRefBS::clean_card_val(); |
tonyp@2849 | 648 | // We must complete this write before we do any of the reads below. |
tonyp@2849 | 649 | OrderAccess::storeload(); |
tonyp@2849 | 650 | } |
tonyp@2849 | 651 | |
ysr@777 | 652 | // We used to use "block_start_careful" here. But we're actually happy |
ysr@777 | 653 | // to update the BOT while we do this... |
ysr@777 | 654 | HeapWord* cur = block_start(mr.start()); |
ysr@777 | 655 | assert(cur <= mr.start(), "Postcondition"); |
ysr@777 | 656 | |
ysr@777 | 657 | while (cur <= mr.start()) { |
ysr@1280 | 658 | if (oop(cur)->klass_or_null() == NULL) { |
ysr@777 | 659 | // Ran into an unparseable point. |
ysr@777 | 660 | return cur; |
ysr@777 | 661 | } |
ysr@777 | 662 | // Otherwise... |
ysr@777 | 663 | int sz = oop(cur)->size(); |
ysr@777 | 664 | if (cur + sz > mr.start()) break; |
ysr@777 | 665 | // Otherwise, go on. |
ysr@777 | 666 | cur = cur + sz; |
ysr@777 | 667 | } |
ysr@777 | 668 | oop obj; |
ysr@777 | 669 | obj = oop(cur); |
ysr@777 | 670 | // If we finish this loop... |
ysr@777 | 671 | assert(cur <= mr.start() |
ysr@1280 | 672 | && obj->klass_or_null() != NULL |
ysr@777 | 673 | && cur + obj->size() > mr.start(), |
ysr@777 | 674 | "Loop postcondition"); |
ysr@777 | 675 | if (!g1h->is_obj_dead(obj)) { |
ysr@777 | 676 | obj->oop_iterate(cl, mr); |
ysr@777 | 677 | } |
ysr@777 | 678 | |
ysr@777 | 679 | HeapWord* next; |
ysr@777 | 680 | while (cur < mr.end()) { |
ysr@777 | 681 | obj = oop(cur); |
ysr@1280 | 682 | if (obj->klass_or_null() == NULL) { |
ysr@777 | 683 | // Ran into an unparseable point. |
ysr@777 | 684 | return cur; |
ysr@777 | 685 | }; |
ysr@777 | 686 | // Otherwise: |
ysr@777 | 687 | next = (cur + obj->size()); |
ysr@777 | 688 | if (!g1h->is_obj_dead(obj)) { |
ysr@777 | 689 | if (next < mr.end()) { |
ysr@777 | 690 | obj->oop_iterate(cl); |
ysr@777 | 691 | } else { |
ysr@777 | 692 | // this obj spans the boundary. If it's an array, stop at the |
ysr@777 | 693 | // boundary. |
ysr@777 | 694 | if (obj->is_objArray()) { |
ysr@777 | 695 | obj->oop_iterate(cl, mr); |
ysr@777 | 696 | } else { |
ysr@777 | 697 | obj->oop_iterate(cl); |
ysr@777 | 698 | } |
ysr@777 | 699 | } |
ysr@777 | 700 | } |
ysr@777 | 701 | cur = next; |
ysr@777 | 702 | } |
ysr@777 | 703 | return NULL; |
ysr@777 | 704 | } |
ysr@777 | 705 | |
ysr@777 | 706 | void HeapRegion::print() const { print_on(gclog_or_tty); } |
ysr@777 | 707 | void HeapRegion::print_on(outputStream* st) const { |
ysr@777 | 708 | if (isHumongous()) { |
ysr@777 | 709 | if (startsHumongous()) |
ysr@777 | 710 | st->print(" HS"); |
ysr@777 | 711 | else |
ysr@777 | 712 | st->print(" HC"); |
ysr@777 | 713 | } else { |
ysr@777 | 714 | st->print(" "); |
ysr@777 | 715 | } |
ysr@777 | 716 | if (in_collection_set()) |
ysr@777 | 717 | st->print(" CS"); |
ysr@777 | 718 | else |
ysr@777 | 719 | st->print(" "); |
ysr@777 | 720 | if (is_young()) |
johnc@1829 | 721 | st->print(is_survivor() ? " SU" : " Y "); |
ysr@777 | 722 | else |
ysr@777 | 723 | st->print(" "); |
ysr@777 | 724 | if (is_empty()) |
ysr@777 | 725 | st->print(" F"); |
ysr@777 | 726 | else |
ysr@777 | 727 | st->print(" "); |
tonyp@1455 | 728 | st->print(" %5d", _gc_time_stamp); |
tonyp@1823 | 729 | st->print(" PTAMS "PTR_FORMAT" NTAMS "PTR_FORMAT, |
tonyp@1823 | 730 | prev_top_at_mark_start(), next_top_at_mark_start()); |
ysr@777 | 731 | G1OffsetTableContigSpace::print_on(st); |
ysr@777 | 732 | } |
ysr@777 | 733 | |
tonyp@1246 | 734 | void HeapRegion::verify(bool allow_dirty) const { |
tonyp@1455 | 735 | bool dummy = false; |
johnc@2969 | 736 | verify(allow_dirty, VerifyOption_G1UsePrevMarking, /* failures */ &dummy); |
tonyp@1246 | 737 | } |
tonyp@1246 | 738 | |
ysr@777 | 739 | // This really ought to be commoned up into OffsetTableContigSpace somehow. |
ysr@777 | 740 | // We would need a mechanism to make that code skip dead objects. |
ysr@777 | 741 | |
tonyp@1455 | 742 | void HeapRegion::verify(bool allow_dirty, |
johnc@2969 | 743 | VerifyOption vo, |
tonyp@1455 | 744 | bool* failures) const { |
ysr@777 | 745 | G1CollectedHeap* g1 = G1CollectedHeap::heap(); |
tonyp@1455 | 746 | *failures = false; |
ysr@777 | 747 | HeapWord* p = bottom(); |
ysr@777 | 748 | HeapWord* prev_p = NULL; |
johnc@2969 | 749 | VerifyLiveClosure vl_cl(g1, vo); |
tonyp@2073 | 750 | bool is_humongous = isHumongous(); |
tonyp@2453 | 751 | bool do_bot_verify = !is_young(); |
tonyp@2073 | 752 | size_t object_num = 0; |
ysr@777 | 753 | while (p < top()) { |
tonyp@2453 | 754 | oop obj = oop(p); |
tonyp@2453 | 755 | size_t obj_size = obj->size(); |
tonyp@2453 | 756 | object_num += 1; |
tonyp@2453 | 757 | |
tonyp@2453 | 758 | if (is_humongous != g1->isHumongous(obj_size)) { |
tonyp@2073 | 759 | gclog_or_tty->print_cr("obj "PTR_FORMAT" is of %shumongous size (" |
tonyp@2073 | 760 | SIZE_FORMAT" words) in a %shumongous region", |
tonyp@2453 | 761 | p, g1->isHumongous(obj_size) ? "" : "non-", |
tonyp@2453 | 762 | obj_size, is_humongous ? "" : "non-"); |
tonyp@2073 | 763 | *failures = true; |
tonyp@2453 | 764 | return; |
tonyp@2073 | 765 | } |
tonyp@2453 | 766 | |
tonyp@2453 | 767 | // If it returns false, verify_for_object() will output the |
tonyp@2453 | 768 | // appropriate messasge. |
tonyp@2453 | 769 | if (do_bot_verify && !_offsets.verify_for_object(p, obj_size)) { |
tonyp@2453 | 770 | *failures = true; |
tonyp@2453 | 771 | return; |
tonyp@2453 | 772 | } |
tonyp@2453 | 773 | |
johnc@2969 | 774 | if (!g1->is_obj_dead_cond(obj, this, vo)) { |
tonyp@2453 | 775 | if (obj->is_oop()) { |
tonyp@2453 | 776 | klassOop klass = obj->klass(); |
tonyp@2453 | 777 | if (!klass->is_perm()) { |
tonyp@2453 | 778 | gclog_or_tty->print_cr("klass "PTR_FORMAT" of object "PTR_FORMAT" " |
tonyp@2453 | 779 | "not in perm", klass, obj); |
tonyp@2453 | 780 | *failures = true; |
tonyp@2453 | 781 | return; |
tonyp@2453 | 782 | } else if (!klass->is_klass()) { |
tonyp@2453 | 783 | gclog_or_tty->print_cr("klass "PTR_FORMAT" of object "PTR_FORMAT" " |
tonyp@2453 | 784 | "not a klass", klass, obj); |
tonyp@2453 | 785 | *failures = true; |
tonyp@2453 | 786 | return; |
tonyp@2453 | 787 | } else { |
tonyp@2453 | 788 | vl_cl.set_containing_obj(obj); |
tonyp@2453 | 789 | obj->oop_iterate(&vl_cl); |
tonyp@2453 | 790 | if (vl_cl.failures()) { |
tonyp@2453 | 791 | *failures = true; |
tonyp@2453 | 792 | } |
tonyp@2453 | 793 | if (G1MaxVerifyFailures >= 0 && |
tonyp@2453 | 794 | vl_cl.n_failures() >= G1MaxVerifyFailures) { |
tonyp@2453 | 795 | return; |
tonyp@2453 | 796 | } |
tonyp@2453 | 797 | } |
tonyp@2453 | 798 | } else { |
tonyp@2453 | 799 | gclog_or_tty->print_cr(PTR_FORMAT" no an oop", obj); |
tonyp@1455 | 800 | *failures = true; |
tonyp@1455 | 801 | return; |
tonyp@1455 | 802 | } |
ysr@777 | 803 | } |
ysr@777 | 804 | prev_p = p; |
tonyp@2453 | 805 | p += obj_size; |
ysr@777 | 806 | } |
tonyp@2453 | 807 | |
tonyp@2453 | 808 | if (p != top()) { |
tonyp@2453 | 809 | gclog_or_tty->print_cr("end of last object "PTR_FORMAT" " |
tonyp@2453 | 810 | "does not match top "PTR_FORMAT, p, top()); |
tonyp@2453 | 811 | *failures = true; |
tonyp@2453 | 812 | return; |
tonyp@2453 | 813 | } |
tonyp@2453 | 814 | |
tonyp@2453 | 815 | HeapWord* the_end = end(); |
tonyp@2453 | 816 | assert(p == top(), "it should still hold"); |
tonyp@2453 | 817 | // Do some extra BOT consistency checking for addresses in the |
tonyp@2453 | 818 | // range [top, end). BOT look-ups in this range should yield |
tonyp@2453 | 819 | // top. No point in doing that if top == end (there's nothing there). |
tonyp@2453 | 820 | if (p < the_end) { |
tonyp@2453 | 821 | // Look up top |
tonyp@2453 | 822 | HeapWord* addr_1 = p; |
tonyp@2453 | 823 | HeapWord* b_start_1 = _offsets.block_start_const(addr_1); |
tonyp@2453 | 824 | if (b_start_1 != p) { |
tonyp@2453 | 825 | gclog_or_tty->print_cr("BOT look up for top: "PTR_FORMAT" " |
tonyp@2453 | 826 | " yielded "PTR_FORMAT", expecting "PTR_FORMAT, |
tonyp@2453 | 827 | addr_1, b_start_1, p); |
tonyp@2453 | 828 | *failures = true; |
tonyp@2453 | 829 | return; |
tonyp@2453 | 830 | } |
tonyp@2453 | 831 | |
tonyp@2453 | 832 | // Look up top + 1 |
tonyp@2453 | 833 | HeapWord* addr_2 = p + 1; |
tonyp@2453 | 834 | if (addr_2 < the_end) { |
tonyp@2453 | 835 | HeapWord* b_start_2 = _offsets.block_start_const(addr_2); |
tonyp@2453 | 836 | if (b_start_2 != p) { |
tonyp@2453 | 837 | gclog_or_tty->print_cr("BOT look up for top + 1: "PTR_FORMAT" " |
tonyp@2453 | 838 | " yielded "PTR_FORMAT", expecting "PTR_FORMAT, |
tonyp@2453 | 839 | addr_2, b_start_2, p); |
tonyp@1455 | 840 | *failures = true; |
tonyp@1455 | 841 | return; |
tonyp@2453 | 842 | } |
tonyp@2453 | 843 | } |
tonyp@2453 | 844 | |
tonyp@2453 | 845 | // Look up an address between top and end |
tonyp@2453 | 846 | size_t diff = pointer_delta(the_end, p) / 2; |
tonyp@2453 | 847 | HeapWord* addr_3 = p + diff; |
tonyp@2453 | 848 | if (addr_3 < the_end) { |
tonyp@2453 | 849 | HeapWord* b_start_3 = _offsets.block_start_const(addr_3); |
tonyp@2453 | 850 | if (b_start_3 != p) { |
tonyp@2453 | 851 | gclog_or_tty->print_cr("BOT look up for top + diff: "PTR_FORMAT" " |
tonyp@2453 | 852 | " yielded "PTR_FORMAT", expecting "PTR_FORMAT, |
tonyp@2453 | 853 | addr_3, b_start_3, p); |
tonyp@2453 | 854 | *failures = true; |
tonyp@2453 | 855 | return; |
tonyp@2453 | 856 | } |
tonyp@2453 | 857 | } |
tonyp@2453 | 858 | |
tonyp@2453 | 859 | // Loook up end - 1 |
tonyp@2453 | 860 | HeapWord* addr_4 = the_end - 1; |
tonyp@2453 | 861 | HeapWord* b_start_4 = _offsets.block_start_const(addr_4); |
tonyp@2453 | 862 | if (b_start_4 != p) { |
tonyp@2453 | 863 | gclog_or_tty->print_cr("BOT look up for end - 1: "PTR_FORMAT" " |
tonyp@2453 | 864 | " yielded "PTR_FORMAT", expecting "PTR_FORMAT, |
tonyp@2453 | 865 | addr_4, b_start_4, p); |
tonyp@2453 | 866 | *failures = true; |
tonyp@2453 | 867 | return; |
tonyp@1455 | 868 | } |
ysr@777 | 869 | } |
tonyp@1455 | 870 | |
tonyp@2073 | 871 | if (is_humongous && object_num > 1) { |
tonyp@2073 | 872 | gclog_or_tty->print_cr("region ["PTR_FORMAT","PTR_FORMAT"] is humongous " |
tonyp@2073 | 873 | "but has "SIZE_FORMAT", objects", |
tonyp@2073 | 874 | bottom(), end(), object_num); |
tonyp@2073 | 875 | *failures = true; |
tonyp@1455 | 876 | return; |
ysr@777 | 877 | } |
ysr@777 | 878 | } |
ysr@777 | 879 | |
ysr@777 | 880 | // G1OffsetTableContigSpace code; copied from space.cpp. Hope this can go |
ysr@777 | 881 | // away eventually. |
ysr@777 | 882 | |
tonyp@791 | 883 | void G1OffsetTableContigSpace::initialize(MemRegion mr, bool clear_space, bool mangle_space) { |
ysr@777 | 884 | // false ==> we'll do the clearing if there's clearing to be done. |
tonyp@791 | 885 | ContiguousSpace::initialize(mr, false, mangle_space); |
ysr@777 | 886 | _offsets.zero_bottom_entry(); |
ysr@777 | 887 | _offsets.initialize_threshold(); |
tonyp@791 | 888 | if (clear_space) clear(mangle_space); |
ysr@777 | 889 | } |
ysr@777 | 890 | |
tonyp@791 | 891 | void G1OffsetTableContigSpace::clear(bool mangle_space) { |
tonyp@791 | 892 | ContiguousSpace::clear(mangle_space); |
ysr@777 | 893 | _offsets.zero_bottom_entry(); |
ysr@777 | 894 | _offsets.initialize_threshold(); |
ysr@777 | 895 | } |
ysr@777 | 896 | |
ysr@777 | 897 | void G1OffsetTableContigSpace::set_bottom(HeapWord* new_bottom) { |
ysr@777 | 898 | Space::set_bottom(new_bottom); |
ysr@777 | 899 | _offsets.set_bottom(new_bottom); |
ysr@777 | 900 | } |
ysr@777 | 901 | |
ysr@777 | 902 | void G1OffsetTableContigSpace::set_end(HeapWord* new_end) { |
ysr@777 | 903 | Space::set_end(new_end); |
ysr@777 | 904 | _offsets.resize(new_end - bottom()); |
ysr@777 | 905 | } |
ysr@777 | 906 | |
ysr@777 | 907 | void G1OffsetTableContigSpace::print() const { |
ysr@777 | 908 | print_short(); |
ysr@777 | 909 | gclog_or_tty->print_cr(" [" INTPTR_FORMAT ", " INTPTR_FORMAT ", " |
ysr@777 | 910 | INTPTR_FORMAT ", " INTPTR_FORMAT ")", |
ysr@777 | 911 | bottom(), top(), _offsets.threshold(), end()); |
ysr@777 | 912 | } |
ysr@777 | 913 | |
ysr@777 | 914 | HeapWord* G1OffsetTableContigSpace::initialize_threshold() { |
ysr@777 | 915 | return _offsets.initialize_threshold(); |
ysr@777 | 916 | } |
ysr@777 | 917 | |
ysr@777 | 918 | HeapWord* G1OffsetTableContigSpace::cross_threshold(HeapWord* start, |
ysr@777 | 919 | HeapWord* end) { |
ysr@777 | 920 | _offsets.alloc_block(start, end); |
ysr@777 | 921 | return _offsets.threshold(); |
ysr@777 | 922 | } |
ysr@777 | 923 | |
ysr@777 | 924 | HeapWord* G1OffsetTableContigSpace::saved_mark_word() const { |
ysr@777 | 925 | G1CollectedHeap* g1h = G1CollectedHeap::heap(); |
ysr@777 | 926 | assert( _gc_time_stamp <= g1h->get_gc_time_stamp(), "invariant" ); |
ysr@777 | 927 | if (_gc_time_stamp < g1h->get_gc_time_stamp()) |
ysr@777 | 928 | return top(); |
ysr@777 | 929 | else |
ysr@777 | 930 | return ContiguousSpace::saved_mark_word(); |
ysr@777 | 931 | } |
ysr@777 | 932 | |
ysr@777 | 933 | void G1OffsetTableContigSpace::set_saved_mark() { |
ysr@777 | 934 | G1CollectedHeap* g1h = G1CollectedHeap::heap(); |
ysr@777 | 935 | unsigned curr_gc_time_stamp = g1h->get_gc_time_stamp(); |
ysr@777 | 936 | |
ysr@777 | 937 | if (_gc_time_stamp < curr_gc_time_stamp) { |
ysr@777 | 938 | // The order of these is important, as another thread might be |
ysr@777 | 939 | // about to start scanning this region. If it does so after |
ysr@777 | 940 | // set_saved_mark and before _gc_time_stamp = ..., then the latter |
ysr@777 | 941 | // will be false, and it will pick up top() as the high water mark |
ysr@777 | 942 | // of region. If it does so after _gc_time_stamp = ..., then it |
ysr@777 | 943 | // will pick up the right saved_mark_word() as the high water mark |
ysr@777 | 944 | // of the region. Either way, the behaviour will be correct. |
ysr@777 | 945 | ContiguousSpace::set_saved_mark(); |
ysr@1280 | 946 | OrderAccess::storestore(); |
iveresov@788 | 947 | _gc_time_stamp = curr_gc_time_stamp; |
tonyp@2715 | 948 | // No need to do another barrier to flush the writes above. If |
tonyp@2715 | 949 | // this is called in parallel with other threads trying to |
tonyp@2715 | 950 | // allocate into the region, the caller should call this while |
tonyp@2715 | 951 | // holding a lock and when the lock is released the writes will be |
tonyp@2715 | 952 | // flushed. |
ysr@777 | 953 | } |
ysr@777 | 954 | } |
ysr@777 | 955 | |
ysr@777 | 956 | G1OffsetTableContigSpace:: |
ysr@777 | 957 | G1OffsetTableContigSpace(G1BlockOffsetSharedArray* sharedOffsetArray, |
ysr@777 | 958 | MemRegion mr, bool is_zeroed) : |
ysr@777 | 959 | _offsets(sharedOffsetArray, mr), |
ysr@777 | 960 | _par_alloc_lock(Mutex::leaf, "OffsetTableContigSpace par alloc lock", true), |
ysr@777 | 961 | _gc_time_stamp(0) |
ysr@777 | 962 | { |
ysr@777 | 963 | _offsets.set_space(this); |
tonyp@791 | 964 | initialize(mr, !is_zeroed, SpaceDecorator::Mangle); |
ysr@777 | 965 | } |