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

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 1
2d8a650513c2
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

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

mercurial