src/share/vm/gc_implementation/parallelScavenge/cardTableExtension.cpp

Thu, 21 Oct 2010 11:55:10 -0700

author
never
date
Thu, 21 Oct 2010 11:55:10 -0700
changeset 2262
1e9a9d2e6509
parent 2061
9d7a8ab3736b
child 2314
f95d63e2154a
permissions
-rw-r--r--

6970683: improvements to hs_err output
Reviewed-by: kvn, jrose, dholmes, coleenp

duke@435 1 /*
jmasa@1967 2 * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 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.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 # include "incls/_precompiled.incl"
duke@435 26 # include "incls/_cardTableExtension.cpp.incl"
duke@435 27
duke@435 28 // Checks an individual oop for missing precise marks. Mark
duke@435 29 // may be either dirty or newgen.
duke@435 30 class CheckForUnmarkedOops : public OopClosure {
coleenp@548 31 private:
coleenp@548 32 PSYoungGen* _young_gen;
duke@435 33 CardTableExtension* _card_table;
coleenp@548 34 HeapWord* _unmarked_addr;
coleenp@548 35 jbyte* _unmarked_card;
duke@435 36
coleenp@548 37 protected:
coleenp@548 38 template <class T> void do_oop_work(T* p) {
coleenp@548 39 oop obj = oopDesc::load_decode_heap_oop_not_null(p);
coleenp@548 40 if (_young_gen->is_in_reserved(obj) &&
duke@435 41 !_card_table->addr_is_marked_imprecise(p)) {
duke@435 42 // Don't overwrite the first missing card mark
duke@435 43 if (_unmarked_addr == NULL) {
duke@435 44 _unmarked_addr = (HeapWord*)p;
duke@435 45 _unmarked_card = _card_table->byte_for(p);
duke@435 46 }
duke@435 47 }
duke@435 48 }
duke@435 49
coleenp@548 50 public:
coleenp@548 51 CheckForUnmarkedOops(PSYoungGen* young_gen, CardTableExtension* card_table) :
coleenp@548 52 _young_gen(young_gen), _card_table(card_table), _unmarked_addr(NULL) { }
coleenp@548 53
coleenp@548 54 virtual void do_oop(oop* p) { CheckForUnmarkedOops::do_oop_work(p); }
coleenp@548 55 virtual void do_oop(narrowOop* p) { CheckForUnmarkedOops::do_oop_work(p); }
coleenp@548 56
duke@435 57 bool has_unmarked_oop() {
duke@435 58 return _unmarked_addr != NULL;
duke@435 59 }
duke@435 60 };
duke@435 61
duke@435 62 // Checks all objects for the existance of some type of mark,
duke@435 63 // precise or imprecise, dirty or newgen.
duke@435 64 class CheckForUnmarkedObjects : public ObjectClosure {
coleenp@548 65 private:
coleenp@548 66 PSYoungGen* _young_gen;
duke@435 67 CardTableExtension* _card_table;
duke@435 68
duke@435 69 public:
duke@435 70 CheckForUnmarkedObjects() {
duke@435 71 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
duke@435 72 assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
duke@435 73
duke@435 74 _young_gen = heap->young_gen();
duke@435 75 _card_table = (CardTableExtension*)heap->barrier_set();
duke@435 76 // No point in asserting barrier set type here. Need to make CardTableExtension
duke@435 77 // a unique barrier set type.
duke@435 78 }
duke@435 79
duke@435 80 // Card marks are not precise. The current system can leave us with
twisti@1040 81 // a mismash of precise marks and beginning of object marks. This means
duke@435 82 // we test for missing precise marks first. If any are found, we don't
duke@435 83 // fail unless the object head is also unmarked.
duke@435 84 virtual void do_object(oop obj) {
coleenp@548 85 CheckForUnmarkedOops object_check(_young_gen, _card_table);
duke@435 86 obj->oop_iterate(&object_check);
duke@435 87 if (object_check.has_unmarked_oop()) {
duke@435 88 assert(_card_table->addr_is_marked_imprecise(obj), "Found unmarked young_gen object");
duke@435 89 }
duke@435 90 }
duke@435 91 };
duke@435 92
duke@435 93 // Checks for precise marking of oops as newgen.
duke@435 94 class CheckForPreciseMarks : public OopClosure {
coleenp@548 95 private:
coleenp@548 96 PSYoungGen* _young_gen;
duke@435 97 CardTableExtension* _card_table;
duke@435 98
coleenp@548 99 protected:
coleenp@548 100 template <class T> void do_oop_work(T* p) {
coleenp@548 101 oop obj = oopDesc::load_decode_heap_oop_not_null(p);
coleenp@548 102 if (_young_gen->is_in_reserved(obj)) {
coleenp@548 103 assert(_card_table->addr_is_marked_precise(p), "Found unmarked precise oop");
coleenp@548 104 _card_table->set_card_newgen(p);
coleenp@548 105 }
coleenp@548 106 }
coleenp@548 107
duke@435 108 public:
duke@435 109 CheckForPreciseMarks( PSYoungGen* young_gen, CardTableExtension* card_table ) :
duke@435 110 _young_gen(young_gen), _card_table(card_table) { }
duke@435 111
coleenp@548 112 virtual void do_oop(oop* p) { CheckForPreciseMarks::do_oop_work(p); }
coleenp@548 113 virtual void do_oop(narrowOop* p) { CheckForPreciseMarks::do_oop_work(p); }
duke@435 114 };
duke@435 115
duke@435 116 // We get passed the space_top value to prevent us from traversing into
duke@435 117 // the old_gen promotion labs, which cannot be safely parsed.
duke@435 118 void CardTableExtension::scavenge_contents(ObjectStartArray* start_array,
duke@435 119 MutableSpace* sp,
duke@435 120 HeapWord* space_top,
duke@435 121 PSPromotionManager* pm)
duke@435 122 {
duke@435 123 assert(start_array != NULL && sp != NULL && pm != NULL, "Sanity");
duke@435 124 assert(start_array->covered_region().contains(sp->used_region()),
duke@435 125 "ObjectStartArray does not cover space");
duke@435 126
duke@435 127 if (sp->not_empty()) {
duke@435 128 oop* sp_top = (oop*)space_top;
duke@435 129 oop* prev_top = NULL;
duke@435 130 jbyte* current_card = byte_for(sp->bottom());
duke@435 131 jbyte* end_card = byte_for(sp_top - 1); // sp_top is exclusive
duke@435 132 // scan card marking array
duke@435 133 while (current_card <= end_card) {
duke@435 134 jbyte value = *current_card;
duke@435 135 // skip clean cards
duke@435 136 if (card_is_clean(value)) {
duke@435 137 current_card++;
duke@435 138 } else {
duke@435 139 // we found a non-clean card
duke@435 140 jbyte* first_nonclean_card = current_card++;
duke@435 141 oop* bottom = (oop*)addr_for(first_nonclean_card);
duke@435 142 // find object starting on card
duke@435 143 oop* bottom_obj = (oop*)start_array->object_start((HeapWord*)bottom);
duke@435 144 // bottom_obj = (oop*)start_array->object_start((HeapWord*)bottom);
duke@435 145 assert(bottom_obj <= bottom, "just checking");
duke@435 146 // make sure we don't scan oops we already looked at
duke@435 147 if (bottom < prev_top) bottom = prev_top;
duke@435 148 // figure out when to stop scanning
duke@435 149 jbyte* first_clean_card;
duke@435 150 oop* top;
duke@435 151 bool restart_scanning;
duke@435 152 do {
duke@435 153 restart_scanning = false;
duke@435 154 // find a clean card
duke@435 155 while (current_card <= end_card) {
duke@435 156 value = *current_card;
duke@435 157 if (card_is_clean(value)) break;
duke@435 158 current_card++;
duke@435 159 }
duke@435 160 // check if we reached the end, if so we are done
duke@435 161 if (current_card >= end_card) {
duke@435 162 first_clean_card = end_card + 1;
duke@435 163 current_card++;
duke@435 164 top = sp_top;
duke@435 165 } else {
duke@435 166 // we have a clean card, find object starting on that card
duke@435 167 first_clean_card = current_card++;
duke@435 168 top = (oop*)addr_for(first_clean_card);
duke@435 169 oop* top_obj = (oop*)start_array->object_start((HeapWord*)top);
duke@435 170 // top_obj = (oop*)start_array->object_start((HeapWord*)top);
duke@435 171 assert(top_obj <= top, "just checking");
duke@435 172 if (oop(top_obj)->is_objArray() || oop(top_obj)->is_typeArray()) {
duke@435 173 // an arrayOop is starting on the clean card - since we do exact store
duke@435 174 // checks for objArrays we are done
duke@435 175 } else {
duke@435 176 // otherwise, it is possible that the object starting on the clean card
duke@435 177 // spans the entire card, and that the store happened on a later card.
duke@435 178 // figure out where the object ends
duke@435 179 top = top_obj + oop(top_obj)->size();
duke@435 180 jbyte* top_card = CardTableModRefBS::byte_for(top - 1); // top is exclusive
duke@435 181 if (top_card > first_clean_card) {
duke@435 182 // object ends a different card
duke@435 183 current_card = top_card + 1;
duke@435 184 if (card_is_clean(*top_card)) {
duke@435 185 // the ending card is clean, we are done
duke@435 186 first_clean_card = top_card;
duke@435 187 } else {
duke@435 188 // the ending card is not clean, continue scanning at start of do-while
duke@435 189 restart_scanning = true;
duke@435 190 }
duke@435 191 } else {
duke@435 192 // object ends on the clean card, we are done.
duke@435 193 assert(first_clean_card == top_card, "just checking");
duke@435 194 }
duke@435 195 }
duke@435 196 }
duke@435 197 } while (restart_scanning);
duke@435 198 // we know which cards to scan, now clear them
duke@435 199 while (first_nonclean_card < first_clean_card) {
duke@435 200 *first_nonclean_card++ = clean_card;
duke@435 201 }
duke@435 202 // scan oops in objects
tonyp@2061 203 do {
tonyp@2061 204 oop(bottom_obj)->push_contents(pm);
tonyp@2061 205 bottom_obj += oop(bottom_obj)->size();
tonyp@2061 206 assert(bottom_obj <= sp_top, "just checking");
tonyp@2061 207 } while (bottom_obj < top);
tonyp@2061 208 pm->drain_stacks_cond_depth();
duke@435 209 // remember top oop* scanned
duke@435 210 prev_top = top;
duke@435 211 }
duke@435 212 }
duke@435 213 }
duke@435 214 }
duke@435 215
duke@435 216 void CardTableExtension::scavenge_contents_parallel(ObjectStartArray* start_array,
duke@435 217 MutableSpace* sp,
duke@435 218 HeapWord* space_top,
duke@435 219 PSPromotionManager* pm,
duke@435 220 uint stripe_number) {
duke@435 221 int ssize = 128; // Naked constant! Work unit = 64k.
duke@435 222 int dirty_card_count = 0;
duke@435 223
duke@435 224 oop* sp_top = (oop*)space_top;
duke@435 225 jbyte* start_card = byte_for(sp->bottom());
duke@435 226 jbyte* end_card = byte_for(sp_top - 1) + 1;
duke@435 227 oop* last_scanned = NULL; // Prevent scanning objects more than once
duke@435 228 for (jbyte* slice = start_card; slice < end_card; slice += ssize*ParallelGCThreads) {
duke@435 229 jbyte* worker_start_card = slice + stripe_number * ssize;
duke@435 230 if (worker_start_card >= end_card)
duke@435 231 return; // We're done.
duke@435 232
duke@435 233 jbyte* worker_end_card = worker_start_card + ssize;
duke@435 234 if (worker_end_card > end_card)
duke@435 235 worker_end_card = end_card;
duke@435 236
duke@435 237 // We do not want to scan objects more than once. In order to accomplish
duke@435 238 // this, we assert that any object with an object head inside our 'slice'
duke@435 239 // belongs to us. We may need to extend the range of scanned cards if the
duke@435 240 // last object continues into the next 'slice'.
duke@435 241 //
duke@435 242 // Note! ending cards are exclusive!
duke@435 243 HeapWord* slice_start = addr_for(worker_start_card);
duke@435 244 HeapWord* slice_end = MIN2((HeapWord*) sp_top, addr_for(worker_end_card));
duke@435 245
duke@435 246 // If there are not objects starting within the chunk, skip it.
duke@435 247 if (!start_array->object_starts_in_range(slice_start, slice_end)) {
duke@435 248 continue;
duke@435 249 }
twisti@1040 250 // Update our beginning addr
duke@435 251 HeapWord* first_object = start_array->object_start(slice_start);
duke@435 252 debug_only(oop* first_object_within_slice = (oop*) first_object;)
duke@435 253 if (first_object < slice_start) {
duke@435 254 last_scanned = (oop*)(first_object + oop(first_object)->size());
duke@435 255 debug_only(first_object_within_slice = last_scanned;)
duke@435 256 worker_start_card = byte_for(last_scanned);
duke@435 257 }
duke@435 258
duke@435 259 // Update the ending addr
duke@435 260 if (slice_end < (HeapWord*)sp_top) {
duke@435 261 // The subtraction is important! An object may start precisely at slice_end.
duke@435 262 HeapWord* last_object = start_array->object_start(slice_end - 1);
duke@435 263 slice_end = last_object + oop(last_object)->size();
duke@435 264 // worker_end_card is exclusive, so bump it one past the end of last_object's
duke@435 265 // covered span.
duke@435 266 worker_end_card = byte_for(slice_end) + 1;
duke@435 267
duke@435 268 if (worker_end_card > end_card)
duke@435 269 worker_end_card = end_card;
duke@435 270 }
duke@435 271
duke@435 272 assert(slice_end <= (HeapWord*)sp_top, "Last object in slice crosses space boundary");
duke@435 273 assert(is_valid_card_address(worker_start_card), "Invalid worker start card");
duke@435 274 assert(is_valid_card_address(worker_end_card), "Invalid worker end card");
duke@435 275 // Note that worker_start_card >= worker_end_card is legal, and happens when
duke@435 276 // an object spans an entire slice.
duke@435 277 assert(worker_start_card <= end_card, "worker start card beyond end card");
duke@435 278 assert(worker_end_card <= end_card, "worker end card beyond end card");
duke@435 279
duke@435 280 jbyte* current_card = worker_start_card;
duke@435 281 while (current_card < worker_end_card) {
duke@435 282 // Find an unclean card.
duke@435 283 while (current_card < worker_end_card && card_is_clean(*current_card)) {
duke@435 284 current_card++;
duke@435 285 }
duke@435 286 jbyte* first_unclean_card = current_card;
duke@435 287
duke@435 288 // Find the end of a run of contiguous unclean cards
duke@435 289 while (current_card < worker_end_card && !card_is_clean(*current_card)) {
duke@435 290 while (current_card < worker_end_card && !card_is_clean(*current_card)) {
duke@435 291 current_card++;
duke@435 292 }
duke@435 293
duke@435 294 if (current_card < worker_end_card) {
duke@435 295 // Some objects may be large enough to span several cards. If such
duke@435 296 // an object has more than one dirty card, separated by a clean card,
duke@435 297 // we will attempt to scan it twice. The test against "last_scanned"
duke@435 298 // prevents the redundant object scan, but it does not prevent newly
duke@435 299 // marked cards from being cleaned.
duke@435 300 HeapWord* last_object_in_dirty_region = start_array->object_start(addr_for(current_card)-1);
duke@435 301 size_t size_of_last_object = oop(last_object_in_dirty_region)->size();
duke@435 302 HeapWord* end_of_last_object = last_object_in_dirty_region + size_of_last_object;
duke@435 303 jbyte* ending_card_of_last_object = byte_for(end_of_last_object);
duke@435 304 assert(ending_card_of_last_object <= worker_end_card, "ending_card_of_last_object is greater than worker_end_card");
duke@435 305 if (ending_card_of_last_object > current_card) {
duke@435 306 // This means the object spans the next complete card.
duke@435 307 // We need to bump the current_card to ending_card_of_last_object
duke@435 308 current_card = ending_card_of_last_object;
duke@435 309 }
duke@435 310 }
duke@435 311 }
duke@435 312 jbyte* following_clean_card = current_card;
duke@435 313
duke@435 314 if (first_unclean_card < worker_end_card) {
duke@435 315 oop* p = (oop*) start_array->object_start(addr_for(first_unclean_card));
duke@435 316 assert((HeapWord*)p <= addr_for(first_unclean_card), "checking");
duke@435 317 // "p" should always be >= "last_scanned" because newly GC dirtied
duke@435 318 // cards are no longer scanned again (see comment at end
duke@435 319 // of loop on the increment of "current_card"). Test that
duke@435 320 // hypothesis before removing this code.
duke@435 321 // If this code is removed, deal with the first time through
duke@435 322 // the loop when the last_scanned is the object starting in
duke@435 323 // the previous slice.
duke@435 324 assert((p >= last_scanned) ||
duke@435 325 (last_scanned == first_object_within_slice),
duke@435 326 "Should no longer be possible");
duke@435 327 if (p < last_scanned) {
duke@435 328 // Avoid scanning more than once; this can happen because
duke@435 329 // newgen cards set by GC may a different set than the
duke@435 330 // originally dirty set
duke@435 331 p = last_scanned;
duke@435 332 }
duke@435 333 oop* to = (oop*)addr_for(following_clean_card);
duke@435 334
duke@435 335 // Test slice_end first!
duke@435 336 if ((HeapWord*)to > slice_end) {
duke@435 337 to = (oop*)slice_end;
duke@435 338 } else if (to > sp_top) {
duke@435 339 to = sp_top;
duke@435 340 }
duke@435 341
duke@435 342 // we know which cards to scan, now clear them
duke@435 343 if (first_unclean_card <= worker_start_card+1)
duke@435 344 first_unclean_card = worker_start_card+1;
duke@435 345 if (following_clean_card >= worker_end_card-1)
duke@435 346 following_clean_card = worker_end_card-1;
duke@435 347
duke@435 348 while (first_unclean_card < following_clean_card) {
duke@435 349 *first_unclean_card++ = clean_card;
duke@435 350 }
duke@435 351
duke@435 352 const int interval = PrefetchScanIntervalInBytes;
duke@435 353 // scan all objects in the range
duke@435 354 if (interval != 0) {
tonyp@2061 355 while (p < to) {
tonyp@2061 356 Prefetch::write(p, interval);
tonyp@2061 357 oop m = oop(p);
tonyp@2061 358 assert(m->is_oop_or_null(), "check for header");
tonyp@2061 359 m->push_contents(pm);
tonyp@2061 360 p += m->size();
duke@435 361 }
tonyp@2061 362 pm->drain_stacks_cond_depth();
duke@435 363 } else {
tonyp@2061 364 while (p < to) {
tonyp@2061 365 oop m = oop(p);
tonyp@2061 366 assert(m->is_oop_or_null(), "check for header");
tonyp@2061 367 m->push_contents(pm);
tonyp@2061 368 p += m->size();
duke@435 369 }
tonyp@2061 370 pm->drain_stacks_cond_depth();
duke@435 371 }
duke@435 372 last_scanned = p;
duke@435 373 }
duke@435 374 // "current_card" is still the "following_clean_card" or
duke@435 375 // the current_card is >= the worker_end_card so the
duke@435 376 // loop will not execute again.
duke@435 377 assert((current_card == following_clean_card) ||
duke@435 378 (current_card >= worker_end_card),
duke@435 379 "current_card should only be incremented if it still equals "
duke@435 380 "following_clean_card");
duke@435 381 // Increment current_card so that it is not processed again.
duke@435 382 // It may now be dirty because a old-to-young pointer was
duke@435 383 // found on it an updated. If it is now dirty, it cannot be
duke@435 384 // be safely cleaned in the next iteration.
duke@435 385 current_card++;
duke@435 386 }
duke@435 387 }
duke@435 388 }
duke@435 389
duke@435 390 // This should be called before a scavenge.
duke@435 391 void CardTableExtension::verify_all_young_refs_imprecise() {
duke@435 392 CheckForUnmarkedObjects check;
duke@435 393
duke@435 394 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
duke@435 395 assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
duke@435 396
duke@435 397 PSOldGen* old_gen = heap->old_gen();
duke@435 398 PSPermGen* perm_gen = heap->perm_gen();
duke@435 399
duke@435 400 old_gen->object_iterate(&check);
duke@435 401 perm_gen->object_iterate(&check);
duke@435 402 }
duke@435 403
duke@435 404 // This should be called immediately after a scavenge, before mutators resume.
duke@435 405 void CardTableExtension::verify_all_young_refs_precise() {
duke@435 406 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
duke@435 407 assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
duke@435 408
duke@435 409 PSOldGen* old_gen = heap->old_gen();
duke@435 410 PSPermGen* perm_gen = heap->perm_gen();
duke@435 411
duke@435 412 CheckForPreciseMarks check(heap->young_gen(), (CardTableExtension*)heap->barrier_set());
duke@435 413
duke@435 414 old_gen->oop_iterate(&check);
duke@435 415 perm_gen->oop_iterate(&check);
duke@435 416
duke@435 417 verify_all_young_refs_precise_helper(old_gen->object_space()->used_region());
duke@435 418 verify_all_young_refs_precise_helper(perm_gen->object_space()->used_region());
duke@435 419 }
duke@435 420
duke@435 421 void CardTableExtension::verify_all_young_refs_precise_helper(MemRegion mr) {
duke@435 422 CardTableExtension* card_table = (CardTableExtension*)Universe::heap()->barrier_set();
duke@435 423 // FIX ME ASSERT HERE
duke@435 424
duke@435 425 jbyte* bot = card_table->byte_for(mr.start());
duke@435 426 jbyte* top = card_table->byte_for(mr.end());
duke@435 427 while(bot <= top) {
duke@435 428 assert(*bot == clean_card || *bot == verify_card, "Found unwanted or unknown card mark");
duke@435 429 if (*bot == verify_card)
duke@435 430 *bot = youngergen_card;
duke@435 431 bot++;
duke@435 432 }
duke@435 433 }
duke@435 434
duke@435 435 bool CardTableExtension::addr_is_marked_imprecise(void *addr) {
duke@435 436 jbyte* p = byte_for(addr);
duke@435 437 jbyte val = *p;
duke@435 438
duke@435 439 if (card_is_dirty(val))
duke@435 440 return true;
duke@435 441
duke@435 442 if (card_is_newgen(val))
duke@435 443 return true;
duke@435 444
duke@435 445 if (card_is_clean(val))
duke@435 446 return false;
duke@435 447
duke@435 448 assert(false, "Found unhandled card mark type");
duke@435 449
duke@435 450 return false;
duke@435 451 }
duke@435 452
duke@435 453 // Also includes verify_card
duke@435 454 bool CardTableExtension::addr_is_marked_precise(void *addr) {
duke@435 455 jbyte* p = byte_for(addr);
duke@435 456 jbyte val = *p;
duke@435 457
duke@435 458 if (card_is_newgen(val))
duke@435 459 return true;
duke@435 460
duke@435 461 if (card_is_verify(val))
duke@435 462 return true;
duke@435 463
duke@435 464 if (card_is_clean(val))
duke@435 465 return false;
duke@435 466
duke@435 467 if (card_is_dirty(val))
duke@435 468 return false;
duke@435 469
duke@435 470 assert(false, "Found unhandled card mark type");
duke@435 471
duke@435 472 return false;
duke@435 473 }
duke@435 474
duke@435 475 // Assumes that only the base or the end changes. This allows indentification
duke@435 476 // of the region that is being resized. The
duke@435 477 // CardTableModRefBS::resize_covered_region() is used for the normal case
duke@435 478 // where the covered regions are growing or shrinking at the high end.
duke@435 479 // The method resize_covered_region_by_end() is analogous to
duke@435 480 // CardTableModRefBS::resize_covered_region() but
duke@435 481 // for regions that grow or shrink at the low end.
duke@435 482 void CardTableExtension::resize_covered_region(MemRegion new_region) {
duke@435 483
duke@435 484 for (int i = 0; i < _cur_covered_regions; i++) {
duke@435 485 if (_covered[i].start() == new_region.start()) {
duke@435 486 // Found a covered region with the same start as the
duke@435 487 // new region. The region is growing or shrinking
duke@435 488 // from the start of the region.
duke@435 489 resize_covered_region_by_start(new_region);
duke@435 490 return;
duke@435 491 }
duke@435 492 if (_covered[i].start() > new_region.start()) {
duke@435 493 break;
duke@435 494 }
duke@435 495 }
duke@435 496
duke@435 497 int changed_region = -1;
duke@435 498 for (int j = 0; j < _cur_covered_regions; j++) {
duke@435 499 if (_covered[j].end() == new_region.end()) {
duke@435 500 changed_region = j;
duke@435 501 // This is a case where the covered region is growing or shrinking
duke@435 502 // at the start of the region.
duke@435 503 assert(changed_region != -1, "Don't expect to add a covered region");
duke@435 504 assert(_covered[changed_region].byte_size() != new_region.byte_size(),
duke@435 505 "The sizes should be different here");
duke@435 506 resize_covered_region_by_end(changed_region, new_region);
duke@435 507 return;
duke@435 508 }
duke@435 509 }
duke@435 510 // This should only be a new covered region (where no existing
duke@435 511 // covered region matches at the start or the end).
duke@435 512 assert(_cur_covered_regions < _max_covered_regions,
duke@435 513 "An existing region should have been found");
duke@435 514 resize_covered_region_by_start(new_region);
duke@435 515 }
duke@435 516
duke@435 517 void CardTableExtension::resize_covered_region_by_start(MemRegion new_region) {
duke@435 518 CardTableModRefBS::resize_covered_region(new_region);
duke@435 519 debug_only(verify_guard();)
duke@435 520 }
duke@435 521
duke@435 522 void CardTableExtension::resize_covered_region_by_end(int changed_region,
duke@435 523 MemRegion new_region) {
duke@435 524 assert(SafepointSynchronize::is_at_safepoint(),
duke@435 525 "Only expect an expansion at the low end at a GC");
duke@435 526 debug_only(verify_guard();)
duke@435 527 #ifdef ASSERT
duke@435 528 for (int k = 0; k < _cur_covered_regions; k++) {
duke@435 529 if (_covered[k].end() == new_region.end()) {
duke@435 530 assert(changed_region == k, "Changed region is incorrect");
duke@435 531 break;
duke@435 532 }
duke@435 533 }
duke@435 534 #endif
duke@435 535
duke@435 536 // Commit new or uncommit old pages, if necessary.
jmasa@1967 537 if (resize_commit_uncommit(changed_region, new_region)) {
jmasa@1967 538 // Set the new start of the committed region
jmasa@1967 539 resize_update_committed_table(changed_region, new_region);
jmasa@1967 540 }
duke@435 541
duke@435 542 // Update card table entries
duke@435 543 resize_update_card_table_entries(changed_region, new_region);
duke@435 544
duke@435 545 // Update the covered region
duke@435 546 resize_update_covered_table(changed_region, new_region);
duke@435 547
duke@435 548 if (TraceCardTableModRefBS) {
duke@435 549 int ind = changed_region;
duke@435 550 gclog_or_tty->print_cr("CardTableModRefBS::resize_covered_region: ");
duke@435 551 gclog_or_tty->print_cr(" "
duke@435 552 " _covered[%d].start(): " INTPTR_FORMAT
duke@435 553 " _covered[%d].last(): " INTPTR_FORMAT,
duke@435 554 ind, _covered[ind].start(),
duke@435 555 ind, _covered[ind].last());
duke@435 556 gclog_or_tty->print_cr(" "
duke@435 557 " _committed[%d].start(): " INTPTR_FORMAT
duke@435 558 " _committed[%d].last(): " INTPTR_FORMAT,
duke@435 559 ind, _committed[ind].start(),
duke@435 560 ind, _committed[ind].last());
duke@435 561 gclog_or_tty->print_cr(" "
duke@435 562 " byte_for(start): " INTPTR_FORMAT
duke@435 563 " byte_for(last): " INTPTR_FORMAT,
duke@435 564 byte_for(_covered[ind].start()),
duke@435 565 byte_for(_covered[ind].last()));
duke@435 566 gclog_or_tty->print_cr(" "
duke@435 567 " addr_for(start): " INTPTR_FORMAT
duke@435 568 " addr_for(last): " INTPTR_FORMAT,
duke@435 569 addr_for((jbyte*) _committed[ind].start()),
duke@435 570 addr_for((jbyte*) _committed[ind].last()));
duke@435 571 }
duke@435 572 debug_only(verify_guard();)
duke@435 573 }
duke@435 574
jmasa@1967 575 bool CardTableExtension::resize_commit_uncommit(int changed_region,
duke@435 576 MemRegion new_region) {
jmasa@1967 577 bool result = false;
duke@435 578 // Commit new or uncommit old pages, if necessary.
duke@435 579 MemRegion cur_committed = _committed[changed_region];
duke@435 580 assert(_covered[changed_region].end() == new_region.end(),
duke@435 581 "The ends of the regions are expected to match");
duke@435 582 // Extend the start of this _committed region to
duke@435 583 // to cover the start of any previous _committed region.
duke@435 584 // This forms overlapping regions, but never interior regions.
duke@435 585 HeapWord* min_prev_start = lowest_prev_committed_start(changed_region);
duke@435 586 if (min_prev_start < cur_committed.start()) {
duke@435 587 // Only really need to set start of "cur_committed" to
duke@435 588 // the new start (min_prev_start) but assertion checking code
duke@435 589 // below use cur_committed.end() so make it correct.
duke@435 590 MemRegion new_committed =
duke@435 591 MemRegion(min_prev_start, cur_committed.end());
duke@435 592 cur_committed = new_committed;
duke@435 593 }
duke@435 594 #ifdef ASSERT
duke@435 595 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
duke@435 596 assert(cur_committed.start() ==
duke@435 597 (HeapWord*) align_size_up((uintptr_t) cur_committed.start(),
duke@435 598 os::vm_page_size()),
duke@435 599 "Starts should have proper alignment");
duke@435 600 #endif
duke@435 601
duke@435 602 jbyte* new_start = byte_for(new_region.start());
duke@435 603 // Round down because this is for the start address
duke@435 604 HeapWord* new_start_aligned =
duke@435 605 (HeapWord*)align_size_down((uintptr_t)new_start, os::vm_page_size());
duke@435 606 // The guard page is always committed and should not be committed over.
duke@435 607 // This method is used in cases where the generation is growing toward
duke@435 608 // lower addresses but the guard region is still at the end of the
duke@435 609 // card table. That still makes sense when looking for writes
duke@435 610 // off the end of the card table.
duke@435 611 if (new_start_aligned < cur_committed.start()) {
duke@435 612 // Expand the committed region
duke@435 613 //
duke@435 614 // Case A
duke@435 615 // |+ guard +|
duke@435 616 // |+ cur committed +++++++++|
duke@435 617 // |+ new committed +++++++++++++++++|
duke@435 618 //
duke@435 619 // Case B
duke@435 620 // |+ guard +|
duke@435 621 // |+ cur committed +|
duke@435 622 // |+ new committed +++++++|
duke@435 623 //
duke@435 624 // These are not expected because the calculation of the
duke@435 625 // cur committed region and the new committed region
duke@435 626 // share the same end for the covered region.
duke@435 627 // Case C
duke@435 628 // |+ guard +|
duke@435 629 // |+ cur committed +|
duke@435 630 // |+ new committed +++++++++++++++++|
duke@435 631 // Case D
duke@435 632 // |+ guard +|
duke@435 633 // |+ cur committed +++++++++++|
duke@435 634 // |+ new committed +++++++|
duke@435 635
duke@435 636 HeapWord* new_end_for_commit =
duke@435 637 MIN2(cur_committed.end(), _guard_region.start());
jmasa@698 638 if(new_start_aligned < new_end_for_commit) {
jmasa@698 639 MemRegion new_committed =
jmasa@698 640 MemRegion(new_start_aligned, new_end_for_commit);
duke@435 641 if (!os::commit_memory((char*)new_committed.start(),
duke@435 642 new_committed.byte_size())) {
duke@435 643 vm_exit_out_of_memory(new_committed.byte_size(),
duke@435 644 "card table expansion");
duke@435 645 }
duke@435 646 }
jmasa@1967 647 result = true;
duke@435 648 } else if (new_start_aligned > cur_committed.start()) {
duke@435 649 // Shrink the committed region
jmasa@1967 650 #if 0 // uncommitting space is currently unsafe because of the interactions
jmasa@1967 651 // of growing and shrinking regions. One region A can uncommit space
jmasa@1967 652 // that it owns but which is being used by another region B (maybe).
jmasa@1967 653 // Region B has not committed the space because it was already
jmasa@1967 654 // committed by region A.
duke@435 655 MemRegion uncommit_region = committed_unique_to_self(changed_region,
duke@435 656 MemRegion(cur_committed.start(), new_start_aligned));
duke@435 657 if (!uncommit_region.is_empty()) {
duke@435 658 if (!os::uncommit_memory((char*)uncommit_region.start(),
duke@435 659 uncommit_region.byte_size())) {
jmasa@1967 660 // If the uncommit fails, ignore it. Let the
jmasa@1967 661 // committed table resizing go even though the committed
jmasa@1967 662 // table will over state the committed space.
duke@435 663 }
duke@435 664 }
jmasa@1967 665 #else
jmasa@1967 666 assert(!result, "Should be false with current workaround");
jmasa@1967 667 #endif
duke@435 668 }
duke@435 669 assert(_committed[changed_region].end() == cur_committed.end(),
duke@435 670 "end should not change");
jmasa@1967 671 return result;
duke@435 672 }
duke@435 673
duke@435 674 void CardTableExtension::resize_update_committed_table(int changed_region,
duke@435 675 MemRegion new_region) {
duke@435 676
duke@435 677 jbyte* new_start = byte_for(new_region.start());
duke@435 678 // Set the new start of the committed region
duke@435 679 HeapWord* new_start_aligned =
duke@435 680 (HeapWord*)align_size_down((uintptr_t)new_start,
duke@435 681 os::vm_page_size());
duke@435 682 MemRegion new_committed = MemRegion(new_start_aligned,
duke@435 683 _committed[changed_region].end());
duke@435 684 _committed[changed_region] = new_committed;
duke@435 685 _committed[changed_region].set_start(new_start_aligned);
duke@435 686 }
duke@435 687
duke@435 688 void CardTableExtension::resize_update_card_table_entries(int changed_region,
duke@435 689 MemRegion new_region) {
duke@435 690 debug_only(verify_guard();)
duke@435 691 MemRegion original_covered = _covered[changed_region];
duke@435 692 // Initialize the card entries. Only consider the
duke@435 693 // region covered by the card table (_whole_heap)
duke@435 694 jbyte* entry;
duke@435 695 if (new_region.start() < _whole_heap.start()) {
duke@435 696 entry = byte_for(_whole_heap.start());
duke@435 697 } else {
duke@435 698 entry = byte_for(new_region.start());
duke@435 699 }
duke@435 700 jbyte* end = byte_for(original_covered.start());
duke@435 701 // If _whole_heap starts at the original covered regions start,
duke@435 702 // this loop will not execute.
duke@435 703 while (entry < end) { *entry++ = clean_card; }
duke@435 704 }
duke@435 705
duke@435 706 void CardTableExtension::resize_update_covered_table(int changed_region,
duke@435 707 MemRegion new_region) {
duke@435 708 // Update the covered region
duke@435 709 _covered[changed_region].set_start(new_region.start());
duke@435 710 _covered[changed_region].set_word_size(new_region.word_size());
duke@435 711
duke@435 712 // reorder regions. There should only be at most 1 out
duke@435 713 // of order.
duke@435 714 for (int i = _cur_covered_regions-1 ; i > 0; i--) {
duke@435 715 if (_covered[i].start() < _covered[i-1].start()) {
duke@435 716 MemRegion covered_mr = _covered[i-1];
duke@435 717 _covered[i-1] = _covered[i];
duke@435 718 _covered[i] = covered_mr;
duke@435 719 MemRegion committed_mr = _committed[i-1];
duke@435 720 _committed[i-1] = _committed[i];
duke@435 721 _committed[i] = committed_mr;
duke@435 722 break;
duke@435 723 }
duke@435 724 }
duke@435 725 #ifdef ASSERT
duke@435 726 for (int m = 0; m < _cur_covered_regions-1; m++) {
duke@435 727 assert(_covered[m].start() <= _covered[m+1].start(),
duke@435 728 "Covered regions out of order");
duke@435 729 assert(_committed[m].start() <= _committed[m+1].start(),
duke@435 730 "Committed regions out of order");
duke@435 731 }
duke@435 732 #endif
duke@435 733 }
duke@435 734
duke@435 735 // Returns the start of any committed region that is lower than
duke@435 736 // the target committed region (index ind) and that intersects the
duke@435 737 // target region. If none, return start of target region.
duke@435 738 //
duke@435 739 // -------------
duke@435 740 // | |
duke@435 741 // -------------
duke@435 742 // ------------
duke@435 743 // | target |
duke@435 744 // ------------
duke@435 745 // -------------
duke@435 746 // | |
duke@435 747 // -------------
duke@435 748 // ^ returns this
duke@435 749 //
duke@435 750 // -------------
duke@435 751 // | |
duke@435 752 // -------------
duke@435 753 // ------------
duke@435 754 // | target |
duke@435 755 // ------------
duke@435 756 // -------------
duke@435 757 // | |
duke@435 758 // -------------
duke@435 759 // ^ returns this
duke@435 760
duke@435 761 HeapWord* CardTableExtension::lowest_prev_committed_start(int ind) const {
duke@435 762 assert(_cur_covered_regions >= 0, "Expecting at least on region");
duke@435 763 HeapWord* min_start = _committed[ind].start();
duke@435 764 for (int j = 0; j < ind; j++) {
duke@435 765 HeapWord* this_start = _committed[j].start();
duke@435 766 if ((this_start < min_start) &&
duke@435 767 !(_committed[j].intersection(_committed[ind])).is_empty()) {
duke@435 768 min_start = this_start;
duke@435 769 }
duke@435 770 }
duke@435 771 return min_start;
duke@435 772 }

mercurial