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

Wed, 11 Apr 2012 16:18:45 +0200

author
stefank
date
Wed, 11 Apr 2012 16:18:45 +0200
changeset 3712
dde53abda3d6
parent 3294
bca17e38de00
child 4037
da91efe96a93
permissions
-rw-r--r--

7160613: VerifyRememberedSets doesn't work with CompressedOops
Summary: use load_decode_heap_oop instead of load_decode_heap_oop_not_null
Reviewed-by: tonyp, brutisso

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

mercurial