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

Fri, 11 Mar 2011 16:35:18 +0100

author
jwilhelm
date
Fri, 11 Mar 2011 16:35:18 +0100
changeset 2648
1fb790245268
parent 2314
f95d63e2154a
child 3294
bca17e38de00
permissions
-rw-r--r--

6820066: Check that -XX:ParGCArrayScanChunk has a value larger than zero.
Summary: Check that -XX:ParGCArrayScanChunk has a value larger than zero.
Reviewed-by: johnc, jmasa, ysr

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) {
coleenp@548 45 oop obj = oopDesc::load_decode_heap_oop_not_null(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,
duke@435 226 uint stripe_number) {
duke@435 227 int ssize = 128; // Naked constant! Work unit = 64k.
duke@435 228 int dirty_card_count = 0;
duke@435 229
duke@435 230 oop* sp_top = (oop*)space_top;
duke@435 231 jbyte* start_card = byte_for(sp->bottom());
duke@435 232 jbyte* end_card = byte_for(sp_top - 1) + 1;
duke@435 233 oop* last_scanned = NULL; // Prevent scanning objects more than once
duke@435 234 for (jbyte* slice = start_card; slice < end_card; slice += ssize*ParallelGCThreads) {
duke@435 235 jbyte* worker_start_card = slice + stripe_number * ssize;
duke@435 236 if (worker_start_card >= end_card)
duke@435 237 return; // We're done.
duke@435 238
duke@435 239 jbyte* worker_end_card = worker_start_card + ssize;
duke@435 240 if (worker_end_card > end_card)
duke@435 241 worker_end_card = end_card;
duke@435 242
duke@435 243 // We do not want to scan objects more than once. In order to accomplish
duke@435 244 // this, we assert that any object with an object head inside our 'slice'
duke@435 245 // belongs to us. We may need to extend the range of scanned cards if the
duke@435 246 // last object continues into the next 'slice'.
duke@435 247 //
duke@435 248 // Note! ending cards are exclusive!
duke@435 249 HeapWord* slice_start = addr_for(worker_start_card);
duke@435 250 HeapWord* slice_end = MIN2((HeapWord*) sp_top, addr_for(worker_end_card));
duke@435 251
duke@435 252 // If there are not objects starting within the chunk, skip it.
duke@435 253 if (!start_array->object_starts_in_range(slice_start, slice_end)) {
duke@435 254 continue;
duke@435 255 }
twisti@1040 256 // Update our beginning addr
duke@435 257 HeapWord* first_object = start_array->object_start(slice_start);
duke@435 258 debug_only(oop* first_object_within_slice = (oop*) first_object;)
duke@435 259 if (first_object < slice_start) {
duke@435 260 last_scanned = (oop*)(first_object + oop(first_object)->size());
duke@435 261 debug_only(first_object_within_slice = last_scanned;)
duke@435 262 worker_start_card = byte_for(last_scanned);
duke@435 263 }
duke@435 264
duke@435 265 // Update the ending addr
duke@435 266 if (slice_end < (HeapWord*)sp_top) {
duke@435 267 // The subtraction is important! An object may start precisely at slice_end.
duke@435 268 HeapWord* last_object = start_array->object_start(slice_end - 1);
duke@435 269 slice_end = last_object + oop(last_object)->size();
duke@435 270 // worker_end_card is exclusive, so bump it one past the end of last_object's
duke@435 271 // covered span.
duke@435 272 worker_end_card = byte_for(slice_end) + 1;
duke@435 273
duke@435 274 if (worker_end_card > end_card)
duke@435 275 worker_end_card = end_card;
duke@435 276 }
duke@435 277
duke@435 278 assert(slice_end <= (HeapWord*)sp_top, "Last object in slice crosses space boundary");
duke@435 279 assert(is_valid_card_address(worker_start_card), "Invalid worker start card");
duke@435 280 assert(is_valid_card_address(worker_end_card), "Invalid worker end card");
duke@435 281 // Note that worker_start_card >= worker_end_card is legal, and happens when
duke@435 282 // an object spans an entire slice.
duke@435 283 assert(worker_start_card <= end_card, "worker start card beyond end card");
duke@435 284 assert(worker_end_card <= end_card, "worker end card beyond end card");
duke@435 285
duke@435 286 jbyte* current_card = worker_start_card;
duke@435 287 while (current_card < worker_end_card) {
duke@435 288 // Find an unclean card.
duke@435 289 while (current_card < worker_end_card && card_is_clean(*current_card)) {
duke@435 290 current_card++;
duke@435 291 }
duke@435 292 jbyte* first_unclean_card = current_card;
duke@435 293
duke@435 294 // Find the end of a run of contiguous unclean cards
duke@435 295 while (current_card < worker_end_card && !card_is_clean(*current_card)) {
duke@435 296 while (current_card < worker_end_card && !card_is_clean(*current_card)) {
duke@435 297 current_card++;
duke@435 298 }
duke@435 299
duke@435 300 if (current_card < worker_end_card) {
duke@435 301 // Some objects may be large enough to span several cards. If such
duke@435 302 // an object has more than one dirty card, separated by a clean card,
duke@435 303 // we will attempt to scan it twice. The test against "last_scanned"
duke@435 304 // prevents the redundant object scan, but it does not prevent newly
duke@435 305 // marked cards from being cleaned.
duke@435 306 HeapWord* last_object_in_dirty_region = start_array->object_start(addr_for(current_card)-1);
duke@435 307 size_t size_of_last_object = oop(last_object_in_dirty_region)->size();
duke@435 308 HeapWord* end_of_last_object = last_object_in_dirty_region + size_of_last_object;
duke@435 309 jbyte* ending_card_of_last_object = byte_for(end_of_last_object);
duke@435 310 assert(ending_card_of_last_object <= worker_end_card, "ending_card_of_last_object is greater than worker_end_card");
duke@435 311 if (ending_card_of_last_object > current_card) {
duke@435 312 // This means the object spans the next complete card.
duke@435 313 // We need to bump the current_card to ending_card_of_last_object
duke@435 314 current_card = ending_card_of_last_object;
duke@435 315 }
duke@435 316 }
duke@435 317 }
duke@435 318 jbyte* following_clean_card = current_card;
duke@435 319
duke@435 320 if (first_unclean_card < worker_end_card) {
duke@435 321 oop* p = (oop*) start_array->object_start(addr_for(first_unclean_card));
duke@435 322 assert((HeapWord*)p <= addr_for(first_unclean_card), "checking");
duke@435 323 // "p" should always be >= "last_scanned" because newly GC dirtied
duke@435 324 // cards are no longer scanned again (see comment at end
duke@435 325 // of loop on the increment of "current_card"). Test that
duke@435 326 // hypothesis before removing this code.
duke@435 327 // If this code is removed, deal with the first time through
duke@435 328 // the loop when the last_scanned is the object starting in
duke@435 329 // the previous slice.
duke@435 330 assert((p >= last_scanned) ||
duke@435 331 (last_scanned == first_object_within_slice),
duke@435 332 "Should no longer be possible");
duke@435 333 if (p < last_scanned) {
duke@435 334 // Avoid scanning more than once; this can happen because
duke@435 335 // newgen cards set by GC may a different set than the
duke@435 336 // originally dirty set
duke@435 337 p = last_scanned;
duke@435 338 }
duke@435 339 oop* to = (oop*)addr_for(following_clean_card);
duke@435 340
duke@435 341 // Test slice_end first!
duke@435 342 if ((HeapWord*)to > slice_end) {
duke@435 343 to = (oop*)slice_end;
duke@435 344 } else if (to > sp_top) {
duke@435 345 to = sp_top;
duke@435 346 }
duke@435 347
duke@435 348 // we know which cards to scan, now clear them
duke@435 349 if (first_unclean_card <= worker_start_card+1)
duke@435 350 first_unclean_card = worker_start_card+1;
duke@435 351 if (following_clean_card >= worker_end_card-1)
duke@435 352 following_clean_card = worker_end_card-1;
duke@435 353
duke@435 354 while (first_unclean_card < following_clean_card) {
duke@435 355 *first_unclean_card++ = clean_card;
duke@435 356 }
duke@435 357
duke@435 358 const int interval = PrefetchScanIntervalInBytes;
duke@435 359 // scan all objects in the range
duke@435 360 if (interval != 0) {
tonyp@2061 361 while (p < to) {
tonyp@2061 362 Prefetch::write(p, interval);
tonyp@2061 363 oop m = oop(p);
tonyp@2061 364 assert(m->is_oop_or_null(), "check for header");
tonyp@2061 365 m->push_contents(pm);
tonyp@2061 366 p += m->size();
duke@435 367 }
tonyp@2061 368 pm->drain_stacks_cond_depth();
duke@435 369 } else {
tonyp@2061 370 while (p < to) {
tonyp@2061 371 oop m = oop(p);
tonyp@2061 372 assert(m->is_oop_or_null(), "check for header");
tonyp@2061 373 m->push_contents(pm);
tonyp@2061 374 p += m->size();
duke@435 375 }
tonyp@2061 376 pm->drain_stacks_cond_depth();
duke@435 377 }
duke@435 378 last_scanned = p;
duke@435 379 }
duke@435 380 // "current_card" is still the "following_clean_card" or
duke@435 381 // the current_card is >= the worker_end_card so the
duke@435 382 // loop will not execute again.
duke@435 383 assert((current_card == following_clean_card) ||
duke@435 384 (current_card >= worker_end_card),
duke@435 385 "current_card should only be incremented if it still equals "
duke@435 386 "following_clean_card");
duke@435 387 // Increment current_card so that it is not processed again.
duke@435 388 // It may now be dirty because a old-to-young pointer was
duke@435 389 // found on it an updated. If it is now dirty, it cannot be
duke@435 390 // be safely cleaned in the next iteration.
duke@435 391 current_card++;
duke@435 392 }
duke@435 393 }
duke@435 394 }
duke@435 395
duke@435 396 // This should be called before a scavenge.
duke@435 397 void CardTableExtension::verify_all_young_refs_imprecise() {
duke@435 398 CheckForUnmarkedObjects check;
duke@435 399
duke@435 400 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
duke@435 401 assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
duke@435 402
duke@435 403 PSOldGen* old_gen = heap->old_gen();
duke@435 404 PSPermGen* perm_gen = heap->perm_gen();
duke@435 405
duke@435 406 old_gen->object_iterate(&check);
duke@435 407 perm_gen->object_iterate(&check);
duke@435 408 }
duke@435 409
duke@435 410 // This should be called immediately after a scavenge, before mutators resume.
duke@435 411 void CardTableExtension::verify_all_young_refs_precise() {
duke@435 412 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
duke@435 413 assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
duke@435 414
duke@435 415 PSOldGen* old_gen = heap->old_gen();
duke@435 416 PSPermGen* perm_gen = heap->perm_gen();
duke@435 417
duke@435 418 CheckForPreciseMarks check(heap->young_gen(), (CardTableExtension*)heap->barrier_set());
duke@435 419
duke@435 420 old_gen->oop_iterate(&check);
duke@435 421 perm_gen->oop_iterate(&check);
duke@435 422
duke@435 423 verify_all_young_refs_precise_helper(old_gen->object_space()->used_region());
duke@435 424 verify_all_young_refs_precise_helper(perm_gen->object_space()->used_region());
duke@435 425 }
duke@435 426
duke@435 427 void CardTableExtension::verify_all_young_refs_precise_helper(MemRegion mr) {
duke@435 428 CardTableExtension* card_table = (CardTableExtension*)Universe::heap()->barrier_set();
duke@435 429 // FIX ME ASSERT HERE
duke@435 430
duke@435 431 jbyte* bot = card_table->byte_for(mr.start());
duke@435 432 jbyte* top = card_table->byte_for(mr.end());
duke@435 433 while(bot <= top) {
duke@435 434 assert(*bot == clean_card || *bot == verify_card, "Found unwanted or unknown card mark");
duke@435 435 if (*bot == verify_card)
duke@435 436 *bot = youngergen_card;
duke@435 437 bot++;
duke@435 438 }
duke@435 439 }
duke@435 440
duke@435 441 bool CardTableExtension::addr_is_marked_imprecise(void *addr) {
duke@435 442 jbyte* p = byte_for(addr);
duke@435 443 jbyte val = *p;
duke@435 444
duke@435 445 if (card_is_dirty(val))
duke@435 446 return true;
duke@435 447
duke@435 448 if (card_is_newgen(val))
duke@435 449 return true;
duke@435 450
duke@435 451 if (card_is_clean(val))
duke@435 452 return false;
duke@435 453
duke@435 454 assert(false, "Found unhandled card mark type");
duke@435 455
duke@435 456 return false;
duke@435 457 }
duke@435 458
duke@435 459 // Also includes verify_card
duke@435 460 bool CardTableExtension::addr_is_marked_precise(void *addr) {
duke@435 461 jbyte* p = byte_for(addr);
duke@435 462 jbyte val = *p;
duke@435 463
duke@435 464 if (card_is_newgen(val))
duke@435 465 return true;
duke@435 466
duke@435 467 if (card_is_verify(val))
duke@435 468 return true;
duke@435 469
duke@435 470 if (card_is_clean(val))
duke@435 471 return false;
duke@435 472
duke@435 473 if (card_is_dirty(val))
duke@435 474 return false;
duke@435 475
duke@435 476 assert(false, "Found unhandled card mark type");
duke@435 477
duke@435 478 return false;
duke@435 479 }
duke@435 480
duke@435 481 // Assumes that only the base or the end changes. This allows indentification
duke@435 482 // of the region that is being resized. The
duke@435 483 // CardTableModRefBS::resize_covered_region() is used for the normal case
duke@435 484 // where the covered regions are growing or shrinking at the high end.
duke@435 485 // The method resize_covered_region_by_end() is analogous to
duke@435 486 // CardTableModRefBS::resize_covered_region() but
duke@435 487 // for regions that grow or shrink at the low end.
duke@435 488 void CardTableExtension::resize_covered_region(MemRegion new_region) {
duke@435 489
duke@435 490 for (int i = 0; i < _cur_covered_regions; i++) {
duke@435 491 if (_covered[i].start() == new_region.start()) {
duke@435 492 // Found a covered region with the same start as the
duke@435 493 // new region. The region is growing or shrinking
duke@435 494 // from the start of the region.
duke@435 495 resize_covered_region_by_start(new_region);
duke@435 496 return;
duke@435 497 }
duke@435 498 if (_covered[i].start() > new_region.start()) {
duke@435 499 break;
duke@435 500 }
duke@435 501 }
duke@435 502
duke@435 503 int changed_region = -1;
duke@435 504 for (int j = 0; j < _cur_covered_regions; j++) {
duke@435 505 if (_covered[j].end() == new_region.end()) {
duke@435 506 changed_region = j;
duke@435 507 // This is a case where the covered region is growing or shrinking
duke@435 508 // at the start of the region.
duke@435 509 assert(changed_region != -1, "Don't expect to add a covered region");
duke@435 510 assert(_covered[changed_region].byte_size() != new_region.byte_size(),
duke@435 511 "The sizes should be different here");
duke@435 512 resize_covered_region_by_end(changed_region, new_region);
duke@435 513 return;
duke@435 514 }
duke@435 515 }
duke@435 516 // This should only be a new covered region (where no existing
duke@435 517 // covered region matches at the start or the end).
duke@435 518 assert(_cur_covered_regions < _max_covered_regions,
duke@435 519 "An existing region should have been found");
duke@435 520 resize_covered_region_by_start(new_region);
duke@435 521 }
duke@435 522
duke@435 523 void CardTableExtension::resize_covered_region_by_start(MemRegion new_region) {
duke@435 524 CardTableModRefBS::resize_covered_region(new_region);
duke@435 525 debug_only(verify_guard();)
duke@435 526 }
duke@435 527
duke@435 528 void CardTableExtension::resize_covered_region_by_end(int changed_region,
duke@435 529 MemRegion new_region) {
duke@435 530 assert(SafepointSynchronize::is_at_safepoint(),
duke@435 531 "Only expect an expansion at the low end at a GC");
duke@435 532 debug_only(verify_guard();)
duke@435 533 #ifdef ASSERT
duke@435 534 for (int k = 0; k < _cur_covered_regions; k++) {
duke@435 535 if (_covered[k].end() == new_region.end()) {
duke@435 536 assert(changed_region == k, "Changed region is incorrect");
duke@435 537 break;
duke@435 538 }
duke@435 539 }
duke@435 540 #endif
duke@435 541
duke@435 542 // Commit new or uncommit old pages, if necessary.
jmasa@1967 543 if (resize_commit_uncommit(changed_region, new_region)) {
jmasa@1967 544 // Set the new start of the committed region
jmasa@1967 545 resize_update_committed_table(changed_region, new_region);
jmasa@1967 546 }
duke@435 547
duke@435 548 // Update card table entries
duke@435 549 resize_update_card_table_entries(changed_region, new_region);
duke@435 550
duke@435 551 // Update the covered region
duke@435 552 resize_update_covered_table(changed_region, new_region);
duke@435 553
duke@435 554 if (TraceCardTableModRefBS) {
duke@435 555 int ind = changed_region;
duke@435 556 gclog_or_tty->print_cr("CardTableModRefBS::resize_covered_region: ");
duke@435 557 gclog_or_tty->print_cr(" "
duke@435 558 " _covered[%d].start(): " INTPTR_FORMAT
duke@435 559 " _covered[%d].last(): " INTPTR_FORMAT,
duke@435 560 ind, _covered[ind].start(),
duke@435 561 ind, _covered[ind].last());
duke@435 562 gclog_or_tty->print_cr(" "
duke@435 563 " _committed[%d].start(): " INTPTR_FORMAT
duke@435 564 " _committed[%d].last(): " INTPTR_FORMAT,
duke@435 565 ind, _committed[ind].start(),
duke@435 566 ind, _committed[ind].last());
duke@435 567 gclog_or_tty->print_cr(" "
duke@435 568 " byte_for(start): " INTPTR_FORMAT
duke@435 569 " byte_for(last): " INTPTR_FORMAT,
duke@435 570 byte_for(_covered[ind].start()),
duke@435 571 byte_for(_covered[ind].last()));
duke@435 572 gclog_or_tty->print_cr(" "
duke@435 573 " addr_for(start): " INTPTR_FORMAT
duke@435 574 " addr_for(last): " INTPTR_FORMAT,
duke@435 575 addr_for((jbyte*) _committed[ind].start()),
duke@435 576 addr_for((jbyte*) _committed[ind].last()));
duke@435 577 }
duke@435 578 debug_only(verify_guard();)
duke@435 579 }
duke@435 580
jmasa@1967 581 bool CardTableExtension::resize_commit_uncommit(int changed_region,
duke@435 582 MemRegion new_region) {
jmasa@1967 583 bool result = false;
duke@435 584 // Commit new or uncommit old pages, if necessary.
duke@435 585 MemRegion cur_committed = _committed[changed_region];
duke@435 586 assert(_covered[changed_region].end() == new_region.end(),
duke@435 587 "The ends of the regions are expected to match");
duke@435 588 // Extend the start of this _committed region to
duke@435 589 // to cover the start of any previous _committed region.
duke@435 590 // This forms overlapping regions, but never interior regions.
duke@435 591 HeapWord* min_prev_start = lowest_prev_committed_start(changed_region);
duke@435 592 if (min_prev_start < cur_committed.start()) {
duke@435 593 // Only really need to set start of "cur_committed" to
duke@435 594 // the new start (min_prev_start) but assertion checking code
duke@435 595 // below use cur_committed.end() so make it correct.
duke@435 596 MemRegion new_committed =
duke@435 597 MemRegion(min_prev_start, cur_committed.end());
duke@435 598 cur_committed = new_committed;
duke@435 599 }
duke@435 600 #ifdef ASSERT
duke@435 601 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
duke@435 602 assert(cur_committed.start() ==
duke@435 603 (HeapWord*) align_size_up((uintptr_t) cur_committed.start(),
duke@435 604 os::vm_page_size()),
duke@435 605 "Starts should have proper alignment");
duke@435 606 #endif
duke@435 607
duke@435 608 jbyte* new_start = byte_for(new_region.start());
duke@435 609 // Round down because this is for the start address
duke@435 610 HeapWord* new_start_aligned =
duke@435 611 (HeapWord*)align_size_down((uintptr_t)new_start, os::vm_page_size());
duke@435 612 // The guard page is always committed and should not be committed over.
duke@435 613 // This method is used in cases where the generation is growing toward
duke@435 614 // lower addresses but the guard region is still at the end of the
duke@435 615 // card table. That still makes sense when looking for writes
duke@435 616 // off the end of the card table.
duke@435 617 if (new_start_aligned < cur_committed.start()) {
duke@435 618 // Expand the committed region
duke@435 619 //
duke@435 620 // Case A
duke@435 621 // |+ guard +|
duke@435 622 // |+ cur committed +++++++++|
duke@435 623 // |+ new committed +++++++++++++++++|
duke@435 624 //
duke@435 625 // Case B
duke@435 626 // |+ guard +|
duke@435 627 // |+ cur committed +|
duke@435 628 // |+ new committed +++++++|
duke@435 629 //
duke@435 630 // These are not expected because the calculation of the
duke@435 631 // cur committed region and the new committed region
duke@435 632 // share the same end for the covered region.
duke@435 633 // Case C
duke@435 634 // |+ guard +|
duke@435 635 // |+ cur committed +|
duke@435 636 // |+ new committed +++++++++++++++++|
duke@435 637 // Case D
duke@435 638 // |+ guard +|
duke@435 639 // |+ cur committed +++++++++++|
duke@435 640 // |+ new committed +++++++|
duke@435 641
duke@435 642 HeapWord* new_end_for_commit =
duke@435 643 MIN2(cur_committed.end(), _guard_region.start());
jmasa@698 644 if(new_start_aligned < new_end_for_commit) {
jmasa@698 645 MemRegion new_committed =
jmasa@698 646 MemRegion(new_start_aligned, new_end_for_commit);
duke@435 647 if (!os::commit_memory((char*)new_committed.start(),
duke@435 648 new_committed.byte_size())) {
duke@435 649 vm_exit_out_of_memory(new_committed.byte_size(),
duke@435 650 "card table expansion");
duke@435 651 }
duke@435 652 }
jmasa@1967 653 result = true;
duke@435 654 } else if (new_start_aligned > cur_committed.start()) {
duke@435 655 // Shrink the committed region
jmasa@1967 656 #if 0 // uncommitting space is currently unsafe because of the interactions
jmasa@1967 657 // of growing and shrinking regions. One region A can uncommit space
jmasa@1967 658 // that it owns but which is being used by another region B (maybe).
jmasa@1967 659 // Region B has not committed the space because it was already
jmasa@1967 660 // committed by region A.
duke@435 661 MemRegion uncommit_region = committed_unique_to_self(changed_region,
duke@435 662 MemRegion(cur_committed.start(), new_start_aligned));
duke@435 663 if (!uncommit_region.is_empty()) {
duke@435 664 if (!os::uncommit_memory((char*)uncommit_region.start(),
duke@435 665 uncommit_region.byte_size())) {
jmasa@1967 666 // If the uncommit fails, ignore it. Let the
jmasa@1967 667 // committed table resizing go even though the committed
jmasa@1967 668 // table will over state the committed space.
duke@435 669 }
duke@435 670 }
jmasa@1967 671 #else
jmasa@1967 672 assert(!result, "Should be false with current workaround");
jmasa@1967 673 #endif
duke@435 674 }
duke@435 675 assert(_committed[changed_region].end() == cur_committed.end(),
duke@435 676 "end should not change");
jmasa@1967 677 return result;
duke@435 678 }
duke@435 679
duke@435 680 void CardTableExtension::resize_update_committed_table(int changed_region,
duke@435 681 MemRegion new_region) {
duke@435 682
duke@435 683 jbyte* new_start = byte_for(new_region.start());
duke@435 684 // Set the new start of the committed region
duke@435 685 HeapWord* new_start_aligned =
duke@435 686 (HeapWord*)align_size_down((uintptr_t)new_start,
duke@435 687 os::vm_page_size());
duke@435 688 MemRegion new_committed = MemRegion(new_start_aligned,
duke@435 689 _committed[changed_region].end());
duke@435 690 _committed[changed_region] = new_committed;
duke@435 691 _committed[changed_region].set_start(new_start_aligned);
duke@435 692 }
duke@435 693
duke@435 694 void CardTableExtension::resize_update_card_table_entries(int changed_region,
duke@435 695 MemRegion new_region) {
duke@435 696 debug_only(verify_guard();)
duke@435 697 MemRegion original_covered = _covered[changed_region];
duke@435 698 // Initialize the card entries. Only consider the
duke@435 699 // region covered by the card table (_whole_heap)
duke@435 700 jbyte* entry;
duke@435 701 if (new_region.start() < _whole_heap.start()) {
duke@435 702 entry = byte_for(_whole_heap.start());
duke@435 703 } else {
duke@435 704 entry = byte_for(new_region.start());
duke@435 705 }
duke@435 706 jbyte* end = byte_for(original_covered.start());
duke@435 707 // If _whole_heap starts at the original covered regions start,
duke@435 708 // this loop will not execute.
duke@435 709 while (entry < end) { *entry++ = clean_card; }
duke@435 710 }
duke@435 711
duke@435 712 void CardTableExtension::resize_update_covered_table(int changed_region,
duke@435 713 MemRegion new_region) {
duke@435 714 // Update the covered region
duke@435 715 _covered[changed_region].set_start(new_region.start());
duke@435 716 _covered[changed_region].set_word_size(new_region.word_size());
duke@435 717
duke@435 718 // reorder regions. There should only be at most 1 out
duke@435 719 // of order.
duke@435 720 for (int i = _cur_covered_regions-1 ; i > 0; i--) {
duke@435 721 if (_covered[i].start() < _covered[i-1].start()) {
duke@435 722 MemRegion covered_mr = _covered[i-1];
duke@435 723 _covered[i-1] = _covered[i];
duke@435 724 _covered[i] = covered_mr;
duke@435 725 MemRegion committed_mr = _committed[i-1];
duke@435 726 _committed[i-1] = _committed[i];
duke@435 727 _committed[i] = committed_mr;
duke@435 728 break;
duke@435 729 }
duke@435 730 }
duke@435 731 #ifdef ASSERT
duke@435 732 for (int m = 0; m < _cur_covered_regions-1; m++) {
duke@435 733 assert(_covered[m].start() <= _covered[m+1].start(),
duke@435 734 "Covered regions out of order");
duke@435 735 assert(_committed[m].start() <= _committed[m+1].start(),
duke@435 736 "Committed regions out of order");
duke@435 737 }
duke@435 738 #endif
duke@435 739 }
duke@435 740
duke@435 741 // Returns the start of any committed region that is lower than
duke@435 742 // the target committed region (index ind) and that intersects the
duke@435 743 // target region. If none, return start of target region.
duke@435 744 //
duke@435 745 // -------------
duke@435 746 // | |
duke@435 747 // -------------
duke@435 748 // ------------
duke@435 749 // | target |
duke@435 750 // ------------
duke@435 751 // -------------
duke@435 752 // | |
duke@435 753 // -------------
duke@435 754 // ^ returns this
duke@435 755 //
duke@435 756 // -------------
duke@435 757 // | |
duke@435 758 // -------------
duke@435 759 // ------------
duke@435 760 // | target |
duke@435 761 // ------------
duke@435 762 // -------------
duke@435 763 // | |
duke@435 764 // -------------
duke@435 765 // ^ returns this
duke@435 766
duke@435 767 HeapWord* CardTableExtension::lowest_prev_committed_start(int ind) const {
duke@435 768 assert(_cur_covered_regions >= 0, "Expecting at least on region");
duke@435 769 HeapWord* min_start = _committed[ind].start();
duke@435 770 for (int j = 0; j < ind; j++) {
duke@435 771 HeapWord* this_start = _committed[j].start();
duke@435 772 if ((this_start < min_start) &&
duke@435 773 !(_committed[j].intersection(_committed[ind])).is_empty()) {
duke@435 774 min_start = this_start;
duke@435 775 }
duke@435 776 }
duke@435 777 return min_start;
duke@435 778 }

mercurial