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

Tue, 30 Sep 2008 12:20:22 -0700

author
jcoomes
date
Tue, 30 Sep 2008 12:20:22 -0700
changeset 810
81cd571500b0
parent 809
a4b729f5b611
child 811
0166ac265d53
permissions
-rw-r--r--

6725697: par compact - rename class ChunkData to RegionData
Reviewed-by: iveresov, tonyp

duke@435 1 /*
xdono@631 2 * Copyright 2005-2008 Sun Microsystems, Inc. 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 *
duke@435 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@435 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@435 21 * have any questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 #include "incls/_precompiled.incl"
duke@435 26 #include "incls/_psParallelCompact.cpp.incl"
duke@435 27
duke@435 28 #include <math.h>
duke@435 29
duke@435 30 // All sizes are in HeapWords.
jcoomes@810 31 const size_t ParallelCompactData::Log2RegionSize = 9; // 512 words
jcoomes@810 32 const size_t ParallelCompactData::RegionSize = (size_t)1 << Log2RegionSize;
jcoomes@810 33 const size_t ParallelCompactData::RegionSizeBytes =
jcoomes@810 34 RegionSize << LogHeapWordSize;
jcoomes@810 35 const size_t ParallelCompactData::RegionSizeOffsetMask = RegionSize - 1;
jcoomes@810 36 const size_t ParallelCompactData::RegionAddrOffsetMask = RegionSizeBytes - 1;
jcoomes@810 37 const size_t ParallelCompactData::RegionAddrMask = ~RegionAddrOffsetMask;
duke@435 38
duke@435 39 // 32-bit: 128 words covers 4 bitmap words
duke@435 40 // 64-bit: 128 words covers 2 bitmap words
duke@435 41 const size_t ParallelCompactData::Log2BlockSize = 7; // 128 words
duke@435 42 const size_t ParallelCompactData::BlockSize = (size_t)1 << Log2BlockSize;
duke@435 43 const size_t ParallelCompactData::BlockOffsetMask = BlockSize - 1;
duke@435 44 const size_t ParallelCompactData::BlockMask = ~BlockOffsetMask;
duke@435 45
jcoomes@810 46 const size_t ParallelCompactData::BlocksPerRegion = RegionSize / BlockSize;
jcoomes@810 47
jcoomes@810 48 const ParallelCompactData::RegionData::region_sz_t
jcoomes@810 49 ParallelCompactData::RegionData::dc_shift = 27;
jcoomes@810 50
jcoomes@810 51 const ParallelCompactData::RegionData::region_sz_t
jcoomes@810 52 ParallelCompactData::RegionData::dc_mask = ~0U << dc_shift;
jcoomes@810 53
jcoomes@810 54 const ParallelCompactData::RegionData::region_sz_t
jcoomes@810 55 ParallelCompactData::RegionData::dc_one = 0x1U << dc_shift;
jcoomes@810 56
jcoomes@810 57 const ParallelCompactData::RegionData::region_sz_t
jcoomes@810 58 ParallelCompactData::RegionData::los_mask = ~dc_mask;
jcoomes@810 59
jcoomes@810 60 const ParallelCompactData::RegionData::region_sz_t
jcoomes@810 61 ParallelCompactData::RegionData::dc_claimed = 0x8U << dc_shift;
jcoomes@810 62
jcoomes@810 63 const ParallelCompactData::RegionData::region_sz_t
jcoomes@810 64 ParallelCompactData::RegionData::dc_completed = 0xcU << dc_shift;
duke@435 65
duke@435 66 #ifdef ASSERT
duke@435 67 short ParallelCompactData::BlockData::_cur_phase = 0;
duke@435 68 #endif
duke@435 69
duke@435 70 SpaceInfo PSParallelCompact::_space_info[PSParallelCompact::last_space_id];
duke@435 71 bool PSParallelCompact::_print_phases = false;
duke@435 72
duke@435 73 ReferenceProcessor* PSParallelCompact::_ref_processor = NULL;
duke@435 74 klassOop PSParallelCompact::_updated_int_array_klass_obj = NULL;
duke@435 75
duke@435 76 double PSParallelCompact::_dwl_mean;
duke@435 77 double PSParallelCompact::_dwl_std_dev;
duke@435 78 double PSParallelCompact::_dwl_first_term;
duke@435 79 double PSParallelCompact::_dwl_adjustment;
duke@435 80 #ifdef ASSERT
duke@435 81 bool PSParallelCompact::_dwl_initialized = false;
duke@435 82 #endif // #ifdef ASSERT
duke@435 83
duke@435 84 #ifdef VALIDATE_MARK_SWEEP
coleenp@548 85 GrowableArray<void*>* PSParallelCompact::_root_refs_stack = NULL;
duke@435 86 GrowableArray<oop> * PSParallelCompact::_live_oops = NULL;
duke@435 87 GrowableArray<oop> * PSParallelCompact::_live_oops_moved_to = NULL;
duke@435 88 GrowableArray<size_t>* PSParallelCompact::_live_oops_size = NULL;
duke@435 89 size_t PSParallelCompact::_live_oops_index = 0;
duke@435 90 size_t PSParallelCompact::_live_oops_index_at_perm = 0;
coleenp@548 91 GrowableArray<void*>* PSParallelCompact::_other_refs_stack = NULL;
coleenp@548 92 GrowableArray<void*>* PSParallelCompact::_adjusted_pointers = NULL;
duke@435 93 bool PSParallelCompact::_pointer_tracking = false;
duke@435 94 bool PSParallelCompact::_root_tracking = true;
duke@435 95
duke@435 96 GrowableArray<HeapWord*>* PSParallelCompact::_cur_gc_live_oops = NULL;
duke@435 97 GrowableArray<HeapWord*>* PSParallelCompact::_cur_gc_live_oops_moved_to = NULL;
duke@435 98 GrowableArray<size_t> * PSParallelCompact::_cur_gc_live_oops_size = NULL;
duke@435 99 GrowableArray<HeapWord*>* PSParallelCompact::_last_gc_live_oops = NULL;
duke@435 100 GrowableArray<HeapWord*>* PSParallelCompact::_last_gc_live_oops_moved_to = NULL;
duke@435 101 GrowableArray<size_t> * PSParallelCompact::_last_gc_live_oops_size = NULL;
duke@435 102 #endif
duke@435 103
duke@435 104 #ifndef PRODUCT
duke@435 105 const char* PSParallelCompact::space_names[] = {
duke@435 106 "perm", "old ", "eden", "from", "to "
duke@435 107 };
duke@435 108
jcoomes@810 109 void PSParallelCompact::print_region_ranges()
duke@435 110 {
duke@435 111 tty->print_cr("space bottom top end new_top");
duke@435 112 tty->print_cr("------ ---------- ---------- ---------- ----------");
duke@435 113
duke@435 114 for (unsigned int id = 0; id < last_space_id; ++id) {
duke@435 115 const MutableSpace* space = _space_info[id].space();
duke@435 116 tty->print_cr("%u %s "
jcoomes@699 117 SIZE_FORMAT_W(10) " " SIZE_FORMAT_W(10) " "
jcoomes@699 118 SIZE_FORMAT_W(10) " " SIZE_FORMAT_W(10) " ",
duke@435 119 id, space_names[id],
jcoomes@810 120 summary_data().addr_to_region_idx(space->bottom()),
jcoomes@810 121 summary_data().addr_to_region_idx(space->top()),
jcoomes@810 122 summary_data().addr_to_region_idx(space->end()),
jcoomes@810 123 summary_data().addr_to_region_idx(_space_info[id].new_top()));
duke@435 124 }
duke@435 125 }
duke@435 126
duke@435 127 void
jcoomes@810 128 print_generic_summary_region(size_t i, const ParallelCompactData::RegionData* c)
duke@435 129 {
jcoomes@810 130 #define REGION_IDX_FORMAT SIZE_FORMAT_W(7)
jcoomes@810 131 #define REGION_DATA_FORMAT SIZE_FORMAT_W(5)
duke@435 132
duke@435 133 ParallelCompactData& sd = PSParallelCompact::summary_data();
jcoomes@810 134 size_t dci = c->destination() ? sd.addr_to_region_idx(c->destination()) : 0;
jcoomes@810 135 tty->print_cr(REGION_IDX_FORMAT " " PTR_FORMAT " "
jcoomes@810 136 REGION_IDX_FORMAT " " PTR_FORMAT " "
jcoomes@810 137 REGION_DATA_FORMAT " " REGION_DATA_FORMAT " "
jcoomes@810 138 REGION_DATA_FORMAT " " REGION_IDX_FORMAT " %d",
duke@435 139 i, c->data_location(), dci, c->destination(),
duke@435 140 c->partial_obj_size(), c->live_obj_size(),
jcoomes@810 141 c->data_size(), c->source_region(), c->destination_count());
jcoomes@810 142
jcoomes@810 143 #undef REGION_IDX_FORMAT
jcoomes@810 144 #undef REGION_DATA_FORMAT
duke@435 145 }
duke@435 146
duke@435 147 void
duke@435 148 print_generic_summary_data(ParallelCompactData& summary_data,
duke@435 149 HeapWord* const beg_addr,
duke@435 150 HeapWord* const end_addr)
duke@435 151 {
duke@435 152 size_t total_words = 0;
jcoomes@810 153 size_t i = summary_data.addr_to_region_idx(beg_addr);
jcoomes@810 154 const size_t last = summary_data.addr_to_region_idx(end_addr);
duke@435 155 HeapWord* pdest = 0;
duke@435 156
duke@435 157 while (i <= last) {
jcoomes@810 158 ParallelCompactData::RegionData* c = summary_data.region(i);
duke@435 159 if (c->data_size() != 0 || c->destination() != pdest) {
jcoomes@810 160 print_generic_summary_region(i, c);
duke@435 161 total_words += c->data_size();
duke@435 162 pdest = c->destination();
duke@435 163 }
duke@435 164 ++i;
duke@435 165 }
duke@435 166
duke@435 167 tty->print_cr("summary_data_bytes=" SIZE_FORMAT, total_words * HeapWordSize);
duke@435 168 }
duke@435 169
duke@435 170 void
duke@435 171 print_generic_summary_data(ParallelCompactData& summary_data,
duke@435 172 SpaceInfo* space_info)
duke@435 173 {
duke@435 174 for (unsigned int id = 0; id < PSParallelCompact::last_space_id; ++id) {
duke@435 175 const MutableSpace* space = space_info[id].space();
duke@435 176 print_generic_summary_data(summary_data, space->bottom(),
duke@435 177 MAX2(space->top(), space_info[id].new_top()));
duke@435 178 }
duke@435 179 }
duke@435 180
duke@435 181 void
jcoomes@810 182 print_initial_summary_region(size_t i,
jcoomes@810 183 const ParallelCompactData::RegionData* c,
jcoomes@810 184 bool newline = true)
duke@435 185 {
jcoomes@699 186 tty->print(SIZE_FORMAT_W(5) " " PTR_FORMAT " "
jcoomes@699 187 SIZE_FORMAT_W(5) " " SIZE_FORMAT_W(5) " "
jcoomes@699 188 SIZE_FORMAT_W(5) " " SIZE_FORMAT_W(5) " %d",
duke@435 189 i, c->destination(),
duke@435 190 c->partial_obj_size(), c->live_obj_size(),
jcoomes@810 191 c->data_size(), c->source_region(), c->destination_count());
duke@435 192 if (newline) tty->cr();
duke@435 193 }
duke@435 194
duke@435 195 void
duke@435 196 print_initial_summary_data(ParallelCompactData& summary_data,
duke@435 197 const MutableSpace* space) {
duke@435 198 if (space->top() == space->bottom()) {
duke@435 199 return;
duke@435 200 }
duke@435 201
jcoomes@810 202 const size_t region_size = ParallelCompactData::RegionSize;
jcoomes@810 203 typedef ParallelCompactData::RegionData RegionData;
jcoomes@810 204 HeapWord* const top_aligned_up = summary_data.region_align_up(space->top());
jcoomes@810 205 const size_t end_region = summary_data.addr_to_region_idx(top_aligned_up);
jcoomes@810 206 const RegionData* c = summary_data.region(end_region - 1);
duke@435 207 HeapWord* end_addr = c->destination() + c->data_size();
duke@435 208 const size_t live_in_space = pointer_delta(end_addr, space->bottom());
duke@435 209
jcoomes@810 210 // Print (and count) the full regions at the beginning of the space.
jcoomes@810 211 size_t full_region_count = 0;
jcoomes@810 212 size_t i = summary_data.addr_to_region_idx(space->bottom());
jcoomes@810 213 while (i < end_region && summary_data.region(i)->data_size() == region_size) {
jcoomes@810 214 print_initial_summary_region(i, summary_data.region(i));
jcoomes@810 215 ++full_region_count;
duke@435 216 ++i;
duke@435 217 }
duke@435 218
jcoomes@810 219 size_t live_to_right = live_in_space - full_region_count * region_size;
duke@435 220
duke@435 221 double max_reclaimed_ratio = 0.0;
jcoomes@810 222 size_t max_reclaimed_ratio_region = 0;
duke@435 223 size_t max_dead_to_right = 0;
duke@435 224 size_t max_live_to_right = 0;
duke@435 225
jcoomes@810 226 // Print the 'reclaimed ratio' for regions while there is something live in
jcoomes@810 227 // the region or to the right of it. The remaining regions are empty (and
duke@435 228 // uninteresting), and computing the ratio will result in division by 0.
jcoomes@810 229 while (i < end_region && live_to_right > 0) {
jcoomes@810 230 c = summary_data.region(i);
jcoomes@810 231 HeapWord* const region_addr = summary_data.region_to_addr(i);
jcoomes@810 232 const size_t used_to_right = pointer_delta(space->top(), region_addr);
duke@435 233 const size_t dead_to_right = used_to_right - live_to_right;
duke@435 234 const double reclaimed_ratio = double(dead_to_right) / live_to_right;
duke@435 235
duke@435 236 if (reclaimed_ratio > max_reclaimed_ratio) {
duke@435 237 max_reclaimed_ratio = reclaimed_ratio;
jcoomes@810 238 max_reclaimed_ratio_region = i;
duke@435 239 max_dead_to_right = dead_to_right;
duke@435 240 max_live_to_right = live_to_right;
duke@435 241 }
duke@435 242
jcoomes@810 243 print_initial_summary_region(i, c, false);
jcoomes@699 244 tty->print_cr(" %12.10f " SIZE_FORMAT_W(10) " " SIZE_FORMAT_W(10),
duke@435 245 reclaimed_ratio, dead_to_right, live_to_right);
duke@435 246
duke@435 247 live_to_right -= c->data_size();
duke@435 248 ++i;
duke@435 249 }
duke@435 250
jcoomes@810 251 // Any remaining regions are empty. Print one more if there is one.
jcoomes@810 252 if (i < end_region) {
jcoomes@810 253 print_initial_summary_region(i, summary_data.region(i));
duke@435 254 }
duke@435 255
jcoomes@699 256 tty->print_cr("max: " SIZE_FORMAT_W(4) " d2r=" SIZE_FORMAT_W(10) " "
jcoomes@699 257 "l2r=" SIZE_FORMAT_W(10) " max_ratio=%14.12f",
jcoomes@810 258 max_reclaimed_ratio_region, max_dead_to_right,
duke@435 259 max_live_to_right, max_reclaimed_ratio);
duke@435 260 }
duke@435 261
duke@435 262 void
duke@435 263 print_initial_summary_data(ParallelCompactData& summary_data,
duke@435 264 SpaceInfo* space_info) {
duke@435 265 unsigned int id = PSParallelCompact::perm_space_id;
duke@435 266 const MutableSpace* space;
duke@435 267 do {
duke@435 268 space = space_info[id].space();
duke@435 269 print_initial_summary_data(summary_data, space);
duke@435 270 } while (++id < PSParallelCompact::eden_space_id);
duke@435 271
duke@435 272 do {
duke@435 273 space = space_info[id].space();
duke@435 274 print_generic_summary_data(summary_data, space->bottom(), space->top());
duke@435 275 } while (++id < PSParallelCompact::last_space_id);
duke@435 276 }
duke@435 277 #endif // #ifndef PRODUCT
duke@435 278
duke@435 279 #ifdef ASSERT
duke@435 280 size_t add_obj_count;
duke@435 281 size_t add_obj_size;
duke@435 282 size_t mark_bitmap_count;
duke@435 283 size_t mark_bitmap_size;
duke@435 284 #endif // #ifdef ASSERT
duke@435 285
duke@435 286 ParallelCompactData::ParallelCompactData()
duke@435 287 {
duke@435 288 _region_start = 0;
duke@435 289
jcoomes@810 290 _region_vspace = 0;
jcoomes@810 291 _region_data = 0;
jcoomes@810 292 _region_count = 0;
duke@435 293
duke@435 294 _block_vspace = 0;
duke@435 295 _block_data = 0;
duke@435 296 _block_count = 0;
duke@435 297 }
duke@435 298
duke@435 299 bool ParallelCompactData::initialize(MemRegion covered_region)
duke@435 300 {
duke@435 301 _region_start = covered_region.start();
duke@435 302 const size_t region_size = covered_region.word_size();
duke@435 303 DEBUG_ONLY(_region_end = _region_start + region_size;)
duke@435 304
jcoomes@810 305 assert(region_align_down(_region_start) == _region_start,
duke@435 306 "region start not aligned");
jcoomes@810 307 assert((region_size & RegionSizeOffsetMask) == 0,
jcoomes@810 308 "region size not a multiple of RegionSize");
jcoomes@810 309
jcoomes@810 310 bool result = initialize_region_data(region_size);
duke@435 311
duke@435 312 // Initialize the block data if it will be used for updating pointers, or if
duke@435 313 // this is a debug build.
jcoomes@810 314 if (!UseParallelOldGCRegionPointerCalc || trueInDebug) {
duke@435 315 result = result && initialize_block_data(region_size);
duke@435 316 }
duke@435 317
duke@435 318 return result;
duke@435 319 }
duke@435 320
duke@435 321 PSVirtualSpace*
duke@435 322 ParallelCompactData::create_vspace(size_t count, size_t element_size)
duke@435 323 {
duke@435 324 const size_t raw_bytes = count * element_size;
duke@435 325 const size_t page_sz = os::page_size_for_region(raw_bytes, raw_bytes, 10);
duke@435 326 const size_t granularity = os::vm_allocation_granularity();
duke@435 327 const size_t bytes = align_size_up(raw_bytes, MAX2(page_sz, granularity));
duke@435 328
duke@435 329 const size_t rs_align = page_sz == (size_t) os::vm_page_size() ? 0 :
duke@435 330 MAX2(page_sz, granularity);
jcoomes@514 331 ReservedSpace rs(bytes, rs_align, rs_align > 0);
duke@435 332 os::trace_page_sizes("par compact", raw_bytes, raw_bytes, page_sz, rs.base(),
duke@435 333 rs.size());
duke@435 334 PSVirtualSpace* vspace = new PSVirtualSpace(rs, page_sz);
duke@435 335 if (vspace != 0) {
duke@435 336 if (vspace->expand_by(bytes)) {
duke@435 337 return vspace;
duke@435 338 }
duke@435 339 delete vspace;
coleenp@672 340 // Release memory reserved in the space.
coleenp@672 341 rs.release();
duke@435 342 }
duke@435 343
duke@435 344 return 0;
duke@435 345 }
duke@435 346
jcoomes@810 347 bool ParallelCompactData::initialize_region_data(size_t region_size)
duke@435 348 {
jcoomes@810 349 const size_t count = (region_size + RegionSizeOffsetMask) >> Log2RegionSize;
jcoomes@810 350 _region_vspace = create_vspace(count, sizeof(RegionData));
jcoomes@810 351 if (_region_vspace != 0) {
jcoomes@810 352 _region_data = (RegionData*)_region_vspace->reserved_low_addr();
jcoomes@810 353 _region_count = count;
duke@435 354 return true;
duke@435 355 }
duke@435 356 return false;
duke@435 357 }
duke@435 358
duke@435 359 bool ParallelCompactData::initialize_block_data(size_t region_size)
duke@435 360 {
duke@435 361 const size_t count = (region_size + BlockOffsetMask) >> Log2BlockSize;
duke@435 362 _block_vspace = create_vspace(count, sizeof(BlockData));
duke@435 363 if (_block_vspace != 0) {
duke@435 364 _block_data = (BlockData*)_block_vspace->reserved_low_addr();
duke@435 365 _block_count = count;
duke@435 366 return true;
duke@435 367 }
duke@435 368 return false;
duke@435 369 }
duke@435 370
duke@435 371 void ParallelCompactData::clear()
duke@435 372 {
duke@435 373 if (_block_data) {
duke@435 374 memset(_block_data, 0, _block_vspace->committed_size());
duke@435 375 }
jcoomes@810 376 memset(_region_data, 0, _region_vspace->committed_size());
duke@435 377 }
duke@435 378
jcoomes@810 379 void ParallelCompactData::clear_range(size_t beg_region, size_t end_region) {
jcoomes@810 380 assert(beg_region <= _region_count, "beg_region out of range");
jcoomes@810 381 assert(end_region <= _region_count, "end_region out of range");
jcoomes@810 382 assert(RegionSize % BlockSize == 0, "RegionSize not a multiple of BlockSize");
jcoomes@810 383
jcoomes@810 384 const size_t region_cnt = end_region - beg_region;
duke@435 385
duke@435 386 if (_block_data) {
jcoomes@810 387 const size_t blocks_per_region = RegionSize / BlockSize;
jcoomes@810 388 const size_t beg_block = beg_region * blocks_per_region;
jcoomes@810 389 const size_t block_cnt = region_cnt * blocks_per_region;
duke@435 390 memset(_block_data + beg_block, 0, block_cnt * sizeof(BlockData));
duke@435 391 }
jcoomes@810 392 memset(_region_data + beg_region, 0, region_cnt * sizeof(RegionData));
duke@435 393 }
duke@435 394
jcoomes@810 395 HeapWord* ParallelCompactData::partial_obj_end(size_t region_idx) const
duke@435 396 {
jcoomes@810 397 const RegionData* cur_cp = region(region_idx);
jcoomes@810 398 const RegionData* const end_cp = region(region_count() - 1);
jcoomes@810 399
jcoomes@810 400 HeapWord* result = region_to_addr(region_idx);
duke@435 401 if (cur_cp < end_cp) {
duke@435 402 do {
duke@435 403 result += cur_cp->partial_obj_size();
jcoomes@810 404 } while (cur_cp->partial_obj_size() == RegionSize && ++cur_cp < end_cp);
duke@435 405 }
duke@435 406 return result;
duke@435 407 }
duke@435 408
duke@435 409 void ParallelCompactData::add_obj(HeapWord* addr, size_t len)
duke@435 410 {
duke@435 411 const size_t obj_ofs = pointer_delta(addr, _region_start);
jcoomes@810 412 const size_t beg_region = obj_ofs >> Log2RegionSize;
jcoomes@810 413 const size_t end_region = (obj_ofs + len - 1) >> Log2RegionSize;
duke@435 414
duke@435 415 DEBUG_ONLY(Atomic::inc_ptr(&add_obj_count);)
duke@435 416 DEBUG_ONLY(Atomic::add_ptr(len, &add_obj_size);)
duke@435 417
jcoomes@810 418 if (beg_region == end_region) {
jcoomes@810 419 // All in one region.
jcoomes@810 420 _region_data[beg_region].add_live_obj(len);
duke@435 421 return;
duke@435 422 }
duke@435 423
jcoomes@810 424 // First region.
jcoomes@810 425 const size_t beg_ofs = region_offset(addr);
jcoomes@810 426 _region_data[beg_region].add_live_obj(RegionSize - beg_ofs);
duke@435 427
duke@435 428 klassOop klass = ((oop)addr)->klass();
jcoomes@810 429 // Middle regions--completely spanned by this object.
jcoomes@810 430 for (size_t region = beg_region + 1; region < end_region; ++region) {
jcoomes@810 431 _region_data[region].set_partial_obj_size(RegionSize);
jcoomes@810 432 _region_data[region].set_partial_obj_addr(addr);
duke@435 433 }
duke@435 434
jcoomes@810 435 // Last region.
jcoomes@810 436 const size_t end_ofs = region_offset(addr + len - 1);
jcoomes@810 437 _region_data[end_region].set_partial_obj_size(end_ofs + 1);
jcoomes@810 438 _region_data[end_region].set_partial_obj_addr(addr);
duke@435 439 }
duke@435 440
duke@435 441 void
duke@435 442 ParallelCompactData::summarize_dense_prefix(HeapWord* beg, HeapWord* end)
duke@435 443 {
jcoomes@810 444 assert(region_offset(beg) == 0, "not RegionSize aligned");
jcoomes@810 445 assert(region_offset(end) == 0, "not RegionSize aligned");
jcoomes@810 446
jcoomes@810 447 size_t cur_region = addr_to_region_idx(beg);
jcoomes@810 448 const size_t end_region = addr_to_region_idx(end);
duke@435 449 HeapWord* addr = beg;
jcoomes@810 450 while (cur_region < end_region) {
jcoomes@810 451 _region_data[cur_region].set_destination(addr);
jcoomes@810 452 _region_data[cur_region].set_destination_count(0);
jcoomes@810 453 _region_data[cur_region].set_source_region(cur_region);
jcoomes@810 454 _region_data[cur_region].set_data_location(addr);
jcoomes@810 455
jcoomes@810 456 // Update live_obj_size so the region appears completely full.
jcoomes@810 457 size_t live_size = RegionSize - _region_data[cur_region].partial_obj_size();
jcoomes@810 458 _region_data[cur_region].set_live_obj_size(live_size);
jcoomes@810 459
jcoomes@810 460 ++cur_region;
jcoomes@810 461 addr += RegionSize;
duke@435 462 }
duke@435 463 }
duke@435 464
duke@435 465 bool ParallelCompactData::summarize(HeapWord* target_beg, HeapWord* target_end,
duke@435 466 HeapWord* source_beg, HeapWord* source_end,
duke@435 467 HeapWord** target_next,
duke@435 468 HeapWord** source_next) {
duke@435 469 // This is too strict.
jcoomes@810 470 // assert(region_offset(source_beg) == 0, "not RegionSize aligned");
duke@435 471
duke@435 472 if (TraceParallelOldGCSummaryPhase) {
duke@435 473 tty->print_cr("tb=" PTR_FORMAT " te=" PTR_FORMAT " "
duke@435 474 "sb=" PTR_FORMAT " se=" PTR_FORMAT " "
duke@435 475 "tn=" PTR_FORMAT " sn=" PTR_FORMAT,
duke@435 476 target_beg, target_end,
duke@435 477 source_beg, source_end,
duke@435 478 target_next != 0 ? *target_next : (HeapWord*) 0,
duke@435 479 source_next != 0 ? *source_next : (HeapWord*) 0);
duke@435 480 }
duke@435 481
jcoomes@810 482 size_t cur_region = addr_to_region_idx(source_beg);
jcoomes@810 483 const size_t end_region = addr_to_region_idx(region_align_up(source_end));
duke@435 484
duke@435 485 HeapWord *dest_addr = target_beg;
jcoomes@810 486 while (cur_region < end_region) {
jcoomes@810 487 size_t words = _region_data[cur_region].data_size();
duke@435 488
duke@435 489 #if 1
duke@435 490 assert(pointer_delta(target_end, dest_addr) >= words,
duke@435 491 "source region does not fit into target region");
duke@435 492 #else
jcoomes@810 493 // XXX - need some work on the corner cases here. If the region does not
jcoomes@810 494 // fit, then must either make sure any partial_obj from the region fits, or
jcoomes@810 495 // "undo" the initial part of the partial_obj that is in the previous
jcoomes@810 496 // region.
duke@435 497 if (dest_addr + words >= target_end) {
duke@435 498 // Let the caller know where to continue.
duke@435 499 *target_next = dest_addr;
jcoomes@810 500 *source_next = region_to_addr(cur_region);
duke@435 501 return false;
duke@435 502 }
duke@435 503 #endif // #if 1
duke@435 504
jcoomes@810 505 _region_data[cur_region].set_destination(dest_addr);
jcoomes@810 506
jcoomes@810 507 // Set the destination_count for cur_region, and if necessary, update
jcoomes@810 508 // source_region for a destination region. The source_region field is
jcoomes@810 509 // updated if cur_region is the first (left-most) region to be copied to a
jcoomes@810 510 // destination region.
duke@435 511 //
jcoomes@810 512 // The destination_count calculation is a bit subtle. A region that has
jcoomes@810 513 // data that compacts into itself does not count itself as a destination.
jcoomes@810 514 // This maintains the invariant that a zero count means the region is
jcoomes@810 515 // available and can be claimed and then filled.
duke@435 516 if (words > 0) {
duke@435 517 HeapWord* const last_addr = dest_addr + words - 1;
jcoomes@810 518 const size_t dest_region_1 = addr_to_region_idx(dest_addr);
jcoomes@810 519 const size_t dest_region_2 = addr_to_region_idx(last_addr);
duke@435 520 #if 0
jcoomes@810 521 // Initially assume that the destination regions will be the same and
duke@435 522 // adjust the value below if necessary. Under this assumption, if
jcoomes@810 523 // cur_region == dest_region_2, then cur_region will be compacted
jcoomes@810 524 // completely into itself.
jcoomes@810 525 uint destination_count = cur_region == dest_region_2 ? 0 : 1;
jcoomes@810 526 if (dest_region_1 != dest_region_2) {
jcoomes@810 527 // Destination regions differ; adjust destination_count.
duke@435 528 destination_count += 1;
jcoomes@810 529 // Data from cur_region will be copied to the start of dest_region_2.
jcoomes@810 530 _region_data[dest_region_2].set_source_region(cur_region);
jcoomes@810 531 } else if (region_offset(dest_addr) == 0) {
jcoomes@810 532 // Data from cur_region will be copied to the start of the destination
jcoomes@810 533 // region.
jcoomes@810 534 _region_data[dest_region_1].set_source_region(cur_region);
duke@435 535 }
duke@435 536 #else
jcoomes@810 537 // Initially assume that the destination regions will be different and
duke@435 538 // adjust the value below if necessary. Under this assumption, if
jcoomes@810 539 // cur_region == dest_region2, then cur_region will be compacted partially
jcoomes@810 540 // into dest_region_1 and partially into itself.
jcoomes@810 541 uint destination_count = cur_region == dest_region_2 ? 1 : 2;
jcoomes@810 542 if (dest_region_1 != dest_region_2) {
jcoomes@810 543 // Data from cur_region will be copied to the start of dest_region_2.
jcoomes@810 544 _region_data[dest_region_2].set_source_region(cur_region);
duke@435 545 } else {
jcoomes@810 546 // Destination regions are the same; adjust destination_count.
duke@435 547 destination_count -= 1;
jcoomes@810 548 if (region_offset(dest_addr) == 0) {
jcoomes@810 549 // Data from cur_region will be copied to the start of the destination
jcoomes@810 550 // region.
jcoomes@810 551 _region_data[dest_region_1].set_source_region(cur_region);
duke@435 552 }
duke@435 553 }
duke@435 554 #endif // #if 0
duke@435 555
jcoomes@810 556 _region_data[cur_region].set_destination_count(destination_count);
jcoomes@810 557 _region_data[cur_region].set_data_location(region_to_addr(cur_region));
duke@435 558 dest_addr += words;
duke@435 559 }
duke@435 560
jcoomes@810 561 ++cur_region;
duke@435 562 }
duke@435 563
duke@435 564 *target_next = dest_addr;
duke@435 565 return true;
duke@435 566 }
duke@435 567
duke@435 568 bool ParallelCompactData::partial_obj_ends_in_block(size_t block_index) {
duke@435 569 HeapWord* block_addr = block_to_addr(block_index);
duke@435 570 HeapWord* block_end_addr = block_addr + BlockSize;
jcoomes@810 571 size_t region_index = addr_to_region_idx(block_addr);
jcoomes@810 572 HeapWord* partial_obj_end_addr = partial_obj_end(region_index);
duke@435 573
duke@435 574 // An object that ends at the end of the block, ends
duke@435 575 // in the block (the last word of the object is to
duke@435 576 // the left of the end).
duke@435 577 if ((block_addr < partial_obj_end_addr) &&
duke@435 578 (partial_obj_end_addr <= block_end_addr)) {
duke@435 579 return true;
duke@435 580 }
duke@435 581
duke@435 582 return false;
duke@435 583 }
duke@435 584
duke@435 585 HeapWord* ParallelCompactData::calc_new_pointer(HeapWord* addr) {
duke@435 586 HeapWord* result = NULL;
jcoomes@810 587 if (UseParallelOldGCRegionPointerCalc) {
jcoomes@810 588 result = region_calc_new_pointer(addr);
duke@435 589 } else {
duke@435 590 result = block_calc_new_pointer(addr);
duke@435 591 }
duke@435 592 return result;
duke@435 593 }
duke@435 594
duke@435 595 // This method is overly complicated (expensive) to be called
duke@435 596 // for every reference.
duke@435 597 // Try to restructure this so that a NULL is returned if
duke@435 598 // the object is dead. But don't wast the cycles to explicitly check
duke@435 599 // that it is dead since only live objects should be passed in.
duke@435 600
jcoomes@810 601 HeapWord* ParallelCompactData::region_calc_new_pointer(HeapWord* addr) {
duke@435 602 assert(addr != NULL, "Should detect NULL oop earlier");
duke@435 603 assert(PSParallelCompact::gc_heap()->is_in(addr), "addr not in heap");
duke@435 604 #ifdef ASSERT
duke@435 605 if (PSParallelCompact::mark_bitmap()->is_unmarked(addr)) {
duke@435 606 gclog_or_tty->print_cr("calc_new_pointer:: addr " PTR_FORMAT, addr);
duke@435 607 }
duke@435 608 #endif
duke@435 609 assert(PSParallelCompact::mark_bitmap()->is_marked(addr), "obj not marked");
duke@435 610
jcoomes@810 611 // Region covering the object.
jcoomes@810 612 size_t region_index = addr_to_region_idx(addr);
jcoomes@810 613 const RegionData* const region_ptr = region(region_index);
jcoomes@810 614 HeapWord* const region_addr = region_align_down(addr);
jcoomes@810 615
jcoomes@810 616 assert(addr < region_addr + RegionSize, "Region does not cover object");
jcoomes@810 617 assert(addr_to_region_ptr(region_addr) == region_ptr, "sanity check");
jcoomes@810 618
jcoomes@810 619 HeapWord* result = region_ptr->destination();
jcoomes@810 620
jcoomes@810 621 // If all the data in the region is live, then the new location of the object
jcoomes@810 622 // can be calculated from the destination of the region plus the offset of the
jcoomes@810 623 // object in the region.
jcoomes@810 624 if (region_ptr->data_size() == RegionSize) {
jcoomes@810 625 result += pointer_delta(addr, region_addr);
duke@435 626 return result;
duke@435 627 }
duke@435 628
duke@435 629 // The new location of the object is
jcoomes@810 630 // region destination +
jcoomes@810 631 // size of the partial object extending onto the region +
jcoomes@810 632 // sizes of the live objects in the Region that are to the left of addr
jcoomes@810 633 const size_t partial_obj_size = region_ptr->partial_obj_size();
jcoomes@810 634 HeapWord* const search_start = region_addr + partial_obj_size;
duke@435 635
duke@435 636 const ParMarkBitMap* bitmap = PSParallelCompact::mark_bitmap();
duke@435 637 size_t live_to_left = bitmap->live_words_in_range(search_start, oop(addr));
duke@435 638
duke@435 639 result += partial_obj_size + live_to_left;
duke@435 640 assert(result <= addr, "object cannot move to the right");
duke@435 641 return result;
duke@435 642 }
duke@435 643
duke@435 644 HeapWord* ParallelCompactData::block_calc_new_pointer(HeapWord* addr) {
duke@435 645 assert(addr != NULL, "Should detect NULL oop earlier");
duke@435 646 assert(PSParallelCompact::gc_heap()->is_in(addr), "addr not in heap");
duke@435 647 #ifdef ASSERT
duke@435 648 if (PSParallelCompact::mark_bitmap()->is_unmarked(addr)) {
duke@435 649 gclog_or_tty->print_cr("calc_new_pointer:: addr " PTR_FORMAT, addr);
duke@435 650 }
duke@435 651 #endif
duke@435 652 assert(PSParallelCompact::mark_bitmap()->is_marked(addr), "obj not marked");
duke@435 653
jcoomes@810 654 // Region covering the object.
jcoomes@810 655 size_t region_index = addr_to_region_idx(addr);
jcoomes@810 656 const RegionData* const region_ptr = region(region_index);
jcoomes@810 657 HeapWord* const region_addr = region_align_down(addr);
jcoomes@810 658
jcoomes@810 659 assert(addr < region_addr + RegionSize, "Region does not cover object");
jcoomes@810 660 assert(addr_to_region_ptr(region_addr) == region_ptr, "sanity check");
jcoomes@810 661
jcoomes@810 662 HeapWord* result = region_ptr->destination();
jcoomes@810 663
jcoomes@810 664 // If all the data in the region is live, then the new location of the object
jcoomes@810 665 // can be calculated from the destination of the region plus the offset of the
jcoomes@810 666 // object in the region.
jcoomes@810 667 if (region_ptr->data_size() == RegionSize) {
jcoomes@810 668 result += pointer_delta(addr, region_addr);
duke@435 669 return result;
duke@435 670 }
duke@435 671
duke@435 672 // The new location of the object is
jcoomes@810 673 // region destination +
duke@435 674 // block offset +
duke@435 675 // sizes of the live objects in the Block that are to the left of addr
duke@435 676 const size_t block_offset = addr_to_block_ptr(addr)->offset();
jcoomes@810 677 HeapWord* const search_start = region_addr + block_offset;
duke@435 678
duke@435 679 const ParMarkBitMap* bitmap = PSParallelCompact::mark_bitmap();
duke@435 680 size_t live_to_left = bitmap->live_words_in_range(search_start, oop(addr));
duke@435 681
duke@435 682 result += block_offset + live_to_left;
duke@435 683 assert(result <= addr, "object cannot move to the right");
jcoomes@810 684 assert(result == region_calc_new_pointer(addr), "Should match");
duke@435 685 return result;
duke@435 686 }
duke@435 687
duke@435 688 klassOop ParallelCompactData::calc_new_klass(klassOop old_klass) {
duke@435 689 klassOop updated_klass;
duke@435 690 if (PSParallelCompact::should_update_klass(old_klass)) {
duke@435 691 updated_klass = (klassOop) calc_new_pointer(old_klass);
duke@435 692 } else {
duke@435 693 updated_klass = old_klass;
duke@435 694 }
duke@435 695
duke@435 696 return updated_klass;
duke@435 697 }
duke@435 698
duke@435 699 #ifdef ASSERT
duke@435 700 void ParallelCompactData::verify_clear(const PSVirtualSpace* vspace)
duke@435 701 {
duke@435 702 const size_t* const beg = (const size_t*)vspace->committed_low_addr();
duke@435 703 const size_t* const end = (const size_t*)vspace->committed_high_addr();
duke@435 704 for (const size_t* p = beg; p < end; ++p) {
duke@435 705 assert(*p == 0, "not zero");
duke@435 706 }
duke@435 707 }
duke@435 708
duke@435 709 void ParallelCompactData::verify_clear()
duke@435 710 {
jcoomes@810 711 verify_clear(_region_vspace);
duke@435 712 verify_clear(_block_vspace);
duke@435 713 }
duke@435 714 #endif // #ifdef ASSERT
duke@435 715
duke@435 716 #ifdef NOT_PRODUCT
jcoomes@810 717 ParallelCompactData::RegionData* debug_region(size_t region_index) {
duke@435 718 ParallelCompactData& sd = PSParallelCompact::summary_data();
jcoomes@810 719 return sd.region(region_index);
duke@435 720 }
duke@435 721 #endif
duke@435 722
duke@435 723 elapsedTimer PSParallelCompact::_accumulated_time;
duke@435 724 unsigned int PSParallelCompact::_total_invocations = 0;
duke@435 725 unsigned int PSParallelCompact::_maximum_compaction_gc_num = 0;
duke@435 726 jlong PSParallelCompact::_time_of_last_gc = 0;
duke@435 727 CollectorCounters* PSParallelCompact::_counters = NULL;
duke@435 728 ParMarkBitMap PSParallelCompact::_mark_bitmap;
duke@435 729 ParallelCompactData PSParallelCompact::_summary_data;
duke@435 730
duke@435 731 PSParallelCompact::IsAliveClosure PSParallelCompact::_is_alive_closure;
coleenp@548 732
coleenp@548 733 void PSParallelCompact::IsAliveClosure::do_object(oop p) { ShouldNotReachHere(); }
coleenp@548 734 bool PSParallelCompact::IsAliveClosure::do_object_b(oop p) { return mark_bitmap()->is_marked(p); }
coleenp@548 735
coleenp@548 736 void PSParallelCompact::KeepAliveClosure::do_oop(oop* p) { PSParallelCompact::KeepAliveClosure::do_oop_work(p); }
coleenp@548 737 void PSParallelCompact::KeepAliveClosure::do_oop(narrowOop* p) { PSParallelCompact::KeepAliveClosure::do_oop_work(p); }
coleenp@548 738
duke@435 739 PSParallelCompact::AdjustPointerClosure PSParallelCompact::_adjust_root_pointer_closure(true);
duke@435 740 PSParallelCompact::AdjustPointerClosure PSParallelCompact::_adjust_pointer_closure(false);
duke@435 741
coleenp@548 742 void PSParallelCompact::AdjustPointerClosure::do_oop(oop* p) { adjust_pointer(p, _is_root); }
coleenp@548 743 void PSParallelCompact::AdjustPointerClosure::do_oop(narrowOop* p) { adjust_pointer(p, _is_root); }
coleenp@548 744
coleenp@548 745 void PSParallelCompact::FollowStackClosure::do_void() { follow_stack(_compaction_manager); }
coleenp@548 746
coleenp@548 747 void PSParallelCompact::MarkAndPushClosure::do_oop(oop* p) { mark_and_push(_compaction_manager, p); }
coleenp@548 748 void PSParallelCompact::MarkAndPushClosure::do_oop(narrowOop* p) { mark_and_push(_compaction_manager, p); }
duke@435 749
duke@435 750 void PSParallelCompact::post_initialize() {
duke@435 751 ParallelScavengeHeap* heap = gc_heap();
duke@435 752 assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
duke@435 753
duke@435 754 MemRegion mr = heap->reserved_region();
duke@435 755 _ref_processor = ReferenceProcessor::create_ref_processor(
duke@435 756 mr, // span
duke@435 757 true, // atomic_discovery
duke@435 758 true, // mt_discovery
duke@435 759 &_is_alive_closure,
duke@435 760 ParallelGCThreads,
duke@435 761 ParallelRefProcEnabled);
duke@435 762 _counters = new CollectorCounters("PSParallelCompact", 1);
duke@435 763
duke@435 764 // Initialize static fields in ParCompactionManager.
duke@435 765 ParCompactionManager::initialize(mark_bitmap());
duke@435 766 }
duke@435 767
duke@435 768 bool PSParallelCompact::initialize() {
duke@435 769 ParallelScavengeHeap* heap = gc_heap();
duke@435 770 assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
duke@435 771 MemRegion mr = heap->reserved_region();
duke@435 772
duke@435 773 // Was the old gen get allocated successfully?
duke@435 774 if (!heap->old_gen()->is_allocated()) {
duke@435 775 return false;
duke@435 776 }
duke@435 777
duke@435 778 initialize_space_info();
duke@435 779 initialize_dead_wood_limiter();
duke@435 780
duke@435 781 if (!_mark_bitmap.initialize(mr)) {
duke@435 782 vm_shutdown_during_initialization("Unable to allocate bit map for "
duke@435 783 "parallel garbage collection for the requested heap size.");
duke@435 784 return false;
duke@435 785 }
duke@435 786
duke@435 787 if (!_summary_data.initialize(mr)) {
duke@435 788 vm_shutdown_during_initialization("Unable to allocate tables for "
duke@435 789 "parallel garbage collection for the requested heap size.");
duke@435 790 return false;
duke@435 791 }
duke@435 792
duke@435 793 return true;
duke@435 794 }
duke@435 795
duke@435 796 void PSParallelCompact::initialize_space_info()
duke@435 797 {
duke@435 798 memset(&_space_info, 0, sizeof(_space_info));
duke@435 799
duke@435 800 ParallelScavengeHeap* heap = gc_heap();
duke@435 801 PSYoungGen* young_gen = heap->young_gen();
duke@435 802 MutableSpace* perm_space = heap->perm_gen()->object_space();
duke@435 803
duke@435 804 _space_info[perm_space_id].set_space(perm_space);
duke@435 805 _space_info[old_space_id].set_space(heap->old_gen()->object_space());
duke@435 806 _space_info[eden_space_id].set_space(young_gen->eden_space());
duke@435 807 _space_info[from_space_id].set_space(young_gen->from_space());
duke@435 808 _space_info[to_space_id].set_space(young_gen->to_space());
duke@435 809
duke@435 810 _space_info[perm_space_id].set_start_array(heap->perm_gen()->start_array());
duke@435 811 _space_info[old_space_id].set_start_array(heap->old_gen()->start_array());
duke@435 812
duke@435 813 _space_info[perm_space_id].set_min_dense_prefix(perm_space->top());
duke@435 814 if (TraceParallelOldGCDensePrefix) {
duke@435 815 tty->print_cr("perm min_dense_prefix=" PTR_FORMAT,
duke@435 816 _space_info[perm_space_id].min_dense_prefix());
duke@435 817 }
duke@435 818 }
duke@435 819
duke@435 820 void PSParallelCompact::initialize_dead_wood_limiter()
duke@435 821 {
duke@435 822 const size_t max = 100;
duke@435 823 _dwl_mean = double(MIN2(ParallelOldDeadWoodLimiterMean, max)) / 100.0;
duke@435 824 _dwl_std_dev = double(MIN2(ParallelOldDeadWoodLimiterStdDev, max)) / 100.0;
duke@435 825 _dwl_first_term = 1.0 / (sqrt(2.0 * M_PI) * _dwl_std_dev);
duke@435 826 DEBUG_ONLY(_dwl_initialized = true;)
duke@435 827 _dwl_adjustment = normal_distribution(1.0);
duke@435 828 }
duke@435 829
duke@435 830 // Simple class for storing info about the heap at the start of GC, to be used
duke@435 831 // after GC for comparison/printing.
duke@435 832 class PreGCValues {
duke@435 833 public:
duke@435 834 PreGCValues() { }
duke@435 835 PreGCValues(ParallelScavengeHeap* heap) { fill(heap); }
duke@435 836
duke@435 837 void fill(ParallelScavengeHeap* heap) {
duke@435 838 _heap_used = heap->used();
duke@435 839 _young_gen_used = heap->young_gen()->used_in_bytes();
duke@435 840 _old_gen_used = heap->old_gen()->used_in_bytes();
duke@435 841 _perm_gen_used = heap->perm_gen()->used_in_bytes();
duke@435 842 };
duke@435 843
duke@435 844 size_t heap_used() const { return _heap_used; }
duke@435 845 size_t young_gen_used() const { return _young_gen_used; }
duke@435 846 size_t old_gen_used() const { return _old_gen_used; }
duke@435 847 size_t perm_gen_used() const { return _perm_gen_used; }
duke@435 848
duke@435 849 private:
duke@435 850 size_t _heap_used;
duke@435 851 size_t _young_gen_used;
duke@435 852 size_t _old_gen_used;
duke@435 853 size_t _perm_gen_used;
duke@435 854 };
duke@435 855
duke@435 856 void
duke@435 857 PSParallelCompact::clear_data_covering_space(SpaceId id)
duke@435 858 {
duke@435 859 // At this point, top is the value before GC, new_top() is the value that will
duke@435 860 // be set at the end of GC. The marking bitmap is cleared to top; nothing
duke@435 861 // should be marked above top. The summary data is cleared to the larger of
duke@435 862 // top & new_top.
duke@435 863 MutableSpace* const space = _space_info[id].space();
duke@435 864 HeapWord* const bot = space->bottom();
duke@435 865 HeapWord* const top = space->top();
duke@435 866 HeapWord* const max_top = MAX2(top, _space_info[id].new_top());
duke@435 867
duke@435 868 const idx_t beg_bit = _mark_bitmap.addr_to_bit(bot);
duke@435 869 const idx_t end_bit = BitMap::word_align_up(_mark_bitmap.addr_to_bit(top));
duke@435 870 _mark_bitmap.clear_range(beg_bit, end_bit);
duke@435 871
jcoomes@810 872 const size_t beg_region = _summary_data.addr_to_region_idx(bot);
jcoomes@810 873 const size_t end_region =
jcoomes@810 874 _summary_data.addr_to_region_idx(_summary_data.region_align_up(max_top));
jcoomes@810 875 _summary_data.clear_range(beg_region, end_region);
duke@435 876 }
duke@435 877
duke@435 878 void PSParallelCompact::pre_compact(PreGCValues* pre_gc_values)
duke@435 879 {
duke@435 880 // Update the from & to space pointers in space_info, since they are swapped
duke@435 881 // at each young gen gc. Do the update unconditionally (even though a
duke@435 882 // promotion failure does not swap spaces) because an unknown number of minor
duke@435 883 // collections will have swapped the spaces an unknown number of times.
duke@435 884 TraceTime tm("pre compact", print_phases(), true, gclog_or_tty);
duke@435 885 ParallelScavengeHeap* heap = gc_heap();
duke@435 886 _space_info[from_space_id].set_space(heap->young_gen()->from_space());
duke@435 887 _space_info[to_space_id].set_space(heap->young_gen()->to_space());
duke@435 888
duke@435 889 pre_gc_values->fill(heap);
duke@435 890
duke@435 891 ParCompactionManager::reset();
duke@435 892 NOT_PRODUCT(_mark_bitmap.reset_counters());
duke@435 893 DEBUG_ONLY(add_obj_count = add_obj_size = 0;)
duke@435 894 DEBUG_ONLY(mark_bitmap_count = mark_bitmap_size = 0;)
duke@435 895
duke@435 896 // Increment the invocation count
apetrusenko@574 897 heap->increment_total_collections(true);
duke@435 898
duke@435 899 // We need to track unique mark sweep invocations as well.
duke@435 900 _total_invocations++;
duke@435 901
duke@435 902 if (PrintHeapAtGC) {
duke@435 903 Universe::print_heap_before_gc();
duke@435 904 }
duke@435 905
duke@435 906 // Fill in TLABs
duke@435 907 heap->accumulate_statistics_all_tlabs();
duke@435 908 heap->ensure_parsability(true); // retire TLABs
duke@435 909
duke@435 910 if (VerifyBeforeGC && heap->total_collections() >= VerifyGCStartAt) {
duke@435 911 HandleMark hm; // Discard invalid handles created during verification
duke@435 912 gclog_or_tty->print(" VerifyBeforeGC:");
duke@435 913 Universe::verify(true);
duke@435 914 }
duke@435 915
duke@435 916 // Verify object start arrays
duke@435 917 if (VerifyObjectStartArray &&
duke@435 918 VerifyBeforeGC) {
duke@435 919 heap->old_gen()->verify_object_start_array();
duke@435 920 heap->perm_gen()->verify_object_start_array();
duke@435 921 }
duke@435 922
duke@435 923 DEBUG_ONLY(mark_bitmap()->verify_clear();)
duke@435 924 DEBUG_ONLY(summary_data().verify_clear();)
jcoomes@645 925
jcoomes@645 926 // Have worker threads release resources the next time they run a task.
jcoomes@645 927 gc_task_manager()->release_all_resources();
duke@435 928 }
duke@435 929
duke@435 930 void PSParallelCompact::post_compact()
duke@435 931 {
duke@435 932 TraceTime tm("post compact", print_phases(), true, gclog_or_tty);
duke@435 933
duke@435 934 // Clear the marking bitmap and summary data and update top() in each space.
duke@435 935 for (unsigned int id = perm_space_id; id < last_space_id; ++id) {
duke@435 936 clear_data_covering_space(SpaceId(id));
duke@435 937 _space_info[id].space()->set_top(_space_info[id].new_top());
duke@435 938 }
duke@435 939
duke@435 940 MutableSpace* const eden_space = _space_info[eden_space_id].space();
duke@435 941 MutableSpace* const from_space = _space_info[from_space_id].space();
duke@435 942 MutableSpace* const to_space = _space_info[to_space_id].space();
duke@435 943
duke@435 944 ParallelScavengeHeap* heap = gc_heap();
duke@435 945 bool eden_empty = eden_space->is_empty();
duke@435 946 if (!eden_empty) {
duke@435 947 eden_empty = absorb_live_data_from_eden(heap->size_policy(),
duke@435 948 heap->young_gen(), heap->old_gen());
duke@435 949 }
duke@435 950
duke@435 951 // Update heap occupancy information which is used as input to the soft ref
duke@435 952 // clearing policy at the next gc.
duke@435 953 Universe::update_heap_info_at_gc();
duke@435 954
duke@435 955 bool young_gen_empty = eden_empty && from_space->is_empty() &&
duke@435 956 to_space->is_empty();
duke@435 957
duke@435 958 BarrierSet* bs = heap->barrier_set();
duke@435 959 if (bs->is_a(BarrierSet::ModRef)) {
duke@435 960 ModRefBarrierSet* modBS = (ModRefBarrierSet*)bs;
duke@435 961 MemRegion old_mr = heap->old_gen()->reserved();
duke@435 962 MemRegion perm_mr = heap->perm_gen()->reserved();
duke@435 963 assert(perm_mr.end() <= old_mr.start(), "Generations out of order");
duke@435 964
duke@435 965 if (young_gen_empty) {
duke@435 966 modBS->clear(MemRegion(perm_mr.start(), old_mr.end()));
duke@435 967 } else {
duke@435 968 modBS->invalidate(MemRegion(perm_mr.start(), old_mr.end()));
duke@435 969 }
duke@435 970 }
duke@435 971
duke@435 972 Threads::gc_epilogue();
duke@435 973 CodeCache::gc_epilogue();
duke@435 974
duke@435 975 COMPILER2_PRESENT(DerivedPointerTable::update_pointers());
duke@435 976
duke@435 977 ref_processor()->enqueue_discovered_references(NULL);
duke@435 978
jmasa@698 979 if (ZapUnusedHeapArea) {
jmasa@698 980 heap->gen_mangle_unused_area();
jmasa@698 981 }
jmasa@698 982
duke@435 983 // Update time of last GC
duke@435 984 reset_millis_since_last_gc();
duke@435 985 }
duke@435 986
duke@435 987 HeapWord*
duke@435 988 PSParallelCompact::compute_dense_prefix_via_density(const SpaceId id,
duke@435 989 bool maximum_compaction)
duke@435 990 {
jcoomes@810 991 const size_t region_size = ParallelCompactData::RegionSize;
duke@435 992 const ParallelCompactData& sd = summary_data();
duke@435 993
duke@435 994 const MutableSpace* const space = _space_info[id].space();
jcoomes@810 995 HeapWord* const top_aligned_up = sd.region_align_up(space->top());
jcoomes@810 996 const RegionData* const beg_cp = sd.addr_to_region_ptr(space->bottom());
jcoomes@810 997 const RegionData* const end_cp = sd.addr_to_region_ptr(top_aligned_up);
jcoomes@810 998
jcoomes@810 999 // Skip full regions at the beginning of the space--they are necessarily part
duke@435 1000 // of the dense prefix.
duke@435 1001 size_t full_count = 0;
jcoomes@810 1002 const RegionData* cp;
jcoomes@810 1003 for (cp = beg_cp; cp < end_cp && cp->data_size() == region_size; ++cp) {
duke@435 1004 ++full_count;
duke@435 1005 }
duke@435 1006
duke@435 1007 assert(total_invocations() >= _maximum_compaction_gc_num, "sanity");
duke@435 1008 const size_t gcs_since_max = total_invocations() - _maximum_compaction_gc_num;
duke@435 1009 const bool interval_ended = gcs_since_max > HeapMaximumCompactionInterval;
duke@435 1010 if (maximum_compaction || cp == end_cp || interval_ended) {
duke@435 1011 _maximum_compaction_gc_num = total_invocations();
jcoomes@810 1012 return sd.region_to_addr(cp);
duke@435 1013 }
duke@435 1014
duke@435 1015 HeapWord* const new_top = _space_info[id].new_top();
duke@435 1016 const size_t space_live = pointer_delta(new_top, space->bottom());
duke@435 1017 const size_t space_used = space->used_in_words();
duke@435 1018 const size_t space_capacity = space->capacity_in_words();
duke@435 1019
duke@435 1020 const double cur_density = double(space_live) / space_capacity;
duke@435 1021 const double deadwood_density =
duke@435 1022 (1.0 - cur_density) * (1.0 - cur_density) * cur_density * cur_density;
duke@435 1023 const size_t deadwood_goal = size_t(space_capacity * deadwood_density);
duke@435 1024
duke@435 1025 if (TraceParallelOldGCDensePrefix) {
duke@435 1026 tty->print_cr("cur_dens=%5.3f dw_dens=%5.3f dw_goal=" SIZE_FORMAT,
duke@435 1027 cur_density, deadwood_density, deadwood_goal);
duke@435 1028 tty->print_cr("space_live=" SIZE_FORMAT " " "space_used=" SIZE_FORMAT " "
duke@435 1029 "space_cap=" SIZE_FORMAT,
duke@435 1030 space_live, space_used,
duke@435 1031 space_capacity);
duke@435 1032 }
duke@435 1033
duke@435 1034 // XXX - Use binary search?
jcoomes@810 1035 HeapWord* dense_prefix = sd.region_to_addr(cp);
jcoomes@810 1036 const RegionData* full_cp = cp;
jcoomes@810 1037 const RegionData* const top_cp = sd.addr_to_region_ptr(space->top() - 1);
duke@435 1038 while (cp < end_cp) {
jcoomes@810 1039 HeapWord* region_destination = cp->destination();
jcoomes@810 1040 const size_t cur_deadwood = pointer_delta(dense_prefix, region_destination);
duke@435 1041 if (TraceParallelOldGCDensePrefix && Verbose) {
jcoomes@699 1042 tty->print_cr("c#=" SIZE_FORMAT_W(4) " dst=" PTR_FORMAT " "
jcoomes@699 1043 "dp=" SIZE_FORMAT_W(8) " " "cdw=" SIZE_FORMAT_W(8),
jcoomes@810 1044 sd.region(cp), region_destination,
duke@435 1045 dense_prefix, cur_deadwood);
duke@435 1046 }
duke@435 1047
duke@435 1048 if (cur_deadwood >= deadwood_goal) {
jcoomes@810 1049 // Found the region that has the correct amount of deadwood to the left.
jcoomes@810 1050 // This typically occurs after crossing a fairly sparse set of regions, so
jcoomes@810 1051 // iterate backwards over those sparse regions, looking for the region
jcoomes@810 1052 // that has the lowest density of live objects 'to the right.'
jcoomes@810 1053 size_t space_to_left = sd.region(cp) * region_size;
duke@435 1054 size_t live_to_left = space_to_left - cur_deadwood;
duke@435 1055 size_t space_to_right = space_capacity - space_to_left;
duke@435 1056 size_t live_to_right = space_live - live_to_left;
duke@435 1057 double density_to_right = double(live_to_right) / space_to_right;
duke@435 1058 while (cp > full_cp) {
duke@435 1059 --cp;
jcoomes@810 1060 const size_t prev_region_live_to_right = live_to_right -
jcoomes@810 1061 cp->data_size();
jcoomes@810 1062 const size_t prev_region_space_to_right = space_to_right + region_size;
jcoomes@810 1063 double prev_region_density_to_right =
jcoomes@810 1064 double(prev_region_live_to_right) / prev_region_space_to_right;
jcoomes@810 1065 if (density_to_right <= prev_region_density_to_right) {
duke@435 1066 return dense_prefix;
duke@435 1067 }
duke@435 1068 if (TraceParallelOldGCDensePrefix && Verbose) {
jcoomes@699 1069 tty->print_cr("backing up from c=" SIZE_FORMAT_W(4) " d2r=%10.8f "
jcoomes@810 1070 "pc_d2r=%10.8f", sd.region(cp), density_to_right,
jcoomes@810 1071 prev_region_density_to_right);
duke@435 1072 }
jcoomes@810 1073 dense_prefix -= region_size;
jcoomes@810 1074 live_to_right = prev_region_live_to_right;
jcoomes@810 1075 space_to_right = prev_region_space_to_right;
jcoomes@810 1076 density_to_right = prev_region_density_to_right;
duke@435 1077 }
duke@435 1078 return dense_prefix;
duke@435 1079 }
duke@435 1080
jcoomes@810 1081 dense_prefix += region_size;
duke@435 1082 ++cp;
duke@435 1083 }
duke@435 1084
duke@435 1085 return dense_prefix;
duke@435 1086 }
duke@435 1087
duke@435 1088 #ifndef PRODUCT
duke@435 1089 void PSParallelCompact::print_dense_prefix_stats(const char* const algorithm,
duke@435 1090 const SpaceId id,
duke@435 1091 const bool maximum_compaction,
duke@435 1092 HeapWord* const addr)
duke@435 1093 {
jcoomes@810 1094 const size_t region_idx = summary_data().addr_to_region_idx(addr);
jcoomes@810 1095 RegionData* const cp = summary_data().region(region_idx);
duke@435 1096 const MutableSpace* const space = _space_info[id].space();
duke@435 1097 HeapWord* const new_top = _space_info[id].new_top();
duke@435 1098
duke@435 1099 const size_t space_live = pointer_delta(new_top, space->bottom());
duke@435 1100 const size_t dead_to_left = pointer_delta(addr, cp->destination());
duke@435 1101 const size_t space_cap = space->capacity_in_words();
duke@435 1102 const double dead_to_left_pct = double(dead_to_left) / space_cap;
duke@435 1103 const size_t live_to_right = new_top - cp->destination();
duke@435 1104 const size_t dead_to_right = space->top() - addr - live_to_right;
duke@435 1105
jcoomes@699 1106 tty->print_cr("%s=" PTR_FORMAT " dpc=" SIZE_FORMAT_W(5) " "
duke@435 1107 "spl=" SIZE_FORMAT " "
duke@435 1108 "d2l=" SIZE_FORMAT " d2l%%=%6.4f "
duke@435 1109 "d2r=" SIZE_FORMAT " l2r=" SIZE_FORMAT
duke@435 1110 " ratio=%10.8f",
jcoomes@810 1111 algorithm, addr, region_idx,
duke@435 1112 space_live,
duke@435 1113 dead_to_left, dead_to_left_pct,
duke@435 1114 dead_to_right, live_to_right,
duke@435 1115 double(dead_to_right) / live_to_right);
duke@435 1116 }
duke@435 1117 #endif // #ifndef PRODUCT
duke@435 1118
duke@435 1119 // Return a fraction indicating how much of the generation can be treated as
duke@435 1120 // "dead wood" (i.e., not reclaimed). The function uses a normal distribution
duke@435 1121 // based on the density of live objects in the generation to determine a limit,
duke@435 1122 // which is then adjusted so the return value is min_percent when the density is
duke@435 1123 // 1.
duke@435 1124 //
duke@435 1125 // The following table shows some return values for a different values of the
duke@435 1126 // standard deviation (ParallelOldDeadWoodLimiterStdDev); the mean is 0.5 and
duke@435 1127 // min_percent is 1.
duke@435 1128 //
duke@435 1129 // fraction allowed as dead wood
duke@435 1130 // -----------------------------------------------------------------
duke@435 1131 // density std_dev=70 std_dev=75 std_dev=80 std_dev=85 std_dev=90 std_dev=95
duke@435 1132 // ------- ---------- ---------- ---------- ---------- ---------- ----------
duke@435 1133 // 0.00000 0.01000000 0.01000000 0.01000000 0.01000000 0.01000000 0.01000000
duke@435 1134 // 0.05000 0.03193096 0.02836880 0.02550828 0.02319280 0.02130337 0.01974941
duke@435 1135 // 0.10000 0.05247504 0.04547452 0.03988045 0.03537016 0.03170171 0.02869272
duke@435 1136 // 0.15000 0.07135702 0.06111390 0.05296419 0.04641639 0.04110601 0.03676066
duke@435 1137 // 0.20000 0.08831616 0.07509618 0.06461766 0.05622444 0.04943437 0.04388975
duke@435 1138 // 0.25000 0.10311208 0.08724696 0.07471205 0.06469760 0.05661313 0.05002313
duke@435 1139 // 0.30000 0.11553050 0.09741183 0.08313394 0.07175114 0.06257797 0.05511132
duke@435 1140 // 0.35000 0.12538832 0.10545958 0.08978741 0.07731366 0.06727491 0.05911289
duke@435 1141 // 0.40000 0.13253818 0.11128511 0.09459590 0.08132834 0.07066107 0.06199500
duke@435 1142 // 0.45000 0.13687208 0.11481163 0.09750361 0.08375387 0.07270534 0.06373386
duke@435 1143 // 0.50000 0.13832410 0.11599237 0.09847664 0.08456518 0.07338887 0.06431510
duke@435 1144 // 0.55000 0.13687208 0.11481163 0.09750361 0.08375387 0.07270534 0.06373386
duke@435 1145 // 0.60000 0.13253818 0.11128511 0.09459590 0.08132834 0.07066107 0.06199500
duke@435 1146 // 0.65000 0.12538832 0.10545958 0.08978741 0.07731366 0.06727491 0.05911289
duke@435 1147 // 0.70000 0.11553050 0.09741183 0.08313394 0.07175114 0.06257797 0.05511132
duke@435 1148 // 0.75000 0.10311208 0.08724696 0.07471205 0.06469760 0.05661313 0.05002313
duke@435 1149 // 0.80000 0.08831616 0.07509618 0.06461766 0.05622444 0.04943437 0.04388975
duke@435 1150 // 0.85000 0.07135702 0.06111390 0.05296419 0.04641639 0.04110601 0.03676066
duke@435 1151 // 0.90000 0.05247504 0.04547452 0.03988045 0.03537016 0.03170171 0.02869272
duke@435 1152 // 0.95000 0.03193096 0.02836880 0.02550828 0.02319280 0.02130337 0.01974941
duke@435 1153 // 1.00000 0.01000000 0.01000000 0.01000000 0.01000000 0.01000000 0.01000000
duke@435 1154
duke@435 1155 double PSParallelCompact::dead_wood_limiter(double density, size_t min_percent)
duke@435 1156 {
duke@435 1157 assert(_dwl_initialized, "uninitialized");
duke@435 1158
duke@435 1159 // The raw limit is the value of the normal distribution at x = density.
duke@435 1160 const double raw_limit = normal_distribution(density);
duke@435 1161
duke@435 1162 // Adjust the raw limit so it becomes the minimum when the density is 1.
duke@435 1163 //
duke@435 1164 // First subtract the adjustment value (which is simply the precomputed value
duke@435 1165 // normal_distribution(1.0)); this yields a value of 0 when the density is 1.
duke@435 1166 // Then add the minimum value, so the minimum is returned when the density is
duke@435 1167 // 1. Finally, prevent negative values, which occur when the mean is not 0.5.
duke@435 1168 const double min = double(min_percent) / 100.0;
duke@435 1169 const double limit = raw_limit - _dwl_adjustment + min;
duke@435 1170 return MAX2(limit, 0.0);
duke@435 1171 }
duke@435 1172
jcoomes@810 1173 ParallelCompactData::RegionData*
jcoomes@810 1174 PSParallelCompact::first_dead_space_region(const RegionData* beg,
jcoomes@810 1175 const RegionData* end)
duke@435 1176 {
jcoomes@810 1177 const size_t region_size = ParallelCompactData::RegionSize;
duke@435 1178 ParallelCompactData& sd = summary_data();
jcoomes@810 1179 size_t left = sd.region(beg);
jcoomes@810 1180 size_t right = end > beg ? sd.region(end) - 1 : left;
duke@435 1181
duke@435 1182 // Binary search.
duke@435 1183 while (left < right) {
duke@435 1184 // Equivalent to (left + right) / 2, but does not overflow.
duke@435 1185 const size_t middle = left + (right - left) / 2;
jcoomes@810 1186 RegionData* const middle_ptr = sd.region(middle);
duke@435 1187 HeapWord* const dest = middle_ptr->destination();
jcoomes@810 1188 HeapWord* const addr = sd.region_to_addr(middle);
duke@435 1189 assert(dest != NULL, "sanity");
duke@435 1190 assert(dest <= addr, "must move left");
duke@435 1191
duke@435 1192 if (middle > left && dest < addr) {
duke@435 1193 right = middle - 1;
jcoomes@810 1194 } else if (middle < right && middle_ptr->data_size() == region_size) {
duke@435 1195 left = middle + 1;
duke@435 1196 } else {
duke@435 1197 return middle_ptr;
duke@435 1198 }
duke@435 1199 }
jcoomes@810 1200 return sd.region(left);
duke@435 1201 }
duke@435 1202
jcoomes@810 1203 ParallelCompactData::RegionData*
jcoomes@810 1204 PSParallelCompact::dead_wood_limit_region(const RegionData* beg,
jcoomes@810 1205 const RegionData* end,
jcoomes@810 1206 size_t dead_words)
duke@435 1207 {
duke@435 1208 ParallelCompactData& sd = summary_data();
jcoomes@810 1209 size_t left = sd.region(beg);
jcoomes@810 1210 size_t right = end > beg ? sd.region(end) - 1 : left;
duke@435 1211
duke@435 1212 // Binary search.
duke@435 1213 while (left < right) {
duke@435 1214 // Equivalent to (left + right) / 2, but does not overflow.
duke@435 1215 const size_t middle = left + (right - left) / 2;
jcoomes@810 1216 RegionData* const middle_ptr = sd.region(middle);
duke@435 1217 HeapWord* const dest = middle_ptr->destination();
jcoomes@810 1218 HeapWord* const addr = sd.region_to_addr(middle);
duke@435 1219 assert(dest != NULL, "sanity");
duke@435 1220 assert(dest <= addr, "must move left");
duke@435 1221
duke@435 1222 const size_t dead_to_left = pointer_delta(addr, dest);
duke@435 1223 if (middle > left && dead_to_left > dead_words) {
duke@435 1224 right = middle - 1;
duke@435 1225 } else if (middle < right && dead_to_left < dead_words) {
duke@435 1226 left = middle + 1;
duke@435 1227 } else {
duke@435 1228 return middle_ptr;
duke@435 1229 }
duke@435 1230 }
jcoomes@810 1231 return sd.region(left);
duke@435 1232 }
duke@435 1233
duke@435 1234 // The result is valid during the summary phase, after the initial summarization
duke@435 1235 // of each space into itself, and before final summarization.
duke@435 1236 inline double
jcoomes@810 1237 PSParallelCompact::reclaimed_ratio(const RegionData* const cp,
duke@435 1238 HeapWord* const bottom,
duke@435 1239 HeapWord* const top,
duke@435 1240 HeapWord* const new_top)
duke@435 1241 {
duke@435 1242 ParallelCompactData& sd = summary_data();
duke@435 1243
duke@435 1244 assert(cp != NULL, "sanity");
duke@435 1245 assert(bottom != NULL, "sanity");
duke@435 1246 assert(top != NULL, "sanity");
duke@435 1247 assert(new_top != NULL, "sanity");
duke@435 1248 assert(top >= new_top, "summary data problem?");
duke@435 1249 assert(new_top > bottom, "space is empty; should not be here");
duke@435 1250 assert(new_top >= cp->destination(), "sanity");
jcoomes@810 1251 assert(top >= sd.region_to_addr(cp), "sanity");
duke@435 1252
duke@435 1253 HeapWord* const destination = cp->destination();
duke@435 1254 const size_t dense_prefix_live = pointer_delta(destination, bottom);
duke@435 1255 const size_t compacted_region_live = pointer_delta(new_top, destination);
jcoomes@810 1256 const size_t compacted_region_used = pointer_delta(top,
jcoomes@810 1257 sd.region_to_addr(cp));
duke@435 1258 const size_t reclaimable = compacted_region_used - compacted_region_live;
duke@435 1259
duke@435 1260 const double divisor = dense_prefix_live + 1.25 * compacted_region_live;
duke@435 1261 return double(reclaimable) / divisor;
duke@435 1262 }
duke@435 1263
duke@435 1264 // Return the address of the end of the dense prefix, a.k.a. the start of the
jcoomes@810 1265 // compacted region. The address is always on a region boundary.
duke@435 1266 //
jcoomes@810 1267 // Completely full regions at the left are skipped, since no compaction can
jcoomes@810 1268 // occur in those regions. Then the maximum amount of dead wood to allow is
jcoomes@810 1269 // computed, based on the density (amount live / capacity) of the generation;
jcoomes@810 1270 // the region with approximately that amount of dead space to the left is
jcoomes@810 1271 // identified as the limit region. Regions between the last completely full
jcoomes@810 1272 // region and the limit region are scanned and the one that has the best
jcoomes@810 1273 // (maximum) reclaimed_ratio() is selected.
duke@435 1274 HeapWord*
duke@435 1275 PSParallelCompact::compute_dense_prefix(const SpaceId id,
duke@435 1276 bool maximum_compaction)
duke@435 1277 {
jcoomes@810 1278 const size_t region_size = ParallelCompactData::RegionSize;
duke@435 1279 const ParallelCompactData& sd = summary_data();
duke@435 1280
duke@435 1281 const MutableSpace* const space = _space_info[id].space();
duke@435 1282 HeapWord* const top = space->top();
jcoomes@810 1283 HeapWord* const top_aligned_up = sd.region_align_up(top);
duke@435 1284 HeapWord* const new_top = _space_info[id].new_top();
jcoomes@810 1285 HeapWord* const new_top_aligned_up = sd.region_align_up(new_top);
duke@435 1286 HeapWord* const bottom = space->bottom();
jcoomes@810 1287 const RegionData* const beg_cp = sd.addr_to_region_ptr(bottom);
jcoomes@810 1288 const RegionData* const top_cp = sd.addr_to_region_ptr(top_aligned_up);
jcoomes@810 1289 const RegionData* const new_top_cp =
jcoomes@810 1290 sd.addr_to_region_ptr(new_top_aligned_up);
jcoomes@810 1291
jcoomes@810 1292 // Skip full regions at the beginning of the space--they are necessarily part
duke@435 1293 // of the dense prefix.
jcoomes@810 1294 const RegionData* const full_cp = first_dead_space_region(beg_cp, new_top_cp);
jcoomes@810 1295 assert(full_cp->destination() == sd.region_to_addr(full_cp) ||
duke@435 1296 space->is_empty(), "no dead space allowed to the left");
jcoomes@810 1297 assert(full_cp->data_size() < region_size || full_cp == new_top_cp - 1,
jcoomes@810 1298 "region must have dead space");
duke@435 1299
duke@435 1300 // The gc number is saved whenever a maximum compaction is done, and used to
duke@435 1301 // determine when the maximum compaction interval has expired. This avoids
duke@435 1302 // successive max compactions for different reasons.
duke@435 1303 assert(total_invocations() >= _maximum_compaction_gc_num, "sanity");
duke@435 1304 const size_t gcs_since_max = total_invocations() - _maximum_compaction_gc_num;
duke@435 1305 const bool interval_ended = gcs_since_max > HeapMaximumCompactionInterval ||
duke@435 1306 total_invocations() == HeapFirstMaximumCompactionCount;
duke@435 1307 if (maximum_compaction || full_cp == top_cp || interval_ended) {
duke@435 1308 _maximum_compaction_gc_num = total_invocations();
jcoomes@810 1309 return sd.region_to_addr(full_cp);
duke@435 1310 }
duke@435 1311
duke@435 1312 const size_t space_live = pointer_delta(new_top, bottom);
duke@435 1313 const size_t space_used = space->used_in_words();
duke@435 1314 const size_t space_capacity = space->capacity_in_words();
duke@435 1315
duke@435 1316 const double density = double(space_live) / double(space_capacity);
duke@435 1317 const size_t min_percent_free =
duke@435 1318 id == perm_space_id ? PermMarkSweepDeadRatio : MarkSweepDeadRatio;
duke@435 1319 const double limiter = dead_wood_limiter(density, min_percent_free);
duke@435 1320 const size_t dead_wood_max = space_used - space_live;
duke@435 1321 const size_t dead_wood_limit = MIN2(size_t(space_capacity * limiter),
duke@435 1322 dead_wood_max);
duke@435 1323
duke@435 1324 if (TraceParallelOldGCDensePrefix) {
duke@435 1325 tty->print_cr("space_live=" SIZE_FORMAT " " "space_used=" SIZE_FORMAT " "
duke@435 1326 "space_cap=" SIZE_FORMAT,
duke@435 1327 space_live, space_used,
duke@435 1328 space_capacity);
duke@435 1329 tty->print_cr("dead_wood_limiter(%6.4f, %d)=%6.4f "
duke@435 1330 "dead_wood_max=" SIZE_FORMAT " dead_wood_limit=" SIZE_FORMAT,
duke@435 1331 density, min_percent_free, limiter,
duke@435 1332 dead_wood_max, dead_wood_limit);
duke@435 1333 }
duke@435 1334
jcoomes@810 1335 // Locate the region with the desired amount of dead space to the left.
jcoomes@810 1336 const RegionData* const limit_cp =
jcoomes@810 1337 dead_wood_limit_region(full_cp, top_cp, dead_wood_limit);
jcoomes@810 1338
jcoomes@810 1339 // Scan from the first region with dead space to the limit region and find the
duke@435 1340 // one with the best (largest) reclaimed ratio.
duke@435 1341 double best_ratio = 0.0;
jcoomes@810 1342 const RegionData* best_cp = full_cp;
jcoomes@810 1343 for (const RegionData* cp = full_cp; cp < limit_cp; ++cp) {
duke@435 1344 double tmp_ratio = reclaimed_ratio(cp, bottom, top, new_top);
duke@435 1345 if (tmp_ratio > best_ratio) {
duke@435 1346 best_cp = cp;
duke@435 1347 best_ratio = tmp_ratio;
duke@435 1348 }
duke@435 1349 }
duke@435 1350
duke@435 1351 #if 0
jcoomes@810 1352 // Something to consider: if the region with the best ratio is 'close to' the
jcoomes@810 1353 // first region w/free space, choose the first region with free space
jcoomes@810 1354 // ("first-free"). The first-free region is usually near the start of the
duke@435 1355 // heap, which means we are copying most of the heap already, so copy a bit
duke@435 1356 // more to get complete compaction.
jcoomes@810 1357 if (pointer_delta(best_cp, full_cp, sizeof(RegionData)) < 4) {
duke@435 1358 _maximum_compaction_gc_num = total_invocations();
duke@435 1359 best_cp = full_cp;
duke@435 1360 }
duke@435 1361 #endif // #if 0
duke@435 1362
jcoomes@810 1363 return sd.region_to_addr(best_cp);
duke@435 1364 }
duke@435 1365
duke@435 1366 void PSParallelCompact::summarize_spaces_quick()
duke@435 1367 {
duke@435 1368 for (unsigned int i = 0; i < last_space_id; ++i) {
duke@435 1369 const MutableSpace* space = _space_info[i].space();
duke@435 1370 bool result = _summary_data.summarize(space->bottom(), space->end(),
duke@435 1371 space->bottom(), space->top(),
duke@435 1372 _space_info[i].new_top_addr());
duke@435 1373 assert(result, "should never fail");
duke@435 1374 _space_info[i].set_dense_prefix(space->bottom());
duke@435 1375 }
duke@435 1376 }
duke@435 1377
duke@435 1378 void PSParallelCompact::fill_dense_prefix_end(SpaceId id)
duke@435 1379 {
duke@435 1380 HeapWord* const dense_prefix_end = dense_prefix(id);
jcoomes@810 1381 const RegionData* region = _summary_data.addr_to_region_ptr(dense_prefix_end);
duke@435 1382 const idx_t dense_prefix_bit = _mark_bitmap.addr_to_bit(dense_prefix_end);
jcoomes@810 1383 if (dead_space_crosses_boundary(region, dense_prefix_bit)) {
duke@435 1384 // Only enough dead space is filled so that any remaining dead space to the
duke@435 1385 // left is larger than the minimum filler object. (The remainder is filled
duke@435 1386 // during the copy/update phase.)
duke@435 1387 //
duke@435 1388 // The size of the dead space to the right of the boundary is not a
duke@435 1389 // concern, since compaction will be able to use whatever space is
duke@435 1390 // available.
duke@435 1391 //
duke@435 1392 // Here '||' is the boundary, 'x' represents a don't care bit and a box
duke@435 1393 // surrounds the space to be filled with an object.
duke@435 1394 //
duke@435 1395 // In the 32-bit VM, each bit represents two 32-bit words:
duke@435 1396 // +---+
duke@435 1397 // a) beg_bits: ... x x x | 0 | || 0 x x ...
duke@435 1398 // end_bits: ... x x x | 0 | || 0 x x ...
duke@435 1399 // +---+
duke@435 1400 //
duke@435 1401 // In the 64-bit VM, each bit represents one 64-bit word:
duke@435 1402 // +------------+
duke@435 1403 // b) beg_bits: ... x x x | 0 || 0 | x x ...
duke@435 1404 // end_bits: ... x x 1 | 0 || 0 | x x ...
duke@435 1405 // +------------+
duke@435 1406 // +-------+
duke@435 1407 // c) beg_bits: ... x x | 0 0 | || 0 x x ...
duke@435 1408 // end_bits: ... x 1 | 0 0 | || 0 x x ...
duke@435 1409 // +-------+
duke@435 1410 // +-----------+
duke@435 1411 // d) beg_bits: ... x | 0 0 0 | || 0 x x ...
duke@435 1412 // end_bits: ... 1 | 0 0 0 | || 0 x x ...
duke@435 1413 // +-----------+
duke@435 1414 // +-------+
duke@435 1415 // e) beg_bits: ... 0 0 | 0 0 | || 0 x x ...
duke@435 1416 // end_bits: ... 0 0 | 0 0 | || 0 x x ...
duke@435 1417 // +-------+
duke@435 1418
duke@435 1419 // Initially assume case a, c or e will apply.
duke@435 1420 size_t obj_len = (size_t)oopDesc::header_size();
duke@435 1421 HeapWord* obj_beg = dense_prefix_end - obj_len;
duke@435 1422
duke@435 1423 #ifdef _LP64
duke@435 1424 if (_mark_bitmap.is_obj_end(dense_prefix_bit - 2)) {
duke@435 1425 // Case b above.
duke@435 1426 obj_beg = dense_prefix_end - 1;
duke@435 1427 } else if (!_mark_bitmap.is_obj_end(dense_prefix_bit - 3) &&
duke@435 1428 _mark_bitmap.is_obj_end(dense_prefix_bit - 4)) {
duke@435 1429 // Case d above.
duke@435 1430 obj_beg = dense_prefix_end - 3;
duke@435 1431 obj_len = 3;
duke@435 1432 }
duke@435 1433 #endif // #ifdef _LP64
duke@435 1434
duke@435 1435 MemRegion region(obj_beg, obj_len);
duke@435 1436 SharedHeap::fill_region_with_object(region);
duke@435 1437 _mark_bitmap.mark_obj(obj_beg, obj_len);
duke@435 1438 _summary_data.add_obj(obj_beg, obj_len);
duke@435 1439 assert(start_array(id) != NULL, "sanity");
duke@435 1440 start_array(id)->allocate_block(obj_beg);
duke@435 1441 }
duke@435 1442 }
duke@435 1443
duke@435 1444 void
duke@435 1445 PSParallelCompact::summarize_space(SpaceId id, bool maximum_compaction)
duke@435 1446 {
duke@435 1447 assert(id < last_space_id, "id out of range");
jcoomes@700 1448 assert(_space_info[id].dense_prefix() == _space_info[id].space()->bottom(),
jcoomes@700 1449 "should have been set in summarize_spaces_quick()");
duke@435 1450
duke@435 1451 const MutableSpace* space = _space_info[id].space();
jcoomes@700 1452 if (_space_info[id].new_top() != space->bottom()) {
jcoomes@700 1453 HeapWord* dense_prefix_end = compute_dense_prefix(id, maximum_compaction);
jcoomes@700 1454 _space_info[id].set_dense_prefix(dense_prefix_end);
duke@435 1455
duke@435 1456 #ifndef PRODUCT
jcoomes@700 1457 if (TraceParallelOldGCDensePrefix) {
jcoomes@700 1458 print_dense_prefix_stats("ratio", id, maximum_compaction,
jcoomes@700 1459 dense_prefix_end);
jcoomes@700 1460 HeapWord* addr = compute_dense_prefix_via_density(id, maximum_compaction);
jcoomes@700 1461 print_dense_prefix_stats("density", id, maximum_compaction, addr);
jcoomes@700 1462 }
jcoomes@700 1463 #endif // #ifndef PRODUCT
jcoomes@700 1464
jcoomes@700 1465 // If dead space crosses the dense prefix boundary, it is (at least
jcoomes@700 1466 // partially) filled with a dummy object, marked live and added to the
jcoomes@700 1467 // summary data. This simplifies the copy/update phase and must be done
jcoomes@700 1468 // before the final locations of objects are determined, to prevent leaving
jcoomes@700 1469 // a fragment of dead space that is too small to fill with an object.
jcoomes@700 1470 if (!maximum_compaction && dense_prefix_end != space->bottom()) {
jcoomes@700 1471 fill_dense_prefix_end(id);
jcoomes@700 1472 }
jcoomes@700 1473
jcoomes@810 1474 // Compute the destination of each Region, and thus each object.
jcoomes@700 1475 _summary_data.summarize_dense_prefix(space->bottom(), dense_prefix_end);
jcoomes@700 1476 _summary_data.summarize(dense_prefix_end, space->end(),
jcoomes@700 1477 dense_prefix_end, space->top(),
jcoomes@700 1478 _space_info[id].new_top_addr());
duke@435 1479 }
duke@435 1480
duke@435 1481 if (TraceParallelOldGCSummaryPhase) {
jcoomes@810 1482 const size_t region_size = ParallelCompactData::RegionSize;
jcoomes@700 1483 HeapWord* const dense_prefix_end = _space_info[id].dense_prefix();
jcoomes@810 1484 const size_t dp_region = _summary_data.addr_to_region_idx(dense_prefix_end);
duke@435 1485 const size_t dp_words = pointer_delta(dense_prefix_end, space->bottom());
jcoomes@700 1486 HeapWord* const new_top = _space_info[id].new_top();
jcoomes@810 1487 const HeapWord* nt_aligned_up = _summary_data.region_align_up(new_top);
duke@435 1488 const size_t cr_words = pointer_delta(nt_aligned_up, dense_prefix_end);
duke@435 1489 tty->print_cr("id=%d cap=" SIZE_FORMAT " dp=" PTR_FORMAT " "
jcoomes@810 1490 "dp_region=" SIZE_FORMAT " " "dp_count=" SIZE_FORMAT " "
duke@435 1491 "cr_count=" SIZE_FORMAT " " "nt=" PTR_FORMAT,
duke@435 1492 id, space->capacity_in_words(), dense_prefix_end,
jcoomes@810 1493 dp_region, dp_words / region_size,
jcoomes@810 1494 cr_words / region_size, new_top);
duke@435 1495 }
duke@435 1496 }
duke@435 1497
duke@435 1498 void PSParallelCompact::summary_phase(ParCompactionManager* cm,
duke@435 1499 bool maximum_compaction)
duke@435 1500 {
duke@435 1501 EventMark m("2 summarize");
duke@435 1502 TraceTime tm("summary phase", print_phases(), true, gclog_or_tty);
duke@435 1503 // trace("2");
duke@435 1504
duke@435 1505 #ifdef ASSERT
duke@435 1506 if (TraceParallelOldGCMarkingPhase) {
duke@435 1507 tty->print_cr("add_obj_count=" SIZE_FORMAT " "
duke@435 1508 "add_obj_bytes=" SIZE_FORMAT,
duke@435 1509 add_obj_count, add_obj_size * HeapWordSize);
duke@435 1510 tty->print_cr("mark_bitmap_count=" SIZE_FORMAT " "
duke@435 1511 "mark_bitmap_bytes=" SIZE_FORMAT,
duke@435 1512 mark_bitmap_count, mark_bitmap_size * HeapWordSize);
duke@435 1513 }
duke@435 1514 #endif // #ifdef ASSERT
duke@435 1515
duke@435 1516 // Quick summarization of each space into itself, to see how much is live.
duke@435 1517 summarize_spaces_quick();
duke@435 1518
duke@435 1519 if (TraceParallelOldGCSummaryPhase) {
duke@435 1520 tty->print_cr("summary_phase: after summarizing each space to self");
duke@435 1521 Universe::print();
jcoomes@810 1522 NOT_PRODUCT(print_region_ranges());
duke@435 1523 if (Verbose) {
duke@435 1524 NOT_PRODUCT(print_initial_summary_data(_summary_data, _space_info));
duke@435 1525 }
duke@435 1526 }
duke@435 1527
duke@435 1528 // The amount of live data that will end up in old space (assuming it fits).
duke@435 1529 size_t old_space_total_live = 0;
duke@435 1530 unsigned int id;
duke@435 1531 for (id = old_space_id; id < last_space_id; ++id) {
duke@435 1532 old_space_total_live += pointer_delta(_space_info[id].new_top(),
duke@435 1533 _space_info[id].space()->bottom());
duke@435 1534 }
duke@435 1535
duke@435 1536 const MutableSpace* old_space = _space_info[old_space_id].space();
duke@435 1537 if (old_space_total_live > old_space->capacity_in_words()) {
duke@435 1538 // XXX - should also try to expand
duke@435 1539 maximum_compaction = true;
duke@435 1540 } else if (!UseParallelOldGCDensePrefix) {
duke@435 1541 maximum_compaction = true;
duke@435 1542 }
duke@435 1543
duke@435 1544 // Permanent and Old generations.
duke@435 1545 summarize_space(perm_space_id, maximum_compaction);
duke@435 1546 summarize_space(old_space_id, maximum_compaction);
duke@435 1547
duke@435 1548 // Summarize the remaining spaces (those in the young gen) into old space. If
duke@435 1549 // the live data from a space doesn't fit, the existing summarization is left
duke@435 1550 // intact, so the data is compacted down within the space itself.
duke@435 1551 HeapWord** new_top_addr = _space_info[old_space_id].new_top_addr();
duke@435 1552 HeapWord* const target_space_end = old_space->end();
duke@435 1553 for (id = eden_space_id; id < last_space_id; ++id) {
duke@435 1554 const MutableSpace* space = _space_info[id].space();
duke@435 1555 const size_t live = pointer_delta(_space_info[id].new_top(),
duke@435 1556 space->bottom());
duke@435 1557 const size_t available = pointer_delta(target_space_end, *new_top_addr);
jcoomes@701 1558 if (live > 0 && live <= available) {
duke@435 1559 // All the live data will fit.
duke@435 1560 if (TraceParallelOldGCSummaryPhase) {
duke@435 1561 tty->print_cr("summarizing %d into old_space @ " PTR_FORMAT,
duke@435 1562 id, *new_top_addr);
duke@435 1563 }
duke@435 1564 _summary_data.summarize(*new_top_addr, target_space_end,
duke@435 1565 space->bottom(), space->top(),
duke@435 1566 new_top_addr);
duke@435 1567
jcoomes@810 1568 // Clear the source_region field for each region in the space.
jcoomes@701 1569 HeapWord* const new_top = _space_info[id].new_top();
jcoomes@810 1570 HeapWord* const clear_end = _summary_data.region_align_up(new_top);
jcoomes@810 1571 RegionData* beg_region =
jcoomes@810 1572 _summary_data.addr_to_region_ptr(space->bottom());
jcoomes@810 1573 RegionData* end_region = _summary_data.addr_to_region_ptr(clear_end);
jcoomes@810 1574 while (beg_region < end_region) {
jcoomes@810 1575 beg_region->set_source_region(0);
jcoomes@810 1576 ++beg_region;
duke@435 1577 }
jcoomes@701 1578
jcoomes@701 1579 // Reset the new_top value for the space.
jcoomes@701 1580 _space_info[id].set_new_top(space->bottom());
duke@435 1581 }
duke@435 1582 }
duke@435 1583
jcoomes@810 1584 // Fill in the block data after any changes to the regions have
duke@435 1585 // been made.
duke@435 1586 #ifdef ASSERT
duke@435 1587 summarize_blocks(cm, perm_space_id);
duke@435 1588 summarize_blocks(cm, old_space_id);
duke@435 1589 #else
jcoomes@810 1590 if (!UseParallelOldGCRegionPointerCalc) {
duke@435 1591 summarize_blocks(cm, perm_space_id);
duke@435 1592 summarize_blocks(cm, old_space_id);
duke@435 1593 }
duke@435 1594 #endif
duke@435 1595
duke@435 1596 if (TraceParallelOldGCSummaryPhase) {
duke@435 1597 tty->print_cr("summary_phase: after final summarization");
duke@435 1598 Universe::print();
jcoomes@810 1599 NOT_PRODUCT(print_region_ranges());
duke@435 1600 if (Verbose) {
duke@435 1601 NOT_PRODUCT(print_generic_summary_data(_summary_data, _space_info));
duke@435 1602 }
duke@435 1603 }
duke@435 1604 }
duke@435 1605
duke@435 1606 // Fill in the BlockData.
duke@435 1607 // Iterate over the spaces and within each space iterate over
jcoomes@810 1608 // the regions and fill in the BlockData for each region.
duke@435 1609
duke@435 1610 void PSParallelCompact::summarize_blocks(ParCompactionManager* cm,
duke@435 1611 SpaceId first_compaction_space_id) {
duke@435 1612 #if 0
duke@435 1613 DEBUG_ONLY(ParallelCompactData::BlockData::set_cur_phase(1);)
duke@435 1614 for (SpaceId cur_space_id = first_compaction_space_id;
duke@435 1615 cur_space_id != last_space_id;
duke@435 1616 cur_space_id = next_compaction_space_id(cur_space_id)) {
jcoomes@810 1617 // Iterate over the regions in the space
jcoomes@810 1618 size_t start_region_index =
jcoomes@810 1619 _summary_data.addr_to_region_idx(space(cur_space_id)->bottom());
duke@435 1620 BitBlockUpdateClosure bbu(mark_bitmap(),
duke@435 1621 cm,
jcoomes@810 1622 start_region_index);
duke@435 1623 // Iterate over blocks.
jcoomes@810 1624 for (size_t region_index = start_region_index;
jcoomes@810 1625 region_index < _summary_data.region_count() &&
jcoomes@810 1626 _summary_data.region_to_addr(region_index) <
jcoomes@810 1627 space(cur_space_id)->top();
jcoomes@810 1628 region_index++) {
jcoomes@810 1629
jcoomes@810 1630 // Reset the closure for the new region. Note that the closure
jcoomes@810 1631 // maintains some data that does not get reset for each region
duke@435 1632 // so a new instance of the closure is no appropriate.
jcoomes@810 1633 bbu.reset_region(region_index);
duke@435 1634
duke@435 1635 // Start the iteration with the first live object. This
jcoomes@810 1636 // may return the end of the region. That is acceptable since
duke@435 1637 // it will properly limit the iterations.
duke@435 1638 ParMarkBitMap::idx_t left_offset = mark_bitmap()->addr_to_bit(
jcoomes@810 1639 _summary_data.first_live_or_end_in_region(region_index));
jcoomes@810 1640
jcoomes@810 1641 // End the iteration at the end of the region.
jcoomes@810 1642 HeapWord* region_addr = _summary_data.region_to_addr(region_index);
jcoomes@810 1643 HeapWord* region_end = region_addr + ParallelCompactData::RegionSize;
duke@435 1644 ParMarkBitMap::idx_t right_offset =
jcoomes@810 1645 mark_bitmap()->addr_to_bit(region_end);
duke@435 1646
duke@435 1647 // Blocks that have not objects starting in them can be
duke@435 1648 // skipped because their data will never be used.
duke@435 1649 if (left_offset < right_offset) {
duke@435 1650
jcoomes@810 1651 // Iterate through the objects in the region.
duke@435 1652 ParMarkBitMap::idx_t last_offset =
duke@435 1653 mark_bitmap()->pair_iterate(&bbu, left_offset, right_offset);
duke@435 1654
duke@435 1655 // If last_offset is less than right_offset, then the iterations
duke@435 1656 // terminated while it was looking for an end bit. "last_offset"
duke@435 1657 // is then the offset for the last start bit. In this situation
duke@435 1658 // the "offset" field for the next block to the right (_cur_block + 1)
duke@435 1659 // will not have been update although there may be live data
jcoomes@810 1660 // to the left of the region.
duke@435 1661
duke@435 1662 size_t cur_block_plus_1 = bbu.cur_block() + 1;
duke@435 1663 HeapWord* cur_block_plus_1_addr =
duke@435 1664 _summary_data.block_to_addr(bbu.cur_block()) +
duke@435 1665 ParallelCompactData::BlockSize;
duke@435 1666 HeapWord* last_offset_addr = mark_bitmap()->bit_to_addr(last_offset);
duke@435 1667 #if 1 // This code works. The else doesn't but should. Why does it?
duke@435 1668 // The current block (cur_block()) has already been updated.
duke@435 1669 // The last block that may need to be updated is either the
duke@435 1670 // next block (current block + 1) or the block where the
duke@435 1671 // last object starts (which can be greater than the
duke@435 1672 // next block if there were no objects found in intervening
duke@435 1673 // blocks).
duke@435 1674 size_t last_block =
duke@435 1675 MAX2(bbu.cur_block() + 1,
duke@435 1676 _summary_data.addr_to_block_idx(last_offset_addr));
duke@435 1677 #else
duke@435 1678 // The current block has already been updated. The only block
duke@435 1679 // that remains to be updated is the block where the last
jcoomes@810 1680 // object in the region starts.
duke@435 1681 size_t last_block = _summary_data.addr_to_block_idx(last_offset_addr);
duke@435 1682 #endif
duke@435 1683 assert_bit_is_start(last_offset);
duke@435 1684 assert((last_block == _summary_data.block_count()) ||
duke@435 1685 (_summary_data.block(last_block)->raw_offset() == 0),
duke@435 1686 "Should not have been set");
jcoomes@810 1687 // Is the last block still in the current region? If still
jcoomes@810 1688 // in this region, update the last block (the counting that
duke@435 1689 // included the current block is meant for the offset of the last
jcoomes@810 1690 // block). If not in this region, do nothing. Should not
jcoomes@810 1691 // update a block in the next region.
jcoomes@810 1692 if (ParallelCompactData::region_contains_block(bbu.region_index(),
jcoomes@810 1693 last_block)) {
duke@435 1694 if (last_offset < right_offset) {
jcoomes@810 1695 // The last object started in this region but ends beyond
jcoomes@810 1696 // this region. Update the block for this last object.
duke@435 1697 assert(mark_bitmap()->is_marked(last_offset), "Should be marked");
duke@435 1698 // No end bit was found. The closure takes care of
duke@435 1699 // the cases where
duke@435 1700 // an objects crosses over into the next block
duke@435 1701 // an objects starts and ends in the next block
duke@435 1702 // It does not handle the case where an object is
duke@435 1703 // the first object in a later block and extends
jcoomes@810 1704 // past the end of the region (i.e., the closure
duke@435 1705 // only handles complete objects that are in the range
duke@435 1706 // it is given). That object is handed back here
duke@435 1707 // for any special consideration necessary.
duke@435 1708 //
duke@435 1709 // Is the first bit in the last block a start or end bit?
duke@435 1710 //
duke@435 1711 // If the partial object ends in the last block L,
duke@435 1712 // then the 1st bit in L may be an end bit.
duke@435 1713 //
duke@435 1714 // Else does the last object start in a block after the current
duke@435 1715 // block? A block AA will already have been updated if an
duke@435 1716 // object ends in the next block AA+1. An object found to end in
duke@435 1717 // the AA+1 is the trigger that updates AA. Objects are being
duke@435 1718 // counted in the current block for updaing a following
duke@435 1719 // block. An object may start in later block
jcoomes@810 1720 // block but may extend beyond the last block in the region.
duke@435 1721 // Updates are only done when the end of an object has been
duke@435 1722 // found. If the last object (covered by block L) starts
duke@435 1723 // beyond the current block, then no object ends in L (otherwise
duke@435 1724 // L would be the current block). So the first bit in L is
duke@435 1725 // a start bit.
duke@435 1726 //
duke@435 1727 // Else the last objects start in the current block and ends
jcoomes@810 1728 // beyond the region. The current block has already been
duke@435 1729 // updated and there is no later block (with an object
duke@435 1730 // starting in it) that needs to be updated.
duke@435 1731 //
duke@435 1732 if (_summary_data.partial_obj_ends_in_block(last_block)) {
duke@435 1733 _summary_data.block(last_block)->set_end_bit_offset(
duke@435 1734 bbu.live_data_left());
duke@435 1735 } else if (last_offset_addr >= cur_block_plus_1_addr) {
duke@435 1736 // The start of the object is on a later block
duke@435 1737 // (to the right of the current block and there are no
duke@435 1738 // complete live objects to the left of this last object
jcoomes@810 1739 // within the region.
duke@435 1740 // The first bit in the block is for the start of the
duke@435 1741 // last object.
duke@435 1742 _summary_data.block(last_block)->set_start_bit_offset(
duke@435 1743 bbu.live_data_left());
duke@435 1744 } else {
duke@435 1745 // The start of the last object was found in
jcoomes@810 1746 // the current region (which has already
duke@435 1747 // been updated).
duke@435 1748 assert(bbu.cur_block() ==
duke@435 1749 _summary_data.addr_to_block_idx(last_offset_addr),
duke@435 1750 "Should be a block already processed");
duke@435 1751 }
duke@435 1752 #ifdef ASSERT
duke@435 1753 // Is there enough block information to find this object?
jcoomes@810 1754 // The destination of the region has not been set so the
duke@435 1755 // values returned by calc_new_pointer() and
duke@435 1756 // block_calc_new_pointer() will only be
duke@435 1757 // offsets. But they should agree.
jcoomes@810 1758 HeapWord* moved_obj_with_regions =
jcoomes@810 1759 _summary_data.region_calc_new_pointer(last_offset_addr);
duke@435 1760 HeapWord* moved_obj_with_blocks =
duke@435 1761 _summary_data.calc_new_pointer(last_offset_addr);
jcoomes@810 1762 assert(moved_obj_with_regions == moved_obj_with_blocks,
duke@435 1763 "Block calculation is wrong");
duke@435 1764 #endif
duke@435 1765 } else if (last_block < _summary_data.block_count()) {
duke@435 1766 // Iterations ended looking for a start bit (but
duke@435 1767 // did not run off the end of the block table).
duke@435 1768 _summary_data.block(last_block)->set_start_bit_offset(
duke@435 1769 bbu.live_data_left());
duke@435 1770 }
duke@435 1771 }
duke@435 1772 #ifdef ASSERT
duke@435 1773 // Is there enough block information to find this object?
duke@435 1774 HeapWord* left_offset_addr = mark_bitmap()->bit_to_addr(left_offset);
jcoomes@810 1775 HeapWord* moved_obj_with_regions =
duke@435 1776 _summary_data.calc_new_pointer(left_offset_addr);
duke@435 1777 HeapWord* moved_obj_with_blocks =
duke@435 1778 _summary_data.calc_new_pointer(left_offset_addr);
jcoomes@810 1779 assert(moved_obj_with_regions == moved_obj_with_blocks,
duke@435 1780 "Block calculation is wrong");
duke@435 1781 #endif
duke@435 1782
jcoomes@810 1783 // Is there another block after the end of this region?
duke@435 1784 #ifdef ASSERT
duke@435 1785 if (last_block < _summary_data.block_count()) {
duke@435 1786 // No object may have been found in a block. If that
jcoomes@810 1787 // block is at the end of the region, the iteration will
duke@435 1788 // terminate without incrementing the current block so
duke@435 1789 // that the current block is not the last block in the
jcoomes@810 1790 // region. That situation precludes asserting that the
jcoomes@810 1791 // current block is the last block in the region. Assert
duke@435 1792 // the lesser condition that the current block does not
jcoomes@810 1793 // exceed the region.
duke@435 1794 assert(_summary_data.block_to_addr(last_block) <=
jcoomes@810 1795 (_summary_data.region_to_addr(region_index) +
jcoomes@810 1796 ParallelCompactData::RegionSize),
jcoomes@810 1797 "Region and block inconsistency");
duke@435 1798 assert(last_offset <= right_offset, "Iteration over ran end");
duke@435 1799 }
duke@435 1800 #endif
duke@435 1801 }
duke@435 1802 #ifdef ASSERT
duke@435 1803 if (PrintGCDetails && Verbose) {
jcoomes@810 1804 if (_summary_data.region(region_index)->partial_obj_size() == 1) {
duke@435 1805 size_t first_block =
jcoomes@810 1806 region_index / ParallelCompactData::BlocksPerRegion;
duke@435 1807 gclog_or_tty->print_cr("first_block " PTR_FORMAT
duke@435 1808 " _offset " PTR_FORMAT
duke@435 1809 "_first_is_start_bit %d",
duke@435 1810 first_block,
duke@435 1811 _summary_data.block(first_block)->raw_offset(),
duke@435 1812 _summary_data.block(first_block)->first_is_start_bit());
duke@435 1813 }
duke@435 1814 }
duke@435 1815 #endif
duke@435 1816 }
duke@435 1817 }
duke@435 1818 DEBUG_ONLY(ParallelCompactData::BlockData::set_cur_phase(16);)
duke@435 1819 #endif // #if 0
duke@435 1820 }
duke@435 1821
duke@435 1822 // This method should contain all heap-specific policy for invoking a full
duke@435 1823 // collection. invoke_no_policy() will only attempt to compact the heap; it
duke@435 1824 // will do nothing further. If we need to bail out for policy reasons, scavenge
duke@435 1825 // before full gc, or any other specialized behavior, it needs to be added here.
duke@435 1826 //
duke@435 1827 // Note that this method should only be called from the vm_thread while at a
duke@435 1828 // safepoint.
duke@435 1829 void PSParallelCompact::invoke(bool maximum_heap_compaction) {
duke@435 1830 assert(SafepointSynchronize::is_at_safepoint(), "should be at safepoint");
duke@435 1831 assert(Thread::current() == (Thread*)VMThread::vm_thread(),
duke@435 1832 "should be in vm thread");
duke@435 1833 ParallelScavengeHeap* heap = gc_heap();
duke@435 1834 GCCause::Cause gc_cause = heap->gc_cause();
duke@435 1835 assert(!heap->is_gc_active(), "not reentrant");
duke@435 1836
duke@435 1837 PSAdaptiveSizePolicy* policy = heap->size_policy();
duke@435 1838
duke@435 1839 // Before each allocation/collection attempt, find out from the
duke@435 1840 // policy object if GCs are, on the whole, taking too long. If so,
duke@435 1841 // bail out without attempting a collection. The exceptions are
duke@435 1842 // for explicitly requested GC's.
duke@435 1843 if (!policy->gc_time_limit_exceeded() ||
duke@435 1844 GCCause::is_user_requested_gc(gc_cause) ||
duke@435 1845 GCCause::is_serviceability_requested_gc(gc_cause)) {
duke@435 1846 IsGCActiveMark mark;
duke@435 1847
duke@435 1848 if (ScavengeBeforeFullGC) {
duke@435 1849 PSScavenge::invoke_no_policy();
duke@435 1850 }
duke@435 1851
duke@435 1852 PSParallelCompact::invoke_no_policy(maximum_heap_compaction);
duke@435 1853 }
duke@435 1854 }
duke@435 1855
jcoomes@810 1856 bool ParallelCompactData::region_contains(size_t region_index, HeapWord* addr) {
jcoomes@810 1857 size_t addr_region_index = addr_to_region_idx(addr);
jcoomes@810 1858 return region_index == addr_region_index;
duke@435 1859 }
duke@435 1860
jcoomes@810 1861 bool ParallelCompactData::region_contains_block(size_t region_index,
jcoomes@810 1862 size_t block_index) {
jcoomes@810 1863 size_t first_block_in_region = region_index * BlocksPerRegion;
jcoomes@810 1864 size_t last_block_in_region = (region_index + 1) * BlocksPerRegion - 1;
jcoomes@810 1865
jcoomes@810 1866 return (first_block_in_region <= block_index) &&
jcoomes@810 1867 (block_index <= last_block_in_region);
duke@435 1868 }
duke@435 1869
duke@435 1870 // This method contains no policy. You should probably
duke@435 1871 // be calling invoke() instead.
duke@435 1872 void PSParallelCompact::invoke_no_policy(bool maximum_heap_compaction) {
duke@435 1873 assert(SafepointSynchronize::is_at_safepoint(), "must be at a safepoint");
duke@435 1874 assert(ref_processor() != NULL, "Sanity");
duke@435 1875
apetrusenko@574 1876 if (GC_locker::check_active_before_gc()) {
duke@435 1877 return;
duke@435 1878 }
duke@435 1879
duke@435 1880 TimeStamp marking_start;
duke@435 1881 TimeStamp compaction_start;
duke@435 1882 TimeStamp collection_exit;
duke@435 1883
duke@435 1884 ParallelScavengeHeap* heap = gc_heap();
duke@435 1885 GCCause::Cause gc_cause = heap->gc_cause();
duke@435 1886 PSYoungGen* young_gen = heap->young_gen();
duke@435 1887 PSOldGen* old_gen = heap->old_gen();
duke@435 1888 PSPermGen* perm_gen = heap->perm_gen();
duke@435 1889 PSAdaptiveSizePolicy* size_policy = heap->size_policy();
duke@435 1890
jmasa@698 1891 if (ZapUnusedHeapArea) {
jmasa@698 1892 // Save information needed to minimize mangling
jmasa@698 1893 heap->record_gen_tops_before_GC();
jmasa@698 1894 }
jmasa@698 1895
duke@435 1896 _print_phases = PrintGCDetails && PrintParallelOldGCPhaseTimes;
duke@435 1897
duke@435 1898 // Make sure data structures are sane, make the heap parsable, and do other
duke@435 1899 // miscellaneous bookkeeping.
duke@435 1900 PreGCValues pre_gc_values;
duke@435 1901 pre_compact(&pre_gc_values);
duke@435 1902
jcoomes@645 1903 // Get the compaction manager reserved for the VM thread.
jcoomes@645 1904 ParCompactionManager* const vmthread_cm =
jcoomes@645 1905 ParCompactionManager::manager_array(gc_task_manager()->workers());
jcoomes@645 1906
duke@435 1907 // Place after pre_compact() where the number of invocations is incremented.
duke@435 1908 AdaptiveSizePolicyOutput(size_policy, heap->total_collections());
duke@435 1909
duke@435 1910 {
duke@435 1911 ResourceMark rm;
duke@435 1912 HandleMark hm;
duke@435 1913
duke@435 1914 const bool is_system_gc = gc_cause == GCCause::_java_lang_system_gc;
duke@435 1915
duke@435 1916 // This is useful for debugging but don't change the output the
duke@435 1917 // the customer sees.
duke@435 1918 const char* gc_cause_str = "Full GC";
duke@435 1919 if (is_system_gc && PrintGCDetails) {
duke@435 1920 gc_cause_str = "Full GC (System)";
duke@435 1921 }
duke@435 1922 gclog_or_tty->date_stamp(PrintGC && PrintGCDateStamps);
duke@435 1923 TraceCPUTime tcpu(PrintGCDetails, true, gclog_or_tty);
duke@435 1924 TraceTime t1(gc_cause_str, PrintGC, !PrintGCDetails, gclog_or_tty);
duke@435 1925 TraceCollectorStats tcs(counters());
duke@435 1926 TraceMemoryManagerStats tms(true /* Full GC */);
duke@435 1927
duke@435 1928 if (TraceGen1Time) accumulated_time()->start();
duke@435 1929
duke@435 1930 // Let the size policy know we're starting
duke@435 1931 size_policy->major_collection_begin();
duke@435 1932
duke@435 1933 // When collecting the permanent generation methodOops may be moving,
duke@435 1934 // so we either have to flush all bcp data or convert it into bci.
duke@435 1935 CodeCache::gc_prologue();
duke@435 1936 Threads::gc_prologue();
duke@435 1937
duke@435 1938 NOT_PRODUCT(ref_processor()->verify_no_references_recorded());
duke@435 1939 COMPILER2_PRESENT(DerivedPointerTable::clear());
duke@435 1940
duke@435 1941 ref_processor()->enable_discovery();
duke@435 1942
duke@435 1943 bool marked_for_unloading = false;
duke@435 1944
duke@435 1945 marking_start.update();
jcoomes@645 1946 marking_phase(vmthread_cm, maximum_heap_compaction);
duke@435 1947
duke@435 1948 #ifndef PRODUCT
duke@435 1949 if (TraceParallelOldGCMarkingPhase) {
duke@435 1950 gclog_or_tty->print_cr("marking_phase: cas_tries %d cas_retries %d "
duke@435 1951 "cas_by_another %d",
duke@435 1952 mark_bitmap()->cas_tries(), mark_bitmap()->cas_retries(),
duke@435 1953 mark_bitmap()->cas_by_another());
duke@435 1954 }
duke@435 1955 #endif // #ifndef PRODUCT
duke@435 1956
duke@435 1957 bool max_on_system_gc = UseMaximumCompactionOnSystemGC && is_system_gc;
jcoomes@645 1958 summary_phase(vmthread_cm, maximum_heap_compaction || max_on_system_gc);
duke@435 1959
duke@435 1960 COMPILER2_PRESENT(assert(DerivedPointerTable::is_active(), "Sanity"));
duke@435 1961 COMPILER2_PRESENT(DerivedPointerTable::set_active(false));
duke@435 1962
duke@435 1963 // adjust_roots() updates Universe::_intArrayKlassObj which is
duke@435 1964 // needed by the compaction for filling holes in the dense prefix.
duke@435 1965 adjust_roots();
duke@435 1966
duke@435 1967 compaction_start.update();
duke@435 1968 // Does the perm gen always have to be done serially because
duke@435 1969 // klasses are used in the update of an object?
jcoomes@645 1970 compact_perm(vmthread_cm);
duke@435 1971
duke@435 1972 if (UseParallelOldGCCompacting) {
duke@435 1973 compact();
duke@435 1974 } else {
jcoomes@645 1975 compact_serial(vmthread_cm);
duke@435 1976 }
duke@435 1977
duke@435 1978 // Reset the mark bitmap, summary data, and do other bookkeeping. Must be
duke@435 1979 // done before resizing.
duke@435 1980 post_compact();
duke@435 1981
duke@435 1982 // Let the size policy know we're done
duke@435 1983 size_policy->major_collection_end(old_gen->used_in_bytes(), gc_cause);
duke@435 1984
duke@435 1985 if (UseAdaptiveSizePolicy) {
duke@435 1986 if (PrintAdaptiveSizePolicy) {
duke@435 1987 gclog_or_tty->print("AdaptiveSizeStart: ");
duke@435 1988 gclog_or_tty->stamp();
duke@435 1989 gclog_or_tty->print_cr(" collection: %d ",
duke@435 1990 heap->total_collections());
duke@435 1991 if (Verbose) {
duke@435 1992 gclog_or_tty->print("old_gen_capacity: %d young_gen_capacity: %d"
duke@435 1993 " perm_gen_capacity: %d ",
duke@435 1994 old_gen->capacity_in_bytes(), young_gen->capacity_in_bytes(),
duke@435 1995 perm_gen->capacity_in_bytes());
duke@435 1996 }
duke@435 1997 }
duke@435 1998
duke@435 1999 // Don't check if the size_policy is ready here. Let
duke@435 2000 // the size_policy check that internally.
duke@435 2001 if (UseAdaptiveGenerationSizePolicyAtMajorCollection &&
duke@435 2002 ((gc_cause != GCCause::_java_lang_system_gc) ||
duke@435 2003 UseAdaptiveSizePolicyWithSystemGC)) {
duke@435 2004 // Calculate optimal free space amounts
duke@435 2005 assert(young_gen->max_size() >
duke@435 2006 young_gen->from_space()->capacity_in_bytes() +
duke@435 2007 young_gen->to_space()->capacity_in_bytes(),
duke@435 2008 "Sizes of space in young gen are out-of-bounds");
duke@435 2009 size_t max_eden_size = young_gen->max_size() -
duke@435 2010 young_gen->from_space()->capacity_in_bytes() -
duke@435 2011 young_gen->to_space()->capacity_in_bytes();
jmasa@698 2012 size_policy->compute_generation_free_space(
jmasa@698 2013 young_gen->used_in_bytes(),
jmasa@698 2014 young_gen->eden_space()->used_in_bytes(),
jmasa@698 2015 old_gen->used_in_bytes(),
jmasa@698 2016 perm_gen->used_in_bytes(),
jmasa@698 2017 young_gen->eden_space()->capacity_in_bytes(),
jmasa@698 2018 old_gen->max_gen_size(),
jmasa@698 2019 max_eden_size,
jmasa@698 2020 true /* full gc*/,
jmasa@698 2021 gc_cause);
jmasa@698 2022
jmasa@698 2023 heap->resize_old_gen(
jmasa@698 2024 size_policy->calculated_old_free_size_in_bytes());
duke@435 2025
duke@435 2026 // Don't resize the young generation at an major collection. A
duke@435 2027 // desired young generation size may have been calculated but
duke@435 2028 // resizing the young generation complicates the code because the
duke@435 2029 // resizing of the old generation may have moved the boundary
duke@435 2030 // between the young generation and the old generation. Let the
duke@435 2031 // young generation resizing happen at the minor collections.
duke@435 2032 }
duke@435 2033 if (PrintAdaptiveSizePolicy) {
duke@435 2034 gclog_or_tty->print_cr("AdaptiveSizeStop: collection: %d ",
duke@435 2035 heap->total_collections());
duke@435 2036 }
duke@435 2037 }
duke@435 2038
duke@435 2039 if (UsePerfData) {
duke@435 2040 PSGCAdaptivePolicyCounters* const counters = heap->gc_policy_counters();
duke@435 2041 counters->update_counters();
duke@435 2042 counters->update_old_capacity(old_gen->capacity_in_bytes());
duke@435 2043 counters->update_young_capacity(young_gen->capacity_in_bytes());
duke@435 2044 }
duke@435 2045
duke@435 2046 heap->resize_all_tlabs();
duke@435 2047
duke@435 2048 // We collected the perm gen, so we'll resize it here.
duke@435 2049 perm_gen->compute_new_size(pre_gc_values.perm_gen_used());
duke@435 2050
duke@435 2051 if (TraceGen1Time) accumulated_time()->stop();
duke@435 2052
duke@435 2053 if (PrintGC) {
duke@435 2054 if (PrintGCDetails) {
duke@435 2055 // No GC timestamp here. This is after GC so it would be confusing.
duke@435 2056 young_gen->print_used_change(pre_gc_values.young_gen_used());
duke@435 2057 old_gen->print_used_change(pre_gc_values.old_gen_used());
duke@435 2058 heap->print_heap_change(pre_gc_values.heap_used());
duke@435 2059 // Print perm gen last (print_heap_change() excludes the perm gen).
duke@435 2060 perm_gen->print_used_change(pre_gc_values.perm_gen_used());
duke@435 2061 } else {
duke@435 2062 heap->print_heap_change(pre_gc_values.heap_used());
duke@435 2063 }
duke@435 2064 }
duke@435 2065
duke@435 2066 // Track memory usage and detect low memory
duke@435 2067 MemoryService::track_memory_usage();
duke@435 2068 heap->update_counters();
duke@435 2069
duke@435 2070 if (PrintGCDetails) {
duke@435 2071 if (size_policy->print_gc_time_limit_would_be_exceeded()) {
duke@435 2072 if (size_policy->gc_time_limit_exceeded()) {
duke@435 2073 gclog_or_tty->print_cr(" GC time is exceeding GCTimeLimit "
duke@435 2074 "of %d%%", GCTimeLimit);
duke@435 2075 } else {
duke@435 2076 gclog_or_tty->print_cr(" GC time would exceed GCTimeLimit "
duke@435 2077 "of %d%%", GCTimeLimit);
duke@435 2078 }
duke@435 2079 }
duke@435 2080 size_policy->set_print_gc_time_limit_would_be_exceeded(false);
duke@435 2081 }
duke@435 2082 }
duke@435 2083
duke@435 2084 if (VerifyAfterGC && heap->total_collections() >= VerifyGCStartAt) {
duke@435 2085 HandleMark hm; // Discard invalid handles created during verification
duke@435 2086 gclog_or_tty->print(" VerifyAfterGC:");
duke@435 2087 Universe::verify(false);
duke@435 2088 }
duke@435 2089
duke@435 2090 // Re-verify object start arrays
duke@435 2091 if (VerifyObjectStartArray &&
duke@435 2092 VerifyAfterGC) {
duke@435 2093 old_gen->verify_object_start_array();
duke@435 2094 perm_gen->verify_object_start_array();
duke@435 2095 }
duke@435 2096
jmasa@698 2097 if (ZapUnusedHeapArea) {
jmasa@698 2098 old_gen->object_space()->check_mangled_unused_area_complete();
jmasa@698 2099 perm_gen->object_space()->check_mangled_unused_area_complete();
jmasa@698 2100 }
jmasa@698 2101
duke@435 2102 NOT_PRODUCT(ref_processor()->verify_no_references_recorded());
duke@435 2103
duke@435 2104 collection_exit.update();
duke@435 2105
duke@435 2106 if (PrintHeapAtGC) {
duke@435 2107 Universe::print_heap_after_gc();
duke@435 2108 }
duke@435 2109 if (PrintGCTaskTimeStamps) {
duke@435 2110 gclog_or_tty->print_cr("VM-Thread " INT64_FORMAT " " INT64_FORMAT " "
duke@435 2111 INT64_FORMAT,
duke@435 2112 marking_start.ticks(), compaction_start.ticks(),
duke@435 2113 collection_exit.ticks());
duke@435 2114 gc_task_manager()->print_task_time_stamps();
duke@435 2115 }
duke@435 2116 }
duke@435 2117
duke@435 2118 bool PSParallelCompact::absorb_live_data_from_eden(PSAdaptiveSizePolicy* size_policy,
duke@435 2119 PSYoungGen* young_gen,
duke@435 2120 PSOldGen* old_gen) {
duke@435 2121 MutableSpace* const eden_space = young_gen->eden_space();
duke@435 2122 assert(!eden_space->is_empty(), "eden must be non-empty");
duke@435 2123 assert(young_gen->virtual_space()->alignment() ==
duke@435 2124 old_gen->virtual_space()->alignment(), "alignments do not match");
duke@435 2125
duke@435 2126 if (!(UseAdaptiveSizePolicy && UseAdaptiveGCBoundary)) {
duke@435 2127 return false;
duke@435 2128 }
duke@435 2129
duke@435 2130 // Both generations must be completely committed.
duke@435 2131 if (young_gen->virtual_space()->uncommitted_size() != 0) {
duke@435 2132 return false;
duke@435 2133 }
duke@435 2134 if (old_gen->virtual_space()->uncommitted_size() != 0) {
duke@435 2135 return false;
duke@435 2136 }
duke@435 2137
duke@435 2138 // Figure out how much to take from eden. Include the average amount promoted
duke@435 2139 // in the total; otherwise the next young gen GC will simply bail out to a
duke@435 2140 // full GC.
duke@435 2141 const size_t alignment = old_gen->virtual_space()->alignment();
duke@435 2142 const size_t eden_used = eden_space->used_in_bytes();
duke@435 2143 const size_t promoted = (size_t)size_policy->avg_promoted()->padded_average();
duke@435 2144 const size_t absorb_size = align_size_up(eden_used + promoted, alignment);
duke@435 2145 const size_t eden_capacity = eden_space->capacity_in_bytes();
duke@435 2146
duke@435 2147 if (absorb_size >= eden_capacity) {
duke@435 2148 return false; // Must leave some space in eden.
duke@435 2149 }
duke@435 2150
duke@435 2151 const size_t new_young_size = young_gen->capacity_in_bytes() - absorb_size;
duke@435 2152 if (new_young_size < young_gen->min_gen_size()) {
duke@435 2153 return false; // Respect young gen minimum size.
duke@435 2154 }
duke@435 2155
duke@435 2156 if (TraceAdaptiveGCBoundary && Verbose) {
duke@435 2157 gclog_or_tty->print(" absorbing " SIZE_FORMAT "K: "
duke@435 2158 "eden " SIZE_FORMAT "K->" SIZE_FORMAT "K "
duke@435 2159 "from " SIZE_FORMAT "K, to " SIZE_FORMAT "K "
duke@435 2160 "young_gen " SIZE_FORMAT "K->" SIZE_FORMAT "K ",
duke@435 2161 absorb_size / K,
duke@435 2162 eden_capacity / K, (eden_capacity - absorb_size) / K,
duke@435 2163 young_gen->from_space()->used_in_bytes() / K,
duke@435 2164 young_gen->to_space()->used_in_bytes() / K,
duke@435 2165 young_gen->capacity_in_bytes() / K, new_young_size / K);
duke@435 2166 }
duke@435 2167
duke@435 2168 // Fill the unused part of the old gen.
duke@435 2169 MutableSpace* const old_space = old_gen->object_space();
duke@435 2170 MemRegion old_gen_unused(old_space->top(), old_space->end());
duke@435 2171 if (!old_gen_unused.is_empty()) {
duke@435 2172 SharedHeap::fill_region_with_object(old_gen_unused);
duke@435 2173 }
duke@435 2174
duke@435 2175 // Take the live data from eden and set both top and end in the old gen to
duke@435 2176 // eden top. (Need to set end because reset_after_change() mangles the region
duke@435 2177 // from end to virtual_space->high() in debug builds).
duke@435 2178 HeapWord* const new_top = eden_space->top();
duke@435 2179 old_gen->virtual_space()->expand_into(young_gen->virtual_space(),
duke@435 2180 absorb_size);
duke@435 2181 young_gen->reset_after_change();
duke@435 2182 old_space->set_top(new_top);
duke@435 2183 old_space->set_end(new_top);
duke@435 2184 old_gen->reset_after_change();
duke@435 2185
duke@435 2186 // Update the object start array for the filler object and the data from eden.
duke@435 2187 ObjectStartArray* const start_array = old_gen->start_array();
duke@435 2188 HeapWord* const start = old_gen_unused.start();
duke@435 2189 for (HeapWord* addr = start; addr < new_top; addr += oop(addr)->size()) {
duke@435 2190 start_array->allocate_block(addr);
duke@435 2191 }
duke@435 2192
duke@435 2193 // Could update the promoted average here, but it is not typically updated at
duke@435 2194 // full GCs and the value to use is unclear. Something like
duke@435 2195 //
duke@435 2196 // cur_promoted_avg + absorb_size / number_of_scavenges_since_last_full_gc.
duke@435 2197
duke@435 2198 size_policy->set_bytes_absorbed_from_eden(absorb_size);
duke@435 2199 return true;
duke@435 2200 }
duke@435 2201
duke@435 2202 GCTaskManager* const PSParallelCompact::gc_task_manager() {
duke@435 2203 assert(ParallelScavengeHeap::gc_task_manager() != NULL,
duke@435 2204 "shouldn't return NULL");
duke@435 2205 return ParallelScavengeHeap::gc_task_manager();
duke@435 2206 }
duke@435 2207
duke@435 2208 void PSParallelCompact::marking_phase(ParCompactionManager* cm,
duke@435 2209 bool maximum_heap_compaction) {
duke@435 2210 // Recursively traverse all live objects and mark them
duke@435 2211 EventMark m("1 mark object");
duke@435 2212 TraceTime tm("marking phase", print_phases(), true, gclog_or_tty);
duke@435 2213
duke@435 2214 ParallelScavengeHeap* heap = gc_heap();
duke@435 2215 uint parallel_gc_threads = heap->gc_task_manager()->workers();
jcoomes@810 2216 TaskQueueSetSuper* qset = ParCompactionManager::region_array();
duke@435 2217 ParallelTaskTerminator terminator(parallel_gc_threads, qset);
duke@435 2218
duke@435 2219 PSParallelCompact::MarkAndPushClosure mark_and_push_closure(cm);
duke@435 2220 PSParallelCompact::FollowStackClosure follow_stack_closure(cm);
duke@435 2221
duke@435 2222 {
duke@435 2223 TraceTime tm_m("par mark", print_phases(), true, gclog_or_tty);
duke@435 2224
duke@435 2225 GCTaskQueue* q = GCTaskQueue::create();
duke@435 2226
duke@435 2227 q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::universe));
duke@435 2228 q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::jni_handles));
duke@435 2229 // We scan the thread roots in parallel
duke@435 2230 Threads::create_thread_roots_marking_tasks(q);
duke@435 2231 q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::object_synchronizer));
duke@435 2232 q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::flat_profiler));
duke@435 2233 q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::management));
duke@435 2234 q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::system_dictionary));
duke@435 2235 q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::jvmti));
duke@435 2236 q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::vm_symbols));
duke@435 2237
duke@435 2238 if (parallel_gc_threads > 1) {
duke@435 2239 for (uint j = 0; j < parallel_gc_threads; j++) {
duke@435 2240 q->enqueue(new StealMarkingTask(&terminator));
duke@435 2241 }
duke@435 2242 }
duke@435 2243
duke@435 2244 WaitForBarrierGCTask* fin = WaitForBarrierGCTask::create();
duke@435 2245 q->enqueue(fin);
duke@435 2246
duke@435 2247 gc_task_manager()->add_list(q);
duke@435 2248
duke@435 2249 fin->wait_for();
duke@435 2250
duke@435 2251 // We have to release the barrier tasks!
duke@435 2252 WaitForBarrierGCTask::destroy(fin);
duke@435 2253 }
duke@435 2254
duke@435 2255 // Process reference objects found during marking
duke@435 2256 {
duke@435 2257 TraceTime tm_r("reference processing", print_phases(), true, gclog_or_tty);
duke@435 2258 ReferencePolicy *soft_ref_policy;
duke@435 2259 if (maximum_heap_compaction) {
duke@435 2260 soft_ref_policy = new AlwaysClearPolicy();
duke@435 2261 } else {
duke@435 2262 #ifdef COMPILER2
duke@435 2263 soft_ref_policy = new LRUMaxHeapPolicy();
duke@435 2264 #else
duke@435 2265 soft_ref_policy = new LRUCurrentHeapPolicy();
duke@435 2266 #endif // COMPILER2
duke@435 2267 }
duke@435 2268 assert(soft_ref_policy != NULL, "No soft reference policy");
duke@435 2269 if (ref_processor()->processing_is_mt()) {
duke@435 2270 RefProcTaskExecutor task_executor;
duke@435 2271 ref_processor()->process_discovered_references(
duke@435 2272 soft_ref_policy, is_alive_closure(), &mark_and_push_closure,
duke@435 2273 &follow_stack_closure, &task_executor);
duke@435 2274 } else {
duke@435 2275 ref_processor()->process_discovered_references(
duke@435 2276 soft_ref_policy, is_alive_closure(), &mark_and_push_closure,
duke@435 2277 &follow_stack_closure, NULL);
duke@435 2278 }
duke@435 2279 }
duke@435 2280
duke@435 2281 TraceTime tm_c("class unloading", print_phases(), true, gclog_or_tty);
duke@435 2282 // Follow system dictionary roots and unload classes.
duke@435 2283 bool purged_class = SystemDictionary::do_unloading(is_alive_closure());
duke@435 2284
duke@435 2285 // Follow code cache roots.
duke@435 2286 CodeCache::do_unloading(is_alive_closure(), &mark_and_push_closure,
duke@435 2287 purged_class);
duke@435 2288 follow_stack(cm); // Flush marking stack.
duke@435 2289
duke@435 2290 // Update subklass/sibling/implementor links of live klasses
duke@435 2291 // revisit_klass_stack is used in follow_weak_klass_links().
duke@435 2292 follow_weak_klass_links(cm);
duke@435 2293
duke@435 2294 // Visit symbol and interned string tables and delete unmarked oops
duke@435 2295 SymbolTable::unlink(is_alive_closure());
duke@435 2296 StringTable::unlink(is_alive_closure());
duke@435 2297
duke@435 2298 assert(cm->marking_stack()->size() == 0, "stack should be empty by now");
duke@435 2299 assert(cm->overflow_stack()->is_empty(), "stack should be empty by now");
duke@435 2300 }
duke@435 2301
duke@435 2302 // This should be moved to the shared markSweep code!
duke@435 2303 class PSAlwaysTrueClosure: public BoolObjectClosure {
duke@435 2304 public:
duke@435 2305 void do_object(oop p) { ShouldNotReachHere(); }
duke@435 2306 bool do_object_b(oop p) { return true; }
duke@435 2307 };
duke@435 2308 static PSAlwaysTrueClosure always_true;
duke@435 2309
duke@435 2310 void PSParallelCompact::adjust_roots() {
duke@435 2311 // Adjust the pointers to reflect the new locations
duke@435 2312 EventMark m("3 adjust roots");
duke@435 2313 TraceTime tm("adjust roots", print_phases(), true, gclog_or_tty);
duke@435 2314
duke@435 2315 // General strong roots.
duke@435 2316 Universe::oops_do(adjust_root_pointer_closure());
duke@435 2317 ReferenceProcessor::oops_do(adjust_root_pointer_closure());
duke@435 2318 JNIHandles::oops_do(adjust_root_pointer_closure()); // Global (strong) JNI handles
duke@435 2319 Threads::oops_do(adjust_root_pointer_closure());
duke@435 2320 ObjectSynchronizer::oops_do(adjust_root_pointer_closure());
duke@435 2321 FlatProfiler::oops_do(adjust_root_pointer_closure());
duke@435 2322 Management::oops_do(adjust_root_pointer_closure());
duke@435 2323 JvmtiExport::oops_do(adjust_root_pointer_closure());
duke@435 2324 // SO_AllClasses
duke@435 2325 SystemDictionary::oops_do(adjust_root_pointer_closure());
duke@435 2326 vmSymbols::oops_do(adjust_root_pointer_closure());
duke@435 2327
duke@435 2328 // Now adjust pointers in remaining weak roots. (All of which should
duke@435 2329 // have been cleared if they pointed to non-surviving objects.)
duke@435 2330 // Global (weak) JNI handles
duke@435 2331 JNIHandles::weak_oops_do(&always_true, adjust_root_pointer_closure());
duke@435 2332
duke@435 2333 CodeCache::oops_do(adjust_pointer_closure());
duke@435 2334 SymbolTable::oops_do(adjust_root_pointer_closure());
duke@435 2335 StringTable::oops_do(adjust_root_pointer_closure());
duke@435 2336 ref_processor()->weak_oops_do(adjust_root_pointer_closure());
duke@435 2337 // Roots were visited so references into the young gen in roots
duke@435 2338 // may have been scanned. Process them also.
duke@435 2339 // Should the reference processor have a span that excludes
duke@435 2340 // young gen objects?
duke@435 2341 PSScavenge::reference_processor()->weak_oops_do(
duke@435 2342 adjust_root_pointer_closure());
duke@435 2343 }
duke@435 2344
duke@435 2345 void PSParallelCompact::compact_perm(ParCompactionManager* cm) {
duke@435 2346 EventMark m("4 compact perm");
duke@435 2347 TraceTime tm("compact perm gen", print_phases(), true, gclog_or_tty);
duke@435 2348 // trace("4");
duke@435 2349
duke@435 2350 gc_heap()->perm_gen()->start_array()->reset();
duke@435 2351 move_and_update(cm, perm_space_id);
duke@435 2352 }
duke@435 2353
jcoomes@810 2354 void PSParallelCompact::enqueue_region_draining_tasks(GCTaskQueue* q,
jcoomes@810 2355 uint parallel_gc_threads)
jcoomes@810 2356 {
duke@435 2357 TraceTime tm("drain task setup", print_phases(), true, gclog_or_tty);
duke@435 2358
duke@435 2359 const unsigned int task_count = MAX2(parallel_gc_threads, 1U);
duke@435 2360 for (unsigned int j = 0; j < task_count; j++) {
duke@435 2361 q->enqueue(new DrainStacksCompactionTask());
duke@435 2362 }
duke@435 2363
jcoomes@810 2364 // Find all regions that are available (can be filled immediately) and
duke@435 2365 // distribute them to the thread stacks. The iteration is done in reverse
jcoomes@810 2366 // order (high to low) so the regions will be removed in ascending order.
duke@435 2367
duke@435 2368 const ParallelCompactData& sd = PSParallelCompact::summary_data();
duke@435 2369
jcoomes@810 2370 size_t fillable_regions = 0; // A count for diagnostic purposes.
duke@435 2371 unsigned int which = 0; // The worker thread number.
duke@435 2372
duke@435 2373 for (unsigned int id = to_space_id; id > perm_space_id; --id) {
duke@435 2374 SpaceInfo* const space_info = _space_info + id;
duke@435 2375 MutableSpace* const space = space_info->space();
duke@435 2376 HeapWord* const new_top = space_info->new_top();
duke@435 2377
jcoomes@810 2378 const size_t beg_region = sd.addr_to_region_idx(space_info->dense_prefix());
jcoomes@810 2379 const size_t end_region =
jcoomes@810 2380 sd.addr_to_region_idx(sd.region_align_up(new_top));
jcoomes@810 2381 assert(end_region > 0, "perm gen cannot be empty");
jcoomes@810 2382
jcoomes@810 2383 for (size_t cur = end_region - 1; cur >= beg_region; --cur) {
jcoomes@810 2384 if (sd.region(cur)->claim_unsafe()) {
duke@435 2385 ParCompactionManager* cm = ParCompactionManager::manager_array(which);
duke@435 2386 cm->save_for_processing(cur);
duke@435 2387
duke@435 2388 if (TraceParallelOldGCCompactionPhase && Verbose) {
jcoomes@810 2389 const size_t count_mod_8 = fillable_regions & 7;
duke@435 2390 if (count_mod_8 == 0) gclog_or_tty->print("fillable: ");
jcoomes@699 2391 gclog_or_tty->print(" " SIZE_FORMAT_W(7), cur);
duke@435 2392 if (count_mod_8 == 7) gclog_or_tty->cr();
duke@435 2393 }
duke@435 2394
jcoomes@810 2395 NOT_PRODUCT(++fillable_regions;)
jcoomes@810 2396
jcoomes@810 2397 // Assign regions to threads in round-robin fashion.
duke@435 2398 if (++which == task_count) {
duke@435 2399 which = 0;
duke@435 2400 }
duke@435 2401 }
duke@435 2402 }
duke@435 2403 }
duke@435 2404
duke@435 2405 if (TraceParallelOldGCCompactionPhase) {
jcoomes@810 2406 if (Verbose && (fillable_regions & 7) != 0) gclog_or_tty->cr();
jcoomes@810 2407 gclog_or_tty->print_cr("%u initially fillable regions", fillable_regions);
duke@435 2408 }
duke@435 2409 }
duke@435 2410
duke@435 2411 #define PAR_OLD_DENSE_PREFIX_OVER_PARTITIONING 4
duke@435 2412
duke@435 2413 void PSParallelCompact::enqueue_dense_prefix_tasks(GCTaskQueue* q,
duke@435 2414 uint parallel_gc_threads) {
duke@435 2415 TraceTime tm("dense prefix task setup", print_phases(), true, gclog_or_tty);
duke@435 2416
duke@435 2417 ParallelCompactData& sd = PSParallelCompact::summary_data();
duke@435 2418
duke@435 2419 // Iterate over all the spaces adding tasks for updating
jcoomes@810 2420 // regions in the dense prefix. Assume that 1 gc thread
duke@435 2421 // will work on opening the gaps and the remaining gc threads
duke@435 2422 // will work on the dense prefix.
duke@435 2423 SpaceId space_id = old_space_id;
duke@435 2424 while (space_id != last_space_id) {
duke@435 2425 HeapWord* const dense_prefix_end = _space_info[space_id].dense_prefix();
duke@435 2426 const MutableSpace* const space = _space_info[space_id].space();
duke@435 2427
duke@435 2428 if (dense_prefix_end == space->bottom()) {
duke@435 2429 // There is no dense prefix for this space.
duke@435 2430 space_id = next_compaction_space_id(space_id);
duke@435 2431 continue;
duke@435 2432 }
duke@435 2433
jcoomes@810 2434 // The dense prefix is before this region.
jcoomes@810 2435 size_t region_index_end_dense_prefix =
jcoomes@810 2436 sd.addr_to_region_idx(dense_prefix_end);
jcoomes@810 2437 RegionData* const dense_prefix_cp =
jcoomes@810 2438 sd.region(region_index_end_dense_prefix);
duke@435 2439 assert(dense_prefix_end == space->end() ||
duke@435 2440 dense_prefix_cp->available() ||
duke@435 2441 dense_prefix_cp->claimed(),
jcoomes@810 2442 "The region after the dense prefix should always be ready to fill");
jcoomes@810 2443
jcoomes@810 2444 size_t region_index_start = sd.addr_to_region_idx(space->bottom());
duke@435 2445
duke@435 2446 // Is there dense prefix work?
jcoomes@810 2447 size_t total_dense_prefix_regions =
jcoomes@810 2448 region_index_end_dense_prefix - region_index_start;
jcoomes@810 2449 // How many regions of the dense prefix should be given to
duke@435 2450 // each thread?
jcoomes@810 2451 if (total_dense_prefix_regions > 0) {
duke@435 2452 uint tasks_for_dense_prefix = 1;
duke@435 2453 if (UseParallelDensePrefixUpdate) {
jcoomes@810 2454 if (total_dense_prefix_regions <=
duke@435 2455 (parallel_gc_threads * PAR_OLD_DENSE_PREFIX_OVER_PARTITIONING)) {
duke@435 2456 // Don't over partition. This assumes that
duke@435 2457 // PAR_OLD_DENSE_PREFIX_OVER_PARTITIONING is a small integer value
jcoomes@810 2458 // so there are not many regions to process.
duke@435 2459 tasks_for_dense_prefix = parallel_gc_threads;
duke@435 2460 } else {
duke@435 2461 // Over partition
duke@435 2462 tasks_for_dense_prefix = parallel_gc_threads *
duke@435 2463 PAR_OLD_DENSE_PREFIX_OVER_PARTITIONING;
duke@435 2464 }
duke@435 2465 }
jcoomes@810 2466 size_t regions_per_thread = total_dense_prefix_regions /
duke@435 2467 tasks_for_dense_prefix;
jcoomes@810 2468 // Give each thread at least 1 region.
jcoomes@810 2469 if (regions_per_thread == 0) {
jcoomes@810 2470 regions_per_thread = 1;
duke@435 2471 }
duke@435 2472
duke@435 2473 for (uint k = 0; k < tasks_for_dense_prefix; k++) {
jcoomes@810 2474 if (region_index_start >= region_index_end_dense_prefix) {
duke@435 2475 break;
duke@435 2476 }
jcoomes@810 2477 // region_index_end is not processed
jcoomes@810 2478 size_t region_index_end = MIN2(region_index_start + regions_per_thread,
jcoomes@810 2479 region_index_end_dense_prefix);
duke@435 2480 q->enqueue(new UpdateDensePrefixTask(
duke@435 2481 space_id,
jcoomes@810 2482 region_index_start,
jcoomes@810 2483 region_index_end));
jcoomes@810 2484 region_index_start = region_index_end;
duke@435 2485 }
duke@435 2486 }
duke@435 2487 // This gets any part of the dense prefix that did not
duke@435 2488 // fit evenly.
jcoomes@810 2489 if (region_index_start < region_index_end_dense_prefix) {
duke@435 2490 q->enqueue(new UpdateDensePrefixTask(
duke@435 2491 space_id,
jcoomes@810 2492 region_index_start,
jcoomes@810 2493 region_index_end_dense_prefix));
duke@435 2494 }
duke@435 2495 space_id = next_compaction_space_id(space_id);
duke@435 2496 } // End tasks for dense prefix
duke@435 2497 }
duke@435 2498
jcoomes@810 2499 void PSParallelCompact::enqueue_region_stealing_tasks(
duke@435 2500 GCTaskQueue* q,
duke@435 2501 ParallelTaskTerminator* terminator_ptr,
duke@435 2502 uint parallel_gc_threads) {
duke@435 2503 TraceTime tm("steal task setup", print_phases(), true, gclog_or_tty);
duke@435 2504
jcoomes@810 2505 // Once a thread has drained it's stack, it should try to steal regions from
duke@435 2506 // other threads.
duke@435 2507 if (parallel_gc_threads > 1) {
duke@435 2508 for (uint j = 0; j < parallel_gc_threads; j++) {
jcoomes@810 2509 q->enqueue(new StealRegionCompactionTask(terminator_ptr));
duke@435 2510 }
duke@435 2511 }
duke@435 2512 }
duke@435 2513
duke@435 2514 void PSParallelCompact::compact() {
duke@435 2515 EventMark m("5 compact");
duke@435 2516 // trace("5");
duke@435 2517 TraceTime tm("compaction phase", print_phases(), true, gclog_or_tty);
duke@435 2518
duke@435 2519 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
duke@435 2520 assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
duke@435 2521 PSOldGen* old_gen = heap->old_gen();
duke@435 2522 old_gen->start_array()->reset();
duke@435 2523 uint parallel_gc_threads = heap->gc_task_manager()->workers();
jcoomes@810 2524 TaskQueueSetSuper* qset = ParCompactionManager::region_array();
duke@435 2525 ParallelTaskTerminator terminator(parallel_gc_threads, qset);
duke@435 2526
duke@435 2527 GCTaskQueue* q = GCTaskQueue::create();
jcoomes@810 2528 enqueue_region_draining_tasks(q, parallel_gc_threads);
duke@435 2529 enqueue_dense_prefix_tasks(q, parallel_gc_threads);
jcoomes@810 2530 enqueue_region_stealing_tasks(q, &terminator, parallel_gc_threads);
duke@435 2531
duke@435 2532 {
duke@435 2533 TraceTime tm_pc("par compact", print_phases(), true, gclog_or_tty);
duke@435 2534
duke@435 2535 WaitForBarrierGCTask* fin = WaitForBarrierGCTask::create();
duke@435 2536 q->enqueue(fin);
duke@435 2537
duke@435 2538 gc_task_manager()->add_list(q);
duke@435 2539
duke@435 2540 fin->wait_for();
duke@435 2541
duke@435 2542 // We have to release the barrier tasks!
duke@435 2543 WaitForBarrierGCTask::destroy(fin);
duke@435 2544
duke@435 2545 #ifdef ASSERT
jcoomes@810 2546 // Verify that all regions have been processed before the deferred updates.
duke@435 2547 // Note that perm_space_id is skipped; this type of verification is not
jcoomes@810 2548 // valid until the perm gen is compacted by regions.
duke@435 2549 for (unsigned int id = old_space_id; id < last_space_id; ++id) {
duke@435 2550 verify_complete(SpaceId(id));
duke@435 2551 }
duke@435 2552 #endif
duke@435 2553 }
duke@435 2554
duke@435 2555 {
duke@435 2556 // Update the deferred objects, if any. Any compaction manager can be used.
duke@435 2557 TraceTime tm_du("deferred updates", print_phases(), true, gclog_or_tty);
duke@435 2558 ParCompactionManager* cm = ParCompactionManager::manager_array(0);
duke@435 2559 for (unsigned int id = old_space_id; id < last_space_id; ++id) {
duke@435 2560 update_deferred_objects(cm, SpaceId(id));
duke@435 2561 }
duke@435 2562 }
duke@435 2563 }
duke@435 2564
duke@435 2565 #ifdef ASSERT
duke@435 2566 void PSParallelCompact::verify_complete(SpaceId space_id) {
jcoomes@810 2567 // All Regions between space bottom() to new_top() should be marked as filled
jcoomes@810 2568 // and all Regions between new_top() and top() should be available (i.e.,
duke@435 2569 // should have been emptied).
duke@435 2570 ParallelCompactData& sd = summary_data();
duke@435 2571 SpaceInfo si = _space_info[space_id];
jcoomes@810 2572 HeapWord* new_top_addr = sd.region_align_up(si.new_top());
jcoomes@810 2573 HeapWord* old_top_addr = sd.region_align_up(si.space()->top());
jcoomes@810 2574 const size_t beg_region = sd.addr_to_region_idx(si.space()->bottom());
jcoomes@810 2575 const size_t new_top_region = sd.addr_to_region_idx(new_top_addr);
jcoomes@810 2576 const size_t old_top_region = sd.addr_to_region_idx(old_top_addr);
duke@435 2577
duke@435 2578 bool issued_a_warning = false;
duke@435 2579
jcoomes@810 2580 size_t cur_region;
jcoomes@810 2581 for (cur_region = beg_region; cur_region < new_top_region; ++cur_region) {
jcoomes@810 2582 const RegionData* const c = sd.region(cur_region);
duke@435 2583 if (!c->completed()) {
jcoomes@810 2584 warning("region " SIZE_FORMAT " not filled: "
duke@435 2585 "destination_count=" SIZE_FORMAT,
jcoomes@810 2586 cur_region, c->destination_count());
duke@435 2587 issued_a_warning = true;
duke@435 2588 }
duke@435 2589 }
duke@435 2590
jcoomes@810 2591 for (cur_region = new_top_region; cur_region < old_top_region; ++cur_region) {
jcoomes@810 2592 const RegionData* const c = sd.region(cur_region);
duke@435 2593 if (!c->available()) {
jcoomes@810 2594 warning("region " SIZE_FORMAT " not empty: "
duke@435 2595 "destination_count=" SIZE_FORMAT,
jcoomes@810 2596 cur_region, c->destination_count());
duke@435 2597 issued_a_warning = true;
duke@435 2598 }
duke@435 2599 }
duke@435 2600
duke@435 2601 if (issued_a_warning) {
jcoomes@810 2602 print_region_ranges();
duke@435 2603 }
duke@435 2604 }
duke@435 2605 #endif // #ifdef ASSERT
duke@435 2606
duke@435 2607 void PSParallelCompact::compact_serial(ParCompactionManager* cm) {
duke@435 2608 EventMark m("5 compact serial");
duke@435 2609 TraceTime tm("compact serial", print_phases(), true, gclog_or_tty);
duke@435 2610
duke@435 2611 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
duke@435 2612 assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
duke@435 2613
duke@435 2614 PSYoungGen* young_gen = heap->young_gen();
duke@435 2615 PSOldGen* old_gen = heap->old_gen();
duke@435 2616
duke@435 2617 old_gen->start_array()->reset();
duke@435 2618 old_gen->move_and_update(cm);
duke@435 2619 young_gen->move_and_update(cm);
duke@435 2620 }
duke@435 2621
duke@435 2622
duke@435 2623 void PSParallelCompact::follow_stack(ParCompactionManager* cm) {
duke@435 2624 while(!cm->overflow_stack()->is_empty()) {
duke@435 2625 oop obj = cm->overflow_stack()->pop();
duke@435 2626 obj->follow_contents(cm);
duke@435 2627 }
duke@435 2628
duke@435 2629 oop obj;
duke@435 2630 // obj is a reference!!!
duke@435 2631 while (cm->marking_stack()->pop_local(obj)) {
duke@435 2632 // It would be nice to assert about the type of objects we might
duke@435 2633 // pop, but they can come from anywhere, unfortunately.
duke@435 2634 obj->follow_contents(cm);
duke@435 2635 }
duke@435 2636 }
duke@435 2637
duke@435 2638 void
duke@435 2639 PSParallelCompact::follow_weak_klass_links(ParCompactionManager* serial_cm) {
duke@435 2640 // All klasses on the revisit stack are marked at this point.
duke@435 2641 // Update and follow all subklass, sibling and implementor links.
duke@435 2642 for (uint i = 0; i < ParallelGCThreads+1; i++) {
duke@435 2643 ParCompactionManager* cm = ParCompactionManager::manager_array(i);
duke@435 2644 KeepAliveClosure keep_alive_closure(cm);
duke@435 2645 for (int i = 0; i < cm->revisit_klass_stack()->length(); i++) {
duke@435 2646 cm->revisit_klass_stack()->at(i)->follow_weak_klass_links(
duke@435 2647 is_alive_closure(),
duke@435 2648 &keep_alive_closure);
duke@435 2649 }
duke@435 2650 follow_stack(cm);
duke@435 2651 }
duke@435 2652 }
duke@435 2653
duke@435 2654 void
duke@435 2655 PSParallelCompact::revisit_weak_klass_link(ParCompactionManager* cm, Klass* k) {
duke@435 2656 cm->revisit_klass_stack()->push(k);
duke@435 2657 }
duke@435 2658
duke@435 2659 #ifdef VALIDATE_MARK_SWEEP
duke@435 2660
coleenp@548 2661 void PSParallelCompact::track_adjusted_pointer(void* p, bool isroot) {
duke@435 2662 if (!ValidateMarkSweep)
duke@435 2663 return;
duke@435 2664
duke@435 2665 if (!isroot) {
duke@435 2666 if (_pointer_tracking) {
duke@435 2667 guarantee(_adjusted_pointers->contains(p), "should have seen this pointer");
duke@435 2668 _adjusted_pointers->remove(p);
duke@435 2669 }
duke@435 2670 } else {
duke@435 2671 ptrdiff_t index = _root_refs_stack->find(p);
duke@435 2672 if (index != -1) {
duke@435 2673 int l = _root_refs_stack->length();
duke@435 2674 if (l > 0 && l - 1 != index) {
coleenp@548 2675 void* last = _root_refs_stack->pop();
duke@435 2676 assert(last != p, "should be different");
duke@435 2677 _root_refs_stack->at_put(index, last);
duke@435 2678 } else {
duke@435 2679 _root_refs_stack->remove(p);
duke@435 2680 }
duke@435 2681 }
duke@435 2682 }
duke@435 2683 }
duke@435 2684
duke@435 2685
coleenp@548 2686 void PSParallelCompact::check_adjust_pointer(void* p) {
duke@435 2687 _adjusted_pointers->push(p);
duke@435 2688 }
duke@435 2689
duke@435 2690
duke@435 2691 class AdjusterTracker: public OopClosure {
duke@435 2692 public:
duke@435 2693 AdjusterTracker() {};
coleenp@548 2694 void do_oop(oop* o) { PSParallelCompact::check_adjust_pointer(o); }
coleenp@548 2695 void do_oop(narrowOop* o) { PSParallelCompact::check_adjust_pointer(o); }
duke@435 2696 };
duke@435 2697
duke@435 2698
duke@435 2699 void PSParallelCompact::track_interior_pointers(oop obj) {
duke@435 2700 if (ValidateMarkSweep) {
duke@435 2701 _adjusted_pointers->clear();
duke@435 2702 _pointer_tracking = true;
duke@435 2703
duke@435 2704 AdjusterTracker checker;
duke@435 2705 obj->oop_iterate(&checker);
duke@435 2706 }
duke@435 2707 }
duke@435 2708
duke@435 2709
duke@435 2710 void PSParallelCompact::check_interior_pointers() {
duke@435 2711 if (ValidateMarkSweep) {
duke@435 2712 _pointer_tracking = false;
duke@435 2713 guarantee(_adjusted_pointers->length() == 0, "should have processed the same pointers");
duke@435 2714 }
duke@435 2715 }
duke@435 2716
duke@435 2717
duke@435 2718 void PSParallelCompact::reset_live_oop_tracking(bool at_perm) {
duke@435 2719 if (ValidateMarkSweep) {
duke@435 2720 guarantee((size_t)_live_oops->length() == _live_oops_index, "should be at end of live oops");
duke@435 2721 _live_oops_index = at_perm ? _live_oops_index_at_perm : 0;
duke@435 2722 }
duke@435 2723 }
duke@435 2724
duke@435 2725
duke@435 2726 void PSParallelCompact::register_live_oop(oop p, size_t size) {
duke@435 2727 if (ValidateMarkSweep) {
duke@435 2728 _live_oops->push(p);
duke@435 2729 _live_oops_size->push(size);
duke@435 2730 _live_oops_index++;
duke@435 2731 }
duke@435 2732 }
duke@435 2733
duke@435 2734 void PSParallelCompact::validate_live_oop(oop p, size_t size) {
duke@435 2735 if (ValidateMarkSweep) {
duke@435 2736 oop obj = _live_oops->at((int)_live_oops_index);
duke@435 2737 guarantee(obj == p, "should be the same object");
duke@435 2738 guarantee(_live_oops_size->at((int)_live_oops_index) == size, "should be the same size");
duke@435 2739 _live_oops_index++;
duke@435 2740 }
duke@435 2741 }
duke@435 2742
duke@435 2743 void PSParallelCompact::live_oop_moved_to(HeapWord* q, size_t size,
duke@435 2744 HeapWord* compaction_top) {
duke@435 2745 assert(oop(q)->forwardee() == NULL || oop(q)->forwardee() == oop(compaction_top),
duke@435 2746 "should be moved to forwarded location");
duke@435 2747 if (ValidateMarkSweep) {
duke@435 2748 PSParallelCompact::validate_live_oop(oop(q), size);
duke@435 2749 _live_oops_moved_to->push(oop(compaction_top));
duke@435 2750 }
duke@435 2751 if (RecordMarkSweepCompaction) {
duke@435 2752 _cur_gc_live_oops->push(q);
duke@435 2753 _cur_gc_live_oops_moved_to->push(compaction_top);
duke@435 2754 _cur_gc_live_oops_size->push(size);
duke@435 2755 }
duke@435 2756 }
duke@435 2757
duke@435 2758
duke@435 2759 void PSParallelCompact::compaction_complete() {
duke@435 2760 if (RecordMarkSweepCompaction) {
duke@435 2761 GrowableArray<HeapWord*>* _tmp_live_oops = _cur_gc_live_oops;
duke@435 2762 GrowableArray<HeapWord*>* _tmp_live_oops_moved_to = _cur_gc_live_oops_moved_to;
duke@435 2763 GrowableArray<size_t> * _tmp_live_oops_size = _cur_gc_live_oops_size;
duke@435 2764
duke@435 2765 _cur_gc_live_oops = _last_gc_live_oops;
duke@435 2766 _cur_gc_live_oops_moved_to = _last_gc_live_oops_moved_to;
duke@435 2767 _cur_gc_live_oops_size = _last_gc_live_oops_size;
duke@435 2768 _last_gc_live_oops = _tmp_live_oops;
duke@435 2769 _last_gc_live_oops_moved_to = _tmp_live_oops_moved_to;
duke@435 2770 _last_gc_live_oops_size = _tmp_live_oops_size;
duke@435 2771 }
duke@435 2772 }
duke@435 2773
duke@435 2774
duke@435 2775 void PSParallelCompact::print_new_location_of_heap_address(HeapWord* q) {
duke@435 2776 if (!RecordMarkSweepCompaction) {
duke@435 2777 tty->print_cr("Requires RecordMarkSweepCompaction to be enabled");
duke@435 2778 return;
duke@435 2779 }
duke@435 2780
duke@435 2781 if (_last_gc_live_oops == NULL) {
duke@435 2782 tty->print_cr("No compaction information gathered yet");
duke@435 2783 return;
duke@435 2784 }
duke@435 2785
duke@435 2786 for (int i = 0; i < _last_gc_live_oops->length(); i++) {
duke@435 2787 HeapWord* old_oop = _last_gc_live_oops->at(i);
duke@435 2788 size_t sz = _last_gc_live_oops_size->at(i);
duke@435 2789 if (old_oop <= q && q < (old_oop + sz)) {
duke@435 2790 HeapWord* new_oop = _last_gc_live_oops_moved_to->at(i);
duke@435 2791 size_t offset = (q - old_oop);
duke@435 2792 tty->print_cr("Address " PTR_FORMAT, q);
duke@435 2793 tty->print_cr(" Was in oop " PTR_FORMAT ", size %d, at offset %d", old_oop, sz, offset);
duke@435 2794 tty->print_cr(" Now in oop " PTR_FORMAT ", actual address " PTR_FORMAT, new_oop, new_oop + offset);
duke@435 2795 return;
duke@435 2796 }
duke@435 2797 }
duke@435 2798
duke@435 2799 tty->print_cr("Address " PTR_FORMAT " not found in live oop information from last GC", q);
duke@435 2800 }
duke@435 2801 #endif //VALIDATE_MARK_SWEEP
duke@435 2802
jcoomes@810 2803 // Update interior oops in the ranges of regions [beg_region, end_region).
duke@435 2804 void
duke@435 2805 PSParallelCompact::update_and_deadwood_in_dense_prefix(ParCompactionManager* cm,
duke@435 2806 SpaceId space_id,
jcoomes@810 2807 size_t beg_region,
jcoomes@810 2808 size_t end_region) {
duke@435 2809 ParallelCompactData& sd = summary_data();
duke@435 2810 ParMarkBitMap* const mbm = mark_bitmap();
duke@435 2811
jcoomes@810 2812 HeapWord* beg_addr = sd.region_to_addr(beg_region);
jcoomes@810 2813 HeapWord* const end_addr = sd.region_to_addr(end_region);
jcoomes@810 2814 assert(beg_region <= end_region, "bad region range");
duke@435 2815 assert(end_addr <= dense_prefix(space_id), "not in the dense prefix");
duke@435 2816
duke@435 2817 #ifdef ASSERT
jcoomes@810 2818 // Claim the regions to avoid triggering an assert when they are marked as
duke@435 2819 // filled.
jcoomes@810 2820 for (size_t claim_region = beg_region; claim_region < end_region; ++claim_region) {
jcoomes@810 2821 assert(sd.region(claim_region)->claim_unsafe(), "claim() failed");
duke@435 2822 }
duke@435 2823 #endif // #ifdef ASSERT
duke@435 2824
duke@435 2825 if (beg_addr != space(space_id)->bottom()) {
duke@435 2826 // Find the first live object or block of dead space that *starts* in this
jcoomes@810 2827 // range of regions. If a partial object crosses onto the region, skip it;
jcoomes@810 2828 // it will be marked for 'deferred update' when the object head is
jcoomes@810 2829 // processed. If dead space crosses onto the region, it is also skipped; it
jcoomes@810 2830 // will be filled when the prior region is processed. If neither of those
jcoomes@810 2831 // apply, the first word in the region is the start of a live object or dead
jcoomes@810 2832 // space.
duke@435 2833 assert(beg_addr > space(space_id)->bottom(), "sanity");
jcoomes@810 2834 const RegionData* const cp = sd.region(beg_region);
duke@435 2835 if (cp->partial_obj_size() != 0) {
jcoomes@810 2836 beg_addr = sd.partial_obj_end(beg_region);
duke@435 2837 } else if (dead_space_crosses_boundary(cp, mbm->addr_to_bit(beg_addr))) {
duke@435 2838 beg_addr = mbm->find_obj_beg(beg_addr, end_addr);
duke@435 2839 }
duke@435 2840 }
duke@435 2841
duke@435 2842 if (beg_addr < end_addr) {
jcoomes@810 2843 // A live object or block of dead space starts in this range of Regions.
duke@435 2844 HeapWord* const dense_prefix_end = dense_prefix(space_id);
duke@435 2845
duke@435 2846 // Create closures and iterate.
duke@435 2847 UpdateOnlyClosure update_closure(mbm, cm, space_id);
duke@435 2848 FillClosure fill_closure(cm, space_id);
duke@435 2849 ParMarkBitMap::IterationStatus status;
duke@435 2850 status = mbm->iterate(&update_closure, &fill_closure, beg_addr, end_addr,
duke@435 2851 dense_prefix_end);
duke@435 2852 if (status == ParMarkBitMap::incomplete) {
duke@435 2853 update_closure.do_addr(update_closure.source());
duke@435 2854 }
duke@435 2855 }
duke@435 2856
jcoomes@810 2857 // Mark the regions as filled.
jcoomes@810 2858 RegionData* const beg_cp = sd.region(beg_region);
jcoomes@810 2859 RegionData* const end_cp = sd.region(end_region);
jcoomes@810 2860 for (RegionData* cp = beg_cp; cp < end_cp; ++cp) {
duke@435 2861 cp->set_completed();
duke@435 2862 }
duke@435 2863 }
duke@435 2864
duke@435 2865 // Return the SpaceId for the space containing addr. If addr is not in the
duke@435 2866 // heap, last_space_id is returned. In debug mode it expects the address to be
duke@435 2867 // in the heap and asserts such.
duke@435 2868 PSParallelCompact::SpaceId PSParallelCompact::space_id(HeapWord* addr) {
duke@435 2869 assert(Universe::heap()->is_in_reserved(addr), "addr not in the heap");
duke@435 2870
duke@435 2871 for (unsigned int id = perm_space_id; id < last_space_id; ++id) {
duke@435 2872 if (_space_info[id].space()->contains(addr)) {
duke@435 2873 return SpaceId(id);
duke@435 2874 }
duke@435 2875 }
duke@435 2876
duke@435 2877 assert(false, "no space contains the addr");
duke@435 2878 return last_space_id;
duke@435 2879 }
duke@435 2880
duke@435 2881 void PSParallelCompact::update_deferred_objects(ParCompactionManager* cm,
duke@435 2882 SpaceId id) {
duke@435 2883 assert(id < last_space_id, "bad space id");
duke@435 2884
duke@435 2885 ParallelCompactData& sd = summary_data();
duke@435 2886 const SpaceInfo* const space_info = _space_info + id;
duke@435 2887 ObjectStartArray* const start_array = space_info->start_array();
duke@435 2888
duke@435 2889 const MutableSpace* const space = space_info->space();
duke@435 2890 assert(space_info->dense_prefix() >= space->bottom(), "dense_prefix not set");
duke@435 2891 HeapWord* const beg_addr = space_info->dense_prefix();
jcoomes@810 2892 HeapWord* const end_addr = sd.region_align_up(space_info->new_top());
jcoomes@810 2893
jcoomes@810 2894 const RegionData* const beg_region = sd.addr_to_region_ptr(beg_addr);
jcoomes@810 2895 const RegionData* const end_region = sd.addr_to_region_ptr(end_addr);
jcoomes@810 2896 const RegionData* cur_region;
jcoomes@810 2897 for (cur_region = beg_region; cur_region < end_region; ++cur_region) {
jcoomes@810 2898 HeapWord* const addr = cur_region->deferred_obj_addr();
duke@435 2899 if (addr != NULL) {
duke@435 2900 if (start_array != NULL) {
duke@435 2901 start_array->allocate_block(addr);
duke@435 2902 }
duke@435 2903 oop(addr)->update_contents(cm);
duke@435 2904 assert(oop(addr)->is_oop_or_null(), "should be an oop now");
duke@435 2905 }
duke@435 2906 }
duke@435 2907 }
duke@435 2908
duke@435 2909 // Skip over count live words starting from beg, and return the address of the
duke@435 2910 // next live word. Unless marked, the word corresponding to beg is assumed to
duke@435 2911 // be dead. Callers must either ensure beg does not correspond to the middle of
duke@435 2912 // an object, or account for those live words in some other way. Callers must
duke@435 2913 // also ensure that there are enough live words in the range [beg, end) to skip.
duke@435 2914 HeapWord*
duke@435 2915 PSParallelCompact::skip_live_words(HeapWord* beg, HeapWord* end, size_t count)
duke@435 2916 {
duke@435 2917 assert(count > 0, "sanity");
duke@435 2918
duke@435 2919 ParMarkBitMap* m = mark_bitmap();
duke@435 2920 idx_t bits_to_skip = m->words_to_bits(count);
duke@435 2921 idx_t cur_beg = m->addr_to_bit(beg);
duke@435 2922 const idx_t search_end = BitMap::word_align_up(m->addr_to_bit(end));
duke@435 2923
duke@435 2924 do {
duke@435 2925 cur_beg = m->find_obj_beg(cur_beg, search_end);
duke@435 2926 idx_t cur_end = m->find_obj_end(cur_beg, search_end);
duke@435 2927 const size_t obj_bits = cur_end - cur_beg + 1;
duke@435 2928 if (obj_bits > bits_to_skip) {
duke@435 2929 return m->bit_to_addr(cur_beg + bits_to_skip);
duke@435 2930 }
duke@435 2931 bits_to_skip -= obj_bits;
duke@435 2932 cur_beg = cur_end + 1;
duke@435 2933 } while (bits_to_skip > 0);
duke@435 2934
duke@435 2935 // Skipping the desired number of words landed just past the end of an object.
duke@435 2936 // Find the start of the next object.
duke@435 2937 cur_beg = m->find_obj_beg(cur_beg, search_end);
duke@435 2938 assert(cur_beg < m->addr_to_bit(end), "not enough live words to skip");
duke@435 2939 return m->bit_to_addr(cur_beg);
duke@435 2940 }
duke@435 2941
duke@435 2942 HeapWord*
duke@435 2943 PSParallelCompact::first_src_addr(HeapWord* const dest_addr,
jcoomes@810 2944 size_t src_region_idx)
duke@435 2945 {
duke@435 2946 ParMarkBitMap* const bitmap = mark_bitmap();
duke@435 2947 const ParallelCompactData& sd = summary_data();
jcoomes@810 2948 const size_t RegionSize = ParallelCompactData::RegionSize;
jcoomes@810 2949
jcoomes@810 2950 assert(sd.is_region_aligned(dest_addr), "not aligned");
jcoomes@810 2951
jcoomes@810 2952 const RegionData* const src_region_ptr = sd.region(src_region_idx);
jcoomes@810 2953 const size_t partial_obj_size = src_region_ptr->partial_obj_size();
jcoomes@810 2954 HeapWord* const src_region_destination = src_region_ptr->destination();
jcoomes@810 2955
jcoomes@810 2956 assert(dest_addr >= src_region_destination, "wrong src region");
jcoomes@810 2957 assert(src_region_ptr->data_size() > 0, "src region cannot be empty");
jcoomes@810 2958
jcoomes@810 2959 HeapWord* const src_region_beg = sd.region_to_addr(src_region_idx);
jcoomes@810 2960 HeapWord* const src_region_end = src_region_beg + RegionSize;
jcoomes@810 2961
jcoomes@810 2962 HeapWord* addr = src_region_beg;
jcoomes@810 2963 if (dest_addr == src_region_destination) {
jcoomes@810 2964 // Return the first live word in the source region.
duke@435 2965 if (partial_obj_size == 0) {
jcoomes@810 2966 addr = bitmap->find_obj_beg(addr, src_region_end);
jcoomes@810 2967 assert(addr < src_region_end, "no objects start in src region");
duke@435 2968 }
duke@435 2969 return addr;
duke@435 2970 }
duke@435 2971
duke@435 2972 // Must skip some live data.
jcoomes@810 2973 size_t words_to_skip = dest_addr - src_region_destination;
jcoomes@810 2974 assert(src_region_ptr->data_size() > words_to_skip, "wrong src region");
duke@435 2975
duke@435 2976 if (partial_obj_size >= words_to_skip) {
duke@435 2977 // All the live words to skip are part of the partial object.
duke@435 2978 addr += words_to_skip;
duke@435 2979 if (partial_obj_size == words_to_skip) {
duke@435 2980 // Find the first live word past the partial object.
jcoomes@810 2981 addr = bitmap->find_obj_beg(addr, src_region_end);
jcoomes@810 2982 assert(addr < src_region_end, "wrong src region");
duke@435 2983 }
duke@435 2984 return addr;
duke@435 2985 }
duke@435 2986
duke@435 2987 // Skip over the partial object (if any).
duke@435 2988 if (partial_obj_size != 0) {
duke@435 2989 words_to_skip -= partial_obj_size;
duke@435 2990 addr += partial_obj_size;
duke@435 2991 }
duke@435 2992
jcoomes@810 2993 // Skip over live words due to objects that start in the region.
jcoomes@810 2994 addr = skip_live_words(addr, src_region_end, words_to_skip);
jcoomes@810 2995 assert(addr < src_region_end, "wrong src region");
duke@435 2996 return addr;
duke@435 2997 }
duke@435 2998
duke@435 2999 void PSParallelCompact::decrement_destination_counts(ParCompactionManager* cm,
jcoomes@810 3000 size_t beg_region,
duke@435 3001 HeapWord* end_addr)
duke@435 3002 {
duke@435 3003 ParallelCompactData& sd = summary_data();
jcoomes@810 3004 RegionData* const beg = sd.region(beg_region);
jcoomes@810 3005 HeapWord* const end_addr_aligned_up = sd.region_align_up(end_addr);
jcoomes@810 3006 RegionData* const end = sd.addr_to_region_ptr(end_addr_aligned_up);
jcoomes@810 3007 size_t cur_idx = beg_region;
jcoomes@810 3008 for (RegionData* cur = beg; cur < end; ++cur, ++cur_idx) {
jcoomes@810 3009 assert(cur->data_size() > 0, "region must have live data");
duke@435 3010 cur->decrement_destination_count();
jcoomes@810 3011 if (cur_idx <= cur->source_region() && cur->available() && cur->claim()) {
duke@435 3012 cm->save_for_processing(cur_idx);
duke@435 3013 }
duke@435 3014 }
duke@435 3015 }
duke@435 3016
jcoomes@810 3017 size_t PSParallelCompact::next_src_region(MoveAndUpdateClosure& closure,
jcoomes@810 3018 SpaceId& src_space_id,
jcoomes@810 3019 HeapWord*& src_space_top,
jcoomes@810 3020 HeapWord* end_addr)
duke@435 3021 {
jcoomes@810 3022 typedef ParallelCompactData::RegionData RegionData;
duke@435 3023
duke@435 3024 ParallelCompactData& sd = PSParallelCompact::summary_data();
jcoomes@810 3025 const size_t region_size = ParallelCompactData::RegionSize;
jcoomes@810 3026
jcoomes@810 3027 size_t src_region_idx = 0;
jcoomes@810 3028
jcoomes@810 3029 // Skip empty regions (if any) up to the top of the space.
jcoomes@810 3030 HeapWord* const src_aligned_up = sd.region_align_up(end_addr);
jcoomes@810 3031 RegionData* src_region_ptr = sd.addr_to_region_ptr(src_aligned_up);
jcoomes@810 3032 HeapWord* const top_aligned_up = sd.region_align_up(src_space_top);
jcoomes@810 3033 const RegionData* const top_region_ptr =
jcoomes@810 3034 sd.addr_to_region_ptr(top_aligned_up);
jcoomes@810 3035 while (src_region_ptr < top_region_ptr && src_region_ptr->data_size() == 0) {
jcoomes@810 3036 ++src_region_ptr;
duke@435 3037 }
duke@435 3038
jcoomes@810 3039 if (src_region_ptr < top_region_ptr) {
jcoomes@810 3040 // The next source region is in the current space. Update src_region_idx
jcoomes@810 3041 // and the source address to match src_region_ptr.
jcoomes@810 3042 src_region_idx = sd.region(src_region_ptr);
jcoomes@810 3043 HeapWord* const src_region_addr = sd.region_to_addr(src_region_idx);
jcoomes@810 3044 if (src_region_addr > closure.source()) {
jcoomes@810 3045 closure.set_source(src_region_addr);
duke@435 3046 }
jcoomes@810 3047 return src_region_idx;
duke@435 3048 }
duke@435 3049
jcoomes@810 3050 // Switch to a new source space and find the first non-empty region.
duke@435 3051 unsigned int space_id = src_space_id + 1;
duke@435 3052 assert(space_id < last_space_id, "not enough spaces");
duke@435 3053
duke@435 3054 HeapWord* const destination = closure.destination();
duke@435 3055
duke@435 3056 do {
duke@435 3057 MutableSpace* space = _space_info[space_id].space();
duke@435 3058 HeapWord* const bottom = space->bottom();
jcoomes@810 3059 const RegionData* const bottom_cp = sd.addr_to_region_ptr(bottom);
duke@435 3060
duke@435 3061 // Iterate over the spaces that do not compact into themselves.
duke@435 3062 if (bottom_cp->destination() != bottom) {
jcoomes@810 3063 HeapWord* const top_aligned_up = sd.region_align_up(space->top());
jcoomes@810 3064 const RegionData* const top_cp = sd.addr_to_region_ptr(top_aligned_up);
jcoomes@810 3065
jcoomes@810 3066 for (const RegionData* src_cp = bottom_cp; src_cp < top_cp; ++src_cp) {
duke@435 3067 if (src_cp->live_obj_size() > 0) {
duke@435 3068 // Found it.
duke@435 3069 assert(src_cp->destination() == destination,
duke@435 3070 "first live obj in the space must match the destination");
duke@435 3071 assert(src_cp->partial_obj_size() == 0,
duke@435 3072 "a space cannot begin with a partial obj");
duke@435 3073
duke@435 3074 src_space_id = SpaceId(space_id);
duke@435 3075 src_space_top = space->top();
jcoomes@810 3076 const size_t src_region_idx = sd.region(src_cp);
jcoomes@810 3077 closure.set_source(sd.region_to_addr(src_region_idx));
jcoomes@810 3078 return src_region_idx;
duke@435 3079 } else {
duke@435 3080 assert(src_cp->data_size() == 0, "sanity");
duke@435 3081 }
duke@435 3082 }
duke@435 3083 }
duke@435 3084 } while (++space_id < last_space_id);
duke@435 3085
jcoomes@810 3086 assert(false, "no source region was found");
duke@435 3087 return 0;
duke@435 3088 }
duke@435 3089
jcoomes@810 3090 void PSParallelCompact::fill_region(ParCompactionManager* cm, size_t region_idx)
duke@435 3091 {
duke@435 3092 typedef ParMarkBitMap::IterationStatus IterationStatus;
jcoomes@810 3093 const size_t RegionSize = ParallelCompactData::RegionSize;
duke@435 3094 ParMarkBitMap* const bitmap = mark_bitmap();
duke@435 3095 ParallelCompactData& sd = summary_data();
jcoomes@810 3096 RegionData* const region_ptr = sd.region(region_idx);
duke@435 3097
duke@435 3098 // Get the items needed to construct the closure.
jcoomes@810 3099 HeapWord* dest_addr = sd.region_to_addr(region_idx);
duke@435 3100 SpaceId dest_space_id = space_id(dest_addr);
duke@435 3101 ObjectStartArray* start_array = _space_info[dest_space_id].start_array();
duke@435 3102 HeapWord* new_top = _space_info[dest_space_id].new_top();
duke@435 3103 assert(dest_addr < new_top, "sanity");
jcoomes@810 3104 const size_t words = MIN2(pointer_delta(new_top, dest_addr), RegionSize);
jcoomes@810 3105
jcoomes@810 3106 // Get the source region and related info.
jcoomes@810 3107 size_t src_region_idx = region_ptr->source_region();
jcoomes@810 3108 SpaceId src_space_id = space_id(sd.region_to_addr(src_region_idx));
duke@435 3109 HeapWord* src_space_top = _space_info[src_space_id].space()->top();
duke@435 3110
duke@435 3111 MoveAndUpdateClosure closure(bitmap, cm, start_array, dest_addr, words);
jcoomes@810 3112 closure.set_source(first_src_addr(dest_addr, src_region_idx));
jcoomes@810 3113
jcoomes@810 3114 // Adjust src_region_idx to prepare for decrementing destination counts (the
jcoomes@810 3115 // destination count is not decremented when a region is copied to itself).
jcoomes@810 3116 if (src_region_idx == region_idx) {
jcoomes@810 3117 src_region_idx += 1;
duke@435 3118 }
duke@435 3119
duke@435 3120 if (bitmap->is_unmarked(closure.source())) {
duke@435 3121 // The first source word is in the middle of an object; copy the remainder
duke@435 3122 // of the object or as much as will fit. The fact that pointer updates were
duke@435 3123 // deferred will be noted when the object header is processed.
duke@435 3124 HeapWord* const old_src_addr = closure.source();
duke@435 3125 closure.copy_partial_obj();
duke@435 3126 if (closure.is_full()) {
jcoomes@810 3127 decrement_destination_counts(cm, src_region_idx, closure.source());
jcoomes@810 3128 region_ptr->set_deferred_obj_addr(NULL);
jcoomes@810 3129 region_ptr->set_completed();
duke@435 3130 return;
duke@435 3131 }
duke@435 3132
jcoomes@810 3133 HeapWord* const end_addr = sd.region_align_down(closure.source());
jcoomes@810 3134 if (sd.region_align_down(old_src_addr) != end_addr) {
jcoomes@810 3135 // The partial object was copied from more than one source region.
jcoomes@810 3136 decrement_destination_counts(cm, src_region_idx, end_addr);
jcoomes@810 3137
jcoomes@810 3138 // Move to the next source region, possibly switching spaces as well. All
duke@435 3139 // args except end_addr may be modified.
jcoomes@810 3140 src_region_idx = next_src_region(closure, src_space_id, src_space_top,
jcoomes@810 3141 end_addr);
duke@435 3142 }
duke@435 3143 }
duke@435 3144
duke@435 3145 do {
duke@435 3146 HeapWord* const cur_addr = closure.source();
jcoomes@810 3147 HeapWord* const end_addr = MIN2(sd.region_align_up(cur_addr + 1),
duke@435 3148 src_space_top);
duke@435 3149 IterationStatus status = bitmap->iterate(&closure, cur_addr, end_addr);
duke@435 3150
duke@435 3151 if (status == ParMarkBitMap::incomplete) {
jcoomes@810 3152 // The last obj that starts in the source region does not end in the
jcoomes@810 3153 // region.
duke@435 3154 assert(closure.source() < end_addr, "sanity")
duke@435 3155 HeapWord* const obj_beg = closure.source();
duke@435 3156 HeapWord* const range_end = MIN2(obj_beg + closure.words_remaining(),
duke@435 3157 src_space_top);
duke@435 3158 HeapWord* const obj_end = bitmap->find_obj_end(obj_beg, range_end);
duke@435 3159 if (obj_end < range_end) {
duke@435 3160 // The end was found; the entire object will fit.
duke@435 3161 status = closure.do_addr(obj_beg, bitmap->obj_size(obj_beg, obj_end));
duke@435 3162 assert(status != ParMarkBitMap::would_overflow, "sanity");
duke@435 3163 } else {
duke@435 3164 // The end was not found; the object will not fit.
duke@435 3165 assert(range_end < src_space_top, "obj cannot cross space boundary");
duke@435 3166 status = ParMarkBitMap::would_overflow;
duke@435 3167 }
duke@435 3168 }
duke@435 3169
duke@435 3170 if (status == ParMarkBitMap::would_overflow) {
duke@435 3171 // The last object did not fit. Note that interior oop updates were
jcoomes@810 3172 // deferred, then copy enough of the object to fill the region.
jcoomes@810 3173 region_ptr->set_deferred_obj_addr(closure.destination());
duke@435 3174 status = closure.copy_until_full(); // copies from closure.source()
duke@435 3175
jcoomes@810 3176 decrement_destination_counts(cm, src_region_idx, closure.source());
jcoomes@810 3177 region_ptr->set_completed();
duke@435 3178 return;
duke@435 3179 }
duke@435 3180
duke@435 3181 if (status == ParMarkBitMap::full) {
jcoomes@810 3182 decrement_destination_counts(cm, src_region_idx, closure.source());
jcoomes@810 3183 region_ptr->set_deferred_obj_addr(NULL);
jcoomes@810 3184 region_ptr->set_completed();
duke@435 3185 return;
duke@435 3186 }
duke@435 3187
jcoomes@810 3188 decrement_destination_counts(cm, src_region_idx, end_addr);
jcoomes@810 3189
jcoomes@810 3190 // Move to the next source region, possibly switching spaces as well. All
duke@435 3191 // args except end_addr may be modified.
jcoomes@810 3192 src_region_idx = next_src_region(closure, src_space_id, src_space_top,
jcoomes@810 3193 end_addr);
duke@435 3194 } while (true);
duke@435 3195 }
duke@435 3196
duke@435 3197 void
duke@435 3198 PSParallelCompact::move_and_update(ParCompactionManager* cm, SpaceId space_id) {
duke@435 3199 const MutableSpace* sp = space(space_id);
duke@435 3200 if (sp->is_empty()) {
duke@435 3201 return;
duke@435 3202 }
duke@435 3203
duke@435 3204 ParallelCompactData& sd = PSParallelCompact::summary_data();
duke@435 3205 ParMarkBitMap* const bitmap = mark_bitmap();
duke@435 3206 HeapWord* const dp_addr = dense_prefix(space_id);
duke@435 3207 HeapWord* beg_addr = sp->bottom();
duke@435 3208 HeapWord* end_addr = sp->top();
duke@435 3209
duke@435 3210 #ifdef ASSERT
duke@435 3211 assert(beg_addr <= dp_addr && dp_addr <= end_addr, "bad dense prefix");
duke@435 3212 if (cm->should_verify_only()) {
duke@435 3213 VerifyUpdateClosure verify_update(cm, sp);
duke@435 3214 bitmap->iterate(&verify_update, beg_addr, end_addr);
duke@435 3215 return;
duke@435 3216 }
duke@435 3217
duke@435 3218 if (cm->should_reset_only()) {
duke@435 3219 ResetObjectsClosure reset_objects(cm);
duke@435 3220 bitmap->iterate(&reset_objects, beg_addr, end_addr);
duke@435 3221 return;
duke@435 3222 }
duke@435 3223 #endif
duke@435 3224
jcoomes@810 3225 const size_t beg_region = sd.addr_to_region_idx(beg_addr);
jcoomes@810 3226 const size_t dp_region = sd.addr_to_region_idx(dp_addr);
jcoomes@810 3227 if (beg_region < dp_region) {
jcoomes@810 3228 update_and_deadwood_in_dense_prefix(cm, space_id, beg_region, dp_region);
duke@435 3229 }
duke@435 3230
jcoomes@810 3231 // The destination of the first live object that starts in the region is one
jcoomes@810 3232 // past the end of the partial object entering the region (if any).
jcoomes@810 3233 HeapWord* const dest_addr = sd.partial_obj_end(dp_region);
duke@435 3234 HeapWord* const new_top = _space_info[space_id].new_top();
duke@435 3235 assert(new_top >= dest_addr, "bad new_top value");
duke@435 3236 const size_t words = pointer_delta(new_top, dest_addr);
duke@435 3237
duke@435 3238 if (words > 0) {
duke@435 3239 ObjectStartArray* start_array = _space_info[space_id].start_array();
duke@435 3240 MoveAndUpdateClosure closure(bitmap, cm, start_array, dest_addr, words);
duke@435 3241
duke@435 3242 ParMarkBitMap::IterationStatus status;
duke@435 3243 status = bitmap->iterate(&closure, dest_addr, end_addr);
duke@435 3244 assert(status == ParMarkBitMap::full, "iteration not complete");
duke@435 3245 assert(bitmap->find_obj_beg(closure.source(), end_addr) == end_addr,
duke@435 3246 "live objects skipped because closure is full");
duke@435 3247 }
duke@435 3248 }
duke@435 3249
duke@435 3250 jlong PSParallelCompact::millis_since_last_gc() {
duke@435 3251 jlong ret_val = os::javaTimeMillis() - _time_of_last_gc;
duke@435 3252 // XXX See note in genCollectedHeap::millis_since_last_gc().
duke@435 3253 if (ret_val < 0) {
duke@435 3254 NOT_PRODUCT(warning("time warp: %d", ret_val);)
duke@435 3255 return 0;
duke@435 3256 }
duke@435 3257 return ret_val;
duke@435 3258 }
duke@435 3259
duke@435 3260 void PSParallelCompact::reset_millis_since_last_gc() {
duke@435 3261 _time_of_last_gc = os::javaTimeMillis();
duke@435 3262 }
duke@435 3263
duke@435 3264 ParMarkBitMap::IterationStatus MoveAndUpdateClosure::copy_until_full()
duke@435 3265 {
duke@435 3266 if (source() != destination()) {
duke@435 3267 assert(source() > destination(), "must copy to the left");
duke@435 3268 Copy::aligned_conjoint_words(source(), destination(), words_remaining());
duke@435 3269 }
duke@435 3270 update_state(words_remaining());
duke@435 3271 assert(is_full(), "sanity");
duke@435 3272 return ParMarkBitMap::full;
duke@435 3273 }
duke@435 3274
duke@435 3275 void MoveAndUpdateClosure::copy_partial_obj()
duke@435 3276 {
duke@435 3277 size_t words = words_remaining();
duke@435 3278
duke@435 3279 HeapWord* const range_end = MIN2(source() + words, bitmap()->region_end());
duke@435 3280 HeapWord* const end_addr = bitmap()->find_obj_end(source(), range_end);
duke@435 3281 if (end_addr < range_end) {
duke@435 3282 words = bitmap()->obj_size(source(), end_addr);
duke@435 3283 }
duke@435 3284
duke@435 3285 // This test is necessary; if omitted, the pointer updates to a partial object
duke@435 3286 // that crosses the dense prefix boundary could be overwritten.
duke@435 3287 if (source() != destination()) {
duke@435 3288 assert(source() > destination(), "must copy to the left");
duke@435 3289 Copy::aligned_conjoint_words(source(), destination(), words);
duke@435 3290 }
duke@435 3291 update_state(words);
duke@435 3292 }
duke@435 3293
duke@435 3294 ParMarkBitMapClosure::IterationStatus
duke@435 3295 MoveAndUpdateClosure::do_addr(HeapWord* addr, size_t words) {
duke@435 3296 assert(destination() != NULL, "sanity");
duke@435 3297 assert(bitmap()->obj_size(addr) == words, "bad size");
duke@435 3298
duke@435 3299 _source = addr;
duke@435 3300 assert(PSParallelCompact::summary_data().calc_new_pointer(source()) ==
duke@435 3301 destination(), "wrong destination");
duke@435 3302
duke@435 3303 if (words > words_remaining()) {
duke@435 3304 return ParMarkBitMap::would_overflow;
duke@435 3305 }
duke@435 3306
duke@435 3307 // The start_array must be updated even if the object is not moving.
duke@435 3308 if (_start_array != NULL) {
duke@435 3309 _start_array->allocate_block(destination());
duke@435 3310 }
duke@435 3311
duke@435 3312 if (destination() != source()) {
duke@435 3313 assert(destination() < source(), "must copy to the left");
duke@435 3314 Copy::aligned_conjoint_words(source(), destination(), words);
duke@435 3315 }
duke@435 3316
duke@435 3317 oop moved_oop = (oop) destination();
duke@435 3318 moved_oop->update_contents(compaction_manager());
duke@435 3319 assert(moved_oop->is_oop_or_null(), "Object should be whole at this point");
duke@435 3320
duke@435 3321 update_state(words);
duke@435 3322 assert(destination() == (HeapWord*)moved_oop + moved_oop->size(), "sanity");
duke@435 3323 return is_full() ? ParMarkBitMap::full : ParMarkBitMap::incomplete;
duke@435 3324 }
duke@435 3325
duke@435 3326 UpdateOnlyClosure::UpdateOnlyClosure(ParMarkBitMap* mbm,
duke@435 3327 ParCompactionManager* cm,
duke@435 3328 PSParallelCompact::SpaceId space_id) :
duke@435 3329 ParMarkBitMapClosure(mbm, cm),
duke@435 3330 _space_id(space_id),
duke@435 3331 _start_array(PSParallelCompact::start_array(space_id))
duke@435 3332 {
duke@435 3333 }
duke@435 3334
duke@435 3335 // Updates the references in the object to their new values.
duke@435 3336 ParMarkBitMapClosure::IterationStatus
duke@435 3337 UpdateOnlyClosure::do_addr(HeapWord* addr, size_t words) {
duke@435 3338 do_addr(addr);
duke@435 3339 return ParMarkBitMap::incomplete;
duke@435 3340 }
duke@435 3341
duke@435 3342 BitBlockUpdateClosure::BitBlockUpdateClosure(ParMarkBitMap* mbm,
duke@435 3343 ParCompactionManager* cm,
jcoomes@810 3344 size_t region_index) :
duke@435 3345 ParMarkBitMapClosure(mbm, cm),
duke@435 3346 _live_data_left(0),
duke@435 3347 _cur_block(0) {
jcoomes@810 3348 _region_start =
jcoomes@810 3349 PSParallelCompact::summary_data().region_to_addr(region_index);
jcoomes@810 3350 _region_end =
jcoomes@810 3351 PSParallelCompact::summary_data().region_to_addr(region_index) +
jcoomes@810 3352 ParallelCompactData::RegionSize;
jcoomes@810 3353 _region_index = region_index;
duke@435 3354 _cur_block =
jcoomes@810 3355 PSParallelCompact::summary_data().addr_to_block_idx(_region_start);
duke@435 3356 }
duke@435 3357
jcoomes@810 3358 bool BitBlockUpdateClosure::region_contains_cur_block() {
jcoomes@810 3359 return ParallelCompactData::region_contains_block(_region_index, _cur_block);
duke@435 3360 }
duke@435 3361
jcoomes@810 3362 void BitBlockUpdateClosure::reset_region(size_t region_index) {
duke@435 3363 DEBUG_ONLY(ParallelCompactData::BlockData::set_cur_phase(7);)
duke@435 3364 ParallelCompactData& sd = PSParallelCompact::summary_data();
jcoomes@810 3365 _region_index = region_index;
duke@435 3366 _live_data_left = 0;
jcoomes@810 3367 _region_start = sd.region_to_addr(region_index);
jcoomes@810 3368 _region_end = sd.region_to_addr(region_index) + ParallelCompactData::RegionSize;
jcoomes@810 3369
jcoomes@810 3370 // The first block in this region
jcoomes@810 3371 size_t first_block = sd.addr_to_block_idx(_region_start);
jcoomes@810 3372 size_t partial_live_size = sd.region(region_index)->partial_obj_size();
duke@435 3373
duke@435 3374 // Set the offset to 0. By definition it should have that value
jcoomes@810 3375 // but it may have been written while processing an earlier region.
duke@435 3376 if (partial_live_size == 0) {
jcoomes@810 3377 // No live object extends onto the region. The first bit
jcoomes@810 3378 // in the bit map for the first region must be a start bit.
duke@435 3379 // Although there may not be any marked bits, it is safe
duke@435 3380 // to set it as a start bit.
duke@435 3381 sd.block(first_block)->set_start_bit_offset(0);
duke@435 3382 sd.block(first_block)->set_first_is_start_bit(true);
duke@435 3383 } else if (sd.partial_obj_ends_in_block(first_block)) {
duke@435 3384 sd.block(first_block)->set_end_bit_offset(0);
duke@435 3385 sd.block(first_block)->set_first_is_start_bit(false);
duke@435 3386 } else {
duke@435 3387 // The partial object extends beyond the first block.
duke@435 3388 // There is no object starting in the first block
duke@435 3389 // so the offset and bit parity are not needed.
duke@435 3390 // Set the the bit parity to start bit so assertions
duke@435 3391 // work when not bit is found.
duke@435 3392 sd.block(first_block)->set_end_bit_offset(0);
duke@435 3393 sd.block(first_block)->set_first_is_start_bit(false);
duke@435 3394 }
duke@435 3395 _cur_block = first_block;
duke@435 3396 #ifdef ASSERT
duke@435 3397 if (sd.block(first_block)->first_is_start_bit()) {
duke@435 3398 assert(!sd.partial_obj_ends_in_block(first_block),
duke@435 3399 "Partial object cannot end in first block");
duke@435 3400 }
duke@435 3401
duke@435 3402 if (PrintGCDetails && Verbose) {
duke@435 3403 if (partial_live_size == 1) {
duke@435 3404 gclog_or_tty->print_cr("first_block " PTR_FORMAT
duke@435 3405 " _offset " PTR_FORMAT
duke@435 3406 " _first_is_start_bit %d",
duke@435 3407 first_block,
duke@435 3408 sd.block(first_block)->raw_offset(),
duke@435 3409 sd.block(first_block)->first_is_start_bit());
duke@435 3410 }
duke@435 3411 }
duke@435 3412 #endif
duke@435 3413 DEBUG_ONLY(ParallelCompactData::BlockData::set_cur_phase(17);)
duke@435 3414 }
duke@435 3415
duke@435 3416 // This method is called when a object has been found (both beginning
duke@435 3417 // and end of the object) in the range of iteration. This method is
duke@435 3418 // calculating the words of live data to the left of a block. That live
duke@435 3419 // data includes any object starting to the left of the block (i.e.,
duke@435 3420 // the live-data-to-the-left of block AAA will include the full size
duke@435 3421 // of any object entering AAA).
duke@435 3422
duke@435 3423 ParMarkBitMapClosure::IterationStatus
duke@435 3424 BitBlockUpdateClosure::do_addr(HeapWord* addr, size_t words) {
duke@435 3425 // add the size to the block data.
duke@435 3426 HeapWord* obj = addr;
duke@435 3427 ParallelCompactData& sd = PSParallelCompact::summary_data();
duke@435 3428
duke@435 3429 assert(bitmap()->obj_size(obj) == words, "bad size");
jcoomes@810 3430 assert(_region_start <= obj, "object is not in region");
jcoomes@810 3431 assert(obj + words <= _region_end, "object is not in region");
duke@435 3432
duke@435 3433 // Update the live data to the left
duke@435 3434 size_t prev_live_data_left = _live_data_left;
duke@435 3435 _live_data_left = _live_data_left + words;
duke@435 3436
duke@435 3437 // Is this object in the current block.
duke@435 3438 size_t block_of_obj = sd.addr_to_block_idx(obj);
duke@435 3439 size_t block_of_obj_last = sd.addr_to_block_idx(obj + words - 1);
duke@435 3440 HeapWord* block_of_obj_last_addr = sd.block_to_addr(block_of_obj_last);
duke@435 3441 if (_cur_block < block_of_obj) {
duke@435 3442
duke@435 3443 //
duke@435 3444 // No object crossed the block boundary and this object was found
duke@435 3445 // on the other side of the block boundary. Update the offset for
duke@435 3446 // the new block with the data size that does not include this object.
duke@435 3447 //
duke@435 3448 // The first bit in block_of_obj is a start bit except in the
jcoomes@810 3449 // case where the partial object for the region extends into
duke@435 3450 // this block.
duke@435 3451 if (sd.partial_obj_ends_in_block(block_of_obj)) {
duke@435 3452 sd.block(block_of_obj)->set_end_bit_offset(prev_live_data_left);
duke@435 3453 } else {
duke@435 3454 sd.block(block_of_obj)->set_start_bit_offset(prev_live_data_left);
duke@435 3455 }
duke@435 3456
duke@435 3457 // Does this object pass beyond the its block?
duke@435 3458 if (block_of_obj < block_of_obj_last) {
duke@435 3459 // Object crosses block boundary. Two blocks need to be udpated:
duke@435 3460 // the current block where the object started
duke@435 3461 // the block where the object ends
duke@435 3462 //
duke@435 3463 // The offset for blocks with no objects starting in them
duke@435 3464 // (e.g., blocks between _cur_block and block_of_obj_last)
duke@435 3465 // should not be needed.
jcoomes@810 3466 // Note that block_of_obj_last may be in another region. If so,
duke@435 3467 // it should be overwritten later. This is a problem (writting
jcoomes@810 3468 // into a block in a later region) for parallel execution.
duke@435 3469 assert(obj < block_of_obj_last_addr,
duke@435 3470 "Object should start in previous block");
duke@435 3471
duke@435 3472 // obj is crossing into block_of_obj_last so the first bit
duke@435 3473 // is and end bit.
duke@435 3474 sd.block(block_of_obj_last)->set_end_bit_offset(_live_data_left);
duke@435 3475
duke@435 3476 _cur_block = block_of_obj_last;
duke@435 3477 } else {
duke@435 3478 // _first_is_start_bit has already been set correctly
duke@435 3479 // in the if-then-else above so don't reset it here.
duke@435 3480 _cur_block = block_of_obj;
duke@435 3481 }
duke@435 3482 } else {
duke@435 3483 // The current block only changes if the object extends beyound
duke@435 3484 // the block it starts in.
duke@435 3485 //
duke@435 3486 // The object starts in the current block.
duke@435 3487 // Does this object pass beyond the end of it?
duke@435 3488 if (block_of_obj < block_of_obj_last) {
duke@435 3489 // Object crosses block boundary.
duke@435 3490 // See note above on possible blocks between block_of_obj and
duke@435 3491 // block_of_obj_last
duke@435 3492 assert(obj < block_of_obj_last_addr,
duke@435 3493 "Object should start in previous block");
duke@435 3494
duke@435 3495 sd.block(block_of_obj_last)->set_end_bit_offset(_live_data_left);
duke@435 3496
duke@435 3497 _cur_block = block_of_obj_last;
duke@435 3498 }
duke@435 3499 }
duke@435 3500
duke@435 3501 // Return incomplete if there are more blocks to be done.
jcoomes@810 3502 if (region_contains_cur_block()) {
duke@435 3503 return ParMarkBitMap::incomplete;
duke@435 3504 }
duke@435 3505 return ParMarkBitMap::complete;
duke@435 3506 }
duke@435 3507
duke@435 3508 // Verify the new location using the forwarding pointer
duke@435 3509 // from MarkSweep::mark_sweep_phase2(). Set the mark_word
duke@435 3510 // to the initial value.
duke@435 3511 ParMarkBitMapClosure::IterationStatus
duke@435 3512 PSParallelCompact::VerifyUpdateClosure::do_addr(HeapWord* addr, size_t words) {
duke@435 3513 // The second arg (words) is not used.
duke@435 3514 oop obj = (oop) addr;
duke@435 3515 HeapWord* forwarding_ptr = (HeapWord*) obj->mark()->decode_pointer();
duke@435 3516 HeapWord* new_pointer = summary_data().calc_new_pointer(obj);
duke@435 3517 if (forwarding_ptr == NULL) {
duke@435 3518 // The object is dead or not moving.
duke@435 3519 assert(bitmap()->is_unmarked(obj) || (new_pointer == (HeapWord*) obj),
duke@435 3520 "Object liveness is wrong.");
duke@435 3521 return ParMarkBitMap::incomplete;
duke@435 3522 }
duke@435 3523 assert(UseParallelOldGCDensePrefix ||
duke@435 3524 (HeapMaximumCompactionInterval > 1) ||
duke@435 3525 (MarkSweepAlwaysCompactCount > 1) ||
duke@435 3526 (forwarding_ptr == new_pointer),
duke@435 3527 "Calculation of new location is incorrect");
duke@435 3528 return ParMarkBitMap::incomplete;
duke@435 3529 }
duke@435 3530
duke@435 3531 // Reset objects modified for debug checking.
duke@435 3532 ParMarkBitMapClosure::IterationStatus
duke@435 3533 PSParallelCompact::ResetObjectsClosure::do_addr(HeapWord* addr, size_t words) {
duke@435 3534 // The second arg (words) is not used.
duke@435 3535 oop obj = (oop) addr;
duke@435 3536 obj->init_mark();
duke@435 3537 return ParMarkBitMap::incomplete;
duke@435 3538 }
duke@435 3539
duke@435 3540 // Prepare for compaction. This method is executed once
duke@435 3541 // (i.e., by a single thread) before compaction.
duke@435 3542 // Save the updated location of the intArrayKlassObj for
duke@435 3543 // filling holes in the dense prefix.
duke@435 3544 void PSParallelCompact::compact_prologue() {
duke@435 3545 _updated_int_array_klass_obj = (klassOop)
duke@435 3546 summary_data().calc_new_pointer(Universe::intArrayKlassObj());
duke@435 3547 }
duke@435 3548
duke@435 3549 // The initial implementation of this method created a field
duke@435 3550 // _next_compaction_space_id in SpaceInfo and initialized
duke@435 3551 // that field in SpaceInfo::initialize_space_info(). That
duke@435 3552 // required that _next_compaction_space_id be declared a
duke@435 3553 // SpaceId in SpaceInfo and that would have required that
duke@435 3554 // either SpaceId be declared in a separate class or that
duke@435 3555 // it be declared in SpaceInfo. It didn't seem consistent
duke@435 3556 // to declare it in SpaceInfo (didn't really fit logically).
duke@435 3557 // Alternatively, defining a separate class to define SpaceId
duke@435 3558 // seem excessive. This implementation is simple and localizes
duke@435 3559 // the knowledge.
duke@435 3560
duke@435 3561 PSParallelCompact::SpaceId
duke@435 3562 PSParallelCompact::next_compaction_space_id(SpaceId id) {
duke@435 3563 assert(id < last_space_id, "id out of range");
duke@435 3564 switch (id) {
duke@435 3565 case perm_space_id :
duke@435 3566 return last_space_id;
duke@435 3567 case old_space_id :
duke@435 3568 return eden_space_id;
duke@435 3569 case eden_space_id :
duke@435 3570 return from_space_id;
duke@435 3571 case from_space_id :
duke@435 3572 return to_space_id;
duke@435 3573 case to_space_id :
duke@435 3574 return last_space_id;
duke@435 3575 default:
duke@435 3576 assert(false, "Bad space id");
duke@435 3577 return last_space_id;
duke@435 3578 }
duke@435 3579 }
duke@435 3580
duke@435 3581 // Here temporarily for debugging
duke@435 3582 #ifdef ASSERT
duke@435 3583 size_t ParallelCompactData::block_idx(BlockData* block) {
duke@435 3584 size_t index = pointer_delta(block,
duke@435 3585 PSParallelCompact::summary_data()._block_data, sizeof(BlockData));
duke@435 3586 return index;
duke@435 3587 }
duke@435 3588 #endif

mercurial