src/share/vm/memory/cardTableModRefBS.cpp

Tue, 16 Feb 2016 21:42:29 +0000

author
poonam
date
Tue, 16 Feb 2016 21:42:29 +0000
changeset 8308
6acf14e730dd
parent 7051
1f1d373cd044
child 7535
7ae4e26cb1e0
child 9327
f96fcd9e1e1b
permissions
-rw-r--r--

8072725: Provide more granular levels for GC verification
Summary: Add option VerifySubSet to selectively verify the memory sub-systems
Reviewed-by: kevinw, jmasa

duke@435 1 /*
drchase@6680 2 * Copyright (c) 2000, 2014, 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 "memory/allocation.inline.hpp"
stefank@2314 27 #include "memory/cardTableModRefBS.hpp"
stefank@2314 28 #include "memory/cardTableRS.hpp"
stefank@2314 29 #include "memory/sharedHeap.hpp"
stefank@2314 30 #include "memory/space.hpp"
stefank@2314 31 #include "memory/space.inline.hpp"
stefank@2314 32 #include "memory/universe.hpp"
stefank@2314 33 #include "runtime/java.hpp"
stefank@2314 34 #include "runtime/mutexLocker.hpp"
stefank@2314 35 #include "runtime/virtualspace.hpp"
zgu@3900 36 #include "services/memTracker.hpp"
jprovino@4542 37 #include "utilities/macros.hpp"
stefank@2314 38 #ifdef COMPILER1
stefank@2314 39 #include "c1/c1_LIR.hpp"
stefank@2314 40 #include "c1/c1_LIRGenerator.hpp"
stefank@2314 41 #endif
stefank@2314 42
duke@435 43 // This kind of "BarrierSet" allows a "CollectedHeap" to detect and
duke@435 44 // enumerate ref fields that have been modified (since the last
duke@435 45 // enumeration.)
duke@435 46
duke@435 47 size_t CardTableModRefBS::compute_byte_map_size()
duke@435 48 {
duke@435 49 assert(_guard_index == cards_required(_whole_heap.word_size()) - 1,
duke@435 50 "unitialized, check declaration order");
duke@435 51 assert(_page_size != 0, "unitialized, check declaration order");
duke@435 52 const size_t granularity = os::vm_allocation_granularity();
duke@435 53 return align_size_up(_guard_index + 1, MAX2(_page_size, granularity));
duke@435 54 }
duke@435 55
duke@435 56 CardTableModRefBS::CardTableModRefBS(MemRegion whole_heap,
duke@435 57 int max_covered_regions):
duke@435 58 ModRefBarrierSet(max_covered_regions),
duke@435 59 _whole_heap(whole_heap),
tschatzl@7051 60 _guard_index(0),
tschatzl@7051 61 _guard_region(),
tschatzl@7051 62 _last_valid_index(0),
jcoomes@456 63 _page_size(os::vm_page_size()),
tschatzl@7051 64 _byte_map_size(0),
tschatzl@7051 65 _covered(NULL),
tschatzl@7051 66 _committed(NULL),
tschatzl@7051 67 _cur_covered_regions(0),
tschatzl@7051 68 _byte_map(NULL),
tschatzl@7051 69 byte_map_base(NULL),
tschatzl@7051 70 // LNC functionality
tschatzl@7051 71 _lowest_non_clean(NULL),
tschatzl@7051 72 _lowest_non_clean_chunk_size(NULL),
tschatzl@7051 73 _lowest_non_clean_base_chunk_index(NULL),
tschatzl@7051 74 _last_LNC_resizing_collection(NULL)
duke@435 75 {
duke@435 76 _kind = BarrierSet::CardTableModRef;
duke@435 77
tschatzl@7051 78 assert((uintptr_t(_whole_heap.start()) & (card_size - 1)) == 0, "heap must start at card boundary");
tschatzl@7051 79 assert((uintptr_t(_whole_heap.end()) & (card_size - 1)) == 0, "heap must end at card boundary");
duke@435 80
duke@435 81 assert(card_size <= 512, "card_size must be less than 512"); // why?
duke@435 82
tschatzl@7051 83 _covered = new MemRegion[_max_covered_regions];
tschatzl@7051 84 if (_covered == NULL) {
tschatzl@7051 85 vm_exit_during_initialization("Could not allocate card table covered region set.");
tschatzl@7051 86 }
tschatzl@7051 87 }
tschatzl@7051 88
tschatzl@7051 89 void CardTableModRefBS::initialize() {
tschatzl@7051 90 _guard_index = cards_required(_whole_heap.word_size()) - 1;
tschatzl@7051 91 _last_valid_index = _guard_index - 1;
tschatzl@7051 92
tschatzl@7051 93 _byte_map_size = compute_byte_map_size();
tschatzl@7051 94
tschatzl@7051 95 HeapWord* low_bound = _whole_heap.start();
tschatzl@7051 96 HeapWord* high_bound = _whole_heap.end();
tschatzl@7051 97
tschatzl@7051 98 _cur_covered_regions = 0;
tschatzl@7051 99 _committed = new MemRegion[_max_covered_regions];
tschatzl@7051 100 if (_committed == NULL) {
tschatzl@7051 101 vm_exit_during_initialization("Could not allocate card table committed region set.");
duke@435 102 }
minqi@5103 103
duke@435 104 const size_t rs_align = _page_size == (size_t) os::vm_page_size() ? 0 :
duke@435 105 MAX2(_page_size, (size_t) os::vm_allocation_granularity());
duke@435 106 ReservedSpace heap_rs(_byte_map_size, rs_align, false);
zgu@3900 107
zgu@3900 108 MemTracker::record_virtual_memory_type((address)heap_rs.base(), mtGC);
zgu@3900 109
duke@435 110 os::trace_page_sizes("card table", _guard_index + 1, _guard_index + 1,
duke@435 111 _page_size, heap_rs.base(), heap_rs.size());
duke@435 112 if (!heap_rs.is_reserved()) {
duke@435 113 vm_exit_during_initialization("Could not reserve enough space for the "
duke@435 114 "card marking array");
duke@435 115 }
duke@435 116
duke@435 117 // The assember store_check code will do an unsigned shift of the oop,
duke@435 118 // then add it to byte_map_base, i.e.
duke@435 119 //
duke@435 120 // _byte_map = byte_map_base + (uintptr_t(low_bound) >> card_shift)
duke@435 121 _byte_map = (jbyte*) heap_rs.base();
duke@435 122 byte_map_base = _byte_map - (uintptr_t(low_bound) >> card_shift);
duke@435 123 assert(byte_for(low_bound) == &_byte_map[0], "Checking start of map");
duke@435 124 assert(byte_for(high_bound-1) <= &_byte_map[_last_valid_index], "Checking end of map");
duke@435 125
duke@435 126 jbyte* guard_card = &_byte_map[_guard_index];
duke@435 127 uintptr_t guard_page = align_size_down((uintptr_t)guard_card, _page_size);
duke@435 128 _guard_region = MemRegion((HeapWord*)guard_page, _page_size);
dcubed@5255 129 os::commit_memory_or_exit((char*)guard_page, _page_size, _page_size,
dcubed@5255 130 !ExecMem, "card table last card");
duke@435 131 *guard_card = last_card;
duke@435 132
tschatzl@7051 133 _lowest_non_clean =
tschatzl@7051 134 NEW_C_HEAP_ARRAY(CardArr, _max_covered_regions, mtGC);
duke@435 135 _lowest_non_clean_chunk_size =
tschatzl@7051 136 NEW_C_HEAP_ARRAY(size_t, _max_covered_regions, mtGC);
duke@435 137 _lowest_non_clean_base_chunk_index =
tschatzl@7051 138 NEW_C_HEAP_ARRAY(uintptr_t, _max_covered_regions, mtGC);
duke@435 139 _last_LNC_resizing_collection =
tschatzl@7051 140 NEW_C_HEAP_ARRAY(int, _max_covered_regions, mtGC);
duke@435 141 if (_lowest_non_clean == NULL
duke@435 142 || _lowest_non_clean_chunk_size == NULL
duke@435 143 || _lowest_non_clean_base_chunk_index == NULL
duke@435 144 || _last_LNC_resizing_collection == NULL)
duke@435 145 vm_exit_during_initialization("couldn't allocate an LNC array.");
tschatzl@7051 146 for (int i = 0; i < _max_covered_regions; i++) {
duke@435 147 _lowest_non_clean[i] = NULL;
duke@435 148 _lowest_non_clean_chunk_size[i] = 0;
duke@435 149 _last_LNC_resizing_collection[i] = -1;
duke@435 150 }
duke@435 151
duke@435 152 if (TraceCardTableModRefBS) {
duke@435 153 gclog_or_tty->print_cr("CardTableModRefBS::CardTableModRefBS: ");
duke@435 154 gclog_or_tty->print_cr(" "
duke@435 155 " &_byte_map[0]: " INTPTR_FORMAT
duke@435 156 " &_byte_map[_last_valid_index]: " INTPTR_FORMAT,
drchase@6680 157 p2i(&_byte_map[0]),
drchase@6680 158 p2i(&_byte_map[_last_valid_index]));
duke@435 159 gclog_or_tty->print_cr(" "
duke@435 160 " byte_map_base: " INTPTR_FORMAT,
drchase@6680 161 p2i(byte_map_base));
duke@435 162 }
duke@435 163 }
duke@435 164
minqi@5103 165 CardTableModRefBS::~CardTableModRefBS() {
minqi@5103 166 if (_covered) {
minqi@5103 167 delete[] _covered;
minqi@5103 168 _covered = NULL;
minqi@5103 169 }
minqi@5103 170 if (_committed) {
minqi@5103 171 delete[] _committed;
minqi@5103 172 _committed = NULL;
minqi@5103 173 }
minqi@5103 174 if (_lowest_non_clean) {
minqi@5103 175 FREE_C_HEAP_ARRAY(CardArr, _lowest_non_clean, mtGC);
minqi@5103 176 _lowest_non_clean = NULL;
minqi@5103 177 }
minqi@5103 178 if (_lowest_non_clean_chunk_size) {
minqi@5103 179 FREE_C_HEAP_ARRAY(size_t, _lowest_non_clean_chunk_size, mtGC);
minqi@5103 180 _lowest_non_clean_chunk_size = NULL;
minqi@5103 181 }
minqi@5103 182 if (_lowest_non_clean_base_chunk_index) {
minqi@5103 183 FREE_C_HEAP_ARRAY(uintptr_t, _lowest_non_clean_base_chunk_index, mtGC);
minqi@5103 184 _lowest_non_clean_base_chunk_index = NULL;
minqi@5103 185 }
minqi@5103 186 if (_last_LNC_resizing_collection) {
minqi@5103 187 FREE_C_HEAP_ARRAY(int, _last_LNC_resizing_collection, mtGC);
minqi@5103 188 _last_LNC_resizing_collection = NULL;
minqi@5103 189 }
minqi@5103 190 }
minqi@5103 191
duke@435 192 int CardTableModRefBS::find_covering_region_by_base(HeapWord* base) {
duke@435 193 int i;
duke@435 194 for (i = 0; i < _cur_covered_regions; i++) {
duke@435 195 if (_covered[i].start() == base) return i;
duke@435 196 if (_covered[i].start() > base) break;
duke@435 197 }
duke@435 198 // If we didn't find it, create a new one.
duke@435 199 assert(_cur_covered_regions < _max_covered_regions,
duke@435 200 "too many covered regions");
duke@435 201 // Move the ones above up, to maintain sorted order.
duke@435 202 for (int j = _cur_covered_regions; j > i; j--) {
duke@435 203 _covered[j] = _covered[j-1];
duke@435 204 _committed[j] = _committed[j-1];
duke@435 205 }
duke@435 206 int res = i;
duke@435 207 _cur_covered_regions++;
duke@435 208 _covered[res].set_start(base);
duke@435 209 _covered[res].set_word_size(0);
duke@435 210 jbyte* ct_start = byte_for(base);
duke@435 211 uintptr_t ct_start_aligned = align_size_down((uintptr_t)ct_start, _page_size);
duke@435 212 _committed[res].set_start((HeapWord*)ct_start_aligned);
duke@435 213 _committed[res].set_word_size(0);
duke@435 214 return res;
duke@435 215 }
duke@435 216
duke@435 217 int CardTableModRefBS::find_covering_region_containing(HeapWord* addr) {
duke@435 218 for (int i = 0; i < _cur_covered_regions; i++) {
duke@435 219 if (_covered[i].contains(addr)) {
duke@435 220 return i;
duke@435 221 }
duke@435 222 }
duke@435 223 assert(0, "address outside of heap?");
duke@435 224 return -1;
duke@435 225 }
duke@435 226
duke@435 227 HeapWord* CardTableModRefBS::largest_prev_committed_end(int ind) const {
duke@435 228 HeapWord* max_end = NULL;
duke@435 229 for (int j = 0; j < ind; j++) {
duke@435 230 HeapWord* this_end = _committed[j].end();
duke@435 231 if (this_end > max_end) max_end = this_end;
duke@435 232 }
duke@435 233 return max_end;
duke@435 234 }
duke@435 235
duke@435 236 MemRegion CardTableModRefBS::committed_unique_to_self(int self,
duke@435 237 MemRegion mr) const {
duke@435 238 MemRegion result = mr;
duke@435 239 for (int r = 0; r < _cur_covered_regions; r += 1) {
duke@435 240 if (r != self) {
duke@435 241 result = result.minus(_committed[r]);
duke@435 242 }
duke@435 243 }
duke@435 244 // Never include the guard page.
duke@435 245 result = result.minus(_guard_region);
duke@435 246 return result;
duke@435 247 }
duke@435 248
duke@435 249 void CardTableModRefBS::resize_covered_region(MemRegion new_region) {
duke@435 250 // We don't change the start of a region, only the end.
duke@435 251 assert(_whole_heap.contains(new_region),
duke@435 252 "attempt to cover area not in reserved area");
duke@435 253 debug_only(verify_guard();)
jmasa@643 254 // collided is true if the expansion would push into another committed region
jmasa@643 255 debug_only(bool collided = false;)
jmasa@441 256 int const ind = find_covering_region_by_base(new_region.start());
jmasa@441 257 MemRegion const old_region = _covered[ind];
duke@435 258 assert(old_region.start() == new_region.start(), "just checking");
duke@435 259 if (new_region.word_size() != old_region.word_size()) {
duke@435 260 // Commit new or uncommit old pages, if necessary.
duke@435 261 MemRegion cur_committed = _committed[ind];
duke@435 262 // Extend the end of this _commited region
duke@435 263 // to cover the end of any lower _committed regions.
duke@435 264 // This forms overlapping regions, but never interior regions.
jmasa@441 265 HeapWord* const max_prev_end = largest_prev_committed_end(ind);
duke@435 266 if (max_prev_end > cur_committed.end()) {
duke@435 267 cur_committed.set_end(max_prev_end);
duke@435 268 }
duke@435 269 // Align the end up to a page size (starts are already aligned).
jmasa@441 270 jbyte* const new_end = byte_after(new_region.last());
jmasa@643 271 HeapWord* new_end_aligned =
jmasa@441 272 (HeapWord*) align_size_up((uintptr_t)new_end, _page_size);
duke@435 273 assert(new_end_aligned >= (HeapWord*) new_end,
duke@435 274 "align up, but less");
jmasa@1016 275 // Check the other regions (excludes "ind") to ensure that
jmasa@1016 276 // the new_end_aligned does not intrude onto the committed
jmasa@1016 277 // space of another region.
jmasa@643 278 int ri = 0;
jmasa@643 279 for (ri = 0; ri < _cur_covered_regions; ri++) {
jmasa@643 280 if (ri != ind) {
jmasa@643 281 if (_committed[ri].contains(new_end_aligned)) {
jmasa@1016 282 // The prior check included in the assert
jmasa@1016 283 // (new_end_aligned >= _committed[ri].start())
jmasa@1016 284 // is redundant with the "contains" test.
jmasa@1016 285 // Any region containing the new end
jmasa@1016 286 // should start at or beyond the region found (ind)
jmasa@1016 287 // for the new end (committed regions are not expected to
jmasa@1016 288 // be proper subsets of other committed regions).
jmasa@1016 289 assert(_committed[ri].start() >= _committed[ind].start(),
jmasa@643 290 "New end of committed region is inconsistent");
jmasa@643 291 new_end_aligned = _committed[ri].start();
jmasa@1016 292 // new_end_aligned can be equal to the start of its
jmasa@1016 293 // committed region (i.e., of "ind") if a second
jmasa@1016 294 // region following "ind" also start at the same location
jmasa@1016 295 // as "ind".
jmasa@1016 296 assert(new_end_aligned >= _committed[ind].start(),
jmasa@643 297 "New end of committed region is before start");
jmasa@643 298 debug_only(collided = true;)
jmasa@643 299 // Should only collide with 1 region
jmasa@643 300 break;
jmasa@643 301 }
jmasa@643 302 }
jmasa@643 303 }
jmasa@643 304 #ifdef ASSERT
jmasa@643 305 for (++ri; ri < _cur_covered_regions; ri++) {
jmasa@643 306 assert(!_committed[ri].contains(new_end_aligned),
jmasa@643 307 "New end of committed region is in a second committed region");
jmasa@643 308 }
jmasa@643 309 #endif
duke@435 310 // The guard page is always committed and should not be committed over.
jmasa@1322 311 // "guarded" is used for assertion checking below and recalls the fact
jmasa@1322 312 // that the would-be end of the new committed region would have
jmasa@1322 313 // penetrated the guard page.
jmasa@1322 314 HeapWord* new_end_for_commit = new_end_aligned;
jmasa@1322 315
jmasa@1322 316 DEBUG_ONLY(bool guarded = false;)
jmasa@1322 317 if (new_end_for_commit > _guard_region.start()) {
jmasa@1322 318 new_end_for_commit = _guard_region.start();
jmasa@1322 319 DEBUG_ONLY(guarded = true;)
jmasa@1322 320 }
jmasa@643 321
duke@435 322 if (new_end_for_commit > cur_committed.end()) {
duke@435 323 // Must commit new pages.
jmasa@441 324 MemRegion const new_committed =
duke@435 325 MemRegion(cur_committed.end(), new_end_for_commit);
duke@435 326
duke@435 327 assert(!new_committed.is_empty(), "Region should not be empty here");
dcubed@5255 328 os::commit_memory_or_exit((char*)new_committed.start(),
dcubed@5255 329 new_committed.byte_size(), _page_size,
dcubed@5255 330 !ExecMem, "card table expansion");
duke@435 331 // Use new_end_aligned (as opposed to new_end_for_commit) because
duke@435 332 // the cur_committed region may include the guard region.
duke@435 333 } else if (new_end_aligned < cur_committed.end()) {
duke@435 334 // Must uncommit pages.
jmasa@441 335 MemRegion const uncommit_region =
duke@435 336 committed_unique_to_self(ind, MemRegion(new_end_aligned,
duke@435 337 cur_committed.end()));
duke@435 338 if (!uncommit_region.is_empty()) {
jmasa@1967 339 // It is not safe to uncommit cards if the boundary between
jmasa@1967 340 // the generations is moving. A shrink can uncommit cards
jmasa@1967 341 // owned by generation A but being used by generation B.
jmasa@1967 342 if (!UseAdaptiveGCBoundary) {
jmasa@1967 343 if (!os::uncommit_memory((char*)uncommit_region.start(),
jmasa@1967 344 uncommit_region.byte_size())) {
jmasa@1967 345 assert(false, "Card table contraction failed");
jmasa@1967 346 // The call failed so don't change the end of the
jmasa@1967 347 // committed region. This is better than taking the
jmasa@1967 348 // VM down.
jmasa@1967 349 new_end_aligned = _committed[ind].end();
jmasa@1967 350 }
jmasa@1967 351 } else {
jmasa@643 352 new_end_aligned = _committed[ind].end();
duke@435 353 }
duke@435 354 }
duke@435 355 }
duke@435 356 // In any case, we can reset the end of the current committed entry.
duke@435 357 _committed[ind].set_end(new_end_aligned);
duke@435 358
jmasa@1967 359 #ifdef ASSERT
jmasa@1967 360 // Check that the last card in the new region is committed according
jmasa@1967 361 // to the tables.
jmasa@1967 362 bool covered = false;
jmasa@1967 363 for (int cr = 0; cr < _cur_covered_regions; cr++) {
jmasa@1967 364 if (_committed[cr].contains(new_end - 1)) {
jmasa@1967 365 covered = true;
jmasa@1967 366 break;
jmasa@1967 367 }
jmasa@1967 368 }
jmasa@1967 369 assert(covered, "Card for end of new region not committed");
jmasa@1967 370 #endif
jmasa@1967 371
duke@435 372 // The default of 0 is not necessarily clean cards.
duke@435 373 jbyte* entry;
duke@435 374 if (old_region.last() < _whole_heap.start()) {
duke@435 375 entry = byte_for(_whole_heap.start());
duke@435 376 } else {
duke@435 377 entry = byte_after(old_region.last());
duke@435 378 }
swamyv@924 379 assert(index_for(new_region.last()) < _guard_index,
duke@435 380 "The guard card will be overwritten");
jmasa@643 381 // This line commented out cleans the newly expanded region and
jmasa@643 382 // not the aligned up expanded region.
jmasa@643 383 // jbyte* const end = byte_after(new_region.last());
jmasa@643 384 jbyte* const end = (jbyte*) new_end_for_commit;
jmasa@1322 385 assert((end >= byte_after(new_region.last())) || collided || guarded,
jmasa@643 386 "Expect to be beyond new region unless impacting another region");
duke@435 387 // do nothing if we resized downward.
jmasa@643 388 #ifdef ASSERT
jmasa@643 389 for (int ri = 0; ri < _cur_covered_regions; ri++) {
jmasa@643 390 if (ri != ind) {
jmasa@643 391 // The end of the new committed region should not
jmasa@643 392 // be in any existing region unless it matches
jmasa@643 393 // the start of the next region.
jmasa@643 394 assert(!_committed[ri].contains(end) ||
jmasa@643 395 (_committed[ri].start() == (HeapWord*) end),
jmasa@643 396 "Overlapping committed regions");
jmasa@643 397 }
jmasa@643 398 }
jmasa@643 399 #endif
duke@435 400 if (entry < end) {
duke@435 401 memset(entry, clean_card, pointer_delta(end, entry, sizeof(jbyte)));
duke@435 402 }
duke@435 403 }
duke@435 404 // In any case, the covered size changes.
duke@435 405 _covered[ind].set_word_size(new_region.word_size());
duke@435 406 if (TraceCardTableModRefBS) {
duke@435 407 gclog_or_tty->print_cr("CardTableModRefBS::resize_covered_region: ");
duke@435 408 gclog_or_tty->print_cr(" "
duke@435 409 " _covered[%d].start(): " INTPTR_FORMAT
duke@435 410 " _covered[%d].last(): " INTPTR_FORMAT,
drchase@6680 411 ind, p2i(_covered[ind].start()),
drchase@6680 412 ind, p2i(_covered[ind].last()));
duke@435 413 gclog_or_tty->print_cr(" "
duke@435 414 " _committed[%d].start(): " INTPTR_FORMAT
duke@435 415 " _committed[%d].last(): " INTPTR_FORMAT,
drchase@6680 416 ind, p2i(_committed[ind].start()),
drchase@6680 417 ind, p2i(_committed[ind].last()));
duke@435 418 gclog_or_tty->print_cr(" "
duke@435 419 " byte_for(start): " INTPTR_FORMAT
duke@435 420 " byte_for(last): " INTPTR_FORMAT,
drchase@6680 421 p2i(byte_for(_covered[ind].start())),
drchase@6680 422 p2i(byte_for(_covered[ind].last())));
duke@435 423 gclog_or_tty->print_cr(" "
duke@435 424 " addr_for(start): " INTPTR_FORMAT
duke@435 425 " addr_for(last): " INTPTR_FORMAT,
drchase@6680 426 p2i(addr_for((jbyte*) _committed[ind].start())),
drchase@6680 427 p2i(addr_for((jbyte*) _committed[ind].last())));
duke@435 428 }
jmasa@1967 429 // Touch the last card of the covered region to show that it
jmasa@1967 430 // is committed (or SEGV).
ccheung@5259 431 debug_only((void) (*byte_for(_covered[ind].last()));)
duke@435 432 debug_only(verify_guard();)
duke@435 433 }
duke@435 434
duke@435 435 // Note that these versions are precise! The scanning code has to handle the
duke@435 436 // fact that the write barrier may be either precise or imprecise.
duke@435 437
goetz@6493 438 void CardTableModRefBS::write_ref_field_work(void* field, oop newVal, bool release) {
goetz@6493 439 inline_write_ref_field(field, newVal, release);
duke@435 440 }
duke@435 441
iveresov@1051 442
ysr@2819 443 void CardTableModRefBS::non_clean_card_iterate_possibly_parallel(Space* sp,
ysr@2819 444 MemRegion mr,
ysr@2889 445 OopsInGenClosure* cl,
ysr@2889 446 CardTableRS* ct) {
duke@435 447 if (!mr.is_empty()) {
stefank@6992 448 // Caller (process_roots()) claims that all GC threads
jmasa@3294 449 // execute this call. With UseDynamicNumberOfGCThreads now all
jmasa@3294 450 // active GC threads execute this call. The number of active GC
jmasa@3294 451 // threads needs to be passed to par_non_clean_card_iterate_work()
jmasa@3294 452 // to get proper partitioning and termination.
jmasa@3294 453 //
jmasa@3294 454 // This is an example of where n_par_threads() is used instead
jmasa@3294 455 // of workers()->active_workers(). n_par_threads can be set to 0 to
jmasa@3294 456 // turn off parallelism. For example when this code is called as
stefank@6992 457 // part of verification and SharedHeap::process_roots() is being
jmasa@3294 458 // used, then n_par_threads() may have been set to 0. active_workers
jmasa@3294 459 // is not overloaded with the meaning that it is a switch to disable
jmasa@3294 460 // parallelism and so keeps the meaning of the number of
jmasa@3294 461 // active gc workers. If parallelism has not been shut off by
jmasa@3294 462 // setting n_par_threads to 0, then n_par_threads should be
jmasa@3294 463 // equal to active_workers. When a different mechanism for shutting
jmasa@3294 464 // off parallelism is used, then active_workers can be used in
jmasa@3294 465 // place of n_par_threads.
jmasa@3294 466 // This is an example of a path where n_par_threads is
jmasa@3294 467 // set to 0 to turn off parallism.
jmasa@3294 468 // [7] CardTableModRefBS::non_clean_card_iterate()
jmasa@3294 469 // [8] CardTableRS::younger_refs_in_space_iterate()
jmasa@3294 470 // [9] Generation::younger_refs_in_space_iterate()
jmasa@3294 471 // [10] OneContigSpaceCardGeneration::younger_refs_iterate()
jmasa@3294 472 // [11] CompactingPermGenGen::younger_refs_iterate()
jmasa@3294 473 // [12] CardTableRS::younger_refs_iterate()
jmasa@3294 474 // [13] SharedHeap::process_strong_roots()
jmasa@3294 475 // [14] G1CollectedHeap::verify()
jmasa@3294 476 // [15] Universe::verify()
jmasa@3294 477 // [16] G1CollectedHeap::do_collection_pause_at_safepoint()
jmasa@3294 478 //
jmasa@3294 479 int n_threads = SharedHeap::heap()->n_par_threads();
jmasa@3294 480 bool is_par = n_threads > 0;
jmasa@3294 481 if (is_par) {
jprovino@4542 482 #if INCLUDE_ALL_GCS
jmasa@3294 483 assert(SharedHeap::heap()->n_par_threads() ==
jmasa@3294 484 SharedHeap::heap()->workers()->active_workers(), "Mismatch");
ysr@2889 485 non_clean_card_iterate_parallel_work(sp, mr, cl, ct, n_threads);
jprovino@4542 486 #else // INCLUDE_ALL_GCS
duke@435 487 fatal("Parallel gc not supported here.");
jprovino@4542 488 #endif // INCLUDE_ALL_GCS
duke@435 489 } else {
ysr@2819 490 // We do not call the non_clean_card_iterate_serial() version below because
ysr@2819 491 // we want to clear the cards (which non_clean_card_iterate_serial() does not
ysr@2889 492 // do for us): clear_cl here does the work of finding contiguous dirty ranges
ysr@2889 493 // of cards to process and clear.
ysr@2889 494
ysr@2889 495 DirtyCardToOopClosure* dcto_cl = sp->new_dcto_cl(cl, precision(),
ysr@2889 496 cl->gen_boundary());
ysr@2889 497 ClearNoncleanCardWrapper clear_cl(dcto_cl, ct);
ysr@2889 498
ysr@2889 499 clear_cl.do_MemRegion(mr);
duke@435 500 }
duke@435 501 }
duke@435 502 }
duke@435 503
ysr@2819 504 // The iterator itself is not MT-aware, but
ysr@2819 505 // MT-aware callers and closures can use this to
ysr@2819 506 // accomplish dirty card iteration in parallel. The
ysr@2819 507 // iterator itself does not clear the dirty cards, or
ysr@2819 508 // change their values in any manner.
ysr@2819 509 void CardTableModRefBS::non_clean_card_iterate_serial(MemRegion mr,
ysr@2819 510 MemRegionClosure* cl) {
jmasa@3294 511 bool is_par = (SharedHeap::heap()->n_par_threads() > 0);
jmasa@3294 512 assert(!is_par ||
jmasa@3294 513 (SharedHeap::heap()->n_par_threads() ==
jmasa@3294 514 SharedHeap::heap()->workers()->active_workers()), "Mismatch");
duke@435 515 for (int i = 0; i < _cur_covered_regions; i++) {
duke@435 516 MemRegion mri = mr.intersection(_covered[i]);
duke@435 517 if (mri.word_size() > 0) {
duke@435 518 jbyte* cur_entry = byte_for(mri.last());
duke@435 519 jbyte* limit = byte_for(mri.start());
duke@435 520 while (cur_entry >= limit) {
duke@435 521 jbyte* next_entry = cur_entry - 1;
duke@435 522 if (*cur_entry != clean_card) {
duke@435 523 size_t non_clean_cards = 1;
duke@435 524 // Should the next card be included in this range of dirty cards.
duke@435 525 while (next_entry >= limit && *next_entry != clean_card) {
duke@435 526 non_clean_cards++;
duke@435 527 cur_entry = next_entry;
duke@435 528 next_entry--;
duke@435 529 }
duke@435 530 // The memory region may not be on a card boundary. So that
duke@435 531 // objects beyond the end of the region are not processed, make
duke@435 532 // cur_cards precise with regard to the end of the memory region.
duke@435 533 MemRegion cur_cards(addr_for(cur_entry),
duke@435 534 non_clean_cards * card_size_in_words);
duke@435 535 MemRegion dirty_region = cur_cards.intersection(mri);
duke@435 536 cl->do_MemRegion(dirty_region);
duke@435 537 }
duke@435 538 cur_entry = next_entry;
duke@435 539 }
duke@435 540 }
duke@435 541 }
duke@435 542 }
duke@435 543
duke@435 544 void CardTableModRefBS::dirty_MemRegion(MemRegion mr) {
ysr@1526 545 assert((HeapWord*)align_size_down((uintptr_t)mr.start(), HeapWordSize) == mr.start(), "Unaligned start");
ysr@1526 546 assert((HeapWord*)align_size_up ((uintptr_t)mr.end(), HeapWordSize) == mr.end(), "Unaligned end" );
duke@435 547 jbyte* cur = byte_for(mr.start());
duke@435 548 jbyte* last = byte_after(mr.last());
duke@435 549 while (cur < last) {
duke@435 550 *cur = dirty_card;
duke@435 551 cur++;
duke@435 552 }
duke@435 553 }
duke@435 554
ysr@777 555 void CardTableModRefBS::invalidate(MemRegion mr, bool whole_heap) {
ysr@1526 556 assert((HeapWord*)align_size_down((uintptr_t)mr.start(), HeapWordSize) == mr.start(), "Unaligned start");
ysr@1526 557 assert((HeapWord*)align_size_up ((uintptr_t)mr.end(), HeapWordSize) == mr.end(), "Unaligned end" );
duke@435 558 for (int i = 0; i < _cur_covered_regions; i++) {
duke@435 559 MemRegion mri = mr.intersection(_covered[i]);
duke@435 560 if (!mri.is_empty()) dirty_MemRegion(mri);
duke@435 561 }
duke@435 562 }
duke@435 563
duke@435 564 void CardTableModRefBS::clear_MemRegion(MemRegion mr) {
duke@435 565 // Be conservative: only clean cards entirely contained within the
duke@435 566 // region.
duke@435 567 jbyte* cur;
duke@435 568 if (mr.start() == _whole_heap.start()) {
duke@435 569 cur = byte_for(mr.start());
duke@435 570 } else {
duke@435 571 assert(mr.start() > _whole_heap.start(), "mr is not covered.");
duke@435 572 cur = byte_after(mr.start() - 1);
duke@435 573 }
duke@435 574 jbyte* last = byte_after(mr.last());
duke@435 575 memset(cur, clean_card, pointer_delta(last, cur, sizeof(jbyte)));
duke@435 576 }
duke@435 577
duke@435 578 void CardTableModRefBS::clear(MemRegion mr) {
duke@435 579 for (int i = 0; i < _cur_covered_regions; i++) {
duke@435 580 MemRegion mri = mr.intersection(_covered[i]);
duke@435 581 if (!mri.is_empty()) clear_MemRegion(mri);
duke@435 582 }
duke@435 583 }
duke@435 584
ysr@777 585 void CardTableModRefBS::dirty(MemRegion mr) {
ysr@777 586 jbyte* first = byte_for(mr.start());
ysr@777 587 jbyte* last = byte_after(mr.last());
ysr@777 588 memset(first, dirty_card, last-first);
ysr@777 589 }
ysr@777 590
ysr@2788 591 // Unlike several other card table methods, dirty_card_iterate()
ysr@2788 592 // iterates over dirty cards ranges in increasing address order.
duke@435 593 void CardTableModRefBS::dirty_card_iterate(MemRegion mr,
duke@435 594 MemRegionClosure* cl) {
duke@435 595 for (int i = 0; i < _cur_covered_regions; i++) {
duke@435 596 MemRegion mri = mr.intersection(_covered[i]);
duke@435 597 if (!mri.is_empty()) {
duke@435 598 jbyte *cur_entry, *next_entry, *limit;
duke@435 599 for (cur_entry = byte_for(mri.start()), limit = byte_for(mri.last());
duke@435 600 cur_entry <= limit;
duke@435 601 cur_entry = next_entry) {
duke@435 602 next_entry = cur_entry + 1;
duke@435 603 if (*cur_entry == dirty_card) {
duke@435 604 size_t dirty_cards;
duke@435 605 // Accumulate maximal dirty card range, starting at cur_entry
duke@435 606 for (dirty_cards = 1;
duke@435 607 next_entry <= limit && *next_entry == dirty_card;
duke@435 608 dirty_cards++, next_entry++);
duke@435 609 MemRegion cur_cards(addr_for(cur_entry),
duke@435 610 dirty_cards*card_size_in_words);
duke@435 611 cl->do_MemRegion(cur_cards);
duke@435 612 }
duke@435 613 }
duke@435 614 }
duke@435 615 }
duke@435 616 }
duke@435 617
ysr@777 618 MemRegion CardTableModRefBS::dirty_card_range_after_reset(MemRegion mr,
ysr@777 619 bool reset,
ysr@777 620 int reset_val) {
duke@435 621 for (int i = 0; i < _cur_covered_regions; i++) {
duke@435 622 MemRegion mri = mr.intersection(_covered[i]);
duke@435 623 if (!mri.is_empty()) {
duke@435 624 jbyte* cur_entry, *next_entry, *limit;
duke@435 625 for (cur_entry = byte_for(mri.start()), limit = byte_for(mri.last());
duke@435 626 cur_entry <= limit;
duke@435 627 cur_entry = next_entry) {
duke@435 628 next_entry = cur_entry + 1;
duke@435 629 if (*cur_entry == dirty_card) {
duke@435 630 size_t dirty_cards;
duke@435 631 // Accumulate maximal dirty card range, starting at cur_entry
duke@435 632 for (dirty_cards = 1;
duke@435 633 next_entry <= limit && *next_entry == dirty_card;
duke@435 634 dirty_cards++, next_entry++);
duke@435 635 MemRegion cur_cards(addr_for(cur_entry),
duke@435 636 dirty_cards*card_size_in_words);
ysr@777 637 if (reset) {
ysr@777 638 for (size_t i = 0; i < dirty_cards; i++) {
ysr@777 639 cur_entry[i] = reset_val;
ysr@777 640 }
duke@435 641 }
duke@435 642 return cur_cards;
duke@435 643 }
duke@435 644 }
duke@435 645 }
duke@435 646 }
duke@435 647 return MemRegion(mr.end(), mr.end());
duke@435 648 }
duke@435 649
duke@435 650 uintx CardTableModRefBS::ct_max_alignment_constraint() {
duke@435 651 return card_size * os::vm_page_size();
duke@435 652 }
duke@435 653
duke@435 654 void CardTableModRefBS::verify_guard() {
duke@435 655 // For product build verification
duke@435 656 guarantee(_byte_map[_guard_index] == last_card,
duke@435 657 "card table guard has been modified");
duke@435 658 }
duke@435 659
duke@435 660 void CardTableModRefBS::verify() {
duke@435 661 verify_guard();
duke@435 662 }
duke@435 663
duke@435 664 #ifndef PRODUCT
tonyp@2849 665 void CardTableModRefBS::verify_region(MemRegion mr,
tonyp@2849 666 jbyte val, bool val_equals) {
tonyp@2849 667 jbyte* start = byte_for(mr.start());
tonyp@2849 668 jbyte* end = byte_for(mr.last());
tschatzl@7051 669 bool failures = false;
tonyp@2849 670 for (jbyte* curr = start; curr <= end; ++curr) {
tonyp@2849 671 jbyte curr_val = *curr;
tonyp@2849 672 bool failed = (val_equals) ? (curr_val != val) : (curr_val == val);
tonyp@2849 673 if (failed) {
tonyp@2849 674 if (!failures) {
tonyp@2849 675 tty->cr();
drchase@6680 676 tty->print_cr("== CT verification failed: [" INTPTR_FORMAT "," INTPTR_FORMAT "]", p2i(start), p2i(end));
tonyp@2849 677 tty->print_cr("== %sexpecting value: %d",
tonyp@2849 678 (val_equals) ? "" : "not ", val);
tonyp@2849 679 failures = true;
tonyp@2849 680 }
tonyp@2849 681 tty->print_cr("== card "PTR_FORMAT" ["PTR_FORMAT","PTR_FORMAT"], "
drchase@6680 682 "val: %d", p2i(curr), p2i(addr_for(curr)),
drchase@6680 683 p2i((HeapWord*) (((size_t) addr_for(curr)) + card_size)),
tonyp@2849 684 (int) curr_val);
tonyp@2849 685 }
duke@435 686 }
tonyp@2849 687 guarantee(!failures, "there should not have been any failures");
duke@435 688 }
apetrusenko@1375 689
tonyp@2849 690 void CardTableModRefBS::verify_not_dirty_region(MemRegion mr) {
tonyp@2849 691 verify_region(mr, dirty_card, false /* val_equals */);
tonyp@2849 692 }
apetrusenko@1375 693
apetrusenko@1375 694 void CardTableModRefBS::verify_dirty_region(MemRegion mr) {
tonyp@2849 695 verify_region(mr, dirty_card, true /* val_equals */);
apetrusenko@1375 696 }
duke@435 697 #endif
duke@435 698
never@3687 699 void CardTableModRefBS::print_on(outputStream* st) const {
never@3687 700 st->print_cr("Card table byte_map: [" INTPTR_FORMAT "," INTPTR_FORMAT "] byte_map_base: " INTPTR_FORMAT,
drchase@6680 701 p2i(_byte_map), p2i(_byte_map + _byte_map_size), p2i(byte_map_base));
never@3687 702 }
never@3687 703
duke@435 704 bool CardTableModRefBSForCTRS::card_will_be_scanned(jbyte cv) {
duke@435 705 return
duke@435 706 CardTableModRefBS::card_will_be_scanned(cv) ||
duke@435 707 _rs->is_prev_nonclean_card_val(cv);
duke@435 708 };
duke@435 709
duke@435 710 bool CardTableModRefBSForCTRS::card_may_have_been_dirty(jbyte cv) {
duke@435 711 return
duke@435 712 cv != clean_card &&
duke@435 713 (CardTableModRefBS::card_may_have_been_dirty(cv) ||
duke@435 714 CardTableRS::youngergen_may_have_been_dirty(cv));
duke@435 715 };

mercurial