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

Mon, 12 Aug 2019 18:30:40 +0300

author
apetushkov
date
Mon, 12 Aug 2019 18:30:40 +0300
changeset 9858
b985cbb00e68
parent 9665
a8441ccaff15
child 9931
fd44df5e3bc3
permissions
-rw-r--r--

8223147: JFR Backport
8199712: Flight Recorder
8203346: JFR: Inconsistent signature of jfr_add_string_constant
8195817: JFR.stop should require name of recording
8195818: JFR.start should increase autogenerated name by one
8195819: Remove recording=x from jcmd JFR.check output
8203921: JFR thread sampling is missing fixes from JDK-8194552
8203929: Limit amount of data for JFR.dump
8203664: JFR start failure after AppCDS archive created with JFR StartFlightRecording
8003209: JFR events for network utilization
8207392: [PPC64] Implement JFR profiling
8202835: jfr/event/os/TestSystemProcess.java fails on missing events
Summary: Backport JFR from JDK11. Initial integration
Reviewed-by: neugens

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

mercurial