Tue, 19 May 2015 15:49:27 +0200
8061715: gc/g1/TestShrinkAuxiliaryData15.java fails with java.lang.RuntimeException: heap decommit failed - after > before
Summary: added WhiteBox methods to count regions and exact aux data sizes
Reviewed-by: jwilhelm, brutisso
ysr@777 | 1 | /* |
tschatzl@7654 | 2 | * Copyright (c) 2001, 2015, 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" |
johnc@5548 | 26 | #include "code/nmethod.hpp" |
stefank@2314 | 27 | #include "gc_implementation/g1/g1BlockOffsetTable.inline.hpp" |
stefank@2314 | 28 | #include "gc_implementation/g1/g1CollectedHeap.inline.hpp" |
stefank@2314 | 29 | #include "gc_implementation/g1/g1OopClosures.inline.hpp" |
stefank@2314 | 30 | #include "gc_implementation/g1/heapRegion.inline.hpp" |
sjohanss@7137 | 31 | #include "gc_implementation/g1/heapRegionBounds.inline.hpp" |
stefank@2314 | 32 | #include "gc_implementation/g1/heapRegionRemSet.hpp" |
tschatzl@7091 | 33 | #include "gc_implementation/g1/heapRegionManager.inline.hpp" |
mgerdin@6990 | 34 | #include "gc_implementation/shared/liveRange.hpp" |
stefank@2314 | 35 | #include "memory/genOopClosures.inline.hpp" |
stefank@2314 | 36 | #include "memory/iterator.hpp" |
goetz@6912 | 37 | #include "memory/space.inline.hpp" |
stefank@2314 | 38 | #include "oops/oop.inline.hpp" |
goetz@6911 | 39 | #include "runtime/orderAccess.inline.hpp" |
ysr@777 | 40 | |
drchase@6680 | 41 | PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC |
drchase@6680 | 42 | |
johnc@3182 | 43 | int HeapRegion::LogOfHRGrainBytes = 0; |
johnc@3182 | 44 | int HeapRegion::LogOfHRGrainWords = 0; |
johnc@3182 | 45 | size_t HeapRegion::GrainBytes = 0; |
johnc@3182 | 46 | size_t HeapRegion::GrainWords = 0; |
johnc@3182 | 47 | size_t HeapRegion::CardsPerRegion = 0; |
tonyp@1377 | 48 | |
ysr@777 | 49 | HeapRegionDCTOC::HeapRegionDCTOC(G1CollectedHeap* g1, |
mgerdin@7655 | 50 | HeapRegion* hr, |
mgerdin@7655 | 51 | G1ParPushHeapRSClosure* cl, |
mgerdin@7655 | 52 | CardTableModRefBS::PrecisionStyle precision) : |
mgerdin@6986 | 53 | DirtyCardToOopClosure(hr, cl, precision, NULL), |
mgerdin@7655 | 54 | _hr(hr), _rs_scan(cl), _g1(g1) { } |
ysr@777 | 55 | |
ysr@777 | 56 | FilterOutOfRegionClosure::FilterOutOfRegionClosure(HeapRegion* r, |
ysr@777 | 57 | OopClosure* oc) : |
tonyp@3957 | 58 | _r_bottom(r->bottom()), _r_end(r->end()), _oc(oc) { } |
ysr@777 | 59 | |
mgerdin@6986 | 60 | void HeapRegionDCTOC::walk_mem_region(MemRegion mr, |
mgerdin@6986 | 61 | HeapWord* bottom, |
mgerdin@6986 | 62 | HeapWord* top) { |
ysr@777 | 63 | G1CollectedHeap* g1h = _g1; |
mgerdin@6990 | 64 | size_t oop_size; |
mgerdin@7655 | 65 | HeapWord* cur = bottom; |
ysr@777 | 66 | |
ysr@777 | 67 | // Start filtering what we add to the remembered set. If the object is |
ysr@777 | 68 | // not considered dead, either because it is marked (in the mark bitmap) |
ysr@777 | 69 | // or it was allocated after marking finished, then we add it. Otherwise |
ysr@777 | 70 | // we can safely ignore the object. |
mgerdin@7655 | 71 | if (!g1h->is_obj_dead(oop(cur), _hr)) { |
mgerdin@7655 | 72 | oop_size = oop(cur)->oop_iterate(_rs_scan, mr); |
ysr@777 | 73 | } else { |
mgerdin@7655 | 74 | oop_size = _hr->block_size(cur); |
ysr@777 | 75 | } |
ysr@777 | 76 | |
mgerdin@7655 | 77 | cur += oop_size; |
ysr@777 | 78 | |
mgerdin@7655 | 79 | if (cur < top) { |
mgerdin@7655 | 80 | oop cur_oop = oop(cur); |
mgerdin@7655 | 81 | oop_size = _hr->block_size(cur); |
mgerdin@7655 | 82 | HeapWord* next_obj = cur + oop_size; |
mgerdin@7655 | 83 | while (next_obj < top) { |
mgerdin@7655 | 84 | // Keep filtering the remembered set. |
mgerdin@7655 | 85 | if (!g1h->is_obj_dead(cur_oop, _hr)) { |
mgerdin@7655 | 86 | // Bottom lies entirely below top, so we can call the |
mgerdin@7655 | 87 | // non-memRegion version of oop_iterate below. |
mgerdin@7655 | 88 | cur_oop->oop_iterate(_rs_scan); |
mgerdin@7655 | 89 | } |
mgerdin@7655 | 90 | cur = next_obj; |
mgerdin@7655 | 91 | cur_oop = oop(cur); |
mgerdin@7655 | 92 | oop_size = _hr->block_size(cur); |
mgerdin@7655 | 93 | next_obj = cur + oop_size; |
ysr@777 | 94 | } |
ysr@777 | 95 | |
ysr@777 | 96 | // Last object. Need to do dead-obj filtering here too. |
mgerdin@7655 | 97 | if (!g1h->is_obj_dead(oop(cur), _hr)) { |
mgerdin@7655 | 98 | oop(cur)->oop_iterate(_rs_scan, mr); |
ysr@777 | 99 | } |
ysr@777 | 100 | } |
ysr@777 | 101 | } |
ysr@777 | 102 | |
tschatzl@5701 | 103 | size_t HeapRegion::max_region_size() { |
sjohanss@7137 | 104 | return HeapRegionBounds::max_size(); |
tschatzl@5701 | 105 | } |
tschatzl@5701 | 106 | |
brutisso@5646 | 107 | void HeapRegion::setup_heap_region_size(size_t initial_heap_size, size_t max_heap_size) { |
tonyp@1377 | 108 | uintx region_size = G1HeapRegionSize; |
tonyp@1377 | 109 | if (FLAG_IS_DEFAULT(G1HeapRegionSize)) { |
brutisso@5646 | 110 | size_t average_heap_size = (initial_heap_size + max_heap_size) / 2; |
sjohanss@7137 | 111 | region_size = MAX2(average_heap_size / HeapRegionBounds::target_number(), |
sjohanss@7137 | 112 | (uintx) HeapRegionBounds::min_size()); |
tonyp@1377 | 113 | } |
tonyp@1377 | 114 | |
tonyp@1377 | 115 | int region_size_log = log2_long((jlong) region_size); |
tonyp@1377 | 116 | // Recalculate the region size to make sure it's a power of |
tonyp@1377 | 117 | // 2. This means that region_size is the largest power of 2 that's |
tonyp@1377 | 118 | // <= what we've calculated so far. |
prr@1840 | 119 | region_size = ((uintx)1 << region_size_log); |
tonyp@1377 | 120 | |
tonyp@1377 | 121 | // Now make sure that we don't go over or under our limits. |
sjohanss@7137 | 122 | if (region_size < HeapRegionBounds::min_size()) { |
sjohanss@7137 | 123 | region_size = HeapRegionBounds::min_size(); |
sjohanss@7137 | 124 | } else if (region_size > HeapRegionBounds::max_size()) { |
sjohanss@7137 | 125 | region_size = HeapRegionBounds::max_size(); |
tonyp@1377 | 126 | } |
tonyp@1377 | 127 | |
tonyp@1377 | 128 | // And recalculate the log. |
tonyp@1377 | 129 | region_size_log = log2_long((jlong) region_size); |
tonyp@1377 | 130 | |
tonyp@1377 | 131 | // Now, set up the globals. |
tonyp@1377 | 132 | guarantee(LogOfHRGrainBytes == 0, "we should only set it once"); |
tonyp@1377 | 133 | LogOfHRGrainBytes = region_size_log; |
tonyp@1377 | 134 | |
tonyp@1377 | 135 | guarantee(LogOfHRGrainWords == 0, "we should only set it once"); |
tonyp@1377 | 136 | LogOfHRGrainWords = LogOfHRGrainBytes - LogHeapWordSize; |
tonyp@1377 | 137 | |
tonyp@1377 | 138 | guarantee(GrainBytes == 0, "we should only set it once"); |
tonyp@1377 | 139 | // The cast to int is safe, given that we've bounded region_size by |
tonyp@1377 | 140 | // MIN_REGION_SIZE and MAX_REGION_SIZE. |
johnc@3182 | 141 | GrainBytes = (size_t)region_size; |
tonyp@1377 | 142 | |
tonyp@1377 | 143 | guarantee(GrainWords == 0, "we should only set it once"); |
tonyp@1377 | 144 | GrainWords = GrainBytes >> LogHeapWordSize; |
tonyp@3713 | 145 | guarantee((size_t) 1 << LogOfHRGrainWords == GrainWords, "sanity"); |
tonyp@1377 | 146 | |
tonyp@1377 | 147 | guarantee(CardsPerRegion == 0, "we should only set it once"); |
tonyp@1377 | 148 | CardsPerRegion = GrainBytes >> CardTableModRefBS::card_shift; |
tonyp@1377 | 149 | } |
tonyp@1377 | 150 | |
ysr@777 | 151 | void HeapRegion::reset_after_compaction() { |
ysr@777 | 152 | G1OffsetTableContigSpace::reset_after_compaction(); |
ysr@777 | 153 | // After a compaction the mark bitmap is invalid, so we must |
ysr@777 | 154 | // treat all objects as being inside the unmarked area. |
ysr@777 | 155 | zero_marked_bytes(); |
ysr@777 | 156 | init_top_at_mark_start(); |
ysr@777 | 157 | } |
ysr@777 | 158 | |
tschatzl@6404 | 159 | void HeapRegion::hr_clear(bool par, bool clear_space, bool locked) { |
tonyp@2472 | 160 | assert(_humongous_start_region == NULL, |
tonyp@2472 | 161 | "we should have already filtered out humongous regions"); |
tonyp@2472 | 162 | assert(_end == _orig_end, |
tonyp@2472 | 163 | "we should have already filtered out humongous regions"); |
tonyp@2472 | 164 | |
ysr@777 | 165 | _in_collection_set = false; |
ysr@777 | 166 | |
sjohanss@7118 | 167 | set_allocation_context(AllocationContext::system()); |
ysr@777 | 168 | set_young_index_in_cset(-1); |
ysr@777 | 169 | uninstall_surv_rate_group(); |
brutisso@7195 | 170 | set_free(); |
tonyp@2715 | 171 | reset_pre_dummy_top(); |
ysr@777 | 172 | |
ysr@777 | 173 | if (!par) { |
ysr@777 | 174 | // If this is parallel, this will be done later. |
ysr@777 | 175 | HeapRegionRemSet* hrrs = rem_set(); |
tschatzl@6404 | 176 | if (locked) { |
tschatzl@6404 | 177 | hrrs->clear_locked(); |
tschatzl@6404 | 178 | } else { |
tschatzl@6404 | 179 | hrrs->clear(); |
tschatzl@6404 | 180 | } |
tonyp@790 | 181 | _claimed = InitialClaimValue; |
ysr@777 | 182 | } |
ysr@777 | 183 | zero_marked_bytes(); |
ysr@777 | 184 | |
ysr@777 | 185 | _offsets.resize(HeapRegion::GrainWords); |
ysr@777 | 186 | init_top_at_mark_start(); |
tonyp@791 | 187 | if (clear_space) clear(SpaceDecorator::Mangle); |
ysr@777 | 188 | } |
ysr@777 | 189 | |
tonyp@2849 | 190 | void HeapRegion::par_clear() { |
tonyp@2849 | 191 | assert(used() == 0, "the region should have been already cleared"); |
johnc@3182 | 192 | assert(capacity() == HeapRegion::GrainBytes, "should be back to normal"); |
tonyp@2849 | 193 | HeapRegionRemSet* hrrs = rem_set(); |
tonyp@2849 | 194 | hrrs->clear(); |
tonyp@2849 | 195 | CardTableModRefBS* ct_bs = |
tonyp@2849 | 196 | (CardTableModRefBS*)G1CollectedHeap::heap()->barrier_set(); |
tonyp@2849 | 197 | ct_bs->clear(MemRegion(bottom(), end())); |
tonyp@2849 | 198 | } |
tonyp@2849 | 199 | |
ysr@777 | 200 | void HeapRegion::calc_gc_efficiency() { |
johnc@3998 | 201 | // GC efficiency is the ratio of how much space would be |
johnc@3998 | 202 | // reclaimed over how long we predict it would take to reclaim it. |
ysr@777 | 203 | G1CollectedHeap* g1h = G1CollectedHeap::heap(); |
tonyp@3539 | 204 | G1CollectorPolicy* g1p = g1h->g1_policy(); |
johnc@3998 | 205 | |
johnc@3998 | 206 | // Retrieve a prediction of the elapsed time for this region for |
johnc@3998 | 207 | // a mixed gc because the region will only be evacuated during a |
johnc@3998 | 208 | // mixed gc. |
johnc@3998 | 209 | double region_elapsed_time_ms = |
johnc@3998 | 210 | g1p->predict_region_elapsed_time_ms(this, false /* for_young_gc */); |
johnc@3998 | 211 | _gc_efficiency = (double) reclaimable_bytes() / region_elapsed_time_ms; |
ysr@777 | 212 | } |
ysr@777 | 213 | |
tonyp@2453 | 214 | void HeapRegion::set_startsHumongous(HeapWord* new_top, HeapWord* new_end) { |
tonyp@2472 | 215 | assert(!isHumongous(), "sanity / pre-condition"); |
tonyp@2241 | 216 | assert(end() == _orig_end, |
tonyp@2241 | 217 | "Should be normal before the humongous object allocation"); |
tonyp@2241 | 218 | assert(top() == bottom(), "should be empty"); |
tonyp@2453 | 219 | assert(bottom() <= new_top && new_top <= new_end, "pre-condition"); |
tonyp@2241 | 220 | |
brutisso@7195 | 221 | _type.set_starts_humongous(); |
ysr@777 | 222 | _humongous_start_region = this; |
tonyp@2241 | 223 | |
tonyp@2241 | 224 | set_end(new_end); |
tonyp@2453 | 225 | _offsets.set_for_starts_humongous(new_top); |
tonyp@2241 | 226 | } |
tonyp@2241 | 227 | |
tonyp@2453 | 228 | void HeapRegion::set_continuesHumongous(HeapRegion* first_hr) { |
tonyp@2472 | 229 | assert(!isHumongous(), "sanity / pre-condition"); |
tonyp@2241 | 230 | assert(end() == _orig_end, |
tonyp@2241 | 231 | "Should be normal before the humongous object allocation"); |
tonyp@2241 | 232 | assert(top() == bottom(), "should be empty"); |
tonyp@2453 | 233 | assert(first_hr->startsHumongous(), "pre-condition"); |
tonyp@2241 | 234 | |
brutisso@7195 | 235 | _type.set_continues_humongous(); |
tonyp@2453 | 236 | _humongous_start_region = first_hr; |
ysr@777 | 237 | } |
ysr@777 | 238 | |
brutisso@7195 | 239 | void HeapRegion::clear_humongous() { |
tonyp@2472 | 240 | assert(isHumongous(), "pre-condition"); |
tonyp@2472 | 241 | |
tonyp@2472 | 242 | if (startsHumongous()) { |
tonyp@2472 | 243 | assert(top() <= end(), "pre-condition"); |
tonyp@2472 | 244 | set_end(_orig_end); |
tonyp@2472 | 245 | if (top() > end()) { |
tonyp@2472 | 246 | // at least one "continues humongous" region after it |
tonyp@2472 | 247 | set_top(end()); |
tonyp@2472 | 248 | } |
tonyp@2472 | 249 | } else { |
tonyp@2472 | 250 | // continues humongous |
tonyp@2472 | 251 | assert(end() == _orig_end, "sanity"); |
tonyp@2472 | 252 | } |
tonyp@2472 | 253 | |
johnc@3182 | 254 | assert(capacity() == HeapRegion::GrainBytes, "pre-condition"); |
tonyp@2472 | 255 | _humongous_start_region = NULL; |
tonyp@2472 | 256 | } |
tonyp@2472 | 257 | |
ysr@777 | 258 | bool HeapRegion::claimHeapRegion(jint claimValue) { |
ysr@777 | 259 | jint current = _claimed; |
ysr@777 | 260 | if (current != claimValue) { |
ysr@777 | 261 | jint res = Atomic::cmpxchg(claimValue, &_claimed, current); |
ysr@777 | 262 | if (res == current) { |
ysr@777 | 263 | return true; |
ysr@777 | 264 | } |
ysr@777 | 265 | } |
ysr@777 | 266 | return false; |
ysr@777 | 267 | } |
ysr@777 | 268 | |
tschatzl@7091 | 269 | HeapRegion::HeapRegion(uint hrm_index, |
tonyp@3713 | 270 | G1BlockOffsetSharedArray* sharedOffsetArray, |
sjohanss@7131 | 271 | MemRegion mr) : |
johnc@4065 | 272 | G1OffsetTableContigSpace(sharedOffsetArray, mr), |
sjohanss@7131 | 273 | _hrm_index(hrm_index), |
sjohanss@7131 | 274 | _allocation_context(AllocationContext::system()), |
brutisso@7195 | 275 | _humongous_start_region(NULL), |
tonyp@3028 | 276 | _in_collection_set(false), |
ysr@777 | 277 | _next_in_special_set(NULL), _orig_end(NULL), |
tonyp@790 | 278 | _claimed(InitialClaimValue), _evacuation_failed(false), |
tonyp@3714 | 279 | _prev_marked_bytes(0), _next_marked_bytes(0), _gc_efficiency(0.0), |
brutisso@7195 | 280 | _next_young_region(NULL), |
tschatzl@7050 | 281 | _next_dirty_cards_region(NULL), _next(NULL), _prev(NULL), |
tonyp@2472 | 282 | #ifdef ASSERT |
tonyp@2472 | 283 | _containing_set(NULL), |
tonyp@2472 | 284 | #endif // ASSERT |
tonyp@2472 | 285 | _young_index_in_cset(-1), _surv_rate_group(NULL), _age_index(-1), |
tonyp@2472 | 286 | _rem_set(NULL), _recorded_rs_length(0), _predicted_elapsed_time_ms(0), |
johnc@1829 | 287 | _predicted_bytes_to_copy(0) |
ysr@777 | 288 | { |
johnc@5548 | 289 | _rem_set = new HeapRegionRemSet(sharedOffsetArray, this); |
tschatzl@7050 | 290 | assert(HeapRegionRemSet::num_par_rem_sets() > 0, "Invariant."); |
tschatzl@7050 | 291 | |
tschatzl@7050 | 292 | initialize(mr); |
tschatzl@7050 | 293 | } |
tschatzl@7050 | 294 | |
tschatzl@7050 | 295 | void HeapRegion::initialize(MemRegion mr, bool clear_space, bool mangle_space) { |
tschatzl@7050 | 296 | assert(_rem_set->is_empty(), "Remembered set must be empty"); |
tschatzl@7050 | 297 | |
tschatzl@7050 | 298 | G1OffsetTableContigSpace::initialize(mr, clear_space, mangle_space); |
tschatzl@7050 | 299 | |
ysr@777 | 300 | _orig_end = mr.end(); |
johnc@4065 | 301 | hr_clear(false /*par*/, false /*clear_space*/); |
tonyp@791 | 302 | set_top(bottom()); |
mgerdin@7647 | 303 | record_timestamp(); |
ysr@777 | 304 | } |
ysr@777 | 305 | |
tonyp@3957 | 306 | CompactibleSpace* HeapRegion::next_compaction_space() const { |
tschatzl@7009 | 307 | return G1CollectedHeap::heap()->next_compaction_region(this); |
ysr@777 | 308 | } |
ysr@777 | 309 | |
tonyp@3416 | 310 | void HeapRegion::note_self_forwarding_removal_start(bool during_initial_mark, |
tonyp@3416 | 311 | bool during_conc_mark) { |
tonyp@3416 | 312 | // We always recreate the prev marking info and we'll explicitly |
tonyp@3416 | 313 | // mark all objects we find to be self-forwarded on the prev |
tonyp@3416 | 314 | // bitmap. So all objects need to be below PTAMS. |
tonyp@3416 | 315 | _prev_marked_bytes = 0; |
tonyp@3416 | 316 | |
tonyp@3416 | 317 | if (during_initial_mark) { |
tonyp@3416 | 318 | // During initial-mark, we'll also explicitly mark all objects |
tonyp@3416 | 319 | // we find to be self-forwarded on the next bitmap. So all |
tonyp@3416 | 320 | // objects need to be below NTAMS. |
tonyp@3416 | 321 | _next_top_at_mark_start = top(); |
tonyp@3416 | 322 | _next_marked_bytes = 0; |
tonyp@3416 | 323 | } else if (during_conc_mark) { |
tonyp@3416 | 324 | // During concurrent mark, all objects in the CSet (including |
tonyp@3416 | 325 | // the ones we find to be self-forwarded) are implicitly live. |
tonyp@3416 | 326 | // So all objects need to be above NTAMS. |
tonyp@3416 | 327 | _next_top_at_mark_start = bottom(); |
tonyp@3416 | 328 | _next_marked_bytes = 0; |
tonyp@3416 | 329 | } |
tonyp@3416 | 330 | } |
tonyp@3416 | 331 | |
tonyp@3416 | 332 | void HeapRegion::note_self_forwarding_removal_end(bool during_initial_mark, |
tonyp@3416 | 333 | bool during_conc_mark, |
tonyp@3416 | 334 | size_t marked_bytes) { |
tonyp@3416 | 335 | assert(0 <= marked_bytes && marked_bytes <= used(), |
tonyp@3416 | 336 | err_msg("marked: "SIZE_FORMAT" used: "SIZE_FORMAT, |
tonyp@3416 | 337 | marked_bytes, used())); |
stefank@6992 | 338 | _prev_top_at_mark_start = top(); |
tonyp@3416 | 339 | _prev_marked_bytes = marked_bytes; |
tonyp@3416 | 340 | } |
tonyp@3416 | 341 | |
ysr@777 | 342 | HeapWord* |
ysr@777 | 343 | HeapRegion::object_iterate_mem_careful(MemRegion mr, |
ysr@777 | 344 | ObjectClosure* cl) { |
ysr@777 | 345 | G1CollectedHeap* g1h = G1CollectedHeap::heap(); |
ysr@777 | 346 | // We used to use "block_start_careful" here. But we're actually happy |
ysr@777 | 347 | // to update the BOT while we do this... |
ysr@777 | 348 | HeapWord* cur = block_start(mr.start()); |
ysr@777 | 349 | mr = mr.intersection(used_region()); |
ysr@777 | 350 | if (mr.is_empty()) return NULL; |
ysr@777 | 351 | // Otherwise, find the obj that extends onto mr.start(). |
ysr@777 | 352 | |
ysr@777 | 353 | assert(cur <= mr.start() |
ysr@1280 | 354 | && (oop(cur)->klass_or_null() == NULL || |
ysr@777 | 355 | cur + oop(cur)->size() > mr.start()), |
ysr@777 | 356 | "postcondition of block_start"); |
ysr@777 | 357 | oop obj; |
ysr@777 | 358 | while (cur < mr.end()) { |
ysr@777 | 359 | obj = oop(cur); |
ysr@1280 | 360 | if (obj->klass_or_null() == NULL) { |
ysr@777 | 361 | // Ran into an unparseable point. |
ysr@777 | 362 | return cur; |
ysr@777 | 363 | } else if (!g1h->is_obj_dead(obj)) { |
ysr@777 | 364 | cl->do_object(obj); |
ysr@777 | 365 | } |
ysr@777 | 366 | if (cl->abort()) return cur; |
ysr@777 | 367 | // The check above must occur before the operation below, since an |
ysr@777 | 368 | // abort might invalidate the "size" operation. |
mgerdin@6990 | 369 | cur += block_size(cur); |
ysr@777 | 370 | } |
ysr@777 | 371 | return NULL; |
ysr@777 | 372 | } |
ysr@777 | 373 | |
ysr@777 | 374 | HeapWord* |
ysr@777 | 375 | HeapRegion:: |
ysr@777 | 376 | oops_on_card_seq_iterate_careful(MemRegion mr, |
johnc@2021 | 377 | FilterOutOfRegionClosure* cl, |
tonyp@2849 | 378 | bool filter_young, |
tonyp@2849 | 379 | jbyte* card_ptr) { |
tonyp@2849 | 380 | // Currently, we should only have to clean the card if filter_young |
tonyp@2849 | 381 | // is true and vice versa. |
tonyp@2849 | 382 | if (filter_young) { |
tonyp@2849 | 383 | assert(card_ptr != NULL, "pre-condition"); |
tonyp@2849 | 384 | } else { |
tonyp@2849 | 385 | assert(card_ptr == NULL, "pre-condition"); |
tonyp@2849 | 386 | } |
ysr@777 | 387 | G1CollectedHeap* g1h = G1CollectedHeap::heap(); |
ysr@777 | 388 | |
ysr@777 | 389 | // If we're within a stop-world GC, then we might look at a card in a |
ysr@777 | 390 | // GC alloc region that extends onto a GC LAB, which may not be |
mgerdin@7647 | 391 | // parseable. Stop such at the "scan_top" of the region. |
johnc@3466 | 392 | if (g1h->is_gc_active()) { |
mgerdin@7647 | 393 | mr = mr.intersection(MemRegion(bottom(), scan_top())); |
ysr@777 | 394 | } else { |
ysr@777 | 395 | mr = mr.intersection(used_region()); |
ysr@777 | 396 | } |
ysr@777 | 397 | if (mr.is_empty()) return NULL; |
ysr@777 | 398 | // Otherwise, find the obj that extends onto mr.start(). |
ysr@777 | 399 | |
johnc@2021 | 400 | // The intersection of the incoming mr (for the card) and the |
johnc@2021 | 401 | // allocated part of the region is non-empty. This implies that |
johnc@2021 | 402 | // we have actually allocated into this region. The code in |
johnc@2021 | 403 | // G1CollectedHeap.cpp that allocates a new region sets the |
johnc@2021 | 404 | // is_young tag on the region before allocating. Thus we |
johnc@2021 | 405 | // safely know if this region is young. |
johnc@2021 | 406 | if (is_young() && filter_young) { |
johnc@2021 | 407 | return NULL; |
johnc@2021 | 408 | } |
johnc@2021 | 409 | |
johnc@2060 | 410 | assert(!is_young(), "check value of filter_young"); |
johnc@2060 | 411 | |
tonyp@2849 | 412 | // We can only clean the card here, after we make the decision that |
tonyp@2849 | 413 | // the card is not young. And we only clean the card if we have been |
tonyp@2849 | 414 | // asked to (i.e., card_ptr != NULL). |
tonyp@2849 | 415 | if (card_ptr != NULL) { |
tonyp@2849 | 416 | *card_ptr = CardTableModRefBS::clean_card_val(); |
tonyp@2849 | 417 | // We must complete this write before we do any of the reads below. |
tonyp@2849 | 418 | OrderAccess::storeload(); |
tonyp@2849 | 419 | } |
tonyp@2849 | 420 | |
johnc@3466 | 421 | // Cache the boundaries of the memory region in some const locals |
johnc@3466 | 422 | HeapWord* const start = mr.start(); |
johnc@3466 | 423 | HeapWord* const end = mr.end(); |
johnc@3466 | 424 | |
ysr@777 | 425 | // We used to use "block_start_careful" here. But we're actually happy |
ysr@777 | 426 | // to update the BOT while we do this... |
johnc@3466 | 427 | HeapWord* cur = block_start(start); |
johnc@3466 | 428 | assert(cur <= start, "Postcondition"); |
ysr@777 | 429 | |
johnc@3466 | 430 | oop obj; |
johnc@3466 | 431 | |
johnc@3466 | 432 | HeapWord* next = cur; |
tschatzl@7654 | 433 | do { |
johnc@3466 | 434 | cur = next; |
johnc@3466 | 435 | obj = oop(cur); |
johnc@3466 | 436 | if (obj->klass_or_null() == NULL) { |
ysr@777 | 437 | // Ran into an unparseable point. |
ysr@777 | 438 | return cur; |
ysr@777 | 439 | } |
ysr@777 | 440 | // Otherwise... |
mgerdin@6990 | 441 | next = cur + block_size(cur); |
tschatzl@7654 | 442 | } while (next <= start); |
johnc@3466 | 443 | |
johnc@3466 | 444 | // If we finish the above loop...We have a parseable object that |
johnc@3466 | 445 | // begins on or before the start of the memory region, and ends |
johnc@3466 | 446 | // inside or spans the entire region. |
mgerdin@6990 | 447 | assert(cur <= start, "Loop postcondition"); |
mgerdin@6990 | 448 | assert(obj->klass_or_null() != NULL, "Loop postcondition"); |
johnc@3466 | 449 | |
tschatzl@7654 | 450 | do { |
ysr@777 | 451 | obj = oop(cur); |
tschatzl@7654 | 452 | assert((cur + block_size(cur)) > (HeapWord*)obj, "Loop invariant"); |
ysr@1280 | 453 | if (obj->klass_or_null() == NULL) { |
ysr@777 | 454 | // Ran into an unparseable point. |
ysr@777 | 455 | return cur; |
tschatzl@7654 | 456 | } |
johnc@3466 | 457 | |
tschatzl@7654 | 458 | // Advance the current pointer. "obj" still points to the object to iterate. |
tschatzl@7654 | 459 | cur = cur + block_size(cur); |
johnc@3466 | 460 | |
ysr@777 | 461 | if (!g1h->is_obj_dead(obj)) { |
tschatzl@7654 | 462 | // Non-objArrays are sometimes marked imprecise at the object start. We |
tschatzl@7654 | 463 | // always need to iterate over them in full. |
tschatzl@7654 | 464 | // We only iterate over object arrays in full if they are completely contained |
tschatzl@7654 | 465 | // in the memory region. |
tschatzl@7654 | 466 | if (!obj->is_objArray() || (((HeapWord*)obj) >= start && cur <= end)) { |
ysr@777 | 467 | obj->oop_iterate(cl); |
ysr@777 | 468 | } else { |
johnc@3466 | 469 | obj->oop_iterate(cl, mr); |
ysr@777 | 470 | } |
ysr@777 | 471 | } |
tschatzl@7654 | 472 | } while (cur < end); |
tschatzl@7654 | 473 | |
ysr@777 | 474 | return NULL; |
ysr@777 | 475 | } |
ysr@777 | 476 | |
johnc@5548 | 477 | // Code roots support |
johnc@5548 | 478 | |
johnc@5548 | 479 | void HeapRegion::add_strong_code_root(nmethod* nm) { |
johnc@5548 | 480 | HeapRegionRemSet* hrrs = rem_set(); |
johnc@5548 | 481 | hrrs->add_strong_code_root(nm); |
johnc@5548 | 482 | } |
johnc@5548 | 483 | |
mgerdin@7208 | 484 | void HeapRegion::add_strong_code_root_locked(nmethod* nm) { |
mgerdin@7208 | 485 | assert_locked_or_safepoint(CodeCache_lock); |
mgerdin@7208 | 486 | HeapRegionRemSet* hrrs = rem_set(); |
mgerdin@7208 | 487 | hrrs->add_strong_code_root_locked(nm); |
mgerdin@7208 | 488 | } |
mgerdin@7208 | 489 | |
johnc@5548 | 490 | void HeapRegion::remove_strong_code_root(nmethod* nm) { |
johnc@5548 | 491 | HeapRegionRemSet* hrrs = rem_set(); |
johnc@5548 | 492 | hrrs->remove_strong_code_root(nm); |
johnc@5548 | 493 | } |
johnc@5548 | 494 | |
johnc@5548 | 495 | void HeapRegion::strong_code_roots_do(CodeBlobClosure* blk) const { |
johnc@5548 | 496 | HeapRegionRemSet* hrrs = rem_set(); |
johnc@5548 | 497 | hrrs->strong_code_roots_do(blk); |
johnc@5548 | 498 | } |
johnc@5548 | 499 | |
johnc@5548 | 500 | class VerifyStrongCodeRootOopClosure: public OopClosure { |
johnc@5548 | 501 | const HeapRegion* _hr; |
johnc@5548 | 502 | nmethod* _nm; |
johnc@5548 | 503 | bool _failures; |
johnc@5548 | 504 | bool _has_oops_in_region; |
johnc@5548 | 505 | |
johnc@5548 | 506 | template <class T> void do_oop_work(T* p) { |
johnc@5548 | 507 | T heap_oop = oopDesc::load_heap_oop(p); |
johnc@5548 | 508 | if (!oopDesc::is_null(heap_oop)) { |
johnc@5548 | 509 | oop obj = oopDesc::decode_heap_oop_not_null(heap_oop); |
johnc@5548 | 510 | |
johnc@5548 | 511 | // Note: not all the oops embedded in the nmethod are in the |
johnc@5548 | 512 | // current region. We only look at those which are. |
johnc@5548 | 513 | if (_hr->is_in(obj)) { |
johnc@5548 | 514 | // Object is in the region. Check that its less than top |
johnc@5548 | 515 | if (_hr->top() <= (HeapWord*)obj) { |
johnc@5548 | 516 | // Object is above top |
johnc@5548 | 517 | gclog_or_tty->print_cr("Object "PTR_FORMAT" in region " |
johnc@5548 | 518 | "["PTR_FORMAT", "PTR_FORMAT") is above " |
johnc@5548 | 519 | "top "PTR_FORMAT, |
hseigel@5784 | 520 | (void *)obj, _hr->bottom(), _hr->end(), _hr->top()); |
johnc@5548 | 521 | _failures = true; |
johnc@5548 | 522 | return; |
johnc@5548 | 523 | } |
johnc@5548 | 524 | // Nmethod has at least one oop in the current region |
johnc@5548 | 525 | _has_oops_in_region = true; |
johnc@5548 | 526 | } |
johnc@5548 | 527 | } |
johnc@5548 | 528 | } |
johnc@5548 | 529 | |
johnc@5548 | 530 | public: |
johnc@5548 | 531 | VerifyStrongCodeRootOopClosure(const HeapRegion* hr, nmethod* nm): |
johnc@5548 | 532 | _hr(hr), _failures(false), _has_oops_in_region(false) {} |
johnc@5548 | 533 | |
johnc@5548 | 534 | void do_oop(narrowOop* p) { do_oop_work(p); } |
johnc@5548 | 535 | void do_oop(oop* p) { do_oop_work(p); } |
johnc@5548 | 536 | |
johnc@5548 | 537 | bool failures() { return _failures; } |
johnc@5548 | 538 | bool has_oops_in_region() { return _has_oops_in_region; } |
johnc@5548 | 539 | }; |
johnc@5548 | 540 | |
johnc@5548 | 541 | class VerifyStrongCodeRootCodeBlobClosure: public CodeBlobClosure { |
johnc@5548 | 542 | const HeapRegion* _hr; |
johnc@5548 | 543 | bool _failures; |
johnc@5548 | 544 | public: |
johnc@5548 | 545 | VerifyStrongCodeRootCodeBlobClosure(const HeapRegion* hr) : |
johnc@5548 | 546 | _hr(hr), _failures(false) {} |
johnc@5548 | 547 | |
johnc@5548 | 548 | void do_code_blob(CodeBlob* cb) { |
johnc@5548 | 549 | nmethod* nm = (cb == NULL) ? NULL : cb->as_nmethod_or_null(); |
johnc@5548 | 550 | if (nm != NULL) { |
johnc@5548 | 551 | // Verify that the nemthod is live |
johnc@5548 | 552 | if (!nm->is_alive()) { |
johnc@5548 | 553 | gclog_or_tty->print_cr("region ["PTR_FORMAT","PTR_FORMAT"] has dead nmethod " |
johnc@5548 | 554 | PTR_FORMAT" in its strong code roots", |
johnc@5548 | 555 | _hr->bottom(), _hr->end(), nm); |
johnc@5548 | 556 | _failures = true; |
johnc@5548 | 557 | } else { |
johnc@5548 | 558 | VerifyStrongCodeRootOopClosure oop_cl(_hr, nm); |
johnc@5548 | 559 | nm->oops_do(&oop_cl); |
johnc@5548 | 560 | if (!oop_cl.has_oops_in_region()) { |
johnc@5548 | 561 | gclog_or_tty->print_cr("region ["PTR_FORMAT","PTR_FORMAT"] has nmethod " |
johnc@5548 | 562 | PTR_FORMAT" in its strong code roots " |
johnc@5548 | 563 | "with no pointers into region", |
johnc@5548 | 564 | _hr->bottom(), _hr->end(), nm); |
johnc@5548 | 565 | _failures = true; |
johnc@5548 | 566 | } else if (oop_cl.failures()) { |
johnc@5548 | 567 | gclog_or_tty->print_cr("region ["PTR_FORMAT","PTR_FORMAT"] has other " |
johnc@5548 | 568 | "failures for nmethod "PTR_FORMAT, |
johnc@5548 | 569 | _hr->bottom(), _hr->end(), nm); |
johnc@5548 | 570 | _failures = true; |
johnc@5548 | 571 | } |
johnc@5548 | 572 | } |
johnc@5548 | 573 | } |
johnc@5548 | 574 | } |
johnc@5548 | 575 | |
johnc@5548 | 576 | bool failures() { return _failures; } |
johnc@5548 | 577 | }; |
johnc@5548 | 578 | |
johnc@5548 | 579 | void HeapRegion::verify_strong_code_roots(VerifyOption vo, bool* failures) const { |
johnc@5548 | 580 | if (!G1VerifyHeapRegionCodeRoots) { |
johnc@5548 | 581 | // We're not verifying code roots. |
johnc@5548 | 582 | return; |
johnc@5548 | 583 | } |
johnc@5548 | 584 | if (vo == VerifyOption_G1UseMarkWord) { |
johnc@5548 | 585 | // Marking verification during a full GC is performed after class |
johnc@5548 | 586 | // unloading, code cache unloading, etc so the strong code roots |
johnc@5548 | 587 | // attached to each heap region are in an inconsistent state. They won't |
johnc@5548 | 588 | // be consistent until the strong code roots are rebuilt after the |
johnc@5548 | 589 | // actual GC. Skip verifying the strong code roots in this particular |
johnc@5548 | 590 | // time. |
johnc@5548 | 591 | assert(VerifyDuringGC, "only way to get here"); |
johnc@5548 | 592 | return; |
johnc@5548 | 593 | } |
johnc@5548 | 594 | |
johnc@5548 | 595 | HeapRegionRemSet* hrrs = rem_set(); |
tschatzl@6402 | 596 | size_t strong_code_roots_length = hrrs->strong_code_roots_list_length(); |
johnc@5548 | 597 | |
johnc@5548 | 598 | // if this region is empty then there should be no entries |
johnc@5548 | 599 | // on its strong code root list |
johnc@5548 | 600 | if (is_empty()) { |
johnc@5548 | 601 | if (strong_code_roots_length > 0) { |
johnc@5548 | 602 | gclog_or_tty->print_cr("region ["PTR_FORMAT","PTR_FORMAT"] is empty " |
tschatzl@6402 | 603 | "but has "SIZE_FORMAT" code root entries", |
johnc@5548 | 604 | bottom(), end(), strong_code_roots_length); |
johnc@5548 | 605 | *failures = true; |
johnc@5548 | 606 | } |
johnc@5548 | 607 | return; |
johnc@5548 | 608 | } |
johnc@5548 | 609 | |
tschatzl@6087 | 610 | if (continuesHumongous()) { |
johnc@5548 | 611 | if (strong_code_roots_length > 0) { |
tschatzl@6087 | 612 | gclog_or_tty->print_cr("region "HR_FORMAT" is a continuation of a humongous " |
tschatzl@6402 | 613 | "region but has "SIZE_FORMAT" code root entries", |
tschatzl@6087 | 614 | HR_FORMAT_PARAMS(this), strong_code_roots_length); |
johnc@5548 | 615 | *failures = true; |
johnc@5548 | 616 | } |
johnc@5548 | 617 | return; |
johnc@5548 | 618 | } |
johnc@5548 | 619 | |
johnc@5548 | 620 | VerifyStrongCodeRootCodeBlobClosure cb_cl(this); |
johnc@5548 | 621 | strong_code_roots_do(&cb_cl); |
johnc@5548 | 622 | |
johnc@5548 | 623 | if (cb_cl.failures()) { |
johnc@5548 | 624 | *failures = true; |
johnc@5548 | 625 | } |
johnc@5548 | 626 | } |
johnc@5548 | 627 | |
ysr@777 | 628 | void HeapRegion::print() const { print_on(gclog_or_tty); } |
ysr@777 | 629 | void HeapRegion::print_on(outputStream* st) const { |
sjohanss@7118 | 630 | st->print("AC%4u", allocation_context()); |
brutisso@7195 | 631 | st->print(" %2s", get_short_type_str()); |
ysr@777 | 632 | if (in_collection_set()) |
ysr@777 | 633 | st->print(" CS"); |
ysr@777 | 634 | else |
ysr@777 | 635 | st->print(" "); |
tonyp@3269 | 636 | st->print(" TS %5d", _gc_time_stamp); |
tonyp@1823 | 637 | st->print(" PTAMS "PTR_FORMAT" NTAMS "PTR_FORMAT, |
tonyp@1823 | 638 | prev_top_at_mark_start(), next_top_at_mark_start()); |
ysr@777 | 639 | G1OffsetTableContigSpace::print_on(st); |
ysr@777 | 640 | } |
ysr@777 | 641 | |
johnc@5548 | 642 | class VerifyLiveClosure: public OopClosure { |
johnc@5548 | 643 | private: |
johnc@5548 | 644 | G1CollectedHeap* _g1h; |
johnc@5548 | 645 | CardTableModRefBS* _bs; |
johnc@5548 | 646 | oop _containing_obj; |
johnc@5548 | 647 | bool _failures; |
johnc@5548 | 648 | int _n_failures; |
johnc@5548 | 649 | VerifyOption _vo; |
johnc@5548 | 650 | public: |
johnc@5548 | 651 | // _vo == UsePrevMarking -> use "prev" marking information, |
johnc@5548 | 652 | // _vo == UseNextMarking -> use "next" marking information, |
johnc@5548 | 653 | // _vo == UseMarkWord -> use mark word from object header. |
johnc@5548 | 654 | VerifyLiveClosure(G1CollectedHeap* g1h, VerifyOption vo) : |
johnc@5548 | 655 | _g1h(g1h), _bs(NULL), _containing_obj(NULL), |
johnc@5548 | 656 | _failures(false), _n_failures(0), _vo(vo) |
johnc@5548 | 657 | { |
johnc@5548 | 658 | BarrierSet* bs = _g1h->barrier_set(); |
johnc@5548 | 659 | if (bs->is_a(BarrierSet::CardTableModRef)) |
johnc@5548 | 660 | _bs = (CardTableModRefBS*)bs; |
johnc@5548 | 661 | } |
johnc@5548 | 662 | |
johnc@5548 | 663 | void set_containing_obj(oop obj) { |
johnc@5548 | 664 | _containing_obj = obj; |
johnc@5548 | 665 | } |
johnc@5548 | 666 | |
johnc@5548 | 667 | bool failures() { return _failures; } |
johnc@5548 | 668 | int n_failures() { return _n_failures; } |
johnc@5548 | 669 | |
johnc@5548 | 670 | virtual void do_oop(narrowOop* p) { do_oop_work(p); } |
johnc@5548 | 671 | virtual void do_oop( oop* p) { do_oop_work(p); } |
johnc@5548 | 672 | |
johnc@5548 | 673 | void print_object(outputStream* out, oop obj) { |
johnc@5548 | 674 | #ifdef PRODUCT |
johnc@5548 | 675 | Klass* k = obj->klass(); |
johnc@5548 | 676 | const char* class_name = InstanceKlass::cast(k)->external_name(); |
johnc@5548 | 677 | out->print_cr("class name %s", class_name); |
johnc@5548 | 678 | #else // PRODUCT |
johnc@5548 | 679 | obj->print_on(out); |
johnc@5548 | 680 | #endif // PRODUCT |
johnc@5548 | 681 | } |
johnc@5548 | 682 | |
johnc@5548 | 683 | template <class T> |
johnc@5548 | 684 | void do_oop_work(T* p) { |
johnc@5548 | 685 | assert(_containing_obj != NULL, "Precondition"); |
johnc@5548 | 686 | assert(!_g1h->is_obj_dead_cond(_containing_obj, _vo), |
johnc@5548 | 687 | "Precondition"); |
johnc@5548 | 688 | T heap_oop = oopDesc::load_heap_oop(p); |
johnc@5548 | 689 | if (!oopDesc::is_null(heap_oop)) { |
johnc@5548 | 690 | oop obj = oopDesc::decode_heap_oop_not_null(heap_oop); |
johnc@5548 | 691 | bool failed = false; |
johnc@5548 | 692 | if (!_g1h->is_in_closed_subset(obj) || _g1h->is_obj_dead_cond(obj, _vo)) { |
johnc@5548 | 693 | MutexLockerEx x(ParGCRareEvent_lock, |
johnc@5548 | 694 | Mutex::_no_safepoint_check_flag); |
johnc@5548 | 695 | |
johnc@5548 | 696 | if (!_failures) { |
drchase@6680 | 697 | gclog_or_tty->cr(); |
johnc@5548 | 698 | gclog_or_tty->print_cr("----------"); |
johnc@5548 | 699 | } |
johnc@5548 | 700 | if (!_g1h->is_in_closed_subset(obj)) { |
johnc@5548 | 701 | HeapRegion* from = _g1h->heap_region_containing((HeapWord*)p); |
johnc@5548 | 702 | gclog_or_tty->print_cr("Field "PTR_FORMAT |
johnc@5548 | 703 | " of live obj "PTR_FORMAT" in region " |
johnc@5548 | 704 | "["PTR_FORMAT", "PTR_FORMAT")", |
johnc@5548 | 705 | p, (void*) _containing_obj, |
johnc@5548 | 706 | from->bottom(), from->end()); |
johnc@5548 | 707 | print_object(gclog_or_tty, _containing_obj); |
johnc@5548 | 708 | gclog_or_tty->print_cr("points to obj "PTR_FORMAT" not in the heap", |
johnc@5548 | 709 | (void*) obj); |
johnc@5548 | 710 | } else { |
johnc@5548 | 711 | HeapRegion* from = _g1h->heap_region_containing((HeapWord*)p); |
johnc@5548 | 712 | HeapRegion* to = _g1h->heap_region_containing((HeapWord*)obj); |
johnc@5548 | 713 | gclog_or_tty->print_cr("Field "PTR_FORMAT |
johnc@5548 | 714 | " of live obj "PTR_FORMAT" in region " |
johnc@5548 | 715 | "["PTR_FORMAT", "PTR_FORMAT")", |
johnc@5548 | 716 | p, (void*) _containing_obj, |
johnc@5548 | 717 | from->bottom(), from->end()); |
johnc@5548 | 718 | print_object(gclog_or_tty, _containing_obj); |
johnc@5548 | 719 | gclog_or_tty->print_cr("points to dead obj "PTR_FORMAT" in region " |
johnc@5548 | 720 | "["PTR_FORMAT", "PTR_FORMAT")", |
johnc@5548 | 721 | (void*) obj, to->bottom(), to->end()); |
johnc@5548 | 722 | print_object(gclog_or_tty, obj); |
johnc@5548 | 723 | } |
johnc@5548 | 724 | gclog_or_tty->print_cr("----------"); |
johnc@5548 | 725 | gclog_or_tty->flush(); |
johnc@5548 | 726 | _failures = true; |
johnc@5548 | 727 | failed = true; |
johnc@5548 | 728 | _n_failures++; |
johnc@5548 | 729 | } |
johnc@5548 | 730 | |
johnc@5548 | 731 | if (!_g1h->full_collection() || G1VerifyRSetsDuringFullGC) { |
johnc@5548 | 732 | HeapRegion* from = _g1h->heap_region_containing((HeapWord*)p); |
johnc@5548 | 733 | HeapRegion* to = _g1h->heap_region_containing(obj); |
johnc@5548 | 734 | if (from != NULL && to != NULL && |
johnc@5548 | 735 | from != to && |
johnc@5548 | 736 | !to->isHumongous()) { |
johnc@5548 | 737 | jbyte cv_obj = *_bs->byte_for_const(_containing_obj); |
johnc@5548 | 738 | jbyte cv_field = *_bs->byte_for_const(p); |
johnc@5548 | 739 | const jbyte dirty = CardTableModRefBS::dirty_card_val(); |
johnc@5548 | 740 | |
johnc@5548 | 741 | bool is_bad = !(from->is_young() |
johnc@5548 | 742 | || to->rem_set()->contains_reference(p) |
johnc@5548 | 743 | || !G1HRRSFlushLogBuffersOnVerify && // buffers were not flushed |
johnc@5548 | 744 | (_containing_obj->is_objArray() ? |
johnc@5548 | 745 | cv_field == dirty |
johnc@5548 | 746 | : cv_obj == dirty || cv_field == dirty)); |
johnc@5548 | 747 | if (is_bad) { |
johnc@5548 | 748 | MutexLockerEx x(ParGCRareEvent_lock, |
johnc@5548 | 749 | Mutex::_no_safepoint_check_flag); |
johnc@5548 | 750 | |
johnc@5548 | 751 | if (!_failures) { |
drchase@6680 | 752 | gclog_or_tty->cr(); |
johnc@5548 | 753 | gclog_or_tty->print_cr("----------"); |
johnc@5548 | 754 | } |
johnc@5548 | 755 | gclog_or_tty->print_cr("Missing rem set entry:"); |
johnc@5548 | 756 | gclog_or_tty->print_cr("Field "PTR_FORMAT" " |
johnc@5548 | 757 | "of obj "PTR_FORMAT", " |
johnc@5548 | 758 | "in region "HR_FORMAT, |
johnc@5548 | 759 | p, (void*) _containing_obj, |
johnc@5548 | 760 | HR_FORMAT_PARAMS(from)); |
johnc@5548 | 761 | _containing_obj->print_on(gclog_or_tty); |
johnc@5548 | 762 | gclog_or_tty->print_cr("points to obj "PTR_FORMAT" " |
johnc@5548 | 763 | "in region "HR_FORMAT, |
johnc@5548 | 764 | (void*) obj, |
johnc@5548 | 765 | HR_FORMAT_PARAMS(to)); |
johnc@5548 | 766 | obj->print_on(gclog_or_tty); |
johnc@5548 | 767 | gclog_or_tty->print_cr("Obj head CTE = %d, field CTE = %d.", |
johnc@5548 | 768 | cv_obj, cv_field); |
johnc@5548 | 769 | gclog_or_tty->print_cr("----------"); |
johnc@5548 | 770 | gclog_or_tty->flush(); |
johnc@5548 | 771 | _failures = true; |
johnc@5548 | 772 | if (!failed) _n_failures++; |
johnc@5548 | 773 | } |
johnc@5548 | 774 | } |
johnc@5548 | 775 | } |
johnc@5548 | 776 | } |
johnc@5548 | 777 | } |
johnc@5548 | 778 | }; |
tonyp@1246 | 779 | |
ysr@777 | 780 | // This really ought to be commoned up into OffsetTableContigSpace somehow. |
ysr@777 | 781 | // We would need a mechanism to make that code skip dead objects. |
ysr@777 | 782 | |
brutisso@3711 | 783 | void HeapRegion::verify(VerifyOption vo, |
tonyp@1455 | 784 | bool* failures) const { |
ysr@777 | 785 | G1CollectedHeap* g1 = G1CollectedHeap::heap(); |
tonyp@1455 | 786 | *failures = false; |
ysr@777 | 787 | HeapWord* p = bottom(); |
ysr@777 | 788 | HeapWord* prev_p = NULL; |
johnc@2969 | 789 | VerifyLiveClosure vl_cl(g1, vo); |
tonyp@2073 | 790 | bool is_humongous = isHumongous(); |
tonyp@2453 | 791 | bool do_bot_verify = !is_young(); |
tonyp@2073 | 792 | size_t object_num = 0; |
ysr@777 | 793 | while (p < top()) { |
tonyp@2453 | 794 | oop obj = oop(p); |
mgerdin@6990 | 795 | size_t obj_size = block_size(p); |
tonyp@2453 | 796 | object_num += 1; |
tonyp@2453 | 797 | |
stefank@6992 | 798 | if (is_humongous != g1->isHumongous(obj_size) && |
stefank@6992 | 799 | !g1->is_obj_dead(obj, this)) { // Dead objects may have bigger block_size since they span several objects. |
tonyp@2073 | 800 | gclog_or_tty->print_cr("obj "PTR_FORMAT" is of %shumongous size (" |
tonyp@2073 | 801 | SIZE_FORMAT" words) in a %shumongous region", |
tonyp@2453 | 802 | p, g1->isHumongous(obj_size) ? "" : "non-", |
tonyp@2453 | 803 | obj_size, is_humongous ? "" : "non-"); |
tonyp@2073 | 804 | *failures = true; |
tonyp@2453 | 805 | return; |
tonyp@2073 | 806 | } |
tonyp@2453 | 807 | |
tonyp@2453 | 808 | // If it returns false, verify_for_object() will output the |
tschatzl@7050 | 809 | // appropriate message. |
stefank@6992 | 810 | if (do_bot_verify && |
stefank@6992 | 811 | !g1->is_obj_dead(obj, this) && |
stefank@6992 | 812 | !_offsets.verify_for_object(p, obj_size)) { |
tonyp@2453 | 813 | *failures = true; |
tonyp@2453 | 814 | return; |
tonyp@2453 | 815 | } |
tonyp@2453 | 816 | |
johnc@2969 | 817 | if (!g1->is_obj_dead_cond(obj, this, vo)) { |
tonyp@2453 | 818 | if (obj->is_oop()) { |
coleenp@4037 | 819 | Klass* klass = obj->klass(); |
stefank@6992 | 820 | bool is_metaspace_object = Metaspace::contains(klass) || |
stefank@6992 | 821 | (vo == VerifyOption_G1UsePrevMarking && |
stefank@6992 | 822 | ClassLoaderDataGraph::unload_list_contains(klass)); |
stefank@6992 | 823 | if (!is_metaspace_object) { |
tonyp@2453 | 824 | gclog_or_tty->print_cr("klass "PTR_FORMAT" of object "PTR_FORMAT" " |
hseigel@5784 | 825 | "not metadata", klass, (void *)obj); |
tonyp@2453 | 826 | *failures = true; |
tonyp@2453 | 827 | return; |
tonyp@2453 | 828 | } else if (!klass->is_klass()) { |
tonyp@2453 | 829 | gclog_or_tty->print_cr("klass "PTR_FORMAT" of object "PTR_FORMAT" " |
hseigel@5784 | 830 | "not a klass", klass, (void *)obj); |
tonyp@2453 | 831 | *failures = true; |
tonyp@2453 | 832 | return; |
tonyp@2453 | 833 | } else { |
tonyp@2453 | 834 | vl_cl.set_containing_obj(obj); |
coleenp@4037 | 835 | obj->oop_iterate_no_header(&vl_cl); |
tonyp@2453 | 836 | if (vl_cl.failures()) { |
tonyp@2453 | 837 | *failures = true; |
tonyp@2453 | 838 | } |
tonyp@2453 | 839 | if (G1MaxVerifyFailures >= 0 && |
tonyp@2453 | 840 | vl_cl.n_failures() >= G1MaxVerifyFailures) { |
tonyp@2453 | 841 | return; |
tonyp@2453 | 842 | } |
tonyp@2453 | 843 | } |
tonyp@2453 | 844 | } else { |
hseigel@5784 | 845 | gclog_or_tty->print_cr(PTR_FORMAT" no an oop", (void *)obj); |
tonyp@1455 | 846 | *failures = true; |
tonyp@1455 | 847 | return; |
tonyp@1455 | 848 | } |
ysr@777 | 849 | } |
ysr@777 | 850 | prev_p = p; |
tonyp@2453 | 851 | p += obj_size; |
ysr@777 | 852 | } |
tonyp@2453 | 853 | |
tonyp@2453 | 854 | if (p != top()) { |
tonyp@2453 | 855 | gclog_or_tty->print_cr("end of last object "PTR_FORMAT" " |
tonyp@2453 | 856 | "does not match top "PTR_FORMAT, p, top()); |
tonyp@2453 | 857 | *failures = true; |
tonyp@2453 | 858 | return; |
tonyp@2453 | 859 | } |
tonyp@2453 | 860 | |
tonyp@2453 | 861 | HeapWord* the_end = end(); |
tonyp@2453 | 862 | assert(p == top(), "it should still hold"); |
tonyp@2453 | 863 | // Do some extra BOT consistency checking for addresses in the |
tonyp@2453 | 864 | // range [top, end). BOT look-ups in this range should yield |
tonyp@2453 | 865 | // top. No point in doing that if top == end (there's nothing there). |
tonyp@2453 | 866 | if (p < the_end) { |
tonyp@2453 | 867 | // Look up top |
tonyp@2453 | 868 | HeapWord* addr_1 = p; |
tonyp@2453 | 869 | HeapWord* b_start_1 = _offsets.block_start_const(addr_1); |
tonyp@2453 | 870 | if (b_start_1 != p) { |
tonyp@2453 | 871 | gclog_or_tty->print_cr("BOT look up for top: "PTR_FORMAT" " |
tonyp@2453 | 872 | " yielded "PTR_FORMAT", expecting "PTR_FORMAT, |
tonyp@2453 | 873 | addr_1, b_start_1, p); |
tonyp@2453 | 874 | *failures = true; |
tonyp@2453 | 875 | return; |
tonyp@2453 | 876 | } |
tonyp@2453 | 877 | |
tonyp@2453 | 878 | // Look up top + 1 |
tonyp@2453 | 879 | HeapWord* addr_2 = p + 1; |
tonyp@2453 | 880 | if (addr_2 < the_end) { |
tonyp@2453 | 881 | HeapWord* b_start_2 = _offsets.block_start_const(addr_2); |
tonyp@2453 | 882 | if (b_start_2 != p) { |
tonyp@2453 | 883 | gclog_or_tty->print_cr("BOT look up for top + 1: "PTR_FORMAT" " |
tonyp@2453 | 884 | " yielded "PTR_FORMAT", expecting "PTR_FORMAT, |
tonyp@2453 | 885 | addr_2, b_start_2, p); |
tonyp@1455 | 886 | *failures = true; |
tonyp@1455 | 887 | return; |
tonyp@2453 | 888 | } |
tonyp@2453 | 889 | } |
tonyp@2453 | 890 | |
tonyp@2453 | 891 | // Look up an address between top and end |
tonyp@2453 | 892 | size_t diff = pointer_delta(the_end, p) / 2; |
tonyp@2453 | 893 | HeapWord* addr_3 = p + diff; |
tonyp@2453 | 894 | if (addr_3 < the_end) { |
tonyp@2453 | 895 | HeapWord* b_start_3 = _offsets.block_start_const(addr_3); |
tonyp@2453 | 896 | if (b_start_3 != p) { |
tonyp@2453 | 897 | gclog_or_tty->print_cr("BOT look up for top + diff: "PTR_FORMAT" " |
tonyp@2453 | 898 | " yielded "PTR_FORMAT", expecting "PTR_FORMAT, |
tonyp@2453 | 899 | addr_3, b_start_3, p); |
tonyp@2453 | 900 | *failures = true; |
tonyp@2453 | 901 | return; |
tonyp@2453 | 902 | } |
tonyp@2453 | 903 | } |
tonyp@2453 | 904 | |
tonyp@2453 | 905 | // Loook up end - 1 |
tonyp@2453 | 906 | HeapWord* addr_4 = the_end - 1; |
tonyp@2453 | 907 | HeapWord* b_start_4 = _offsets.block_start_const(addr_4); |
tonyp@2453 | 908 | if (b_start_4 != p) { |
tonyp@2453 | 909 | gclog_or_tty->print_cr("BOT look up for end - 1: "PTR_FORMAT" " |
tonyp@2453 | 910 | " yielded "PTR_FORMAT", expecting "PTR_FORMAT, |
tonyp@2453 | 911 | addr_4, b_start_4, p); |
tonyp@2453 | 912 | *failures = true; |
tonyp@2453 | 913 | return; |
tonyp@1455 | 914 | } |
ysr@777 | 915 | } |
tonyp@1455 | 916 | |
tonyp@2073 | 917 | if (is_humongous && object_num > 1) { |
tonyp@2073 | 918 | gclog_or_tty->print_cr("region ["PTR_FORMAT","PTR_FORMAT"] is humongous " |
tonyp@2073 | 919 | "but has "SIZE_FORMAT", objects", |
tonyp@2073 | 920 | bottom(), end(), object_num); |
tonyp@2073 | 921 | *failures = true; |
tonyp@1455 | 922 | return; |
ysr@777 | 923 | } |
johnc@5548 | 924 | |
johnc@5548 | 925 | verify_strong_code_roots(vo, failures); |
johnc@5548 | 926 | } |
johnc@5548 | 927 | |
johnc@5548 | 928 | void HeapRegion::verify() const { |
johnc@5548 | 929 | bool dummy = false; |
johnc@5548 | 930 | verify(VerifyOption_G1UsePrevMarking, /* failures */ &dummy); |
ysr@777 | 931 | } |
ysr@777 | 932 | |
ysr@777 | 933 | // G1OffsetTableContigSpace code; copied from space.cpp. Hope this can go |
ysr@777 | 934 | // away eventually. |
ysr@777 | 935 | |
tonyp@791 | 936 | void G1OffsetTableContigSpace::clear(bool mangle_space) { |
mgerdin@6990 | 937 | set_top(bottom()); |
mgerdin@7647 | 938 | _scan_top = bottom(); |
mgerdin@6990 | 939 | CompactibleSpace::clear(mangle_space); |
tschatzl@7050 | 940 | reset_bot(); |
ysr@777 | 941 | } |
ysr@777 | 942 | |
ysr@777 | 943 | void G1OffsetTableContigSpace::set_bottom(HeapWord* new_bottom) { |
ysr@777 | 944 | Space::set_bottom(new_bottom); |
ysr@777 | 945 | _offsets.set_bottom(new_bottom); |
ysr@777 | 946 | } |
ysr@777 | 947 | |
ysr@777 | 948 | void G1OffsetTableContigSpace::set_end(HeapWord* new_end) { |
ysr@777 | 949 | Space::set_end(new_end); |
ysr@777 | 950 | _offsets.resize(new_end - bottom()); |
ysr@777 | 951 | } |
ysr@777 | 952 | |
ysr@777 | 953 | void G1OffsetTableContigSpace::print() const { |
ysr@777 | 954 | print_short(); |
ysr@777 | 955 | gclog_or_tty->print_cr(" [" INTPTR_FORMAT ", " INTPTR_FORMAT ", " |
ysr@777 | 956 | INTPTR_FORMAT ", " INTPTR_FORMAT ")", |
ysr@777 | 957 | bottom(), top(), _offsets.threshold(), end()); |
ysr@777 | 958 | } |
ysr@777 | 959 | |
ysr@777 | 960 | HeapWord* G1OffsetTableContigSpace::initialize_threshold() { |
ysr@777 | 961 | return _offsets.initialize_threshold(); |
ysr@777 | 962 | } |
ysr@777 | 963 | |
ysr@777 | 964 | HeapWord* G1OffsetTableContigSpace::cross_threshold(HeapWord* start, |
ysr@777 | 965 | HeapWord* end) { |
ysr@777 | 966 | _offsets.alloc_block(start, end); |
ysr@777 | 967 | return _offsets.threshold(); |
ysr@777 | 968 | } |
ysr@777 | 969 | |
mgerdin@7647 | 970 | HeapWord* G1OffsetTableContigSpace::scan_top() const { |
ysr@777 | 971 | G1CollectedHeap* g1h = G1CollectedHeap::heap(); |
mgerdin@7366 | 972 | HeapWord* local_top = top(); |
mgerdin@7366 | 973 | OrderAccess::loadload(); |
mgerdin@7647 | 974 | const unsigned local_time_stamp = _gc_time_stamp; |
mgerdin@7647 | 975 | assert(local_time_stamp <= g1h->get_gc_time_stamp(), "invariant"); |
mgerdin@7647 | 976 | if (local_time_stamp < g1h->get_gc_time_stamp()) { |
mgerdin@7366 | 977 | return local_top; |
mgerdin@7366 | 978 | } else { |
mgerdin@7647 | 979 | return _scan_top; |
mgerdin@7366 | 980 | } |
ysr@777 | 981 | } |
ysr@777 | 982 | |
mgerdin@7647 | 983 | void G1OffsetTableContigSpace::record_timestamp() { |
ysr@777 | 984 | G1CollectedHeap* g1h = G1CollectedHeap::heap(); |
ysr@777 | 985 | unsigned curr_gc_time_stamp = g1h->get_gc_time_stamp(); |
ysr@777 | 986 | |
ysr@777 | 987 | if (_gc_time_stamp < curr_gc_time_stamp) { |
mgerdin@7647 | 988 | // Setting the time stamp here tells concurrent readers to look at |
mgerdin@7647 | 989 | // scan_top to know the maximum allowed address to look at. |
mgerdin@7647 | 990 | |
mgerdin@7647 | 991 | // scan_top should be bottom for all regions except for the |
mgerdin@7647 | 992 | // retained old alloc region which should have scan_top == top |
mgerdin@7647 | 993 | HeapWord* st = _scan_top; |
mgerdin@7647 | 994 | guarantee(st == _bottom || st == _top, "invariant"); |
mgerdin@7647 | 995 | |
iveresov@788 | 996 | _gc_time_stamp = curr_gc_time_stamp; |
ysr@777 | 997 | } |
ysr@777 | 998 | } |
ysr@777 | 999 | |
mgerdin@7647 | 1000 | void G1OffsetTableContigSpace::record_retained_region() { |
mgerdin@7647 | 1001 | // scan_top is the maximum address where it's safe for the next gc to |
mgerdin@7647 | 1002 | // scan this region. |
mgerdin@7647 | 1003 | _scan_top = top(); |
mgerdin@7647 | 1004 | } |
mgerdin@7647 | 1005 | |
mgerdin@6990 | 1006 | void G1OffsetTableContigSpace::safe_object_iterate(ObjectClosure* blk) { |
mgerdin@6990 | 1007 | object_iterate(blk); |
mgerdin@6990 | 1008 | } |
mgerdin@6990 | 1009 | |
mgerdin@6990 | 1010 | void G1OffsetTableContigSpace::object_iterate(ObjectClosure* blk) { |
mgerdin@6990 | 1011 | HeapWord* p = bottom(); |
mgerdin@6990 | 1012 | while (p < top()) { |
mgerdin@6990 | 1013 | if (block_is_obj(p)) { |
mgerdin@6990 | 1014 | blk->do_object(oop(p)); |
mgerdin@6990 | 1015 | } |
mgerdin@6990 | 1016 | p += block_size(p); |
mgerdin@6990 | 1017 | } |
mgerdin@6990 | 1018 | } |
mgerdin@6990 | 1019 | |
mgerdin@6990 | 1020 | #define block_is_always_obj(q) true |
mgerdin@6990 | 1021 | void G1OffsetTableContigSpace::prepare_for_compaction(CompactPoint* cp) { |
mgerdin@6990 | 1022 | SCAN_AND_FORWARD(cp, top, block_is_always_obj, block_size); |
mgerdin@6990 | 1023 | } |
mgerdin@6990 | 1024 | #undef block_is_always_obj |
mgerdin@6990 | 1025 | |
ysr@777 | 1026 | G1OffsetTableContigSpace:: |
ysr@777 | 1027 | G1OffsetTableContigSpace(G1BlockOffsetSharedArray* sharedOffsetArray, |
johnc@4065 | 1028 | MemRegion mr) : |
ysr@777 | 1029 | _offsets(sharedOffsetArray, mr), |
ysr@777 | 1030 | _par_alloc_lock(Mutex::leaf, "OffsetTableContigSpace par alloc lock", true), |
ysr@777 | 1031 | _gc_time_stamp(0) |
ysr@777 | 1032 | { |
ysr@777 | 1033 | _offsets.set_space(this); |
tschatzl@7050 | 1034 | } |
tschatzl@7050 | 1035 | |
tschatzl@7050 | 1036 | void G1OffsetTableContigSpace::initialize(MemRegion mr, bool clear_space, bool mangle_space) { |
tschatzl@7050 | 1037 | CompactibleSpace::initialize(mr, clear_space, mangle_space); |
mgerdin@6990 | 1038 | _top = bottom(); |
mgerdin@7647 | 1039 | _scan_top = bottom(); |
mgerdin@7647 | 1040 | set_saved_mark_word(NULL); |
tschatzl@7050 | 1041 | reset_bot(); |
ysr@777 | 1042 | } |
tschatzl@7050 | 1043 |