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

Fri, 07 Sep 2012 12:04:16 -0400

author
coleenp
date
Fri, 07 Sep 2012 12:04:16 -0400
changeset 4047
aed758eda82a
parent 4037
da91efe96a93
child 4128
f81a7c0c618d
permissions
-rw-r--r--

7195833: NPG: Rename instanceClassLoaderKlass, instanceRefKlass and instanceMirrorKlass
Summary: Simple renaming to be consistent with instanceKlass->InstanceKlass renaming
Reviewed-by: stefank, jmasa

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

mercurial