1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/gc_implementation/parallelScavenge/psParallelCompact.cpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,3383 @@ 1.4 +/* 1.5 + * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#include "precompiled.hpp" 1.29 +#include "classfile/symbolTable.hpp" 1.30 +#include "classfile/systemDictionary.hpp" 1.31 +#include "code/codeCache.hpp" 1.32 +#include "gc_implementation/parallelScavenge/gcTaskManager.hpp" 1.33 +#include "gc_implementation/parallelScavenge/parallelScavengeHeap.inline.hpp" 1.34 +#include "gc_implementation/parallelScavenge/pcTasks.hpp" 1.35 +#include "gc_implementation/parallelScavenge/psAdaptiveSizePolicy.hpp" 1.36 +#include "gc_implementation/parallelScavenge/psCompactionManager.inline.hpp" 1.37 +#include "gc_implementation/parallelScavenge/psMarkSweep.hpp" 1.38 +#include "gc_implementation/parallelScavenge/psMarkSweepDecorator.hpp" 1.39 +#include "gc_implementation/parallelScavenge/psOldGen.hpp" 1.40 +#include "gc_implementation/parallelScavenge/psParallelCompact.hpp" 1.41 +#include "gc_implementation/parallelScavenge/psPromotionManager.inline.hpp" 1.42 +#include "gc_implementation/parallelScavenge/psScavenge.hpp" 1.43 +#include "gc_implementation/parallelScavenge/psYoungGen.hpp" 1.44 +#include "gc_implementation/shared/gcHeapSummary.hpp" 1.45 +#include "gc_implementation/shared/gcTimer.hpp" 1.46 +#include "gc_implementation/shared/gcTrace.hpp" 1.47 +#include "gc_implementation/shared/gcTraceTime.hpp" 1.48 +#include "gc_implementation/shared/isGCActiveMark.hpp" 1.49 +#include "gc_interface/gcCause.hpp" 1.50 +#include "memory/gcLocker.inline.hpp" 1.51 +#include "memory/referencePolicy.hpp" 1.52 +#include "memory/referenceProcessor.hpp" 1.53 +#include "oops/methodData.hpp" 1.54 +#include "oops/oop.inline.hpp" 1.55 +#include "oops/oop.pcgc.inline.hpp" 1.56 +#include "runtime/fprofiler.hpp" 1.57 +#include "runtime/safepoint.hpp" 1.58 +#include "runtime/vmThread.hpp" 1.59 +#include "services/management.hpp" 1.60 +#include "services/memoryService.hpp" 1.61 +#include "services/memTracker.hpp" 1.62 +#include "utilities/events.hpp" 1.63 +#include "utilities/stack.inline.hpp" 1.64 + 1.65 +#include <math.h> 1.66 + 1.67 +PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC 1.68 + 1.69 +// All sizes are in HeapWords. 1.70 +const size_t ParallelCompactData::Log2RegionSize = 16; // 64K words 1.71 +const size_t ParallelCompactData::RegionSize = (size_t)1 << Log2RegionSize; 1.72 +const size_t ParallelCompactData::RegionSizeBytes = 1.73 + RegionSize << LogHeapWordSize; 1.74 +const size_t ParallelCompactData::RegionSizeOffsetMask = RegionSize - 1; 1.75 +const size_t ParallelCompactData::RegionAddrOffsetMask = RegionSizeBytes - 1; 1.76 +const size_t ParallelCompactData::RegionAddrMask = ~RegionAddrOffsetMask; 1.77 + 1.78 +const size_t ParallelCompactData::Log2BlockSize = 7; // 128 words 1.79 +const size_t ParallelCompactData::BlockSize = (size_t)1 << Log2BlockSize; 1.80 +const size_t ParallelCompactData::BlockSizeBytes = 1.81 + BlockSize << LogHeapWordSize; 1.82 +const size_t ParallelCompactData::BlockSizeOffsetMask = BlockSize - 1; 1.83 +const size_t ParallelCompactData::BlockAddrOffsetMask = BlockSizeBytes - 1; 1.84 +const size_t ParallelCompactData::BlockAddrMask = ~BlockAddrOffsetMask; 1.85 + 1.86 +const size_t ParallelCompactData::BlocksPerRegion = RegionSize / BlockSize; 1.87 +const size_t ParallelCompactData::Log2BlocksPerRegion = 1.88 + Log2RegionSize - Log2BlockSize; 1.89 + 1.90 +const ParallelCompactData::RegionData::region_sz_t 1.91 +ParallelCompactData::RegionData::dc_shift = 27; 1.92 + 1.93 +const ParallelCompactData::RegionData::region_sz_t 1.94 +ParallelCompactData::RegionData::dc_mask = ~0U << dc_shift; 1.95 + 1.96 +const ParallelCompactData::RegionData::region_sz_t 1.97 +ParallelCompactData::RegionData::dc_one = 0x1U << dc_shift; 1.98 + 1.99 +const ParallelCompactData::RegionData::region_sz_t 1.100 +ParallelCompactData::RegionData::los_mask = ~dc_mask; 1.101 + 1.102 +const ParallelCompactData::RegionData::region_sz_t 1.103 +ParallelCompactData::RegionData::dc_claimed = 0x8U << dc_shift; 1.104 + 1.105 +const ParallelCompactData::RegionData::region_sz_t 1.106 +ParallelCompactData::RegionData::dc_completed = 0xcU << dc_shift; 1.107 + 1.108 +SpaceInfo PSParallelCompact::_space_info[PSParallelCompact::last_space_id]; 1.109 +bool PSParallelCompact::_print_phases = false; 1.110 + 1.111 +ReferenceProcessor* PSParallelCompact::_ref_processor = NULL; 1.112 +Klass* PSParallelCompact::_updated_int_array_klass_obj = NULL; 1.113 + 1.114 +double PSParallelCompact::_dwl_mean; 1.115 +double PSParallelCompact::_dwl_std_dev; 1.116 +double PSParallelCompact::_dwl_first_term; 1.117 +double PSParallelCompact::_dwl_adjustment; 1.118 +#ifdef ASSERT 1.119 +bool PSParallelCompact::_dwl_initialized = false; 1.120 +#endif // #ifdef ASSERT 1.121 + 1.122 +void SplitInfo::record(size_t src_region_idx, size_t partial_obj_size, 1.123 + HeapWord* destination) 1.124 +{ 1.125 + assert(src_region_idx != 0, "invalid src_region_idx"); 1.126 + assert(partial_obj_size != 0, "invalid partial_obj_size argument"); 1.127 + assert(destination != NULL, "invalid destination argument"); 1.128 + 1.129 + _src_region_idx = src_region_idx; 1.130 + _partial_obj_size = partial_obj_size; 1.131 + _destination = destination; 1.132 + 1.133 + // These fields may not be updated below, so make sure they're clear. 1.134 + assert(_dest_region_addr == NULL, "should have been cleared"); 1.135 + assert(_first_src_addr == NULL, "should have been cleared"); 1.136 + 1.137 + // Determine the number of destination regions for the partial object. 1.138 + HeapWord* const last_word = destination + partial_obj_size - 1; 1.139 + const ParallelCompactData& sd = PSParallelCompact::summary_data(); 1.140 + HeapWord* const beg_region_addr = sd.region_align_down(destination); 1.141 + HeapWord* const end_region_addr = sd.region_align_down(last_word); 1.142 + 1.143 + if (beg_region_addr == end_region_addr) { 1.144 + // One destination region. 1.145 + _destination_count = 1; 1.146 + if (end_region_addr == destination) { 1.147 + // The destination falls on a region boundary, thus the first word of the 1.148 + // partial object will be the first word copied to the destination region. 1.149 + _dest_region_addr = end_region_addr; 1.150 + _first_src_addr = sd.region_to_addr(src_region_idx); 1.151 + } 1.152 + } else { 1.153 + // Two destination regions. When copied, the partial object will cross a 1.154 + // destination region boundary, so a word somewhere within the partial 1.155 + // object will be the first word copied to the second destination region. 1.156 + _destination_count = 2; 1.157 + _dest_region_addr = end_region_addr; 1.158 + const size_t ofs = pointer_delta(end_region_addr, destination); 1.159 + assert(ofs < _partial_obj_size, "sanity"); 1.160 + _first_src_addr = sd.region_to_addr(src_region_idx) + ofs; 1.161 + } 1.162 +} 1.163 + 1.164 +void SplitInfo::clear() 1.165 +{ 1.166 + _src_region_idx = 0; 1.167 + _partial_obj_size = 0; 1.168 + _destination = NULL; 1.169 + _destination_count = 0; 1.170 + _dest_region_addr = NULL; 1.171 + _first_src_addr = NULL; 1.172 + assert(!is_valid(), "sanity"); 1.173 +} 1.174 + 1.175 +#ifdef ASSERT 1.176 +void SplitInfo::verify_clear() 1.177 +{ 1.178 + assert(_src_region_idx == 0, "not clear"); 1.179 + assert(_partial_obj_size == 0, "not clear"); 1.180 + assert(_destination == NULL, "not clear"); 1.181 + assert(_destination_count == 0, "not clear"); 1.182 + assert(_dest_region_addr == NULL, "not clear"); 1.183 + assert(_first_src_addr == NULL, "not clear"); 1.184 +} 1.185 +#endif // #ifdef ASSERT 1.186 + 1.187 + 1.188 +void PSParallelCompact::print_on_error(outputStream* st) { 1.189 + _mark_bitmap.print_on_error(st); 1.190 +} 1.191 + 1.192 +#ifndef PRODUCT 1.193 +const char* PSParallelCompact::space_names[] = { 1.194 + "old ", "eden", "from", "to " 1.195 +}; 1.196 + 1.197 +void PSParallelCompact::print_region_ranges() 1.198 +{ 1.199 + tty->print_cr("space bottom top end new_top"); 1.200 + tty->print_cr("------ ---------- ---------- ---------- ----------"); 1.201 + 1.202 + for (unsigned int id = 0; id < last_space_id; ++id) { 1.203 + const MutableSpace* space = _space_info[id].space(); 1.204 + tty->print_cr("%u %s " 1.205 + SIZE_FORMAT_W(10) " " SIZE_FORMAT_W(10) " " 1.206 + SIZE_FORMAT_W(10) " " SIZE_FORMAT_W(10) " ", 1.207 + id, space_names[id], 1.208 + summary_data().addr_to_region_idx(space->bottom()), 1.209 + summary_data().addr_to_region_idx(space->top()), 1.210 + summary_data().addr_to_region_idx(space->end()), 1.211 + summary_data().addr_to_region_idx(_space_info[id].new_top())); 1.212 + } 1.213 +} 1.214 + 1.215 +void 1.216 +print_generic_summary_region(size_t i, const ParallelCompactData::RegionData* c) 1.217 +{ 1.218 +#define REGION_IDX_FORMAT SIZE_FORMAT_W(7) 1.219 +#define REGION_DATA_FORMAT SIZE_FORMAT_W(5) 1.220 + 1.221 + ParallelCompactData& sd = PSParallelCompact::summary_data(); 1.222 + size_t dci = c->destination() ? sd.addr_to_region_idx(c->destination()) : 0; 1.223 + tty->print_cr(REGION_IDX_FORMAT " " PTR_FORMAT " " 1.224 + REGION_IDX_FORMAT " " PTR_FORMAT " " 1.225 + REGION_DATA_FORMAT " " REGION_DATA_FORMAT " " 1.226 + REGION_DATA_FORMAT " " REGION_IDX_FORMAT " %d", 1.227 + i, c->data_location(), dci, c->destination(), 1.228 + c->partial_obj_size(), c->live_obj_size(), 1.229 + c->data_size(), c->source_region(), c->destination_count()); 1.230 + 1.231 +#undef REGION_IDX_FORMAT 1.232 +#undef REGION_DATA_FORMAT 1.233 +} 1.234 + 1.235 +void 1.236 +print_generic_summary_data(ParallelCompactData& summary_data, 1.237 + HeapWord* const beg_addr, 1.238 + HeapWord* const end_addr) 1.239 +{ 1.240 + size_t total_words = 0; 1.241 + size_t i = summary_data.addr_to_region_idx(beg_addr); 1.242 + const size_t last = summary_data.addr_to_region_idx(end_addr); 1.243 + HeapWord* pdest = 0; 1.244 + 1.245 + while (i <= last) { 1.246 + ParallelCompactData::RegionData* c = summary_data.region(i); 1.247 + if (c->data_size() != 0 || c->destination() != pdest) { 1.248 + print_generic_summary_region(i, c); 1.249 + total_words += c->data_size(); 1.250 + pdest = c->destination(); 1.251 + } 1.252 + ++i; 1.253 + } 1.254 + 1.255 + tty->print_cr("summary_data_bytes=" SIZE_FORMAT, total_words * HeapWordSize); 1.256 +} 1.257 + 1.258 +void 1.259 +print_generic_summary_data(ParallelCompactData& summary_data, 1.260 + SpaceInfo* space_info) 1.261 +{ 1.262 + for (unsigned int id = 0; id < PSParallelCompact::last_space_id; ++id) { 1.263 + const MutableSpace* space = space_info[id].space(); 1.264 + print_generic_summary_data(summary_data, space->bottom(), 1.265 + MAX2(space->top(), space_info[id].new_top())); 1.266 + } 1.267 +} 1.268 + 1.269 +void 1.270 +print_initial_summary_region(size_t i, 1.271 + const ParallelCompactData::RegionData* c, 1.272 + bool newline = true) 1.273 +{ 1.274 + tty->print(SIZE_FORMAT_W(5) " " PTR_FORMAT " " 1.275 + SIZE_FORMAT_W(5) " " SIZE_FORMAT_W(5) " " 1.276 + SIZE_FORMAT_W(5) " " SIZE_FORMAT_W(5) " %d", 1.277 + i, c->destination(), 1.278 + c->partial_obj_size(), c->live_obj_size(), 1.279 + c->data_size(), c->source_region(), c->destination_count()); 1.280 + if (newline) tty->cr(); 1.281 +} 1.282 + 1.283 +void 1.284 +print_initial_summary_data(ParallelCompactData& summary_data, 1.285 + const MutableSpace* space) { 1.286 + if (space->top() == space->bottom()) { 1.287 + return; 1.288 + } 1.289 + 1.290 + const size_t region_size = ParallelCompactData::RegionSize; 1.291 + typedef ParallelCompactData::RegionData RegionData; 1.292 + HeapWord* const top_aligned_up = summary_data.region_align_up(space->top()); 1.293 + const size_t end_region = summary_data.addr_to_region_idx(top_aligned_up); 1.294 + const RegionData* c = summary_data.region(end_region - 1); 1.295 + HeapWord* end_addr = c->destination() + c->data_size(); 1.296 + const size_t live_in_space = pointer_delta(end_addr, space->bottom()); 1.297 + 1.298 + // Print (and count) the full regions at the beginning of the space. 1.299 + size_t full_region_count = 0; 1.300 + size_t i = summary_data.addr_to_region_idx(space->bottom()); 1.301 + while (i < end_region && summary_data.region(i)->data_size() == region_size) { 1.302 + print_initial_summary_region(i, summary_data.region(i)); 1.303 + ++full_region_count; 1.304 + ++i; 1.305 + } 1.306 + 1.307 + size_t live_to_right = live_in_space - full_region_count * region_size; 1.308 + 1.309 + double max_reclaimed_ratio = 0.0; 1.310 + size_t max_reclaimed_ratio_region = 0; 1.311 + size_t max_dead_to_right = 0; 1.312 + size_t max_live_to_right = 0; 1.313 + 1.314 + // Print the 'reclaimed ratio' for regions while there is something live in 1.315 + // the region or to the right of it. The remaining regions are empty (and 1.316 + // uninteresting), and computing the ratio will result in division by 0. 1.317 + while (i < end_region && live_to_right > 0) { 1.318 + c = summary_data.region(i); 1.319 + HeapWord* const region_addr = summary_data.region_to_addr(i); 1.320 + const size_t used_to_right = pointer_delta(space->top(), region_addr); 1.321 + const size_t dead_to_right = used_to_right - live_to_right; 1.322 + const double reclaimed_ratio = double(dead_to_right) / live_to_right; 1.323 + 1.324 + if (reclaimed_ratio > max_reclaimed_ratio) { 1.325 + max_reclaimed_ratio = reclaimed_ratio; 1.326 + max_reclaimed_ratio_region = i; 1.327 + max_dead_to_right = dead_to_right; 1.328 + max_live_to_right = live_to_right; 1.329 + } 1.330 + 1.331 + print_initial_summary_region(i, c, false); 1.332 + tty->print_cr(" %12.10f " SIZE_FORMAT_W(10) " " SIZE_FORMAT_W(10), 1.333 + reclaimed_ratio, dead_to_right, live_to_right); 1.334 + 1.335 + live_to_right -= c->data_size(); 1.336 + ++i; 1.337 + } 1.338 + 1.339 + // Any remaining regions are empty. Print one more if there is one. 1.340 + if (i < end_region) { 1.341 + print_initial_summary_region(i, summary_data.region(i)); 1.342 + } 1.343 + 1.344 + tty->print_cr("max: " SIZE_FORMAT_W(4) " d2r=" SIZE_FORMAT_W(10) " " 1.345 + "l2r=" SIZE_FORMAT_W(10) " max_ratio=%14.12f", 1.346 + max_reclaimed_ratio_region, max_dead_to_right, 1.347 + max_live_to_right, max_reclaimed_ratio); 1.348 +} 1.349 + 1.350 +void 1.351 +print_initial_summary_data(ParallelCompactData& summary_data, 1.352 + SpaceInfo* space_info) { 1.353 + unsigned int id = PSParallelCompact::old_space_id; 1.354 + const MutableSpace* space; 1.355 + do { 1.356 + space = space_info[id].space(); 1.357 + print_initial_summary_data(summary_data, space); 1.358 + } while (++id < PSParallelCompact::eden_space_id); 1.359 + 1.360 + do { 1.361 + space = space_info[id].space(); 1.362 + print_generic_summary_data(summary_data, space->bottom(), space->top()); 1.363 + } while (++id < PSParallelCompact::last_space_id); 1.364 +} 1.365 +#endif // #ifndef PRODUCT 1.366 + 1.367 +#ifdef ASSERT 1.368 +size_t add_obj_count; 1.369 +size_t add_obj_size; 1.370 +size_t mark_bitmap_count; 1.371 +size_t mark_bitmap_size; 1.372 +#endif // #ifdef ASSERT 1.373 + 1.374 +ParallelCompactData::ParallelCompactData() 1.375 +{ 1.376 + _region_start = 0; 1.377 + 1.378 + _region_vspace = 0; 1.379 + _reserved_byte_size = 0; 1.380 + _region_data = 0; 1.381 + _region_count = 0; 1.382 + 1.383 + _block_vspace = 0; 1.384 + _block_data = 0; 1.385 + _block_count = 0; 1.386 +} 1.387 + 1.388 +bool ParallelCompactData::initialize(MemRegion covered_region) 1.389 +{ 1.390 + _region_start = covered_region.start(); 1.391 + const size_t region_size = covered_region.word_size(); 1.392 + DEBUG_ONLY(_region_end = _region_start + region_size;) 1.393 + 1.394 + assert(region_align_down(_region_start) == _region_start, 1.395 + "region start not aligned"); 1.396 + assert((region_size & RegionSizeOffsetMask) == 0, 1.397 + "region size not a multiple of RegionSize"); 1.398 + 1.399 + bool result = initialize_region_data(region_size) && initialize_block_data(); 1.400 + return result; 1.401 +} 1.402 + 1.403 +PSVirtualSpace* 1.404 +ParallelCompactData::create_vspace(size_t count, size_t element_size) 1.405 +{ 1.406 + const size_t raw_bytes = count * element_size; 1.407 + const size_t page_sz = os::page_size_for_region(raw_bytes, raw_bytes, 10); 1.408 + const size_t granularity = os::vm_allocation_granularity(); 1.409 + _reserved_byte_size = align_size_up(raw_bytes, MAX2(page_sz, granularity)); 1.410 + 1.411 + const size_t rs_align = page_sz == (size_t) os::vm_page_size() ? 0 : 1.412 + MAX2(page_sz, granularity); 1.413 + ReservedSpace rs(_reserved_byte_size, rs_align, rs_align > 0); 1.414 + os::trace_page_sizes("par compact", raw_bytes, raw_bytes, page_sz, rs.base(), 1.415 + rs.size()); 1.416 + 1.417 + MemTracker::record_virtual_memory_type((address)rs.base(), mtGC); 1.418 + 1.419 + PSVirtualSpace* vspace = new PSVirtualSpace(rs, page_sz); 1.420 + if (vspace != 0) { 1.421 + if (vspace->expand_by(_reserved_byte_size)) { 1.422 + return vspace; 1.423 + } 1.424 + delete vspace; 1.425 + // Release memory reserved in the space. 1.426 + rs.release(); 1.427 + } 1.428 + 1.429 + return 0; 1.430 +} 1.431 + 1.432 +bool ParallelCompactData::initialize_region_data(size_t region_size) 1.433 +{ 1.434 + const size_t count = (region_size + RegionSizeOffsetMask) >> Log2RegionSize; 1.435 + _region_vspace = create_vspace(count, sizeof(RegionData)); 1.436 + if (_region_vspace != 0) { 1.437 + _region_data = (RegionData*)_region_vspace->reserved_low_addr(); 1.438 + _region_count = count; 1.439 + return true; 1.440 + } 1.441 + return false; 1.442 +} 1.443 + 1.444 +bool ParallelCompactData::initialize_block_data() 1.445 +{ 1.446 + assert(_region_count != 0, "region data must be initialized first"); 1.447 + const size_t count = _region_count << Log2BlocksPerRegion; 1.448 + _block_vspace = create_vspace(count, sizeof(BlockData)); 1.449 + if (_block_vspace != 0) { 1.450 + _block_data = (BlockData*)_block_vspace->reserved_low_addr(); 1.451 + _block_count = count; 1.452 + return true; 1.453 + } 1.454 + return false; 1.455 +} 1.456 + 1.457 +void ParallelCompactData::clear() 1.458 +{ 1.459 + memset(_region_data, 0, _region_vspace->committed_size()); 1.460 + memset(_block_data, 0, _block_vspace->committed_size()); 1.461 +} 1.462 + 1.463 +void ParallelCompactData::clear_range(size_t beg_region, size_t end_region) { 1.464 + assert(beg_region <= _region_count, "beg_region out of range"); 1.465 + assert(end_region <= _region_count, "end_region out of range"); 1.466 + assert(RegionSize % BlockSize == 0, "RegionSize not a multiple of BlockSize"); 1.467 + 1.468 + const size_t region_cnt = end_region - beg_region; 1.469 + memset(_region_data + beg_region, 0, region_cnt * sizeof(RegionData)); 1.470 + 1.471 + const size_t beg_block = beg_region * BlocksPerRegion; 1.472 + const size_t block_cnt = region_cnt * BlocksPerRegion; 1.473 + memset(_block_data + beg_block, 0, block_cnt * sizeof(BlockData)); 1.474 +} 1.475 + 1.476 +HeapWord* ParallelCompactData::partial_obj_end(size_t region_idx) const 1.477 +{ 1.478 + const RegionData* cur_cp = region(region_idx); 1.479 + const RegionData* const end_cp = region(region_count() - 1); 1.480 + 1.481 + HeapWord* result = region_to_addr(region_idx); 1.482 + if (cur_cp < end_cp) { 1.483 + do { 1.484 + result += cur_cp->partial_obj_size(); 1.485 + } while (cur_cp->partial_obj_size() == RegionSize && ++cur_cp < end_cp); 1.486 + } 1.487 + return result; 1.488 +} 1.489 + 1.490 +void ParallelCompactData::add_obj(HeapWord* addr, size_t len) 1.491 +{ 1.492 + const size_t obj_ofs = pointer_delta(addr, _region_start); 1.493 + const size_t beg_region = obj_ofs >> Log2RegionSize; 1.494 + const size_t end_region = (obj_ofs + len - 1) >> Log2RegionSize; 1.495 + 1.496 + DEBUG_ONLY(Atomic::inc_ptr(&add_obj_count);) 1.497 + DEBUG_ONLY(Atomic::add_ptr(len, &add_obj_size);) 1.498 + 1.499 + if (beg_region == end_region) { 1.500 + // All in one region. 1.501 + _region_data[beg_region].add_live_obj(len); 1.502 + return; 1.503 + } 1.504 + 1.505 + // First region. 1.506 + const size_t beg_ofs = region_offset(addr); 1.507 + _region_data[beg_region].add_live_obj(RegionSize - beg_ofs); 1.508 + 1.509 + Klass* klass = ((oop)addr)->klass(); 1.510 + // Middle regions--completely spanned by this object. 1.511 + for (size_t region = beg_region + 1; region < end_region; ++region) { 1.512 + _region_data[region].set_partial_obj_size(RegionSize); 1.513 + _region_data[region].set_partial_obj_addr(addr); 1.514 + } 1.515 + 1.516 + // Last region. 1.517 + const size_t end_ofs = region_offset(addr + len - 1); 1.518 + _region_data[end_region].set_partial_obj_size(end_ofs + 1); 1.519 + _region_data[end_region].set_partial_obj_addr(addr); 1.520 +} 1.521 + 1.522 +void 1.523 +ParallelCompactData::summarize_dense_prefix(HeapWord* beg, HeapWord* end) 1.524 +{ 1.525 + assert(region_offset(beg) == 0, "not RegionSize aligned"); 1.526 + assert(region_offset(end) == 0, "not RegionSize aligned"); 1.527 + 1.528 + size_t cur_region = addr_to_region_idx(beg); 1.529 + const size_t end_region = addr_to_region_idx(end); 1.530 + HeapWord* addr = beg; 1.531 + while (cur_region < end_region) { 1.532 + _region_data[cur_region].set_destination(addr); 1.533 + _region_data[cur_region].set_destination_count(0); 1.534 + _region_data[cur_region].set_source_region(cur_region); 1.535 + _region_data[cur_region].set_data_location(addr); 1.536 + 1.537 + // Update live_obj_size so the region appears completely full. 1.538 + size_t live_size = RegionSize - _region_data[cur_region].partial_obj_size(); 1.539 + _region_data[cur_region].set_live_obj_size(live_size); 1.540 + 1.541 + ++cur_region; 1.542 + addr += RegionSize; 1.543 + } 1.544 +} 1.545 + 1.546 +// Find the point at which a space can be split and, if necessary, record the 1.547 +// split point. 1.548 +// 1.549 +// If the current src region (which overflowed the destination space) doesn't 1.550 +// have a partial object, the split point is at the beginning of the current src 1.551 +// region (an "easy" split, no extra bookkeeping required). 1.552 +// 1.553 +// If the current src region has a partial object, the split point is in the 1.554 +// region where that partial object starts (call it the split_region). If 1.555 +// split_region has a partial object, then the split point is just after that 1.556 +// partial object (a "hard" split where we have to record the split data and 1.557 +// zero the partial_obj_size field). With a "hard" split, we know that the 1.558 +// partial_obj ends within split_region because the partial object that caused 1.559 +// the overflow starts in split_region. If split_region doesn't have a partial 1.560 +// obj, then the split is at the beginning of split_region (another "easy" 1.561 +// split). 1.562 +HeapWord* 1.563 +ParallelCompactData::summarize_split_space(size_t src_region, 1.564 + SplitInfo& split_info, 1.565 + HeapWord* destination, 1.566 + HeapWord* target_end, 1.567 + HeapWord** target_next) 1.568 +{ 1.569 + assert(destination <= target_end, "sanity"); 1.570 + assert(destination + _region_data[src_region].data_size() > target_end, 1.571 + "region should not fit into target space"); 1.572 + assert(is_region_aligned(target_end), "sanity"); 1.573 + 1.574 + size_t split_region = src_region; 1.575 + HeapWord* split_destination = destination; 1.576 + size_t partial_obj_size = _region_data[src_region].partial_obj_size(); 1.577 + 1.578 + if (destination + partial_obj_size > target_end) { 1.579 + // The split point is just after the partial object (if any) in the 1.580 + // src_region that contains the start of the object that overflowed the 1.581 + // destination space. 1.582 + // 1.583 + // Find the start of the "overflow" object and set split_region to the 1.584 + // region containing it. 1.585 + HeapWord* const overflow_obj = _region_data[src_region].partial_obj_addr(); 1.586 + split_region = addr_to_region_idx(overflow_obj); 1.587 + 1.588 + // Clear the source_region field of all destination regions whose first word 1.589 + // came from data after the split point (a non-null source_region field 1.590 + // implies a region must be filled). 1.591 + // 1.592 + // An alternative to the simple loop below: clear during post_compact(), 1.593 + // which uses memcpy instead of individual stores, and is easy to 1.594 + // parallelize. (The downside is that it clears the entire RegionData 1.595 + // object as opposed to just one field.) 1.596 + // 1.597 + // post_compact() would have to clear the summary data up to the highest 1.598 + // address that was written during the summary phase, which would be 1.599 + // 1.600 + // max(top, max(new_top, clear_top)) 1.601 + // 1.602 + // where clear_top is a new field in SpaceInfo. Would have to set clear_top 1.603 + // to target_end. 1.604 + const RegionData* const sr = region(split_region); 1.605 + const size_t beg_idx = 1.606 + addr_to_region_idx(region_align_up(sr->destination() + 1.607 + sr->partial_obj_size())); 1.608 + const size_t end_idx = addr_to_region_idx(target_end); 1.609 + 1.610 + if (TraceParallelOldGCSummaryPhase) { 1.611 + gclog_or_tty->print_cr("split: clearing source_region field in [" 1.612 + SIZE_FORMAT ", " SIZE_FORMAT ")", 1.613 + beg_idx, end_idx); 1.614 + } 1.615 + for (size_t idx = beg_idx; idx < end_idx; ++idx) { 1.616 + _region_data[idx].set_source_region(0); 1.617 + } 1.618 + 1.619 + // Set split_destination and partial_obj_size to reflect the split region. 1.620 + split_destination = sr->destination(); 1.621 + partial_obj_size = sr->partial_obj_size(); 1.622 + } 1.623 + 1.624 + // The split is recorded only if a partial object extends onto the region. 1.625 + if (partial_obj_size != 0) { 1.626 + _region_data[split_region].set_partial_obj_size(0); 1.627 + split_info.record(split_region, partial_obj_size, split_destination); 1.628 + } 1.629 + 1.630 + // Setup the continuation addresses. 1.631 + *target_next = split_destination + partial_obj_size; 1.632 + HeapWord* const source_next = region_to_addr(split_region) + partial_obj_size; 1.633 + 1.634 + if (TraceParallelOldGCSummaryPhase) { 1.635 + const char * split_type = partial_obj_size == 0 ? "easy" : "hard"; 1.636 + gclog_or_tty->print_cr("%s split: src=" PTR_FORMAT " src_c=" SIZE_FORMAT 1.637 + " pos=" SIZE_FORMAT, 1.638 + split_type, source_next, split_region, 1.639 + partial_obj_size); 1.640 + gclog_or_tty->print_cr("%s split: dst=" PTR_FORMAT " dst_c=" SIZE_FORMAT 1.641 + " tn=" PTR_FORMAT, 1.642 + split_type, split_destination, 1.643 + addr_to_region_idx(split_destination), 1.644 + *target_next); 1.645 + 1.646 + if (partial_obj_size != 0) { 1.647 + HeapWord* const po_beg = split_info.destination(); 1.648 + HeapWord* const po_end = po_beg + split_info.partial_obj_size(); 1.649 + gclog_or_tty->print_cr("%s split: " 1.650 + "po_beg=" PTR_FORMAT " " SIZE_FORMAT " " 1.651 + "po_end=" PTR_FORMAT " " SIZE_FORMAT, 1.652 + split_type, 1.653 + po_beg, addr_to_region_idx(po_beg), 1.654 + po_end, addr_to_region_idx(po_end)); 1.655 + } 1.656 + } 1.657 + 1.658 + return source_next; 1.659 +} 1.660 + 1.661 +bool ParallelCompactData::summarize(SplitInfo& split_info, 1.662 + HeapWord* source_beg, HeapWord* source_end, 1.663 + HeapWord** source_next, 1.664 + HeapWord* target_beg, HeapWord* target_end, 1.665 + HeapWord** target_next) 1.666 +{ 1.667 + if (TraceParallelOldGCSummaryPhase) { 1.668 + HeapWord* const source_next_val = source_next == NULL ? NULL : *source_next; 1.669 + tty->print_cr("sb=" PTR_FORMAT " se=" PTR_FORMAT " sn=" PTR_FORMAT 1.670 + "tb=" PTR_FORMAT " te=" PTR_FORMAT " tn=" PTR_FORMAT, 1.671 + source_beg, source_end, source_next_val, 1.672 + target_beg, target_end, *target_next); 1.673 + } 1.674 + 1.675 + size_t cur_region = addr_to_region_idx(source_beg); 1.676 + const size_t end_region = addr_to_region_idx(region_align_up(source_end)); 1.677 + 1.678 + HeapWord *dest_addr = target_beg; 1.679 + while (cur_region < end_region) { 1.680 + // The destination must be set even if the region has no data. 1.681 + _region_data[cur_region].set_destination(dest_addr); 1.682 + 1.683 + size_t words = _region_data[cur_region].data_size(); 1.684 + if (words > 0) { 1.685 + // If cur_region does not fit entirely into the target space, find a point 1.686 + // at which the source space can be 'split' so that part is copied to the 1.687 + // target space and the rest is copied elsewhere. 1.688 + if (dest_addr + words > target_end) { 1.689 + assert(source_next != NULL, "source_next is NULL when splitting"); 1.690 + *source_next = summarize_split_space(cur_region, split_info, dest_addr, 1.691 + target_end, target_next); 1.692 + return false; 1.693 + } 1.694 + 1.695 + // Compute the destination_count for cur_region, and if necessary, update 1.696 + // source_region for a destination region. The source_region field is 1.697 + // updated if cur_region is the first (left-most) region to be copied to a 1.698 + // destination region. 1.699 + // 1.700 + // The destination_count calculation is a bit subtle. A region that has 1.701 + // data that compacts into itself does not count itself as a destination. 1.702 + // This maintains the invariant that a zero count means the region is 1.703 + // available and can be claimed and then filled. 1.704 + uint destination_count = 0; 1.705 + if (split_info.is_split(cur_region)) { 1.706 + // The current region has been split: the partial object will be copied 1.707 + // to one destination space and the remaining data will be copied to 1.708 + // another destination space. Adjust the initial destination_count and, 1.709 + // if necessary, set the source_region field if the partial object will 1.710 + // cross a destination region boundary. 1.711 + destination_count = split_info.destination_count(); 1.712 + if (destination_count == 2) { 1.713 + size_t dest_idx = addr_to_region_idx(split_info.dest_region_addr()); 1.714 + _region_data[dest_idx].set_source_region(cur_region); 1.715 + } 1.716 + } 1.717 + 1.718 + HeapWord* const last_addr = dest_addr + words - 1; 1.719 + const size_t dest_region_1 = addr_to_region_idx(dest_addr); 1.720 + const size_t dest_region_2 = addr_to_region_idx(last_addr); 1.721 + 1.722 + // Initially assume that the destination regions will be the same and 1.723 + // adjust the value below if necessary. Under this assumption, if 1.724 + // cur_region == dest_region_2, then cur_region will be compacted 1.725 + // completely into itself. 1.726 + destination_count += cur_region == dest_region_2 ? 0 : 1; 1.727 + if (dest_region_1 != dest_region_2) { 1.728 + // Destination regions differ; adjust destination_count. 1.729 + destination_count += 1; 1.730 + // Data from cur_region will be copied to the start of dest_region_2. 1.731 + _region_data[dest_region_2].set_source_region(cur_region); 1.732 + } else if (region_offset(dest_addr) == 0) { 1.733 + // Data from cur_region will be copied to the start of the destination 1.734 + // region. 1.735 + _region_data[dest_region_1].set_source_region(cur_region); 1.736 + } 1.737 + 1.738 + _region_data[cur_region].set_destination_count(destination_count); 1.739 + _region_data[cur_region].set_data_location(region_to_addr(cur_region)); 1.740 + dest_addr += words; 1.741 + } 1.742 + 1.743 + ++cur_region; 1.744 + } 1.745 + 1.746 + *target_next = dest_addr; 1.747 + return true; 1.748 +} 1.749 + 1.750 +HeapWord* ParallelCompactData::calc_new_pointer(HeapWord* addr) { 1.751 + assert(addr != NULL, "Should detect NULL oop earlier"); 1.752 + assert(PSParallelCompact::gc_heap()->is_in(addr), "not in heap"); 1.753 + assert(PSParallelCompact::mark_bitmap()->is_marked(addr), "not marked"); 1.754 + 1.755 + // Region covering the object. 1.756 + RegionData* const region_ptr = addr_to_region_ptr(addr); 1.757 + HeapWord* result = region_ptr->destination(); 1.758 + 1.759 + // If the entire Region is live, the new location is region->destination + the 1.760 + // offset of the object within in the Region. 1.761 + 1.762 + // Run some performance tests to determine if this special case pays off. It 1.763 + // is worth it for pointers into the dense prefix. If the optimization to 1.764 + // avoid pointer updates in regions that only point to the dense prefix is 1.765 + // ever implemented, this should be revisited. 1.766 + if (region_ptr->data_size() == RegionSize) { 1.767 + result += region_offset(addr); 1.768 + return result; 1.769 + } 1.770 + 1.771 + // Otherwise, the new location is region->destination + block offset + the 1.772 + // number of live words in the Block that are (a) to the left of addr and (b) 1.773 + // due to objects that start in the Block. 1.774 + 1.775 + // Fill in the block table if necessary. This is unsynchronized, so multiple 1.776 + // threads may fill the block table for a region (harmless, since it is 1.777 + // idempotent). 1.778 + if (!region_ptr->blocks_filled()) { 1.779 + PSParallelCompact::fill_blocks(addr_to_region_idx(addr)); 1.780 + region_ptr->set_blocks_filled(); 1.781 + } 1.782 + 1.783 + HeapWord* const search_start = block_align_down(addr); 1.784 + const size_t block_offset = addr_to_block_ptr(addr)->offset(); 1.785 + 1.786 + const ParMarkBitMap* bitmap = PSParallelCompact::mark_bitmap(); 1.787 + const size_t live = bitmap->live_words_in_range(search_start, oop(addr)); 1.788 + result += block_offset + live; 1.789 + DEBUG_ONLY(PSParallelCompact::check_new_location(addr, result)); 1.790 + return result; 1.791 +} 1.792 + 1.793 +#ifdef ASSERT 1.794 +void ParallelCompactData::verify_clear(const PSVirtualSpace* vspace) 1.795 +{ 1.796 + const size_t* const beg = (const size_t*)vspace->committed_low_addr(); 1.797 + const size_t* const end = (const size_t*)vspace->committed_high_addr(); 1.798 + for (const size_t* p = beg; p < end; ++p) { 1.799 + assert(*p == 0, "not zero"); 1.800 + } 1.801 +} 1.802 + 1.803 +void ParallelCompactData::verify_clear() 1.804 +{ 1.805 + verify_clear(_region_vspace); 1.806 + verify_clear(_block_vspace); 1.807 +} 1.808 +#endif // #ifdef ASSERT 1.809 + 1.810 +STWGCTimer PSParallelCompact::_gc_timer; 1.811 +ParallelOldTracer PSParallelCompact::_gc_tracer; 1.812 +elapsedTimer PSParallelCompact::_accumulated_time; 1.813 +unsigned int PSParallelCompact::_total_invocations = 0; 1.814 +unsigned int PSParallelCompact::_maximum_compaction_gc_num = 0; 1.815 +jlong PSParallelCompact::_time_of_last_gc = 0; 1.816 +CollectorCounters* PSParallelCompact::_counters = NULL; 1.817 +ParMarkBitMap PSParallelCompact::_mark_bitmap; 1.818 +ParallelCompactData PSParallelCompact::_summary_data; 1.819 + 1.820 +PSParallelCompact::IsAliveClosure PSParallelCompact::_is_alive_closure; 1.821 + 1.822 +bool PSParallelCompact::IsAliveClosure::do_object_b(oop p) { return mark_bitmap()->is_marked(p); } 1.823 + 1.824 +void PSParallelCompact::KeepAliveClosure::do_oop(oop* p) { PSParallelCompact::KeepAliveClosure::do_oop_work(p); } 1.825 +void PSParallelCompact::KeepAliveClosure::do_oop(narrowOop* p) { PSParallelCompact::KeepAliveClosure::do_oop_work(p); } 1.826 + 1.827 +PSParallelCompact::AdjustPointerClosure PSParallelCompact::_adjust_pointer_closure; 1.828 +PSParallelCompact::AdjustKlassClosure PSParallelCompact::_adjust_klass_closure; 1.829 + 1.830 +void PSParallelCompact::AdjustPointerClosure::do_oop(oop* p) { adjust_pointer(p); } 1.831 +void PSParallelCompact::AdjustPointerClosure::do_oop(narrowOop* p) { adjust_pointer(p); } 1.832 + 1.833 +void PSParallelCompact::FollowStackClosure::do_void() { _compaction_manager->follow_marking_stacks(); } 1.834 + 1.835 +void PSParallelCompact::MarkAndPushClosure::do_oop(oop* p) { 1.836 + mark_and_push(_compaction_manager, p); 1.837 +} 1.838 +void PSParallelCompact::MarkAndPushClosure::do_oop(narrowOop* p) { mark_and_push(_compaction_manager, p); } 1.839 + 1.840 +void PSParallelCompact::FollowKlassClosure::do_klass(Klass* klass) { 1.841 + klass->oops_do(_mark_and_push_closure); 1.842 +} 1.843 +void PSParallelCompact::AdjustKlassClosure::do_klass(Klass* klass) { 1.844 + klass->oops_do(&PSParallelCompact::_adjust_pointer_closure); 1.845 +} 1.846 + 1.847 +void PSParallelCompact::post_initialize() { 1.848 + ParallelScavengeHeap* heap = gc_heap(); 1.849 + assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity"); 1.850 + 1.851 + MemRegion mr = heap->reserved_region(); 1.852 + _ref_processor = 1.853 + new ReferenceProcessor(mr, // span 1.854 + ParallelRefProcEnabled && (ParallelGCThreads > 1), // mt processing 1.855 + (int) ParallelGCThreads, // mt processing degree 1.856 + true, // mt discovery 1.857 + (int) ParallelGCThreads, // mt discovery degree 1.858 + true, // atomic_discovery 1.859 + &_is_alive_closure); // non-header is alive closure 1.860 + _counters = new CollectorCounters("PSParallelCompact", 1); 1.861 + 1.862 + // Initialize static fields in ParCompactionManager. 1.863 + ParCompactionManager::initialize(mark_bitmap()); 1.864 +} 1.865 + 1.866 +bool PSParallelCompact::initialize() { 1.867 + ParallelScavengeHeap* heap = gc_heap(); 1.868 + assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity"); 1.869 + MemRegion mr = heap->reserved_region(); 1.870 + 1.871 + // Was the old gen get allocated successfully? 1.872 + if (!heap->old_gen()->is_allocated()) { 1.873 + return false; 1.874 + } 1.875 + 1.876 + initialize_space_info(); 1.877 + initialize_dead_wood_limiter(); 1.878 + 1.879 + if (!_mark_bitmap.initialize(mr)) { 1.880 + vm_shutdown_during_initialization( 1.881 + err_msg("Unable to allocate " SIZE_FORMAT "KB bitmaps for parallel " 1.882 + "garbage collection for the requested " SIZE_FORMAT "KB heap.", 1.883 + _mark_bitmap.reserved_byte_size()/K, mr.byte_size()/K)); 1.884 + return false; 1.885 + } 1.886 + 1.887 + if (!_summary_data.initialize(mr)) { 1.888 + vm_shutdown_during_initialization( 1.889 + err_msg("Unable to allocate " SIZE_FORMAT "KB card tables for parallel " 1.890 + "garbage collection for the requested " SIZE_FORMAT "KB heap.", 1.891 + _summary_data.reserved_byte_size()/K, mr.byte_size()/K)); 1.892 + return false; 1.893 + } 1.894 + 1.895 + return true; 1.896 +} 1.897 + 1.898 +void PSParallelCompact::initialize_space_info() 1.899 +{ 1.900 + memset(&_space_info, 0, sizeof(_space_info)); 1.901 + 1.902 + ParallelScavengeHeap* heap = gc_heap(); 1.903 + PSYoungGen* young_gen = heap->young_gen(); 1.904 + 1.905 + _space_info[old_space_id].set_space(heap->old_gen()->object_space()); 1.906 + _space_info[eden_space_id].set_space(young_gen->eden_space()); 1.907 + _space_info[from_space_id].set_space(young_gen->from_space()); 1.908 + _space_info[to_space_id].set_space(young_gen->to_space()); 1.909 + 1.910 + _space_info[old_space_id].set_start_array(heap->old_gen()->start_array()); 1.911 +} 1.912 + 1.913 +void PSParallelCompact::initialize_dead_wood_limiter() 1.914 +{ 1.915 + const size_t max = 100; 1.916 + _dwl_mean = double(MIN2(ParallelOldDeadWoodLimiterMean, max)) / 100.0; 1.917 + _dwl_std_dev = double(MIN2(ParallelOldDeadWoodLimiterStdDev, max)) / 100.0; 1.918 + _dwl_first_term = 1.0 / (sqrt(2.0 * M_PI) * _dwl_std_dev); 1.919 + DEBUG_ONLY(_dwl_initialized = true;) 1.920 + _dwl_adjustment = normal_distribution(1.0); 1.921 +} 1.922 + 1.923 +// Simple class for storing info about the heap at the start of GC, to be used 1.924 +// after GC for comparison/printing. 1.925 +class PreGCValues { 1.926 +public: 1.927 + PreGCValues() { } 1.928 + PreGCValues(ParallelScavengeHeap* heap) { fill(heap); } 1.929 + 1.930 + void fill(ParallelScavengeHeap* heap) { 1.931 + _heap_used = heap->used(); 1.932 + _young_gen_used = heap->young_gen()->used_in_bytes(); 1.933 + _old_gen_used = heap->old_gen()->used_in_bytes(); 1.934 + _metadata_used = MetaspaceAux::used_bytes(); 1.935 + }; 1.936 + 1.937 + size_t heap_used() const { return _heap_used; } 1.938 + size_t young_gen_used() const { return _young_gen_used; } 1.939 + size_t old_gen_used() const { return _old_gen_used; } 1.940 + size_t metadata_used() const { return _metadata_used; } 1.941 + 1.942 +private: 1.943 + size_t _heap_used; 1.944 + size_t _young_gen_used; 1.945 + size_t _old_gen_used; 1.946 + size_t _metadata_used; 1.947 +}; 1.948 + 1.949 +void 1.950 +PSParallelCompact::clear_data_covering_space(SpaceId id) 1.951 +{ 1.952 + // At this point, top is the value before GC, new_top() is the value that will 1.953 + // be set at the end of GC. The marking bitmap is cleared to top; nothing 1.954 + // should be marked above top. The summary data is cleared to the larger of 1.955 + // top & new_top. 1.956 + MutableSpace* const space = _space_info[id].space(); 1.957 + HeapWord* const bot = space->bottom(); 1.958 + HeapWord* const top = space->top(); 1.959 + HeapWord* const max_top = MAX2(top, _space_info[id].new_top()); 1.960 + 1.961 + const idx_t beg_bit = _mark_bitmap.addr_to_bit(bot); 1.962 + const idx_t end_bit = BitMap::word_align_up(_mark_bitmap.addr_to_bit(top)); 1.963 + _mark_bitmap.clear_range(beg_bit, end_bit); 1.964 + 1.965 + const size_t beg_region = _summary_data.addr_to_region_idx(bot); 1.966 + const size_t end_region = 1.967 + _summary_data.addr_to_region_idx(_summary_data.region_align_up(max_top)); 1.968 + _summary_data.clear_range(beg_region, end_region); 1.969 + 1.970 + // Clear the data used to 'split' regions. 1.971 + SplitInfo& split_info = _space_info[id].split_info(); 1.972 + if (split_info.is_valid()) { 1.973 + split_info.clear(); 1.974 + } 1.975 + DEBUG_ONLY(split_info.verify_clear();) 1.976 +} 1.977 + 1.978 +void PSParallelCompact::pre_compact(PreGCValues* pre_gc_values) 1.979 +{ 1.980 + // Update the from & to space pointers in space_info, since they are swapped 1.981 + // at each young gen gc. Do the update unconditionally (even though a 1.982 + // promotion failure does not swap spaces) because an unknown number of minor 1.983 + // collections will have swapped the spaces an unknown number of times. 1.984 + GCTraceTime tm("pre compact", print_phases(), true, &_gc_timer); 1.985 + ParallelScavengeHeap* heap = gc_heap(); 1.986 + _space_info[from_space_id].set_space(heap->young_gen()->from_space()); 1.987 + _space_info[to_space_id].set_space(heap->young_gen()->to_space()); 1.988 + 1.989 + pre_gc_values->fill(heap); 1.990 + 1.991 + DEBUG_ONLY(add_obj_count = add_obj_size = 0;) 1.992 + DEBUG_ONLY(mark_bitmap_count = mark_bitmap_size = 0;) 1.993 + 1.994 + // Increment the invocation count 1.995 + heap->increment_total_collections(true); 1.996 + 1.997 + // We need to track unique mark sweep invocations as well. 1.998 + _total_invocations++; 1.999 + 1.1000 + heap->print_heap_before_gc(); 1.1001 + heap->trace_heap_before_gc(&_gc_tracer); 1.1002 + 1.1003 + // Fill in TLABs 1.1004 + heap->accumulate_statistics_all_tlabs(); 1.1005 + heap->ensure_parsability(true); // retire TLABs 1.1006 + 1.1007 + if (VerifyBeforeGC && heap->total_collections() >= VerifyGCStartAt) { 1.1008 + HandleMark hm; // Discard invalid handles created during verification 1.1009 + Universe::verify(" VerifyBeforeGC:"); 1.1010 + } 1.1011 + 1.1012 + // Verify object start arrays 1.1013 + if (VerifyObjectStartArray && 1.1014 + VerifyBeforeGC) { 1.1015 + heap->old_gen()->verify_object_start_array(); 1.1016 + } 1.1017 + 1.1018 + DEBUG_ONLY(mark_bitmap()->verify_clear();) 1.1019 + DEBUG_ONLY(summary_data().verify_clear();) 1.1020 + 1.1021 + // Have worker threads release resources the next time they run a task. 1.1022 + gc_task_manager()->release_all_resources(); 1.1023 +} 1.1024 + 1.1025 +void PSParallelCompact::post_compact() 1.1026 +{ 1.1027 + GCTraceTime tm("post compact", print_phases(), true, &_gc_timer); 1.1028 + 1.1029 + for (unsigned int id = old_space_id; id < last_space_id; ++id) { 1.1030 + // Clear the marking bitmap, summary data and split info. 1.1031 + clear_data_covering_space(SpaceId(id)); 1.1032 + // Update top(). Must be done after clearing the bitmap and summary data. 1.1033 + _space_info[id].publish_new_top(); 1.1034 + } 1.1035 + 1.1036 + MutableSpace* const eden_space = _space_info[eden_space_id].space(); 1.1037 + MutableSpace* const from_space = _space_info[from_space_id].space(); 1.1038 + MutableSpace* const to_space = _space_info[to_space_id].space(); 1.1039 + 1.1040 + ParallelScavengeHeap* heap = gc_heap(); 1.1041 + bool eden_empty = eden_space->is_empty(); 1.1042 + if (!eden_empty) { 1.1043 + eden_empty = absorb_live_data_from_eden(heap->size_policy(), 1.1044 + heap->young_gen(), heap->old_gen()); 1.1045 + } 1.1046 + 1.1047 + // Update heap occupancy information which is used as input to the soft ref 1.1048 + // clearing policy at the next gc. 1.1049 + Universe::update_heap_info_at_gc(); 1.1050 + 1.1051 + bool young_gen_empty = eden_empty && from_space->is_empty() && 1.1052 + to_space->is_empty(); 1.1053 + 1.1054 + BarrierSet* bs = heap->barrier_set(); 1.1055 + if (bs->is_a(BarrierSet::ModRef)) { 1.1056 + ModRefBarrierSet* modBS = (ModRefBarrierSet*)bs; 1.1057 + MemRegion old_mr = heap->old_gen()->reserved(); 1.1058 + 1.1059 + if (young_gen_empty) { 1.1060 + modBS->clear(MemRegion(old_mr.start(), old_mr.end())); 1.1061 + } else { 1.1062 + modBS->invalidate(MemRegion(old_mr.start(), old_mr.end())); 1.1063 + } 1.1064 + } 1.1065 + 1.1066 + // Delete metaspaces for unloaded class loaders and clean up loader_data graph 1.1067 + ClassLoaderDataGraph::purge(); 1.1068 + MetaspaceAux::verify_metrics(); 1.1069 + 1.1070 + Threads::gc_epilogue(); 1.1071 + CodeCache::gc_epilogue(); 1.1072 + JvmtiExport::gc_epilogue(); 1.1073 + 1.1074 + COMPILER2_PRESENT(DerivedPointerTable::update_pointers()); 1.1075 + 1.1076 + ref_processor()->enqueue_discovered_references(NULL); 1.1077 + 1.1078 + if (ZapUnusedHeapArea) { 1.1079 + heap->gen_mangle_unused_area(); 1.1080 + } 1.1081 + 1.1082 + // Update time of last GC 1.1083 + reset_millis_since_last_gc(); 1.1084 +} 1.1085 + 1.1086 +HeapWord* 1.1087 +PSParallelCompact::compute_dense_prefix_via_density(const SpaceId id, 1.1088 + bool maximum_compaction) 1.1089 +{ 1.1090 + const size_t region_size = ParallelCompactData::RegionSize; 1.1091 + const ParallelCompactData& sd = summary_data(); 1.1092 + 1.1093 + const MutableSpace* const space = _space_info[id].space(); 1.1094 + HeapWord* const top_aligned_up = sd.region_align_up(space->top()); 1.1095 + const RegionData* const beg_cp = sd.addr_to_region_ptr(space->bottom()); 1.1096 + const RegionData* const end_cp = sd.addr_to_region_ptr(top_aligned_up); 1.1097 + 1.1098 + // Skip full regions at the beginning of the space--they are necessarily part 1.1099 + // of the dense prefix. 1.1100 + size_t full_count = 0; 1.1101 + const RegionData* cp; 1.1102 + for (cp = beg_cp; cp < end_cp && cp->data_size() == region_size; ++cp) { 1.1103 + ++full_count; 1.1104 + } 1.1105 + 1.1106 + assert(total_invocations() >= _maximum_compaction_gc_num, "sanity"); 1.1107 + const size_t gcs_since_max = total_invocations() - _maximum_compaction_gc_num; 1.1108 + const bool interval_ended = gcs_since_max > HeapMaximumCompactionInterval; 1.1109 + if (maximum_compaction || cp == end_cp || interval_ended) { 1.1110 + _maximum_compaction_gc_num = total_invocations(); 1.1111 + return sd.region_to_addr(cp); 1.1112 + } 1.1113 + 1.1114 + HeapWord* const new_top = _space_info[id].new_top(); 1.1115 + const size_t space_live = pointer_delta(new_top, space->bottom()); 1.1116 + const size_t space_used = space->used_in_words(); 1.1117 + const size_t space_capacity = space->capacity_in_words(); 1.1118 + 1.1119 + const double cur_density = double(space_live) / space_capacity; 1.1120 + const double deadwood_density = 1.1121 + (1.0 - cur_density) * (1.0 - cur_density) * cur_density * cur_density; 1.1122 + const size_t deadwood_goal = size_t(space_capacity * deadwood_density); 1.1123 + 1.1124 + if (TraceParallelOldGCDensePrefix) { 1.1125 + tty->print_cr("cur_dens=%5.3f dw_dens=%5.3f dw_goal=" SIZE_FORMAT, 1.1126 + cur_density, deadwood_density, deadwood_goal); 1.1127 + tty->print_cr("space_live=" SIZE_FORMAT " " "space_used=" SIZE_FORMAT " " 1.1128 + "space_cap=" SIZE_FORMAT, 1.1129 + space_live, space_used, 1.1130 + space_capacity); 1.1131 + } 1.1132 + 1.1133 + // XXX - Use binary search? 1.1134 + HeapWord* dense_prefix = sd.region_to_addr(cp); 1.1135 + const RegionData* full_cp = cp; 1.1136 + const RegionData* const top_cp = sd.addr_to_region_ptr(space->top() - 1); 1.1137 + while (cp < end_cp) { 1.1138 + HeapWord* region_destination = cp->destination(); 1.1139 + const size_t cur_deadwood = pointer_delta(dense_prefix, region_destination); 1.1140 + if (TraceParallelOldGCDensePrefix && Verbose) { 1.1141 + tty->print_cr("c#=" SIZE_FORMAT_W(4) " dst=" PTR_FORMAT " " 1.1142 + "dp=" SIZE_FORMAT_W(8) " " "cdw=" SIZE_FORMAT_W(8), 1.1143 + sd.region(cp), region_destination, 1.1144 + dense_prefix, cur_deadwood); 1.1145 + } 1.1146 + 1.1147 + if (cur_deadwood >= deadwood_goal) { 1.1148 + // Found the region that has the correct amount of deadwood to the left. 1.1149 + // This typically occurs after crossing a fairly sparse set of regions, so 1.1150 + // iterate backwards over those sparse regions, looking for the region 1.1151 + // that has the lowest density of live objects 'to the right.' 1.1152 + size_t space_to_left = sd.region(cp) * region_size; 1.1153 + size_t live_to_left = space_to_left - cur_deadwood; 1.1154 + size_t space_to_right = space_capacity - space_to_left; 1.1155 + size_t live_to_right = space_live - live_to_left; 1.1156 + double density_to_right = double(live_to_right) / space_to_right; 1.1157 + while (cp > full_cp) { 1.1158 + --cp; 1.1159 + const size_t prev_region_live_to_right = live_to_right - 1.1160 + cp->data_size(); 1.1161 + const size_t prev_region_space_to_right = space_to_right + region_size; 1.1162 + double prev_region_density_to_right = 1.1163 + double(prev_region_live_to_right) / prev_region_space_to_right; 1.1164 + if (density_to_right <= prev_region_density_to_right) { 1.1165 + return dense_prefix; 1.1166 + } 1.1167 + if (TraceParallelOldGCDensePrefix && Verbose) { 1.1168 + tty->print_cr("backing up from c=" SIZE_FORMAT_W(4) " d2r=%10.8f " 1.1169 + "pc_d2r=%10.8f", sd.region(cp), density_to_right, 1.1170 + prev_region_density_to_right); 1.1171 + } 1.1172 + dense_prefix -= region_size; 1.1173 + live_to_right = prev_region_live_to_right; 1.1174 + space_to_right = prev_region_space_to_right; 1.1175 + density_to_right = prev_region_density_to_right; 1.1176 + } 1.1177 + return dense_prefix; 1.1178 + } 1.1179 + 1.1180 + dense_prefix += region_size; 1.1181 + ++cp; 1.1182 + } 1.1183 + 1.1184 + return dense_prefix; 1.1185 +} 1.1186 + 1.1187 +#ifndef PRODUCT 1.1188 +void PSParallelCompact::print_dense_prefix_stats(const char* const algorithm, 1.1189 + const SpaceId id, 1.1190 + const bool maximum_compaction, 1.1191 + HeapWord* const addr) 1.1192 +{ 1.1193 + const size_t region_idx = summary_data().addr_to_region_idx(addr); 1.1194 + RegionData* const cp = summary_data().region(region_idx); 1.1195 + const MutableSpace* const space = _space_info[id].space(); 1.1196 + HeapWord* const new_top = _space_info[id].new_top(); 1.1197 + 1.1198 + const size_t space_live = pointer_delta(new_top, space->bottom()); 1.1199 + const size_t dead_to_left = pointer_delta(addr, cp->destination()); 1.1200 + const size_t space_cap = space->capacity_in_words(); 1.1201 + const double dead_to_left_pct = double(dead_to_left) / space_cap; 1.1202 + const size_t live_to_right = new_top - cp->destination(); 1.1203 + const size_t dead_to_right = space->top() - addr - live_to_right; 1.1204 + 1.1205 + tty->print_cr("%s=" PTR_FORMAT " dpc=" SIZE_FORMAT_W(5) " " 1.1206 + "spl=" SIZE_FORMAT " " 1.1207 + "d2l=" SIZE_FORMAT " d2l%%=%6.4f " 1.1208 + "d2r=" SIZE_FORMAT " l2r=" SIZE_FORMAT 1.1209 + " ratio=%10.8f", 1.1210 + algorithm, addr, region_idx, 1.1211 + space_live, 1.1212 + dead_to_left, dead_to_left_pct, 1.1213 + dead_to_right, live_to_right, 1.1214 + double(dead_to_right) / live_to_right); 1.1215 +} 1.1216 +#endif // #ifndef PRODUCT 1.1217 + 1.1218 +// Return a fraction indicating how much of the generation can be treated as 1.1219 +// "dead wood" (i.e., not reclaimed). The function uses a normal distribution 1.1220 +// based on the density of live objects in the generation to determine a limit, 1.1221 +// which is then adjusted so the return value is min_percent when the density is 1.1222 +// 1. 1.1223 +// 1.1224 +// The following table shows some return values for a different values of the 1.1225 +// standard deviation (ParallelOldDeadWoodLimiterStdDev); the mean is 0.5 and 1.1226 +// min_percent is 1. 1.1227 +// 1.1228 +// fraction allowed as dead wood 1.1229 +// ----------------------------------------------------------------- 1.1230 +// density std_dev=70 std_dev=75 std_dev=80 std_dev=85 std_dev=90 std_dev=95 1.1231 +// ------- ---------- ---------- ---------- ---------- ---------- ---------- 1.1232 +// 0.00000 0.01000000 0.01000000 0.01000000 0.01000000 0.01000000 0.01000000 1.1233 +// 0.05000 0.03193096 0.02836880 0.02550828 0.02319280 0.02130337 0.01974941 1.1234 +// 0.10000 0.05247504 0.04547452 0.03988045 0.03537016 0.03170171 0.02869272 1.1235 +// 0.15000 0.07135702 0.06111390 0.05296419 0.04641639 0.04110601 0.03676066 1.1236 +// 0.20000 0.08831616 0.07509618 0.06461766 0.05622444 0.04943437 0.04388975 1.1237 +// 0.25000 0.10311208 0.08724696 0.07471205 0.06469760 0.05661313 0.05002313 1.1238 +// 0.30000 0.11553050 0.09741183 0.08313394 0.07175114 0.06257797 0.05511132 1.1239 +// 0.35000 0.12538832 0.10545958 0.08978741 0.07731366 0.06727491 0.05911289 1.1240 +// 0.40000 0.13253818 0.11128511 0.09459590 0.08132834 0.07066107 0.06199500 1.1241 +// 0.45000 0.13687208 0.11481163 0.09750361 0.08375387 0.07270534 0.06373386 1.1242 +// 0.50000 0.13832410 0.11599237 0.09847664 0.08456518 0.07338887 0.06431510 1.1243 +// 0.55000 0.13687208 0.11481163 0.09750361 0.08375387 0.07270534 0.06373386 1.1244 +// 0.60000 0.13253818 0.11128511 0.09459590 0.08132834 0.07066107 0.06199500 1.1245 +// 0.65000 0.12538832 0.10545958 0.08978741 0.07731366 0.06727491 0.05911289 1.1246 +// 0.70000 0.11553050 0.09741183 0.08313394 0.07175114 0.06257797 0.05511132 1.1247 +// 0.75000 0.10311208 0.08724696 0.07471205 0.06469760 0.05661313 0.05002313 1.1248 +// 0.80000 0.08831616 0.07509618 0.06461766 0.05622444 0.04943437 0.04388975 1.1249 +// 0.85000 0.07135702 0.06111390 0.05296419 0.04641639 0.04110601 0.03676066 1.1250 +// 0.90000 0.05247504 0.04547452 0.03988045 0.03537016 0.03170171 0.02869272 1.1251 +// 0.95000 0.03193096 0.02836880 0.02550828 0.02319280 0.02130337 0.01974941 1.1252 +// 1.00000 0.01000000 0.01000000 0.01000000 0.01000000 0.01000000 0.01000000 1.1253 + 1.1254 +double PSParallelCompact::dead_wood_limiter(double density, size_t min_percent) 1.1255 +{ 1.1256 + assert(_dwl_initialized, "uninitialized"); 1.1257 + 1.1258 + // The raw limit is the value of the normal distribution at x = density. 1.1259 + const double raw_limit = normal_distribution(density); 1.1260 + 1.1261 + // Adjust the raw limit so it becomes the minimum when the density is 1. 1.1262 + // 1.1263 + // First subtract the adjustment value (which is simply the precomputed value 1.1264 + // normal_distribution(1.0)); this yields a value of 0 when the density is 1. 1.1265 + // Then add the minimum value, so the minimum is returned when the density is 1.1266 + // 1. Finally, prevent negative values, which occur when the mean is not 0.5. 1.1267 + const double min = double(min_percent) / 100.0; 1.1268 + const double limit = raw_limit - _dwl_adjustment + min; 1.1269 + return MAX2(limit, 0.0); 1.1270 +} 1.1271 + 1.1272 +ParallelCompactData::RegionData* 1.1273 +PSParallelCompact::first_dead_space_region(const RegionData* beg, 1.1274 + const RegionData* end) 1.1275 +{ 1.1276 + const size_t region_size = ParallelCompactData::RegionSize; 1.1277 + ParallelCompactData& sd = summary_data(); 1.1278 + size_t left = sd.region(beg); 1.1279 + size_t right = end > beg ? sd.region(end) - 1 : left; 1.1280 + 1.1281 + // Binary search. 1.1282 + while (left < right) { 1.1283 + // Equivalent to (left + right) / 2, but does not overflow. 1.1284 + const size_t middle = left + (right - left) / 2; 1.1285 + RegionData* const middle_ptr = sd.region(middle); 1.1286 + HeapWord* const dest = middle_ptr->destination(); 1.1287 + HeapWord* const addr = sd.region_to_addr(middle); 1.1288 + assert(dest != NULL, "sanity"); 1.1289 + assert(dest <= addr, "must move left"); 1.1290 + 1.1291 + if (middle > left && dest < addr) { 1.1292 + right = middle - 1; 1.1293 + } else if (middle < right && middle_ptr->data_size() == region_size) { 1.1294 + left = middle + 1; 1.1295 + } else { 1.1296 + return middle_ptr; 1.1297 + } 1.1298 + } 1.1299 + return sd.region(left); 1.1300 +} 1.1301 + 1.1302 +ParallelCompactData::RegionData* 1.1303 +PSParallelCompact::dead_wood_limit_region(const RegionData* beg, 1.1304 + const RegionData* end, 1.1305 + size_t dead_words) 1.1306 +{ 1.1307 + ParallelCompactData& sd = summary_data(); 1.1308 + size_t left = sd.region(beg); 1.1309 + size_t right = end > beg ? sd.region(end) - 1 : left; 1.1310 + 1.1311 + // Binary search. 1.1312 + while (left < right) { 1.1313 + // Equivalent to (left + right) / 2, but does not overflow. 1.1314 + const size_t middle = left + (right - left) / 2; 1.1315 + RegionData* const middle_ptr = sd.region(middle); 1.1316 + HeapWord* const dest = middle_ptr->destination(); 1.1317 + HeapWord* const addr = sd.region_to_addr(middle); 1.1318 + assert(dest != NULL, "sanity"); 1.1319 + assert(dest <= addr, "must move left"); 1.1320 + 1.1321 + const size_t dead_to_left = pointer_delta(addr, dest); 1.1322 + if (middle > left && dead_to_left > dead_words) { 1.1323 + right = middle - 1; 1.1324 + } else if (middle < right && dead_to_left < dead_words) { 1.1325 + left = middle + 1; 1.1326 + } else { 1.1327 + return middle_ptr; 1.1328 + } 1.1329 + } 1.1330 + return sd.region(left); 1.1331 +} 1.1332 + 1.1333 +// The result is valid during the summary phase, after the initial summarization 1.1334 +// of each space into itself, and before final summarization. 1.1335 +inline double 1.1336 +PSParallelCompact::reclaimed_ratio(const RegionData* const cp, 1.1337 + HeapWord* const bottom, 1.1338 + HeapWord* const top, 1.1339 + HeapWord* const new_top) 1.1340 +{ 1.1341 + ParallelCompactData& sd = summary_data(); 1.1342 + 1.1343 + assert(cp != NULL, "sanity"); 1.1344 + assert(bottom != NULL, "sanity"); 1.1345 + assert(top != NULL, "sanity"); 1.1346 + assert(new_top != NULL, "sanity"); 1.1347 + assert(top >= new_top, "summary data problem?"); 1.1348 + assert(new_top > bottom, "space is empty; should not be here"); 1.1349 + assert(new_top >= cp->destination(), "sanity"); 1.1350 + assert(top >= sd.region_to_addr(cp), "sanity"); 1.1351 + 1.1352 + HeapWord* const destination = cp->destination(); 1.1353 + const size_t dense_prefix_live = pointer_delta(destination, bottom); 1.1354 + const size_t compacted_region_live = pointer_delta(new_top, destination); 1.1355 + const size_t compacted_region_used = pointer_delta(top, 1.1356 + sd.region_to_addr(cp)); 1.1357 + const size_t reclaimable = compacted_region_used - compacted_region_live; 1.1358 + 1.1359 + const double divisor = dense_prefix_live + 1.25 * compacted_region_live; 1.1360 + return double(reclaimable) / divisor; 1.1361 +} 1.1362 + 1.1363 +// Return the address of the end of the dense prefix, a.k.a. the start of the 1.1364 +// compacted region. The address is always on a region boundary. 1.1365 +// 1.1366 +// Completely full regions at the left are skipped, since no compaction can 1.1367 +// occur in those regions. Then the maximum amount of dead wood to allow is 1.1368 +// computed, based on the density (amount live / capacity) of the generation; 1.1369 +// the region with approximately that amount of dead space to the left is 1.1370 +// identified as the limit region. Regions between the last completely full 1.1371 +// region and the limit region are scanned and the one that has the best 1.1372 +// (maximum) reclaimed_ratio() is selected. 1.1373 +HeapWord* 1.1374 +PSParallelCompact::compute_dense_prefix(const SpaceId id, 1.1375 + bool maximum_compaction) 1.1376 +{ 1.1377 + if (ParallelOldGCSplitALot) { 1.1378 + if (_space_info[id].dense_prefix() != _space_info[id].space()->bottom()) { 1.1379 + // The value was chosen to provoke splitting a young gen space; use it. 1.1380 + return _space_info[id].dense_prefix(); 1.1381 + } 1.1382 + } 1.1383 + 1.1384 + const size_t region_size = ParallelCompactData::RegionSize; 1.1385 + const ParallelCompactData& sd = summary_data(); 1.1386 + 1.1387 + const MutableSpace* const space = _space_info[id].space(); 1.1388 + HeapWord* const top = space->top(); 1.1389 + HeapWord* const top_aligned_up = sd.region_align_up(top); 1.1390 + HeapWord* const new_top = _space_info[id].new_top(); 1.1391 + HeapWord* const new_top_aligned_up = sd.region_align_up(new_top); 1.1392 + HeapWord* const bottom = space->bottom(); 1.1393 + const RegionData* const beg_cp = sd.addr_to_region_ptr(bottom); 1.1394 + const RegionData* const top_cp = sd.addr_to_region_ptr(top_aligned_up); 1.1395 + const RegionData* const new_top_cp = 1.1396 + sd.addr_to_region_ptr(new_top_aligned_up); 1.1397 + 1.1398 + // Skip full regions at the beginning of the space--they are necessarily part 1.1399 + // of the dense prefix. 1.1400 + const RegionData* const full_cp = first_dead_space_region(beg_cp, new_top_cp); 1.1401 + assert(full_cp->destination() == sd.region_to_addr(full_cp) || 1.1402 + space->is_empty(), "no dead space allowed to the left"); 1.1403 + assert(full_cp->data_size() < region_size || full_cp == new_top_cp - 1, 1.1404 + "region must have dead space"); 1.1405 + 1.1406 + // The gc number is saved whenever a maximum compaction is done, and used to 1.1407 + // determine when the maximum compaction interval has expired. This avoids 1.1408 + // successive max compactions for different reasons. 1.1409 + assert(total_invocations() >= _maximum_compaction_gc_num, "sanity"); 1.1410 + const size_t gcs_since_max = total_invocations() - _maximum_compaction_gc_num; 1.1411 + const bool interval_ended = gcs_since_max > HeapMaximumCompactionInterval || 1.1412 + total_invocations() == HeapFirstMaximumCompactionCount; 1.1413 + if (maximum_compaction || full_cp == top_cp || interval_ended) { 1.1414 + _maximum_compaction_gc_num = total_invocations(); 1.1415 + return sd.region_to_addr(full_cp); 1.1416 + } 1.1417 + 1.1418 + const size_t space_live = pointer_delta(new_top, bottom); 1.1419 + const size_t space_used = space->used_in_words(); 1.1420 + const size_t space_capacity = space->capacity_in_words(); 1.1421 + 1.1422 + const double density = double(space_live) / double(space_capacity); 1.1423 + const size_t min_percent_free = MarkSweepDeadRatio; 1.1424 + const double limiter = dead_wood_limiter(density, min_percent_free); 1.1425 + const size_t dead_wood_max = space_used - space_live; 1.1426 + const size_t dead_wood_limit = MIN2(size_t(space_capacity * limiter), 1.1427 + dead_wood_max); 1.1428 + 1.1429 + if (TraceParallelOldGCDensePrefix) { 1.1430 + tty->print_cr("space_live=" SIZE_FORMAT " " "space_used=" SIZE_FORMAT " " 1.1431 + "space_cap=" SIZE_FORMAT, 1.1432 + space_live, space_used, 1.1433 + space_capacity); 1.1434 + tty->print_cr("dead_wood_limiter(%6.4f, %d)=%6.4f " 1.1435 + "dead_wood_max=" SIZE_FORMAT " dead_wood_limit=" SIZE_FORMAT, 1.1436 + density, min_percent_free, limiter, 1.1437 + dead_wood_max, dead_wood_limit); 1.1438 + } 1.1439 + 1.1440 + // Locate the region with the desired amount of dead space to the left. 1.1441 + const RegionData* const limit_cp = 1.1442 + dead_wood_limit_region(full_cp, top_cp, dead_wood_limit); 1.1443 + 1.1444 + // Scan from the first region with dead space to the limit region and find the 1.1445 + // one with the best (largest) reclaimed ratio. 1.1446 + double best_ratio = 0.0; 1.1447 + const RegionData* best_cp = full_cp; 1.1448 + for (const RegionData* cp = full_cp; cp < limit_cp; ++cp) { 1.1449 + double tmp_ratio = reclaimed_ratio(cp, bottom, top, new_top); 1.1450 + if (tmp_ratio > best_ratio) { 1.1451 + best_cp = cp; 1.1452 + best_ratio = tmp_ratio; 1.1453 + } 1.1454 + } 1.1455 + 1.1456 +#if 0 1.1457 + // Something to consider: if the region with the best ratio is 'close to' the 1.1458 + // first region w/free space, choose the first region with free space 1.1459 + // ("first-free"). The first-free region is usually near the start of the 1.1460 + // heap, which means we are copying most of the heap already, so copy a bit 1.1461 + // more to get complete compaction. 1.1462 + if (pointer_delta(best_cp, full_cp, sizeof(RegionData)) < 4) { 1.1463 + _maximum_compaction_gc_num = total_invocations(); 1.1464 + best_cp = full_cp; 1.1465 + } 1.1466 +#endif // #if 0 1.1467 + 1.1468 + return sd.region_to_addr(best_cp); 1.1469 +} 1.1470 + 1.1471 +#ifndef PRODUCT 1.1472 +void 1.1473 +PSParallelCompact::fill_with_live_objects(SpaceId id, HeapWord* const start, 1.1474 + size_t words) 1.1475 +{ 1.1476 + if (TraceParallelOldGCSummaryPhase) { 1.1477 + tty->print_cr("fill_with_live_objects [" PTR_FORMAT " " PTR_FORMAT ") " 1.1478 + SIZE_FORMAT, start, start + words, words); 1.1479 + } 1.1480 + 1.1481 + ObjectStartArray* const start_array = _space_info[id].start_array(); 1.1482 + CollectedHeap::fill_with_objects(start, words); 1.1483 + for (HeapWord* p = start; p < start + words; p += oop(p)->size()) { 1.1484 + _mark_bitmap.mark_obj(p, words); 1.1485 + _summary_data.add_obj(p, words); 1.1486 + start_array->allocate_block(p); 1.1487 + } 1.1488 +} 1.1489 + 1.1490 +void 1.1491 +PSParallelCompact::summarize_new_objects(SpaceId id, HeapWord* start) 1.1492 +{ 1.1493 + ParallelCompactData& sd = summary_data(); 1.1494 + MutableSpace* space = _space_info[id].space(); 1.1495 + 1.1496 + // Find the source and destination start addresses. 1.1497 + HeapWord* const src_addr = sd.region_align_down(start); 1.1498 + HeapWord* dst_addr; 1.1499 + if (src_addr < start) { 1.1500 + dst_addr = sd.addr_to_region_ptr(src_addr)->destination(); 1.1501 + } else if (src_addr > space->bottom()) { 1.1502 + // The start (the original top() value) is aligned to a region boundary so 1.1503 + // the associated region does not have a destination. Compute the 1.1504 + // destination from the previous region. 1.1505 + RegionData* const cp = sd.addr_to_region_ptr(src_addr) - 1; 1.1506 + dst_addr = cp->destination() + cp->data_size(); 1.1507 + } else { 1.1508 + // Filling the entire space. 1.1509 + dst_addr = space->bottom(); 1.1510 + } 1.1511 + assert(dst_addr != NULL, "sanity"); 1.1512 + 1.1513 + // Update the summary data. 1.1514 + bool result = _summary_data.summarize(_space_info[id].split_info(), 1.1515 + src_addr, space->top(), NULL, 1.1516 + dst_addr, space->end(), 1.1517 + _space_info[id].new_top_addr()); 1.1518 + assert(result, "should not fail: bad filler object size"); 1.1519 +} 1.1520 + 1.1521 +void 1.1522 +PSParallelCompact::provoke_split_fill_survivor(SpaceId id) 1.1523 +{ 1.1524 + if (total_invocations() % (ParallelOldGCSplitInterval * 3) != 0) { 1.1525 + return; 1.1526 + } 1.1527 + 1.1528 + MutableSpace* const space = _space_info[id].space(); 1.1529 + if (space->is_empty()) { 1.1530 + HeapWord* b = space->bottom(); 1.1531 + HeapWord* t = b + space->capacity_in_words() / 2; 1.1532 + space->set_top(t); 1.1533 + if (ZapUnusedHeapArea) { 1.1534 + space->set_top_for_allocations(); 1.1535 + } 1.1536 + 1.1537 + size_t min_size = CollectedHeap::min_fill_size(); 1.1538 + size_t obj_len = min_size; 1.1539 + while (b + obj_len <= t) { 1.1540 + CollectedHeap::fill_with_object(b, obj_len); 1.1541 + mark_bitmap()->mark_obj(b, obj_len); 1.1542 + summary_data().add_obj(b, obj_len); 1.1543 + b += obj_len; 1.1544 + obj_len = (obj_len & (min_size*3)) + min_size; // 8 16 24 32 8 16 24 32 ... 1.1545 + } 1.1546 + if (b < t) { 1.1547 + // The loop didn't completely fill to t (top); adjust top downward. 1.1548 + space->set_top(b); 1.1549 + if (ZapUnusedHeapArea) { 1.1550 + space->set_top_for_allocations(); 1.1551 + } 1.1552 + } 1.1553 + 1.1554 + HeapWord** nta = _space_info[id].new_top_addr(); 1.1555 + bool result = summary_data().summarize(_space_info[id].split_info(), 1.1556 + space->bottom(), space->top(), NULL, 1.1557 + space->bottom(), space->end(), nta); 1.1558 + assert(result, "space must fit into itself"); 1.1559 + } 1.1560 +} 1.1561 + 1.1562 +void 1.1563 +PSParallelCompact::provoke_split(bool & max_compaction) 1.1564 +{ 1.1565 + if (total_invocations() % ParallelOldGCSplitInterval != 0) { 1.1566 + return; 1.1567 + } 1.1568 + 1.1569 + const size_t region_size = ParallelCompactData::RegionSize; 1.1570 + ParallelCompactData& sd = summary_data(); 1.1571 + 1.1572 + MutableSpace* const eden_space = _space_info[eden_space_id].space(); 1.1573 + MutableSpace* const from_space = _space_info[from_space_id].space(); 1.1574 + const size_t eden_live = pointer_delta(eden_space->top(), 1.1575 + _space_info[eden_space_id].new_top()); 1.1576 + const size_t from_live = pointer_delta(from_space->top(), 1.1577 + _space_info[from_space_id].new_top()); 1.1578 + 1.1579 + const size_t min_fill_size = CollectedHeap::min_fill_size(); 1.1580 + const size_t eden_free = pointer_delta(eden_space->end(), eden_space->top()); 1.1581 + const size_t eden_fillable = eden_free >= min_fill_size ? eden_free : 0; 1.1582 + const size_t from_free = pointer_delta(from_space->end(), from_space->top()); 1.1583 + const size_t from_fillable = from_free >= min_fill_size ? from_free : 0; 1.1584 + 1.1585 + // Choose the space to split; need at least 2 regions live (or fillable). 1.1586 + SpaceId id; 1.1587 + MutableSpace* space; 1.1588 + size_t live_words; 1.1589 + size_t fill_words; 1.1590 + if (eden_live + eden_fillable >= region_size * 2) { 1.1591 + id = eden_space_id; 1.1592 + space = eden_space; 1.1593 + live_words = eden_live; 1.1594 + fill_words = eden_fillable; 1.1595 + } else if (from_live + from_fillable >= region_size * 2) { 1.1596 + id = from_space_id; 1.1597 + space = from_space; 1.1598 + live_words = from_live; 1.1599 + fill_words = from_fillable; 1.1600 + } else { 1.1601 + return; // Give up. 1.1602 + } 1.1603 + assert(fill_words == 0 || fill_words >= min_fill_size, "sanity"); 1.1604 + 1.1605 + if (live_words < region_size * 2) { 1.1606 + // Fill from top() to end() w/live objects of mixed sizes. 1.1607 + HeapWord* const fill_start = space->top(); 1.1608 + live_words += fill_words; 1.1609 + 1.1610 + space->set_top(fill_start + fill_words); 1.1611 + if (ZapUnusedHeapArea) { 1.1612 + space->set_top_for_allocations(); 1.1613 + } 1.1614 + 1.1615 + HeapWord* cur_addr = fill_start; 1.1616 + while (fill_words > 0) { 1.1617 + const size_t r = (size_t)os::random() % (region_size / 2) + min_fill_size; 1.1618 + size_t cur_size = MIN2(align_object_size_(r), fill_words); 1.1619 + if (fill_words - cur_size < min_fill_size) { 1.1620 + cur_size = fill_words; // Avoid leaving a fragment too small to fill. 1.1621 + } 1.1622 + 1.1623 + CollectedHeap::fill_with_object(cur_addr, cur_size); 1.1624 + mark_bitmap()->mark_obj(cur_addr, cur_size); 1.1625 + sd.add_obj(cur_addr, cur_size); 1.1626 + 1.1627 + cur_addr += cur_size; 1.1628 + fill_words -= cur_size; 1.1629 + } 1.1630 + 1.1631 + summarize_new_objects(id, fill_start); 1.1632 + } 1.1633 + 1.1634 + max_compaction = false; 1.1635 + 1.1636 + // Manipulate the old gen so that it has room for about half of the live data 1.1637 + // in the target young gen space (live_words / 2). 1.1638 + id = old_space_id; 1.1639 + space = _space_info[id].space(); 1.1640 + const size_t free_at_end = space->free_in_words(); 1.1641 + const size_t free_target = align_object_size(live_words / 2); 1.1642 + const size_t dead = pointer_delta(space->top(), _space_info[id].new_top()); 1.1643 + 1.1644 + if (free_at_end >= free_target + min_fill_size) { 1.1645 + // Fill space above top() and set the dense prefix so everything survives. 1.1646 + HeapWord* const fill_start = space->top(); 1.1647 + const size_t fill_size = free_at_end - free_target; 1.1648 + space->set_top(space->top() + fill_size); 1.1649 + if (ZapUnusedHeapArea) { 1.1650 + space->set_top_for_allocations(); 1.1651 + } 1.1652 + fill_with_live_objects(id, fill_start, fill_size); 1.1653 + summarize_new_objects(id, fill_start); 1.1654 + _space_info[id].set_dense_prefix(sd.region_align_down(space->top())); 1.1655 + } else if (dead + free_at_end > free_target) { 1.1656 + // Find a dense prefix that makes the right amount of space available. 1.1657 + HeapWord* cur = sd.region_align_down(space->top()); 1.1658 + HeapWord* cur_destination = sd.addr_to_region_ptr(cur)->destination(); 1.1659 + size_t dead_to_right = pointer_delta(space->end(), cur_destination); 1.1660 + while (dead_to_right < free_target) { 1.1661 + cur -= region_size; 1.1662 + cur_destination = sd.addr_to_region_ptr(cur)->destination(); 1.1663 + dead_to_right = pointer_delta(space->end(), cur_destination); 1.1664 + } 1.1665 + _space_info[id].set_dense_prefix(cur); 1.1666 + } 1.1667 +} 1.1668 +#endif // #ifndef PRODUCT 1.1669 + 1.1670 +void PSParallelCompact::summarize_spaces_quick() 1.1671 +{ 1.1672 + for (unsigned int i = 0; i < last_space_id; ++i) { 1.1673 + const MutableSpace* space = _space_info[i].space(); 1.1674 + HeapWord** nta = _space_info[i].new_top_addr(); 1.1675 + bool result = _summary_data.summarize(_space_info[i].split_info(), 1.1676 + space->bottom(), space->top(), NULL, 1.1677 + space->bottom(), space->end(), nta); 1.1678 + assert(result, "space must fit into itself"); 1.1679 + _space_info[i].set_dense_prefix(space->bottom()); 1.1680 + } 1.1681 + 1.1682 +#ifndef PRODUCT 1.1683 + if (ParallelOldGCSplitALot) { 1.1684 + provoke_split_fill_survivor(to_space_id); 1.1685 + } 1.1686 +#endif // #ifndef PRODUCT 1.1687 +} 1.1688 + 1.1689 +void PSParallelCompact::fill_dense_prefix_end(SpaceId id) 1.1690 +{ 1.1691 + HeapWord* const dense_prefix_end = dense_prefix(id); 1.1692 + const RegionData* region = _summary_data.addr_to_region_ptr(dense_prefix_end); 1.1693 + const idx_t dense_prefix_bit = _mark_bitmap.addr_to_bit(dense_prefix_end); 1.1694 + if (dead_space_crosses_boundary(region, dense_prefix_bit)) { 1.1695 + // Only enough dead space is filled so that any remaining dead space to the 1.1696 + // left is larger than the minimum filler object. (The remainder is filled 1.1697 + // during the copy/update phase.) 1.1698 + // 1.1699 + // The size of the dead space to the right of the boundary is not a 1.1700 + // concern, since compaction will be able to use whatever space is 1.1701 + // available. 1.1702 + // 1.1703 + // Here '||' is the boundary, 'x' represents a don't care bit and a box 1.1704 + // surrounds the space to be filled with an object. 1.1705 + // 1.1706 + // In the 32-bit VM, each bit represents two 32-bit words: 1.1707 + // +---+ 1.1708 + // a) beg_bits: ... x x x | 0 | || 0 x x ... 1.1709 + // end_bits: ... x x x | 0 | || 0 x x ... 1.1710 + // +---+ 1.1711 + // 1.1712 + // In the 64-bit VM, each bit represents one 64-bit word: 1.1713 + // +------------+ 1.1714 + // b) beg_bits: ... x x x | 0 || 0 | x x ... 1.1715 + // end_bits: ... x x 1 | 0 || 0 | x x ... 1.1716 + // +------------+ 1.1717 + // +-------+ 1.1718 + // c) beg_bits: ... x x | 0 0 | || 0 x x ... 1.1719 + // end_bits: ... x 1 | 0 0 | || 0 x x ... 1.1720 + // +-------+ 1.1721 + // +-----------+ 1.1722 + // d) beg_bits: ... x | 0 0 0 | || 0 x x ... 1.1723 + // end_bits: ... 1 | 0 0 0 | || 0 x x ... 1.1724 + // +-----------+ 1.1725 + // +-------+ 1.1726 + // e) beg_bits: ... 0 0 | 0 0 | || 0 x x ... 1.1727 + // end_bits: ... 0 0 | 0 0 | || 0 x x ... 1.1728 + // +-------+ 1.1729 + 1.1730 + // Initially assume case a, c or e will apply. 1.1731 + size_t obj_len = CollectedHeap::min_fill_size(); 1.1732 + HeapWord* obj_beg = dense_prefix_end - obj_len; 1.1733 + 1.1734 +#ifdef _LP64 1.1735 + if (MinObjAlignment > 1) { // object alignment > heap word size 1.1736 + // Cases a, c or e. 1.1737 + } else if (_mark_bitmap.is_obj_end(dense_prefix_bit - 2)) { 1.1738 + // Case b above. 1.1739 + obj_beg = dense_prefix_end - 1; 1.1740 + } else if (!_mark_bitmap.is_obj_end(dense_prefix_bit - 3) && 1.1741 + _mark_bitmap.is_obj_end(dense_prefix_bit - 4)) { 1.1742 + // Case d above. 1.1743 + obj_beg = dense_prefix_end - 3; 1.1744 + obj_len = 3; 1.1745 + } 1.1746 +#endif // #ifdef _LP64 1.1747 + 1.1748 + CollectedHeap::fill_with_object(obj_beg, obj_len); 1.1749 + _mark_bitmap.mark_obj(obj_beg, obj_len); 1.1750 + _summary_data.add_obj(obj_beg, obj_len); 1.1751 + assert(start_array(id) != NULL, "sanity"); 1.1752 + start_array(id)->allocate_block(obj_beg); 1.1753 + } 1.1754 +} 1.1755 + 1.1756 +void 1.1757 +PSParallelCompact::clear_source_region(HeapWord* beg_addr, HeapWord* end_addr) 1.1758 +{ 1.1759 + RegionData* const beg_ptr = _summary_data.addr_to_region_ptr(beg_addr); 1.1760 + HeapWord* const end_aligned_up = _summary_data.region_align_up(end_addr); 1.1761 + RegionData* const end_ptr = _summary_data.addr_to_region_ptr(end_aligned_up); 1.1762 + for (RegionData* cur = beg_ptr; cur < end_ptr; ++cur) { 1.1763 + cur->set_source_region(0); 1.1764 + } 1.1765 +} 1.1766 + 1.1767 +void 1.1768 +PSParallelCompact::summarize_space(SpaceId id, bool maximum_compaction) 1.1769 +{ 1.1770 + assert(id < last_space_id, "id out of range"); 1.1771 + assert(_space_info[id].dense_prefix() == _space_info[id].space()->bottom() || 1.1772 + ParallelOldGCSplitALot && id == old_space_id, 1.1773 + "should have been reset in summarize_spaces_quick()"); 1.1774 + 1.1775 + const MutableSpace* space = _space_info[id].space(); 1.1776 + if (_space_info[id].new_top() != space->bottom()) { 1.1777 + HeapWord* dense_prefix_end = compute_dense_prefix(id, maximum_compaction); 1.1778 + _space_info[id].set_dense_prefix(dense_prefix_end); 1.1779 + 1.1780 +#ifndef PRODUCT 1.1781 + if (TraceParallelOldGCDensePrefix) { 1.1782 + print_dense_prefix_stats("ratio", id, maximum_compaction, 1.1783 + dense_prefix_end); 1.1784 + HeapWord* addr = compute_dense_prefix_via_density(id, maximum_compaction); 1.1785 + print_dense_prefix_stats("density", id, maximum_compaction, addr); 1.1786 + } 1.1787 +#endif // #ifndef PRODUCT 1.1788 + 1.1789 + // Recompute the summary data, taking into account the dense prefix. If 1.1790 + // every last byte will be reclaimed, then the existing summary data which 1.1791 + // compacts everything can be left in place. 1.1792 + if (!maximum_compaction && dense_prefix_end != space->bottom()) { 1.1793 + // If dead space crosses the dense prefix boundary, it is (at least 1.1794 + // partially) filled with a dummy object, marked live and added to the 1.1795 + // summary data. This simplifies the copy/update phase and must be done 1.1796 + // before the final locations of objects are determined, to prevent 1.1797 + // leaving a fragment of dead space that is too small to fill. 1.1798 + fill_dense_prefix_end(id); 1.1799 + 1.1800 + // Compute the destination of each Region, and thus each object. 1.1801 + _summary_data.summarize_dense_prefix(space->bottom(), dense_prefix_end); 1.1802 + _summary_data.summarize(_space_info[id].split_info(), 1.1803 + dense_prefix_end, space->top(), NULL, 1.1804 + dense_prefix_end, space->end(), 1.1805 + _space_info[id].new_top_addr()); 1.1806 + } 1.1807 + } 1.1808 + 1.1809 + if (TraceParallelOldGCSummaryPhase) { 1.1810 + const size_t region_size = ParallelCompactData::RegionSize; 1.1811 + HeapWord* const dense_prefix_end = _space_info[id].dense_prefix(); 1.1812 + const size_t dp_region = _summary_data.addr_to_region_idx(dense_prefix_end); 1.1813 + const size_t dp_words = pointer_delta(dense_prefix_end, space->bottom()); 1.1814 + HeapWord* const new_top = _space_info[id].new_top(); 1.1815 + const HeapWord* nt_aligned_up = _summary_data.region_align_up(new_top); 1.1816 + const size_t cr_words = pointer_delta(nt_aligned_up, dense_prefix_end); 1.1817 + tty->print_cr("id=%d cap=" SIZE_FORMAT " dp=" PTR_FORMAT " " 1.1818 + "dp_region=" SIZE_FORMAT " " "dp_count=" SIZE_FORMAT " " 1.1819 + "cr_count=" SIZE_FORMAT " " "nt=" PTR_FORMAT, 1.1820 + id, space->capacity_in_words(), dense_prefix_end, 1.1821 + dp_region, dp_words / region_size, 1.1822 + cr_words / region_size, new_top); 1.1823 + } 1.1824 +} 1.1825 + 1.1826 +#ifndef PRODUCT 1.1827 +void PSParallelCompact::summary_phase_msg(SpaceId dst_space_id, 1.1828 + HeapWord* dst_beg, HeapWord* dst_end, 1.1829 + SpaceId src_space_id, 1.1830 + HeapWord* src_beg, HeapWord* src_end) 1.1831 +{ 1.1832 + if (TraceParallelOldGCSummaryPhase) { 1.1833 + tty->print_cr("summarizing %d [%s] into %d [%s]: " 1.1834 + "src=" PTR_FORMAT "-" PTR_FORMAT " " 1.1835 + SIZE_FORMAT "-" SIZE_FORMAT " " 1.1836 + "dst=" PTR_FORMAT "-" PTR_FORMAT " " 1.1837 + SIZE_FORMAT "-" SIZE_FORMAT, 1.1838 + src_space_id, space_names[src_space_id], 1.1839 + dst_space_id, space_names[dst_space_id], 1.1840 + src_beg, src_end, 1.1841 + _summary_data.addr_to_region_idx(src_beg), 1.1842 + _summary_data.addr_to_region_idx(src_end), 1.1843 + dst_beg, dst_end, 1.1844 + _summary_data.addr_to_region_idx(dst_beg), 1.1845 + _summary_data.addr_to_region_idx(dst_end)); 1.1846 + } 1.1847 +} 1.1848 +#endif // #ifndef PRODUCT 1.1849 + 1.1850 +void PSParallelCompact::summary_phase(ParCompactionManager* cm, 1.1851 + bool maximum_compaction) 1.1852 +{ 1.1853 + GCTraceTime tm("summary phase", print_phases(), true, &_gc_timer); 1.1854 + // trace("2"); 1.1855 + 1.1856 +#ifdef ASSERT 1.1857 + if (TraceParallelOldGCMarkingPhase) { 1.1858 + tty->print_cr("add_obj_count=" SIZE_FORMAT " " 1.1859 + "add_obj_bytes=" SIZE_FORMAT, 1.1860 + add_obj_count, add_obj_size * HeapWordSize); 1.1861 + tty->print_cr("mark_bitmap_count=" SIZE_FORMAT " " 1.1862 + "mark_bitmap_bytes=" SIZE_FORMAT, 1.1863 + mark_bitmap_count, mark_bitmap_size * HeapWordSize); 1.1864 + } 1.1865 +#endif // #ifdef ASSERT 1.1866 + 1.1867 + // Quick summarization of each space into itself, to see how much is live. 1.1868 + summarize_spaces_quick(); 1.1869 + 1.1870 + if (TraceParallelOldGCSummaryPhase) { 1.1871 + tty->print_cr("summary_phase: after summarizing each space to self"); 1.1872 + Universe::print(); 1.1873 + NOT_PRODUCT(print_region_ranges()); 1.1874 + if (Verbose) { 1.1875 + NOT_PRODUCT(print_initial_summary_data(_summary_data, _space_info)); 1.1876 + } 1.1877 + } 1.1878 + 1.1879 + // The amount of live data that will end up in old space (assuming it fits). 1.1880 + size_t old_space_total_live = 0; 1.1881 + for (unsigned int id = old_space_id; id < last_space_id; ++id) { 1.1882 + old_space_total_live += pointer_delta(_space_info[id].new_top(), 1.1883 + _space_info[id].space()->bottom()); 1.1884 + } 1.1885 + 1.1886 + MutableSpace* const old_space = _space_info[old_space_id].space(); 1.1887 + const size_t old_capacity = old_space->capacity_in_words(); 1.1888 + if (old_space_total_live > old_capacity) { 1.1889 + // XXX - should also try to expand 1.1890 + maximum_compaction = true; 1.1891 + } 1.1892 +#ifndef PRODUCT 1.1893 + if (ParallelOldGCSplitALot && old_space_total_live < old_capacity) { 1.1894 + provoke_split(maximum_compaction); 1.1895 + } 1.1896 +#endif // #ifndef PRODUCT 1.1897 + 1.1898 + // Old generations. 1.1899 + summarize_space(old_space_id, maximum_compaction); 1.1900 + 1.1901 + // Summarize the remaining spaces in the young gen. The initial target space 1.1902 + // is the old gen. If a space does not fit entirely into the target, then the 1.1903 + // remainder is compacted into the space itself and that space becomes the new 1.1904 + // target. 1.1905 + SpaceId dst_space_id = old_space_id; 1.1906 + HeapWord* dst_space_end = old_space->end(); 1.1907 + HeapWord** new_top_addr = _space_info[dst_space_id].new_top_addr(); 1.1908 + for (unsigned int id = eden_space_id; id < last_space_id; ++id) { 1.1909 + const MutableSpace* space = _space_info[id].space(); 1.1910 + const size_t live = pointer_delta(_space_info[id].new_top(), 1.1911 + space->bottom()); 1.1912 + const size_t available = pointer_delta(dst_space_end, *new_top_addr); 1.1913 + 1.1914 + NOT_PRODUCT(summary_phase_msg(dst_space_id, *new_top_addr, dst_space_end, 1.1915 + SpaceId(id), space->bottom(), space->top());) 1.1916 + if (live > 0 && live <= available) { 1.1917 + // All the live data will fit. 1.1918 + bool done = _summary_data.summarize(_space_info[id].split_info(), 1.1919 + space->bottom(), space->top(), 1.1920 + NULL, 1.1921 + *new_top_addr, dst_space_end, 1.1922 + new_top_addr); 1.1923 + assert(done, "space must fit into old gen"); 1.1924 + 1.1925 + // Reset the new_top value for the space. 1.1926 + _space_info[id].set_new_top(space->bottom()); 1.1927 + } else if (live > 0) { 1.1928 + // Attempt to fit part of the source space into the target space. 1.1929 + HeapWord* next_src_addr = NULL; 1.1930 + bool done = _summary_data.summarize(_space_info[id].split_info(), 1.1931 + space->bottom(), space->top(), 1.1932 + &next_src_addr, 1.1933 + *new_top_addr, dst_space_end, 1.1934 + new_top_addr); 1.1935 + assert(!done, "space should not fit into old gen"); 1.1936 + assert(next_src_addr != NULL, "sanity"); 1.1937 + 1.1938 + // The source space becomes the new target, so the remainder is compacted 1.1939 + // within the space itself. 1.1940 + dst_space_id = SpaceId(id); 1.1941 + dst_space_end = space->end(); 1.1942 + new_top_addr = _space_info[id].new_top_addr(); 1.1943 + NOT_PRODUCT(summary_phase_msg(dst_space_id, 1.1944 + space->bottom(), dst_space_end, 1.1945 + SpaceId(id), next_src_addr, space->top());) 1.1946 + done = _summary_data.summarize(_space_info[id].split_info(), 1.1947 + next_src_addr, space->top(), 1.1948 + NULL, 1.1949 + space->bottom(), dst_space_end, 1.1950 + new_top_addr); 1.1951 + assert(done, "space must fit when compacted into itself"); 1.1952 + assert(*new_top_addr <= space->top(), "usage should not grow"); 1.1953 + } 1.1954 + } 1.1955 + 1.1956 + if (TraceParallelOldGCSummaryPhase) { 1.1957 + tty->print_cr("summary_phase: after final summarization"); 1.1958 + Universe::print(); 1.1959 + NOT_PRODUCT(print_region_ranges()); 1.1960 + if (Verbose) { 1.1961 + NOT_PRODUCT(print_generic_summary_data(_summary_data, _space_info)); 1.1962 + } 1.1963 + } 1.1964 +} 1.1965 + 1.1966 +// This method should contain all heap-specific policy for invoking a full 1.1967 +// collection. invoke_no_policy() will only attempt to compact the heap; it 1.1968 +// will do nothing further. If we need to bail out for policy reasons, scavenge 1.1969 +// before full gc, or any other specialized behavior, it needs to be added here. 1.1970 +// 1.1971 +// Note that this method should only be called from the vm_thread while at a 1.1972 +// safepoint. 1.1973 +// 1.1974 +// Note that the all_soft_refs_clear flag in the collector policy 1.1975 +// may be true because this method can be called without intervening 1.1976 +// activity. For example when the heap space is tight and full measure 1.1977 +// are being taken to free space. 1.1978 +void PSParallelCompact::invoke(bool maximum_heap_compaction) { 1.1979 + assert(SafepointSynchronize::is_at_safepoint(), "should be at safepoint"); 1.1980 + assert(Thread::current() == (Thread*)VMThread::vm_thread(), 1.1981 + "should be in vm thread"); 1.1982 + 1.1983 + ParallelScavengeHeap* heap = gc_heap(); 1.1984 + GCCause::Cause gc_cause = heap->gc_cause(); 1.1985 + assert(!heap->is_gc_active(), "not reentrant"); 1.1986 + 1.1987 + PSAdaptiveSizePolicy* policy = heap->size_policy(); 1.1988 + IsGCActiveMark mark; 1.1989 + 1.1990 + if (ScavengeBeforeFullGC) { 1.1991 + PSScavenge::invoke_no_policy(); 1.1992 + } 1.1993 + 1.1994 + const bool clear_all_soft_refs = 1.1995 + heap->collector_policy()->should_clear_all_soft_refs(); 1.1996 + 1.1997 + PSParallelCompact::invoke_no_policy(clear_all_soft_refs || 1.1998 + maximum_heap_compaction); 1.1999 +} 1.2000 + 1.2001 +// This method contains no policy. You should probably 1.2002 +// be calling invoke() instead. 1.2003 +bool PSParallelCompact::invoke_no_policy(bool maximum_heap_compaction) { 1.2004 + assert(SafepointSynchronize::is_at_safepoint(), "must be at a safepoint"); 1.2005 + assert(ref_processor() != NULL, "Sanity"); 1.2006 + 1.2007 + if (GC_locker::check_active_before_gc()) { 1.2008 + return false; 1.2009 + } 1.2010 + 1.2011 + ParallelScavengeHeap* heap = gc_heap(); 1.2012 + 1.2013 + _gc_timer.register_gc_start(); 1.2014 + _gc_tracer.report_gc_start(heap->gc_cause(), _gc_timer.gc_start()); 1.2015 + 1.2016 + TimeStamp marking_start; 1.2017 + TimeStamp compaction_start; 1.2018 + TimeStamp collection_exit; 1.2019 + 1.2020 + GCCause::Cause gc_cause = heap->gc_cause(); 1.2021 + PSYoungGen* young_gen = heap->young_gen(); 1.2022 + PSOldGen* old_gen = heap->old_gen(); 1.2023 + PSAdaptiveSizePolicy* size_policy = heap->size_policy(); 1.2024 + 1.2025 + // The scope of casr should end after code that can change 1.2026 + // CollectorPolicy::_should_clear_all_soft_refs. 1.2027 + ClearedAllSoftRefs casr(maximum_heap_compaction, 1.2028 + heap->collector_policy()); 1.2029 + 1.2030 + if (ZapUnusedHeapArea) { 1.2031 + // Save information needed to minimize mangling 1.2032 + heap->record_gen_tops_before_GC(); 1.2033 + } 1.2034 + 1.2035 + heap->pre_full_gc_dump(&_gc_timer); 1.2036 + 1.2037 + _print_phases = PrintGCDetails && PrintParallelOldGCPhaseTimes; 1.2038 + 1.2039 + // Make sure data structures are sane, make the heap parsable, and do other 1.2040 + // miscellaneous bookkeeping. 1.2041 + PreGCValues pre_gc_values; 1.2042 + pre_compact(&pre_gc_values); 1.2043 + 1.2044 + // Get the compaction manager reserved for the VM thread. 1.2045 + ParCompactionManager* const vmthread_cm = 1.2046 + ParCompactionManager::manager_array(gc_task_manager()->workers()); 1.2047 + 1.2048 + // Place after pre_compact() where the number of invocations is incremented. 1.2049 + AdaptiveSizePolicyOutput(size_policy, heap->total_collections()); 1.2050 + 1.2051 + { 1.2052 + ResourceMark rm; 1.2053 + HandleMark hm; 1.2054 + 1.2055 + // Set the number of GC threads to be used in this collection 1.2056 + gc_task_manager()->set_active_gang(); 1.2057 + gc_task_manager()->task_idle_workers(); 1.2058 + heap->set_par_threads(gc_task_manager()->active_workers()); 1.2059 + 1.2060 + gclog_or_tty->date_stamp(PrintGC && PrintGCDateStamps); 1.2061 + TraceCPUTime tcpu(PrintGCDetails, true, gclog_or_tty); 1.2062 + GCTraceTime t1(GCCauseString("Full GC", gc_cause), PrintGC, !PrintGCDetails, NULL); 1.2063 + TraceCollectorStats tcs(counters()); 1.2064 + TraceMemoryManagerStats tms(true /* Full GC */,gc_cause); 1.2065 + 1.2066 + if (TraceGen1Time) accumulated_time()->start(); 1.2067 + 1.2068 + // Let the size policy know we're starting 1.2069 + size_policy->major_collection_begin(); 1.2070 + 1.2071 + CodeCache::gc_prologue(); 1.2072 + Threads::gc_prologue(); 1.2073 + 1.2074 + COMPILER2_PRESENT(DerivedPointerTable::clear()); 1.2075 + 1.2076 + ref_processor()->enable_discovery(true /*verify_disabled*/, true /*verify_no_refs*/); 1.2077 + ref_processor()->setup_policy(maximum_heap_compaction); 1.2078 + 1.2079 + bool marked_for_unloading = false; 1.2080 + 1.2081 + marking_start.update(); 1.2082 + marking_phase(vmthread_cm, maximum_heap_compaction, &_gc_tracer); 1.2083 + 1.2084 + bool max_on_system_gc = UseMaximumCompactionOnSystemGC 1.2085 + && gc_cause == GCCause::_java_lang_system_gc; 1.2086 + summary_phase(vmthread_cm, maximum_heap_compaction || max_on_system_gc); 1.2087 + 1.2088 + COMPILER2_PRESENT(assert(DerivedPointerTable::is_active(), "Sanity")); 1.2089 + COMPILER2_PRESENT(DerivedPointerTable::set_active(false)); 1.2090 + 1.2091 + // adjust_roots() updates Universe::_intArrayKlassObj which is 1.2092 + // needed by the compaction for filling holes in the dense prefix. 1.2093 + adjust_roots(); 1.2094 + 1.2095 + compaction_start.update(); 1.2096 + compact(); 1.2097 + 1.2098 + // Reset the mark bitmap, summary data, and do other bookkeeping. Must be 1.2099 + // done before resizing. 1.2100 + post_compact(); 1.2101 + 1.2102 + // Let the size policy know we're done 1.2103 + size_policy->major_collection_end(old_gen->used_in_bytes(), gc_cause); 1.2104 + 1.2105 + if (UseAdaptiveSizePolicy) { 1.2106 + if (PrintAdaptiveSizePolicy) { 1.2107 + gclog_or_tty->print("AdaptiveSizeStart: "); 1.2108 + gclog_or_tty->stamp(); 1.2109 + gclog_or_tty->print_cr(" collection: %d ", 1.2110 + heap->total_collections()); 1.2111 + if (Verbose) { 1.2112 + gclog_or_tty->print("old_gen_capacity: %d young_gen_capacity: %d", 1.2113 + old_gen->capacity_in_bytes(), young_gen->capacity_in_bytes()); 1.2114 + } 1.2115 + } 1.2116 + 1.2117 + // Don't check if the size_policy is ready here. Let 1.2118 + // the size_policy check that internally. 1.2119 + if (UseAdaptiveGenerationSizePolicyAtMajorCollection && 1.2120 + ((gc_cause != GCCause::_java_lang_system_gc) || 1.2121 + UseAdaptiveSizePolicyWithSystemGC)) { 1.2122 + // Calculate optimal free space amounts 1.2123 + assert(young_gen->max_size() > 1.2124 + young_gen->from_space()->capacity_in_bytes() + 1.2125 + young_gen->to_space()->capacity_in_bytes(), 1.2126 + "Sizes of space in young gen are out-of-bounds"); 1.2127 + 1.2128 + size_t young_live = young_gen->used_in_bytes(); 1.2129 + size_t eden_live = young_gen->eden_space()->used_in_bytes(); 1.2130 + size_t old_live = old_gen->used_in_bytes(); 1.2131 + size_t cur_eden = young_gen->eden_space()->capacity_in_bytes(); 1.2132 + size_t max_old_gen_size = old_gen->max_gen_size(); 1.2133 + size_t max_eden_size = young_gen->max_size() - 1.2134 + young_gen->from_space()->capacity_in_bytes() - 1.2135 + young_gen->to_space()->capacity_in_bytes(); 1.2136 + 1.2137 + // Used for diagnostics 1.2138 + size_policy->clear_generation_free_space_flags(); 1.2139 + 1.2140 + size_policy->compute_generations_free_space(young_live, 1.2141 + eden_live, 1.2142 + old_live, 1.2143 + cur_eden, 1.2144 + max_old_gen_size, 1.2145 + max_eden_size, 1.2146 + true /* full gc*/); 1.2147 + 1.2148 + size_policy->check_gc_overhead_limit(young_live, 1.2149 + eden_live, 1.2150 + max_old_gen_size, 1.2151 + max_eden_size, 1.2152 + true /* full gc*/, 1.2153 + gc_cause, 1.2154 + heap->collector_policy()); 1.2155 + 1.2156 + size_policy->decay_supplemental_growth(true /* full gc*/); 1.2157 + 1.2158 + heap->resize_old_gen( 1.2159 + size_policy->calculated_old_free_size_in_bytes()); 1.2160 + 1.2161 + // Don't resize the young generation at an major collection. A 1.2162 + // desired young generation size may have been calculated but 1.2163 + // resizing the young generation complicates the code because the 1.2164 + // resizing of the old generation may have moved the boundary 1.2165 + // between the young generation and the old generation. Let the 1.2166 + // young generation resizing happen at the minor collections. 1.2167 + } 1.2168 + if (PrintAdaptiveSizePolicy) { 1.2169 + gclog_or_tty->print_cr("AdaptiveSizeStop: collection: %d ", 1.2170 + heap->total_collections()); 1.2171 + } 1.2172 + } 1.2173 + 1.2174 + if (UsePerfData) { 1.2175 + PSGCAdaptivePolicyCounters* const counters = heap->gc_policy_counters(); 1.2176 + counters->update_counters(); 1.2177 + counters->update_old_capacity(old_gen->capacity_in_bytes()); 1.2178 + counters->update_young_capacity(young_gen->capacity_in_bytes()); 1.2179 + } 1.2180 + 1.2181 + heap->resize_all_tlabs(); 1.2182 + 1.2183 + // Resize the metaspace capactiy after a collection 1.2184 + MetaspaceGC::compute_new_size(); 1.2185 + 1.2186 + if (TraceGen1Time) accumulated_time()->stop(); 1.2187 + 1.2188 + if (PrintGC) { 1.2189 + if (PrintGCDetails) { 1.2190 + // No GC timestamp here. This is after GC so it would be confusing. 1.2191 + young_gen->print_used_change(pre_gc_values.young_gen_used()); 1.2192 + old_gen->print_used_change(pre_gc_values.old_gen_used()); 1.2193 + heap->print_heap_change(pre_gc_values.heap_used()); 1.2194 + MetaspaceAux::print_metaspace_change(pre_gc_values.metadata_used()); 1.2195 + } else { 1.2196 + heap->print_heap_change(pre_gc_values.heap_used()); 1.2197 + } 1.2198 + } 1.2199 + 1.2200 + // Track memory usage and detect low memory 1.2201 + MemoryService::track_memory_usage(); 1.2202 + heap->update_counters(); 1.2203 + gc_task_manager()->release_idle_workers(); 1.2204 + } 1.2205 + 1.2206 +#ifdef ASSERT 1.2207 + for (size_t i = 0; i < ParallelGCThreads + 1; ++i) { 1.2208 + ParCompactionManager* const cm = 1.2209 + ParCompactionManager::manager_array(int(i)); 1.2210 + assert(cm->marking_stack()->is_empty(), "should be empty"); 1.2211 + assert(ParCompactionManager::region_list(int(i))->is_empty(), "should be empty"); 1.2212 + } 1.2213 +#endif // ASSERT 1.2214 + 1.2215 + if (VerifyAfterGC && heap->total_collections() >= VerifyGCStartAt) { 1.2216 + HandleMark hm; // Discard invalid handles created during verification 1.2217 + Universe::verify(" VerifyAfterGC:"); 1.2218 + } 1.2219 + 1.2220 + // Re-verify object start arrays 1.2221 + if (VerifyObjectStartArray && 1.2222 + VerifyAfterGC) { 1.2223 + old_gen->verify_object_start_array(); 1.2224 + } 1.2225 + 1.2226 + if (ZapUnusedHeapArea) { 1.2227 + old_gen->object_space()->check_mangled_unused_area_complete(); 1.2228 + } 1.2229 + 1.2230 + NOT_PRODUCT(ref_processor()->verify_no_references_recorded()); 1.2231 + 1.2232 + collection_exit.update(); 1.2233 + 1.2234 + heap->print_heap_after_gc(); 1.2235 + heap->trace_heap_after_gc(&_gc_tracer); 1.2236 + 1.2237 + if (PrintGCTaskTimeStamps) { 1.2238 + gclog_or_tty->print_cr("VM-Thread " INT64_FORMAT " " INT64_FORMAT " " 1.2239 + INT64_FORMAT, 1.2240 + marking_start.ticks(), compaction_start.ticks(), 1.2241 + collection_exit.ticks()); 1.2242 + gc_task_manager()->print_task_time_stamps(); 1.2243 + } 1.2244 + 1.2245 + heap->post_full_gc_dump(&_gc_timer); 1.2246 + 1.2247 +#ifdef TRACESPINNING 1.2248 + ParallelTaskTerminator::print_termination_counts(); 1.2249 +#endif 1.2250 + 1.2251 + _gc_timer.register_gc_end(); 1.2252 + 1.2253 + _gc_tracer.report_dense_prefix(dense_prefix(old_space_id)); 1.2254 + _gc_tracer.report_gc_end(_gc_timer.gc_end(), _gc_timer.time_partitions()); 1.2255 + 1.2256 + return true; 1.2257 +} 1.2258 + 1.2259 +bool PSParallelCompact::absorb_live_data_from_eden(PSAdaptiveSizePolicy* size_policy, 1.2260 + PSYoungGen* young_gen, 1.2261 + PSOldGen* old_gen) { 1.2262 + MutableSpace* const eden_space = young_gen->eden_space(); 1.2263 + assert(!eden_space->is_empty(), "eden must be non-empty"); 1.2264 + assert(young_gen->virtual_space()->alignment() == 1.2265 + old_gen->virtual_space()->alignment(), "alignments do not match"); 1.2266 + 1.2267 + if (!(UseAdaptiveSizePolicy && UseAdaptiveGCBoundary)) { 1.2268 + return false; 1.2269 + } 1.2270 + 1.2271 + // Both generations must be completely committed. 1.2272 + if (young_gen->virtual_space()->uncommitted_size() != 0) { 1.2273 + return false; 1.2274 + } 1.2275 + if (old_gen->virtual_space()->uncommitted_size() != 0) { 1.2276 + return false; 1.2277 + } 1.2278 + 1.2279 + // Figure out how much to take from eden. Include the average amount promoted 1.2280 + // in the total; otherwise the next young gen GC will simply bail out to a 1.2281 + // full GC. 1.2282 + const size_t alignment = old_gen->virtual_space()->alignment(); 1.2283 + const size_t eden_used = eden_space->used_in_bytes(); 1.2284 + const size_t promoted = (size_t)size_policy->avg_promoted()->padded_average(); 1.2285 + const size_t absorb_size = align_size_up(eden_used + promoted, alignment); 1.2286 + const size_t eden_capacity = eden_space->capacity_in_bytes(); 1.2287 + 1.2288 + if (absorb_size >= eden_capacity) { 1.2289 + return false; // Must leave some space in eden. 1.2290 + } 1.2291 + 1.2292 + const size_t new_young_size = young_gen->capacity_in_bytes() - absorb_size; 1.2293 + if (new_young_size < young_gen->min_gen_size()) { 1.2294 + return false; // Respect young gen minimum size. 1.2295 + } 1.2296 + 1.2297 + if (TraceAdaptiveGCBoundary && Verbose) { 1.2298 + gclog_or_tty->print(" absorbing " SIZE_FORMAT "K: " 1.2299 + "eden " SIZE_FORMAT "K->" SIZE_FORMAT "K " 1.2300 + "from " SIZE_FORMAT "K, to " SIZE_FORMAT "K " 1.2301 + "young_gen " SIZE_FORMAT "K->" SIZE_FORMAT "K ", 1.2302 + absorb_size / K, 1.2303 + eden_capacity / K, (eden_capacity - absorb_size) / K, 1.2304 + young_gen->from_space()->used_in_bytes() / K, 1.2305 + young_gen->to_space()->used_in_bytes() / K, 1.2306 + young_gen->capacity_in_bytes() / K, new_young_size / K); 1.2307 + } 1.2308 + 1.2309 + // Fill the unused part of the old gen. 1.2310 + MutableSpace* const old_space = old_gen->object_space(); 1.2311 + HeapWord* const unused_start = old_space->top(); 1.2312 + size_t const unused_words = pointer_delta(old_space->end(), unused_start); 1.2313 + 1.2314 + if (unused_words > 0) { 1.2315 + if (unused_words < CollectedHeap::min_fill_size()) { 1.2316 + return false; // If the old gen cannot be filled, must give up. 1.2317 + } 1.2318 + CollectedHeap::fill_with_objects(unused_start, unused_words); 1.2319 + } 1.2320 + 1.2321 + // Take the live data from eden and set both top and end in the old gen to 1.2322 + // eden top. (Need to set end because reset_after_change() mangles the region 1.2323 + // from end to virtual_space->high() in debug builds). 1.2324 + HeapWord* const new_top = eden_space->top(); 1.2325 + old_gen->virtual_space()->expand_into(young_gen->virtual_space(), 1.2326 + absorb_size); 1.2327 + young_gen->reset_after_change(); 1.2328 + old_space->set_top(new_top); 1.2329 + old_space->set_end(new_top); 1.2330 + old_gen->reset_after_change(); 1.2331 + 1.2332 + // Update the object start array for the filler object and the data from eden. 1.2333 + ObjectStartArray* const start_array = old_gen->start_array(); 1.2334 + for (HeapWord* p = unused_start; p < new_top; p += oop(p)->size()) { 1.2335 + start_array->allocate_block(p); 1.2336 + } 1.2337 + 1.2338 + // Could update the promoted average here, but it is not typically updated at 1.2339 + // full GCs and the value to use is unclear. Something like 1.2340 + // 1.2341 + // cur_promoted_avg + absorb_size / number_of_scavenges_since_last_full_gc. 1.2342 + 1.2343 + size_policy->set_bytes_absorbed_from_eden(absorb_size); 1.2344 + return true; 1.2345 +} 1.2346 + 1.2347 +GCTaskManager* const PSParallelCompact::gc_task_manager() { 1.2348 + assert(ParallelScavengeHeap::gc_task_manager() != NULL, 1.2349 + "shouldn't return NULL"); 1.2350 + return ParallelScavengeHeap::gc_task_manager(); 1.2351 +} 1.2352 + 1.2353 +void PSParallelCompact::marking_phase(ParCompactionManager* cm, 1.2354 + bool maximum_heap_compaction, 1.2355 + ParallelOldTracer *gc_tracer) { 1.2356 + // Recursively traverse all live objects and mark them 1.2357 + GCTraceTime tm("marking phase", print_phases(), true, &_gc_timer); 1.2358 + 1.2359 + ParallelScavengeHeap* heap = gc_heap(); 1.2360 + uint parallel_gc_threads = heap->gc_task_manager()->workers(); 1.2361 + uint active_gc_threads = heap->gc_task_manager()->active_workers(); 1.2362 + TaskQueueSetSuper* qset = ParCompactionManager::region_array(); 1.2363 + ParallelTaskTerminator terminator(active_gc_threads, qset); 1.2364 + 1.2365 + PSParallelCompact::MarkAndPushClosure mark_and_push_closure(cm); 1.2366 + PSParallelCompact::FollowStackClosure follow_stack_closure(cm); 1.2367 + 1.2368 + // Need new claim bits before marking starts. 1.2369 + ClassLoaderDataGraph::clear_claimed_marks(); 1.2370 + 1.2371 + { 1.2372 + GCTraceTime tm_m("par mark", print_phases(), true, &_gc_timer); 1.2373 + 1.2374 + ParallelScavengeHeap::ParStrongRootsScope psrs; 1.2375 + 1.2376 + GCTaskQueue* q = GCTaskQueue::create(); 1.2377 + 1.2378 + q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::universe)); 1.2379 + q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::jni_handles)); 1.2380 + // We scan the thread roots in parallel 1.2381 + Threads::create_thread_roots_marking_tasks(q); 1.2382 + q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::object_synchronizer)); 1.2383 + q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::flat_profiler)); 1.2384 + q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::management)); 1.2385 + q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::system_dictionary)); 1.2386 + q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::class_loader_data)); 1.2387 + q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::jvmti)); 1.2388 + q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::code_cache)); 1.2389 + 1.2390 + if (active_gc_threads > 1) { 1.2391 + for (uint j = 0; j < active_gc_threads; j++) { 1.2392 + q->enqueue(new StealMarkingTask(&terminator)); 1.2393 + } 1.2394 + } 1.2395 + 1.2396 + gc_task_manager()->execute_and_wait(q); 1.2397 + } 1.2398 + 1.2399 + // Process reference objects found during marking 1.2400 + { 1.2401 + GCTraceTime tm_r("reference processing", print_phases(), true, &_gc_timer); 1.2402 + 1.2403 + ReferenceProcessorStats stats; 1.2404 + if (ref_processor()->processing_is_mt()) { 1.2405 + RefProcTaskExecutor task_executor; 1.2406 + stats = ref_processor()->process_discovered_references( 1.2407 + is_alive_closure(), &mark_and_push_closure, &follow_stack_closure, 1.2408 + &task_executor, &_gc_timer); 1.2409 + } else { 1.2410 + stats = ref_processor()->process_discovered_references( 1.2411 + is_alive_closure(), &mark_and_push_closure, &follow_stack_closure, NULL, 1.2412 + &_gc_timer); 1.2413 + } 1.2414 + 1.2415 + gc_tracer->report_gc_reference_stats(stats); 1.2416 + } 1.2417 + 1.2418 + GCTraceTime tm_c("class unloading", print_phases(), true, &_gc_timer); 1.2419 + 1.2420 + // This is the point where the entire marking should have completed. 1.2421 + assert(cm->marking_stacks_empty(), "Marking should have completed"); 1.2422 + 1.2423 + // Follow system dictionary roots and unload classes. 1.2424 + bool purged_class = SystemDictionary::do_unloading(is_alive_closure()); 1.2425 + 1.2426 + // Unload nmethods. 1.2427 + CodeCache::do_unloading(is_alive_closure(), purged_class); 1.2428 + 1.2429 + // Prune dead klasses from subklass/sibling/implementor lists. 1.2430 + Klass::clean_weak_klass_links(is_alive_closure()); 1.2431 + 1.2432 + // Delete entries for dead interned strings. 1.2433 + StringTable::unlink(is_alive_closure()); 1.2434 + 1.2435 + // Clean up unreferenced symbols in symbol table. 1.2436 + SymbolTable::unlink(); 1.2437 + _gc_tracer.report_object_count_after_gc(is_alive_closure()); 1.2438 +} 1.2439 + 1.2440 +void PSParallelCompact::follow_class_loader(ParCompactionManager* cm, 1.2441 + ClassLoaderData* cld) { 1.2442 + PSParallelCompact::MarkAndPushClosure mark_and_push_closure(cm); 1.2443 + PSParallelCompact::FollowKlassClosure follow_klass_closure(&mark_and_push_closure); 1.2444 + 1.2445 + cld->oops_do(&mark_and_push_closure, &follow_klass_closure, true); 1.2446 +} 1.2447 + 1.2448 +// This should be moved to the shared markSweep code! 1.2449 +class PSAlwaysTrueClosure: public BoolObjectClosure { 1.2450 +public: 1.2451 + bool do_object_b(oop p) { return true; } 1.2452 +}; 1.2453 +static PSAlwaysTrueClosure always_true; 1.2454 + 1.2455 +void PSParallelCompact::adjust_roots() { 1.2456 + // Adjust the pointers to reflect the new locations 1.2457 + GCTraceTime tm("adjust roots", print_phases(), true, &_gc_timer); 1.2458 + 1.2459 + // Need new claim bits when tracing through and adjusting pointers. 1.2460 + ClassLoaderDataGraph::clear_claimed_marks(); 1.2461 + 1.2462 + // General strong roots. 1.2463 + Universe::oops_do(adjust_pointer_closure()); 1.2464 + JNIHandles::oops_do(adjust_pointer_closure()); // Global (strong) JNI handles 1.2465 + CLDToOopClosure adjust_from_cld(adjust_pointer_closure()); 1.2466 + Threads::oops_do(adjust_pointer_closure(), &adjust_from_cld, NULL); 1.2467 + ObjectSynchronizer::oops_do(adjust_pointer_closure()); 1.2468 + FlatProfiler::oops_do(adjust_pointer_closure()); 1.2469 + Management::oops_do(adjust_pointer_closure()); 1.2470 + JvmtiExport::oops_do(adjust_pointer_closure()); 1.2471 + // SO_AllClasses 1.2472 + SystemDictionary::oops_do(adjust_pointer_closure()); 1.2473 + ClassLoaderDataGraph::oops_do(adjust_pointer_closure(), adjust_klass_closure(), true); 1.2474 + 1.2475 + // Now adjust pointers in remaining weak roots. (All of which should 1.2476 + // have been cleared if they pointed to non-surviving objects.) 1.2477 + // Global (weak) JNI handles 1.2478 + JNIHandles::weak_oops_do(&always_true, adjust_pointer_closure()); 1.2479 + 1.2480 + CodeCache::oops_do(adjust_pointer_closure()); 1.2481 + StringTable::oops_do(adjust_pointer_closure()); 1.2482 + ref_processor()->weak_oops_do(adjust_pointer_closure()); 1.2483 + // Roots were visited so references into the young gen in roots 1.2484 + // may have been scanned. Process them also. 1.2485 + // Should the reference processor have a span that excludes 1.2486 + // young gen objects? 1.2487 + PSScavenge::reference_processor()->weak_oops_do(adjust_pointer_closure()); 1.2488 +} 1.2489 + 1.2490 +void PSParallelCompact::enqueue_region_draining_tasks(GCTaskQueue* q, 1.2491 + uint parallel_gc_threads) 1.2492 +{ 1.2493 + GCTraceTime tm("drain task setup", print_phases(), true, &_gc_timer); 1.2494 + 1.2495 + // Find the threads that are active 1.2496 + unsigned int which = 0; 1.2497 + 1.2498 + const uint task_count = MAX2(parallel_gc_threads, 1U); 1.2499 + for (uint j = 0; j < task_count; j++) { 1.2500 + q->enqueue(new DrainStacksCompactionTask(j)); 1.2501 + ParCompactionManager::verify_region_list_empty(j); 1.2502 + // Set the region stacks variables to "no" region stack values 1.2503 + // so that they will be recognized and needing a region stack 1.2504 + // in the stealing tasks if they do not get one by executing 1.2505 + // a draining stack. 1.2506 + ParCompactionManager* cm = ParCompactionManager::manager_array(j); 1.2507 + cm->set_region_stack(NULL); 1.2508 + cm->set_region_stack_index((uint)max_uintx); 1.2509 + } 1.2510 + ParCompactionManager::reset_recycled_stack_index(); 1.2511 + 1.2512 + // Find all regions that are available (can be filled immediately) and 1.2513 + // distribute them to the thread stacks. The iteration is done in reverse 1.2514 + // order (high to low) so the regions will be removed in ascending order. 1.2515 + 1.2516 + const ParallelCompactData& sd = PSParallelCompact::summary_data(); 1.2517 + 1.2518 + size_t fillable_regions = 0; // A count for diagnostic purposes. 1.2519 + // A region index which corresponds to the tasks created above. 1.2520 + // "which" must be 0 <= which < task_count 1.2521 + 1.2522 + which = 0; 1.2523 + // id + 1 is used to test termination so unsigned can 1.2524 + // be used with an old_space_id == 0. 1.2525 + for (unsigned int id = to_space_id; id + 1 > old_space_id; --id) { 1.2526 + SpaceInfo* const space_info = _space_info + id; 1.2527 + MutableSpace* const space = space_info->space(); 1.2528 + HeapWord* const new_top = space_info->new_top(); 1.2529 + 1.2530 + const size_t beg_region = sd.addr_to_region_idx(space_info->dense_prefix()); 1.2531 + const size_t end_region = 1.2532 + sd.addr_to_region_idx(sd.region_align_up(new_top)); 1.2533 + 1.2534 + for (size_t cur = end_region - 1; cur + 1 > beg_region; --cur) { 1.2535 + if (sd.region(cur)->claim_unsafe()) { 1.2536 + ParCompactionManager::region_list_push(which, cur); 1.2537 + 1.2538 + if (TraceParallelOldGCCompactionPhase && Verbose) { 1.2539 + const size_t count_mod_8 = fillable_regions & 7; 1.2540 + if (count_mod_8 == 0) gclog_or_tty->print("fillable: "); 1.2541 + gclog_or_tty->print(" " SIZE_FORMAT_W(7), cur); 1.2542 + if (count_mod_8 == 7) gclog_or_tty->cr(); 1.2543 + } 1.2544 + 1.2545 + NOT_PRODUCT(++fillable_regions;) 1.2546 + 1.2547 + // Assign regions to tasks in round-robin fashion. 1.2548 + if (++which == task_count) { 1.2549 + assert(which <= parallel_gc_threads, 1.2550 + "Inconsistent number of workers"); 1.2551 + which = 0; 1.2552 + } 1.2553 + } 1.2554 + } 1.2555 + } 1.2556 + 1.2557 + if (TraceParallelOldGCCompactionPhase) { 1.2558 + if (Verbose && (fillable_regions & 7) != 0) gclog_or_tty->cr(); 1.2559 + gclog_or_tty->print_cr("%u initially fillable regions", fillable_regions); 1.2560 + } 1.2561 +} 1.2562 + 1.2563 +#define PAR_OLD_DENSE_PREFIX_OVER_PARTITIONING 4 1.2564 + 1.2565 +void PSParallelCompact::enqueue_dense_prefix_tasks(GCTaskQueue* q, 1.2566 + uint parallel_gc_threads) { 1.2567 + GCTraceTime tm("dense prefix task setup", print_phases(), true, &_gc_timer); 1.2568 + 1.2569 + ParallelCompactData& sd = PSParallelCompact::summary_data(); 1.2570 + 1.2571 + // Iterate over all the spaces adding tasks for updating 1.2572 + // regions in the dense prefix. Assume that 1 gc thread 1.2573 + // will work on opening the gaps and the remaining gc threads 1.2574 + // will work on the dense prefix. 1.2575 + unsigned int space_id; 1.2576 + for (space_id = old_space_id; space_id < last_space_id; ++ space_id) { 1.2577 + HeapWord* const dense_prefix_end = _space_info[space_id].dense_prefix(); 1.2578 + const MutableSpace* const space = _space_info[space_id].space(); 1.2579 + 1.2580 + if (dense_prefix_end == space->bottom()) { 1.2581 + // There is no dense prefix for this space. 1.2582 + continue; 1.2583 + } 1.2584 + 1.2585 + // The dense prefix is before this region. 1.2586 + size_t region_index_end_dense_prefix = 1.2587 + sd.addr_to_region_idx(dense_prefix_end); 1.2588 + RegionData* const dense_prefix_cp = 1.2589 + sd.region(region_index_end_dense_prefix); 1.2590 + assert(dense_prefix_end == space->end() || 1.2591 + dense_prefix_cp->available() || 1.2592 + dense_prefix_cp->claimed(), 1.2593 + "The region after the dense prefix should always be ready to fill"); 1.2594 + 1.2595 + size_t region_index_start = sd.addr_to_region_idx(space->bottom()); 1.2596 + 1.2597 + // Is there dense prefix work? 1.2598 + size_t total_dense_prefix_regions = 1.2599 + region_index_end_dense_prefix - region_index_start; 1.2600 + // How many regions of the dense prefix should be given to 1.2601 + // each thread? 1.2602 + if (total_dense_prefix_regions > 0) { 1.2603 + uint tasks_for_dense_prefix = 1; 1.2604 + if (total_dense_prefix_regions <= 1.2605 + (parallel_gc_threads * PAR_OLD_DENSE_PREFIX_OVER_PARTITIONING)) { 1.2606 + // Don't over partition. This assumes that 1.2607 + // PAR_OLD_DENSE_PREFIX_OVER_PARTITIONING is a small integer value 1.2608 + // so there are not many regions to process. 1.2609 + tasks_for_dense_prefix = parallel_gc_threads; 1.2610 + } else { 1.2611 + // Over partition 1.2612 + tasks_for_dense_prefix = parallel_gc_threads * 1.2613 + PAR_OLD_DENSE_PREFIX_OVER_PARTITIONING; 1.2614 + } 1.2615 + size_t regions_per_thread = total_dense_prefix_regions / 1.2616 + tasks_for_dense_prefix; 1.2617 + // Give each thread at least 1 region. 1.2618 + if (regions_per_thread == 0) { 1.2619 + regions_per_thread = 1; 1.2620 + } 1.2621 + 1.2622 + for (uint k = 0; k < tasks_for_dense_prefix; k++) { 1.2623 + if (region_index_start >= region_index_end_dense_prefix) { 1.2624 + break; 1.2625 + } 1.2626 + // region_index_end is not processed 1.2627 + size_t region_index_end = MIN2(region_index_start + regions_per_thread, 1.2628 + region_index_end_dense_prefix); 1.2629 + q->enqueue(new UpdateDensePrefixTask(SpaceId(space_id), 1.2630 + region_index_start, 1.2631 + region_index_end)); 1.2632 + region_index_start = region_index_end; 1.2633 + } 1.2634 + } 1.2635 + // This gets any part of the dense prefix that did not 1.2636 + // fit evenly. 1.2637 + if (region_index_start < region_index_end_dense_prefix) { 1.2638 + q->enqueue(new UpdateDensePrefixTask(SpaceId(space_id), 1.2639 + region_index_start, 1.2640 + region_index_end_dense_prefix)); 1.2641 + } 1.2642 + } 1.2643 +} 1.2644 + 1.2645 +void PSParallelCompact::enqueue_region_stealing_tasks( 1.2646 + GCTaskQueue* q, 1.2647 + ParallelTaskTerminator* terminator_ptr, 1.2648 + uint parallel_gc_threads) { 1.2649 + GCTraceTime tm("steal task setup", print_phases(), true, &_gc_timer); 1.2650 + 1.2651 + // Once a thread has drained it's stack, it should try to steal regions from 1.2652 + // other threads. 1.2653 + if (parallel_gc_threads > 1) { 1.2654 + for (uint j = 0; j < parallel_gc_threads; j++) { 1.2655 + q->enqueue(new StealRegionCompactionTask(terminator_ptr)); 1.2656 + } 1.2657 + } 1.2658 +} 1.2659 + 1.2660 +#ifdef ASSERT 1.2661 +// Write a histogram of the number of times the block table was filled for a 1.2662 +// region. 1.2663 +void PSParallelCompact::write_block_fill_histogram(outputStream* const out) 1.2664 +{ 1.2665 + if (!TraceParallelOldGCCompactionPhase) return; 1.2666 + 1.2667 + typedef ParallelCompactData::RegionData rd_t; 1.2668 + ParallelCompactData& sd = summary_data(); 1.2669 + 1.2670 + for (unsigned int id = old_space_id; id < last_space_id; ++id) { 1.2671 + MutableSpace* const spc = _space_info[id].space(); 1.2672 + if (spc->bottom() != spc->top()) { 1.2673 + const rd_t* const beg = sd.addr_to_region_ptr(spc->bottom()); 1.2674 + HeapWord* const top_aligned_up = sd.region_align_up(spc->top()); 1.2675 + const rd_t* const end = sd.addr_to_region_ptr(top_aligned_up); 1.2676 + 1.2677 + size_t histo[5] = { 0, 0, 0, 0, 0 }; 1.2678 + const size_t histo_len = sizeof(histo) / sizeof(size_t); 1.2679 + const size_t region_cnt = pointer_delta(end, beg, sizeof(rd_t)); 1.2680 + 1.2681 + for (const rd_t* cur = beg; cur < end; ++cur) { 1.2682 + ++histo[MIN2(cur->blocks_filled_count(), histo_len - 1)]; 1.2683 + } 1.2684 + out->print("%u %-4s" SIZE_FORMAT_W(5), id, space_names[id], region_cnt); 1.2685 + for (size_t i = 0; i < histo_len; ++i) { 1.2686 + out->print(" " SIZE_FORMAT_W(5) " %5.1f%%", 1.2687 + histo[i], 100.0 * histo[i] / region_cnt); 1.2688 + } 1.2689 + out->cr(); 1.2690 + } 1.2691 + } 1.2692 +} 1.2693 +#endif // #ifdef ASSERT 1.2694 + 1.2695 +void PSParallelCompact::compact() { 1.2696 + // trace("5"); 1.2697 + GCTraceTime tm("compaction phase", print_phases(), true, &_gc_timer); 1.2698 + 1.2699 + ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap(); 1.2700 + assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity"); 1.2701 + PSOldGen* old_gen = heap->old_gen(); 1.2702 + old_gen->start_array()->reset(); 1.2703 + uint parallel_gc_threads = heap->gc_task_manager()->workers(); 1.2704 + uint active_gc_threads = heap->gc_task_manager()->active_workers(); 1.2705 + TaskQueueSetSuper* qset = ParCompactionManager::region_array(); 1.2706 + ParallelTaskTerminator terminator(active_gc_threads, qset); 1.2707 + 1.2708 + GCTaskQueue* q = GCTaskQueue::create(); 1.2709 + enqueue_region_draining_tasks(q, active_gc_threads); 1.2710 + enqueue_dense_prefix_tasks(q, active_gc_threads); 1.2711 + enqueue_region_stealing_tasks(q, &terminator, active_gc_threads); 1.2712 + 1.2713 + { 1.2714 + GCTraceTime tm_pc("par compact", print_phases(), true, &_gc_timer); 1.2715 + 1.2716 + gc_task_manager()->execute_and_wait(q); 1.2717 + 1.2718 +#ifdef ASSERT 1.2719 + // Verify that all regions have been processed before the deferred updates. 1.2720 + for (unsigned int id = old_space_id; id < last_space_id; ++id) { 1.2721 + verify_complete(SpaceId(id)); 1.2722 + } 1.2723 +#endif 1.2724 + } 1.2725 + 1.2726 + { 1.2727 + // Update the deferred objects, if any. Any compaction manager can be used. 1.2728 + GCTraceTime tm_du("deferred updates", print_phases(), true, &_gc_timer); 1.2729 + ParCompactionManager* cm = ParCompactionManager::manager_array(0); 1.2730 + for (unsigned int id = old_space_id; id < last_space_id; ++id) { 1.2731 + update_deferred_objects(cm, SpaceId(id)); 1.2732 + } 1.2733 + } 1.2734 + 1.2735 + DEBUG_ONLY(write_block_fill_histogram(gclog_or_tty)); 1.2736 +} 1.2737 + 1.2738 +#ifdef ASSERT 1.2739 +void PSParallelCompact::verify_complete(SpaceId space_id) { 1.2740 + // All Regions between space bottom() to new_top() should be marked as filled 1.2741 + // and all Regions between new_top() and top() should be available (i.e., 1.2742 + // should have been emptied). 1.2743 + ParallelCompactData& sd = summary_data(); 1.2744 + SpaceInfo si = _space_info[space_id]; 1.2745 + HeapWord* new_top_addr = sd.region_align_up(si.new_top()); 1.2746 + HeapWord* old_top_addr = sd.region_align_up(si.space()->top()); 1.2747 + const size_t beg_region = sd.addr_to_region_idx(si.space()->bottom()); 1.2748 + const size_t new_top_region = sd.addr_to_region_idx(new_top_addr); 1.2749 + const size_t old_top_region = sd.addr_to_region_idx(old_top_addr); 1.2750 + 1.2751 + bool issued_a_warning = false; 1.2752 + 1.2753 + size_t cur_region; 1.2754 + for (cur_region = beg_region; cur_region < new_top_region; ++cur_region) { 1.2755 + const RegionData* const c = sd.region(cur_region); 1.2756 + if (!c->completed()) { 1.2757 + warning("region " SIZE_FORMAT " not filled: " 1.2758 + "destination_count=" SIZE_FORMAT, 1.2759 + cur_region, c->destination_count()); 1.2760 + issued_a_warning = true; 1.2761 + } 1.2762 + } 1.2763 + 1.2764 + for (cur_region = new_top_region; cur_region < old_top_region; ++cur_region) { 1.2765 + const RegionData* const c = sd.region(cur_region); 1.2766 + if (!c->available()) { 1.2767 + warning("region " SIZE_FORMAT " not empty: " 1.2768 + "destination_count=" SIZE_FORMAT, 1.2769 + cur_region, c->destination_count()); 1.2770 + issued_a_warning = true; 1.2771 + } 1.2772 + } 1.2773 + 1.2774 + if (issued_a_warning) { 1.2775 + print_region_ranges(); 1.2776 + } 1.2777 +} 1.2778 +#endif // #ifdef ASSERT 1.2779 + 1.2780 +// Update interior oops in the ranges of regions [beg_region, end_region). 1.2781 +void 1.2782 +PSParallelCompact::update_and_deadwood_in_dense_prefix(ParCompactionManager* cm, 1.2783 + SpaceId space_id, 1.2784 + size_t beg_region, 1.2785 + size_t end_region) { 1.2786 + ParallelCompactData& sd = summary_data(); 1.2787 + ParMarkBitMap* const mbm = mark_bitmap(); 1.2788 + 1.2789 + HeapWord* beg_addr = sd.region_to_addr(beg_region); 1.2790 + HeapWord* const end_addr = sd.region_to_addr(end_region); 1.2791 + assert(beg_region <= end_region, "bad region range"); 1.2792 + assert(end_addr <= dense_prefix(space_id), "not in the dense prefix"); 1.2793 + 1.2794 +#ifdef ASSERT 1.2795 + // Claim the regions to avoid triggering an assert when they are marked as 1.2796 + // filled. 1.2797 + for (size_t claim_region = beg_region; claim_region < end_region; ++claim_region) { 1.2798 + assert(sd.region(claim_region)->claim_unsafe(), "claim() failed"); 1.2799 + } 1.2800 +#endif // #ifdef ASSERT 1.2801 + 1.2802 + if (beg_addr != space(space_id)->bottom()) { 1.2803 + // Find the first live object or block of dead space that *starts* in this 1.2804 + // range of regions. If a partial object crosses onto the region, skip it; 1.2805 + // it will be marked for 'deferred update' when the object head is 1.2806 + // processed. If dead space crosses onto the region, it is also skipped; it 1.2807 + // will be filled when the prior region is processed. If neither of those 1.2808 + // apply, the first word in the region is the start of a live object or dead 1.2809 + // space. 1.2810 + assert(beg_addr > space(space_id)->bottom(), "sanity"); 1.2811 + const RegionData* const cp = sd.region(beg_region); 1.2812 + if (cp->partial_obj_size() != 0) { 1.2813 + beg_addr = sd.partial_obj_end(beg_region); 1.2814 + } else if (dead_space_crosses_boundary(cp, mbm->addr_to_bit(beg_addr))) { 1.2815 + beg_addr = mbm->find_obj_beg(beg_addr, end_addr); 1.2816 + } 1.2817 + } 1.2818 + 1.2819 + if (beg_addr < end_addr) { 1.2820 + // A live object or block of dead space starts in this range of Regions. 1.2821 + HeapWord* const dense_prefix_end = dense_prefix(space_id); 1.2822 + 1.2823 + // Create closures and iterate. 1.2824 + UpdateOnlyClosure update_closure(mbm, cm, space_id); 1.2825 + FillClosure fill_closure(cm, space_id); 1.2826 + ParMarkBitMap::IterationStatus status; 1.2827 + status = mbm->iterate(&update_closure, &fill_closure, beg_addr, end_addr, 1.2828 + dense_prefix_end); 1.2829 + if (status == ParMarkBitMap::incomplete) { 1.2830 + update_closure.do_addr(update_closure.source()); 1.2831 + } 1.2832 + } 1.2833 + 1.2834 + // Mark the regions as filled. 1.2835 + RegionData* const beg_cp = sd.region(beg_region); 1.2836 + RegionData* const end_cp = sd.region(end_region); 1.2837 + for (RegionData* cp = beg_cp; cp < end_cp; ++cp) { 1.2838 + cp->set_completed(); 1.2839 + } 1.2840 +} 1.2841 + 1.2842 +// Return the SpaceId for the space containing addr. If addr is not in the 1.2843 +// heap, last_space_id is returned. In debug mode it expects the address to be 1.2844 +// in the heap and asserts such. 1.2845 +PSParallelCompact::SpaceId PSParallelCompact::space_id(HeapWord* addr) { 1.2846 + assert(Universe::heap()->is_in_reserved(addr), "addr not in the heap"); 1.2847 + 1.2848 + for (unsigned int id = old_space_id; id < last_space_id; ++id) { 1.2849 + if (_space_info[id].space()->contains(addr)) { 1.2850 + return SpaceId(id); 1.2851 + } 1.2852 + } 1.2853 + 1.2854 + assert(false, "no space contains the addr"); 1.2855 + return last_space_id; 1.2856 +} 1.2857 + 1.2858 +void PSParallelCompact::update_deferred_objects(ParCompactionManager* cm, 1.2859 + SpaceId id) { 1.2860 + assert(id < last_space_id, "bad space id"); 1.2861 + 1.2862 + ParallelCompactData& sd = summary_data(); 1.2863 + const SpaceInfo* const space_info = _space_info + id; 1.2864 + ObjectStartArray* const start_array = space_info->start_array(); 1.2865 + 1.2866 + const MutableSpace* const space = space_info->space(); 1.2867 + assert(space_info->dense_prefix() >= space->bottom(), "dense_prefix not set"); 1.2868 + HeapWord* const beg_addr = space_info->dense_prefix(); 1.2869 + HeapWord* const end_addr = sd.region_align_up(space_info->new_top()); 1.2870 + 1.2871 + const RegionData* const beg_region = sd.addr_to_region_ptr(beg_addr); 1.2872 + const RegionData* const end_region = sd.addr_to_region_ptr(end_addr); 1.2873 + const RegionData* cur_region; 1.2874 + for (cur_region = beg_region; cur_region < end_region; ++cur_region) { 1.2875 + HeapWord* const addr = cur_region->deferred_obj_addr(); 1.2876 + if (addr != NULL) { 1.2877 + if (start_array != NULL) { 1.2878 + start_array->allocate_block(addr); 1.2879 + } 1.2880 + oop(addr)->update_contents(cm); 1.2881 + assert(oop(addr)->is_oop_or_null(), "should be an oop now"); 1.2882 + } 1.2883 + } 1.2884 +} 1.2885 + 1.2886 +// Skip over count live words starting from beg, and return the address of the 1.2887 +// next live word. Unless marked, the word corresponding to beg is assumed to 1.2888 +// be dead. Callers must either ensure beg does not correspond to the middle of 1.2889 +// an object, or account for those live words in some other way. Callers must 1.2890 +// also ensure that there are enough live words in the range [beg, end) to skip. 1.2891 +HeapWord* 1.2892 +PSParallelCompact::skip_live_words(HeapWord* beg, HeapWord* end, size_t count) 1.2893 +{ 1.2894 + assert(count > 0, "sanity"); 1.2895 + 1.2896 + ParMarkBitMap* m = mark_bitmap(); 1.2897 + idx_t bits_to_skip = m->words_to_bits(count); 1.2898 + idx_t cur_beg = m->addr_to_bit(beg); 1.2899 + const idx_t search_end = BitMap::word_align_up(m->addr_to_bit(end)); 1.2900 + 1.2901 + do { 1.2902 + cur_beg = m->find_obj_beg(cur_beg, search_end); 1.2903 + idx_t cur_end = m->find_obj_end(cur_beg, search_end); 1.2904 + const size_t obj_bits = cur_end - cur_beg + 1; 1.2905 + if (obj_bits > bits_to_skip) { 1.2906 + return m->bit_to_addr(cur_beg + bits_to_skip); 1.2907 + } 1.2908 + bits_to_skip -= obj_bits; 1.2909 + cur_beg = cur_end + 1; 1.2910 + } while (bits_to_skip > 0); 1.2911 + 1.2912 + // Skipping the desired number of words landed just past the end of an object. 1.2913 + // Find the start of the next object. 1.2914 + cur_beg = m->find_obj_beg(cur_beg, search_end); 1.2915 + assert(cur_beg < m->addr_to_bit(end), "not enough live words to skip"); 1.2916 + return m->bit_to_addr(cur_beg); 1.2917 +} 1.2918 + 1.2919 +HeapWord* PSParallelCompact::first_src_addr(HeapWord* const dest_addr, 1.2920 + SpaceId src_space_id, 1.2921 + size_t src_region_idx) 1.2922 +{ 1.2923 + assert(summary_data().is_region_aligned(dest_addr), "not aligned"); 1.2924 + 1.2925 + const SplitInfo& split_info = _space_info[src_space_id].split_info(); 1.2926 + if (split_info.dest_region_addr() == dest_addr) { 1.2927 + // The partial object ending at the split point contains the first word to 1.2928 + // be copied to dest_addr. 1.2929 + return split_info.first_src_addr(); 1.2930 + } 1.2931 + 1.2932 + const ParallelCompactData& sd = summary_data(); 1.2933 + ParMarkBitMap* const bitmap = mark_bitmap(); 1.2934 + const size_t RegionSize = ParallelCompactData::RegionSize; 1.2935 + 1.2936 + assert(sd.is_region_aligned(dest_addr), "not aligned"); 1.2937 + const RegionData* const src_region_ptr = sd.region(src_region_idx); 1.2938 + const size_t partial_obj_size = src_region_ptr->partial_obj_size(); 1.2939 + HeapWord* const src_region_destination = src_region_ptr->destination(); 1.2940 + 1.2941 + assert(dest_addr >= src_region_destination, "wrong src region"); 1.2942 + assert(src_region_ptr->data_size() > 0, "src region cannot be empty"); 1.2943 + 1.2944 + HeapWord* const src_region_beg = sd.region_to_addr(src_region_idx); 1.2945 + HeapWord* const src_region_end = src_region_beg + RegionSize; 1.2946 + 1.2947 + HeapWord* addr = src_region_beg; 1.2948 + if (dest_addr == src_region_destination) { 1.2949 + // Return the first live word in the source region. 1.2950 + if (partial_obj_size == 0) { 1.2951 + addr = bitmap->find_obj_beg(addr, src_region_end); 1.2952 + assert(addr < src_region_end, "no objects start in src region"); 1.2953 + } 1.2954 + return addr; 1.2955 + } 1.2956 + 1.2957 + // Must skip some live data. 1.2958 + size_t words_to_skip = dest_addr - src_region_destination; 1.2959 + assert(src_region_ptr->data_size() > words_to_skip, "wrong src region"); 1.2960 + 1.2961 + if (partial_obj_size >= words_to_skip) { 1.2962 + // All the live words to skip are part of the partial object. 1.2963 + addr += words_to_skip; 1.2964 + if (partial_obj_size == words_to_skip) { 1.2965 + // Find the first live word past the partial object. 1.2966 + addr = bitmap->find_obj_beg(addr, src_region_end); 1.2967 + assert(addr < src_region_end, "wrong src region"); 1.2968 + } 1.2969 + return addr; 1.2970 + } 1.2971 + 1.2972 + // Skip over the partial object (if any). 1.2973 + if (partial_obj_size != 0) { 1.2974 + words_to_skip -= partial_obj_size; 1.2975 + addr += partial_obj_size; 1.2976 + } 1.2977 + 1.2978 + // Skip over live words due to objects that start in the region. 1.2979 + addr = skip_live_words(addr, src_region_end, words_to_skip); 1.2980 + assert(addr < src_region_end, "wrong src region"); 1.2981 + return addr; 1.2982 +} 1.2983 + 1.2984 +void PSParallelCompact::decrement_destination_counts(ParCompactionManager* cm, 1.2985 + SpaceId src_space_id, 1.2986 + size_t beg_region, 1.2987 + HeapWord* end_addr) 1.2988 +{ 1.2989 + ParallelCompactData& sd = summary_data(); 1.2990 + 1.2991 +#ifdef ASSERT 1.2992 + MutableSpace* const src_space = _space_info[src_space_id].space(); 1.2993 + HeapWord* const beg_addr = sd.region_to_addr(beg_region); 1.2994 + assert(src_space->contains(beg_addr) || beg_addr == src_space->end(), 1.2995 + "src_space_id does not match beg_addr"); 1.2996 + assert(src_space->contains(end_addr) || end_addr == src_space->end(), 1.2997 + "src_space_id does not match end_addr"); 1.2998 +#endif // #ifdef ASSERT 1.2999 + 1.3000 + RegionData* const beg = sd.region(beg_region); 1.3001 + RegionData* const end = sd.addr_to_region_ptr(sd.region_align_up(end_addr)); 1.3002 + 1.3003 + // Regions up to new_top() are enqueued if they become available. 1.3004 + HeapWord* const new_top = _space_info[src_space_id].new_top(); 1.3005 + RegionData* const enqueue_end = 1.3006 + sd.addr_to_region_ptr(sd.region_align_up(new_top)); 1.3007 + 1.3008 + for (RegionData* cur = beg; cur < end; ++cur) { 1.3009 + assert(cur->data_size() > 0, "region must have live data"); 1.3010 + cur->decrement_destination_count(); 1.3011 + if (cur < enqueue_end && cur->available() && cur->claim()) { 1.3012 + cm->push_region(sd.region(cur)); 1.3013 + } 1.3014 + } 1.3015 +} 1.3016 + 1.3017 +size_t PSParallelCompact::next_src_region(MoveAndUpdateClosure& closure, 1.3018 + SpaceId& src_space_id, 1.3019 + HeapWord*& src_space_top, 1.3020 + HeapWord* end_addr) 1.3021 +{ 1.3022 + typedef ParallelCompactData::RegionData RegionData; 1.3023 + 1.3024 + ParallelCompactData& sd = PSParallelCompact::summary_data(); 1.3025 + const size_t region_size = ParallelCompactData::RegionSize; 1.3026 + 1.3027 + size_t src_region_idx = 0; 1.3028 + 1.3029 + // Skip empty regions (if any) up to the top of the space. 1.3030 + HeapWord* const src_aligned_up = sd.region_align_up(end_addr); 1.3031 + RegionData* src_region_ptr = sd.addr_to_region_ptr(src_aligned_up); 1.3032 + HeapWord* const top_aligned_up = sd.region_align_up(src_space_top); 1.3033 + const RegionData* const top_region_ptr = 1.3034 + sd.addr_to_region_ptr(top_aligned_up); 1.3035 + while (src_region_ptr < top_region_ptr && src_region_ptr->data_size() == 0) { 1.3036 + ++src_region_ptr; 1.3037 + } 1.3038 + 1.3039 + if (src_region_ptr < top_region_ptr) { 1.3040 + // The next source region is in the current space. Update src_region_idx 1.3041 + // and the source address to match src_region_ptr. 1.3042 + src_region_idx = sd.region(src_region_ptr); 1.3043 + HeapWord* const src_region_addr = sd.region_to_addr(src_region_idx); 1.3044 + if (src_region_addr > closure.source()) { 1.3045 + closure.set_source(src_region_addr); 1.3046 + } 1.3047 + return src_region_idx; 1.3048 + } 1.3049 + 1.3050 + // Switch to a new source space and find the first non-empty region. 1.3051 + unsigned int space_id = src_space_id + 1; 1.3052 + assert(space_id < last_space_id, "not enough spaces"); 1.3053 + 1.3054 + HeapWord* const destination = closure.destination(); 1.3055 + 1.3056 + do { 1.3057 + MutableSpace* space = _space_info[space_id].space(); 1.3058 + HeapWord* const bottom = space->bottom(); 1.3059 + const RegionData* const bottom_cp = sd.addr_to_region_ptr(bottom); 1.3060 + 1.3061 + // Iterate over the spaces that do not compact into themselves. 1.3062 + if (bottom_cp->destination() != bottom) { 1.3063 + HeapWord* const top_aligned_up = sd.region_align_up(space->top()); 1.3064 + const RegionData* const top_cp = sd.addr_to_region_ptr(top_aligned_up); 1.3065 + 1.3066 + for (const RegionData* src_cp = bottom_cp; src_cp < top_cp; ++src_cp) { 1.3067 + if (src_cp->live_obj_size() > 0) { 1.3068 + // Found it. 1.3069 + assert(src_cp->destination() == destination, 1.3070 + "first live obj in the space must match the destination"); 1.3071 + assert(src_cp->partial_obj_size() == 0, 1.3072 + "a space cannot begin with a partial obj"); 1.3073 + 1.3074 + src_space_id = SpaceId(space_id); 1.3075 + src_space_top = space->top(); 1.3076 + const size_t src_region_idx = sd.region(src_cp); 1.3077 + closure.set_source(sd.region_to_addr(src_region_idx)); 1.3078 + return src_region_idx; 1.3079 + } else { 1.3080 + assert(src_cp->data_size() == 0, "sanity"); 1.3081 + } 1.3082 + } 1.3083 + } 1.3084 + } while (++space_id < last_space_id); 1.3085 + 1.3086 + assert(false, "no source region was found"); 1.3087 + return 0; 1.3088 +} 1.3089 + 1.3090 +void PSParallelCompact::fill_region(ParCompactionManager* cm, size_t region_idx) 1.3091 +{ 1.3092 + typedef ParMarkBitMap::IterationStatus IterationStatus; 1.3093 + const size_t RegionSize = ParallelCompactData::RegionSize; 1.3094 + ParMarkBitMap* const bitmap = mark_bitmap(); 1.3095 + ParallelCompactData& sd = summary_data(); 1.3096 + RegionData* const region_ptr = sd.region(region_idx); 1.3097 + 1.3098 + // Get the items needed to construct the closure. 1.3099 + HeapWord* dest_addr = sd.region_to_addr(region_idx); 1.3100 + SpaceId dest_space_id = space_id(dest_addr); 1.3101 + ObjectStartArray* start_array = _space_info[dest_space_id].start_array(); 1.3102 + HeapWord* new_top = _space_info[dest_space_id].new_top(); 1.3103 + assert(dest_addr < new_top, "sanity"); 1.3104 + const size_t words = MIN2(pointer_delta(new_top, dest_addr), RegionSize); 1.3105 + 1.3106 + // Get the source region and related info. 1.3107 + size_t src_region_idx = region_ptr->source_region(); 1.3108 + SpaceId src_space_id = space_id(sd.region_to_addr(src_region_idx)); 1.3109 + HeapWord* src_space_top = _space_info[src_space_id].space()->top(); 1.3110 + 1.3111 + MoveAndUpdateClosure closure(bitmap, cm, start_array, dest_addr, words); 1.3112 + closure.set_source(first_src_addr(dest_addr, src_space_id, src_region_idx)); 1.3113 + 1.3114 + // Adjust src_region_idx to prepare for decrementing destination counts (the 1.3115 + // destination count is not decremented when a region is copied to itself). 1.3116 + if (src_region_idx == region_idx) { 1.3117 + src_region_idx += 1; 1.3118 + } 1.3119 + 1.3120 + if (bitmap->is_unmarked(closure.source())) { 1.3121 + // The first source word is in the middle of an object; copy the remainder 1.3122 + // of the object or as much as will fit. The fact that pointer updates were 1.3123 + // deferred will be noted when the object header is processed. 1.3124 + HeapWord* const old_src_addr = closure.source(); 1.3125 + closure.copy_partial_obj(); 1.3126 + if (closure.is_full()) { 1.3127 + decrement_destination_counts(cm, src_space_id, src_region_idx, 1.3128 + closure.source()); 1.3129 + region_ptr->set_deferred_obj_addr(NULL); 1.3130 + region_ptr->set_completed(); 1.3131 + return; 1.3132 + } 1.3133 + 1.3134 + HeapWord* const end_addr = sd.region_align_down(closure.source()); 1.3135 + if (sd.region_align_down(old_src_addr) != end_addr) { 1.3136 + // The partial object was copied from more than one source region. 1.3137 + decrement_destination_counts(cm, src_space_id, src_region_idx, end_addr); 1.3138 + 1.3139 + // Move to the next source region, possibly switching spaces as well. All 1.3140 + // args except end_addr may be modified. 1.3141 + src_region_idx = next_src_region(closure, src_space_id, src_space_top, 1.3142 + end_addr); 1.3143 + } 1.3144 + } 1.3145 + 1.3146 + do { 1.3147 + HeapWord* const cur_addr = closure.source(); 1.3148 + HeapWord* const end_addr = MIN2(sd.region_align_up(cur_addr + 1), 1.3149 + src_space_top); 1.3150 + IterationStatus status = bitmap->iterate(&closure, cur_addr, end_addr); 1.3151 + 1.3152 + if (status == ParMarkBitMap::incomplete) { 1.3153 + // The last obj that starts in the source region does not end in the 1.3154 + // region. 1.3155 + assert(closure.source() < end_addr, "sanity"); 1.3156 + HeapWord* const obj_beg = closure.source(); 1.3157 + HeapWord* const range_end = MIN2(obj_beg + closure.words_remaining(), 1.3158 + src_space_top); 1.3159 + HeapWord* const obj_end = bitmap->find_obj_end(obj_beg, range_end); 1.3160 + if (obj_end < range_end) { 1.3161 + // The end was found; the entire object will fit. 1.3162 + status = closure.do_addr(obj_beg, bitmap->obj_size(obj_beg, obj_end)); 1.3163 + assert(status != ParMarkBitMap::would_overflow, "sanity"); 1.3164 + } else { 1.3165 + // The end was not found; the object will not fit. 1.3166 + assert(range_end < src_space_top, "obj cannot cross space boundary"); 1.3167 + status = ParMarkBitMap::would_overflow; 1.3168 + } 1.3169 + } 1.3170 + 1.3171 + if (status == ParMarkBitMap::would_overflow) { 1.3172 + // The last object did not fit. Note that interior oop updates were 1.3173 + // deferred, then copy enough of the object to fill the region. 1.3174 + region_ptr->set_deferred_obj_addr(closure.destination()); 1.3175 + status = closure.copy_until_full(); // copies from closure.source() 1.3176 + 1.3177 + decrement_destination_counts(cm, src_space_id, src_region_idx, 1.3178 + closure.source()); 1.3179 + region_ptr->set_completed(); 1.3180 + return; 1.3181 + } 1.3182 + 1.3183 + if (status == ParMarkBitMap::full) { 1.3184 + decrement_destination_counts(cm, src_space_id, src_region_idx, 1.3185 + closure.source()); 1.3186 + region_ptr->set_deferred_obj_addr(NULL); 1.3187 + region_ptr->set_completed(); 1.3188 + return; 1.3189 + } 1.3190 + 1.3191 + decrement_destination_counts(cm, src_space_id, src_region_idx, end_addr); 1.3192 + 1.3193 + // Move to the next source region, possibly switching spaces as well. All 1.3194 + // args except end_addr may be modified. 1.3195 + src_region_idx = next_src_region(closure, src_space_id, src_space_top, 1.3196 + end_addr); 1.3197 + } while (true); 1.3198 +} 1.3199 + 1.3200 +void PSParallelCompact::fill_blocks(size_t region_idx) 1.3201 +{ 1.3202 + // Fill in the block table elements for the specified region. Each block 1.3203 + // table element holds the number of live words in the region that are to the 1.3204 + // left of the first object that starts in the block. Thus only blocks in 1.3205 + // which an object starts need to be filled. 1.3206 + // 1.3207 + // The algorithm scans the section of the bitmap that corresponds to the 1.3208 + // region, keeping a running total of the live words. When an object start is 1.3209 + // found, if it's the first to start in the block that contains it, the 1.3210 + // current total is written to the block table element. 1.3211 + const size_t Log2BlockSize = ParallelCompactData::Log2BlockSize; 1.3212 + const size_t Log2RegionSize = ParallelCompactData::Log2RegionSize; 1.3213 + const size_t RegionSize = ParallelCompactData::RegionSize; 1.3214 + 1.3215 + ParallelCompactData& sd = summary_data(); 1.3216 + const size_t partial_obj_size = sd.region(region_idx)->partial_obj_size(); 1.3217 + if (partial_obj_size >= RegionSize) { 1.3218 + return; // No objects start in this region. 1.3219 + } 1.3220 + 1.3221 + // Ensure the first loop iteration decides that the block has changed. 1.3222 + size_t cur_block = sd.block_count(); 1.3223 + 1.3224 + const ParMarkBitMap* const bitmap = mark_bitmap(); 1.3225 + 1.3226 + const size_t Log2BitsPerBlock = Log2BlockSize - LogMinObjAlignment; 1.3227 + assert((size_t)1 << Log2BitsPerBlock == 1.3228 + bitmap->words_to_bits(ParallelCompactData::BlockSize), "sanity"); 1.3229 + 1.3230 + size_t beg_bit = bitmap->words_to_bits(region_idx << Log2RegionSize); 1.3231 + const size_t range_end = beg_bit + bitmap->words_to_bits(RegionSize); 1.3232 + size_t live_bits = bitmap->words_to_bits(partial_obj_size); 1.3233 + beg_bit = bitmap->find_obj_beg(beg_bit + live_bits, range_end); 1.3234 + while (beg_bit < range_end) { 1.3235 + const size_t new_block = beg_bit >> Log2BitsPerBlock; 1.3236 + if (new_block != cur_block) { 1.3237 + cur_block = new_block; 1.3238 + sd.block(cur_block)->set_offset(bitmap->bits_to_words(live_bits)); 1.3239 + } 1.3240 + 1.3241 + const size_t end_bit = bitmap->find_obj_end(beg_bit, range_end); 1.3242 + if (end_bit < range_end - 1) { 1.3243 + live_bits += end_bit - beg_bit + 1; 1.3244 + beg_bit = bitmap->find_obj_beg(end_bit + 1, range_end); 1.3245 + } else { 1.3246 + return; 1.3247 + } 1.3248 + } 1.3249 +} 1.3250 + 1.3251 +void 1.3252 +PSParallelCompact::move_and_update(ParCompactionManager* cm, SpaceId space_id) { 1.3253 + const MutableSpace* sp = space(space_id); 1.3254 + if (sp->is_empty()) { 1.3255 + return; 1.3256 + } 1.3257 + 1.3258 + ParallelCompactData& sd = PSParallelCompact::summary_data(); 1.3259 + ParMarkBitMap* const bitmap = mark_bitmap(); 1.3260 + HeapWord* const dp_addr = dense_prefix(space_id); 1.3261 + HeapWord* beg_addr = sp->bottom(); 1.3262 + HeapWord* end_addr = sp->top(); 1.3263 + 1.3264 + assert(beg_addr <= dp_addr && dp_addr <= end_addr, "bad dense prefix"); 1.3265 + 1.3266 + const size_t beg_region = sd.addr_to_region_idx(beg_addr); 1.3267 + const size_t dp_region = sd.addr_to_region_idx(dp_addr); 1.3268 + if (beg_region < dp_region) { 1.3269 + update_and_deadwood_in_dense_prefix(cm, space_id, beg_region, dp_region); 1.3270 + } 1.3271 + 1.3272 + // The destination of the first live object that starts in the region is one 1.3273 + // past the end of the partial object entering the region (if any). 1.3274 + HeapWord* const dest_addr = sd.partial_obj_end(dp_region); 1.3275 + HeapWord* const new_top = _space_info[space_id].new_top(); 1.3276 + assert(new_top >= dest_addr, "bad new_top value"); 1.3277 + const size_t words = pointer_delta(new_top, dest_addr); 1.3278 + 1.3279 + if (words > 0) { 1.3280 + ObjectStartArray* start_array = _space_info[space_id].start_array(); 1.3281 + MoveAndUpdateClosure closure(bitmap, cm, start_array, dest_addr, words); 1.3282 + 1.3283 + ParMarkBitMap::IterationStatus status; 1.3284 + status = bitmap->iterate(&closure, dest_addr, end_addr); 1.3285 + assert(status == ParMarkBitMap::full, "iteration not complete"); 1.3286 + assert(bitmap->find_obj_beg(closure.source(), end_addr) == end_addr, 1.3287 + "live objects skipped because closure is full"); 1.3288 + } 1.3289 +} 1.3290 + 1.3291 +jlong PSParallelCompact::millis_since_last_gc() { 1.3292 + // We need a monotonically non-deccreasing time in ms but 1.3293 + // os::javaTimeMillis() does not guarantee monotonicity. 1.3294 + jlong now = os::javaTimeNanos() / NANOSECS_PER_MILLISEC; 1.3295 + jlong ret_val = now - _time_of_last_gc; 1.3296 + // XXX See note in genCollectedHeap::millis_since_last_gc(). 1.3297 + if (ret_val < 0) { 1.3298 + NOT_PRODUCT(warning("time warp: "INT64_FORMAT, ret_val);) 1.3299 + return 0; 1.3300 + } 1.3301 + return ret_val; 1.3302 +} 1.3303 + 1.3304 +void PSParallelCompact::reset_millis_since_last_gc() { 1.3305 + // We need a monotonically non-deccreasing time in ms but 1.3306 + // os::javaTimeMillis() does not guarantee monotonicity. 1.3307 + _time_of_last_gc = os::javaTimeNanos() / NANOSECS_PER_MILLISEC; 1.3308 +} 1.3309 + 1.3310 +ParMarkBitMap::IterationStatus MoveAndUpdateClosure::copy_until_full() 1.3311 +{ 1.3312 + if (source() != destination()) { 1.3313 + DEBUG_ONLY(PSParallelCompact::check_new_location(source(), destination());) 1.3314 + Copy::aligned_conjoint_words(source(), destination(), words_remaining()); 1.3315 + } 1.3316 + update_state(words_remaining()); 1.3317 + assert(is_full(), "sanity"); 1.3318 + return ParMarkBitMap::full; 1.3319 +} 1.3320 + 1.3321 +void MoveAndUpdateClosure::copy_partial_obj() 1.3322 +{ 1.3323 + size_t words = words_remaining(); 1.3324 + 1.3325 + HeapWord* const range_end = MIN2(source() + words, bitmap()->region_end()); 1.3326 + HeapWord* const end_addr = bitmap()->find_obj_end(source(), range_end); 1.3327 + if (end_addr < range_end) { 1.3328 + words = bitmap()->obj_size(source(), end_addr); 1.3329 + } 1.3330 + 1.3331 + // This test is necessary; if omitted, the pointer updates to a partial object 1.3332 + // that crosses the dense prefix boundary could be overwritten. 1.3333 + if (source() != destination()) { 1.3334 + DEBUG_ONLY(PSParallelCompact::check_new_location(source(), destination());) 1.3335 + Copy::aligned_conjoint_words(source(), destination(), words); 1.3336 + } 1.3337 + update_state(words); 1.3338 +} 1.3339 + 1.3340 +ParMarkBitMapClosure::IterationStatus 1.3341 +MoveAndUpdateClosure::do_addr(HeapWord* addr, size_t words) { 1.3342 + assert(destination() != NULL, "sanity"); 1.3343 + assert(bitmap()->obj_size(addr) == words, "bad size"); 1.3344 + 1.3345 + _source = addr; 1.3346 + assert(PSParallelCompact::summary_data().calc_new_pointer(source()) == 1.3347 + destination(), "wrong destination"); 1.3348 + 1.3349 + if (words > words_remaining()) { 1.3350 + return ParMarkBitMap::would_overflow; 1.3351 + } 1.3352 + 1.3353 + // The start_array must be updated even if the object is not moving. 1.3354 + if (_start_array != NULL) { 1.3355 + _start_array->allocate_block(destination()); 1.3356 + } 1.3357 + 1.3358 + if (destination() != source()) { 1.3359 + DEBUG_ONLY(PSParallelCompact::check_new_location(source(), destination());) 1.3360 + Copy::aligned_conjoint_words(source(), destination(), words); 1.3361 + } 1.3362 + 1.3363 + oop moved_oop = (oop) destination(); 1.3364 + moved_oop->update_contents(compaction_manager()); 1.3365 + assert(moved_oop->is_oop_or_null(), "Object should be whole at this point"); 1.3366 + 1.3367 + update_state(words); 1.3368 + assert(destination() == (HeapWord*)moved_oop + moved_oop->size(), "sanity"); 1.3369 + return is_full() ? ParMarkBitMap::full : ParMarkBitMap::incomplete; 1.3370 +} 1.3371 + 1.3372 +UpdateOnlyClosure::UpdateOnlyClosure(ParMarkBitMap* mbm, 1.3373 + ParCompactionManager* cm, 1.3374 + PSParallelCompact::SpaceId space_id) : 1.3375 + ParMarkBitMapClosure(mbm, cm), 1.3376 + _space_id(space_id), 1.3377 + _start_array(PSParallelCompact::start_array(space_id)) 1.3378 +{ 1.3379 +} 1.3380 + 1.3381 +// Updates the references in the object to their new values. 1.3382 +ParMarkBitMapClosure::IterationStatus 1.3383 +UpdateOnlyClosure::do_addr(HeapWord* addr, size_t words) { 1.3384 + do_addr(addr); 1.3385 + return ParMarkBitMap::incomplete; 1.3386 +}