duke@435: /* drchase@6680: * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #include "precompiled.hpp" stefank@2314: #include "classfile/symbolTable.hpp" stefank@2314: #include "classfile/systemDictionary.hpp" stefank@2314: #include "code/codeCache.hpp" stefank@2314: #include "gc_implementation/parallelScavenge/gcTaskManager.hpp" stefank@2314: #include "gc_implementation/parallelScavenge/parallelScavengeHeap.inline.hpp" stefank@2314: #include "gc_implementation/parallelScavenge/pcTasks.hpp" stefank@2314: #include "gc_implementation/parallelScavenge/psAdaptiveSizePolicy.hpp" stefank@2314: #include "gc_implementation/parallelScavenge/psCompactionManager.inline.hpp" stefank@2314: #include "gc_implementation/parallelScavenge/psMarkSweep.hpp" stefank@2314: #include "gc_implementation/parallelScavenge/psMarkSweepDecorator.hpp" stefank@2314: #include "gc_implementation/parallelScavenge/psOldGen.hpp" stefank@2314: #include "gc_implementation/parallelScavenge/psParallelCompact.hpp" stefank@2314: #include "gc_implementation/parallelScavenge/psPromotionManager.inline.hpp" stefank@2314: #include "gc_implementation/parallelScavenge/psScavenge.hpp" stefank@2314: #include "gc_implementation/parallelScavenge/psYoungGen.hpp" sla@5237: #include "gc_implementation/shared/gcHeapSummary.hpp" sla@5237: #include "gc_implementation/shared/gcTimer.hpp" sla@5237: #include "gc_implementation/shared/gcTrace.hpp" sla@5237: #include "gc_implementation/shared/gcTraceTime.hpp" stefank@2314: #include "gc_implementation/shared/isGCActiveMark.hpp" stefank@2314: #include "gc_interface/gcCause.hpp" stefank@2314: #include "memory/gcLocker.inline.hpp" stefank@2314: #include "memory/referencePolicy.hpp" stefank@2314: #include "memory/referenceProcessor.hpp" coleenp@4037: #include "oops/methodData.hpp" stefank@2314: #include "oops/oop.inline.hpp" stefank@2314: #include "oops/oop.pcgc.inline.hpp" stefank@2314: #include "runtime/fprofiler.hpp" stefank@2314: #include "runtime/safepoint.hpp" stefank@2314: #include "runtime/vmThread.hpp" stefank@2314: #include "services/management.hpp" stefank@2314: #include "services/memoryService.hpp" zgu@3900: #include "services/memTracker.hpp" stefank@2314: #include "utilities/events.hpp" stefank@2314: #include "utilities/stack.inline.hpp" duke@435: duke@435: #include duke@435: drchase@6680: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC drchase@6680: duke@435: // All sizes are in HeapWords. jcoomes@5201: const size_t ParallelCompactData::Log2RegionSize = 16; // 64K words jcoomes@810: const size_t ParallelCompactData::RegionSize = (size_t)1 << Log2RegionSize; jcoomes@810: const size_t ParallelCompactData::RegionSizeBytes = jcoomes@810: RegionSize << LogHeapWordSize; jcoomes@810: const size_t ParallelCompactData::RegionSizeOffsetMask = RegionSize - 1; jcoomes@810: const size_t ParallelCompactData::RegionAddrOffsetMask = RegionSizeBytes - 1; jcoomes@5201: const size_t ParallelCompactData::RegionAddrMask = ~RegionAddrOffsetMask; jcoomes@5201: jcoomes@5201: const size_t ParallelCompactData::Log2BlockSize = 7; // 128 words jcoomes@5201: const size_t ParallelCompactData::BlockSize = (size_t)1 << Log2BlockSize; jcoomes@5201: const size_t ParallelCompactData::BlockSizeBytes = jcoomes@5201: BlockSize << LogHeapWordSize; jcoomes@5201: const size_t ParallelCompactData::BlockSizeOffsetMask = BlockSize - 1; jcoomes@5201: const size_t ParallelCompactData::BlockAddrOffsetMask = BlockSizeBytes - 1; jcoomes@5201: const size_t ParallelCompactData::BlockAddrMask = ~BlockAddrOffsetMask; jcoomes@5201: jcoomes@5201: const size_t ParallelCompactData::BlocksPerRegion = RegionSize / BlockSize; jcoomes@5201: const size_t ParallelCompactData::Log2BlocksPerRegion = jcoomes@5201: Log2RegionSize - Log2BlockSize; duke@435: jcoomes@810: const ParallelCompactData::RegionData::region_sz_t jcoomes@810: ParallelCompactData::RegionData::dc_shift = 27; jcoomes@810: jcoomes@810: const ParallelCompactData::RegionData::region_sz_t jcoomes@810: ParallelCompactData::RegionData::dc_mask = ~0U << dc_shift; jcoomes@810: jcoomes@810: const ParallelCompactData::RegionData::region_sz_t jcoomes@810: ParallelCompactData::RegionData::dc_one = 0x1U << dc_shift; jcoomes@810: jcoomes@810: const ParallelCompactData::RegionData::region_sz_t jcoomes@810: ParallelCompactData::RegionData::los_mask = ~dc_mask; jcoomes@810: jcoomes@810: const ParallelCompactData::RegionData::region_sz_t jcoomes@810: ParallelCompactData::RegionData::dc_claimed = 0x8U << dc_shift; jcoomes@810: jcoomes@810: const ParallelCompactData::RegionData::region_sz_t jcoomes@810: ParallelCompactData::RegionData::dc_completed = 0xcU << dc_shift; duke@435: duke@435: SpaceInfo PSParallelCompact::_space_info[PSParallelCompact::last_space_id]; duke@435: bool PSParallelCompact::_print_phases = false; duke@435: duke@435: ReferenceProcessor* PSParallelCompact::_ref_processor = NULL; coleenp@4037: Klass* PSParallelCompact::_updated_int_array_klass_obj = NULL; duke@435: duke@435: double PSParallelCompact::_dwl_mean; duke@435: double PSParallelCompact::_dwl_std_dev; duke@435: double PSParallelCompact::_dwl_first_term; duke@435: double PSParallelCompact::_dwl_adjustment; duke@435: #ifdef ASSERT duke@435: bool PSParallelCompact::_dwl_initialized = false; duke@435: #endif // #ifdef ASSERT duke@435: jcoomes@917: void SplitInfo::record(size_t src_region_idx, size_t partial_obj_size, jcoomes@917: HeapWord* destination) jcoomes@917: { jcoomes@917: assert(src_region_idx != 0, "invalid src_region_idx"); jcoomes@917: assert(partial_obj_size != 0, "invalid partial_obj_size argument"); jcoomes@917: assert(destination != NULL, "invalid destination argument"); jcoomes@917: jcoomes@917: _src_region_idx = src_region_idx; jcoomes@917: _partial_obj_size = partial_obj_size; jcoomes@917: _destination = destination; jcoomes@917: jcoomes@917: // These fields may not be updated below, so make sure they're clear. jcoomes@917: assert(_dest_region_addr == NULL, "should have been cleared"); jcoomes@917: assert(_first_src_addr == NULL, "should have been cleared"); jcoomes@917: jcoomes@917: // Determine the number of destination regions for the partial object. jcoomes@917: HeapWord* const last_word = destination + partial_obj_size - 1; jcoomes@917: const ParallelCompactData& sd = PSParallelCompact::summary_data(); jcoomes@917: HeapWord* const beg_region_addr = sd.region_align_down(destination); jcoomes@917: HeapWord* const end_region_addr = sd.region_align_down(last_word); jcoomes@917: jcoomes@917: if (beg_region_addr == end_region_addr) { jcoomes@917: // One destination region. jcoomes@917: _destination_count = 1; jcoomes@917: if (end_region_addr == destination) { jcoomes@917: // The destination falls on a region boundary, thus the first word of the jcoomes@917: // partial object will be the first word copied to the destination region. jcoomes@917: _dest_region_addr = end_region_addr; jcoomes@917: _first_src_addr = sd.region_to_addr(src_region_idx); jcoomes@917: } jcoomes@917: } else { jcoomes@917: // Two destination regions. When copied, the partial object will cross a jcoomes@917: // destination region boundary, so a word somewhere within the partial jcoomes@917: // object will be the first word copied to the second destination region. jcoomes@917: _destination_count = 2; jcoomes@917: _dest_region_addr = end_region_addr; jcoomes@917: const size_t ofs = pointer_delta(end_region_addr, destination); jcoomes@917: assert(ofs < _partial_obj_size, "sanity"); jcoomes@917: _first_src_addr = sd.region_to_addr(src_region_idx) + ofs; jcoomes@917: } jcoomes@917: } jcoomes@917: jcoomes@917: void SplitInfo::clear() jcoomes@917: { jcoomes@917: _src_region_idx = 0; jcoomes@917: _partial_obj_size = 0; jcoomes@917: _destination = NULL; jcoomes@917: _destination_count = 0; jcoomes@917: _dest_region_addr = NULL; jcoomes@917: _first_src_addr = NULL; jcoomes@917: assert(!is_valid(), "sanity"); jcoomes@917: } jcoomes@917: jcoomes@917: #ifdef ASSERT jcoomes@917: void SplitInfo::verify_clear() jcoomes@917: { jcoomes@917: assert(_src_region_idx == 0, "not clear"); jcoomes@917: assert(_partial_obj_size == 0, "not clear"); jcoomes@917: assert(_destination == NULL, "not clear"); jcoomes@917: assert(_destination_count == 0, "not clear"); jcoomes@917: assert(_dest_region_addr == NULL, "not clear"); jcoomes@917: assert(_first_src_addr == NULL, "not clear"); jcoomes@917: } jcoomes@917: #endif // #ifdef ASSERT jcoomes@917: jcoomes@917: stefank@4904: void PSParallelCompact::print_on_error(outputStream* st) { stefank@4904: _mark_bitmap.print_on_error(st); stefank@4904: } stefank@4904: duke@435: #ifndef PRODUCT duke@435: const char* PSParallelCompact::space_names[] = { coleenp@4037: "old ", "eden", "from", "to " duke@435: }; duke@435: jcoomes@810: void PSParallelCompact::print_region_ranges() duke@435: { duke@435: tty->print_cr("space bottom top end new_top"); duke@435: tty->print_cr("------ ---------- ---------- ---------- ----------"); duke@435: duke@435: for (unsigned int id = 0; id < last_space_id; ++id) { duke@435: const MutableSpace* space = _space_info[id].space(); duke@435: tty->print_cr("%u %s " jcoomes@699: SIZE_FORMAT_W(10) " " SIZE_FORMAT_W(10) " " jcoomes@699: SIZE_FORMAT_W(10) " " SIZE_FORMAT_W(10) " ", duke@435: id, space_names[id], jcoomes@810: summary_data().addr_to_region_idx(space->bottom()), jcoomes@810: summary_data().addr_to_region_idx(space->top()), jcoomes@810: summary_data().addr_to_region_idx(space->end()), jcoomes@810: summary_data().addr_to_region_idx(_space_info[id].new_top())); duke@435: } duke@435: } duke@435: duke@435: void jcoomes@810: print_generic_summary_region(size_t i, const ParallelCompactData::RegionData* c) duke@435: { jcoomes@810: #define REGION_IDX_FORMAT SIZE_FORMAT_W(7) jcoomes@810: #define REGION_DATA_FORMAT SIZE_FORMAT_W(5) duke@435: duke@435: ParallelCompactData& sd = PSParallelCompact::summary_data(); jcoomes@810: size_t dci = c->destination() ? sd.addr_to_region_idx(c->destination()) : 0; jcoomes@810: tty->print_cr(REGION_IDX_FORMAT " " PTR_FORMAT " " jcoomes@810: REGION_IDX_FORMAT " " PTR_FORMAT " " jcoomes@810: REGION_DATA_FORMAT " " REGION_DATA_FORMAT " " jcoomes@810: REGION_DATA_FORMAT " " REGION_IDX_FORMAT " %d", duke@435: i, c->data_location(), dci, c->destination(), duke@435: c->partial_obj_size(), c->live_obj_size(), jcoomes@810: c->data_size(), c->source_region(), c->destination_count()); jcoomes@810: jcoomes@810: #undef REGION_IDX_FORMAT jcoomes@810: #undef REGION_DATA_FORMAT duke@435: } duke@435: duke@435: void duke@435: print_generic_summary_data(ParallelCompactData& summary_data, duke@435: HeapWord* const beg_addr, duke@435: HeapWord* const end_addr) duke@435: { duke@435: size_t total_words = 0; jcoomes@810: size_t i = summary_data.addr_to_region_idx(beg_addr); jcoomes@810: const size_t last = summary_data.addr_to_region_idx(end_addr); duke@435: HeapWord* pdest = 0; duke@435: duke@435: while (i <= last) { jcoomes@810: ParallelCompactData::RegionData* c = summary_data.region(i); duke@435: if (c->data_size() != 0 || c->destination() != pdest) { jcoomes@810: print_generic_summary_region(i, c); duke@435: total_words += c->data_size(); duke@435: pdest = c->destination(); duke@435: } duke@435: ++i; duke@435: } duke@435: duke@435: tty->print_cr("summary_data_bytes=" SIZE_FORMAT, total_words * HeapWordSize); duke@435: } duke@435: duke@435: void duke@435: print_generic_summary_data(ParallelCompactData& summary_data, duke@435: SpaceInfo* space_info) duke@435: { duke@435: for (unsigned int id = 0; id < PSParallelCompact::last_space_id; ++id) { duke@435: const MutableSpace* space = space_info[id].space(); duke@435: print_generic_summary_data(summary_data, space->bottom(), duke@435: MAX2(space->top(), space_info[id].new_top())); duke@435: } duke@435: } duke@435: duke@435: void jcoomes@810: print_initial_summary_region(size_t i, jcoomes@810: const ParallelCompactData::RegionData* c, jcoomes@810: bool newline = true) duke@435: { jcoomes@699: tty->print(SIZE_FORMAT_W(5) " " PTR_FORMAT " " jcoomes@699: SIZE_FORMAT_W(5) " " SIZE_FORMAT_W(5) " " jcoomes@699: SIZE_FORMAT_W(5) " " SIZE_FORMAT_W(5) " %d", duke@435: i, c->destination(), duke@435: c->partial_obj_size(), c->live_obj_size(), jcoomes@810: c->data_size(), c->source_region(), c->destination_count()); duke@435: if (newline) tty->cr(); duke@435: } duke@435: duke@435: void duke@435: print_initial_summary_data(ParallelCompactData& summary_data, duke@435: const MutableSpace* space) { duke@435: if (space->top() == space->bottom()) { duke@435: return; duke@435: } duke@435: jcoomes@810: const size_t region_size = ParallelCompactData::RegionSize; jcoomes@810: typedef ParallelCompactData::RegionData RegionData; jcoomes@810: HeapWord* const top_aligned_up = summary_data.region_align_up(space->top()); jcoomes@810: const size_t end_region = summary_data.addr_to_region_idx(top_aligned_up); jcoomes@810: const RegionData* c = summary_data.region(end_region - 1); duke@435: HeapWord* end_addr = c->destination() + c->data_size(); duke@435: const size_t live_in_space = pointer_delta(end_addr, space->bottom()); duke@435: jcoomes@810: // Print (and count) the full regions at the beginning of the space. jcoomes@810: size_t full_region_count = 0; jcoomes@810: size_t i = summary_data.addr_to_region_idx(space->bottom()); jcoomes@810: while (i < end_region && summary_data.region(i)->data_size() == region_size) { jcoomes@810: print_initial_summary_region(i, summary_data.region(i)); jcoomes@810: ++full_region_count; duke@435: ++i; duke@435: } duke@435: jcoomes@810: size_t live_to_right = live_in_space - full_region_count * region_size; duke@435: duke@435: double max_reclaimed_ratio = 0.0; jcoomes@810: size_t max_reclaimed_ratio_region = 0; duke@435: size_t max_dead_to_right = 0; duke@435: size_t max_live_to_right = 0; duke@435: jcoomes@810: // Print the 'reclaimed ratio' for regions while there is something live in jcoomes@810: // the region or to the right of it. The remaining regions are empty (and duke@435: // uninteresting), and computing the ratio will result in division by 0. jcoomes@810: while (i < end_region && live_to_right > 0) { jcoomes@810: c = summary_data.region(i); jcoomes@810: HeapWord* const region_addr = summary_data.region_to_addr(i); jcoomes@810: const size_t used_to_right = pointer_delta(space->top(), region_addr); duke@435: const size_t dead_to_right = used_to_right - live_to_right; duke@435: const double reclaimed_ratio = double(dead_to_right) / live_to_right; duke@435: duke@435: if (reclaimed_ratio > max_reclaimed_ratio) { duke@435: max_reclaimed_ratio = reclaimed_ratio; jcoomes@810: max_reclaimed_ratio_region = i; duke@435: max_dead_to_right = dead_to_right; duke@435: max_live_to_right = live_to_right; duke@435: } duke@435: jcoomes@810: print_initial_summary_region(i, c, false); jcoomes@699: tty->print_cr(" %12.10f " SIZE_FORMAT_W(10) " " SIZE_FORMAT_W(10), duke@435: reclaimed_ratio, dead_to_right, live_to_right); duke@435: duke@435: live_to_right -= c->data_size(); duke@435: ++i; duke@435: } duke@435: jcoomes@810: // Any remaining regions are empty. Print one more if there is one. jcoomes@810: if (i < end_region) { jcoomes@810: print_initial_summary_region(i, summary_data.region(i)); duke@435: } duke@435: jcoomes@699: tty->print_cr("max: " SIZE_FORMAT_W(4) " d2r=" SIZE_FORMAT_W(10) " " jcoomes@699: "l2r=" SIZE_FORMAT_W(10) " max_ratio=%14.12f", jcoomes@810: max_reclaimed_ratio_region, max_dead_to_right, duke@435: max_live_to_right, max_reclaimed_ratio); duke@435: } duke@435: duke@435: void duke@435: print_initial_summary_data(ParallelCompactData& summary_data, duke@435: SpaceInfo* space_info) { coleenp@4037: unsigned int id = PSParallelCompact::old_space_id; duke@435: const MutableSpace* space; duke@435: do { duke@435: space = space_info[id].space(); duke@435: print_initial_summary_data(summary_data, space); duke@435: } while (++id < PSParallelCompact::eden_space_id); duke@435: duke@435: do { duke@435: space = space_info[id].space(); duke@435: print_generic_summary_data(summary_data, space->bottom(), space->top()); duke@435: } while (++id < PSParallelCompact::last_space_id); duke@435: } duke@435: #endif // #ifndef PRODUCT duke@435: duke@435: #ifdef ASSERT duke@435: size_t add_obj_count; duke@435: size_t add_obj_size; duke@435: size_t mark_bitmap_count; duke@435: size_t mark_bitmap_size; duke@435: #endif // #ifdef ASSERT duke@435: duke@435: ParallelCompactData::ParallelCompactData() duke@435: { duke@435: _region_start = 0; duke@435: jcoomes@810: _region_vspace = 0; tamao@5161: _reserved_byte_size = 0; jcoomes@810: _region_data = 0; jcoomes@810: _region_count = 0; jcoomes@5201: jcoomes@5201: _block_vspace = 0; jcoomes@5201: _block_data = 0; jcoomes@5201: _block_count = 0; duke@435: } duke@435: duke@435: bool ParallelCompactData::initialize(MemRegion covered_region) duke@435: { duke@435: _region_start = covered_region.start(); duke@435: const size_t region_size = covered_region.word_size(); duke@435: DEBUG_ONLY(_region_end = _region_start + region_size;) duke@435: jcoomes@810: assert(region_align_down(_region_start) == _region_start, duke@435: "region start not aligned"); jcoomes@810: assert((region_size & RegionSizeOffsetMask) == 0, jcoomes@810: "region size not a multiple of RegionSize"); jcoomes@810: jcoomes@5201: bool result = initialize_region_data(region_size) && initialize_block_data(); duke@435: return result; duke@435: } duke@435: duke@435: PSVirtualSpace* duke@435: ParallelCompactData::create_vspace(size_t count, size_t element_size) duke@435: { duke@435: const size_t raw_bytes = count * element_size; duke@435: const size_t page_sz = os::page_size_for_region(raw_bytes, raw_bytes, 10); duke@435: const size_t granularity = os::vm_allocation_granularity(); tamao@5161: _reserved_byte_size = align_size_up(raw_bytes, MAX2(page_sz, granularity)); duke@435: duke@435: const size_t rs_align = page_sz == (size_t) os::vm_page_size() ? 0 : duke@435: MAX2(page_sz, granularity); tamao@5161: ReservedSpace rs(_reserved_byte_size, rs_align, rs_align > 0); duke@435: os::trace_page_sizes("par compact", raw_bytes, raw_bytes, page_sz, rs.base(), duke@435: rs.size()); zgu@3900: zgu@3900: MemTracker::record_virtual_memory_type((address)rs.base(), mtGC); zgu@3900: duke@435: PSVirtualSpace* vspace = new PSVirtualSpace(rs, page_sz); duke@435: if (vspace != 0) { tamao@5161: if (vspace->expand_by(_reserved_byte_size)) { duke@435: return vspace; duke@435: } duke@435: delete vspace; coleenp@672: // Release memory reserved in the space. coleenp@672: rs.release(); duke@435: } duke@435: duke@435: return 0; duke@435: } duke@435: jcoomes@810: bool ParallelCompactData::initialize_region_data(size_t region_size) duke@435: { jcoomes@810: const size_t count = (region_size + RegionSizeOffsetMask) >> Log2RegionSize; jcoomes@810: _region_vspace = create_vspace(count, sizeof(RegionData)); jcoomes@810: if (_region_vspace != 0) { jcoomes@810: _region_data = (RegionData*)_region_vspace->reserved_low_addr(); jcoomes@810: _region_count = count; duke@435: return true; duke@435: } duke@435: return false; duke@435: } duke@435: jcoomes@5201: bool ParallelCompactData::initialize_block_data() jcoomes@5201: { jcoomes@5201: assert(_region_count != 0, "region data must be initialized first"); jcoomes@5201: const size_t count = _region_count << Log2BlocksPerRegion; jcoomes@5201: _block_vspace = create_vspace(count, sizeof(BlockData)); jcoomes@5201: if (_block_vspace != 0) { jcoomes@5201: _block_data = (BlockData*)_block_vspace->reserved_low_addr(); jcoomes@5201: _block_count = count; jcoomes@5201: return true; jcoomes@5201: } jcoomes@5201: return false; jcoomes@5201: } jcoomes@5201: duke@435: void ParallelCompactData::clear() duke@435: { jcoomes@810: memset(_region_data, 0, _region_vspace->committed_size()); jcoomes@5201: memset(_block_data, 0, _block_vspace->committed_size()); duke@435: } duke@435: jcoomes@810: void ParallelCompactData::clear_range(size_t beg_region, size_t end_region) { jcoomes@810: assert(beg_region <= _region_count, "beg_region out of range"); jcoomes@810: assert(end_region <= _region_count, "end_region out of range"); jcoomes@5201: assert(RegionSize % BlockSize == 0, "RegionSize not a multiple of BlockSize"); jcoomes@810: jcoomes@810: const size_t region_cnt = end_region - beg_region; jcoomes@810: memset(_region_data + beg_region, 0, region_cnt * sizeof(RegionData)); jcoomes@5201: jcoomes@5201: const size_t beg_block = beg_region * BlocksPerRegion; jcoomes@5201: const size_t block_cnt = region_cnt * BlocksPerRegion; jcoomes@5201: memset(_block_data + beg_block, 0, block_cnt * sizeof(BlockData)); duke@435: } duke@435: jcoomes@810: HeapWord* ParallelCompactData::partial_obj_end(size_t region_idx) const duke@435: { jcoomes@810: const RegionData* cur_cp = region(region_idx); jcoomes@810: const RegionData* const end_cp = region(region_count() - 1); jcoomes@810: jcoomes@810: HeapWord* result = region_to_addr(region_idx); duke@435: if (cur_cp < end_cp) { duke@435: do { duke@435: result += cur_cp->partial_obj_size(); jcoomes@810: } while (cur_cp->partial_obj_size() == RegionSize && ++cur_cp < end_cp); duke@435: } duke@435: return result; duke@435: } duke@435: duke@435: void ParallelCompactData::add_obj(HeapWord* addr, size_t len) duke@435: { duke@435: const size_t obj_ofs = pointer_delta(addr, _region_start); jcoomes@810: const size_t beg_region = obj_ofs >> Log2RegionSize; jcoomes@810: const size_t end_region = (obj_ofs + len - 1) >> Log2RegionSize; duke@435: duke@435: DEBUG_ONLY(Atomic::inc_ptr(&add_obj_count);) duke@435: DEBUG_ONLY(Atomic::add_ptr(len, &add_obj_size);) duke@435: jcoomes@810: if (beg_region == end_region) { jcoomes@810: // All in one region. jcoomes@810: _region_data[beg_region].add_live_obj(len); duke@435: return; duke@435: } duke@435: jcoomes@810: // First region. jcoomes@810: const size_t beg_ofs = region_offset(addr); jcoomes@810: _region_data[beg_region].add_live_obj(RegionSize - beg_ofs); duke@435: coleenp@4037: Klass* klass = ((oop)addr)->klass(); jcoomes@810: // Middle regions--completely spanned by this object. jcoomes@810: for (size_t region = beg_region + 1; region < end_region; ++region) { jcoomes@810: _region_data[region].set_partial_obj_size(RegionSize); jcoomes@810: _region_data[region].set_partial_obj_addr(addr); duke@435: } duke@435: jcoomes@810: // Last region. jcoomes@810: const size_t end_ofs = region_offset(addr + len - 1); jcoomes@810: _region_data[end_region].set_partial_obj_size(end_ofs + 1); jcoomes@810: _region_data[end_region].set_partial_obj_addr(addr); duke@435: } duke@435: duke@435: void duke@435: ParallelCompactData::summarize_dense_prefix(HeapWord* beg, HeapWord* end) duke@435: { jcoomes@810: assert(region_offset(beg) == 0, "not RegionSize aligned"); jcoomes@810: assert(region_offset(end) == 0, "not RegionSize aligned"); jcoomes@810: jcoomes@810: size_t cur_region = addr_to_region_idx(beg); jcoomes@810: const size_t end_region = addr_to_region_idx(end); duke@435: HeapWord* addr = beg; jcoomes@810: while (cur_region < end_region) { jcoomes@810: _region_data[cur_region].set_destination(addr); jcoomes@810: _region_data[cur_region].set_destination_count(0); jcoomes@810: _region_data[cur_region].set_source_region(cur_region); jcoomes@810: _region_data[cur_region].set_data_location(addr); jcoomes@810: jcoomes@810: // Update live_obj_size so the region appears completely full. jcoomes@810: size_t live_size = RegionSize - _region_data[cur_region].partial_obj_size(); jcoomes@810: _region_data[cur_region].set_live_obj_size(live_size); jcoomes@810: jcoomes@810: ++cur_region; jcoomes@810: addr += RegionSize; duke@435: } duke@435: } duke@435: jcoomes@917: // Find the point at which a space can be split and, if necessary, record the jcoomes@917: // split point. jcoomes@917: // jcoomes@917: // If the current src region (which overflowed the destination space) doesn't jcoomes@917: // have a partial object, the split point is at the beginning of the current src jcoomes@917: // region (an "easy" split, no extra bookkeeping required). jcoomes@917: // jcoomes@917: // If the current src region has a partial object, the split point is in the jcoomes@917: // region where that partial object starts (call it the split_region). If jcoomes@917: // split_region has a partial object, then the split point is just after that jcoomes@917: // partial object (a "hard" split where we have to record the split data and jcoomes@917: // zero the partial_obj_size field). With a "hard" split, we know that the jcoomes@917: // partial_obj ends within split_region because the partial object that caused jcoomes@917: // the overflow starts in split_region. If split_region doesn't have a partial jcoomes@917: // obj, then the split is at the beginning of split_region (another "easy" jcoomes@917: // split). jcoomes@917: HeapWord* jcoomes@917: ParallelCompactData::summarize_split_space(size_t src_region, jcoomes@917: SplitInfo& split_info, jcoomes@917: HeapWord* destination, jcoomes@917: HeapWord* target_end, jcoomes@917: HeapWord** target_next) jcoomes@917: { jcoomes@917: assert(destination <= target_end, "sanity"); jcoomes@917: assert(destination + _region_data[src_region].data_size() > target_end, jcoomes@917: "region should not fit into target space"); jcoomes@1131: assert(is_region_aligned(target_end), "sanity"); jcoomes@917: jcoomes@917: size_t split_region = src_region; jcoomes@917: HeapWord* split_destination = destination; jcoomes@917: size_t partial_obj_size = _region_data[src_region].partial_obj_size(); jcoomes@917: jcoomes@917: if (destination + partial_obj_size > target_end) { jcoomes@917: // The split point is just after the partial object (if any) in the jcoomes@917: // src_region that contains the start of the object that overflowed the jcoomes@917: // destination space. jcoomes@917: // jcoomes@917: // Find the start of the "overflow" object and set split_region to the jcoomes@917: // region containing it. jcoomes@917: HeapWord* const overflow_obj = _region_data[src_region].partial_obj_addr(); jcoomes@917: split_region = addr_to_region_idx(overflow_obj); jcoomes@917: jcoomes@917: // Clear the source_region field of all destination regions whose first word jcoomes@917: // came from data after the split point (a non-null source_region field jcoomes@917: // implies a region must be filled). jcoomes@917: // jcoomes@917: // An alternative to the simple loop below: clear during post_compact(), jcoomes@917: // which uses memcpy instead of individual stores, and is easy to jcoomes@917: // parallelize. (The downside is that it clears the entire RegionData jcoomes@917: // object as opposed to just one field.) jcoomes@917: // jcoomes@917: // post_compact() would have to clear the summary data up to the highest jcoomes@917: // address that was written during the summary phase, which would be jcoomes@917: // jcoomes@917: // max(top, max(new_top, clear_top)) jcoomes@917: // jcoomes@917: // where clear_top is a new field in SpaceInfo. Would have to set clear_top jcoomes@1131: // to target_end. jcoomes@917: const RegionData* const sr = region(split_region); jcoomes@917: const size_t beg_idx = jcoomes@917: addr_to_region_idx(region_align_up(sr->destination() + jcoomes@917: sr->partial_obj_size())); jcoomes@1131: const size_t end_idx = addr_to_region_idx(target_end); jcoomes@917: jcoomes@917: if (TraceParallelOldGCSummaryPhase) { jcoomes@917: gclog_or_tty->print_cr("split: clearing source_region field in [" jcoomes@917: SIZE_FORMAT ", " SIZE_FORMAT ")", jcoomes@917: beg_idx, end_idx); jcoomes@917: } jcoomes@917: for (size_t idx = beg_idx; idx < end_idx; ++idx) { jcoomes@917: _region_data[idx].set_source_region(0); jcoomes@917: } jcoomes@917: jcoomes@917: // Set split_destination and partial_obj_size to reflect the split region. jcoomes@917: split_destination = sr->destination(); jcoomes@917: partial_obj_size = sr->partial_obj_size(); jcoomes@917: } jcoomes@917: jcoomes@917: // The split is recorded only if a partial object extends onto the region. jcoomes@917: if (partial_obj_size != 0) { jcoomes@917: _region_data[split_region].set_partial_obj_size(0); jcoomes@917: split_info.record(split_region, partial_obj_size, split_destination); jcoomes@917: } jcoomes@917: jcoomes@917: // Setup the continuation addresses. jcoomes@917: *target_next = split_destination + partial_obj_size; jcoomes@917: HeapWord* const source_next = region_to_addr(split_region) + partial_obj_size; jcoomes@917: jcoomes@917: if (TraceParallelOldGCSummaryPhase) { jcoomes@917: const char * split_type = partial_obj_size == 0 ? "easy" : "hard"; jcoomes@917: gclog_or_tty->print_cr("%s split: src=" PTR_FORMAT " src_c=" SIZE_FORMAT jcoomes@917: " pos=" SIZE_FORMAT, jcoomes@917: split_type, source_next, split_region, jcoomes@917: partial_obj_size); jcoomes@917: gclog_or_tty->print_cr("%s split: dst=" PTR_FORMAT " dst_c=" SIZE_FORMAT jcoomes@917: " tn=" PTR_FORMAT, jcoomes@917: split_type, split_destination, jcoomes@917: addr_to_region_idx(split_destination), jcoomes@917: *target_next); jcoomes@917: jcoomes@917: if (partial_obj_size != 0) { jcoomes@917: HeapWord* const po_beg = split_info.destination(); jcoomes@917: HeapWord* const po_end = po_beg + split_info.partial_obj_size(); jcoomes@917: gclog_or_tty->print_cr("%s split: " jcoomes@917: "po_beg=" PTR_FORMAT " " SIZE_FORMAT " " jcoomes@917: "po_end=" PTR_FORMAT " " SIZE_FORMAT, jcoomes@917: split_type, jcoomes@917: po_beg, addr_to_region_idx(po_beg), jcoomes@917: po_end, addr_to_region_idx(po_end)); jcoomes@917: } jcoomes@917: } jcoomes@917: jcoomes@917: return source_next; jcoomes@917: } jcoomes@917: jcoomes@917: bool ParallelCompactData::summarize(SplitInfo& split_info, duke@435: HeapWord* source_beg, HeapWord* source_end, jcoomes@917: HeapWord** source_next, jcoomes@917: HeapWord* target_beg, HeapWord* target_end, jcoomes@917: HeapWord** target_next) jcoomes@917: { duke@435: if (TraceParallelOldGCSummaryPhase) { jcoomes@917: HeapWord* const source_next_val = source_next == NULL ? NULL : *source_next; jcoomes@917: tty->print_cr("sb=" PTR_FORMAT " se=" PTR_FORMAT " sn=" PTR_FORMAT jcoomes@917: "tb=" PTR_FORMAT " te=" PTR_FORMAT " tn=" PTR_FORMAT, jcoomes@917: source_beg, source_end, source_next_val, jcoomes@917: target_beg, target_end, *target_next); duke@435: } duke@435: jcoomes@810: size_t cur_region = addr_to_region_idx(source_beg); jcoomes@810: const size_t end_region = addr_to_region_idx(region_align_up(source_end)); duke@435: duke@435: HeapWord *dest_addr = target_beg; jcoomes@810: while (cur_region < end_region) { jcoomes@917: // The destination must be set even if the region has no data. jcoomes@917: _region_data[cur_region].set_destination(dest_addr); jcoomes@917: jcoomes@810: size_t words = _region_data[cur_region].data_size(); duke@435: if (words > 0) { jcoomes@917: // If cur_region does not fit entirely into the target space, find a point jcoomes@917: // at which the source space can be 'split' so that part is copied to the jcoomes@917: // target space and the rest is copied elsewhere. jcoomes@917: if (dest_addr + words > target_end) { jcoomes@917: assert(source_next != NULL, "source_next is NULL when splitting"); jcoomes@917: *source_next = summarize_split_space(cur_region, split_info, dest_addr, jcoomes@917: target_end, target_next); jcoomes@917: return false; jcoomes@917: } jcoomes@917: jcoomes@917: // Compute the destination_count for cur_region, and if necessary, update jcoomes@917: // source_region for a destination region. The source_region field is jcoomes@917: // updated if cur_region is the first (left-most) region to be copied to a jcoomes@917: // destination region. jcoomes@917: // jcoomes@917: // The destination_count calculation is a bit subtle. A region that has jcoomes@917: // data that compacts into itself does not count itself as a destination. jcoomes@917: // This maintains the invariant that a zero count means the region is jcoomes@917: // available and can be claimed and then filled. jcoomes@917: uint destination_count = 0; jcoomes@917: if (split_info.is_split(cur_region)) { jcoomes@917: // The current region has been split: the partial object will be copied jcoomes@917: // to one destination space and the remaining data will be copied to jcoomes@917: // another destination space. Adjust the initial destination_count and, jcoomes@917: // if necessary, set the source_region field if the partial object will jcoomes@917: // cross a destination region boundary. jcoomes@917: destination_count = split_info.destination_count(); jcoomes@917: if (destination_count == 2) { jcoomes@917: size_t dest_idx = addr_to_region_idx(split_info.dest_region_addr()); jcoomes@917: _region_data[dest_idx].set_source_region(cur_region); jcoomes@917: } jcoomes@917: } jcoomes@917: duke@435: HeapWord* const last_addr = dest_addr + words - 1; jcoomes@810: const size_t dest_region_1 = addr_to_region_idx(dest_addr); jcoomes@810: const size_t dest_region_2 = addr_to_region_idx(last_addr); jcoomes@917: jcoomes@810: // Initially assume that the destination regions will be the same and duke@435: // adjust the value below if necessary. Under this assumption, if jcoomes@810: // cur_region == dest_region_2, then cur_region will be compacted jcoomes@810: // completely into itself. jcoomes@917: destination_count += cur_region == dest_region_2 ? 0 : 1; jcoomes@810: if (dest_region_1 != dest_region_2) { jcoomes@810: // Destination regions differ; adjust destination_count. duke@435: destination_count += 1; jcoomes@810: // Data from cur_region will be copied to the start of dest_region_2. jcoomes@810: _region_data[dest_region_2].set_source_region(cur_region); jcoomes@810: } else if (region_offset(dest_addr) == 0) { jcoomes@810: // Data from cur_region will be copied to the start of the destination jcoomes@810: // region. jcoomes@810: _region_data[dest_region_1].set_source_region(cur_region); duke@435: } duke@435: jcoomes@810: _region_data[cur_region].set_destination_count(destination_count); jcoomes@810: _region_data[cur_region].set_data_location(region_to_addr(cur_region)); duke@435: dest_addr += words; duke@435: } duke@435: jcoomes@810: ++cur_region; duke@435: } duke@435: duke@435: *target_next = dest_addr; duke@435: return true; duke@435: } duke@435: duke@435: HeapWord* ParallelCompactData::calc_new_pointer(HeapWord* addr) { duke@435: assert(addr != NULL, "Should detect NULL oop earlier"); jcoomes@5201: assert(PSParallelCompact::gc_heap()->is_in(addr), "not in heap"); jcoomes@5201: assert(PSParallelCompact::mark_bitmap()->is_marked(addr), "not marked"); duke@435: jcoomes@810: // Region covering the object. jcoomes@5201: RegionData* const region_ptr = addr_to_region_ptr(addr); jcoomes@810: HeapWord* result = region_ptr->destination(); jcoomes@810: jcoomes@5201: // If the entire Region is live, the new location is region->destination + the jcoomes@5201: // offset of the object within in the Region. jcoomes@5201: jcoomes@5201: // Run some performance tests to determine if this special case pays off. It jcoomes@5201: // is worth it for pointers into the dense prefix. If the optimization to jcoomes@5201: // avoid pointer updates in regions that only point to the dense prefix is jcoomes@5201: // ever implemented, this should be revisited. jcoomes@810: if (region_ptr->data_size() == RegionSize) { jcoomes@5201: result += region_offset(addr); duke@435: return result; duke@435: } duke@435: jcoomes@5201: // Otherwise, the new location is region->destination + block offset + the jcoomes@5201: // number of live words in the Block that are (a) to the left of addr and (b) jcoomes@5201: // due to objects that start in the Block. jcoomes@5201: jcoomes@5201: // Fill in the block table if necessary. This is unsynchronized, so multiple jcoomes@5201: // threads may fill the block table for a region (harmless, since it is jcoomes@5201: // idempotent). jcoomes@5201: if (!region_ptr->blocks_filled()) { jcoomes@5201: PSParallelCompact::fill_blocks(addr_to_region_idx(addr)); jcoomes@5201: region_ptr->set_blocks_filled(); jcoomes@5201: } jcoomes@5201: jcoomes@5201: HeapWord* const search_start = block_align_down(addr); jcoomes@5201: const size_t block_offset = addr_to_block_ptr(addr)->offset(); duke@435: duke@435: const ParMarkBitMap* bitmap = PSParallelCompact::mark_bitmap(); jcoomes@5201: const size_t live = bitmap->live_words_in_range(search_start, oop(addr)); jcoomes@5201: result += block_offset + live; jcoomes@5201: DEBUG_ONLY(PSParallelCompact::check_new_location(addr, result)); duke@435: return result; duke@435: } duke@435: jcoomes@5201: #ifdef ASSERT duke@435: void ParallelCompactData::verify_clear(const PSVirtualSpace* vspace) duke@435: { duke@435: const size_t* const beg = (const size_t*)vspace->committed_low_addr(); duke@435: const size_t* const end = (const size_t*)vspace->committed_high_addr(); duke@435: for (const size_t* p = beg; p < end; ++p) { duke@435: assert(*p == 0, "not zero"); duke@435: } duke@435: } duke@435: duke@435: void ParallelCompactData::verify_clear() duke@435: { jcoomes@810: verify_clear(_region_vspace); jcoomes@5201: verify_clear(_block_vspace); duke@435: } duke@435: #endif // #ifdef ASSERT duke@435: sla@5237: STWGCTimer PSParallelCompact::_gc_timer; sla@5237: ParallelOldTracer PSParallelCompact::_gc_tracer; duke@435: elapsedTimer PSParallelCompact::_accumulated_time; duke@435: unsigned int PSParallelCompact::_total_invocations = 0; duke@435: unsigned int PSParallelCompact::_maximum_compaction_gc_num = 0; duke@435: jlong PSParallelCompact::_time_of_last_gc = 0; duke@435: CollectorCounters* PSParallelCompact::_counters = NULL; duke@435: ParMarkBitMap PSParallelCompact::_mark_bitmap; duke@435: ParallelCompactData PSParallelCompact::_summary_data; duke@435: duke@435: PSParallelCompact::IsAliveClosure PSParallelCompact::_is_alive_closure; coleenp@548: coleenp@548: bool PSParallelCompact::IsAliveClosure::do_object_b(oop p) { return mark_bitmap()->is_marked(p); } coleenp@548: coleenp@548: void PSParallelCompact::KeepAliveClosure::do_oop(oop* p) { PSParallelCompact::KeepAliveClosure::do_oop_work(p); } coleenp@548: void PSParallelCompact::KeepAliveClosure::do_oop(narrowOop* p) { PSParallelCompact::KeepAliveClosure::do_oop_work(p); } coleenp@548: stefank@5011: PSParallelCompact::AdjustPointerClosure PSParallelCompact::_adjust_pointer_closure; coleenp@4037: PSParallelCompact::AdjustKlassClosure PSParallelCompact::_adjust_klass_closure; duke@435: stefank@5011: void PSParallelCompact::AdjustPointerClosure::do_oop(oop* p) { adjust_pointer(p); } stefank@5011: void PSParallelCompact::AdjustPointerClosure::do_oop(narrowOop* p) { adjust_pointer(p); } coleenp@548: jcoomes@1746: void PSParallelCompact::FollowStackClosure::do_void() { _compaction_manager->follow_marking_stacks(); } coleenp@548: coleenp@4037: void PSParallelCompact::MarkAndPushClosure::do_oop(oop* p) { coleenp@4037: mark_and_push(_compaction_manager, p); coleenp@4037: } coleenp@548: void PSParallelCompact::MarkAndPushClosure::do_oop(narrowOop* p) { mark_and_push(_compaction_manager, p); } duke@435: coleenp@4037: void PSParallelCompact::FollowKlassClosure::do_klass(Klass* klass) { coleenp@4037: klass->oops_do(_mark_and_push_closure); coleenp@4037: } coleenp@4037: void PSParallelCompact::AdjustKlassClosure::do_klass(Klass* klass) { stefank@5011: klass->oops_do(&PSParallelCompact::_adjust_pointer_closure); coleenp@4037: } coleenp@4037: duke@435: void PSParallelCompact::post_initialize() { duke@435: ParallelScavengeHeap* heap = gc_heap(); duke@435: assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity"); duke@435: duke@435: MemRegion mr = heap->reserved_region(); ysr@2651: _ref_processor = ysr@2651: new ReferenceProcessor(mr, // span ysr@2651: ParallelRefProcEnabled && (ParallelGCThreads > 1), // mt processing ysr@2651: (int) ParallelGCThreads, // mt processing degree ysr@2651: true, // mt discovery ysr@2651: (int) ParallelGCThreads, // mt discovery degree ysr@2651: true, // atomic_discovery brutisso@6719: &_is_alive_closure); // non-header is alive closure duke@435: _counters = new CollectorCounters("PSParallelCompact", 1); duke@435: duke@435: // Initialize static fields in ParCompactionManager. duke@435: ParCompactionManager::initialize(mark_bitmap()); duke@435: } duke@435: duke@435: bool PSParallelCompact::initialize() { duke@435: ParallelScavengeHeap* heap = gc_heap(); duke@435: assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity"); duke@435: MemRegion mr = heap->reserved_region(); duke@435: duke@435: // Was the old gen get allocated successfully? duke@435: if (!heap->old_gen()->is_allocated()) { duke@435: return false; duke@435: } duke@435: duke@435: initialize_space_info(); duke@435: initialize_dead_wood_limiter(); duke@435: duke@435: if (!_mark_bitmap.initialize(mr)) { tamao@5161: vm_shutdown_during_initialization( tamao@5161: err_msg("Unable to allocate " SIZE_FORMAT "KB bitmaps for parallel " tamao@5161: "garbage collection for the requested " SIZE_FORMAT "KB heap.", tamao@5161: _mark_bitmap.reserved_byte_size()/K, mr.byte_size()/K)); duke@435: return false; duke@435: } duke@435: duke@435: if (!_summary_data.initialize(mr)) { tamao@5161: vm_shutdown_during_initialization( tamao@5161: err_msg("Unable to allocate " SIZE_FORMAT "KB card tables for parallel " tamao@5161: "garbage collection for the requested " SIZE_FORMAT "KB heap.", tamao@5161: _summary_data.reserved_byte_size()/K, mr.byte_size()/K)); duke@435: return false; duke@435: } duke@435: duke@435: return true; duke@435: } duke@435: duke@435: void PSParallelCompact::initialize_space_info() duke@435: { duke@435: memset(&_space_info, 0, sizeof(_space_info)); duke@435: duke@435: ParallelScavengeHeap* heap = gc_heap(); duke@435: PSYoungGen* young_gen = heap->young_gen(); coleenp@4037: duke@435: _space_info[old_space_id].set_space(heap->old_gen()->object_space()); duke@435: _space_info[eden_space_id].set_space(young_gen->eden_space()); duke@435: _space_info[from_space_id].set_space(young_gen->from_space()); duke@435: _space_info[to_space_id].set_space(young_gen->to_space()); duke@435: duke@435: _space_info[old_space_id].set_start_array(heap->old_gen()->start_array()); duke@435: } duke@435: duke@435: void PSParallelCompact::initialize_dead_wood_limiter() duke@435: { duke@435: const size_t max = 100; duke@435: _dwl_mean = double(MIN2(ParallelOldDeadWoodLimiterMean, max)) / 100.0; duke@435: _dwl_std_dev = double(MIN2(ParallelOldDeadWoodLimiterStdDev, max)) / 100.0; duke@435: _dwl_first_term = 1.0 / (sqrt(2.0 * M_PI) * _dwl_std_dev); duke@435: DEBUG_ONLY(_dwl_initialized = true;) duke@435: _dwl_adjustment = normal_distribution(1.0); duke@435: } duke@435: duke@435: // Simple class for storing info about the heap at the start of GC, to be used duke@435: // after GC for comparison/printing. duke@435: class PreGCValues { duke@435: public: duke@435: PreGCValues() { } duke@435: PreGCValues(ParallelScavengeHeap* heap) { fill(heap); } duke@435: duke@435: void fill(ParallelScavengeHeap* heap) { duke@435: _heap_used = heap->used(); duke@435: _young_gen_used = heap->young_gen()->used_in_bytes(); duke@435: _old_gen_used = heap->old_gen()->used_in_bytes(); ehelin@6609: _metadata_used = MetaspaceAux::used_bytes(); duke@435: }; duke@435: duke@435: size_t heap_used() const { return _heap_used; } duke@435: size_t young_gen_used() const { return _young_gen_used; } duke@435: size_t old_gen_used() const { return _old_gen_used; } coleenp@4037: size_t metadata_used() const { return _metadata_used; } duke@435: duke@435: private: duke@435: size_t _heap_used; duke@435: size_t _young_gen_used; duke@435: size_t _old_gen_used; coleenp@4037: size_t _metadata_used; duke@435: }; duke@435: duke@435: void duke@435: PSParallelCompact::clear_data_covering_space(SpaceId id) duke@435: { duke@435: // At this point, top is the value before GC, new_top() is the value that will duke@435: // be set at the end of GC. The marking bitmap is cleared to top; nothing duke@435: // should be marked above top. The summary data is cleared to the larger of duke@435: // top & new_top. duke@435: MutableSpace* const space = _space_info[id].space(); duke@435: HeapWord* const bot = space->bottom(); duke@435: HeapWord* const top = space->top(); duke@435: HeapWord* const max_top = MAX2(top, _space_info[id].new_top()); duke@435: duke@435: const idx_t beg_bit = _mark_bitmap.addr_to_bit(bot); duke@435: const idx_t end_bit = BitMap::word_align_up(_mark_bitmap.addr_to_bit(top)); duke@435: _mark_bitmap.clear_range(beg_bit, end_bit); duke@435: jcoomes@810: const size_t beg_region = _summary_data.addr_to_region_idx(bot); jcoomes@810: const size_t end_region = jcoomes@810: _summary_data.addr_to_region_idx(_summary_data.region_align_up(max_top)); jcoomes@810: _summary_data.clear_range(beg_region, end_region); jcoomes@917: jcoomes@917: // Clear the data used to 'split' regions. jcoomes@917: SplitInfo& split_info = _space_info[id].split_info(); jcoomes@917: if (split_info.is_valid()) { jcoomes@917: split_info.clear(); jcoomes@917: } jcoomes@917: DEBUG_ONLY(split_info.verify_clear();) duke@435: } duke@435: duke@435: void PSParallelCompact::pre_compact(PreGCValues* pre_gc_values) duke@435: { duke@435: // Update the from & to space pointers in space_info, since they are swapped duke@435: // at each young gen gc. Do the update unconditionally (even though a duke@435: // promotion failure does not swap spaces) because an unknown number of minor duke@435: // collections will have swapped the spaces an unknown number of times. brutisso@6904: GCTraceTime tm("pre compact", print_phases(), true, &_gc_timer, _gc_tracer.gc_id()); duke@435: ParallelScavengeHeap* heap = gc_heap(); duke@435: _space_info[from_space_id].set_space(heap->young_gen()->from_space()); duke@435: _space_info[to_space_id].set_space(heap->young_gen()->to_space()); duke@435: duke@435: pre_gc_values->fill(heap); duke@435: duke@435: DEBUG_ONLY(add_obj_count = add_obj_size = 0;) duke@435: DEBUG_ONLY(mark_bitmap_count = mark_bitmap_size = 0;) duke@435: duke@435: // Increment the invocation count apetrusenko@574: heap->increment_total_collections(true); duke@435: duke@435: // We need to track unique mark sweep invocations as well. duke@435: _total_invocations++; duke@435: never@3499: heap->print_heap_before_gc(); sla@5237: heap->trace_heap_before_gc(&_gc_tracer); duke@435: duke@435: // Fill in TLABs duke@435: heap->accumulate_statistics_all_tlabs(); duke@435: heap->ensure_parsability(true); // retire TLABs duke@435: duke@435: if (VerifyBeforeGC && heap->total_collections() >= VerifyGCStartAt) { duke@435: HandleMark hm; // Discard invalid handles created during verification stefank@5018: Universe::verify(" VerifyBeforeGC:"); duke@435: } duke@435: duke@435: // Verify object start arrays duke@435: if (VerifyObjectStartArray && duke@435: VerifyBeforeGC) { duke@435: heap->old_gen()->verify_object_start_array(); duke@435: } duke@435: duke@435: DEBUG_ONLY(mark_bitmap()->verify_clear();) duke@435: DEBUG_ONLY(summary_data().verify_clear();) jcoomes@645: jcoomes@645: // Have worker threads release resources the next time they run a task. jcoomes@645: gc_task_manager()->release_all_resources(); duke@435: } duke@435: duke@435: void PSParallelCompact::post_compact() duke@435: { brutisso@6904: GCTraceTime tm("post compact", print_phases(), true, &_gc_timer, _gc_tracer.gc_id()); duke@435: coleenp@4037: for (unsigned int id = old_space_id; id < last_space_id; ++id) { jcoomes@917: // Clear the marking bitmap, summary data and split info. duke@435: clear_data_covering_space(SpaceId(id)); jcoomes@917: // Update top(). Must be done after clearing the bitmap and summary data. jcoomes@917: _space_info[id].publish_new_top(); duke@435: } duke@435: duke@435: MutableSpace* const eden_space = _space_info[eden_space_id].space(); duke@435: MutableSpace* const from_space = _space_info[from_space_id].space(); duke@435: MutableSpace* const to_space = _space_info[to_space_id].space(); duke@435: duke@435: ParallelScavengeHeap* heap = gc_heap(); duke@435: bool eden_empty = eden_space->is_empty(); duke@435: if (!eden_empty) { duke@435: eden_empty = absorb_live_data_from_eden(heap->size_policy(), duke@435: heap->young_gen(), heap->old_gen()); duke@435: } duke@435: duke@435: // Update heap occupancy information which is used as input to the soft ref duke@435: // clearing policy at the next gc. duke@435: Universe::update_heap_info_at_gc(); duke@435: duke@435: bool young_gen_empty = eden_empty && from_space->is_empty() && duke@435: to_space->is_empty(); duke@435: duke@435: BarrierSet* bs = heap->barrier_set(); duke@435: if (bs->is_a(BarrierSet::ModRef)) { duke@435: ModRefBarrierSet* modBS = (ModRefBarrierSet*)bs; duke@435: MemRegion old_mr = heap->old_gen()->reserved(); duke@435: duke@435: if (young_gen_empty) { coleenp@4037: modBS->clear(MemRegion(old_mr.start(), old_mr.end())); duke@435: } else { coleenp@4037: modBS->invalidate(MemRegion(old_mr.start(), old_mr.end())); duke@435: } duke@435: } duke@435: coleenp@4037: // Delete metaspaces for unloaded class loaders and clean up loader_data graph coleenp@4037: ClassLoaderDataGraph::purge(); jmasa@5015: MetaspaceAux::verify_metrics(); coleenp@4037: duke@435: Threads::gc_epilogue(); duke@435: CodeCache::gc_epilogue(); kamg@2467: JvmtiExport::gc_epilogue(); duke@435: duke@435: COMPILER2_PRESENT(DerivedPointerTable::update_pointers()); duke@435: duke@435: ref_processor()->enqueue_discovered_references(NULL); duke@435: jmasa@698: if (ZapUnusedHeapArea) { jmasa@698: heap->gen_mangle_unused_area(); jmasa@698: } jmasa@698: duke@435: // Update time of last GC duke@435: reset_millis_since_last_gc(); duke@435: } duke@435: duke@435: HeapWord* duke@435: PSParallelCompact::compute_dense_prefix_via_density(const SpaceId id, duke@435: bool maximum_compaction) duke@435: { jcoomes@810: const size_t region_size = ParallelCompactData::RegionSize; duke@435: const ParallelCompactData& sd = summary_data(); duke@435: duke@435: const MutableSpace* const space = _space_info[id].space(); jcoomes@810: HeapWord* const top_aligned_up = sd.region_align_up(space->top()); jcoomes@810: const RegionData* const beg_cp = sd.addr_to_region_ptr(space->bottom()); jcoomes@810: const RegionData* const end_cp = sd.addr_to_region_ptr(top_aligned_up); jcoomes@810: jcoomes@810: // Skip full regions at the beginning of the space--they are necessarily part duke@435: // of the dense prefix. duke@435: size_t full_count = 0; jcoomes@810: const RegionData* cp; jcoomes@810: for (cp = beg_cp; cp < end_cp && cp->data_size() == region_size; ++cp) { duke@435: ++full_count; duke@435: } duke@435: duke@435: assert(total_invocations() >= _maximum_compaction_gc_num, "sanity"); duke@435: const size_t gcs_since_max = total_invocations() - _maximum_compaction_gc_num; duke@435: const bool interval_ended = gcs_since_max > HeapMaximumCompactionInterval; duke@435: if (maximum_compaction || cp == end_cp || interval_ended) { duke@435: _maximum_compaction_gc_num = total_invocations(); jcoomes@810: return sd.region_to_addr(cp); duke@435: } duke@435: duke@435: HeapWord* const new_top = _space_info[id].new_top(); duke@435: const size_t space_live = pointer_delta(new_top, space->bottom()); duke@435: const size_t space_used = space->used_in_words(); duke@435: const size_t space_capacity = space->capacity_in_words(); duke@435: duke@435: const double cur_density = double(space_live) / space_capacity; duke@435: const double deadwood_density = duke@435: (1.0 - cur_density) * (1.0 - cur_density) * cur_density * cur_density; duke@435: const size_t deadwood_goal = size_t(space_capacity * deadwood_density); duke@435: duke@435: if (TraceParallelOldGCDensePrefix) { duke@435: tty->print_cr("cur_dens=%5.3f dw_dens=%5.3f dw_goal=" SIZE_FORMAT, duke@435: cur_density, deadwood_density, deadwood_goal); duke@435: tty->print_cr("space_live=" SIZE_FORMAT " " "space_used=" SIZE_FORMAT " " duke@435: "space_cap=" SIZE_FORMAT, duke@435: space_live, space_used, duke@435: space_capacity); duke@435: } duke@435: duke@435: // XXX - Use binary search? jcoomes@810: HeapWord* dense_prefix = sd.region_to_addr(cp); jcoomes@810: const RegionData* full_cp = cp; jcoomes@810: const RegionData* const top_cp = sd.addr_to_region_ptr(space->top() - 1); duke@435: while (cp < end_cp) { jcoomes@810: HeapWord* region_destination = cp->destination(); jcoomes@810: const size_t cur_deadwood = pointer_delta(dense_prefix, region_destination); duke@435: if (TraceParallelOldGCDensePrefix && Verbose) { jcoomes@699: tty->print_cr("c#=" SIZE_FORMAT_W(4) " dst=" PTR_FORMAT " " jcoomes@699: "dp=" SIZE_FORMAT_W(8) " " "cdw=" SIZE_FORMAT_W(8), jcoomes@810: sd.region(cp), region_destination, duke@435: dense_prefix, cur_deadwood); duke@435: } duke@435: duke@435: if (cur_deadwood >= deadwood_goal) { jcoomes@810: // Found the region that has the correct amount of deadwood to the left. jcoomes@810: // This typically occurs after crossing a fairly sparse set of regions, so jcoomes@810: // iterate backwards over those sparse regions, looking for the region jcoomes@810: // that has the lowest density of live objects 'to the right.' jcoomes@810: size_t space_to_left = sd.region(cp) * region_size; duke@435: size_t live_to_left = space_to_left - cur_deadwood; duke@435: size_t space_to_right = space_capacity - space_to_left; duke@435: size_t live_to_right = space_live - live_to_left; duke@435: double density_to_right = double(live_to_right) / space_to_right; duke@435: while (cp > full_cp) { duke@435: --cp; jcoomes@810: const size_t prev_region_live_to_right = live_to_right - jcoomes@810: cp->data_size(); jcoomes@810: const size_t prev_region_space_to_right = space_to_right + region_size; jcoomes@810: double prev_region_density_to_right = jcoomes@810: double(prev_region_live_to_right) / prev_region_space_to_right; jcoomes@810: if (density_to_right <= prev_region_density_to_right) { duke@435: return dense_prefix; duke@435: } duke@435: if (TraceParallelOldGCDensePrefix && Verbose) { jcoomes@699: tty->print_cr("backing up from c=" SIZE_FORMAT_W(4) " d2r=%10.8f " jcoomes@810: "pc_d2r=%10.8f", sd.region(cp), density_to_right, jcoomes@810: prev_region_density_to_right); duke@435: } jcoomes@810: dense_prefix -= region_size; jcoomes@810: live_to_right = prev_region_live_to_right; jcoomes@810: space_to_right = prev_region_space_to_right; jcoomes@810: density_to_right = prev_region_density_to_right; duke@435: } duke@435: return dense_prefix; duke@435: } duke@435: jcoomes@810: dense_prefix += region_size; duke@435: ++cp; duke@435: } duke@435: duke@435: return dense_prefix; duke@435: } duke@435: duke@435: #ifndef PRODUCT duke@435: void PSParallelCompact::print_dense_prefix_stats(const char* const algorithm, duke@435: const SpaceId id, duke@435: const bool maximum_compaction, duke@435: HeapWord* const addr) duke@435: { jcoomes@810: const size_t region_idx = summary_data().addr_to_region_idx(addr); jcoomes@810: RegionData* const cp = summary_data().region(region_idx); duke@435: const MutableSpace* const space = _space_info[id].space(); duke@435: HeapWord* const new_top = _space_info[id].new_top(); duke@435: duke@435: const size_t space_live = pointer_delta(new_top, space->bottom()); duke@435: const size_t dead_to_left = pointer_delta(addr, cp->destination()); duke@435: const size_t space_cap = space->capacity_in_words(); duke@435: const double dead_to_left_pct = double(dead_to_left) / space_cap; duke@435: const size_t live_to_right = new_top - cp->destination(); duke@435: const size_t dead_to_right = space->top() - addr - live_to_right; duke@435: jcoomes@699: tty->print_cr("%s=" PTR_FORMAT " dpc=" SIZE_FORMAT_W(5) " " duke@435: "spl=" SIZE_FORMAT " " duke@435: "d2l=" SIZE_FORMAT " d2l%%=%6.4f " duke@435: "d2r=" SIZE_FORMAT " l2r=" SIZE_FORMAT duke@435: " ratio=%10.8f", jcoomes@810: algorithm, addr, region_idx, duke@435: space_live, duke@435: dead_to_left, dead_to_left_pct, duke@435: dead_to_right, live_to_right, duke@435: double(dead_to_right) / live_to_right); duke@435: } duke@435: #endif // #ifndef PRODUCT duke@435: duke@435: // Return a fraction indicating how much of the generation can be treated as duke@435: // "dead wood" (i.e., not reclaimed). The function uses a normal distribution duke@435: // based on the density of live objects in the generation to determine a limit, duke@435: // which is then adjusted so the return value is min_percent when the density is duke@435: // 1. duke@435: // duke@435: // The following table shows some return values for a different values of the duke@435: // standard deviation (ParallelOldDeadWoodLimiterStdDev); the mean is 0.5 and duke@435: // min_percent is 1. duke@435: // duke@435: // fraction allowed as dead wood duke@435: // ----------------------------------------------------------------- duke@435: // density std_dev=70 std_dev=75 std_dev=80 std_dev=85 std_dev=90 std_dev=95 duke@435: // ------- ---------- ---------- ---------- ---------- ---------- ---------- duke@435: // 0.00000 0.01000000 0.01000000 0.01000000 0.01000000 0.01000000 0.01000000 duke@435: // 0.05000 0.03193096 0.02836880 0.02550828 0.02319280 0.02130337 0.01974941 duke@435: // 0.10000 0.05247504 0.04547452 0.03988045 0.03537016 0.03170171 0.02869272 duke@435: // 0.15000 0.07135702 0.06111390 0.05296419 0.04641639 0.04110601 0.03676066 duke@435: // 0.20000 0.08831616 0.07509618 0.06461766 0.05622444 0.04943437 0.04388975 duke@435: // 0.25000 0.10311208 0.08724696 0.07471205 0.06469760 0.05661313 0.05002313 duke@435: // 0.30000 0.11553050 0.09741183 0.08313394 0.07175114 0.06257797 0.05511132 duke@435: // 0.35000 0.12538832 0.10545958 0.08978741 0.07731366 0.06727491 0.05911289 duke@435: // 0.40000 0.13253818 0.11128511 0.09459590 0.08132834 0.07066107 0.06199500 duke@435: // 0.45000 0.13687208 0.11481163 0.09750361 0.08375387 0.07270534 0.06373386 duke@435: // 0.50000 0.13832410 0.11599237 0.09847664 0.08456518 0.07338887 0.06431510 duke@435: // 0.55000 0.13687208 0.11481163 0.09750361 0.08375387 0.07270534 0.06373386 duke@435: // 0.60000 0.13253818 0.11128511 0.09459590 0.08132834 0.07066107 0.06199500 duke@435: // 0.65000 0.12538832 0.10545958 0.08978741 0.07731366 0.06727491 0.05911289 duke@435: // 0.70000 0.11553050 0.09741183 0.08313394 0.07175114 0.06257797 0.05511132 duke@435: // 0.75000 0.10311208 0.08724696 0.07471205 0.06469760 0.05661313 0.05002313 duke@435: // 0.80000 0.08831616 0.07509618 0.06461766 0.05622444 0.04943437 0.04388975 duke@435: // 0.85000 0.07135702 0.06111390 0.05296419 0.04641639 0.04110601 0.03676066 duke@435: // 0.90000 0.05247504 0.04547452 0.03988045 0.03537016 0.03170171 0.02869272 duke@435: // 0.95000 0.03193096 0.02836880 0.02550828 0.02319280 0.02130337 0.01974941 duke@435: // 1.00000 0.01000000 0.01000000 0.01000000 0.01000000 0.01000000 0.01000000 duke@435: duke@435: double PSParallelCompact::dead_wood_limiter(double density, size_t min_percent) duke@435: { duke@435: assert(_dwl_initialized, "uninitialized"); duke@435: duke@435: // The raw limit is the value of the normal distribution at x = density. duke@435: const double raw_limit = normal_distribution(density); duke@435: duke@435: // Adjust the raw limit so it becomes the minimum when the density is 1. duke@435: // duke@435: // First subtract the adjustment value (which is simply the precomputed value duke@435: // normal_distribution(1.0)); this yields a value of 0 when the density is 1. duke@435: // Then add the minimum value, so the minimum is returned when the density is duke@435: // 1. Finally, prevent negative values, which occur when the mean is not 0.5. duke@435: const double min = double(min_percent) / 100.0; duke@435: const double limit = raw_limit - _dwl_adjustment + min; duke@435: return MAX2(limit, 0.0); duke@435: } duke@435: jcoomes@810: ParallelCompactData::RegionData* jcoomes@810: PSParallelCompact::first_dead_space_region(const RegionData* beg, jcoomes@810: const RegionData* end) duke@435: { jcoomes@810: const size_t region_size = ParallelCompactData::RegionSize; duke@435: ParallelCompactData& sd = summary_data(); jcoomes@810: size_t left = sd.region(beg); jcoomes@810: size_t right = end > beg ? sd.region(end) - 1 : left; duke@435: duke@435: // Binary search. duke@435: while (left < right) { duke@435: // Equivalent to (left + right) / 2, but does not overflow. duke@435: const size_t middle = left + (right - left) / 2; jcoomes@810: RegionData* const middle_ptr = sd.region(middle); duke@435: HeapWord* const dest = middle_ptr->destination(); jcoomes@810: HeapWord* const addr = sd.region_to_addr(middle); duke@435: assert(dest != NULL, "sanity"); duke@435: assert(dest <= addr, "must move left"); duke@435: duke@435: if (middle > left && dest < addr) { duke@435: right = middle - 1; jcoomes@810: } else if (middle < right && middle_ptr->data_size() == region_size) { duke@435: left = middle + 1; duke@435: } else { duke@435: return middle_ptr; duke@435: } duke@435: } jcoomes@810: return sd.region(left); duke@435: } duke@435: jcoomes@810: ParallelCompactData::RegionData* jcoomes@810: PSParallelCompact::dead_wood_limit_region(const RegionData* beg, jcoomes@810: const RegionData* end, jcoomes@810: size_t dead_words) duke@435: { duke@435: ParallelCompactData& sd = summary_data(); jcoomes@810: size_t left = sd.region(beg); jcoomes@810: size_t right = end > beg ? sd.region(end) - 1 : left; duke@435: duke@435: // Binary search. duke@435: while (left < right) { duke@435: // Equivalent to (left + right) / 2, but does not overflow. duke@435: const size_t middle = left + (right - left) / 2; jcoomes@810: RegionData* const middle_ptr = sd.region(middle); duke@435: HeapWord* const dest = middle_ptr->destination(); jcoomes@810: HeapWord* const addr = sd.region_to_addr(middle); duke@435: assert(dest != NULL, "sanity"); duke@435: assert(dest <= addr, "must move left"); duke@435: duke@435: const size_t dead_to_left = pointer_delta(addr, dest); duke@435: if (middle > left && dead_to_left > dead_words) { duke@435: right = middle - 1; duke@435: } else if (middle < right && dead_to_left < dead_words) { duke@435: left = middle + 1; duke@435: } else { duke@435: return middle_ptr; duke@435: } duke@435: } jcoomes@810: return sd.region(left); duke@435: } duke@435: duke@435: // The result is valid during the summary phase, after the initial summarization duke@435: // of each space into itself, and before final summarization. duke@435: inline double jcoomes@810: PSParallelCompact::reclaimed_ratio(const RegionData* const cp, duke@435: HeapWord* const bottom, duke@435: HeapWord* const top, duke@435: HeapWord* const new_top) duke@435: { duke@435: ParallelCompactData& sd = summary_data(); duke@435: duke@435: assert(cp != NULL, "sanity"); duke@435: assert(bottom != NULL, "sanity"); duke@435: assert(top != NULL, "sanity"); duke@435: assert(new_top != NULL, "sanity"); duke@435: assert(top >= new_top, "summary data problem?"); duke@435: assert(new_top > bottom, "space is empty; should not be here"); duke@435: assert(new_top >= cp->destination(), "sanity"); jcoomes@810: assert(top >= sd.region_to_addr(cp), "sanity"); duke@435: duke@435: HeapWord* const destination = cp->destination(); duke@435: const size_t dense_prefix_live = pointer_delta(destination, bottom); duke@435: const size_t compacted_region_live = pointer_delta(new_top, destination); jcoomes@810: const size_t compacted_region_used = pointer_delta(top, jcoomes@810: sd.region_to_addr(cp)); duke@435: const size_t reclaimable = compacted_region_used - compacted_region_live; duke@435: duke@435: const double divisor = dense_prefix_live + 1.25 * compacted_region_live; duke@435: return double(reclaimable) / divisor; duke@435: } duke@435: duke@435: // Return the address of the end of the dense prefix, a.k.a. the start of the jcoomes@810: // compacted region. The address is always on a region boundary. duke@435: // jcoomes@810: // Completely full regions at the left are skipped, since no compaction can jcoomes@810: // occur in those regions. Then the maximum amount of dead wood to allow is jcoomes@810: // computed, based on the density (amount live / capacity) of the generation; jcoomes@810: // the region with approximately that amount of dead space to the left is jcoomes@810: // identified as the limit region. Regions between the last completely full jcoomes@810: // region and the limit region are scanned and the one that has the best jcoomes@810: // (maximum) reclaimed_ratio() is selected. duke@435: HeapWord* duke@435: PSParallelCompact::compute_dense_prefix(const SpaceId id, duke@435: bool maximum_compaction) duke@435: { jcoomes@918: if (ParallelOldGCSplitALot) { jcoomes@918: if (_space_info[id].dense_prefix() != _space_info[id].space()->bottom()) { jcoomes@918: // The value was chosen to provoke splitting a young gen space; use it. jcoomes@918: return _space_info[id].dense_prefix(); jcoomes@918: } jcoomes@918: } jcoomes@918: jcoomes@810: const size_t region_size = ParallelCompactData::RegionSize; duke@435: const ParallelCompactData& sd = summary_data(); duke@435: duke@435: const MutableSpace* const space = _space_info[id].space(); duke@435: HeapWord* const top = space->top(); jcoomes@810: HeapWord* const top_aligned_up = sd.region_align_up(top); duke@435: HeapWord* const new_top = _space_info[id].new_top(); jcoomes@810: HeapWord* const new_top_aligned_up = sd.region_align_up(new_top); duke@435: HeapWord* const bottom = space->bottom(); jcoomes@810: const RegionData* const beg_cp = sd.addr_to_region_ptr(bottom); jcoomes@810: const RegionData* const top_cp = sd.addr_to_region_ptr(top_aligned_up); jcoomes@810: const RegionData* const new_top_cp = jcoomes@810: sd.addr_to_region_ptr(new_top_aligned_up); jcoomes@810: jcoomes@810: // Skip full regions at the beginning of the space--they are necessarily part duke@435: // of the dense prefix. jcoomes@810: const RegionData* const full_cp = first_dead_space_region(beg_cp, new_top_cp); jcoomes@810: assert(full_cp->destination() == sd.region_to_addr(full_cp) || duke@435: space->is_empty(), "no dead space allowed to the left"); jcoomes@810: assert(full_cp->data_size() < region_size || full_cp == new_top_cp - 1, jcoomes@810: "region must have dead space"); duke@435: duke@435: // The gc number is saved whenever a maximum compaction is done, and used to duke@435: // determine when the maximum compaction interval has expired. This avoids duke@435: // successive max compactions for different reasons. duke@435: assert(total_invocations() >= _maximum_compaction_gc_num, "sanity"); duke@435: const size_t gcs_since_max = total_invocations() - _maximum_compaction_gc_num; duke@435: const bool interval_ended = gcs_since_max > HeapMaximumCompactionInterval || duke@435: total_invocations() == HeapFirstMaximumCompactionCount; duke@435: if (maximum_compaction || full_cp == top_cp || interval_ended) { duke@435: _maximum_compaction_gc_num = total_invocations(); jcoomes@810: return sd.region_to_addr(full_cp); duke@435: } duke@435: duke@435: const size_t space_live = pointer_delta(new_top, bottom); duke@435: const size_t space_used = space->used_in_words(); duke@435: const size_t space_capacity = space->capacity_in_words(); duke@435: duke@435: const double density = double(space_live) / double(space_capacity); coleenp@4037: const size_t min_percent_free = MarkSweepDeadRatio; duke@435: const double limiter = dead_wood_limiter(density, min_percent_free); duke@435: const size_t dead_wood_max = space_used - space_live; duke@435: const size_t dead_wood_limit = MIN2(size_t(space_capacity * limiter), duke@435: dead_wood_max); duke@435: duke@435: if (TraceParallelOldGCDensePrefix) { duke@435: tty->print_cr("space_live=" SIZE_FORMAT " " "space_used=" SIZE_FORMAT " " duke@435: "space_cap=" SIZE_FORMAT, duke@435: space_live, space_used, duke@435: space_capacity); duke@435: tty->print_cr("dead_wood_limiter(%6.4f, %d)=%6.4f " duke@435: "dead_wood_max=" SIZE_FORMAT " dead_wood_limit=" SIZE_FORMAT, duke@435: density, min_percent_free, limiter, duke@435: dead_wood_max, dead_wood_limit); duke@435: } duke@435: jcoomes@810: // Locate the region with the desired amount of dead space to the left. jcoomes@810: const RegionData* const limit_cp = jcoomes@810: dead_wood_limit_region(full_cp, top_cp, dead_wood_limit); jcoomes@810: jcoomes@810: // Scan from the first region with dead space to the limit region and find the duke@435: // one with the best (largest) reclaimed ratio. duke@435: double best_ratio = 0.0; jcoomes@810: const RegionData* best_cp = full_cp; jcoomes@810: for (const RegionData* cp = full_cp; cp < limit_cp; ++cp) { duke@435: double tmp_ratio = reclaimed_ratio(cp, bottom, top, new_top); duke@435: if (tmp_ratio > best_ratio) { duke@435: best_cp = cp; duke@435: best_ratio = tmp_ratio; duke@435: } duke@435: } duke@435: duke@435: #if 0 jcoomes@810: // Something to consider: if the region with the best ratio is 'close to' the jcoomes@810: // first region w/free space, choose the first region with free space jcoomes@810: // ("first-free"). The first-free region is usually near the start of the duke@435: // heap, which means we are copying most of the heap already, so copy a bit duke@435: // more to get complete compaction. jcoomes@810: if (pointer_delta(best_cp, full_cp, sizeof(RegionData)) < 4) { duke@435: _maximum_compaction_gc_num = total_invocations(); duke@435: best_cp = full_cp; duke@435: } duke@435: #endif // #if 0 duke@435: jcoomes@810: return sd.region_to_addr(best_cp); duke@435: } duke@435: jcoomes@918: #ifndef PRODUCT jcoomes@918: void jcoomes@918: PSParallelCompact::fill_with_live_objects(SpaceId id, HeapWord* const start, jcoomes@918: size_t words) jcoomes@918: { jcoomes@918: if (TraceParallelOldGCSummaryPhase) { jcoomes@918: tty->print_cr("fill_with_live_objects [" PTR_FORMAT " " PTR_FORMAT ") " jcoomes@918: SIZE_FORMAT, start, start + words, words); jcoomes@918: } jcoomes@918: jcoomes@918: ObjectStartArray* const start_array = _space_info[id].start_array(); jcoomes@918: CollectedHeap::fill_with_objects(start, words); jcoomes@918: for (HeapWord* p = start; p < start + words; p += oop(p)->size()) { jcoomes@918: _mark_bitmap.mark_obj(p, words); jcoomes@918: _summary_data.add_obj(p, words); jcoomes@918: start_array->allocate_block(p); jcoomes@918: } jcoomes@918: } jcoomes@918: jcoomes@918: void jcoomes@918: PSParallelCompact::summarize_new_objects(SpaceId id, HeapWord* start) jcoomes@918: { jcoomes@918: ParallelCompactData& sd = summary_data(); jcoomes@918: MutableSpace* space = _space_info[id].space(); jcoomes@918: jcoomes@918: // Find the source and destination start addresses. jcoomes@918: HeapWord* const src_addr = sd.region_align_down(start); jcoomes@918: HeapWord* dst_addr; jcoomes@918: if (src_addr < start) { jcoomes@918: dst_addr = sd.addr_to_region_ptr(src_addr)->destination(); jcoomes@918: } else if (src_addr > space->bottom()) { jcoomes@918: // The start (the original top() value) is aligned to a region boundary so jcoomes@918: // the associated region does not have a destination. Compute the jcoomes@918: // destination from the previous region. jcoomes@918: RegionData* const cp = sd.addr_to_region_ptr(src_addr) - 1; jcoomes@918: dst_addr = cp->destination() + cp->data_size(); jcoomes@918: } else { jcoomes@918: // Filling the entire space. jcoomes@918: dst_addr = space->bottom(); jcoomes@918: } jcoomes@918: assert(dst_addr != NULL, "sanity"); jcoomes@918: jcoomes@918: // Update the summary data. jcoomes@918: bool result = _summary_data.summarize(_space_info[id].split_info(), jcoomes@918: src_addr, space->top(), NULL, jcoomes@918: dst_addr, space->end(), jcoomes@918: _space_info[id].new_top_addr()); jcoomes@918: assert(result, "should not fail: bad filler object size"); jcoomes@918: } jcoomes@918: jcoomes@918: void jcoomes@931: PSParallelCompact::provoke_split_fill_survivor(SpaceId id) jcoomes@931: { jcoomes@931: if (total_invocations() % (ParallelOldGCSplitInterval * 3) != 0) { jcoomes@931: return; jcoomes@931: } jcoomes@931: jcoomes@931: MutableSpace* const space = _space_info[id].space(); jcoomes@931: if (space->is_empty()) { jcoomes@931: HeapWord* b = space->bottom(); jcoomes@931: HeapWord* t = b + space->capacity_in_words() / 2; jcoomes@931: space->set_top(t); jcoomes@931: if (ZapUnusedHeapArea) { jcoomes@931: space->set_top_for_allocations(); jcoomes@931: } jcoomes@931: kvn@1926: size_t min_size = CollectedHeap::min_fill_size(); kvn@1926: size_t obj_len = min_size; jcoomes@931: while (b + obj_len <= t) { jcoomes@931: CollectedHeap::fill_with_object(b, obj_len); jcoomes@931: mark_bitmap()->mark_obj(b, obj_len); jcoomes@931: summary_data().add_obj(b, obj_len); jcoomes@931: b += obj_len; kvn@1926: obj_len = (obj_len & (min_size*3)) + min_size; // 8 16 24 32 8 16 24 32 ... jcoomes@931: } jcoomes@931: if (b < t) { jcoomes@931: // The loop didn't completely fill to t (top); adjust top downward. jcoomes@931: space->set_top(b); jcoomes@931: if (ZapUnusedHeapArea) { jcoomes@931: space->set_top_for_allocations(); jcoomes@931: } jcoomes@931: } jcoomes@931: jcoomes@931: HeapWord** nta = _space_info[id].new_top_addr(); jcoomes@931: bool result = summary_data().summarize(_space_info[id].split_info(), jcoomes@931: space->bottom(), space->top(), NULL, jcoomes@931: space->bottom(), space->end(), nta); jcoomes@931: assert(result, "space must fit into itself"); jcoomes@931: } jcoomes@931: } jcoomes@931: jcoomes@931: void jcoomes@918: PSParallelCompact::provoke_split(bool & max_compaction) jcoomes@918: { jcoomes@931: if (total_invocations() % ParallelOldGCSplitInterval != 0) { jcoomes@931: return; jcoomes@931: } jcoomes@931: jcoomes@918: const size_t region_size = ParallelCompactData::RegionSize; jcoomes@918: ParallelCompactData& sd = summary_data(); jcoomes@918: jcoomes@918: MutableSpace* const eden_space = _space_info[eden_space_id].space(); jcoomes@918: MutableSpace* const from_space = _space_info[from_space_id].space(); jcoomes@918: const size_t eden_live = pointer_delta(eden_space->top(), jcoomes@918: _space_info[eden_space_id].new_top()); jcoomes@918: const size_t from_live = pointer_delta(from_space->top(), jcoomes@918: _space_info[from_space_id].new_top()); jcoomes@918: jcoomes@918: const size_t min_fill_size = CollectedHeap::min_fill_size(); jcoomes@918: const size_t eden_free = pointer_delta(eden_space->end(), eden_space->top()); jcoomes@918: const size_t eden_fillable = eden_free >= min_fill_size ? eden_free : 0; jcoomes@918: const size_t from_free = pointer_delta(from_space->end(), from_space->top()); jcoomes@918: const size_t from_fillable = from_free >= min_fill_size ? from_free : 0; jcoomes@918: jcoomes@918: // Choose the space to split; need at least 2 regions live (or fillable). jcoomes@918: SpaceId id; jcoomes@918: MutableSpace* space; jcoomes@918: size_t live_words; jcoomes@918: size_t fill_words; jcoomes@918: if (eden_live + eden_fillable >= region_size * 2) { jcoomes@918: id = eden_space_id; jcoomes@918: space = eden_space; jcoomes@918: live_words = eden_live; jcoomes@918: fill_words = eden_fillable; jcoomes@918: } else if (from_live + from_fillable >= region_size * 2) { jcoomes@918: id = from_space_id; jcoomes@918: space = from_space; jcoomes@918: live_words = from_live; jcoomes@918: fill_words = from_fillable; jcoomes@918: } else { jcoomes@918: return; // Give up. jcoomes@918: } jcoomes@918: assert(fill_words == 0 || fill_words >= min_fill_size, "sanity"); jcoomes@918: jcoomes@918: if (live_words < region_size * 2) { jcoomes@918: // Fill from top() to end() w/live objects of mixed sizes. jcoomes@918: HeapWord* const fill_start = space->top(); jcoomes@918: live_words += fill_words; jcoomes@918: jcoomes@918: space->set_top(fill_start + fill_words); jcoomes@918: if (ZapUnusedHeapArea) { jcoomes@918: space->set_top_for_allocations(); jcoomes@918: } jcoomes@918: jcoomes@918: HeapWord* cur_addr = fill_start; jcoomes@918: while (fill_words > 0) { jcoomes@918: const size_t r = (size_t)os::random() % (region_size / 2) + min_fill_size; jcoomes@918: size_t cur_size = MIN2(align_object_size_(r), fill_words); jcoomes@918: if (fill_words - cur_size < min_fill_size) { jcoomes@918: cur_size = fill_words; // Avoid leaving a fragment too small to fill. jcoomes@918: } jcoomes@918: jcoomes@918: CollectedHeap::fill_with_object(cur_addr, cur_size); jcoomes@918: mark_bitmap()->mark_obj(cur_addr, cur_size); jcoomes@918: sd.add_obj(cur_addr, cur_size); jcoomes@918: jcoomes@918: cur_addr += cur_size; jcoomes@918: fill_words -= cur_size; jcoomes@918: } jcoomes@918: jcoomes@918: summarize_new_objects(id, fill_start); jcoomes@918: } jcoomes@918: jcoomes@918: max_compaction = false; jcoomes@918: jcoomes@918: // Manipulate the old gen so that it has room for about half of the live data jcoomes@918: // in the target young gen space (live_words / 2). jcoomes@918: id = old_space_id; jcoomes@918: space = _space_info[id].space(); jcoomes@918: const size_t free_at_end = space->free_in_words(); jcoomes@918: const size_t free_target = align_object_size(live_words / 2); jcoomes@918: const size_t dead = pointer_delta(space->top(), _space_info[id].new_top()); jcoomes@918: jcoomes@918: if (free_at_end >= free_target + min_fill_size) { jcoomes@918: // Fill space above top() and set the dense prefix so everything survives. jcoomes@918: HeapWord* const fill_start = space->top(); jcoomes@918: const size_t fill_size = free_at_end - free_target; jcoomes@918: space->set_top(space->top() + fill_size); jcoomes@918: if (ZapUnusedHeapArea) { jcoomes@918: space->set_top_for_allocations(); jcoomes@918: } jcoomes@918: fill_with_live_objects(id, fill_start, fill_size); jcoomes@918: summarize_new_objects(id, fill_start); jcoomes@918: _space_info[id].set_dense_prefix(sd.region_align_down(space->top())); jcoomes@918: } else if (dead + free_at_end > free_target) { jcoomes@918: // Find a dense prefix that makes the right amount of space available. jcoomes@918: HeapWord* cur = sd.region_align_down(space->top()); jcoomes@918: HeapWord* cur_destination = sd.addr_to_region_ptr(cur)->destination(); jcoomes@918: size_t dead_to_right = pointer_delta(space->end(), cur_destination); jcoomes@918: while (dead_to_right < free_target) { jcoomes@918: cur -= region_size; jcoomes@918: cur_destination = sd.addr_to_region_ptr(cur)->destination(); jcoomes@918: dead_to_right = pointer_delta(space->end(), cur_destination); jcoomes@918: } jcoomes@918: _space_info[id].set_dense_prefix(cur); jcoomes@918: } jcoomes@918: } jcoomes@918: #endif // #ifndef PRODUCT jcoomes@918: duke@435: void PSParallelCompact::summarize_spaces_quick() duke@435: { duke@435: for (unsigned int i = 0; i < last_space_id; ++i) { duke@435: const MutableSpace* space = _space_info[i].space(); jcoomes@917: HeapWord** nta = _space_info[i].new_top_addr(); jcoomes@917: bool result = _summary_data.summarize(_space_info[i].split_info(), jcoomes@917: space->bottom(), space->top(), NULL, jcoomes@917: space->bottom(), space->end(), nta); jcoomes@917: assert(result, "space must fit into itself"); duke@435: _space_info[i].set_dense_prefix(space->bottom()); duke@435: } jcoomes@931: jcoomes@931: #ifndef PRODUCT jcoomes@931: if (ParallelOldGCSplitALot) { jcoomes@931: provoke_split_fill_survivor(to_space_id); jcoomes@931: } jcoomes@931: #endif // #ifndef PRODUCT duke@435: } duke@435: duke@435: void PSParallelCompact::fill_dense_prefix_end(SpaceId id) duke@435: { duke@435: HeapWord* const dense_prefix_end = dense_prefix(id); jcoomes@810: const RegionData* region = _summary_data.addr_to_region_ptr(dense_prefix_end); duke@435: const idx_t dense_prefix_bit = _mark_bitmap.addr_to_bit(dense_prefix_end); jcoomes@810: if (dead_space_crosses_boundary(region, dense_prefix_bit)) { duke@435: // Only enough dead space is filled so that any remaining dead space to the duke@435: // left is larger than the minimum filler object. (The remainder is filled duke@435: // during the copy/update phase.) duke@435: // duke@435: // The size of the dead space to the right of the boundary is not a duke@435: // concern, since compaction will be able to use whatever space is duke@435: // available. duke@435: // duke@435: // Here '||' is the boundary, 'x' represents a don't care bit and a box duke@435: // surrounds the space to be filled with an object. duke@435: // duke@435: // In the 32-bit VM, each bit represents two 32-bit words: duke@435: // +---+ duke@435: // a) beg_bits: ... x x x | 0 | || 0 x x ... duke@435: // end_bits: ... x x x | 0 | || 0 x x ... duke@435: // +---+ duke@435: // duke@435: // In the 64-bit VM, each bit represents one 64-bit word: duke@435: // +------------+ duke@435: // b) beg_bits: ... x x x | 0 || 0 | x x ... duke@435: // end_bits: ... x x 1 | 0 || 0 | x x ... duke@435: // +------------+ duke@435: // +-------+ duke@435: // c) beg_bits: ... x x | 0 0 | || 0 x x ... duke@435: // end_bits: ... x 1 | 0 0 | || 0 x x ... duke@435: // +-------+ duke@435: // +-----------+ duke@435: // d) beg_bits: ... x | 0 0 0 | || 0 x x ... duke@435: // end_bits: ... 1 | 0 0 0 | || 0 x x ... duke@435: // +-----------+ duke@435: // +-------+ duke@435: // e) beg_bits: ... 0 0 | 0 0 | || 0 x x ... duke@435: // end_bits: ... 0 0 | 0 0 | || 0 x x ... duke@435: // +-------+ duke@435: duke@435: // Initially assume case a, c or e will apply. kvn@1926: size_t obj_len = CollectedHeap::min_fill_size(); duke@435: HeapWord* obj_beg = dense_prefix_end - obj_len; duke@435: duke@435: #ifdef _LP64 kvn@1926: if (MinObjAlignment > 1) { // object alignment > heap word size kvn@1926: // Cases a, c or e. kvn@1926: } else if (_mark_bitmap.is_obj_end(dense_prefix_bit - 2)) { duke@435: // Case b above. duke@435: obj_beg = dense_prefix_end - 1; duke@435: } else if (!_mark_bitmap.is_obj_end(dense_prefix_bit - 3) && duke@435: _mark_bitmap.is_obj_end(dense_prefix_bit - 4)) { duke@435: // Case d above. duke@435: obj_beg = dense_prefix_end - 3; duke@435: obj_len = 3; duke@435: } duke@435: #endif // #ifdef _LP64 duke@435: jcoomes@917: CollectedHeap::fill_with_object(obj_beg, obj_len); duke@435: _mark_bitmap.mark_obj(obj_beg, obj_len); duke@435: _summary_data.add_obj(obj_beg, obj_len); duke@435: assert(start_array(id) != NULL, "sanity"); duke@435: start_array(id)->allocate_block(obj_beg); duke@435: } duke@435: } duke@435: duke@435: void jcoomes@917: PSParallelCompact::clear_source_region(HeapWord* beg_addr, HeapWord* end_addr) jcoomes@917: { jcoomes@917: RegionData* const beg_ptr = _summary_data.addr_to_region_ptr(beg_addr); jcoomes@917: HeapWord* const end_aligned_up = _summary_data.region_align_up(end_addr); jcoomes@917: RegionData* const end_ptr = _summary_data.addr_to_region_ptr(end_aligned_up); jcoomes@917: for (RegionData* cur = beg_ptr; cur < end_ptr; ++cur) { jcoomes@917: cur->set_source_region(0); jcoomes@917: } jcoomes@917: } jcoomes@917: jcoomes@917: void duke@435: PSParallelCompact::summarize_space(SpaceId id, bool maximum_compaction) duke@435: { duke@435: assert(id < last_space_id, "id out of range"); jcoomes@918: assert(_space_info[id].dense_prefix() == _space_info[id].space()->bottom() || jcoomes@918: ParallelOldGCSplitALot && id == old_space_id, jcoomes@918: "should have been reset in summarize_spaces_quick()"); duke@435: duke@435: const MutableSpace* space = _space_info[id].space(); jcoomes@700: if (_space_info[id].new_top() != space->bottom()) { jcoomes@700: HeapWord* dense_prefix_end = compute_dense_prefix(id, maximum_compaction); jcoomes@700: _space_info[id].set_dense_prefix(dense_prefix_end); duke@435: duke@435: #ifndef PRODUCT jcoomes@700: if (TraceParallelOldGCDensePrefix) { jcoomes@700: print_dense_prefix_stats("ratio", id, maximum_compaction, jcoomes@700: dense_prefix_end); jcoomes@700: HeapWord* addr = compute_dense_prefix_via_density(id, maximum_compaction); jcoomes@700: print_dense_prefix_stats("density", id, maximum_compaction, addr); jcoomes@700: } jcoomes@700: #endif // #ifndef PRODUCT jcoomes@700: jcoomes@918: // Recompute the summary data, taking into account the dense prefix. If jcoomes@918: // every last byte will be reclaimed, then the existing summary data which jcoomes@918: // compacts everything can be left in place. jcoomes@700: if (!maximum_compaction && dense_prefix_end != space->bottom()) { jcoomes@917: // If dead space crosses the dense prefix boundary, it is (at least jcoomes@917: // partially) filled with a dummy object, marked live and added to the jcoomes@917: // summary data. This simplifies the copy/update phase and must be done jcoomes@918: // before the final locations of objects are determined, to prevent jcoomes@918: // leaving a fragment of dead space that is too small to fill. jcoomes@700: fill_dense_prefix_end(id); jcoomes@917: jcoomes@917: // Compute the destination of each Region, and thus each object. jcoomes@917: _summary_data.summarize_dense_prefix(space->bottom(), dense_prefix_end); jcoomes@917: _summary_data.summarize(_space_info[id].split_info(), jcoomes@917: dense_prefix_end, space->top(), NULL, jcoomes@917: dense_prefix_end, space->end(), jcoomes@917: _space_info[id].new_top_addr()); jcoomes@700: } duke@435: } duke@435: duke@435: if (TraceParallelOldGCSummaryPhase) { jcoomes@810: const size_t region_size = ParallelCompactData::RegionSize; jcoomes@700: HeapWord* const dense_prefix_end = _space_info[id].dense_prefix(); jcoomes@810: const size_t dp_region = _summary_data.addr_to_region_idx(dense_prefix_end); duke@435: const size_t dp_words = pointer_delta(dense_prefix_end, space->bottom()); jcoomes@700: HeapWord* const new_top = _space_info[id].new_top(); jcoomes@810: const HeapWord* nt_aligned_up = _summary_data.region_align_up(new_top); duke@435: const size_t cr_words = pointer_delta(nt_aligned_up, dense_prefix_end); duke@435: tty->print_cr("id=%d cap=" SIZE_FORMAT " dp=" PTR_FORMAT " " jcoomes@810: "dp_region=" SIZE_FORMAT " " "dp_count=" SIZE_FORMAT " " duke@435: "cr_count=" SIZE_FORMAT " " "nt=" PTR_FORMAT, duke@435: id, space->capacity_in_words(), dense_prefix_end, jcoomes@810: dp_region, dp_words / region_size, jcoomes@810: cr_words / region_size, new_top); duke@435: } duke@435: } duke@435: jcoomes@917: #ifndef PRODUCT jcoomes@917: void PSParallelCompact::summary_phase_msg(SpaceId dst_space_id, jcoomes@917: HeapWord* dst_beg, HeapWord* dst_end, jcoomes@917: SpaceId src_space_id, jcoomes@917: HeapWord* src_beg, HeapWord* src_end) jcoomes@917: { jcoomes@917: if (TraceParallelOldGCSummaryPhase) { jcoomes@917: tty->print_cr("summarizing %d [%s] into %d [%s]: " jcoomes@917: "src=" PTR_FORMAT "-" PTR_FORMAT " " jcoomes@917: SIZE_FORMAT "-" SIZE_FORMAT " " jcoomes@917: "dst=" PTR_FORMAT "-" PTR_FORMAT " " jcoomes@917: SIZE_FORMAT "-" SIZE_FORMAT, jcoomes@917: src_space_id, space_names[src_space_id], jcoomes@917: dst_space_id, space_names[dst_space_id], jcoomes@917: src_beg, src_end, jcoomes@917: _summary_data.addr_to_region_idx(src_beg), jcoomes@917: _summary_data.addr_to_region_idx(src_end), jcoomes@917: dst_beg, dst_end, jcoomes@917: _summary_data.addr_to_region_idx(dst_beg), jcoomes@917: _summary_data.addr_to_region_idx(dst_end)); jcoomes@917: } jcoomes@917: } jcoomes@917: #endif // #ifndef PRODUCT jcoomes@917: duke@435: void PSParallelCompact::summary_phase(ParCompactionManager* cm, duke@435: bool maximum_compaction) duke@435: { brutisso@6904: GCTraceTime tm("summary phase", print_phases(), true, &_gc_timer, _gc_tracer.gc_id()); duke@435: // trace("2"); duke@435: duke@435: #ifdef ASSERT duke@435: if (TraceParallelOldGCMarkingPhase) { duke@435: tty->print_cr("add_obj_count=" SIZE_FORMAT " " duke@435: "add_obj_bytes=" SIZE_FORMAT, duke@435: add_obj_count, add_obj_size * HeapWordSize); duke@435: tty->print_cr("mark_bitmap_count=" SIZE_FORMAT " " duke@435: "mark_bitmap_bytes=" SIZE_FORMAT, duke@435: mark_bitmap_count, mark_bitmap_size * HeapWordSize); duke@435: } duke@435: #endif // #ifdef ASSERT duke@435: duke@435: // Quick summarization of each space into itself, to see how much is live. duke@435: summarize_spaces_quick(); duke@435: duke@435: if (TraceParallelOldGCSummaryPhase) { duke@435: tty->print_cr("summary_phase: after summarizing each space to self"); duke@435: Universe::print(); jcoomes@810: NOT_PRODUCT(print_region_ranges()); duke@435: if (Verbose) { duke@435: NOT_PRODUCT(print_initial_summary_data(_summary_data, _space_info)); duke@435: } duke@435: } duke@435: duke@435: // The amount of live data that will end up in old space (assuming it fits). duke@435: size_t old_space_total_live = 0; jcoomes@917: for (unsigned int id = old_space_id; id < last_space_id; ++id) { duke@435: old_space_total_live += pointer_delta(_space_info[id].new_top(), duke@435: _space_info[id].space()->bottom()); duke@435: } duke@435: jcoomes@917: MutableSpace* const old_space = _space_info[old_space_id].space(); jcoomes@918: const size_t old_capacity = old_space->capacity_in_words(); jcoomes@918: if (old_space_total_live > old_capacity) { duke@435: // XXX - should also try to expand duke@435: maximum_compaction = true; duke@435: } jcoomes@918: #ifndef PRODUCT jcoomes@918: if (ParallelOldGCSplitALot && old_space_total_live < old_capacity) { jcoomes@931: provoke_split(maximum_compaction); jcoomes@918: } jcoomes@918: #endif // #ifndef PRODUCT duke@435: coleenp@4037: // Old generations. duke@435: summarize_space(old_space_id, maximum_compaction); duke@435: jcoomes@917: // Summarize the remaining spaces in the young gen. The initial target space jcoomes@917: // is the old gen. If a space does not fit entirely into the target, then the jcoomes@917: // remainder is compacted into the space itself and that space becomes the new jcoomes@917: // target. jcoomes@917: SpaceId dst_space_id = old_space_id; jcoomes@917: HeapWord* dst_space_end = old_space->end(); jcoomes@917: HeapWord** new_top_addr = _space_info[dst_space_id].new_top_addr(); jcoomes@917: for (unsigned int id = eden_space_id; id < last_space_id; ++id) { duke@435: const MutableSpace* space = _space_info[id].space(); duke@435: const size_t live = pointer_delta(_space_info[id].new_top(), duke@435: space->bottom()); jcoomes@917: const size_t available = pointer_delta(dst_space_end, *new_top_addr); jcoomes@917: jcoomes@917: NOT_PRODUCT(summary_phase_msg(dst_space_id, *new_top_addr, dst_space_end, jcoomes@917: SpaceId(id), space->bottom(), space->top());) jcoomes@701: if (live > 0 && live <= available) { duke@435: // All the live data will fit. jcoomes@917: bool done = _summary_data.summarize(_space_info[id].split_info(), jcoomes@917: space->bottom(), space->top(), jcoomes@917: NULL, jcoomes@917: *new_top_addr, dst_space_end, jcoomes@917: new_top_addr); jcoomes@917: assert(done, "space must fit into old gen"); jcoomes@917: jcoomes@701: // Reset the new_top value for the space. jcoomes@701: _space_info[id].set_new_top(space->bottom()); jcoomes@917: } else if (live > 0) { jcoomes@917: // Attempt to fit part of the source space into the target space. jcoomes@917: HeapWord* next_src_addr = NULL; jcoomes@917: bool done = _summary_data.summarize(_space_info[id].split_info(), jcoomes@917: space->bottom(), space->top(), jcoomes@917: &next_src_addr, jcoomes@917: *new_top_addr, dst_space_end, jcoomes@917: new_top_addr); jcoomes@917: assert(!done, "space should not fit into old gen"); jcoomes@917: assert(next_src_addr != NULL, "sanity"); jcoomes@917: jcoomes@917: // The source space becomes the new target, so the remainder is compacted jcoomes@917: // within the space itself. jcoomes@917: dst_space_id = SpaceId(id); jcoomes@917: dst_space_end = space->end(); jcoomes@917: new_top_addr = _space_info[id].new_top_addr(); jcoomes@917: NOT_PRODUCT(summary_phase_msg(dst_space_id, jcoomes@917: space->bottom(), dst_space_end, jcoomes@917: SpaceId(id), next_src_addr, space->top());) jcoomes@917: done = _summary_data.summarize(_space_info[id].split_info(), jcoomes@917: next_src_addr, space->top(), jcoomes@917: NULL, jcoomes@917: space->bottom(), dst_space_end, jcoomes@917: new_top_addr); jcoomes@917: assert(done, "space must fit when compacted into itself"); jcoomes@917: assert(*new_top_addr <= space->top(), "usage should not grow"); duke@435: } duke@435: } duke@435: duke@435: if (TraceParallelOldGCSummaryPhase) { duke@435: tty->print_cr("summary_phase: after final summarization"); duke@435: Universe::print(); jcoomes@810: NOT_PRODUCT(print_region_ranges()); duke@435: if (Verbose) { duke@435: NOT_PRODUCT(print_generic_summary_data(_summary_data, _space_info)); duke@435: } duke@435: } duke@435: } duke@435: duke@435: // This method should contain all heap-specific policy for invoking a full duke@435: // collection. invoke_no_policy() will only attempt to compact the heap; it duke@435: // will do nothing further. If we need to bail out for policy reasons, scavenge duke@435: // before full gc, or any other specialized behavior, it needs to be added here. duke@435: // duke@435: // Note that this method should only be called from the vm_thread while at a duke@435: // safepoint. jmasa@1822: // jmasa@1822: // Note that the all_soft_refs_clear flag in the collector policy jmasa@1822: // may be true because this method can be called without intervening jmasa@1822: // activity. For example when the heap space is tight and full measure jmasa@1822: // are being taken to free space. duke@435: void PSParallelCompact::invoke(bool maximum_heap_compaction) { duke@435: assert(SafepointSynchronize::is_at_safepoint(), "should be at safepoint"); duke@435: assert(Thread::current() == (Thread*)VMThread::vm_thread(), duke@435: "should be in vm thread"); jmasa@1822: duke@435: ParallelScavengeHeap* heap = gc_heap(); duke@435: GCCause::Cause gc_cause = heap->gc_cause(); duke@435: assert(!heap->is_gc_active(), "not reentrant"); duke@435: duke@435: PSAdaptiveSizePolicy* policy = heap->size_policy(); jmasa@1822: IsGCActiveMark mark; jmasa@1822: jmasa@1822: if (ScavengeBeforeFullGC) { jmasa@1822: PSScavenge::invoke_no_policy(); duke@435: } jmasa@1822: jmasa@1822: const bool clear_all_soft_refs = jmasa@1822: heap->collector_policy()->should_clear_all_soft_refs(); jmasa@1822: jmasa@1822: PSParallelCompact::invoke_no_policy(clear_all_soft_refs || jmasa@1822: maximum_heap_compaction); duke@435: } duke@435: duke@435: // This method contains no policy. You should probably duke@435: // be calling invoke() instead. jcoomes@3540: bool PSParallelCompact::invoke_no_policy(bool maximum_heap_compaction) { duke@435: assert(SafepointSynchronize::is_at_safepoint(), "must be at a safepoint"); duke@435: assert(ref_processor() != NULL, "Sanity"); duke@435: apetrusenko@574: if (GC_locker::check_active_before_gc()) { jcoomes@3540: return false; duke@435: } duke@435: sla@5237: ParallelScavengeHeap* heap = gc_heap(); sla@5237: mgronlun@6131: _gc_timer.register_gc_start(); sla@5237: _gc_tracer.report_gc_start(heap->gc_cause(), _gc_timer.gc_start()); sla@5237: duke@435: TimeStamp marking_start; duke@435: TimeStamp compaction_start; duke@435: TimeStamp collection_exit; duke@435: duke@435: GCCause::Cause gc_cause = heap->gc_cause(); duke@435: PSYoungGen* young_gen = heap->young_gen(); duke@435: PSOldGen* old_gen = heap->old_gen(); duke@435: PSAdaptiveSizePolicy* size_policy = heap->size_policy(); duke@435: jmasa@1822: // The scope of casr should end after code that can change jmasa@1822: // CollectorPolicy::_should_clear_all_soft_refs. jmasa@1822: ClearedAllSoftRefs casr(maximum_heap_compaction, jmasa@1822: heap->collector_policy()); jmasa@1822: jmasa@698: if (ZapUnusedHeapArea) { jmasa@698: // Save information needed to minimize mangling jmasa@698: heap->record_gen_tops_before_GC(); jmasa@698: } jmasa@698: sla@5237: heap->pre_full_gc_dump(&_gc_timer); ysr@1050: duke@435: _print_phases = PrintGCDetails && PrintParallelOldGCPhaseTimes; duke@435: duke@435: // Make sure data structures are sane, make the heap parsable, and do other duke@435: // miscellaneous bookkeeping. duke@435: PreGCValues pre_gc_values; duke@435: pre_compact(&pre_gc_values); duke@435: jcoomes@645: // Get the compaction manager reserved for the VM thread. jcoomes@645: ParCompactionManager* const vmthread_cm = jcoomes@645: ParCompactionManager::manager_array(gc_task_manager()->workers()); jcoomes@645: duke@435: // Place after pre_compact() where the number of invocations is incremented. duke@435: AdaptiveSizePolicyOutput(size_policy, heap->total_collections()); duke@435: duke@435: { duke@435: ResourceMark rm; duke@435: HandleMark hm; duke@435: jmasa@3294: // Set the number of GC threads to be used in this collection jmasa@3294: gc_task_manager()->set_active_gang(); jmasa@3294: gc_task_manager()->task_idle_workers(); jmasa@3294: heap->set_par_threads(gc_task_manager()->active_workers()); jmasa@3294: duke@435: gclog_or_tty->date_stamp(PrintGC && PrintGCDateStamps); duke@435: TraceCPUTime tcpu(PrintGCDetails, true, gclog_or_tty); brutisso@6904: GCTraceTime t1(GCCauseString("Full GC", gc_cause), PrintGC, !PrintGCDetails, NULL, _gc_tracer.gc_id()); duke@435: TraceCollectorStats tcs(counters()); fparain@2888: TraceMemoryManagerStats tms(true /* Full GC */,gc_cause); duke@435: duke@435: if (TraceGen1Time) accumulated_time()->start(); duke@435: duke@435: // Let the size policy know we're starting duke@435: size_policy->major_collection_begin(); duke@435: duke@435: CodeCache::gc_prologue(); duke@435: Threads::gc_prologue(); duke@435: duke@435: COMPILER2_PRESENT(DerivedPointerTable::clear()); duke@435: johnc@3175: ref_processor()->enable_discovery(true /*verify_disabled*/, true /*verify_no_refs*/); ysr@892: ref_processor()->setup_policy(maximum_heap_compaction); duke@435: duke@435: bool marked_for_unloading = false; duke@435: duke@435: marking_start.update(); sla@5237: marking_phase(vmthread_cm, maximum_heap_compaction, &_gc_tracer); duke@435: brutisso@3767: bool max_on_system_gc = UseMaximumCompactionOnSystemGC brutisso@3767: && gc_cause == GCCause::_java_lang_system_gc; jcoomes@645: summary_phase(vmthread_cm, maximum_heap_compaction || max_on_system_gc); duke@435: duke@435: COMPILER2_PRESENT(assert(DerivedPointerTable::is_active(), "Sanity")); duke@435: COMPILER2_PRESENT(DerivedPointerTable::set_active(false)); duke@435: duke@435: // adjust_roots() updates Universe::_intArrayKlassObj which is duke@435: // needed by the compaction for filling holes in the dense prefix. duke@435: adjust_roots(); duke@435: duke@435: compaction_start.update(); jcoomes@2783: compact(); duke@435: duke@435: // Reset the mark bitmap, summary data, and do other bookkeeping. Must be duke@435: // done before resizing. duke@435: post_compact(); duke@435: duke@435: // Let the size policy know we're done duke@435: size_policy->major_collection_end(old_gen->used_in_bytes(), gc_cause); duke@435: duke@435: if (UseAdaptiveSizePolicy) { duke@435: if (PrintAdaptiveSizePolicy) { duke@435: gclog_or_tty->print("AdaptiveSizeStart: "); duke@435: gclog_or_tty->stamp(); duke@435: gclog_or_tty->print_cr(" collection: %d ", duke@435: heap->total_collections()); duke@435: if (Verbose) { coleenp@4037: gclog_or_tty->print("old_gen_capacity: %d young_gen_capacity: %d", coleenp@4037: old_gen->capacity_in_bytes(), young_gen->capacity_in_bytes()); duke@435: } duke@435: } duke@435: duke@435: // Don't check if the size_policy is ready here. Let duke@435: // the size_policy check that internally. duke@435: if (UseAdaptiveGenerationSizePolicyAtMajorCollection && duke@435: ((gc_cause != GCCause::_java_lang_system_gc) || duke@435: UseAdaptiveSizePolicyWithSystemGC)) { duke@435: // Calculate optimal free space amounts duke@435: assert(young_gen->max_size() > duke@435: young_gen->from_space()->capacity_in_bytes() + duke@435: young_gen->to_space()->capacity_in_bytes(), duke@435: "Sizes of space in young gen are out-of-bounds"); tamao@5120: tamao@5120: size_t young_live = young_gen->used_in_bytes(); tamao@5120: size_t eden_live = young_gen->eden_space()->used_in_bytes(); tamao@5120: size_t old_live = old_gen->used_in_bytes(); tamao@5120: size_t cur_eden = young_gen->eden_space()->capacity_in_bytes(); tamao@5120: size_t max_old_gen_size = old_gen->max_gen_size(); duke@435: size_t max_eden_size = young_gen->max_size() - duke@435: young_gen->from_space()->capacity_in_bytes() - duke@435: young_gen->to_space()->capacity_in_bytes(); tamao@5120: tamao@5120: // Used for diagnostics tamao@5120: size_policy->clear_generation_free_space_flags(); tamao@5120: tamao@5192: size_policy->compute_generations_free_space(young_live, tamao@5192: eden_live, tamao@5192: old_live, tamao@5192: cur_eden, tamao@5192: max_old_gen_size, tamao@5192: max_eden_size, tamao@5192: true /* full gc*/); tamao@5120: tamao@5120: size_policy->check_gc_overhead_limit(young_live, tamao@5120: eden_live, tamao@5120: max_old_gen_size, tamao@5120: max_eden_size, tamao@5120: true /* full gc*/, tamao@5120: gc_cause, tamao@5120: heap->collector_policy()); tamao@5120: tamao@5120: size_policy->decay_supplemental_growth(true /* full gc*/); jmasa@698: jmasa@698: heap->resize_old_gen( jmasa@698: size_policy->calculated_old_free_size_in_bytes()); duke@435: duke@435: // Don't resize the young generation at an major collection. A duke@435: // desired young generation size may have been calculated but duke@435: // resizing the young generation complicates the code because the duke@435: // resizing of the old generation may have moved the boundary duke@435: // between the young generation and the old generation. Let the duke@435: // young generation resizing happen at the minor collections. duke@435: } duke@435: if (PrintAdaptiveSizePolicy) { duke@435: gclog_or_tty->print_cr("AdaptiveSizeStop: collection: %d ", duke@435: heap->total_collections()); duke@435: } duke@435: } duke@435: duke@435: if (UsePerfData) { duke@435: PSGCAdaptivePolicyCounters* const counters = heap->gc_policy_counters(); duke@435: counters->update_counters(); duke@435: counters->update_old_capacity(old_gen->capacity_in_bytes()); duke@435: counters->update_young_capacity(young_gen->capacity_in_bytes()); duke@435: } duke@435: duke@435: heap->resize_all_tlabs(); duke@435: coleenp@4037: // Resize the metaspace capactiy after a collection coleenp@4037: MetaspaceGC::compute_new_size(); duke@435: duke@435: if (TraceGen1Time) accumulated_time()->stop(); duke@435: duke@435: if (PrintGC) { duke@435: if (PrintGCDetails) { duke@435: // No GC timestamp here. This is after GC so it would be confusing. duke@435: young_gen->print_used_change(pre_gc_values.young_gen_used()); duke@435: old_gen->print_used_change(pre_gc_values.old_gen_used()); duke@435: heap->print_heap_change(pre_gc_values.heap_used()); coleenp@4037: MetaspaceAux::print_metaspace_change(pre_gc_values.metadata_used()); duke@435: } else { duke@435: heap->print_heap_change(pre_gc_values.heap_used()); duke@435: } duke@435: } duke@435: duke@435: // Track memory usage and detect low memory duke@435: MemoryService::track_memory_usage(); duke@435: heap->update_counters(); jmasa@3294: gc_task_manager()->release_idle_workers(); duke@435: } duke@435: jcoomes@2191: #ifdef ASSERT jcoomes@2191: for (size_t i = 0; i < ParallelGCThreads + 1; ++i) { jcoomes@2191: ParCompactionManager* const cm = jcoomes@2191: ParCompactionManager::manager_array(int(i)); jcoomes@2191: assert(cm->marking_stack()->is_empty(), "should be empty"); jmasa@3294: assert(ParCompactionManager::region_list(int(i))->is_empty(), "should be empty"); jcoomes@2191: } jcoomes@2191: #endif // ASSERT jcoomes@2191: duke@435: if (VerifyAfterGC && heap->total_collections() >= VerifyGCStartAt) { duke@435: HandleMark hm; // Discard invalid handles created during verification stefank@5018: Universe::verify(" VerifyAfterGC:"); duke@435: } duke@435: duke@435: // Re-verify object start arrays duke@435: if (VerifyObjectStartArray && duke@435: VerifyAfterGC) { duke@435: old_gen->verify_object_start_array(); duke@435: } duke@435: jmasa@698: if (ZapUnusedHeapArea) { jmasa@698: old_gen->object_space()->check_mangled_unused_area_complete(); jmasa@698: } jmasa@698: duke@435: NOT_PRODUCT(ref_processor()->verify_no_references_recorded()); duke@435: duke@435: collection_exit.update(); duke@435: never@3499: heap->print_heap_after_gc(); sla@5237: heap->trace_heap_after_gc(&_gc_tracer); sla@5237: duke@435: if (PrintGCTaskTimeStamps) { duke@435: gclog_or_tty->print_cr("VM-Thread " INT64_FORMAT " " INT64_FORMAT " " duke@435: INT64_FORMAT, duke@435: marking_start.ticks(), compaction_start.ticks(), duke@435: collection_exit.ticks()); duke@435: gc_task_manager()->print_task_time_stamps(); duke@435: } jmasa@981: sla@5237: heap->post_full_gc_dump(&_gc_timer); ysr@1050: jmasa@981: #ifdef TRACESPINNING jmasa@981: ParallelTaskTerminator::print_termination_counts(); jmasa@981: #endif jcoomes@3540: mgronlun@6131: _gc_timer.register_gc_end(); sla@5237: sla@5237: _gc_tracer.report_dense_prefix(dense_prefix(old_space_id)); sla@5237: _gc_tracer.report_gc_end(_gc_timer.gc_end(), _gc_timer.time_partitions()); sla@5237: jcoomes@3540: return true; duke@435: } duke@435: duke@435: bool PSParallelCompact::absorb_live_data_from_eden(PSAdaptiveSizePolicy* size_policy, duke@435: PSYoungGen* young_gen, duke@435: PSOldGen* old_gen) { duke@435: MutableSpace* const eden_space = young_gen->eden_space(); duke@435: assert(!eden_space->is_empty(), "eden must be non-empty"); duke@435: assert(young_gen->virtual_space()->alignment() == duke@435: old_gen->virtual_space()->alignment(), "alignments do not match"); duke@435: duke@435: if (!(UseAdaptiveSizePolicy && UseAdaptiveGCBoundary)) { duke@435: return false; duke@435: } duke@435: duke@435: // Both generations must be completely committed. duke@435: if (young_gen->virtual_space()->uncommitted_size() != 0) { duke@435: return false; duke@435: } duke@435: if (old_gen->virtual_space()->uncommitted_size() != 0) { duke@435: return false; duke@435: } duke@435: duke@435: // Figure out how much to take from eden. Include the average amount promoted duke@435: // in the total; otherwise the next young gen GC will simply bail out to a duke@435: // full GC. duke@435: const size_t alignment = old_gen->virtual_space()->alignment(); duke@435: const size_t eden_used = eden_space->used_in_bytes(); duke@435: const size_t promoted = (size_t)size_policy->avg_promoted()->padded_average(); duke@435: const size_t absorb_size = align_size_up(eden_used + promoted, alignment); duke@435: const size_t eden_capacity = eden_space->capacity_in_bytes(); duke@435: duke@435: if (absorb_size >= eden_capacity) { duke@435: return false; // Must leave some space in eden. duke@435: } duke@435: duke@435: const size_t new_young_size = young_gen->capacity_in_bytes() - absorb_size; duke@435: if (new_young_size < young_gen->min_gen_size()) { duke@435: return false; // Respect young gen minimum size. duke@435: } duke@435: duke@435: if (TraceAdaptiveGCBoundary && Verbose) { duke@435: gclog_or_tty->print(" absorbing " SIZE_FORMAT "K: " duke@435: "eden " SIZE_FORMAT "K->" SIZE_FORMAT "K " duke@435: "from " SIZE_FORMAT "K, to " SIZE_FORMAT "K " duke@435: "young_gen " SIZE_FORMAT "K->" SIZE_FORMAT "K ", duke@435: absorb_size / K, duke@435: eden_capacity / K, (eden_capacity - absorb_size) / K, duke@435: young_gen->from_space()->used_in_bytes() / K, duke@435: young_gen->to_space()->used_in_bytes() / K, duke@435: young_gen->capacity_in_bytes() / K, new_young_size / K); duke@435: } duke@435: duke@435: // Fill the unused part of the old gen. duke@435: MutableSpace* const old_space = old_gen->object_space(); jcoomes@916: HeapWord* const unused_start = old_space->top(); jcoomes@916: size_t const unused_words = pointer_delta(old_space->end(), unused_start); jcoomes@916: jcoomes@916: if (unused_words > 0) { jcoomes@916: if (unused_words < CollectedHeap::min_fill_size()) { jcoomes@916: return false; // If the old gen cannot be filled, must give up. jcoomes@916: } jcoomes@916: CollectedHeap::fill_with_objects(unused_start, unused_words); duke@435: } duke@435: duke@435: // Take the live data from eden and set both top and end in the old gen to duke@435: // eden top. (Need to set end because reset_after_change() mangles the region duke@435: // from end to virtual_space->high() in debug builds). duke@435: HeapWord* const new_top = eden_space->top(); duke@435: old_gen->virtual_space()->expand_into(young_gen->virtual_space(), duke@435: absorb_size); duke@435: young_gen->reset_after_change(); duke@435: old_space->set_top(new_top); duke@435: old_space->set_end(new_top); duke@435: old_gen->reset_after_change(); duke@435: duke@435: // Update the object start array for the filler object and the data from eden. duke@435: ObjectStartArray* const start_array = old_gen->start_array(); jcoomes@916: for (HeapWord* p = unused_start; p < new_top; p += oop(p)->size()) { jcoomes@916: start_array->allocate_block(p); duke@435: } duke@435: duke@435: // Could update the promoted average here, but it is not typically updated at duke@435: // full GCs and the value to use is unclear. Something like duke@435: // duke@435: // cur_promoted_avg + absorb_size / number_of_scavenges_since_last_full_gc. duke@435: duke@435: size_policy->set_bytes_absorbed_from_eden(absorb_size); duke@435: return true; duke@435: } duke@435: duke@435: GCTaskManager* const PSParallelCompact::gc_task_manager() { duke@435: assert(ParallelScavengeHeap::gc_task_manager() != NULL, duke@435: "shouldn't return NULL"); duke@435: return ParallelScavengeHeap::gc_task_manager(); duke@435: } duke@435: duke@435: void PSParallelCompact::marking_phase(ParCompactionManager* cm, sla@5237: bool maximum_heap_compaction, sla@5237: ParallelOldTracer *gc_tracer) { duke@435: // Recursively traverse all live objects and mark them brutisso@6904: GCTraceTime tm("marking phase", print_phases(), true, &_gc_timer, _gc_tracer.gc_id()); duke@435: duke@435: ParallelScavengeHeap* heap = gc_heap(); duke@435: uint parallel_gc_threads = heap->gc_task_manager()->workers(); jmasa@3294: uint active_gc_threads = heap->gc_task_manager()->active_workers(); jcoomes@810: TaskQueueSetSuper* qset = ParCompactionManager::region_array(); jmasa@3294: ParallelTaskTerminator terminator(active_gc_threads, qset); duke@435: duke@435: PSParallelCompact::MarkAndPushClosure mark_and_push_closure(cm); duke@435: PSParallelCompact::FollowStackClosure follow_stack_closure(cm); duke@435: coleenp@4037: // Need new claim bits before marking starts. coleenp@4037: ClassLoaderDataGraph::clear_claimed_marks(); coleenp@4037: duke@435: { brutisso@6904: GCTraceTime tm_m("par mark", print_phases(), true, &_gc_timer, _gc_tracer.gc_id()); sla@5237: jrose@1424: ParallelScavengeHeap::ParStrongRootsScope psrs; duke@435: duke@435: GCTaskQueue* q = GCTaskQueue::create(); duke@435: duke@435: q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::universe)); duke@435: q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::jni_handles)); duke@435: // We scan the thread roots in parallel duke@435: Threads::create_thread_roots_marking_tasks(q); duke@435: q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::object_synchronizer)); duke@435: q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::flat_profiler)); duke@435: q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::management)); duke@435: q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::system_dictionary)); stefank@5194: q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::class_loader_data)); duke@435: q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::jvmti)); jrose@1424: q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::code_cache)); duke@435: jmasa@3294: if (active_gc_threads > 1) { jmasa@3294: for (uint j = 0; j < active_gc_threads; j++) { duke@435: q->enqueue(new StealMarkingTask(&terminator)); duke@435: } duke@435: } duke@435: jmasa@3294: gc_task_manager()->execute_and_wait(q); duke@435: } duke@435: duke@435: // Process reference objects found during marking duke@435: { brutisso@6904: GCTraceTime tm_r("reference processing", print_phases(), true, &_gc_timer, _gc_tracer.gc_id()); sla@5237: sla@5237: ReferenceProcessorStats stats; duke@435: if (ref_processor()->processing_is_mt()) { duke@435: RefProcTaskExecutor task_executor; sla@5237: stats = ref_processor()->process_discovered_references( ysr@888: is_alive_closure(), &mark_and_push_closure, &follow_stack_closure, brutisso@6904: &task_executor, &_gc_timer, _gc_tracer.gc_id()); duke@435: } else { sla@5237: stats = ref_processor()->process_discovered_references( sla@5237: is_alive_closure(), &mark_and_push_closure, &follow_stack_closure, NULL, brutisso@6904: &_gc_timer, _gc_tracer.gc_id()); duke@435: } sla@5237: sla@5237: gc_tracer->report_gc_reference_stats(stats); duke@435: } duke@435: brutisso@6904: GCTraceTime tm_c("class unloading", print_phases(), true, &_gc_timer, _gc_tracer.gc_id()); stefank@5020: stefank@5020: // This is the point where the entire marking should have completed. stefank@5020: assert(cm->marking_stacks_empty(), "Marking should have completed"); stefank@5020: duke@435: // Follow system dictionary roots and unload classes. duke@435: bool purged_class = SystemDictionary::do_unloading(is_alive_closure()); duke@435: stefank@5020: // Unload nmethods. brutisso@4098: CodeCache::do_unloading(is_alive_closure(), purged_class); stefank@5020: stefank@5020: // Prune dead klasses from subklass/sibling/implementor lists. coleenp@4037: Klass::clean_weak_klass_links(is_alive_closure()); duke@435: stefank@5020: // Delete entries for dead interned strings. duke@435: StringTable::unlink(is_alive_closure()); stefank@5020: coleenp@2497: // Clean up unreferenced symbols in symbol table. coleenp@2497: SymbolTable::unlink(); sla@5237: _gc_tracer.report_object_count_after_gc(is_alive_closure()); duke@435: } duke@435: coleenp@4037: void PSParallelCompact::follow_class_loader(ParCompactionManager* cm, coleenp@4037: ClassLoaderData* cld) { coleenp@4037: PSParallelCompact::MarkAndPushClosure mark_and_push_closure(cm); coleenp@4037: PSParallelCompact::FollowKlassClosure follow_klass_closure(&mark_and_push_closure); coleenp@4037: coleenp@4037: cld->oops_do(&mark_and_push_closure, &follow_klass_closure, true); coleenp@4037: } coleenp@4037: duke@435: // This should be moved to the shared markSweep code! duke@435: class PSAlwaysTrueClosure: public BoolObjectClosure { duke@435: public: duke@435: bool do_object_b(oop p) { return true; } duke@435: }; duke@435: static PSAlwaysTrueClosure always_true; duke@435: duke@435: void PSParallelCompact::adjust_roots() { duke@435: // Adjust the pointers to reflect the new locations brutisso@6904: GCTraceTime tm("adjust roots", print_phases(), true, &_gc_timer, _gc_tracer.gc_id()); duke@435: coleenp@4037: // Need new claim bits when tracing through and adjusting pointers. coleenp@4037: ClassLoaderDataGraph::clear_claimed_marks(); coleenp@4037: duke@435: // General strong roots. stefank@5011: Universe::oops_do(adjust_pointer_closure()); stefank@5011: JNIHandles::oops_do(adjust_pointer_closure()); // Global (strong) JNI handles stefank@5011: CLDToOopClosure adjust_from_cld(adjust_pointer_closure()); stefank@5011: Threads::oops_do(adjust_pointer_closure(), &adjust_from_cld, NULL); stefank@5011: ObjectSynchronizer::oops_do(adjust_pointer_closure()); stefank@5011: FlatProfiler::oops_do(adjust_pointer_closure()); stefank@5011: Management::oops_do(adjust_pointer_closure()); stefank@5011: JvmtiExport::oops_do(adjust_pointer_closure()); stefank@5011: SystemDictionary::oops_do(adjust_pointer_closure()); stefank@5011: ClassLoaderDataGraph::oops_do(adjust_pointer_closure(), adjust_klass_closure(), true); duke@435: duke@435: // Now adjust pointers in remaining weak roots. (All of which should duke@435: // have been cleared if they pointed to non-surviving objects.) duke@435: // Global (weak) JNI handles stefank@5011: JNIHandles::weak_oops_do(&always_true, adjust_pointer_closure()); duke@435: stefank@6992: CodeBlobToOopClosure adjust_from_blobs(adjust_pointer_closure(), CodeBlobToOopClosure::FixRelocations); stefank@6992: CodeCache::blobs_do(&adjust_from_blobs); stefank@5011: StringTable::oops_do(adjust_pointer_closure()); stefank@5011: ref_processor()->weak_oops_do(adjust_pointer_closure()); duke@435: // Roots were visited so references into the young gen in roots duke@435: // may have been scanned. Process them also. duke@435: // Should the reference processor have a span that excludes duke@435: // young gen objects? stefank@5011: PSScavenge::reference_processor()->weak_oops_do(adjust_pointer_closure()); duke@435: } duke@435: jcoomes@810: void PSParallelCompact::enqueue_region_draining_tasks(GCTaskQueue* q, jcoomes@810: uint parallel_gc_threads) jcoomes@810: { brutisso@6904: GCTraceTime tm("drain task setup", print_phases(), true, &_gc_timer, _gc_tracer.gc_id()); duke@435: jmasa@3294: // Find the threads that are active jmasa@3294: unsigned int which = 0; jmasa@3294: jmasa@3294: const uint task_count = MAX2(parallel_gc_threads, 1U); jmasa@3294: for (uint j = 0; j < task_count; j++) { jmasa@2188: q->enqueue(new DrainStacksCompactionTask(j)); jmasa@3294: ParCompactionManager::verify_region_list_empty(j); jmasa@3294: // Set the region stacks variables to "no" region stack values jmasa@3294: // so that they will be recognized and needing a region stack jmasa@3294: // in the stealing tasks if they do not get one by executing jmasa@3294: // a draining stack. jmasa@3294: ParCompactionManager* cm = ParCompactionManager::manager_array(j); jmasa@3294: cm->set_region_stack(NULL); jmasa@3294: cm->set_region_stack_index((uint)max_uintx); duke@435: } jmasa@3294: ParCompactionManager::reset_recycled_stack_index(); duke@435: jcoomes@810: // Find all regions that are available (can be filled immediately) and duke@435: // distribute them to the thread stacks. The iteration is done in reverse jcoomes@810: // order (high to low) so the regions will be removed in ascending order. duke@435: duke@435: const ParallelCompactData& sd = PSParallelCompact::summary_data(); duke@435: jcoomes@810: size_t fillable_regions = 0; // A count for diagnostic purposes. jmasa@3294: // A region index which corresponds to the tasks created above. jmasa@3294: // "which" must be 0 <= which < task_count jmasa@3294: jmasa@3294: which = 0; coleenp@4037: // id + 1 is used to test termination so unsigned can coleenp@4037: // be used with an old_space_id == 0. coleenp@4037: for (unsigned int id = to_space_id; id + 1 > old_space_id; --id) { duke@435: SpaceInfo* const space_info = _space_info + id; duke@435: MutableSpace* const space = space_info->space(); duke@435: HeapWord* const new_top = space_info->new_top(); duke@435: jcoomes@810: const size_t beg_region = sd.addr_to_region_idx(space_info->dense_prefix()); jcoomes@810: const size_t end_region = jcoomes@810: sd.addr_to_region_idx(sd.region_align_up(new_top)); coleenp@4037: coleenp@4037: for (size_t cur = end_region - 1; cur + 1 > beg_region; --cur) { jcoomes@810: if (sd.region(cur)->claim_unsafe()) { jmasa@3294: ParCompactionManager::region_list_push(which, cur); duke@435: duke@435: if (TraceParallelOldGCCompactionPhase && Verbose) { jcoomes@810: const size_t count_mod_8 = fillable_regions & 7; duke@435: if (count_mod_8 == 0) gclog_or_tty->print("fillable: "); jcoomes@699: gclog_or_tty->print(" " SIZE_FORMAT_W(7), cur); duke@435: if (count_mod_8 == 7) gclog_or_tty->cr(); duke@435: } duke@435: jcoomes@810: NOT_PRODUCT(++fillable_regions;) jcoomes@810: jmasa@3294: // Assign regions to tasks in round-robin fashion. duke@435: if (++which == task_count) { jmasa@3294: assert(which <= parallel_gc_threads, jmasa@3294: "Inconsistent number of workers"); duke@435: which = 0; duke@435: } duke@435: } duke@435: } duke@435: } duke@435: duke@435: if (TraceParallelOldGCCompactionPhase) { jcoomes@810: if (Verbose && (fillable_regions & 7) != 0) gclog_or_tty->cr(); jcoomes@810: gclog_or_tty->print_cr("%u initially fillable regions", fillable_regions); duke@435: } duke@435: } duke@435: duke@435: #define PAR_OLD_DENSE_PREFIX_OVER_PARTITIONING 4 duke@435: duke@435: void PSParallelCompact::enqueue_dense_prefix_tasks(GCTaskQueue* q, duke@435: uint parallel_gc_threads) { brutisso@6904: GCTraceTime tm("dense prefix task setup", print_phases(), true, &_gc_timer, _gc_tracer.gc_id()); duke@435: duke@435: ParallelCompactData& sd = PSParallelCompact::summary_data(); duke@435: duke@435: // Iterate over all the spaces adding tasks for updating jcoomes@810: // regions in the dense prefix. Assume that 1 gc thread duke@435: // will work on opening the gaps and the remaining gc threads duke@435: // will work on the dense prefix. jcoomes@917: unsigned int space_id; jcoomes@917: for (space_id = old_space_id; space_id < last_space_id; ++ space_id) { duke@435: HeapWord* const dense_prefix_end = _space_info[space_id].dense_prefix(); duke@435: const MutableSpace* const space = _space_info[space_id].space(); duke@435: duke@435: if (dense_prefix_end == space->bottom()) { duke@435: // There is no dense prefix for this space. duke@435: continue; duke@435: } duke@435: jcoomes@810: // The dense prefix is before this region. jcoomes@810: size_t region_index_end_dense_prefix = jcoomes@810: sd.addr_to_region_idx(dense_prefix_end); jcoomes@810: RegionData* const dense_prefix_cp = jcoomes@810: sd.region(region_index_end_dense_prefix); duke@435: assert(dense_prefix_end == space->end() || duke@435: dense_prefix_cp->available() || duke@435: dense_prefix_cp->claimed(), jcoomes@810: "The region after the dense prefix should always be ready to fill"); jcoomes@810: jcoomes@810: size_t region_index_start = sd.addr_to_region_idx(space->bottom()); duke@435: duke@435: // Is there dense prefix work? jcoomes@810: size_t total_dense_prefix_regions = jcoomes@810: region_index_end_dense_prefix - region_index_start; jcoomes@810: // How many regions of the dense prefix should be given to duke@435: // each thread? jcoomes@810: if (total_dense_prefix_regions > 0) { duke@435: uint tasks_for_dense_prefix = 1; jcoomes@2783: if (total_dense_prefix_regions <= jcoomes@2783: (parallel_gc_threads * PAR_OLD_DENSE_PREFIX_OVER_PARTITIONING)) { jcoomes@2783: // Don't over partition. This assumes that jcoomes@2783: // PAR_OLD_DENSE_PREFIX_OVER_PARTITIONING is a small integer value jcoomes@2783: // so there are not many regions to process. jcoomes@2783: tasks_for_dense_prefix = parallel_gc_threads; jcoomes@2783: } else { jcoomes@2783: // Over partition jcoomes@2783: tasks_for_dense_prefix = parallel_gc_threads * jcoomes@2783: PAR_OLD_DENSE_PREFIX_OVER_PARTITIONING; duke@435: } jcoomes@810: size_t regions_per_thread = total_dense_prefix_regions / duke@435: tasks_for_dense_prefix; jcoomes@810: // Give each thread at least 1 region. jcoomes@810: if (regions_per_thread == 0) { jcoomes@810: regions_per_thread = 1; duke@435: } duke@435: duke@435: for (uint k = 0; k < tasks_for_dense_prefix; k++) { jcoomes@810: if (region_index_start >= region_index_end_dense_prefix) { duke@435: break; duke@435: } jcoomes@810: // region_index_end is not processed jcoomes@810: size_t region_index_end = MIN2(region_index_start + regions_per_thread, jcoomes@810: region_index_end_dense_prefix); jcoomes@917: q->enqueue(new UpdateDensePrefixTask(SpaceId(space_id), jcoomes@917: region_index_start, jcoomes@917: region_index_end)); jcoomes@810: region_index_start = region_index_end; duke@435: } duke@435: } duke@435: // This gets any part of the dense prefix that did not duke@435: // fit evenly. jcoomes@810: if (region_index_start < region_index_end_dense_prefix) { jcoomes@917: q->enqueue(new UpdateDensePrefixTask(SpaceId(space_id), jcoomes@917: region_index_start, jcoomes@917: region_index_end_dense_prefix)); duke@435: } jcoomes@917: } duke@435: } duke@435: jcoomes@810: void PSParallelCompact::enqueue_region_stealing_tasks( duke@435: GCTaskQueue* q, duke@435: ParallelTaskTerminator* terminator_ptr, duke@435: uint parallel_gc_threads) { brutisso@6904: GCTraceTime tm("steal task setup", print_phases(), true, &_gc_timer, _gc_tracer.gc_id()); duke@435: jcoomes@810: // Once a thread has drained it's stack, it should try to steal regions from duke@435: // other threads. duke@435: if (parallel_gc_threads > 1) { duke@435: for (uint j = 0; j < parallel_gc_threads; j++) { jcoomes@810: q->enqueue(new StealRegionCompactionTask(terminator_ptr)); duke@435: } duke@435: } duke@435: } duke@435: jcoomes@5201: #ifdef ASSERT jcoomes@5201: // Write a histogram of the number of times the block table was filled for a jcoomes@5201: // region. jcoomes@5201: void PSParallelCompact::write_block_fill_histogram(outputStream* const out) jcoomes@5201: { jcoomes@5201: if (!TraceParallelOldGCCompactionPhase) return; jcoomes@5201: jcoomes@5201: typedef ParallelCompactData::RegionData rd_t; jcoomes@5201: ParallelCompactData& sd = summary_data(); jcoomes@5201: jcoomes@5201: for (unsigned int id = old_space_id; id < last_space_id; ++id) { jcoomes@5201: MutableSpace* const spc = _space_info[id].space(); jcoomes@5201: if (spc->bottom() != spc->top()) { jcoomes@5201: const rd_t* const beg = sd.addr_to_region_ptr(spc->bottom()); jcoomes@5201: HeapWord* const top_aligned_up = sd.region_align_up(spc->top()); jcoomes@5201: const rd_t* const end = sd.addr_to_region_ptr(top_aligned_up); jcoomes@5201: jcoomes@5201: size_t histo[5] = { 0, 0, 0, 0, 0 }; jcoomes@5201: const size_t histo_len = sizeof(histo) / sizeof(size_t); jcoomes@5201: const size_t region_cnt = pointer_delta(end, beg, sizeof(rd_t)); jcoomes@5201: jcoomes@5201: for (const rd_t* cur = beg; cur < end; ++cur) { jcoomes@5201: ++histo[MIN2(cur->blocks_filled_count(), histo_len - 1)]; jcoomes@5201: } jcoomes@5201: out->print("%u %-4s" SIZE_FORMAT_W(5), id, space_names[id], region_cnt); jcoomes@5201: for (size_t i = 0; i < histo_len; ++i) { jcoomes@5201: out->print(" " SIZE_FORMAT_W(5) " %5.1f%%", jcoomes@5201: histo[i], 100.0 * histo[i] / region_cnt); jcoomes@5201: } jcoomes@5201: out->cr(); jcoomes@5201: } jcoomes@5201: } jcoomes@5201: } jcoomes@5201: #endif // #ifdef ASSERT jcoomes@5201: duke@435: void PSParallelCompact::compact() { duke@435: // trace("5"); brutisso@6904: GCTraceTime tm("compaction phase", print_phases(), true, &_gc_timer, _gc_tracer.gc_id()); duke@435: duke@435: ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap(); duke@435: assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity"); duke@435: PSOldGen* old_gen = heap->old_gen(); duke@435: old_gen->start_array()->reset(); duke@435: uint parallel_gc_threads = heap->gc_task_manager()->workers(); jmasa@3294: uint active_gc_threads = heap->gc_task_manager()->active_workers(); jcoomes@810: TaskQueueSetSuper* qset = ParCompactionManager::region_array(); jmasa@3294: ParallelTaskTerminator terminator(active_gc_threads, qset); duke@435: duke@435: GCTaskQueue* q = GCTaskQueue::create(); jmasa@3294: enqueue_region_draining_tasks(q, active_gc_threads); jmasa@3294: enqueue_dense_prefix_tasks(q, active_gc_threads); jmasa@3294: enqueue_region_stealing_tasks(q, &terminator, active_gc_threads); duke@435: duke@435: { brutisso@6904: GCTraceTime tm_pc("par compact", print_phases(), true, &_gc_timer, _gc_tracer.gc_id()); duke@435: jmasa@3294: gc_task_manager()->execute_and_wait(q); duke@435: duke@435: #ifdef ASSERT jcoomes@810: // Verify that all regions have been processed before the deferred updates. duke@435: for (unsigned int id = old_space_id; id < last_space_id; ++id) { duke@435: verify_complete(SpaceId(id)); duke@435: } duke@435: #endif duke@435: } duke@435: duke@435: { duke@435: // Update the deferred objects, if any. Any compaction manager can be used. brutisso@6904: GCTraceTime tm_du("deferred updates", print_phases(), true, &_gc_timer, _gc_tracer.gc_id()); duke@435: ParCompactionManager* cm = ParCompactionManager::manager_array(0); duke@435: for (unsigned int id = old_space_id; id < last_space_id; ++id) { duke@435: update_deferred_objects(cm, SpaceId(id)); duke@435: } duke@435: } jcoomes@5201: jcoomes@5201: DEBUG_ONLY(write_block_fill_histogram(gclog_or_tty)); duke@435: } duke@435: duke@435: #ifdef ASSERT duke@435: void PSParallelCompact::verify_complete(SpaceId space_id) { jcoomes@810: // All Regions between space bottom() to new_top() should be marked as filled jcoomes@810: // and all Regions between new_top() and top() should be available (i.e., duke@435: // should have been emptied). duke@435: ParallelCompactData& sd = summary_data(); duke@435: SpaceInfo si = _space_info[space_id]; jcoomes@810: HeapWord* new_top_addr = sd.region_align_up(si.new_top()); jcoomes@810: HeapWord* old_top_addr = sd.region_align_up(si.space()->top()); jcoomes@810: const size_t beg_region = sd.addr_to_region_idx(si.space()->bottom()); jcoomes@810: const size_t new_top_region = sd.addr_to_region_idx(new_top_addr); jcoomes@810: const size_t old_top_region = sd.addr_to_region_idx(old_top_addr); duke@435: duke@435: bool issued_a_warning = false; duke@435: jcoomes@810: size_t cur_region; jcoomes@810: for (cur_region = beg_region; cur_region < new_top_region; ++cur_region) { jcoomes@810: const RegionData* const c = sd.region(cur_region); duke@435: if (!c->completed()) { jcoomes@810: warning("region " SIZE_FORMAT " not filled: " duke@435: "destination_count=" SIZE_FORMAT, jcoomes@810: cur_region, c->destination_count()); duke@435: issued_a_warning = true; duke@435: } duke@435: } duke@435: jcoomes@810: for (cur_region = new_top_region; cur_region < old_top_region; ++cur_region) { jcoomes@810: const RegionData* const c = sd.region(cur_region); duke@435: if (!c->available()) { jcoomes@810: warning("region " SIZE_FORMAT " not empty: " duke@435: "destination_count=" SIZE_FORMAT, jcoomes@810: cur_region, c->destination_count()); duke@435: issued_a_warning = true; duke@435: } duke@435: } duke@435: duke@435: if (issued_a_warning) { jcoomes@810: print_region_ranges(); duke@435: } duke@435: } duke@435: #endif // #ifdef ASSERT duke@435: jcoomes@810: // Update interior oops in the ranges of regions [beg_region, end_region). duke@435: void duke@435: PSParallelCompact::update_and_deadwood_in_dense_prefix(ParCompactionManager* cm, duke@435: SpaceId space_id, jcoomes@810: size_t beg_region, jcoomes@810: size_t end_region) { duke@435: ParallelCompactData& sd = summary_data(); duke@435: ParMarkBitMap* const mbm = mark_bitmap(); duke@435: jcoomes@810: HeapWord* beg_addr = sd.region_to_addr(beg_region); jcoomes@810: HeapWord* const end_addr = sd.region_to_addr(end_region); jcoomes@810: assert(beg_region <= end_region, "bad region range"); duke@435: assert(end_addr <= dense_prefix(space_id), "not in the dense prefix"); duke@435: duke@435: #ifdef ASSERT jcoomes@810: // Claim the regions to avoid triggering an assert when they are marked as duke@435: // filled. jcoomes@810: for (size_t claim_region = beg_region; claim_region < end_region; ++claim_region) { jcoomes@810: assert(sd.region(claim_region)->claim_unsafe(), "claim() failed"); duke@435: } duke@435: #endif // #ifdef ASSERT duke@435: duke@435: if (beg_addr != space(space_id)->bottom()) { duke@435: // Find the first live object or block of dead space that *starts* in this jcoomes@810: // range of regions. If a partial object crosses onto the region, skip it; jcoomes@810: // it will be marked for 'deferred update' when the object head is jcoomes@810: // processed. If dead space crosses onto the region, it is also skipped; it jcoomes@810: // will be filled when the prior region is processed. If neither of those jcoomes@810: // apply, the first word in the region is the start of a live object or dead jcoomes@810: // space. duke@435: assert(beg_addr > space(space_id)->bottom(), "sanity"); jcoomes@810: const RegionData* const cp = sd.region(beg_region); duke@435: if (cp->partial_obj_size() != 0) { jcoomes@810: beg_addr = sd.partial_obj_end(beg_region); duke@435: } else if (dead_space_crosses_boundary(cp, mbm->addr_to_bit(beg_addr))) { duke@435: beg_addr = mbm->find_obj_beg(beg_addr, end_addr); duke@435: } duke@435: } duke@435: duke@435: if (beg_addr < end_addr) { jcoomes@810: // A live object or block of dead space starts in this range of Regions. duke@435: HeapWord* const dense_prefix_end = dense_prefix(space_id); duke@435: duke@435: // Create closures and iterate. duke@435: UpdateOnlyClosure update_closure(mbm, cm, space_id); duke@435: FillClosure fill_closure(cm, space_id); duke@435: ParMarkBitMap::IterationStatus status; duke@435: status = mbm->iterate(&update_closure, &fill_closure, beg_addr, end_addr, duke@435: dense_prefix_end); duke@435: if (status == ParMarkBitMap::incomplete) { duke@435: update_closure.do_addr(update_closure.source()); duke@435: } duke@435: } duke@435: jcoomes@810: // Mark the regions as filled. jcoomes@810: RegionData* const beg_cp = sd.region(beg_region); jcoomes@810: RegionData* const end_cp = sd.region(end_region); jcoomes@810: for (RegionData* cp = beg_cp; cp < end_cp; ++cp) { duke@435: cp->set_completed(); duke@435: } duke@435: } duke@435: duke@435: // Return the SpaceId for the space containing addr. If addr is not in the duke@435: // heap, last_space_id is returned. In debug mode it expects the address to be duke@435: // in the heap and asserts such. duke@435: PSParallelCompact::SpaceId PSParallelCompact::space_id(HeapWord* addr) { duke@435: assert(Universe::heap()->is_in_reserved(addr), "addr not in the heap"); duke@435: coleenp@4037: for (unsigned int id = old_space_id; id < last_space_id; ++id) { duke@435: if (_space_info[id].space()->contains(addr)) { duke@435: return SpaceId(id); duke@435: } duke@435: } duke@435: duke@435: assert(false, "no space contains the addr"); duke@435: return last_space_id; duke@435: } duke@435: duke@435: void PSParallelCompact::update_deferred_objects(ParCompactionManager* cm, duke@435: SpaceId id) { duke@435: assert(id < last_space_id, "bad space id"); duke@435: duke@435: ParallelCompactData& sd = summary_data(); duke@435: const SpaceInfo* const space_info = _space_info + id; duke@435: ObjectStartArray* const start_array = space_info->start_array(); duke@435: duke@435: const MutableSpace* const space = space_info->space(); duke@435: assert(space_info->dense_prefix() >= space->bottom(), "dense_prefix not set"); duke@435: HeapWord* const beg_addr = space_info->dense_prefix(); jcoomes@810: HeapWord* const end_addr = sd.region_align_up(space_info->new_top()); jcoomes@810: jcoomes@810: const RegionData* const beg_region = sd.addr_to_region_ptr(beg_addr); jcoomes@810: const RegionData* const end_region = sd.addr_to_region_ptr(end_addr); jcoomes@810: const RegionData* cur_region; jcoomes@810: for (cur_region = beg_region; cur_region < end_region; ++cur_region) { jcoomes@810: HeapWord* const addr = cur_region->deferred_obj_addr(); duke@435: if (addr != NULL) { duke@435: if (start_array != NULL) { duke@435: start_array->allocate_block(addr); duke@435: } duke@435: oop(addr)->update_contents(cm); duke@435: assert(oop(addr)->is_oop_or_null(), "should be an oop now"); duke@435: } duke@435: } duke@435: } duke@435: duke@435: // Skip over count live words starting from beg, and return the address of the duke@435: // next live word. Unless marked, the word corresponding to beg is assumed to duke@435: // be dead. Callers must either ensure beg does not correspond to the middle of duke@435: // an object, or account for those live words in some other way. Callers must duke@435: // also ensure that there are enough live words in the range [beg, end) to skip. duke@435: HeapWord* duke@435: PSParallelCompact::skip_live_words(HeapWord* beg, HeapWord* end, size_t count) duke@435: { duke@435: assert(count > 0, "sanity"); duke@435: duke@435: ParMarkBitMap* m = mark_bitmap(); duke@435: idx_t bits_to_skip = m->words_to_bits(count); duke@435: idx_t cur_beg = m->addr_to_bit(beg); duke@435: const idx_t search_end = BitMap::word_align_up(m->addr_to_bit(end)); duke@435: duke@435: do { duke@435: cur_beg = m->find_obj_beg(cur_beg, search_end); duke@435: idx_t cur_end = m->find_obj_end(cur_beg, search_end); duke@435: const size_t obj_bits = cur_end - cur_beg + 1; duke@435: if (obj_bits > bits_to_skip) { duke@435: return m->bit_to_addr(cur_beg + bits_to_skip); duke@435: } duke@435: bits_to_skip -= obj_bits; duke@435: cur_beg = cur_end + 1; duke@435: } while (bits_to_skip > 0); duke@435: duke@435: // Skipping the desired number of words landed just past the end of an object. duke@435: // Find the start of the next object. duke@435: cur_beg = m->find_obj_beg(cur_beg, search_end); duke@435: assert(cur_beg < m->addr_to_bit(end), "not enough live words to skip"); duke@435: return m->bit_to_addr(cur_beg); duke@435: } duke@435: jcoomes@917: HeapWord* PSParallelCompact::first_src_addr(HeapWord* const dest_addr, jcoomes@917: SpaceId src_space_id, jcoomes@917: size_t src_region_idx) duke@435: { jcoomes@917: assert(summary_data().is_region_aligned(dest_addr), "not aligned"); jcoomes@917: jcoomes@917: const SplitInfo& split_info = _space_info[src_space_id].split_info(); jcoomes@917: if (split_info.dest_region_addr() == dest_addr) { jcoomes@917: // The partial object ending at the split point contains the first word to jcoomes@917: // be copied to dest_addr. jcoomes@917: return split_info.first_src_addr(); jcoomes@917: } jcoomes@917: jcoomes@917: const ParallelCompactData& sd = summary_data(); duke@435: ParMarkBitMap* const bitmap = mark_bitmap(); jcoomes@810: const size_t RegionSize = ParallelCompactData::RegionSize; jcoomes@810: jcoomes@810: assert(sd.is_region_aligned(dest_addr), "not aligned"); jcoomes@810: const RegionData* const src_region_ptr = sd.region(src_region_idx); jcoomes@810: const size_t partial_obj_size = src_region_ptr->partial_obj_size(); jcoomes@810: HeapWord* const src_region_destination = src_region_ptr->destination(); jcoomes@810: jcoomes@810: assert(dest_addr >= src_region_destination, "wrong src region"); jcoomes@810: assert(src_region_ptr->data_size() > 0, "src region cannot be empty"); jcoomes@810: jcoomes@810: HeapWord* const src_region_beg = sd.region_to_addr(src_region_idx); jcoomes@810: HeapWord* const src_region_end = src_region_beg + RegionSize; jcoomes@810: jcoomes@810: HeapWord* addr = src_region_beg; jcoomes@810: if (dest_addr == src_region_destination) { jcoomes@810: // Return the first live word in the source region. duke@435: if (partial_obj_size == 0) { jcoomes@810: addr = bitmap->find_obj_beg(addr, src_region_end); jcoomes@810: assert(addr < src_region_end, "no objects start in src region"); duke@435: } duke@435: return addr; duke@435: } duke@435: duke@435: // Must skip some live data. jcoomes@810: size_t words_to_skip = dest_addr - src_region_destination; jcoomes@810: assert(src_region_ptr->data_size() > words_to_skip, "wrong src region"); duke@435: duke@435: if (partial_obj_size >= words_to_skip) { duke@435: // All the live words to skip are part of the partial object. duke@435: addr += words_to_skip; duke@435: if (partial_obj_size == words_to_skip) { duke@435: // Find the first live word past the partial object. jcoomes@810: addr = bitmap->find_obj_beg(addr, src_region_end); jcoomes@810: assert(addr < src_region_end, "wrong src region"); duke@435: } duke@435: return addr; duke@435: } duke@435: duke@435: // Skip over the partial object (if any). duke@435: if (partial_obj_size != 0) { duke@435: words_to_skip -= partial_obj_size; duke@435: addr += partial_obj_size; duke@435: } duke@435: jcoomes@810: // Skip over live words due to objects that start in the region. jcoomes@810: addr = skip_live_words(addr, src_region_end, words_to_skip); jcoomes@810: assert(addr < src_region_end, "wrong src region"); duke@435: return addr; duke@435: } duke@435: duke@435: void PSParallelCompact::decrement_destination_counts(ParCompactionManager* cm, jcoomes@930: SpaceId src_space_id, jcoomes@810: size_t beg_region, duke@435: HeapWord* end_addr) duke@435: { duke@435: ParallelCompactData& sd = summary_data(); jcoomes@930: jcoomes@930: #ifdef ASSERT jcoomes@930: MutableSpace* const src_space = _space_info[src_space_id].space(); jcoomes@930: HeapWord* const beg_addr = sd.region_to_addr(beg_region); jcoomes@930: assert(src_space->contains(beg_addr) || beg_addr == src_space->end(), jcoomes@930: "src_space_id does not match beg_addr"); jcoomes@930: assert(src_space->contains(end_addr) || end_addr == src_space->end(), jcoomes@930: "src_space_id does not match end_addr"); jcoomes@930: #endif // #ifdef ASSERT jcoomes@930: jcoomes@810: RegionData* const beg = sd.region(beg_region); jcoomes@930: RegionData* const end = sd.addr_to_region_ptr(sd.region_align_up(end_addr)); jcoomes@930: jcoomes@930: // Regions up to new_top() are enqueued if they become available. jcoomes@930: HeapWord* const new_top = _space_info[src_space_id].new_top(); jcoomes@930: RegionData* const enqueue_end = jcoomes@930: sd.addr_to_region_ptr(sd.region_align_up(new_top)); jcoomes@930: jcoomes@930: for (RegionData* cur = beg; cur < end; ++cur) { jcoomes@810: assert(cur->data_size() > 0, "region must have live data"); duke@435: cur->decrement_destination_count(); jcoomes@930: if (cur < enqueue_end && cur->available() && cur->claim()) { jcoomes@1993: cm->push_region(sd.region(cur)); duke@435: } duke@435: } duke@435: } duke@435: jcoomes@810: size_t PSParallelCompact::next_src_region(MoveAndUpdateClosure& closure, jcoomes@810: SpaceId& src_space_id, jcoomes@810: HeapWord*& src_space_top, jcoomes@810: HeapWord* end_addr) duke@435: { jcoomes@810: typedef ParallelCompactData::RegionData RegionData; duke@435: duke@435: ParallelCompactData& sd = PSParallelCompact::summary_data(); jcoomes@810: const size_t region_size = ParallelCompactData::RegionSize; jcoomes@810: jcoomes@810: size_t src_region_idx = 0; jcoomes@810: jcoomes@810: // Skip empty regions (if any) up to the top of the space. jcoomes@810: HeapWord* const src_aligned_up = sd.region_align_up(end_addr); jcoomes@810: RegionData* src_region_ptr = sd.addr_to_region_ptr(src_aligned_up); jcoomes@810: HeapWord* const top_aligned_up = sd.region_align_up(src_space_top); jcoomes@810: const RegionData* const top_region_ptr = jcoomes@810: sd.addr_to_region_ptr(top_aligned_up); jcoomes@810: while (src_region_ptr < top_region_ptr && src_region_ptr->data_size() == 0) { jcoomes@810: ++src_region_ptr; duke@435: } duke@435: jcoomes@810: if (src_region_ptr < top_region_ptr) { jcoomes@810: // The next source region is in the current space. Update src_region_idx jcoomes@810: // and the source address to match src_region_ptr. jcoomes@810: src_region_idx = sd.region(src_region_ptr); jcoomes@810: HeapWord* const src_region_addr = sd.region_to_addr(src_region_idx); jcoomes@810: if (src_region_addr > closure.source()) { jcoomes@810: closure.set_source(src_region_addr); duke@435: } jcoomes@810: return src_region_idx; duke@435: } duke@435: jcoomes@810: // Switch to a new source space and find the first non-empty region. duke@435: unsigned int space_id = src_space_id + 1; duke@435: assert(space_id < last_space_id, "not enough spaces"); duke@435: duke@435: HeapWord* const destination = closure.destination(); duke@435: duke@435: do { duke@435: MutableSpace* space = _space_info[space_id].space(); duke@435: HeapWord* const bottom = space->bottom(); jcoomes@810: const RegionData* const bottom_cp = sd.addr_to_region_ptr(bottom); duke@435: duke@435: // Iterate over the spaces that do not compact into themselves. duke@435: if (bottom_cp->destination() != bottom) { jcoomes@810: HeapWord* const top_aligned_up = sd.region_align_up(space->top()); jcoomes@810: const RegionData* const top_cp = sd.addr_to_region_ptr(top_aligned_up); jcoomes@810: jcoomes@810: for (const RegionData* src_cp = bottom_cp; src_cp < top_cp; ++src_cp) { duke@435: if (src_cp->live_obj_size() > 0) { duke@435: // Found it. duke@435: assert(src_cp->destination() == destination, duke@435: "first live obj in the space must match the destination"); duke@435: assert(src_cp->partial_obj_size() == 0, duke@435: "a space cannot begin with a partial obj"); duke@435: duke@435: src_space_id = SpaceId(space_id); duke@435: src_space_top = space->top(); jcoomes@810: const size_t src_region_idx = sd.region(src_cp); jcoomes@810: closure.set_source(sd.region_to_addr(src_region_idx)); jcoomes@810: return src_region_idx; duke@435: } else { duke@435: assert(src_cp->data_size() == 0, "sanity"); duke@435: } duke@435: } duke@435: } duke@435: } while (++space_id < last_space_id); duke@435: jcoomes@810: assert(false, "no source region was found"); duke@435: return 0; duke@435: } duke@435: jcoomes@810: void PSParallelCompact::fill_region(ParCompactionManager* cm, size_t region_idx) duke@435: { duke@435: typedef ParMarkBitMap::IterationStatus IterationStatus; jcoomes@810: const size_t RegionSize = ParallelCompactData::RegionSize; duke@435: ParMarkBitMap* const bitmap = mark_bitmap(); duke@435: ParallelCompactData& sd = summary_data(); jcoomes@810: RegionData* const region_ptr = sd.region(region_idx); duke@435: duke@435: // Get the items needed to construct the closure. jcoomes@810: HeapWord* dest_addr = sd.region_to_addr(region_idx); duke@435: SpaceId dest_space_id = space_id(dest_addr); duke@435: ObjectStartArray* start_array = _space_info[dest_space_id].start_array(); duke@435: HeapWord* new_top = _space_info[dest_space_id].new_top(); duke@435: assert(dest_addr < new_top, "sanity"); jcoomes@810: const size_t words = MIN2(pointer_delta(new_top, dest_addr), RegionSize); jcoomes@810: jcoomes@810: // Get the source region and related info. jcoomes@810: size_t src_region_idx = region_ptr->source_region(); jcoomes@810: SpaceId src_space_id = space_id(sd.region_to_addr(src_region_idx)); duke@435: HeapWord* src_space_top = _space_info[src_space_id].space()->top(); duke@435: duke@435: MoveAndUpdateClosure closure(bitmap, cm, start_array, dest_addr, words); jcoomes@917: closure.set_source(first_src_addr(dest_addr, src_space_id, src_region_idx)); jcoomes@810: jcoomes@810: // Adjust src_region_idx to prepare for decrementing destination counts (the jcoomes@810: // destination count is not decremented when a region is copied to itself). jcoomes@810: if (src_region_idx == region_idx) { jcoomes@810: src_region_idx += 1; duke@435: } duke@435: duke@435: if (bitmap->is_unmarked(closure.source())) { duke@435: // The first source word is in the middle of an object; copy the remainder duke@435: // of the object or as much as will fit. The fact that pointer updates were duke@435: // deferred will be noted when the object header is processed. duke@435: HeapWord* const old_src_addr = closure.source(); duke@435: closure.copy_partial_obj(); duke@435: if (closure.is_full()) { jcoomes@930: decrement_destination_counts(cm, src_space_id, src_region_idx, jcoomes@930: closure.source()); jcoomes@810: region_ptr->set_deferred_obj_addr(NULL); jcoomes@810: region_ptr->set_completed(); duke@435: return; duke@435: } duke@435: jcoomes@810: HeapWord* const end_addr = sd.region_align_down(closure.source()); jcoomes@810: if (sd.region_align_down(old_src_addr) != end_addr) { jcoomes@810: // The partial object was copied from more than one source region. jcoomes@930: decrement_destination_counts(cm, src_space_id, src_region_idx, end_addr); jcoomes@810: jcoomes@810: // Move to the next source region, possibly switching spaces as well. All duke@435: // args except end_addr may be modified. jcoomes@810: src_region_idx = next_src_region(closure, src_space_id, src_space_top, jcoomes@810: end_addr); duke@435: } duke@435: } duke@435: duke@435: do { duke@435: HeapWord* const cur_addr = closure.source(); jcoomes@810: HeapWord* const end_addr = MIN2(sd.region_align_up(cur_addr + 1), duke@435: src_space_top); duke@435: IterationStatus status = bitmap->iterate(&closure, cur_addr, end_addr); duke@435: duke@435: if (status == ParMarkBitMap::incomplete) { jcoomes@810: // The last obj that starts in the source region does not end in the jcoomes@810: // region. jcoomes@1844: assert(closure.source() < end_addr, "sanity"); duke@435: HeapWord* const obj_beg = closure.source(); duke@435: HeapWord* const range_end = MIN2(obj_beg + closure.words_remaining(), duke@435: src_space_top); duke@435: HeapWord* const obj_end = bitmap->find_obj_end(obj_beg, range_end); duke@435: if (obj_end < range_end) { duke@435: // The end was found; the entire object will fit. duke@435: status = closure.do_addr(obj_beg, bitmap->obj_size(obj_beg, obj_end)); duke@435: assert(status != ParMarkBitMap::would_overflow, "sanity"); duke@435: } else { duke@435: // The end was not found; the object will not fit. duke@435: assert(range_end < src_space_top, "obj cannot cross space boundary"); duke@435: status = ParMarkBitMap::would_overflow; duke@435: } duke@435: } duke@435: duke@435: if (status == ParMarkBitMap::would_overflow) { duke@435: // The last object did not fit. Note that interior oop updates were jcoomes@810: // deferred, then copy enough of the object to fill the region. jcoomes@810: region_ptr->set_deferred_obj_addr(closure.destination()); duke@435: status = closure.copy_until_full(); // copies from closure.source() duke@435: jcoomes@930: decrement_destination_counts(cm, src_space_id, src_region_idx, jcoomes@930: closure.source()); jcoomes@810: region_ptr->set_completed(); duke@435: return; duke@435: } duke@435: duke@435: if (status == ParMarkBitMap::full) { jcoomes@930: decrement_destination_counts(cm, src_space_id, src_region_idx, jcoomes@930: closure.source()); jcoomes@810: region_ptr->set_deferred_obj_addr(NULL); jcoomes@810: region_ptr->set_completed(); duke@435: return; duke@435: } duke@435: jcoomes@930: decrement_destination_counts(cm, src_space_id, src_region_idx, end_addr); jcoomes@810: jcoomes@810: // Move to the next source region, possibly switching spaces as well. All duke@435: // args except end_addr may be modified. jcoomes@810: src_region_idx = next_src_region(closure, src_space_id, src_space_top, jcoomes@810: end_addr); duke@435: } while (true); duke@435: } duke@435: jcoomes@5201: void PSParallelCompact::fill_blocks(size_t region_idx) jcoomes@5201: { jcoomes@5201: // Fill in the block table elements for the specified region. Each block jcoomes@5201: // table element holds the number of live words in the region that are to the jcoomes@5201: // left of the first object that starts in the block. Thus only blocks in jcoomes@5201: // which an object starts need to be filled. jcoomes@5201: // jcoomes@5201: // The algorithm scans the section of the bitmap that corresponds to the jcoomes@5201: // region, keeping a running total of the live words. When an object start is jcoomes@5201: // found, if it's the first to start in the block that contains it, the jcoomes@5201: // current total is written to the block table element. jcoomes@5201: const size_t Log2BlockSize = ParallelCompactData::Log2BlockSize; jcoomes@5201: const size_t Log2RegionSize = ParallelCompactData::Log2RegionSize; jcoomes@5201: const size_t RegionSize = ParallelCompactData::RegionSize; jcoomes@5201: jcoomes@5201: ParallelCompactData& sd = summary_data(); jcoomes@5201: const size_t partial_obj_size = sd.region(region_idx)->partial_obj_size(); jcoomes@5201: if (partial_obj_size >= RegionSize) { jcoomes@5201: return; // No objects start in this region. jcoomes@5201: } jcoomes@5201: jcoomes@5201: // Ensure the first loop iteration decides that the block has changed. jcoomes@5201: size_t cur_block = sd.block_count(); jcoomes@5201: jcoomes@5201: const ParMarkBitMap* const bitmap = mark_bitmap(); jcoomes@5201: jcoomes@5201: const size_t Log2BitsPerBlock = Log2BlockSize - LogMinObjAlignment; jcoomes@5201: assert((size_t)1 << Log2BitsPerBlock == jcoomes@5201: bitmap->words_to_bits(ParallelCompactData::BlockSize), "sanity"); jcoomes@5201: jcoomes@5201: size_t beg_bit = bitmap->words_to_bits(region_idx << Log2RegionSize); jcoomes@5201: const size_t range_end = beg_bit + bitmap->words_to_bits(RegionSize); jcoomes@5201: size_t live_bits = bitmap->words_to_bits(partial_obj_size); jcoomes@5201: beg_bit = bitmap->find_obj_beg(beg_bit + live_bits, range_end); jcoomes@5201: while (beg_bit < range_end) { jcoomes@5201: const size_t new_block = beg_bit >> Log2BitsPerBlock; jcoomes@5201: if (new_block != cur_block) { jcoomes@5201: cur_block = new_block; jcoomes@5201: sd.block(cur_block)->set_offset(bitmap->bits_to_words(live_bits)); jcoomes@5201: } jcoomes@5201: jcoomes@5201: const size_t end_bit = bitmap->find_obj_end(beg_bit, range_end); jcoomes@5201: if (end_bit < range_end - 1) { jcoomes@5201: live_bits += end_bit - beg_bit + 1; jcoomes@5201: beg_bit = bitmap->find_obj_beg(end_bit + 1, range_end); jcoomes@5201: } else { jcoomes@5201: return; jcoomes@5201: } jcoomes@5201: } jcoomes@5201: } jcoomes@5201: duke@435: void duke@435: PSParallelCompact::move_and_update(ParCompactionManager* cm, SpaceId space_id) { duke@435: const MutableSpace* sp = space(space_id); duke@435: if (sp->is_empty()) { duke@435: return; duke@435: } duke@435: duke@435: ParallelCompactData& sd = PSParallelCompact::summary_data(); duke@435: ParMarkBitMap* const bitmap = mark_bitmap(); duke@435: HeapWord* const dp_addr = dense_prefix(space_id); duke@435: HeapWord* beg_addr = sp->bottom(); duke@435: HeapWord* end_addr = sp->top(); duke@435: duke@435: assert(beg_addr <= dp_addr && dp_addr <= end_addr, "bad dense prefix"); duke@435: jcoomes@810: const size_t beg_region = sd.addr_to_region_idx(beg_addr); jcoomes@810: const size_t dp_region = sd.addr_to_region_idx(dp_addr); jcoomes@810: if (beg_region < dp_region) { jcoomes@810: update_and_deadwood_in_dense_prefix(cm, space_id, beg_region, dp_region); duke@435: } duke@435: jcoomes@810: // The destination of the first live object that starts in the region is one jcoomes@810: // past the end of the partial object entering the region (if any). jcoomes@810: HeapWord* const dest_addr = sd.partial_obj_end(dp_region); duke@435: HeapWord* const new_top = _space_info[space_id].new_top(); duke@435: assert(new_top >= dest_addr, "bad new_top value"); duke@435: const size_t words = pointer_delta(new_top, dest_addr); duke@435: duke@435: if (words > 0) { duke@435: ObjectStartArray* start_array = _space_info[space_id].start_array(); duke@435: MoveAndUpdateClosure closure(bitmap, cm, start_array, dest_addr, words); duke@435: duke@435: ParMarkBitMap::IterationStatus status; duke@435: status = bitmap->iterate(&closure, dest_addr, end_addr); duke@435: assert(status == ParMarkBitMap::full, "iteration not complete"); duke@435: assert(bitmap->find_obj_beg(closure.source(), end_addr) == end_addr, duke@435: "live objects skipped because closure is full"); duke@435: } duke@435: } duke@435: duke@435: jlong PSParallelCompact::millis_since_last_gc() { johnc@3339: // We need a monotonically non-deccreasing time in ms but johnc@3339: // os::javaTimeMillis() does not guarantee monotonicity. johnc@3339: jlong now = os::javaTimeNanos() / NANOSECS_PER_MILLISEC; johnc@3339: jlong ret_val = now - _time_of_last_gc; duke@435: // XXX See note in genCollectedHeap::millis_since_last_gc(). duke@435: if (ret_val < 0) { johnc@3339: NOT_PRODUCT(warning("time warp: "INT64_FORMAT, ret_val);) duke@435: return 0; duke@435: } duke@435: return ret_val; duke@435: } duke@435: duke@435: void PSParallelCompact::reset_millis_since_last_gc() { johnc@3339: // We need a monotonically non-deccreasing time in ms but johnc@3339: // os::javaTimeMillis() does not guarantee monotonicity. johnc@3339: _time_of_last_gc = os::javaTimeNanos() / NANOSECS_PER_MILLISEC; duke@435: } duke@435: duke@435: ParMarkBitMap::IterationStatus MoveAndUpdateClosure::copy_until_full() duke@435: { duke@435: if (source() != destination()) { jcoomes@930: DEBUG_ONLY(PSParallelCompact::check_new_location(source(), destination());) duke@435: Copy::aligned_conjoint_words(source(), destination(), words_remaining()); duke@435: } duke@435: update_state(words_remaining()); duke@435: assert(is_full(), "sanity"); duke@435: return ParMarkBitMap::full; duke@435: } duke@435: duke@435: void MoveAndUpdateClosure::copy_partial_obj() duke@435: { duke@435: size_t words = words_remaining(); duke@435: duke@435: HeapWord* const range_end = MIN2(source() + words, bitmap()->region_end()); duke@435: HeapWord* const end_addr = bitmap()->find_obj_end(source(), range_end); duke@435: if (end_addr < range_end) { duke@435: words = bitmap()->obj_size(source(), end_addr); duke@435: } duke@435: duke@435: // This test is necessary; if omitted, the pointer updates to a partial object duke@435: // that crosses the dense prefix boundary could be overwritten. duke@435: if (source() != destination()) { jcoomes@930: DEBUG_ONLY(PSParallelCompact::check_new_location(source(), destination());) duke@435: Copy::aligned_conjoint_words(source(), destination(), words); duke@435: } duke@435: update_state(words); duke@435: } duke@435: duke@435: ParMarkBitMapClosure::IterationStatus duke@435: MoveAndUpdateClosure::do_addr(HeapWord* addr, size_t words) { duke@435: assert(destination() != NULL, "sanity"); duke@435: assert(bitmap()->obj_size(addr) == words, "bad size"); duke@435: duke@435: _source = addr; duke@435: assert(PSParallelCompact::summary_data().calc_new_pointer(source()) == duke@435: destination(), "wrong destination"); duke@435: duke@435: if (words > words_remaining()) { duke@435: return ParMarkBitMap::would_overflow; duke@435: } duke@435: duke@435: // The start_array must be updated even if the object is not moving. duke@435: if (_start_array != NULL) { duke@435: _start_array->allocate_block(destination()); duke@435: } duke@435: duke@435: if (destination() != source()) { jcoomes@930: DEBUG_ONLY(PSParallelCompact::check_new_location(source(), destination());) duke@435: Copy::aligned_conjoint_words(source(), destination(), words); duke@435: } duke@435: duke@435: oop moved_oop = (oop) destination(); duke@435: moved_oop->update_contents(compaction_manager()); duke@435: assert(moved_oop->is_oop_or_null(), "Object should be whole at this point"); duke@435: duke@435: update_state(words); duke@435: assert(destination() == (HeapWord*)moved_oop + moved_oop->size(), "sanity"); duke@435: return is_full() ? ParMarkBitMap::full : ParMarkBitMap::incomplete; duke@435: } duke@435: duke@435: UpdateOnlyClosure::UpdateOnlyClosure(ParMarkBitMap* mbm, duke@435: ParCompactionManager* cm, duke@435: PSParallelCompact::SpaceId space_id) : duke@435: ParMarkBitMapClosure(mbm, cm), duke@435: _space_id(space_id), duke@435: _start_array(PSParallelCompact::start_array(space_id)) duke@435: { duke@435: } duke@435: duke@435: // Updates the references in the object to their new values. duke@435: ParMarkBitMapClosure::IterationStatus duke@435: UpdateOnlyClosure::do_addr(HeapWord* addr, size_t words) { duke@435: do_addr(addr); duke@435: return ParMarkBitMap::incomplete; duke@435: }