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

Wed, 14 Oct 2020 17:44:48 +0800

author
aoqi
date
Wed, 14 Oct 2020 17:44:48 +0800
changeset 9931
fd44df5e3bc3
parent 9703
2fdf635bcf28
parent 9858
b985cbb00e68
permissions
-rw-r--r--

Merge

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

mercurial