duke@435: /* duke@435: * Copyright 2005-2007 Sun Microsystems, Inc. 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: * duke@435: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, duke@435: * CA 95054 USA or visit www.sun.com if you need additional information or duke@435: * have any questions. duke@435: * duke@435: */ duke@435: duke@435: #include "incls/_precompiled.incl" duke@435: #include "incls/_psParallelCompact.cpp.incl" duke@435: duke@435: #include duke@435: duke@435: // All sizes are in HeapWords. duke@435: const size_t ParallelCompactData::Log2ChunkSize = 9; // 512 words duke@435: const size_t ParallelCompactData::ChunkSize = (size_t)1 << Log2ChunkSize; duke@435: const size_t ParallelCompactData::ChunkSizeBytes = ChunkSize << LogHeapWordSize; duke@435: const size_t ParallelCompactData::ChunkSizeOffsetMask = ChunkSize - 1; duke@435: const size_t ParallelCompactData::ChunkAddrOffsetMask = ChunkSizeBytes - 1; duke@435: const size_t ParallelCompactData::ChunkAddrMask = ~ChunkAddrOffsetMask; duke@435: duke@435: // 32-bit: 128 words covers 4 bitmap words duke@435: // 64-bit: 128 words covers 2 bitmap words duke@435: const size_t ParallelCompactData::Log2BlockSize = 7; // 128 words duke@435: const size_t ParallelCompactData::BlockSize = (size_t)1 << Log2BlockSize; duke@435: const size_t ParallelCompactData::BlockOffsetMask = BlockSize - 1; duke@435: const size_t ParallelCompactData::BlockMask = ~BlockOffsetMask; duke@435: duke@435: const size_t ParallelCompactData::BlocksPerChunk = ChunkSize / BlockSize; duke@435: duke@435: const ParallelCompactData::ChunkData::chunk_sz_t duke@435: ParallelCompactData::ChunkData::dc_shift = 27; duke@435: duke@435: const ParallelCompactData::ChunkData::chunk_sz_t duke@435: ParallelCompactData::ChunkData::dc_mask = ~0U << dc_shift; duke@435: duke@435: const ParallelCompactData::ChunkData::chunk_sz_t duke@435: ParallelCompactData::ChunkData::dc_one = 0x1U << dc_shift; duke@435: duke@435: const ParallelCompactData::ChunkData::chunk_sz_t duke@435: ParallelCompactData::ChunkData::los_mask = ~dc_mask; duke@435: duke@435: const ParallelCompactData::ChunkData::chunk_sz_t duke@435: ParallelCompactData::ChunkData::dc_claimed = 0x8U << dc_shift; duke@435: duke@435: const ParallelCompactData::ChunkData::chunk_sz_t duke@435: ParallelCompactData::ChunkData::dc_completed = 0xcU << dc_shift; duke@435: duke@435: #ifdef ASSERT duke@435: short ParallelCompactData::BlockData::_cur_phase = 0; duke@435: #endif 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; duke@435: klassOop 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: duke@435: #ifdef VALIDATE_MARK_SWEEP coleenp@548: GrowableArray* PSParallelCompact::_root_refs_stack = NULL; duke@435: GrowableArray * PSParallelCompact::_live_oops = NULL; duke@435: GrowableArray * PSParallelCompact::_live_oops_moved_to = NULL; duke@435: GrowableArray* PSParallelCompact::_live_oops_size = NULL; duke@435: size_t PSParallelCompact::_live_oops_index = 0; duke@435: size_t PSParallelCompact::_live_oops_index_at_perm = 0; coleenp@548: GrowableArray* PSParallelCompact::_other_refs_stack = NULL; coleenp@548: GrowableArray* PSParallelCompact::_adjusted_pointers = NULL; duke@435: bool PSParallelCompact::_pointer_tracking = false; duke@435: bool PSParallelCompact::_root_tracking = true; duke@435: duke@435: GrowableArray* PSParallelCompact::_cur_gc_live_oops = NULL; duke@435: GrowableArray* PSParallelCompact::_cur_gc_live_oops_moved_to = NULL; duke@435: GrowableArray * PSParallelCompact::_cur_gc_live_oops_size = NULL; duke@435: GrowableArray* PSParallelCompact::_last_gc_live_oops = NULL; duke@435: GrowableArray* PSParallelCompact::_last_gc_live_oops_moved_to = NULL; duke@435: GrowableArray * PSParallelCompact::_last_gc_live_oops_size = NULL; duke@435: #endif duke@435: duke@435: // XXX beg - verification code; only works while we also mark in object headers duke@435: static void duke@435: verify_mark_bitmap(ParMarkBitMap& _mark_bitmap) duke@435: { duke@435: ParallelScavengeHeap* heap = PSParallelCompact::gc_heap(); duke@435: duke@435: PSPermGen* perm_gen = heap->perm_gen(); duke@435: PSOldGen* old_gen = heap->old_gen(); duke@435: PSYoungGen* young_gen = heap->young_gen(); duke@435: duke@435: MutableSpace* perm_space = perm_gen->object_space(); duke@435: MutableSpace* old_space = old_gen->object_space(); duke@435: MutableSpace* eden_space = young_gen->eden_space(); duke@435: MutableSpace* from_space = young_gen->from_space(); duke@435: MutableSpace* to_space = young_gen->to_space(); duke@435: duke@435: // 'from_space' here is the survivor space at the lower address. duke@435: if (to_space->bottom() < from_space->bottom()) { duke@435: from_space = to_space; duke@435: to_space = young_gen->from_space(); duke@435: } duke@435: duke@435: HeapWord* boundaries[12]; duke@435: unsigned int bidx = 0; duke@435: const unsigned int bidx_max = sizeof(boundaries) / sizeof(boundaries[0]); duke@435: duke@435: boundaries[0] = perm_space->bottom(); duke@435: boundaries[1] = perm_space->top(); duke@435: boundaries[2] = old_space->bottom(); duke@435: boundaries[3] = old_space->top(); duke@435: boundaries[4] = eden_space->bottom(); duke@435: boundaries[5] = eden_space->top(); duke@435: boundaries[6] = from_space->bottom(); duke@435: boundaries[7] = from_space->top(); duke@435: boundaries[8] = to_space->bottom(); duke@435: boundaries[9] = to_space->top(); duke@435: boundaries[10] = to_space->end(); duke@435: boundaries[11] = to_space->end(); duke@435: duke@435: BitMap::idx_t beg_bit = 0; duke@435: BitMap::idx_t end_bit; duke@435: BitMap::idx_t tmp_bit; duke@435: const BitMap::idx_t last_bit = _mark_bitmap.size(); duke@435: do { duke@435: HeapWord* addr = _mark_bitmap.bit_to_addr(beg_bit); duke@435: if (_mark_bitmap.is_marked(beg_bit)) { duke@435: oop obj = (oop)addr; duke@435: assert(obj->is_gc_marked(), "obj header is not marked"); duke@435: end_bit = _mark_bitmap.find_obj_end(beg_bit, last_bit); duke@435: const size_t size = _mark_bitmap.obj_size(beg_bit, end_bit); duke@435: assert(size == (size_t)obj->size(), "end bit wrong?"); duke@435: beg_bit = _mark_bitmap.find_obj_beg(beg_bit + 1, last_bit); duke@435: assert(beg_bit > end_bit, "bit set in middle of an obj"); duke@435: } else { duke@435: if (addr >= boundaries[bidx] && addr < boundaries[bidx + 1]) { duke@435: // a dead object in the current space. duke@435: oop obj = (oop)addr; duke@435: end_bit = _mark_bitmap.addr_to_bit(addr + obj->size()); duke@435: assert(!obj->is_gc_marked(), "obj marked in header, not in bitmap"); duke@435: tmp_bit = beg_bit + 1; duke@435: beg_bit = _mark_bitmap.find_obj_beg(tmp_bit, end_bit); duke@435: assert(beg_bit == end_bit, "beg bit set in unmarked obj"); duke@435: beg_bit = _mark_bitmap.find_obj_end(tmp_bit, end_bit); duke@435: assert(beg_bit == end_bit, "end bit set in unmarked obj"); duke@435: } else if (addr < boundaries[bidx + 2]) { duke@435: // addr is between top in the current space and bottom in the next. duke@435: end_bit = beg_bit + pointer_delta(boundaries[bidx + 2], addr); duke@435: tmp_bit = beg_bit; duke@435: beg_bit = _mark_bitmap.find_obj_beg(tmp_bit, end_bit); duke@435: assert(beg_bit == end_bit, "beg bit set above top"); duke@435: beg_bit = _mark_bitmap.find_obj_end(tmp_bit, end_bit); duke@435: assert(beg_bit == end_bit, "end bit set above top"); duke@435: bidx += 2; duke@435: } else if (bidx < bidx_max - 2) { duke@435: bidx += 2; // ??? duke@435: } else { duke@435: tmp_bit = beg_bit; duke@435: beg_bit = _mark_bitmap.find_obj_beg(tmp_bit, last_bit); duke@435: assert(beg_bit == last_bit, "beg bit set outside heap"); duke@435: beg_bit = _mark_bitmap.find_obj_end(tmp_bit, last_bit); duke@435: assert(beg_bit == last_bit, "end bit set outside heap"); duke@435: } duke@435: } duke@435: } while (beg_bit < last_bit); duke@435: } duke@435: // XXX end - verification code; only works while we also mark in object headers duke@435: duke@435: #ifndef PRODUCT duke@435: const char* PSParallelCompact::space_names[] = { duke@435: "perm", "old ", "eden", "from", "to " duke@435: }; duke@435: duke@435: void PSParallelCompact::print_chunk_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 " duke@435: SIZE_FORMAT_W("10") " " SIZE_FORMAT_W("10") " " duke@435: SIZE_FORMAT_W("10") " " SIZE_FORMAT_W("10") " ", duke@435: id, space_names[id], duke@435: summary_data().addr_to_chunk_idx(space->bottom()), duke@435: summary_data().addr_to_chunk_idx(space->top()), duke@435: summary_data().addr_to_chunk_idx(space->end()), duke@435: summary_data().addr_to_chunk_idx(_space_info[id].new_top())); duke@435: } duke@435: } duke@435: duke@435: void duke@435: print_generic_summary_chunk(size_t i, const ParallelCompactData::ChunkData* c) duke@435: { duke@435: #define CHUNK_IDX_FORMAT SIZE_FORMAT_W("7") duke@435: #define CHUNK_DATA_FORMAT SIZE_FORMAT_W("5") duke@435: duke@435: ParallelCompactData& sd = PSParallelCompact::summary_data(); duke@435: size_t dci = c->destination() ? sd.addr_to_chunk_idx(c->destination()) : 0; duke@435: tty->print_cr(CHUNK_IDX_FORMAT " " PTR_FORMAT " " duke@435: CHUNK_IDX_FORMAT " " PTR_FORMAT " " duke@435: CHUNK_DATA_FORMAT " " CHUNK_DATA_FORMAT " " duke@435: CHUNK_DATA_FORMAT " " CHUNK_IDX_FORMAT " %d", duke@435: i, c->data_location(), dci, c->destination(), duke@435: c->partial_obj_size(), c->live_obj_size(), duke@435: c->data_size(), c->source_chunk(), c->destination_count()); duke@435: duke@435: #undef CHUNK_IDX_FORMAT duke@435: #undef CHUNK_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; duke@435: size_t i = summary_data.addr_to_chunk_idx(beg_addr); duke@435: const size_t last = summary_data.addr_to_chunk_idx(end_addr); duke@435: HeapWord* pdest = 0; duke@435: duke@435: while (i <= last) { duke@435: ParallelCompactData::ChunkData* c = summary_data.chunk(i); duke@435: if (c->data_size() != 0 || c->destination() != pdest) { duke@435: print_generic_summary_chunk(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 duke@435: print_initial_summary_chunk(size_t i, duke@435: const ParallelCompactData::ChunkData* c, duke@435: bool newline = true) duke@435: { duke@435: tty->print(SIZE_FORMAT_W("5") " " PTR_FORMAT " " duke@435: SIZE_FORMAT_W("5") " " SIZE_FORMAT_W("5") " " duke@435: SIZE_FORMAT_W("5") " " SIZE_FORMAT_W("5") " %d", duke@435: i, c->destination(), duke@435: c->partial_obj_size(), c->live_obj_size(), duke@435: c->data_size(), c->source_chunk(), 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: duke@435: const size_t chunk_size = ParallelCompactData::ChunkSize; duke@435: HeapWord* const top_aligned_up = summary_data.chunk_align_up(space->top()); duke@435: const size_t end_chunk = summary_data.addr_to_chunk_idx(top_aligned_up); duke@435: const ParallelCompactData::ChunkData* c = summary_data.chunk(end_chunk - 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: duke@435: // Print (and count) the full chunks at the beginning of the space. duke@435: size_t full_chunk_count = 0; duke@435: size_t i = summary_data.addr_to_chunk_idx(space->bottom()); duke@435: while (i < end_chunk && summary_data.chunk(i)->data_size() == chunk_size) { duke@435: print_initial_summary_chunk(i, summary_data.chunk(i)); duke@435: ++full_chunk_count; duke@435: ++i; duke@435: } duke@435: duke@435: size_t live_to_right = live_in_space - full_chunk_count * chunk_size; duke@435: duke@435: double max_reclaimed_ratio = 0.0; duke@435: size_t max_reclaimed_ratio_chunk = 0; duke@435: size_t max_dead_to_right = 0; duke@435: size_t max_live_to_right = 0; duke@435: duke@435: // Print the 'reclaimed ratio' for chunks while there is something live in the duke@435: // chunk or to the right of it. The remaining chunks are empty (and duke@435: // uninteresting), and computing the ratio will result in division by 0. duke@435: while (i < end_chunk && live_to_right > 0) { duke@435: c = summary_data.chunk(i); duke@435: HeapWord* const chunk_addr = summary_data.chunk_to_addr(i); duke@435: const size_t used_to_right = pointer_delta(space->top(), chunk_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; duke@435: max_reclaimed_ratio_chunk = i; duke@435: max_dead_to_right = dead_to_right; duke@435: max_live_to_right = live_to_right; duke@435: } duke@435: duke@435: print_initial_summary_chunk(i, c, false); duke@435: 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: duke@435: // Any remaining chunks are empty. Print one more if there is one. duke@435: if (i < end_chunk) { duke@435: print_initial_summary_chunk(i, summary_data.chunk(i)); duke@435: } duke@435: duke@435: tty->print_cr("max: " SIZE_FORMAT_W("4") " d2r=" SIZE_FORMAT_W("10") " " duke@435: "l2r=" SIZE_FORMAT_W("10") " max_ratio=%14.12f", duke@435: max_reclaimed_ratio_chunk, 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) { duke@435: unsigned int id = PSParallelCompact::perm_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: duke@435: _chunk_vspace = 0; duke@435: _chunk_data = 0; duke@435: _chunk_count = 0; duke@435: duke@435: _block_vspace = 0; duke@435: _block_data = 0; duke@435: _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: duke@435: assert(chunk_align_down(_region_start) == _region_start, duke@435: "region start not aligned"); duke@435: assert((region_size & ChunkSizeOffsetMask) == 0, duke@435: "region size not a multiple of ChunkSize"); duke@435: duke@435: bool result = initialize_chunk_data(region_size); duke@435: duke@435: // Initialize the block data if it will be used for updating pointers, or if duke@435: // this is a debug build. duke@435: if (!UseParallelOldGCChunkPointerCalc || trueInDebug) { duke@435: result = result && initialize_block_data(region_size); duke@435: } duke@435: 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(); duke@435: const size_t bytes = 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); jcoomes@514: ReservedSpace rs(bytes, 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()); duke@435: PSVirtualSpace* vspace = new PSVirtualSpace(rs, page_sz); duke@435: if (vspace != 0) { duke@435: if (vspace->expand_by(bytes)) { duke@435: return vspace; duke@435: } duke@435: delete vspace; duke@435: } duke@435: duke@435: return 0; duke@435: } duke@435: duke@435: bool ParallelCompactData::initialize_chunk_data(size_t region_size) duke@435: { duke@435: const size_t count = (region_size + ChunkSizeOffsetMask) >> Log2ChunkSize; duke@435: _chunk_vspace = create_vspace(count, sizeof(ChunkData)); duke@435: if (_chunk_vspace != 0) { duke@435: _chunk_data = (ChunkData*)_chunk_vspace->reserved_low_addr(); duke@435: _chunk_count = count; duke@435: return true; duke@435: } duke@435: return false; duke@435: } duke@435: duke@435: bool ParallelCompactData::initialize_block_data(size_t region_size) duke@435: { duke@435: const size_t count = (region_size + BlockOffsetMask) >> Log2BlockSize; duke@435: _block_vspace = create_vspace(count, sizeof(BlockData)); duke@435: if (_block_vspace != 0) { duke@435: _block_data = (BlockData*)_block_vspace->reserved_low_addr(); duke@435: _block_count = count; duke@435: return true; duke@435: } duke@435: return false; duke@435: } duke@435: duke@435: void ParallelCompactData::clear() duke@435: { duke@435: if (_block_data) { duke@435: memset(_block_data, 0, _block_vspace->committed_size()); duke@435: } duke@435: memset(_chunk_data, 0, _chunk_vspace->committed_size()); duke@435: } duke@435: duke@435: void ParallelCompactData::clear_range(size_t beg_chunk, size_t end_chunk) { duke@435: assert(beg_chunk <= _chunk_count, "beg_chunk out of range"); duke@435: assert(end_chunk <= _chunk_count, "end_chunk out of range"); duke@435: assert(ChunkSize % BlockSize == 0, "ChunkSize not a multiple of BlockSize"); duke@435: duke@435: const size_t chunk_cnt = end_chunk - beg_chunk; duke@435: duke@435: if (_block_data) { duke@435: const size_t blocks_per_chunk = ChunkSize / BlockSize; duke@435: const size_t beg_block = beg_chunk * blocks_per_chunk; duke@435: const size_t block_cnt = chunk_cnt * blocks_per_chunk; duke@435: memset(_block_data + beg_block, 0, block_cnt * sizeof(BlockData)); duke@435: } duke@435: memset(_chunk_data + beg_chunk, 0, chunk_cnt * sizeof(ChunkData)); duke@435: } duke@435: duke@435: HeapWord* ParallelCompactData::partial_obj_end(size_t chunk_idx) const duke@435: { duke@435: const ChunkData* cur_cp = chunk(chunk_idx); duke@435: const ChunkData* const end_cp = chunk(chunk_count() - 1); duke@435: duke@435: HeapWord* result = chunk_to_addr(chunk_idx); duke@435: if (cur_cp < end_cp) { duke@435: do { duke@435: result += cur_cp->partial_obj_size(); duke@435: } while (cur_cp->partial_obj_size() == ChunkSize && ++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); duke@435: const size_t beg_chunk = obj_ofs >> Log2ChunkSize; duke@435: const size_t end_chunk = (obj_ofs + len - 1) >> Log2ChunkSize; 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: duke@435: if (beg_chunk == end_chunk) { duke@435: // All in one chunk. duke@435: _chunk_data[beg_chunk].add_live_obj(len); duke@435: return; duke@435: } duke@435: duke@435: // First chunk. duke@435: const size_t beg_ofs = chunk_offset(addr); duke@435: _chunk_data[beg_chunk].add_live_obj(ChunkSize - beg_ofs); duke@435: duke@435: klassOop klass = ((oop)addr)->klass(); duke@435: // Middle chunks--completely spanned by this object. duke@435: for (size_t chunk = beg_chunk + 1; chunk < end_chunk; ++chunk) { duke@435: _chunk_data[chunk].set_partial_obj_size(ChunkSize); duke@435: _chunk_data[chunk].set_partial_obj_addr(addr); duke@435: } duke@435: duke@435: // Last chunk. duke@435: const size_t end_ofs = chunk_offset(addr + len - 1); duke@435: _chunk_data[end_chunk].set_partial_obj_size(end_ofs + 1); duke@435: _chunk_data[end_chunk].set_partial_obj_addr(addr); duke@435: } duke@435: duke@435: void duke@435: ParallelCompactData::summarize_dense_prefix(HeapWord* beg, HeapWord* end) duke@435: { duke@435: assert(chunk_offset(beg) == 0, "not ChunkSize aligned"); duke@435: assert(chunk_offset(end) == 0, "not ChunkSize aligned"); duke@435: duke@435: size_t cur_chunk = addr_to_chunk_idx(beg); duke@435: const size_t end_chunk = addr_to_chunk_idx(end); duke@435: HeapWord* addr = beg; duke@435: while (cur_chunk < end_chunk) { duke@435: _chunk_data[cur_chunk].set_destination(addr); duke@435: _chunk_data[cur_chunk].set_destination_count(0); duke@435: _chunk_data[cur_chunk].set_source_chunk(cur_chunk); duke@435: _chunk_data[cur_chunk].set_data_location(addr); duke@435: duke@435: // Update live_obj_size so the chunk appears completely full. duke@435: size_t live_size = ChunkSize - _chunk_data[cur_chunk].partial_obj_size(); duke@435: _chunk_data[cur_chunk].set_live_obj_size(live_size); duke@435: duke@435: ++cur_chunk; duke@435: addr += ChunkSize; duke@435: } duke@435: } duke@435: duke@435: bool ParallelCompactData::summarize(HeapWord* target_beg, HeapWord* target_end, duke@435: HeapWord* source_beg, HeapWord* source_end, duke@435: HeapWord** target_next, duke@435: HeapWord** source_next) { duke@435: // This is too strict. duke@435: // assert(chunk_offset(source_beg) == 0, "not ChunkSize aligned"); duke@435: duke@435: if (TraceParallelOldGCSummaryPhase) { duke@435: tty->print_cr("tb=" PTR_FORMAT " te=" PTR_FORMAT " " duke@435: "sb=" PTR_FORMAT " se=" PTR_FORMAT " " duke@435: "tn=" PTR_FORMAT " sn=" PTR_FORMAT, duke@435: target_beg, target_end, duke@435: source_beg, source_end, duke@435: target_next != 0 ? *target_next : (HeapWord*) 0, duke@435: source_next != 0 ? *source_next : (HeapWord*) 0); duke@435: } duke@435: duke@435: size_t cur_chunk = addr_to_chunk_idx(source_beg); duke@435: const size_t end_chunk = addr_to_chunk_idx(chunk_align_up(source_end)); duke@435: duke@435: HeapWord *dest_addr = target_beg; duke@435: while (cur_chunk < end_chunk) { duke@435: size_t words = _chunk_data[cur_chunk].data_size(); duke@435: duke@435: #if 1 duke@435: assert(pointer_delta(target_end, dest_addr) >= words, duke@435: "source region does not fit into target region"); duke@435: #else duke@435: // XXX - need some work on the corner cases here. If the chunk does not duke@435: // fit, then must either make sure any partial_obj from the chunk fits, or duke@435: // 'undo' the initial part of the partial_obj that is in the previous chunk. duke@435: if (dest_addr + words >= target_end) { duke@435: // Let the caller know where to continue. duke@435: *target_next = dest_addr; duke@435: *source_next = chunk_to_addr(cur_chunk); duke@435: return false; duke@435: } duke@435: #endif // #if 1 duke@435: duke@435: _chunk_data[cur_chunk].set_destination(dest_addr); duke@435: duke@435: // Set the destination_count for cur_chunk, and if necessary, update duke@435: // source_chunk for a destination chunk. The source_chunk field is updated duke@435: // if cur_chunk is the first (left-most) chunk to be copied to a destination duke@435: // chunk. duke@435: // duke@435: // The destination_count calculation is a bit subtle. A chunk that has data duke@435: // that compacts into itself does not count itself as a destination. This duke@435: // maintains the invariant that a zero count means the chunk is available duke@435: // and can be claimed and then filled. duke@435: if (words > 0) { duke@435: HeapWord* const last_addr = dest_addr + words - 1; duke@435: const size_t dest_chunk_1 = addr_to_chunk_idx(dest_addr); duke@435: const size_t dest_chunk_2 = addr_to_chunk_idx(last_addr); duke@435: #if 0 duke@435: // Initially assume that the destination chunks will be the same and duke@435: // adjust the value below if necessary. Under this assumption, if duke@435: // cur_chunk == dest_chunk_2, then cur_chunk will be compacted completely duke@435: // into itself. duke@435: uint destination_count = cur_chunk == dest_chunk_2 ? 0 : 1; duke@435: if (dest_chunk_1 != dest_chunk_2) { duke@435: // Destination chunks differ; adjust destination_count. duke@435: destination_count += 1; duke@435: // Data from cur_chunk will be copied to the start of dest_chunk_2. duke@435: _chunk_data[dest_chunk_2].set_source_chunk(cur_chunk); duke@435: } else if (chunk_offset(dest_addr) == 0) { duke@435: // Data from cur_chunk will be copied to the start of the destination duke@435: // chunk. duke@435: _chunk_data[dest_chunk_1].set_source_chunk(cur_chunk); duke@435: } duke@435: #else duke@435: // Initially assume that the destination chunks will be different and duke@435: // adjust the value below if necessary. Under this assumption, if duke@435: // cur_chunk == dest_chunk2, then cur_chunk will be compacted partially duke@435: // into dest_chunk_1 and partially into itself. duke@435: uint destination_count = cur_chunk == dest_chunk_2 ? 1 : 2; duke@435: if (dest_chunk_1 != dest_chunk_2) { duke@435: // Data from cur_chunk will be copied to the start of dest_chunk_2. duke@435: _chunk_data[dest_chunk_2].set_source_chunk(cur_chunk); duke@435: } else { duke@435: // Destination chunks are the same; adjust destination_count. duke@435: destination_count -= 1; duke@435: if (chunk_offset(dest_addr) == 0) { duke@435: // Data from cur_chunk will be copied to the start of the destination duke@435: // chunk. duke@435: _chunk_data[dest_chunk_1].set_source_chunk(cur_chunk); duke@435: } duke@435: } duke@435: #endif // #if 0 duke@435: duke@435: _chunk_data[cur_chunk].set_destination_count(destination_count); duke@435: _chunk_data[cur_chunk].set_data_location(chunk_to_addr(cur_chunk)); duke@435: dest_addr += words; duke@435: } duke@435: duke@435: ++cur_chunk; duke@435: } duke@435: duke@435: *target_next = dest_addr; duke@435: return true; duke@435: } duke@435: duke@435: bool ParallelCompactData::partial_obj_ends_in_block(size_t block_index) { duke@435: HeapWord* block_addr = block_to_addr(block_index); duke@435: HeapWord* block_end_addr = block_addr + BlockSize; duke@435: size_t chunk_index = addr_to_chunk_idx(block_addr); duke@435: HeapWord* partial_obj_end_addr = partial_obj_end(chunk_index); duke@435: duke@435: // An object that ends at the end of the block, ends duke@435: // in the block (the last word of the object is to duke@435: // the left of the end). duke@435: if ((block_addr < partial_obj_end_addr) && duke@435: (partial_obj_end_addr <= block_end_addr)) { duke@435: return true; duke@435: } duke@435: duke@435: return false; duke@435: } duke@435: duke@435: HeapWord* ParallelCompactData::calc_new_pointer(HeapWord* addr) { duke@435: HeapWord* result = NULL; duke@435: if (UseParallelOldGCChunkPointerCalc) { duke@435: result = chunk_calc_new_pointer(addr); duke@435: } else { duke@435: result = block_calc_new_pointer(addr); duke@435: } duke@435: return result; duke@435: } duke@435: duke@435: // This method is overly complicated (expensive) to be called duke@435: // for every reference. duke@435: // Try to restructure this so that a NULL is returned if duke@435: // the object is dead. But don't wast the cycles to explicitly check duke@435: // that it is dead since only live objects should be passed in. duke@435: duke@435: HeapWord* ParallelCompactData::chunk_calc_new_pointer(HeapWord* addr) { duke@435: assert(addr != NULL, "Should detect NULL oop earlier"); duke@435: assert(PSParallelCompact::gc_heap()->is_in(addr), "addr not in heap"); duke@435: #ifdef ASSERT duke@435: if (PSParallelCompact::mark_bitmap()->is_unmarked(addr)) { duke@435: gclog_or_tty->print_cr("calc_new_pointer:: addr " PTR_FORMAT, addr); duke@435: } duke@435: #endif duke@435: assert(PSParallelCompact::mark_bitmap()->is_marked(addr), "obj not marked"); duke@435: duke@435: // Chunk covering the object. duke@435: size_t chunk_index = addr_to_chunk_idx(addr); duke@435: const ChunkData* const chunk_ptr = chunk(chunk_index); duke@435: HeapWord* const chunk_addr = chunk_align_down(addr); duke@435: duke@435: assert(addr < chunk_addr + ChunkSize, "Chunk does not cover object"); duke@435: assert(addr_to_chunk_ptr(chunk_addr) == chunk_ptr, "sanity check"); duke@435: duke@435: HeapWord* result = chunk_ptr->destination(); duke@435: duke@435: // If all the data in the chunk is live, then the new location of the object duke@435: // can be calculated from the destination of the chunk plus the offset of the duke@435: // object in the chunk. duke@435: if (chunk_ptr->data_size() == ChunkSize) { duke@435: result += pointer_delta(addr, chunk_addr); duke@435: return result; duke@435: } duke@435: duke@435: // The new location of the object is duke@435: // chunk destination + duke@435: // size of the partial object extending onto the chunk + duke@435: // sizes of the live objects in the Chunk that are to the left of addr duke@435: const size_t partial_obj_size = chunk_ptr->partial_obj_size(); duke@435: HeapWord* const search_start = chunk_addr + partial_obj_size; duke@435: duke@435: const ParMarkBitMap* bitmap = PSParallelCompact::mark_bitmap(); duke@435: size_t live_to_left = bitmap->live_words_in_range(search_start, oop(addr)); duke@435: duke@435: result += partial_obj_size + live_to_left; duke@435: assert(result <= addr, "object cannot move to the right"); duke@435: return result; duke@435: } duke@435: duke@435: HeapWord* ParallelCompactData::block_calc_new_pointer(HeapWord* addr) { duke@435: assert(addr != NULL, "Should detect NULL oop earlier"); duke@435: assert(PSParallelCompact::gc_heap()->is_in(addr), "addr not in heap"); duke@435: #ifdef ASSERT duke@435: if (PSParallelCompact::mark_bitmap()->is_unmarked(addr)) { duke@435: gclog_or_tty->print_cr("calc_new_pointer:: addr " PTR_FORMAT, addr); duke@435: } duke@435: #endif duke@435: assert(PSParallelCompact::mark_bitmap()->is_marked(addr), "obj not marked"); duke@435: duke@435: // Chunk covering the object. duke@435: size_t chunk_index = addr_to_chunk_idx(addr); duke@435: const ChunkData* const chunk_ptr = chunk(chunk_index); duke@435: HeapWord* const chunk_addr = chunk_align_down(addr); duke@435: duke@435: assert(addr < chunk_addr + ChunkSize, "Chunk does not cover object"); duke@435: assert(addr_to_chunk_ptr(chunk_addr) == chunk_ptr, "sanity check"); duke@435: duke@435: HeapWord* result = chunk_ptr->destination(); duke@435: duke@435: // If all the data in the chunk is live, then the new location of the object duke@435: // can be calculated from the destination of the chunk plus the offset of the duke@435: // object in the chunk. duke@435: if (chunk_ptr->data_size() == ChunkSize) { duke@435: result += pointer_delta(addr, chunk_addr); duke@435: return result; duke@435: } duke@435: duke@435: // The new location of the object is duke@435: // chunk destination + duke@435: // block offset + duke@435: // sizes of the live objects in the Block that are to the left of addr duke@435: const size_t block_offset = addr_to_block_ptr(addr)->offset(); duke@435: HeapWord* const search_start = chunk_addr + block_offset; duke@435: duke@435: const ParMarkBitMap* bitmap = PSParallelCompact::mark_bitmap(); duke@435: size_t live_to_left = bitmap->live_words_in_range(search_start, oop(addr)); duke@435: duke@435: result += block_offset + live_to_left; duke@435: assert(result <= addr, "object cannot move to the right"); duke@435: assert(result == chunk_calc_new_pointer(addr), "Should match"); duke@435: return result; duke@435: } duke@435: duke@435: klassOop ParallelCompactData::calc_new_klass(klassOop old_klass) { duke@435: klassOop updated_klass; duke@435: if (PSParallelCompact::should_update_klass(old_klass)) { duke@435: updated_klass = (klassOop) calc_new_pointer(old_klass); duke@435: } else { duke@435: updated_klass = old_klass; duke@435: } duke@435: duke@435: return updated_klass; duke@435: } duke@435: duke@435: #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: { duke@435: verify_clear(_chunk_vspace); duke@435: verify_clear(_block_vspace); duke@435: } duke@435: #endif // #ifdef ASSERT duke@435: duke@435: #ifdef NOT_PRODUCT duke@435: ParallelCompactData::ChunkData* debug_chunk(size_t chunk_index) { duke@435: ParallelCompactData& sd = PSParallelCompact::summary_data(); duke@435: return sd.chunk(chunk_index); duke@435: } duke@435: #endif duke@435: 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: void PSParallelCompact::IsAliveClosure::do_object(oop p) { ShouldNotReachHere(); } 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: duke@435: PSParallelCompact::AdjustPointerClosure PSParallelCompact::_adjust_root_pointer_closure(true); duke@435: PSParallelCompact::AdjustPointerClosure PSParallelCompact::_adjust_pointer_closure(false); duke@435: coleenp@548: void PSParallelCompact::AdjustPointerClosure::do_oop(oop* p) { adjust_pointer(p, _is_root); } coleenp@548: void PSParallelCompact::AdjustPointerClosure::do_oop(narrowOop* p) { adjust_pointer(p, _is_root); } coleenp@548: coleenp@548: void PSParallelCompact::FollowStackClosure::do_void() { follow_stack(_compaction_manager); } coleenp@548: coleenp@548: void PSParallelCompact::MarkAndPushClosure::do_oop(oop* p) { mark_and_push(_compaction_manager, p); } coleenp@548: void PSParallelCompact::MarkAndPushClosure::do_oop(narrowOop* p) { mark_and_push(_compaction_manager, p); } duke@435: 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(); duke@435: _ref_processor = ReferenceProcessor::create_ref_processor( duke@435: mr, // span duke@435: true, // atomic_discovery duke@435: true, // mt_discovery duke@435: &_is_alive_closure, duke@435: ParallelGCThreads, duke@435: ParallelRefProcEnabled); 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)) { duke@435: vm_shutdown_during_initialization("Unable to allocate bit map for " duke@435: "parallel garbage collection for the requested heap size."); duke@435: return false; duke@435: } duke@435: duke@435: if (!_summary_data.initialize(mr)) { duke@435: vm_shutdown_during_initialization("Unable to allocate tables for " duke@435: "parallel garbage collection for the requested heap size."); 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(); duke@435: MutableSpace* perm_space = heap->perm_gen()->object_space(); duke@435: duke@435: _space_info[perm_space_id].set_space(perm_space); 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[perm_space_id].set_start_array(heap->perm_gen()->start_array()); duke@435: _space_info[old_space_id].set_start_array(heap->old_gen()->start_array()); duke@435: duke@435: _space_info[perm_space_id].set_min_dense_prefix(perm_space->top()); duke@435: if (TraceParallelOldGCDensePrefix) { duke@435: tty->print_cr("perm min_dense_prefix=" PTR_FORMAT, duke@435: _space_info[perm_space_id].min_dense_prefix()); duke@435: } 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(); duke@435: _perm_gen_used = heap->perm_gen()->used_in_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; } duke@435: size_t perm_gen_used() const { return _perm_gen_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; duke@435: size_t _perm_gen_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: duke@435: const size_t beg_chunk = _summary_data.addr_to_chunk_idx(bot); duke@435: const size_t end_chunk = duke@435: _summary_data.addr_to_chunk_idx(_summary_data.chunk_align_up(max_top)); duke@435: _summary_data.clear_range(beg_chunk, end_chunk); 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. duke@435: TraceTime tm("pre compact", print_phases(), true, gclog_or_tty); 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: ParCompactionManager::reset(); duke@435: NOT_PRODUCT(_mark_bitmap.reset_counters()); 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: duke@435: if (PrintHeapAtGC) { duke@435: Universe::print_heap_before_gc(); duke@435: } 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 duke@435: gclog_or_tty->print(" VerifyBeforeGC:"); duke@435: Universe::verify(true); 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: heap->perm_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: { duke@435: TraceTime tm("post compact", print_phases(), true, gclog_or_tty); duke@435: duke@435: // Clear the marking bitmap and summary data and update top() in each space. duke@435: for (unsigned int id = perm_space_id; id < last_space_id; ++id) { duke@435: clear_data_covering_space(SpaceId(id)); duke@435: _space_info[id].space()->set_top(_space_info[id].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: MemRegion perm_mr = heap->perm_gen()->reserved(); duke@435: assert(perm_mr.end() <= old_mr.start(), "Generations out of order"); duke@435: duke@435: if (young_gen_empty) { duke@435: modBS->clear(MemRegion(perm_mr.start(), old_mr.end())); duke@435: } else { duke@435: modBS->invalidate(MemRegion(perm_mr.start(), old_mr.end())); duke@435: } duke@435: } duke@435: duke@435: Threads::gc_epilogue(); duke@435: CodeCache::gc_epilogue(); duke@435: duke@435: COMPILER2_PRESENT(DerivedPointerTable::update_pointers()); duke@435: duke@435: ref_processor()->enqueue_discovered_references(NULL); duke@435: 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: { duke@435: const size_t chunk_size = ParallelCompactData::ChunkSize; duke@435: const ParallelCompactData& sd = summary_data(); duke@435: duke@435: const MutableSpace* const space = _space_info[id].space(); duke@435: HeapWord* const top_aligned_up = sd.chunk_align_up(space->top()); duke@435: const ChunkData* const beg_cp = sd.addr_to_chunk_ptr(space->bottom()); duke@435: const ChunkData* const end_cp = sd.addr_to_chunk_ptr(top_aligned_up); duke@435: duke@435: // Skip full chunks at the beginning of the space--they are necessarily part duke@435: // of the dense prefix. duke@435: size_t full_count = 0; duke@435: const ChunkData* cp; duke@435: for (cp = beg_cp; cp < end_cp && cp->data_size() == chunk_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(); duke@435: return sd.chunk_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? duke@435: HeapWord* dense_prefix = sd.chunk_to_addr(cp); duke@435: const ChunkData* full_cp = cp; duke@435: const ChunkData* const top_cp = sd.addr_to_chunk_ptr(space->top() - 1); duke@435: while (cp < end_cp) { duke@435: HeapWord* chunk_destination = cp->destination(); duke@435: const size_t cur_deadwood = pointer_delta(dense_prefix, chunk_destination); duke@435: if (TraceParallelOldGCDensePrefix && Verbose) { duke@435: tty->print_cr("c#=" SIZE_FORMAT_W("04") " dst=" PTR_FORMAT " " duke@435: "dp=" SIZE_FORMAT_W("08") " " "cdw=" SIZE_FORMAT_W("08"), duke@435: sd.chunk(cp), chunk_destination, duke@435: dense_prefix, cur_deadwood); duke@435: } duke@435: duke@435: if (cur_deadwood >= deadwood_goal) { duke@435: // Found the chunk that has the correct amount of deadwood to the left. duke@435: // This typically occurs after crossing a fairly sparse set of chunks, so duke@435: // iterate backwards over those sparse chunks, looking for the chunk that duke@435: // has the lowest density of live objects 'to the right.' duke@435: size_t space_to_left = sd.chunk(cp) * chunk_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; duke@435: const size_t prev_chunk_live_to_right = live_to_right - cp->data_size(); duke@435: const size_t prev_chunk_space_to_right = space_to_right + chunk_size; duke@435: double prev_chunk_density_to_right = duke@435: double(prev_chunk_live_to_right) / prev_chunk_space_to_right; duke@435: if (density_to_right <= prev_chunk_density_to_right) { duke@435: return dense_prefix; duke@435: } duke@435: if (TraceParallelOldGCDensePrefix && Verbose) { duke@435: tty->print_cr("backing up from c=" SIZE_FORMAT_W("4") " d2r=%10.8f " duke@435: "pc_d2r=%10.8f", sd.chunk(cp), density_to_right, duke@435: prev_chunk_density_to_right); duke@435: } duke@435: dense_prefix -= chunk_size; duke@435: live_to_right = prev_chunk_live_to_right; duke@435: space_to_right = prev_chunk_space_to_right; duke@435: density_to_right = prev_chunk_density_to_right; duke@435: } duke@435: return dense_prefix; duke@435: } duke@435: duke@435: dense_prefix += chunk_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: { duke@435: const size_t chunk_idx = summary_data().addr_to_chunk_idx(addr); duke@435: ChunkData* const cp = summary_data().chunk(chunk_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: duke@435: tty->print_cr("%s=" PTR_FORMAT " dpc=" SIZE_FORMAT_W("05") " " 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", duke@435: algorithm, addr, chunk_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: duke@435: ParallelCompactData::ChunkData* duke@435: PSParallelCompact::first_dead_space_chunk(const ChunkData* beg, duke@435: const ChunkData* end) duke@435: { duke@435: const size_t chunk_size = ParallelCompactData::ChunkSize; duke@435: ParallelCompactData& sd = summary_data(); duke@435: size_t left = sd.chunk(beg); duke@435: size_t right = end > beg ? sd.chunk(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; duke@435: ChunkData* const middle_ptr = sd.chunk(middle); duke@435: HeapWord* const dest = middle_ptr->destination(); duke@435: HeapWord* const addr = sd.chunk_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; duke@435: } else if (middle < right && middle_ptr->data_size() == chunk_size) { duke@435: left = middle + 1; duke@435: } else { duke@435: return middle_ptr; duke@435: } duke@435: } duke@435: return sd.chunk(left); duke@435: } duke@435: duke@435: ParallelCompactData::ChunkData* duke@435: PSParallelCompact::dead_wood_limit_chunk(const ChunkData* beg, duke@435: const ChunkData* end, duke@435: size_t dead_words) duke@435: { duke@435: ParallelCompactData& sd = summary_data(); duke@435: size_t left = sd.chunk(beg); duke@435: size_t right = end > beg ? sd.chunk(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; duke@435: ChunkData* const middle_ptr = sd.chunk(middle); duke@435: HeapWord* const dest = middle_ptr->destination(); duke@435: HeapWord* const addr = sd.chunk_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: } duke@435: return sd.chunk(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 duke@435: PSParallelCompact::reclaimed_ratio(const ChunkData* 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"); duke@435: assert(top >= sd.chunk_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); duke@435: const size_t compacted_region_used = pointer_delta(top, sd.chunk_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 duke@435: // compacted region. The address is always on a chunk boundary. duke@435: // duke@435: // Completely full chunks at the left are skipped, since no compaction can occur duke@435: // in those chunks. Then the maximum amount of dead wood to allow is computed, duke@435: // based on the density (amount live / capacity) of the generation; the chunk duke@435: // with approximately that amount of dead space to the left is identified as the duke@435: // limit chunk. Chunks between the last completely full chunk and the limit duke@435: // chunk are scanned and the one that has the best (maximum) reclaimed_ratio() duke@435: // is selected. duke@435: HeapWord* duke@435: PSParallelCompact::compute_dense_prefix(const SpaceId id, duke@435: bool maximum_compaction) duke@435: { duke@435: const size_t chunk_size = ParallelCompactData::ChunkSize; 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(); duke@435: HeapWord* const top_aligned_up = sd.chunk_align_up(top); duke@435: HeapWord* const new_top = _space_info[id].new_top(); duke@435: HeapWord* const new_top_aligned_up = sd.chunk_align_up(new_top); duke@435: HeapWord* const bottom = space->bottom(); duke@435: const ChunkData* const beg_cp = sd.addr_to_chunk_ptr(bottom); duke@435: const ChunkData* const top_cp = sd.addr_to_chunk_ptr(top_aligned_up); duke@435: const ChunkData* const new_top_cp = sd.addr_to_chunk_ptr(new_top_aligned_up); duke@435: duke@435: // Skip full chunks at the beginning of the space--they are necessarily part duke@435: // of the dense prefix. duke@435: const ChunkData* const full_cp = first_dead_space_chunk(beg_cp, new_top_cp); duke@435: assert(full_cp->destination() == sd.chunk_to_addr(full_cp) || duke@435: space->is_empty(), "no dead space allowed to the left"); duke@435: assert(full_cp->data_size() < chunk_size || full_cp == new_top_cp - 1, duke@435: "chunk 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(); duke@435: return sd.chunk_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); duke@435: const size_t min_percent_free = duke@435: id == perm_space_id ? PermMarkSweepDeadRatio : 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: duke@435: // Locate the chunk with the desired amount of dead space to the left. duke@435: const ChunkData* const limit_cp = duke@435: dead_wood_limit_chunk(full_cp, top_cp, dead_wood_limit); duke@435: duke@435: // Scan from the first chunk with dead space to the limit chunk and find the duke@435: // one with the best (largest) reclaimed ratio. duke@435: double best_ratio = 0.0; duke@435: const ChunkData* best_cp = full_cp; duke@435: for (const ChunkData* 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 duke@435: // Something to consider: if the chunk with the best ratio is 'close to' the duke@435: // first chunk w/free space, choose the first chunk with free space duke@435: // ("first-free"). The first-free chunk 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. duke@435: if (pointer_delta(best_cp, full_cp, sizeof(ChunkData)) < 4) { duke@435: _maximum_compaction_gc_num = total_invocations(); duke@435: best_cp = full_cp; duke@435: } duke@435: #endif // #if 0 duke@435: duke@435: return sd.chunk_to_addr(best_cp); duke@435: } duke@435: 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(); duke@435: bool result = _summary_data.summarize(space->bottom(), space->end(), duke@435: space->bottom(), space->top(), duke@435: _space_info[i].new_top_addr()); duke@435: assert(result, "should never fail"); duke@435: _space_info[i].set_dense_prefix(space->bottom()); duke@435: } 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); duke@435: const ChunkData* chunk = _summary_data.addr_to_chunk_ptr(dense_prefix_end); duke@435: const idx_t dense_prefix_bit = _mark_bitmap.addr_to_bit(dense_prefix_end); duke@435: if (dead_space_crosses_boundary(chunk, 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. duke@435: size_t obj_len = (size_t)oopDesc::header_size(); duke@435: HeapWord* obj_beg = dense_prefix_end - obj_len; duke@435: duke@435: #ifdef _LP64 duke@435: 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: duke@435: MemRegion region(obj_beg, obj_len); duke@435: SharedHeap::fill_region_with_object(region); 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 duke@435: PSParallelCompact::summarize_space(SpaceId id, bool maximum_compaction) duke@435: { duke@435: assert(id < last_space_id, "id out of range"); duke@435: duke@435: const MutableSpace* space = _space_info[id].space(); duke@435: HeapWord** new_top_addr = _space_info[id].new_top_addr(); duke@435: duke@435: HeapWord* dense_prefix_end = compute_dense_prefix(id, maximum_compaction); duke@435: _space_info[id].set_dense_prefix(dense_prefix_end); duke@435: duke@435: #ifndef PRODUCT duke@435: if (TraceParallelOldGCDensePrefix) { duke@435: print_dense_prefix_stats("ratio", id, maximum_compaction, dense_prefix_end); duke@435: HeapWord* addr = compute_dense_prefix_via_density(id, maximum_compaction); duke@435: print_dense_prefix_stats("density", id, maximum_compaction, addr); duke@435: } duke@435: #endif // #ifndef PRODUCT duke@435: duke@435: // If dead space crosses the dense prefix boundary, it is (at least partially) duke@435: // filled with a dummy object, marked live and added to the summary data. duke@435: // This simplifies the copy/update phase and must be done before the final duke@435: // locations of objects are determined, to prevent leaving a fragment of dead duke@435: // space that is too small to fill with an object. duke@435: if (!maximum_compaction && dense_prefix_end != space->bottom()) { duke@435: fill_dense_prefix_end(id); duke@435: } duke@435: duke@435: // Compute the destination of each Chunk, and thus each object. duke@435: _summary_data.summarize_dense_prefix(space->bottom(), dense_prefix_end); duke@435: _summary_data.summarize(dense_prefix_end, space->end(), duke@435: dense_prefix_end, space->top(), duke@435: new_top_addr); duke@435: duke@435: if (TraceParallelOldGCSummaryPhase) { duke@435: const size_t chunk_size = ParallelCompactData::ChunkSize; duke@435: const size_t dp_chunk = _summary_data.addr_to_chunk_idx(dense_prefix_end); duke@435: const size_t dp_words = pointer_delta(dense_prefix_end, space->bottom()); duke@435: const HeapWord* nt_aligned_up = _summary_data.chunk_align_up(*new_top_addr); 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 " " duke@435: "dp_chunk=" 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, duke@435: dp_chunk, dp_words / chunk_size, duke@435: cr_words / chunk_size, *new_top_addr); duke@435: } duke@435: } duke@435: duke@435: void PSParallelCompact::summary_phase(ParCompactionManager* cm, duke@435: bool maximum_compaction) duke@435: { duke@435: EventMark m("2 summarize"); duke@435: TraceTime tm("summary phase", print_phases(), true, gclog_or_tty); duke@435: // trace("2"); duke@435: duke@435: #ifdef ASSERT duke@435: if (VerifyParallelOldWithMarkSweep && duke@435: (PSParallelCompact::total_invocations() % duke@435: VerifyParallelOldWithMarkSweepInterval) == 0) { duke@435: verify_mark_bitmap(_mark_bitmap); duke@435: } 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(); duke@435: NOT_PRODUCT(print_chunk_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; duke@435: unsigned int id; duke@435: for (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: duke@435: const MutableSpace* old_space = _space_info[old_space_id].space(); duke@435: if (old_space_total_live > old_space->capacity_in_words()) { duke@435: // XXX - should also try to expand duke@435: maximum_compaction = true; duke@435: } else if (!UseParallelOldGCDensePrefix) { duke@435: maximum_compaction = true; duke@435: } duke@435: duke@435: // Permanent and Old generations. duke@435: summarize_space(perm_space_id, maximum_compaction); duke@435: summarize_space(old_space_id, maximum_compaction); duke@435: duke@435: // Summarize the remaining spaces (those in the young gen) into old space. If duke@435: // the live data from a space doesn't fit, the existing summarization is left duke@435: // intact, so the data is compacted down within the space itself. duke@435: HeapWord** new_top_addr = _space_info[old_space_id].new_top_addr(); duke@435: HeapWord* const target_space_end = old_space->end(); duke@435: for (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()); duke@435: const size_t available = pointer_delta(target_space_end, *new_top_addr); duke@435: if (live <= available) { duke@435: // All the live data will fit. duke@435: if (TraceParallelOldGCSummaryPhase) { duke@435: tty->print_cr("summarizing %d into old_space @ " PTR_FORMAT, duke@435: id, *new_top_addr); duke@435: } duke@435: _summary_data.summarize(*new_top_addr, target_space_end, duke@435: space->bottom(), space->top(), duke@435: new_top_addr); duke@435: duke@435: // Reset the new_top value for the space. duke@435: _space_info[id].set_new_top(space->bottom()); duke@435: duke@435: // Clear the source_chunk field for each chunk in the space. duke@435: ChunkData* beg_chunk = _summary_data.addr_to_chunk_ptr(space->bottom()); duke@435: ChunkData* end_chunk = _summary_data.addr_to_chunk_ptr(space->top() - 1); duke@435: while (beg_chunk <= end_chunk) { duke@435: beg_chunk->set_source_chunk(0); duke@435: ++beg_chunk; duke@435: } duke@435: } duke@435: } duke@435: duke@435: // Fill in the block data after any changes to the chunks have duke@435: // been made. duke@435: #ifdef ASSERT duke@435: summarize_blocks(cm, perm_space_id); duke@435: summarize_blocks(cm, old_space_id); duke@435: #else duke@435: if (!UseParallelOldGCChunkPointerCalc) { duke@435: summarize_blocks(cm, perm_space_id); duke@435: summarize_blocks(cm, old_space_id); duke@435: } duke@435: #endif duke@435: duke@435: if (TraceParallelOldGCSummaryPhase) { duke@435: tty->print_cr("summary_phase: after final summarization"); duke@435: Universe::print(); duke@435: NOT_PRODUCT(print_chunk_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: // Fill in the BlockData. duke@435: // Iterate over the spaces and within each space iterate over duke@435: // the chunks and fill in the BlockData for each chunk. duke@435: duke@435: void PSParallelCompact::summarize_blocks(ParCompactionManager* cm, duke@435: SpaceId first_compaction_space_id) { duke@435: #if 0 duke@435: DEBUG_ONLY(ParallelCompactData::BlockData::set_cur_phase(1);) duke@435: for (SpaceId cur_space_id = first_compaction_space_id; duke@435: cur_space_id != last_space_id; duke@435: cur_space_id = next_compaction_space_id(cur_space_id)) { duke@435: // Iterate over the chunks in the space duke@435: size_t start_chunk_index = duke@435: _summary_data.addr_to_chunk_idx(space(cur_space_id)->bottom()); duke@435: BitBlockUpdateClosure bbu(mark_bitmap(), duke@435: cm, duke@435: start_chunk_index); duke@435: // Iterate over blocks. duke@435: for (size_t chunk_index = start_chunk_index; duke@435: chunk_index < _summary_data.chunk_count() && duke@435: _summary_data.chunk_to_addr(chunk_index) < space(cur_space_id)->top(); duke@435: chunk_index++) { duke@435: duke@435: // Reset the closure for the new chunk. Note that the closure duke@435: // maintains some data that does not get reset for each chunk duke@435: // so a new instance of the closure is no appropriate. duke@435: bbu.reset_chunk(chunk_index); duke@435: duke@435: // Start the iteration with the first live object. This duke@435: // may return the end of the chunk. That is acceptable since duke@435: // it will properly limit the iterations. duke@435: ParMarkBitMap::idx_t left_offset = mark_bitmap()->addr_to_bit( duke@435: _summary_data.first_live_or_end_in_chunk(chunk_index)); duke@435: duke@435: // End the iteration at the end of the chunk. duke@435: HeapWord* chunk_addr = _summary_data.chunk_to_addr(chunk_index); duke@435: HeapWord* chunk_end = chunk_addr + ParallelCompactData::ChunkSize; duke@435: ParMarkBitMap::idx_t right_offset = duke@435: mark_bitmap()->addr_to_bit(chunk_end); duke@435: duke@435: // Blocks that have not objects starting in them can be duke@435: // skipped because their data will never be used. duke@435: if (left_offset < right_offset) { duke@435: duke@435: // Iterate through the objects in the chunk. duke@435: ParMarkBitMap::idx_t last_offset = duke@435: mark_bitmap()->pair_iterate(&bbu, left_offset, right_offset); duke@435: duke@435: // If last_offset is less than right_offset, then the iterations duke@435: // terminated while it was looking for an end bit. "last_offset" duke@435: // is then the offset for the last start bit. In this situation duke@435: // the "offset" field for the next block to the right (_cur_block + 1) duke@435: // will not have been update although there may be live data duke@435: // to the left of the chunk. duke@435: duke@435: size_t cur_block_plus_1 = bbu.cur_block() + 1; duke@435: HeapWord* cur_block_plus_1_addr = duke@435: _summary_data.block_to_addr(bbu.cur_block()) + duke@435: ParallelCompactData::BlockSize; duke@435: HeapWord* last_offset_addr = mark_bitmap()->bit_to_addr(last_offset); duke@435: #if 1 // This code works. The else doesn't but should. Why does it? duke@435: // The current block (cur_block()) has already been updated. duke@435: // The last block that may need to be updated is either the duke@435: // next block (current block + 1) or the block where the duke@435: // last object starts (which can be greater than the duke@435: // next block if there were no objects found in intervening duke@435: // blocks). duke@435: size_t last_block = duke@435: MAX2(bbu.cur_block() + 1, duke@435: _summary_data.addr_to_block_idx(last_offset_addr)); duke@435: #else duke@435: // The current block has already been updated. The only block duke@435: // that remains to be updated is the block where the last duke@435: // object in the chunk starts. duke@435: size_t last_block = _summary_data.addr_to_block_idx(last_offset_addr); duke@435: #endif duke@435: assert_bit_is_start(last_offset); duke@435: assert((last_block == _summary_data.block_count()) || duke@435: (_summary_data.block(last_block)->raw_offset() == 0), duke@435: "Should not have been set"); duke@435: // Is the last block still in the current chunk? If still duke@435: // in this chunk, update the last block (the counting that duke@435: // included the current block is meant for the offset of the last duke@435: // block). If not in this chunk, do nothing. Should not duke@435: // update a block in the next chunk. duke@435: if (ParallelCompactData::chunk_contains_block(bbu.chunk_index(), duke@435: last_block)) { duke@435: if (last_offset < right_offset) { duke@435: // The last object started in this chunk but ends beyond duke@435: // this chunk. Update the block for this last object. duke@435: assert(mark_bitmap()->is_marked(last_offset), "Should be marked"); duke@435: // No end bit was found. The closure takes care of duke@435: // the cases where duke@435: // an objects crosses over into the next block duke@435: // an objects starts and ends in the next block duke@435: // It does not handle the case where an object is duke@435: // the first object in a later block and extends duke@435: // past the end of the chunk (i.e., the closure duke@435: // only handles complete objects that are in the range duke@435: // it is given). That object is handed back here duke@435: // for any special consideration necessary. duke@435: // duke@435: // Is the first bit in the last block a start or end bit? duke@435: // duke@435: // If the partial object ends in the last block L, duke@435: // then the 1st bit in L may be an end bit. duke@435: // duke@435: // Else does the last object start in a block after the current duke@435: // block? A block AA will already have been updated if an duke@435: // object ends in the next block AA+1. An object found to end in duke@435: // the AA+1 is the trigger that updates AA. Objects are being duke@435: // counted in the current block for updaing a following duke@435: // block. An object may start in later block duke@435: // block but may extend beyond the last block in the chunk. duke@435: // Updates are only done when the end of an object has been duke@435: // found. If the last object (covered by block L) starts duke@435: // beyond the current block, then no object ends in L (otherwise duke@435: // L would be the current block). So the first bit in L is duke@435: // a start bit. duke@435: // duke@435: // Else the last objects start in the current block and ends duke@435: // beyond the chunk. The current block has already been duke@435: // updated and there is no later block (with an object duke@435: // starting in it) that needs to be updated. duke@435: // duke@435: if (_summary_data.partial_obj_ends_in_block(last_block)) { duke@435: _summary_data.block(last_block)->set_end_bit_offset( duke@435: bbu.live_data_left()); duke@435: } else if (last_offset_addr >= cur_block_plus_1_addr) { duke@435: // The start of the object is on a later block duke@435: // (to the right of the current block and there are no duke@435: // complete live objects to the left of this last object duke@435: // within the chunk. duke@435: // The first bit in the block is for the start of the duke@435: // last object. duke@435: _summary_data.block(last_block)->set_start_bit_offset( duke@435: bbu.live_data_left()); duke@435: } else { duke@435: // The start of the last object was found in duke@435: // the current chunk (which has already duke@435: // been updated). duke@435: assert(bbu.cur_block() == duke@435: _summary_data.addr_to_block_idx(last_offset_addr), duke@435: "Should be a block already processed"); duke@435: } duke@435: #ifdef ASSERT duke@435: // Is there enough block information to find this object? duke@435: // The destination of the chunk has not been set so the duke@435: // values returned by calc_new_pointer() and duke@435: // block_calc_new_pointer() will only be duke@435: // offsets. But they should agree. duke@435: HeapWord* moved_obj_with_chunks = duke@435: _summary_data.chunk_calc_new_pointer(last_offset_addr); duke@435: HeapWord* moved_obj_with_blocks = duke@435: _summary_data.calc_new_pointer(last_offset_addr); duke@435: assert(moved_obj_with_chunks == moved_obj_with_blocks, duke@435: "Block calculation is wrong"); duke@435: #endif duke@435: } else if (last_block < _summary_data.block_count()) { duke@435: // Iterations ended looking for a start bit (but duke@435: // did not run off the end of the block table). duke@435: _summary_data.block(last_block)->set_start_bit_offset( duke@435: bbu.live_data_left()); duke@435: } duke@435: } duke@435: #ifdef ASSERT duke@435: // Is there enough block information to find this object? duke@435: HeapWord* left_offset_addr = mark_bitmap()->bit_to_addr(left_offset); duke@435: HeapWord* moved_obj_with_chunks = duke@435: _summary_data.calc_new_pointer(left_offset_addr); duke@435: HeapWord* moved_obj_with_blocks = duke@435: _summary_data.calc_new_pointer(left_offset_addr); duke@435: assert(moved_obj_with_chunks == moved_obj_with_blocks, duke@435: "Block calculation is wrong"); duke@435: #endif duke@435: duke@435: // Is there another block after the end of this chunk? duke@435: #ifdef ASSERT duke@435: if (last_block < _summary_data.block_count()) { duke@435: // No object may have been found in a block. If that duke@435: // block is at the end of the chunk, the iteration will duke@435: // terminate without incrementing the current block so duke@435: // that the current block is not the last block in the duke@435: // chunk. That situation precludes asserting that the duke@435: // current block is the last block in the chunk. Assert duke@435: // the lesser condition that the current block does not duke@435: // exceed the chunk. duke@435: assert(_summary_data.block_to_addr(last_block) <= duke@435: (_summary_data.chunk_to_addr(chunk_index) + duke@435: ParallelCompactData::ChunkSize), duke@435: "Chunk and block inconsistency"); duke@435: assert(last_offset <= right_offset, "Iteration over ran end"); duke@435: } duke@435: #endif duke@435: } duke@435: #ifdef ASSERT duke@435: if (PrintGCDetails && Verbose) { duke@435: if (_summary_data.chunk(chunk_index)->partial_obj_size() == 1) { duke@435: size_t first_block = duke@435: chunk_index / ParallelCompactData::BlocksPerChunk; duke@435: gclog_or_tty->print_cr("first_block " PTR_FORMAT duke@435: " _offset " PTR_FORMAT duke@435: "_first_is_start_bit %d", duke@435: first_block, duke@435: _summary_data.block(first_block)->raw_offset(), duke@435: _summary_data.block(first_block)->first_is_start_bit()); duke@435: } duke@435: } duke@435: #endif duke@435: } duke@435: } duke@435: DEBUG_ONLY(ParallelCompactData::BlockData::set_cur_phase(16);) duke@435: #endif // #if 0 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. 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"); 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(); duke@435: duke@435: // Before each allocation/collection attempt, find out from the duke@435: // policy object if GCs are, on the whole, taking too long. If so, duke@435: // bail out without attempting a collection. The exceptions are duke@435: // for explicitly requested GC's. duke@435: if (!policy->gc_time_limit_exceeded() || duke@435: GCCause::is_user_requested_gc(gc_cause) || duke@435: GCCause::is_serviceability_requested_gc(gc_cause)) { duke@435: IsGCActiveMark mark; duke@435: duke@435: if (ScavengeBeforeFullGC) { duke@435: PSScavenge::invoke_no_policy(); duke@435: } duke@435: duke@435: PSParallelCompact::invoke_no_policy(maximum_heap_compaction); duke@435: } duke@435: } duke@435: duke@435: bool ParallelCompactData::chunk_contains(size_t chunk_index, HeapWord* addr) { duke@435: size_t addr_chunk_index = addr_to_chunk_idx(addr); duke@435: return chunk_index == addr_chunk_index; duke@435: } duke@435: duke@435: bool ParallelCompactData::chunk_contains_block(size_t chunk_index, duke@435: size_t block_index) { duke@435: size_t first_block_in_chunk = chunk_index * BlocksPerChunk; duke@435: size_t last_block_in_chunk = (chunk_index + 1) * BlocksPerChunk - 1; duke@435: duke@435: return (first_block_in_chunk <= block_index) && duke@435: (block_index <= last_block_in_chunk); duke@435: } duke@435: duke@435: // This method contains no policy. You should probably duke@435: // be calling invoke() instead. duke@435: void 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()) { duke@435: return; duke@435: } duke@435: duke@435: TimeStamp marking_start; duke@435: TimeStamp compaction_start; duke@435: TimeStamp collection_exit; duke@435: duke@435: ParallelScavengeHeap* heap = gc_heap(); 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: PSPermGen* perm_gen = heap->perm_gen(); duke@435: PSAdaptiveSizePolicy* size_policy = heap->size_policy(); duke@435: 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: duke@435: const bool is_system_gc = gc_cause == GCCause::_java_lang_system_gc; duke@435: duke@435: // This is useful for debugging but don't change the output the duke@435: // the customer sees. duke@435: const char* gc_cause_str = "Full GC"; duke@435: if (is_system_gc && PrintGCDetails) { duke@435: gc_cause_str = "Full GC (System)"; duke@435: } duke@435: gclog_or_tty->date_stamp(PrintGC && PrintGCDateStamps); duke@435: TraceCPUTime tcpu(PrintGCDetails, true, gclog_or_tty); duke@435: TraceTime t1(gc_cause_str, PrintGC, !PrintGCDetails, gclog_or_tty); duke@435: TraceCollectorStats tcs(counters()); duke@435: TraceMemoryManagerStats tms(true /* Full GC */); 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: // When collecting the permanent generation methodOops may be moving, duke@435: // so we either have to flush all bcp data or convert it into bci. duke@435: CodeCache::gc_prologue(); duke@435: Threads::gc_prologue(); duke@435: duke@435: NOT_PRODUCT(ref_processor()->verify_no_references_recorded()); duke@435: COMPILER2_PRESENT(DerivedPointerTable::clear()); duke@435: duke@435: ref_processor()->enable_discovery(); duke@435: duke@435: bool marked_for_unloading = false; duke@435: duke@435: marking_start.update(); jcoomes@645: marking_phase(vmthread_cm, maximum_heap_compaction); duke@435: duke@435: #ifndef PRODUCT duke@435: if (TraceParallelOldGCMarkingPhase) { duke@435: gclog_or_tty->print_cr("marking_phase: cas_tries %d cas_retries %d " duke@435: "cas_by_another %d", duke@435: mark_bitmap()->cas_tries(), mark_bitmap()->cas_retries(), duke@435: mark_bitmap()->cas_by_another()); duke@435: } duke@435: #endif // #ifndef PRODUCT duke@435: duke@435: #ifdef ASSERT duke@435: if (VerifyParallelOldWithMarkSweep && duke@435: (PSParallelCompact::total_invocations() % duke@435: VerifyParallelOldWithMarkSweepInterval) == 0) { duke@435: gclog_or_tty->print_cr("Verify marking with mark_sweep_phase1()"); duke@435: if (PrintGCDetails && Verbose) { duke@435: gclog_or_tty->print_cr("mark_sweep_phase1:"); duke@435: } duke@435: // Clear the discovered lists so that discovered objects duke@435: // don't look like they have been discovered twice. duke@435: ref_processor()->clear_discovered_references(); duke@435: duke@435: PSMarkSweep::allocate_stacks(); duke@435: MemRegion mr = Universe::heap()->reserved_region(); duke@435: PSMarkSweep::ref_processor()->enable_discovery(); duke@435: PSMarkSweep::mark_sweep_phase1(maximum_heap_compaction); duke@435: } duke@435: #endif duke@435: duke@435: bool max_on_system_gc = UseMaximumCompactionOnSystemGC && is_system_gc; jcoomes@645: summary_phase(vmthread_cm, maximum_heap_compaction || max_on_system_gc); duke@435: duke@435: #ifdef ASSERT duke@435: if (VerifyParallelOldWithMarkSweep && duke@435: (PSParallelCompact::total_invocations() % duke@435: VerifyParallelOldWithMarkSweepInterval) == 0) { duke@435: if (PrintGCDetails && Verbose) { duke@435: gclog_or_tty->print_cr("mark_sweep_phase2:"); duke@435: } duke@435: PSMarkSweep::mark_sweep_phase2(); duke@435: } duke@435: #endif 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: #ifdef ASSERT duke@435: if (VerifyParallelOldWithMarkSweep && duke@435: (PSParallelCompact::total_invocations() % duke@435: VerifyParallelOldWithMarkSweepInterval) == 0) { duke@435: // Do a separate verify phase so that the verify duke@435: // code can use the the forwarding pointers to duke@435: // check the new pointer calculation. The restore_marks() duke@435: // has to be done before the real compact. jcoomes@645: vmthread_cm->set_action(ParCompactionManager::VerifyUpdate); jcoomes@645: compact_perm(vmthread_cm); jcoomes@645: compact_serial(vmthread_cm); jcoomes@645: vmthread_cm->set_action(ParCompactionManager::ResetObjects); jcoomes@645: compact_perm(vmthread_cm); jcoomes@645: compact_serial(vmthread_cm); jcoomes@645: vmthread_cm->set_action(ParCompactionManager::UpdateAndCopy); duke@435: duke@435: // For debugging only duke@435: PSMarkSweep::restore_marks(); duke@435: PSMarkSweep::deallocate_stacks(); duke@435: } duke@435: #endif duke@435: duke@435: compaction_start.update(); duke@435: // Does the perm gen always have to be done serially because duke@435: // klasses are used in the update of an object? jcoomes@645: compact_perm(vmthread_cm); duke@435: duke@435: if (UseParallelOldGCCompacting) { duke@435: compact(); duke@435: } else { jcoomes@645: compact_serial(vmthread_cm); duke@435: } 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) { duke@435: gclog_or_tty->print("old_gen_capacity: %d young_gen_capacity: %d" duke@435: " perm_gen_capacity: %d ", duke@435: old_gen->capacity_in_bytes(), young_gen->capacity_in_bytes(), duke@435: perm_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"); 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(); duke@435: size_policy->compute_generation_free_space(young_gen->used_in_bytes(), duke@435: young_gen->eden_space()->used_in_bytes(), duke@435: old_gen->used_in_bytes(), duke@435: perm_gen->used_in_bytes(), duke@435: young_gen->eden_space()->capacity_in_bytes(), duke@435: old_gen->max_gen_size(), duke@435: max_eden_size, duke@435: true /* full gc*/, duke@435: gc_cause); duke@435: duke@435: heap->resize_old_gen(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: duke@435: // We collected the perm gen, so we'll resize it here. duke@435: perm_gen->compute_new_size(pre_gc_values.perm_gen_used()); 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()); duke@435: // Print perm gen last (print_heap_change() excludes the perm gen). duke@435: perm_gen->print_used_change(pre_gc_values.perm_gen_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(); duke@435: duke@435: if (PrintGCDetails) { duke@435: if (size_policy->print_gc_time_limit_would_be_exceeded()) { duke@435: if (size_policy->gc_time_limit_exceeded()) { duke@435: gclog_or_tty->print_cr(" GC time is exceeding GCTimeLimit " duke@435: "of %d%%", GCTimeLimit); duke@435: } else { duke@435: gclog_or_tty->print_cr(" GC time would exceed GCTimeLimit " duke@435: "of %d%%", GCTimeLimit); duke@435: } duke@435: } duke@435: size_policy->set_print_gc_time_limit_would_be_exceeded(false); duke@435: } duke@435: } duke@435: duke@435: if (VerifyAfterGC && heap->total_collections() >= VerifyGCStartAt) { duke@435: HandleMark hm; // Discard invalid handles created during verification duke@435: gclog_or_tty->print(" VerifyAfterGC:"); duke@435: Universe::verify(false); 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: perm_gen->verify_object_start_array(); duke@435: } duke@435: duke@435: NOT_PRODUCT(ref_processor()->verify_no_references_recorded()); duke@435: duke@435: collection_exit.update(); duke@435: duke@435: if (PrintHeapAtGC) { duke@435: Universe::print_heap_after_gc(); duke@435: } 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: } 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(); duke@435: MemRegion old_gen_unused(old_space->top(), old_space->end()); duke@435: if (!old_gen_unused.is_empty()) { duke@435: SharedHeap::fill_region_with_object(old_gen_unused); 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(); duke@435: HeapWord* const start = old_gen_unused.start(); duke@435: for (HeapWord* addr = start; addr < new_top; addr += oop(addr)->size()) { duke@435: start_array->allocate_block(addr); 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, duke@435: bool maximum_heap_compaction) { duke@435: // Recursively traverse all live objects and mark them duke@435: EventMark m("1 mark object"); duke@435: TraceTime tm("marking phase", print_phases(), true, gclog_or_tty); duke@435: duke@435: ParallelScavengeHeap* heap = gc_heap(); duke@435: uint parallel_gc_threads = heap->gc_task_manager()->workers(); duke@435: TaskQueueSetSuper* qset = ParCompactionManager::chunk_array(); duke@435: ParallelTaskTerminator terminator(parallel_gc_threads, qset); duke@435: duke@435: PSParallelCompact::MarkAndPushClosure mark_and_push_closure(cm); duke@435: PSParallelCompact::FollowStackClosure follow_stack_closure(cm); duke@435: duke@435: { duke@435: TraceTime tm_m("par mark", print_phases(), true, gclog_or_tty); 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)); duke@435: q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::jvmti)); duke@435: q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::vm_symbols)); duke@435: duke@435: if (parallel_gc_threads > 1) { duke@435: for (uint j = 0; j < parallel_gc_threads; j++) { duke@435: q->enqueue(new StealMarkingTask(&terminator)); duke@435: } duke@435: } duke@435: duke@435: WaitForBarrierGCTask* fin = WaitForBarrierGCTask::create(); duke@435: q->enqueue(fin); duke@435: duke@435: gc_task_manager()->add_list(q); duke@435: duke@435: fin->wait_for(); duke@435: duke@435: // We have to release the barrier tasks! duke@435: WaitForBarrierGCTask::destroy(fin); duke@435: } duke@435: duke@435: // Process reference objects found during marking duke@435: { duke@435: TraceTime tm_r("reference processing", print_phases(), true, gclog_or_tty); duke@435: ReferencePolicy *soft_ref_policy; duke@435: if (maximum_heap_compaction) { duke@435: soft_ref_policy = new AlwaysClearPolicy(); duke@435: } else { duke@435: #ifdef COMPILER2 duke@435: soft_ref_policy = new LRUMaxHeapPolicy(); duke@435: #else duke@435: soft_ref_policy = new LRUCurrentHeapPolicy(); duke@435: #endif // COMPILER2 duke@435: } duke@435: assert(soft_ref_policy != NULL, "No soft reference policy"); duke@435: if (ref_processor()->processing_is_mt()) { duke@435: RefProcTaskExecutor task_executor; duke@435: ref_processor()->process_discovered_references( duke@435: soft_ref_policy, is_alive_closure(), &mark_and_push_closure, duke@435: &follow_stack_closure, &task_executor); duke@435: } else { duke@435: ref_processor()->process_discovered_references( duke@435: soft_ref_policy, is_alive_closure(), &mark_and_push_closure, duke@435: &follow_stack_closure, NULL); duke@435: } duke@435: } duke@435: duke@435: TraceTime tm_c("class unloading", print_phases(), true, gclog_or_tty); duke@435: // Follow system dictionary roots and unload classes. duke@435: bool purged_class = SystemDictionary::do_unloading(is_alive_closure()); duke@435: duke@435: // Follow code cache roots. duke@435: CodeCache::do_unloading(is_alive_closure(), &mark_and_push_closure, duke@435: purged_class); duke@435: follow_stack(cm); // Flush marking stack. duke@435: duke@435: // Update subklass/sibling/implementor links of live klasses duke@435: // revisit_klass_stack is used in follow_weak_klass_links(). duke@435: follow_weak_klass_links(cm); duke@435: duke@435: // Visit symbol and interned string tables and delete unmarked oops duke@435: SymbolTable::unlink(is_alive_closure()); duke@435: StringTable::unlink(is_alive_closure()); duke@435: duke@435: assert(cm->marking_stack()->size() == 0, "stack should be empty by now"); duke@435: assert(cm->overflow_stack()->is_empty(), "stack should be empty by now"); duke@435: } duke@435: duke@435: // This should be moved to the shared markSweep code! duke@435: class PSAlwaysTrueClosure: public BoolObjectClosure { duke@435: public: duke@435: void do_object(oop p) { ShouldNotReachHere(); } 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 duke@435: EventMark m("3 adjust roots"); duke@435: TraceTime tm("adjust roots", print_phases(), true, gclog_or_tty); duke@435: duke@435: // General strong roots. duke@435: Universe::oops_do(adjust_root_pointer_closure()); duke@435: ReferenceProcessor::oops_do(adjust_root_pointer_closure()); duke@435: JNIHandles::oops_do(adjust_root_pointer_closure()); // Global (strong) JNI handles duke@435: Threads::oops_do(adjust_root_pointer_closure()); duke@435: ObjectSynchronizer::oops_do(adjust_root_pointer_closure()); duke@435: FlatProfiler::oops_do(adjust_root_pointer_closure()); duke@435: Management::oops_do(adjust_root_pointer_closure()); duke@435: JvmtiExport::oops_do(adjust_root_pointer_closure()); duke@435: // SO_AllClasses duke@435: SystemDictionary::oops_do(adjust_root_pointer_closure()); duke@435: vmSymbols::oops_do(adjust_root_pointer_closure()); 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 duke@435: JNIHandles::weak_oops_do(&always_true, adjust_root_pointer_closure()); duke@435: duke@435: CodeCache::oops_do(adjust_pointer_closure()); duke@435: SymbolTable::oops_do(adjust_root_pointer_closure()); duke@435: StringTable::oops_do(adjust_root_pointer_closure()); duke@435: ref_processor()->weak_oops_do(adjust_root_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? duke@435: PSScavenge::reference_processor()->weak_oops_do( duke@435: adjust_root_pointer_closure()); duke@435: } duke@435: duke@435: void PSParallelCompact::compact_perm(ParCompactionManager* cm) { duke@435: EventMark m("4 compact perm"); duke@435: TraceTime tm("compact perm gen", print_phases(), true, gclog_or_tty); duke@435: // trace("4"); duke@435: duke@435: gc_heap()->perm_gen()->start_array()->reset(); duke@435: move_and_update(cm, perm_space_id); duke@435: } duke@435: duke@435: void PSParallelCompact::enqueue_chunk_draining_tasks(GCTaskQueue* q, duke@435: uint parallel_gc_threads) { duke@435: TraceTime tm("drain task setup", print_phases(), true, gclog_or_tty); duke@435: duke@435: const unsigned int task_count = MAX2(parallel_gc_threads, 1U); duke@435: for (unsigned int j = 0; j < task_count; j++) { duke@435: q->enqueue(new DrainStacksCompactionTask()); duke@435: } duke@435: duke@435: // Find all chunks that are available (can be filled immediately) and duke@435: // distribute them to the thread stacks. The iteration is done in reverse duke@435: // order (high to low) so the chunks will be removed in ascending order. duke@435: duke@435: const ParallelCompactData& sd = PSParallelCompact::summary_data(); duke@435: duke@435: size_t fillable_chunks = 0; // A count for diagnostic purposes. duke@435: unsigned int which = 0; // The worker thread number. duke@435: duke@435: for (unsigned int id = to_space_id; id > perm_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: duke@435: const size_t beg_chunk = sd.addr_to_chunk_idx(space_info->dense_prefix()); duke@435: const size_t end_chunk = sd.addr_to_chunk_idx(sd.chunk_align_up(new_top)); duke@435: assert(end_chunk > 0, "perm gen cannot be empty"); duke@435: duke@435: for (size_t cur = end_chunk - 1; cur >= beg_chunk; --cur) { duke@435: if (sd.chunk(cur)->claim_unsafe()) { duke@435: ParCompactionManager* cm = ParCompactionManager::manager_array(which); duke@435: cm->save_for_processing(cur); duke@435: duke@435: if (TraceParallelOldGCCompactionPhase && Verbose) { duke@435: const size_t count_mod_8 = fillable_chunks & 7; duke@435: if (count_mod_8 == 0) gclog_or_tty->print("fillable: "); duke@435: gclog_or_tty->print(" " SIZE_FORMAT_W("7"), cur); duke@435: if (count_mod_8 == 7) gclog_or_tty->cr(); duke@435: } duke@435: duke@435: NOT_PRODUCT(++fillable_chunks;) duke@435: duke@435: // Assign chunks to threads in round-robin fashion. duke@435: if (++which == task_count) { duke@435: which = 0; duke@435: } duke@435: } duke@435: } duke@435: } duke@435: duke@435: if (TraceParallelOldGCCompactionPhase) { duke@435: if (Verbose && (fillable_chunks & 7) != 0) gclog_or_tty->cr(); duke@435: gclog_or_tty->print_cr("%u initially fillable chunks", fillable_chunks); 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) { duke@435: TraceTime tm("dense prefix task setup", print_phases(), true, gclog_or_tty); duke@435: duke@435: ParallelCompactData& sd = PSParallelCompact::summary_data(); duke@435: duke@435: // Iterate over all the spaces adding tasks for updating duke@435: // chunks 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. duke@435: SpaceId space_id = old_space_id; duke@435: while (space_id != last_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: space_id = next_compaction_space_id(space_id); duke@435: continue; duke@435: } duke@435: duke@435: // The dense prefix is before this chunk. duke@435: size_t chunk_index_end_dense_prefix = duke@435: sd.addr_to_chunk_idx(dense_prefix_end); duke@435: ChunkData* const dense_prefix_cp = sd.chunk(chunk_index_end_dense_prefix); duke@435: assert(dense_prefix_end == space->end() || duke@435: dense_prefix_cp->available() || duke@435: dense_prefix_cp->claimed(), duke@435: "The chunk after the dense prefix should always be ready to fill"); duke@435: duke@435: size_t chunk_index_start = sd.addr_to_chunk_idx(space->bottom()); duke@435: duke@435: // Is there dense prefix work? duke@435: size_t total_dense_prefix_chunks = duke@435: chunk_index_end_dense_prefix - chunk_index_start; duke@435: // How many chunks of the dense prefix should be given to duke@435: // each thread? duke@435: if (total_dense_prefix_chunks > 0) { duke@435: uint tasks_for_dense_prefix = 1; duke@435: if (UseParallelDensePrefixUpdate) { duke@435: if (total_dense_prefix_chunks <= duke@435: (parallel_gc_threads * PAR_OLD_DENSE_PREFIX_OVER_PARTITIONING)) { duke@435: // Don't over partition. This assumes that duke@435: // PAR_OLD_DENSE_PREFIX_OVER_PARTITIONING is a small integer value duke@435: // so there are not many chunks to process. duke@435: tasks_for_dense_prefix = parallel_gc_threads; duke@435: } else { duke@435: // Over partition duke@435: tasks_for_dense_prefix = parallel_gc_threads * duke@435: PAR_OLD_DENSE_PREFIX_OVER_PARTITIONING; duke@435: } duke@435: } duke@435: size_t chunks_per_thread = total_dense_prefix_chunks / duke@435: tasks_for_dense_prefix; duke@435: // Give each thread at least 1 chunk. duke@435: if (chunks_per_thread == 0) { duke@435: chunks_per_thread = 1; duke@435: } duke@435: duke@435: for (uint k = 0; k < tasks_for_dense_prefix; k++) { duke@435: if (chunk_index_start >= chunk_index_end_dense_prefix) { duke@435: break; duke@435: } duke@435: // chunk_index_end is not processed duke@435: size_t chunk_index_end = MIN2(chunk_index_start + chunks_per_thread, duke@435: chunk_index_end_dense_prefix); duke@435: q->enqueue(new UpdateDensePrefixTask( duke@435: space_id, duke@435: chunk_index_start, duke@435: chunk_index_end)); duke@435: chunk_index_start = chunk_index_end; duke@435: } duke@435: } duke@435: // This gets any part of the dense prefix that did not duke@435: // fit evenly. duke@435: if (chunk_index_start < chunk_index_end_dense_prefix) { duke@435: q->enqueue(new UpdateDensePrefixTask( duke@435: space_id, duke@435: chunk_index_start, duke@435: chunk_index_end_dense_prefix)); duke@435: } duke@435: space_id = next_compaction_space_id(space_id); duke@435: } // End tasks for dense prefix duke@435: } duke@435: duke@435: void PSParallelCompact::enqueue_chunk_stealing_tasks( duke@435: GCTaskQueue* q, duke@435: ParallelTaskTerminator* terminator_ptr, duke@435: uint parallel_gc_threads) { duke@435: TraceTime tm("steal task setup", print_phases(), true, gclog_or_tty); duke@435: duke@435: // Once a thread has drained it's stack, it should try to steal chunks from duke@435: // other threads. duke@435: if (parallel_gc_threads > 1) { duke@435: for (uint j = 0; j < parallel_gc_threads; j++) { duke@435: q->enqueue(new StealChunkCompactionTask(terminator_ptr)); duke@435: } duke@435: } duke@435: } duke@435: duke@435: void PSParallelCompact::compact() { duke@435: EventMark m("5 compact"); duke@435: // trace("5"); duke@435: TraceTime tm("compaction phase", print_phases(), true, gclog_or_tty); 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(); duke@435: TaskQueueSetSuper* qset = ParCompactionManager::chunk_array(); duke@435: ParallelTaskTerminator terminator(parallel_gc_threads, qset); duke@435: duke@435: GCTaskQueue* q = GCTaskQueue::create(); duke@435: enqueue_chunk_draining_tasks(q, parallel_gc_threads); duke@435: enqueue_dense_prefix_tasks(q, parallel_gc_threads); duke@435: enqueue_chunk_stealing_tasks(q, &terminator, parallel_gc_threads); duke@435: duke@435: { duke@435: TraceTime tm_pc("par compact", print_phases(), true, gclog_or_tty); duke@435: duke@435: WaitForBarrierGCTask* fin = WaitForBarrierGCTask::create(); duke@435: q->enqueue(fin); duke@435: duke@435: gc_task_manager()->add_list(q); duke@435: duke@435: fin->wait_for(); duke@435: duke@435: // We have to release the barrier tasks! duke@435: WaitForBarrierGCTask::destroy(fin); duke@435: duke@435: #ifdef ASSERT duke@435: // Verify that all chunks have been processed before the deferred updates. duke@435: // Note that perm_space_id is skipped; this type of verification is not duke@435: // valid until the perm gen is compacted by chunks. 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. duke@435: TraceTime tm_du("deferred updates", print_phases(), true, gclog_or_tty); 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: } duke@435: } duke@435: duke@435: #ifdef ASSERT duke@435: void PSParallelCompact::verify_complete(SpaceId space_id) { duke@435: // All Chunks between space bottom() to new_top() should be marked as filled duke@435: // and all Chunks 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]; duke@435: HeapWord* new_top_addr = sd.chunk_align_up(si.new_top()); duke@435: HeapWord* old_top_addr = sd.chunk_align_up(si.space()->top()); duke@435: const size_t beg_chunk = sd.addr_to_chunk_idx(si.space()->bottom()); duke@435: const size_t new_top_chunk = sd.addr_to_chunk_idx(new_top_addr); duke@435: const size_t old_top_chunk = sd.addr_to_chunk_idx(old_top_addr); duke@435: duke@435: bool issued_a_warning = false; duke@435: duke@435: size_t cur_chunk; duke@435: for (cur_chunk = beg_chunk; cur_chunk < new_top_chunk; ++cur_chunk) { duke@435: const ChunkData* const c = sd.chunk(cur_chunk); duke@435: if (!c->completed()) { duke@435: warning("chunk " SIZE_FORMAT " not filled: " duke@435: "destination_count=" SIZE_FORMAT, duke@435: cur_chunk, c->destination_count()); duke@435: issued_a_warning = true; duke@435: } duke@435: } duke@435: duke@435: for (cur_chunk = new_top_chunk; cur_chunk < old_top_chunk; ++cur_chunk) { duke@435: const ChunkData* const c = sd.chunk(cur_chunk); duke@435: if (!c->available()) { duke@435: warning("chunk " SIZE_FORMAT " not empty: " duke@435: "destination_count=" SIZE_FORMAT, duke@435: cur_chunk, c->destination_count()); duke@435: issued_a_warning = true; duke@435: } duke@435: } duke@435: duke@435: if (issued_a_warning) { duke@435: print_chunk_ranges(); duke@435: } duke@435: } duke@435: #endif // #ifdef ASSERT duke@435: duke@435: void PSParallelCompact::compact_serial(ParCompactionManager* cm) { duke@435: EventMark m("5 compact serial"); duke@435: TraceTime tm("compact serial", print_phases(), true, gclog_or_tty); duke@435: duke@435: ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap(); duke@435: assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity"); duke@435: duke@435: PSYoungGen* young_gen = heap->young_gen(); duke@435: PSOldGen* old_gen = heap->old_gen(); duke@435: duke@435: old_gen->start_array()->reset(); duke@435: old_gen->move_and_update(cm); duke@435: young_gen->move_and_update(cm); duke@435: } duke@435: duke@435: duke@435: void PSParallelCompact::follow_stack(ParCompactionManager* cm) { duke@435: while(!cm->overflow_stack()->is_empty()) { duke@435: oop obj = cm->overflow_stack()->pop(); duke@435: obj->follow_contents(cm); duke@435: } duke@435: duke@435: oop obj; duke@435: // obj is a reference!!! duke@435: while (cm->marking_stack()->pop_local(obj)) { duke@435: // It would be nice to assert about the type of objects we might duke@435: // pop, but they can come from anywhere, unfortunately. duke@435: obj->follow_contents(cm); duke@435: } duke@435: } duke@435: duke@435: void duke@435: PSParallelCompact::follow_weak_klass_links(ParCompactionManager* serial_cm) { duke@435: // All klasses on the revisit stack are marked at this point. duke@435: // Update and follow all subklass, sibling and implementor links. duke@435: for (uint i = 0; i < ParallelGCThreads+1; i++) { duke@435: ParCompactionManager* cm = ParCompactionManager::manager_array(i); duke@435: KeepAliveClosure keep_alive_closure(cm); duke@435: for (int i = 0; i < cm->revisit_klass_stack()->length(); i++) { duke@435: cm->revisit_klass_stack()->at(i)->follow_weak_klass_links( duke@435: is_alive_closure(), duke@435: &keep_alive_closure); duke@435: } duke@435: follow_stack(cm); duke@435: } duke@435: } duke@435: duke@435: void duke@435: PSParallelCompact::revisit_weak_klass_link(ParCompactionManager* cm, Klass* k) { duke@435: cm->revisit_klass_stack()->push(k); duke@435: } duke@435: duke@435: #ifdef VALIDATE_MARK_SWEEP duke@435: coleenp@548: void PSParallelCompact::track_adjusted_pointer(void* p, bool isroot) { duke@435: if (!ValidateMarkSweep) duke@435: return; duke@435: duke@435: if (!isroot) { duke@435: if (_pointer_tracking) { duke@435: guarantee(_adjusted_pointers->contains(p), "should have seen this pointer"); duke@435: _adjusted_pointers->remove(p); duke@435: } duke@435: } else { duke@435: ptrdiff_t index = _root_refs_stack->find(p); duke@435: if (index != -1) { duke@435: int l = _root_refs_stack->length(); duke@435: if (l > 0 && l - 1 != index) { coleenp@548: void* last = _root_refs_stack->pop(); duke@435: assert(last != p, "should be different"); duke@435: _root_refs_stack->at_put(index, last); duke@435: } else { duke@435: _root_refs_stack->remove(p); duke@435: } duke@435: } duke@435: } duke@435: } duke@435: duke@435: coleenp@548: void PSParallelCompact::check_adjust_pointer(void* p) { duke@435: _adjusted_pointers->push(p); duke@435: } duke@435: duke@435: duke@435: class AdjusterTracker: public OopClosure { duke@435: public: duke@435: AdjusterTracker() {}; coleenp@548: void do_oop(oop* o) { PSParallelCompact::check_adjust_pointer(o); } coleenp@548: void do_oop(narrowOop* o) { PSParallelCompact::check_adjust_pointer(o); } duke@435: }; duke@435: duke@435: duke@435: void PSParallelCompact::track_interior_pointers(oop obj) { duke@435: if (ValidateMarkSweep) { duke@435: _adjusted_pointers->clear(); duke@435: _pointer_tracking = true; duke@435: duke@435: AdjusterTracker checker; duke@435: obj->oop_iterate(&checker); duke@435: } duke@435: } duke@435: duke@435: duke@435: void PSParallelCompact::check_interior_pointers() { duke@435: if (ValidateMarkSweep) { duke@435: _pointer_tracking = false; duke@435: guarantee(_adjusted_pointers->length() == 0, "should have processed the same pointers"); duke@435: } duke@435: } duke@435: duke@435: duke@435: void PSParallelCompact::reset_live_oop_tracking(bool at_perm) { duke@435: if (ValidateMarkSweep) { duke@435: guarantee((size_t)_live_oops->length() == _live_oops_index, "should be at end of live oops"); duke@435: _live_oops_index = at_perm ? _live_oops_index_at_perm : 0; duke@435: } duke@435: } duke@435: duke@435: duke@435: void PSParallelCompact::register_live_oop(oop p, size_t size) { duke@435: if (ValidateMarkSweep) { duke@435: _live_oops->push(p); duke@435: _live_oops_size->push(size); duke@435: _live_oops_index++; duke@435: } duke@435: } duke@435: duke@435: void PSParallelCompact::validate_live_oop(oop p, size_t size) { duke@435: if (ValidateMarkSweep) { duke@435: oop obj = _live_oops->at((int)_live_oops_index); duke@435: guarantee(obj == p, "should be the same object"); duke@435: guarantee(_live_oops_size->at((int)_live_oops_index) == size, "should be the same size"); duke@435: _live_oops_index++; duke@435: } duke@435: } duke@435: duke@435: void PSParallelCompact::live_oop_moved_to(HeapWord* q, size_t size, duke@435: HeapWord* compaction_top) { duke@435: assert(oop(q)->forwardee() == NULL || oop(q)->forwardee() == oop(compaction_top), duke@435: "should be moved to forwarded location"); duke@435: if (ValidateMarkSweep) { duke@435: PSParallelCompact::validate_live_oop(oop(q), size); duke@435: _live_oops_moved_to->push(oop(compaction_top)); duke@435: } duke@435: if (RecordMarkSweepCompaction) { duke@435: _cur_gc_live_oops->push(q); duke@435: _cur_gc_live_oops_moved_to->push(compaction_top); duke@435: _cur_gc_live_oops_size->push(size); duke@435: } duke@435: } duke@435: duke@435: duke@435: void PSParallelCompact::compaction_complete() { duke@435: if (RecordMarkSweepCompaction) { duke@435: GrowableArray* _tmp_live_oops = _cur_gc_live_oops; duke@435: GrowableArray* _tmp_live_oops_moved_to = _cur_gc_live_oops_moved_to; duke@435: GrowableArray * _tmp_live_oops_size = _cur_gc_live_oops_size; duke@435: duke@435: _cur_gc_live_oops = _last_gc_live_oops; duke@435: _cur_gc_live_oops_moved_to = _last_gc_live_oops_moved_to; duke@435: _cur_gc_live_oops_size = _last_gc_live_oops_size; duke@435: _last_gc_live_oops = _tmp_live_oops; duke@435: _last_gc_live_oops_moved_to = _tmp_live_oops_moved_to; duke@435: _last_gc_live_oops_size = _tmp_live_oops_size; duke@435: } duke@435: } duke@435: duke@435: duke@435: void PSParallelCompact::print_new_location_of_heap_address(HeapWord* q) { duke@435: if (!RecordMarkSweepCompaction) { duke@435: tty->print_cr("Requires RecordMarkSweepCompaction to be enabled"); duke@435: return; duke@435: } duke@435: duke@435: if (_last_gc_live_oops == NULL) { duke@435: tty->print_cr("No compaction information gathered yet"); duke@435: return; duke@435: } duke@435: duke@435: for (int i = 0; i < _last_gc_live_oops->length(); i++) { duke@435: HeapWord* old_oop = _last_gc_live_oops->at(i); duke@435: size_t sz = _last_gc_live_oops_size->at(i); duke@435: if (old_oop <= q && q < (old_oop + sz)) { duke@435: HeapWord* new_oop = _last_gc_live_oops_moved_to->at(i); duke@435: size_t offset = (q - old_oop); duke@435: tty->print_cr("Address " PTR_FORMAT, q); duke@435: tty->print_cr(" Was in oop " PTR_FORMAT ", size %d, at offset %d", old_oop, sz, offset); duke@435: tty->print_cr(" Now in oop " PTR_FORMAT ", actual address " PTR_FORMAT, new_oop, new_oop + offset); duke@435: return; duke@435: } duke@435: } duke@435: duke@435: tty->print_cr("Address " PTR_FORMAT " not found in live oop information from last GC", q); duke@435: } duke@435: #endif //VALIDATE_MARK_SWEEP duke@435: duke@435: // Update interior oops in the ranges of chunks [beg_chunk, end_chunk). duke@435: void duke@435: PSParallelCompact::update_and_deadwood_in_dense_prefix(ParCompactionManager* cm, duke@435: SpaceId space_id, duke@435: size_t beg_chunk, duke@435: size_t end_chunk) { duke@435: ParallelCompactData& sd = summary_data(); duke@435: ParMarkBitMap* const mbm = mark_bitmap(); duke@435: duke@435: HeapWord* beg_addr = sd.chunk_to_addr(beg_chunk); duke@435: HeapWord* const end_addr = sd.chunk_to_addr(end_chunk); duke@435: assert(beg_chunk <= end_chunk, "bad chunk range"); duke@435: assert(end_addr <= dense_prefix(space_id), "not in the dense prefix"); duke@435: duke@435: #ifdef ASSERT duke@435: // Claim the chunks to avoid triggering an assert when they are marked as duke@435: // filled. duke@435: for (size_t claim_chunk = beg_chunk; claim_chunk < end_chunk; ++claim_chunk) { duke@435: assert(sd.chunk(claim_chunk)->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 duke@435: // range of chunks. If a partial object crosses onto the chunk, skip it; it duke@435: // will be marked for 'deferred update' when the object head is processed. duke@435: // If dead space crosses onto the chunk, it is also skipped; it will be duke@435: // filled when the prior chunk is processed. If neither of those apply, the duke@435: // first word in the chunk is the start of a live object or dead space. duke@435: assert(beg_addr > space(space_id)->bottom(), "sanity"); duke@435: const ChunkData* const cp = sd.chunk(beg_chunk); duke@435: if (cp->partial_obj_size() != 0) { duke@435: beg_addr = sd.partial_obj_end(beg_chunk); 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) { duke@435: // A live object or block of dead space starts in this range of Chunks. 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: duke@435: // Mark the chunks as filled. duke@435: ChunkData* const beg_cp = sd.chunk(beg_chunk); duke@435: ChunkData* const end_cp = sd.chunk(end_chunk); duke@435: for (ChunkData* 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: duke@435: for (unsigned int id = perm_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(); duke@435: HeapWord* const end_addr = sd.chunk_align_up(space_info->new_top()); duke@435: duke@435: const ChunkData* const beg_chunk = sd.addr_to_chunk_ptr(beg_addr); duke@435: const ChunkData* const end_chunk = sd.addr_to_chunk_ptr(end_addr); duke@435: const ChunkData* cur_chunk; duke@435: for (cur_chunk = beg_chunk; cur_chunk < end_chunk; ++cur_chunk) { duke@435: HeapWord* const addr = cur_chunk->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: duke@435: HeapWord* duke@435: PSParallelCompact::first_src_addr(HeapWord* const dest_addr, duke@435: size_t src_chunk_idx) duke@435: { duke@435: ParMarkBitMap* const bitmap = mark_bitmap(); duke@435: const ParallelCompactData& sd = summary_data(); duke@435: const size_t ChunkSize = ParallelCompactData::ChunkSize; duke@435: duke@435: assert(sd.is_chunk_aligned(dest_addr), "not aligned"); duke@435: duke@435: const ChunkData* const src_chunk_ptr = sd.chunk(src_chunk_idx); duke@435: const size_t partial_obj_size = src_chunk_ptr->partial_obj_size(); duke@435: HeapWord* const src_chunk_destination = src_chunk_ptr->destination(); duke@435: duke@435: assert(dest_addr >= src_chunk_destination, "wrong src chunk"); duke@435: assert(src_chunk_ptr->data_size() > 0, "src chunk cannot be empty"); duke@435: duke@435: HeapWord* const src_chunk_beg = sd.chunk_to_addr(src_chunk_idx); duke@435: HeapWord* const src_chunk_end = src_chunk_beg + ChunkSize; duke@435: duke@435: HeapWord* addr = src_chunk_beg; duke@435: if (dest_addr == src_chunk_destination) { duke@435: // Return the first live word in the source chunk. duke@435: if (partial_obj_size == 0) { duke@435: addr = bitmap->find_obj_beg(addr, src_chunk_end); duke@435: assert(addr < src_chunk_end, "no objects start in src chunk"); duke@435: } duke@435: return addr; duke@435: } duke@435: duke@435: // Must skip some live data. duke@435: size_t words_to_skip = dest_addr - src_chunk_destination; duke@435: assert(src_chunk_ptr->data_size() > words_to_skip, "wrong src chunk"); 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. duke@435: addr = bitmap->find_obj_beg(addr, src_chunk_end); duke@435: assert(addr < src_chunk_end, "wrong src chunk"); 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: duke@435: // Skip over live words due to objects that start in the chunk. duke@435: addr = skip_live_words(addr, src_chunk_end, words_to_skip); duke@435: assert(addr < src_chunk_end, "wrong src chunk"); duke@435: return addr; duke@435: } duke@435: duke@435: void PSParallelCompact::decrement_destination_counts(ParCompactionManager* cm, duke@435: size_t beg_chunk, duke@435: HeapWord* end_addr) duke@435: { duke@435: ParallelCompactData& sd = summary_data(); duke@435: ChunkData* const beg = sd.chunk(beg_chunk); duke@435: HeapWord* const end_addr_aligned_up = sd.chunk_align_up(end_addr); duke@435: ChunkData* const end = sd.addr_to_chunk_ptr(end_addr_aligned_up); duke@435: size_t cur_idx = beg_chunk; duke@435: for (ChunkData* cur = beg; cur < end; ++cur, ++cur_idx) { duke@435: assert(cur->data_size() > 0, "chunk must have live data"); duke@435: cur->decrement_destination_count(); duke@435: if (cur_idx <= cur->source_chunk() && cur->available() && cur->claim()) { duke@435: cm->save_for_processing(cur_idx); duke@435: } duke@435: } duke@435: } duke@435: duke@435: size_t PSParallelCompact::next_src_chunk(MoveAndUpdateClosure& closure, duke@435: SpaceId& src_space_id, duke@435: HeapWord*& src_space_top, duke@435: HeapWord* end_addr) duke@435: { duke@435: typedef ParallelCompactData::ChunkData ChunkData; duke@435: duke@435: ParallelCompactData& sd = PSParallelCompact::summary_data(); duke@435: const size_t chunk_size = ParallelCompactData::ChunkSize; duke@435: duke@435: size_t src_chunk_idx = 0; duke@435: duke@435: // Skip empty chunks (if any) up to the top of the space. duke@435: HeapWord* const src_aligned_up = sd.chunk_align_up(end_addr); duke@435: ChunkData* src_chunk_ptr = sd.addr_to_chunk_ptr(src_aligned_up); duke@435: HeapWord* const top_aligned_up = sd.chunk_align_up(src_space_top); duke@435: const ChunkData* const top_chunk_ptr = sd.addr_to_chunk_ptr(top_aligned_up); duke@435: while (src_chunk_ptr < top_chunk_ptr && src_chunk_ptr->data_size() == 0) { duke@435: ++src_chunk_ptr; duke@435: } duke@435: duke@435: if (src_chunk_ptr < top_chunk_ptr) { duke@435: // The next source chunk is in the current space. Update src_chunk_idx and duke@435: // the source address to match src_chunk_ptr. duke@435: src_chunk_idx = sd.chunk(src_chunk_ptr); duke@435: HeapWord* const src_chunk_addr = sd.chunk_to_addr(src_chunk_idx); duke@435: if (src_chunk_addr > closure.source()) { duke@435: closure.set_source(src_chunk_addr); duke@435: } duke@435: return src_chunk_idx; duke@435: } duke@435: duke@435: // Switch to a new source space and find the first non-empty chunk. 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(); duke@435: const ChunkData* const bottom_cp = sd.addr_to_chunk_ptr(bottom); duke@435: duke@435: // Iterate over the spaces that do not compact into themselves. duke@435: if (bottom_cp->destination() != bottom) { duke@435: HeapWord* const top_aligned_up = sd.chunk_align_up(space->top()); duke@435: const ChunkData* const top_cp = sd.addr_to_chunk_ptr(top_aligned_up); duke@435: duke@435: for (const ChunkData* 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(); duke@435: const size_t src_chunk_idx = sd.chunk(src_cp); duke@435: closure.set_source(sd.chunk_to_addr(src_chunk_idx)); duke@435: return src_chunk_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: duke@435: assert(false, "no source chunk was found"); duke@435: return 0; duke@435: } duke@435: duke@435: void PSParallelCompact::fill_chunk(ParCompactionManager* cm, size_t chunk_idx) duke@435: { duke@435: typedef ParMarkBitMap::IterationStatus IterationStatus; duke@435: const size_t ChunkSize = ParallelCompactData::ChunkSize; duke@435: ParMarkBitMap* const bitmap = mark_bitmap(); duke@435: ParallelCompactData& sd = summary_data(); duke@435: ChunkData* const chunk_ptr = sd.chunk(chunk_idx); duke@435: duke@435: // Get the items needed to construct the closure. duke@435: HeapWord* dest_addr = sd.chunk_to_addr(chunk_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"); duke@435: const size_t words = MIN2(pointer_delta(new_top, dest_addr), ChunkSize); duke@435: duke@435: // Get the source chunk and related info. duke@435: size_t src_chunk_idx = chunk_ptr->source_chunk(); duke@435: SpaceId src_space_id = space_id(sd.chunk_to_addr(src_chunk_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); duke@435: closure.set_source(first_src_addr(dest_addr, src_chunk_idx)); duke@435: duke@435: // Adjust src_chunk_idx to prepare for decrementing destination counts (the duke@435: // destination count is not decremented when a chunk is copied to itself). duke@435: if (src_chunk_idx == chunk_idx) { duke@435: src_chunk_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()) { duke@435: decrement_destination_counts(cm, src_chunk_idx, closure.source()); duke@435: chunk_ptr->set_deferred_obj_addr(NULL); duke@435: chunk_ptr->set_completed(); duke@435: return; duke@435: } duke@435: duke@435: HeapWord* const end_addr = sd.chunk_align_down(closure.source()); duke@435: if (sd.chunk_align_down(old_src_addr) != end_addr) { duke@435: // The partial object was copied from more than one source chunk. duke@435: decrement_destination_counts(cm, src_chunk_idx, end_addr); duke@435: duke@435: // Move to the next source chunk, possibly switching spaces as well. All duke@435: // args except end_addr may be modified. duke@435: src_chunk_idx = next_src_chunk(closure, src_space_id, src_space_top, duke@435: end_addr); duke@435: } duke@435: } duke@435: duke@435: do { duke@435: HeapWord* const cur_addr = closure.source(); duke@435: HeapWord* const end_addr = MIN2(sd.chunk_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) { duke@435: // The last obj that starts in the source chunk does not end in the chunk. duke@435: 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 duke@435: // deferred, then copy enough of the object to fill the chunk. duke@435: chunk_ptr->set_deferred_obj_addr(closure.destination()); duke@435: status = closure.copy_until_full(); // copies from closure.source() duke@435: duke@435: decrement_destination_counts(cm, src_chunk_idx, closure.source()); duke@435: chunk_ptr->set_completed(); duke@435: return; duke@435: } duke@435: duke@435: if (status == ParMarkBitMap::full) { duke@435: decrement_destination_counts(cm, src_chunk_idx, closure.source()); duke@435: chunk_ptr->set_deferred_obj_addr(NULL); duke@435: chunk_ptr->set_completed(); duke@435: return; duke@435: } duke@435: duke@435: decrement_destination_counts(cm, src_chunk_idx, end_addr); duke@435: duke@435: // Move to the next source chunk, possibly switching spaces as well. All duke@435: // args except end_addr may be modified. duke@435: src_chunk_idx = next_src_chunk(closure, src_space_id, src_space_top, duke@435: end_addr); duke@435: } while (true); duke@435: } duke@435: 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: #ifdef ASSERT duke@435: assert(beg_addr <= dp_addr && dp_addr <= end_addr, "bad dense prefix"); duke@435: if (cm->should_verify_only()) { duke@435: VerifyUpdateClosure verify_update(cm, sp); duke@435: bitmap->iterate(&verify_update, beg_addr, end_addr); duke@435: return; duke@435: } duke@435: duke@435: if (cm->should_reset_only()) { duke@435: ResetObjectsClosure reset_objects(cm); duke@435: bitmap->iterate(&reset_objects, beg_addr, end_addr); duke@435: return; duke@435: } duke@435: #endif duke@435: duke@435: const size_t beg_chunk = sd.addr_to_chunk_idx(beg_addr); duke@435: const size_t dp_chunk = sd.addr_to_chunk_idx(dp_addr); duke@435: if (beg_chunk < dp_chunk) { duke@435: update_and_deadwood_in_dense_prefix(cm, space_id, beg_chunk, dp_chunk); duke@435: } duke@435: duke@435: // The destination of the first live object that starts in the chunk is one duke@435: // past the end of the partial object entering the chunk (if any). duke@435: HeapWord* const dest_addr = sd.partial_obj_end(dp_chunk); 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() { duke@435: jlong ret_val = os::javaTimeMillis() - _time_of_last_gc; duke@435: // XXX See note in genCollectedHeap::millis_since_last_gc(). duke@435: if (ret_val < 0) { duke@435: NOT_PRODUCT(warning("time warp: %d", 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() { duke@435: _time_of_last_gc = os::javaTimeMillis(); duke@435: } duke@435: duke@435: ParMarkBitMap::IterationStatus MoveAndUpdateClosure::copy_until_full() duke@435: { duke@435: if (source() != destination()) { duke@435: assert(source() > destination(), "must copy to the left"); 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()) { duke@435: assert(source() > destination(), "must copy to the left"); 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()) { duke@435: assert(destination() < source(), "must copy to the left"); 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: } duke@435: duke@435: BitBlockUpdateClosure::BitBlockUpdateClosure(ParMarkBitMap* mbm, duke@435: ParCompactionManager* cm, duke@435: size_t chunk_index) : duke@435: ParMarkBitMapClosure(mbm, cm), duke@435: _live_data_left(0), duke@435: _cur_block(0) { duke@435: _chunk_start = duke@435: PSParallelCompact::summary_data().chunk_to_addr(chunk_index); duke@435: _chunk_end = duke@435: PSParallelCompact::summary_data().chunk_to_addr(chunk_index) + duke@435: ParallelCompactData::ChunkSize; duke@435: _chunk_index = chunk_index; duke@435: _cur_block = duke@435: PSParallelCompact::summary_data().addr_to_block_idx(_chunk_start); duke@435: } duke@435: duke@435: bool BitBlockUpdateClosure::chunk_contains_cur_block() { duke@435: return ParallelCompactData::chunk_contains_block(_chunk_index, _cur_block); duke@435: } duke@435: duke@435: void BitBlockUpdateClosure::reset_chunk(size_t chunk_index) { duke@435: DEBUG_ONLY(ParallelCompactData::BlockData::set_cur_phase(7);) duke@435: ParallelCompactData& sd = PSParallelCompact::summary_data(); duke@435: _chunk_index = chunk_index; duke@435: _live_data_left = 0; duke@435: _chunk_start = sd.chunk_to_addr(chunk_index); duke@435: _chunk_end = sd.chunk_to_addr(chunk_index) + ParallelCompactData::ChunkSize; duke@435: duke@435: // The first block in this chunk duke@435: size_t first_block = sd.addr_to_block_idx(_chunk_start); duke@435: size_t partial_live_size = sd.chunk(chunk_index)->partial_obj_size(); duke@435: duke@435: // Set the offset to 0. By definition it should have that value duke@435: // but it may have been written while processing an earlier chunk. duke@435: if (partial_live_size == 0) { duke@435: // No live object extends onto the chunk. The first bit duke@435: // in the bit map for the first chunk must be a start bit. duke@435: // Although there may not be any marked bits, it is safe duke@435: // to set it as a start bit. duke@435: sd.block(first_block)->set_start_bit_offset(0); duke@435: sd.block(first_block)->set_first_is_start_bit(true); duke@435: } else if (sd.partial_obj_ends_in_block(first_block)) { duke@435: sd.block(first_block)->set_end_bit_offset(0); duke@435: sd.block(first_block)->set_first_is_start_bit(false); duke@435: } else { duke@435: // The partial object extends beyond the first block. duke@435: // There is no object starting in the first block duke@435: // so the offset and bit parity are not needed. duke@435: // Set the the bit parity to start bit so assertions duke@435: // work when not bit is found. duke@435: sd.block(first_block)->set_end_bit_offset(0); duke@435: sd.block(first_block)->set_first_is_start_bit(false); duke@435: } duke@435: _cur_block = first_block; duke@435: #ifdef ASSERT duke@435: if (sd.block(first_block)->first_is_start_bit()) { duke@435: assert(!sd.partial_obj_ends_in_block(first_block), duke@435: "Partial object cannot end in first block"); duke@435: } duke@435: duke@435: if (PrintGCDetails && Verbose) { duke@435: if (partial_live_size == 1) { duke@435: gclog_or_tty->print_cr("first_block " PTR_FORMAT duke@435: " _offset " PTR_FORMAT duke@435: " _first_is_start_bit %d", duke@435: first_block, duke@435: sd.block(first_block)->raw_offset(), duke@435: sd.block(first_block)->first_is_start_bit()); duke@435: } duke@435: } duke@435: #endif duke@435: DEBUG_ONLY(ParallelCompactData::BlockData::set_cur_phase(17);) duke@435: } duke@435: duke@435: // This method is called when a object has been found (both beginning duke@435: // and end of the object) in the range of iteration. This method is duke@435: // calculating the words of live data to the left of a block. That live duke@435: // data includes any object starting to the left of the block (i.e., duke@435: // the live-data-to-the-left of block AAA will include the full size duke@435: // of any object entering AAA). duke@435: duke@435: ParMarkBitMapClosure::IterationStatus duke@435: BitBlockUpdateClosure::do_addr(HeapWord* addr, size_t words) { duke@435: // add the size to the block data. duke@435: HeapWord* obj = addr; duke@435: ParallelCompactData& sd = PSParallelCompact::summary_data(); duke@435: duke@435: assert(bitmap()->obj_size(obj) == words, "bad size"); duke@435: assert(_chunk_start <= obj, "object is not in chunk"); duke@435: assert(obj + words <= _chunk_end, "object is not in chunk"); duke@435: duke@435: // Update the live data to the left duke@435: size_t prev_live_data_left = _live_data_left; duke@435: _live_data_left = _live_data_left + words; duke@435: duke@435: // Is this object in the current block. duke@435: size_t block_of_obj = sd.addr_to_block_idx(obj); duke@435: size_t block_of_obj_last = sd.addr_to_block_idx(obj + words - 1); duke@435: HeapWord* block_of_obj_last_addr = sd.block_to_addr(block_of_obj_last); duke@435: if (_cur_block < block_of_obj) { duke@435: duke@435: // duke@435: // No object crossed the block boundary and this object was found duke@435: // on the other side of the block boundary. Update the offset for duke@435: // the new block with the data size that does not include this object. duke@435: // duke@435: // The first bit in block_of_obj is a start bit except in the duke@435: // case where the partial object for the chunk extends into duke@435: // this block. duke@435: if (sd.partial_obj_ends_in_block(block_of_obj)) { duke@435: sd.block(block_of_obj)->set_end_bit_offset(prev_live_data_left); duke@435: } else { duke@435: sd.block(block_of_obj)->set_start_bit_offset(prev_live_data_left); duke@435: } duke@435: duke@435: // Does this object pass beyond the its block? duke@435: if (block_of_obj < block_of_obj_last) { duke@435: // Object crosses block boundary. Two blocks need to be udpated: duke@435: // the current block where the object started duke@435: // the block where the object ends duke@435: // duke@435: // The offset for blocks with no objects starting in them duke@435: // (e.g., blocks between _cur_block and block_of_obj_last) duke@435: // should not be needed. duke@435: // Note that block_of_obj_last may be in another chunk. If so, duke@435: // it should be overwritten later. This is a problem (writting duke@435: // into a block in a later chunk) for parallel execution. duke@435: assert(obj < block_of_obj_last_addr, duke@435: "Object should start in previous block"); duke@435: duke@435: // obj is crossing into block_of_obj_last so the first bit duke@435: // is and end bit. duke@435: sd.block(block_of_obj_last)->set_end_bit_offset(_live_data_left); duke@435: duke@435: _cur_block = block_of_obj_last; duke@435: } else { duke@435: // _first_is_start_bit has already been set correctly duke@435: // in the if-then-else above so don't reset it here. duke@435: _cur_block = block_of_obj; duke@435: } duke@435: } else { duke@435: // The current block only changes if the object extends beyound duke@435: // the block it starts in. duke@435: // duke@435: // The object starts in the current block. duke@435: // Does this object pass beyond the end of it? duke@435: if (block_of_obj < block_of_obj_last) { duke@435: // Object crosses block boundary. duke@435: // See note above on possible blocks between block_of_obj and duke@435: // block_of_obj_last duke@435: assert(obj < block_of_obj_last_addr, duke@435: "Object should start in previous block"); duke@435: duke@435: sd.block(block_of_obj_last)->set_end_bit_offset(_live_data_left); duke@435: duke@435: _cur_block = block_of_obj_last; duke@435: } duke@435: } duke@435: duke@435: // Return incomplete if there are more blocks to be done. duke@435: if (chunk_contains_cur_block()) { duke@435: return ParMarkBitMap::incomplete; duke@435: } duke@435: return ParMarkBitMap::complete; duke@435: } duke@435: duke@435: // Verify the new location using the forwarding pointer duke@435: // from MarkSweep::mark_sweep_phase2(). Set the mark_word duke@435: // to the initial value. duke@435: ParMarkBitMapClosure::IterationStatus duke@435: PSParallelCompact::VerifyUpdateClosure::do_addr(HeapWord* addr, size_t words) { duke@435: // The second arg (words) is not used. duke@435: oop obj = (oop) addr; duke@435: HeapWord* forwarding_ptr = (HeapWord*) obj->mark()->decode_pointer(); duke@435: HeapWord* new_pointer = summary_data().calc_new_pointer(obj); duke@435: if (forwarding_ptr == NULL) { duke@435: // The object is dead or not moving. duke@435: assert(bitmap()->is_unmarked(obj) || (new_pointer == (HeapWord*) obj), duke@435: "Object liveness is wrong."); duke@435: return ParMarkBitMap::incomplete; duke@435: } duke@435: assert(UseParallelOldGCDensePrefix || duke@435: (HeapMaximumCompactionInterval > 1) || duke@435: (MarkSweepAlwaysCompactCount > 1) || duke@435: (forwarding_ptr == new_pointer), duke@435: "Calculation of new location is incorrect"); duke@435: return ParMarkBitMap::incomplete; duke@435: } duke@435: duke@435: // Reset objects modified for debug checking. duke@435: ParMarkBitMapClosure::IterationStatus duke@435: PSParallelCompact::ResetObjectsClosure::do_addr(HeapWord* addr, size_t words) { duke@435: // The second arg (words) is not used. duke@435: oop obj = (oop) addr; duke@435: obj->init_mark(); duke@435: return ParMarkBitMap::incomplete; duke@435: } duke@435: duke@435: // Prepare for compaction. This method is executed once duke@435: // (i.e., by a single thread) before compaction. duke@435: // Save the updated location of the intArrayKlassObj for duke@435: // filling holes in the dense prefix. duke@435: void PSParallelCompact::compact_prologue() { duke@435: _updated_int_array_klass_obj = (klassOop) duke@435: summary_data().calc_new_pointer(Universe::intArrayKlassObj()); duke@435: } duke@435: duke@435: // The initial implementation of this method created a field duke@435: // _next_compaction_space_id in SpaceInfo and initialized duke@435: // that field in SpaceInfo::initialize_space_info(). That duke@435: // required that _next_compaction_space_id be declared a duke@435: // SpaceId in SpaceInfo and that would have required that duke@435: // either SpaceId be declared in a separate class or that duke@435: // it be declared in SpaceInfo. It didn't seem consistent duke@435: // to declare it in SpaceInfo (didn't really fit logically). duke@435: // Alternatively, defining a separate class to define SpaceId duke@435: // seem excessive. This implementation is simple and localizes duke@435: // the knowledge. duke@435: duke@435: PSParallelCompact::SpaceId duke@435: PSParallelCompact::next_compaction_space_id(SpaceId id) { duke@435: assert(id < last_space_id, "id out of range"); duke@435: switch (id) { duke@435: case perm_space_id : duke@435: return last_space_id; duke@435: case old_space_id : duke@435: return eden_space_id; duke@435: case eden_space_id : duke@435: return from_space_id; duke@435: case from_space_id : duke@435: return to_space_id; duke@435: case to_space_id : duke@435: return last_space_id; duke@435: default: duke@435: assert(false, "Bad space id"); duke@435: return last_space_id; duke@435: } duke@435: } duke@435: duke@435: // Here temporarily for debugging duke@435: #ifdef ASSERT duke@435: size_t ParallelCompactData::block_idx(BlockData* block) { duke@435: size_t index = pointer_delta(block, duke@435: PSParallelCompact::summary_data()._block_data, sizeof(BlockData)); duke@435: return index; duke@435: } duke@435: #endif