/* * Copyright (c) 2005, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. *
*/
// These fields may not be updated below, so make sure they're clear.
assert(_dest_region_addr == NULL, "should have been cleared");
assert(_first_src_addr == NULL, "should have been cleared");
// Determine the number of destination regions for the partial object.
HeapWord* const last_word = destination + partial_obj_size - 1; const ParallelCompactData& sd = PSParallelCompact::summary_data();
HeapWord* const beg_region_addr = sd.region_align_down(destination);
HeapWord* const end_region_addr = sd.region_align_down(last_word);
if (beg_region_addr == end_region_addr) { // One destination region.
_destination_count = 1; if (end_region_addr == destination) { // The destination falls on a region boundary, thus the first word of the // partial object will be the first word copied to the destination region.
_dest_region_addr = end_region_addr;
_first_src_addr = sd.region_to_addr(src_region_idx);
}
} else { // Two destination regions. When copied, the partial object will cross a // destination region boundary, so a word somewhere within the partial // object will be the first word copied to the second destination region.
_destination_count = 2;
_dest_region_addr = end_region_addr; const size_t ofs = pointer_delta(end_region_addr, destination);
assert(ofs < _partial_obj_size, "sanity");
_first_src_addr = sd.region_to_addr(src_region_idx) + ofs;
}
}
// Print the 'reclaimed ratio' for regions while there is something live in // the region or to the right of it. The remaining regions are empty (and // uninteresting), and computing the ratio will result in division by 0. while (i < end_region && live_to_right > 0) {
c = summary_data.region(i);
HeapWord* const region_addr = summary_data.region_to_addr(i); const size_t used_to_right = pointer_delta(space->top(), region_addr); const size_t dead_to_right = used_to_right - live_to_right; constdouble reclaimed_ratio = double(dead_to_right) / live_to_right;
// Any remaining regions are empty. Print one more if there is one. if (i < end_region) {
ParallelCompactData::RegionData* c = summary_data.region(i);
log_develop_trace(gc, compaction)(
SIZE_FORMAT_W(5) " " PTR_FORMAT " " SIZE_FORMAT_W(5) " " SIZE_FORMAT_W(5) " " SIZE_FORMAT_W(5) " " SIZE_FORMAT_W(5) " %d",
i, p2i(c->destination()),
c->partial_obj_size(), c->live_obj_size(),
c->data_size(), c->source_region(), c->destination_count());
}
unsignedint id = PSParallelCompact::old_space_id; const MutableSpace* space; do {
space = space_info[id].space();
print_initial_summary_data(summary_data, space);
} while (++id < PSParallelCompact::eden_space_id);
do {
space = space_info[id].space();
print_generic_summary_data(summary_data, space->bottom(), space->top());
} while (++id < PSParallelCompact::last_space_id);
} #endif// #ifndef PRODUCT
void ParallelCompactData::clear_range(size_t beg_region, size_t end_region) {
assert(beg_region <= _region_count, "beg_region out of range");
assert(end_region <= _region_count, "end_region out of range");
assert(RegionSize % BlockSize == 0, "RegionSize not a multiple of BlockSize");
// Middle regions--completely spanned by this object. for (size_t region = beg_region + 1; region < end_region; ++region) {
_region_data[region].set_partial_obj_size(RegionSize);
_region_data[region].set_partial_obj_addr(addr);
}
// Last region. const size_t end_ofs = region_offset(addr + len - 1);
_region_data[end_region].set_partial_obj_size(end_ofs + 1);
_region_data[end_region].set_partial_obj_addr(addr);
}
// Update live_obj_size so the region appears completely full.
size_t live_size = RegionSize - _region_data[cur_region].partial_obj_size();
_region_data[cur_region].set_live_obj_size(live_size);
++cur_region;
addr += RegionSize;
}
}
// Find the point at which a space can be split and, if necessary, record the // split point. // // If the current src region (which overflowed the destination space) doesn't // have a partial object, the split point is at the beginning of the current src // region (an "easy" split, no extra bookkeeping required). // // If the current src region has a partial object, the split point is in the // region where that partial object starts (call it the split_region). If // split_region has a partial object, then the split point is just after that // partial object (a "hard" split where we have to record the split data and // zero the partial_obj_size field). With a "hard" split, we know that the // partial_obj ends within split_region because the partial object that caused // the overflow starts in split_region. If split_region doesn't have a partial // obj, then the split is at the beginning of split_region (another "easy" // split).
HeapWord*
ParallelCompactData::summarize_split_space(size_t src_region,
SplitInfo& split_info,
HeapWord* destination,
HeapWord* target_end,
HeapWord** target_next)
{
assert(destination <= target_end, "sanity");
assert(destination + _region_data[src_region].data_size() > target_end, "region should not fit into target space");
assert(is_region_aligned(target_end), "sanity");
if (destination + partial_obj_size > target_end) { // The split point is just after the partial object (if any) in the // src_region that contains the start of the object that overflowed the // destination space. // // Find the start of the "overflow" object and set split_region to the // region containing it.
HeapWord* const overflow_obj = _region_data[src_region].partial_obj_addr();
split_region = addr_to_region_idx(overflow_obj);
// Clear the source_region field of all destination regions whose first word // came from data after the split point (a non-null source_region field // implies a region must be filled). // // An alternative to the simple loop below: clear during post_compact(), // which uses memcpy instead of individual stores, and is easy to // parallelize. (The downside is that it clears the entire RegionData // object as opposed to just one field.) // // post_compact() would have to clear the summary data up to the highest // address that was written during the summary phase, which would be // // max(top, max(new_top, clear_top)) // // where clear_top is a new field in SpaceInfo. Would have to set clear_top // to target_end. const RegionData* const sr = region(split_region); const size_t beg_idx =
addr_to_region_idx(region_align_up(sr->destination() +
sr->partial_obj_size())); const size_t end_idx = addr_to_region_idx(target_end);
log_develop_trace(gc, compaction)("split: clearing source_region field in [" SIZE_FORMAT ", " SIZE_FORMAT ")", beg_idx, end_idx); for (size_t idx = beg_idx; idx < end_idx; ++idx) {
_region_data[idx].set_source_region(0);
}
// Set split_destination and partial_obj_size to reflect the split region.
split_destination = sr->destination();
partial_obj_size = sr->partial_obj_size();
}
// The split is recorded only if a partial object extends onto the region. if (partial_obj_size != 0) {
_region_data[split_region].set_partial_obj_size(0);
split_info.record(split_region, partial_obj_size, split_destination);
}
HeapWord *dest_addr = target_beg; while (cur_region < end_region) { // The destination must be set even if the region has no data.
_region_data[cur_region].set_destination(dest_addr);
size_t words = _region_data[cur_region].data_size(); if (words > 0) { // If cur_region does not fit entirely into the target space, find a point // at which the source space can be 'split' so that part is copied to the // target space and the rest is copied elsewhere. if (dest_addr + words > target_end) {
assert(source_next != NULL, "source_next is NULL when splitting");
*source_next = summarize_split_space(cur_region, split_info, dest_addr,
target_end, target_next); returnfalse;
}
// Compute the destination_count for cur_region, and if necessary, update // source_region for a destination region. The source_region field is // updated if cur_region is the first (left-most) region to be copied to a // destination region. // // The destination_count calculation is a bit subtle. A region that has // data that compacts into itself does not count itself as a destination. // This maintains the invariant that a zero count means the region is // available and can be claimed and then filled.
uint destination_count = 0; if (split_info.is_split(cur_region)) { // The current region has been split: the partial object will be copied // to one destination space and the remaining data will be copied to // another destination space. Adjust the initial destination_count and, // if necessary, set the source_region field if the partial object will // cross a destination region boundary.
destination_count = split_info.destination_count(); if (destination_count == 2) {
size_t dest_idx = addr_to_region_idx(split_info.dest_region_addr());
_region_data[dest_idx].set_source_region(cur_region);
}
}
// Initially assume that the destination regions will be the same and // adjust the value below if necessary. Under this assumption, if // cur_region == dest_region_2, then cur_region will be compacted // completely into itself.
destination_count += cur_region == dest_region_2 ? 0 : 1; if (dest_region_1 != dest_region_2) { // Destination regions differ; adjust destination_count.
destination_count += 1; // Data from cur_region will be copied to the start of dest_region_2.
_region_data[dest_region_2].set_source_region(cur_region);
} elseif (is_region_aligned(dest_addr)) { // Data from cur_region will be copied to the start of the destination // region.
_region_data[dest_region_1].set_source_region(cur_region);
}
// Region covering the object.
RegionData* const region_ptr = addr_to_region_ptr(addr);
HeapWord* result = region_ptr->destination();
// If the entire Region is live, the new location is region->destination + the // offset of the object within in the Region.
// Run some performance tests to determine if this special case pays off. It // is worth it for pointers into the dense prefix. If the optimization to // avoid pointer updates in regions that only point to the dense prefix is // ever implemented, this should be revisited. if (region_ptr->data_size() == RegionSize) {
result += region_offset(addr); return result;
}
// Otherwise, the new location is region->destination + block offset + the // number of live words in the Block that are (a) to the left of addr and (b) // due to objects that start in the Block.
// Fill in the block table if necessary. This is unsynchronized, so multiple // threads may fill the block table for a region (harmless, since it is // idempotent). if (!region_ptr->blocks_filled()) {
PSParallelCompact::fill_blocks(addr_to_region_idx(addr));
region_ptr->set_blocks_filled();
}
void
PSParallelCompact::clear_data_covering_space(SpaceId id)
{ // At this point, top is the value before GC, new_top() is the value that will // be set at the end of GC. The marking bitmap is cleared to top; nothing // should be marked above top. The summary data is cleared to the larger of // top & new_top.
MutableSpace* const space = _space_info[id].space();
HeapWord* const bot = space->bottom();
HeapWord* const top = space->top();
HeapWord* const max_top = MAX2(top, _space_info[id].new_top());
// Clear the data used to 'split' regions.
SplitInfo& split_info = _space_info[id].split_info(); if (split_info.is_valid()) {
split_info.clear();
}
DEBUG_ONLY(split_info.verify_clear();)
}
void PSParallelCompact::pre_compact()
{ // Update the from & to space pointers in space_info, since they are swapped // at each young gen gc. Do the update unconditionally (even though a // promotion failure does not swap spaces) because an unknown number of young // collections will have swapped the spaces an unknown number of times.
GCTraceTime(Debug, gc, phases) tm("Pre Compact", &_gc_timer);
ParallelScavengeHeap* heap = ParallelScavengeHeap::heap();
_space_info[from_space_id].set_space(heap->young_gen()->from_space());
_space_info[to_space_id].set_space(heap->young_gen()->to_space());
// Increment the invocation count
heap->increment_total_collections(true);
for (unsignedint id = old_space_id; id < last_space_id; ++id) { // Clear the marking bitmap, summary data and split info.
clear_data_covering_space(SpaceId(id)); // Update top(). Must be done after clearing the bitmap and summary data.
_space_info[id].publish_new_top();
}
// Update heap occupancy information which is used as input to the soft ref // clearing policy at the next gc.
Universe::heap()->update_capacity_and_used_at_gc();
// Delete metaspaces for unloaded class loaders and clean up loader_data graph
ClassLoaderDataGraph::purge(/*at_safepoint*/true);
DEBUG_ONLY(MetaspaceUtils::verify();)
// Need to clear claim bits for the next mark.
ClassLoaderDataGraph::clear_claimed_marks();
// Skip full regions at the beginning of the space--they are necessarily part // of the dense prefix.
size_t full_count = 0; const RegionData* cp; for (cp = beg_cp; cp < end_cp && cp->data_size() == region_size; ++cp) {
++full_count;
}
if (cur_deadwood >= deadwood_goal) { // Found the region that has the correct amount of deadwood to the left. // This typically occurs after crossing a fairly sparse set of regions, so // iterate backwards over those sparse regions, looking for the region // that has the lowest density of live objects 'to the right.'
size_t space_to_left = sd.region(cp) * region_size;
size_t live_to_left = space_to_left - cur_deadwood;
size_t space_to_right = space_capacity - space_to_left;
size_t live_to_right = space_live - live_to_left; double density_to_right = double(live_to_right) / space_to_right; while (cp > full_cp) {
--cp; const size_t prev_region_live_to_right = live_to_right -
cp->data_size(); const size_t prev_region_space_to_right = space_to_right + region_size; double prev_region_density_to_right = double(prev_region_live_to_right) / prev_region_space_to_right; if (density_to_right <= prev_region_density_to_right) { return dense_prefix;
}
log_develop_trace(gc, compaction)( "backing up from c=" SIZE_FORMAT_W(4) " d2r=%10.8f " "pc_d2r=%10.8f",
sd.region(cp), density_to_right,
prev_region_density_to_right);
// The raw limit is the value of the normal distribution at x = density. constdouble raw_limit = normal_distribution(density);
// Adjust the raw limit so it becomes the minimum when the density is 1. // // First subtract the adjustment value (which is simply the precomputed value // normal_distribution(1.0)); this yields a value of 0 when the density is 1. // Then add the minimum value, so the minimum is returned when the density is // 1. Finally, prevent negative values, which occur when the mean is not 0.5. constdouble min = double(min_percent) / 100.0; constdouble limit = raw_limit - _dwl_adjustment + min; return MAX2(limit, 0.0);
}
ParallelCompactData::RegionData*
PSParallelCompact::first_dead_space_region(const RegionData* beg, const RegionData* end)
{ const size_t region_size = ParallelCompactData::RegionSize;
ParallelCompactData& sd = summary_data();
size_t left = sd.region(beg);
size_t right = end > beg ? sd.region(end) - 1 : left;
// Binary search. while (left < right) { // Equivalent to (left + right) / 2, but does not overflow. const size_t middle = left + (right - left) / 2;
RegionData* const middle_ptr = sd.region(middle);
HeapWord* const dest = middle_ptr->destination();
HeapWord* const addr = sd.region_to_addr(middle);
assert(dest != NULL, "sanity");
assert(dest <= addr, "must move left");
if (middle > left && dest < addr) {
right = middle - 1;
} elseif (middle < right && middle_ptr->data_size() == region_size) {
left = middle + 1;
} else { return middle_ptr;
}
} return sd.region(left);
}
ParallelCompactData::RegionData*
PSParallelCompact::dead_wood_limit_region(const RegionData* beg, const RegionData* end,
size_t dead_words)
{
ParallelCompactData& sd = summary_data();
size_t left = sd.region(beg);
size_t right = end > beg ? sd.region(end) - 1 : left;
// Binary search. while (left < right) { // Equivalent to (left + right) / 2, but does not overflow. const size_t middle = left + (right - left) / 2;
RegionData* const middle_ptr = sd.region(middle);
HeapWord* const dest = middle_ptr->destination();
HeapWord* const addr = sd.region_to_addr(middle);
assert(dest != NULL, "sanity");
assert(dest <= addr, "must move left");
const size_t dead_to_left = pointer_delta(addr, dest); if (middle > left && dead_to_left > dead_words) {
right = middle - 1;
} elseif (middle < right && dead_to_left < dead_words) {
left = middle + 1;
} else { return middle_ptr;
}
} return sd.region(left);
}
// The result is valid during the summary phase, after the initial summarization // of each space into itself, and before final summarization. inlinedouble
PSParallelCompact::reclaimed_ratio(const RegionData* const cp,
HeapWord* const bottom,
HeapWord* const top,
HeapWord* const new_top)
{
ParallelCompactData& sd = summary_data();
assert(cp != NULL, "sanity");
assert(bottom != NULL, "sanity");
assert(top != NULL, "sanity");
assert(new_top != NULL, "sanity");
assert(top >= new_top, "summary data problem?");
assert(new_top > bottom, "space is empty; should not be here");
assert(new_top >= cp->destination(), "sanity");
assert(top >= sd.region_to_addr(cp), "sanity");
// Return the address of the end of the dense prefix, a.k.a. the start of the // compacted region. The address is always on a region boundary. // // Completely full regions at the left are skipped, since no compaction can // occur in those regions. Then the maximum amount of dead wood to allow is // computed, based on the density (amount live / capacity) of the generation; // the region with approximately that amount of dead space to the left is // identified as the limit region. Regions between the last completely full // region and the limit region are scanned and the one that has the best // (maximum) reclaimed_ratio() is selected.
HeapWord*
PSParallelCompact::compute_dense_prefix(const SpaceId id, bool maximum_compaction)
{ const size_t region_size = ParallelCompactData::RegionSize; const ParallelCompactData& sd = summary_data();
// Skip full regions at the beginning of the space--they are necessarily part // of the dense prefix. const RegionData* const full_cp = first_dead_space_region(beg_cp, new_top_cp);
assert(full_cp->destination() == sd.region_to_addr(full_cp) ||
space->is_empty(), "no dead space allowed to the left");
assert(full_cp->data_size() < region_size || full_cp == new_top_cp - 1, "region must have dead space");
// The gc number is saved whenever a maximum compaction is done, and used to // determine when the maximum compaction interval has expired. This avoids // successive max compactions for different reasons.
assert(total_invocations() >= _maximum_compaction_gc_num, "sanity"); const size_t gcs_since_max = total_invocations() - _maximum_compaction_gc_num; constbool interval_ended = gcs_since_max > HeapMaximumCompactionInterval ||
total_invocations() == HeapFirstMaximumCompactionCount; if (maximum_compaction || full_cp == top_cp || interval_ended) {
_maximum_compaction_gc_num = total_invocations(); return sd.region_to_addr(full_cp);
}
// Locate the region with the desired amount of dead space to the left. const RegionData* const limit_cp =
dead_wood_limit_region(full_cp, top_cp, dead_wood_limit);
// Scan from the first region with dead space to the limit region and find the // one with the best (largest) reclaimed ratio. double best_ratio = 0.0; const RegionData* best_cp = full_cp; for (const RegionData* cp = full_cp; cp < limit_cp; ++cp) { double tmp_ratio = reclaimed_ratio(cp, bottom, top, new_top); if (tmp_ratio > best_ratio) {
best_cp = cp;
best_ratio = tmp_ratio;
}
}
return sd.region_to_addr(best_cp);
}
void PSParallelCompact::summarize_spaces_quick()
{ for (unsignedint i = 0; i < last_space_id; ++i) { const MutableSpace* space = _space_info[i].space();
HeapWord** nta = _space_info[i].new_top_addr(); bool result = _summary_data.summarize(_space_info[i].split_info(),
space->bottom(), space->top(), NULL,
space->bottom(), space->end(), nta);
assert(result, "space must fit into itself");
_space_info[i].set_dense_prefix(space->bottom());
}
}
void PSParallelCompact::fill_dense_prefix_end(SpaceId id)
{
HeapWord* const dense_prefix_end = dense_prefix(id); const RegionData* region = _summary_data.addr_to_region_ptr(dense_prefix_end); const idx_t dense_prefix_bit = _mark_bitmap.addr_to_bit(dense_prefix_end); if (dead_space_crosses_boundary(region, dense_prefix_bit)) { // Only enough dead space is filled so that any remaining dead space to the // left is larger than the minimum filler object. (The remainder is filled // during the copy/update phase.) // // The size of the dead space to the right of the boundary is not a // concern, since compaction will be able to use whatever space is // available. // // Here '||' is the boundary, 'x' represents a don't care bit and a box // surrounds the space to be filled with an object. // // In the 32-bit VM, each bit represents two 32-bit words: // +---+ // a) beg_bits: ... x x x | 0 | || 0 x x ... // end_bits: ... x x x | 0 | || 0 x x ... // +---+ // // In the 64-bit VM, each bit represents one 64-bit word: // +------------+ // b) beg_bits: ... x x x | 0 || 0 | x x ... // end_bits: ... x x 1 | 0 || 0 | x x ... // +------------+ // +-------+ // c) beg_bits: ... x x | 0 0 | || 0 x x ... // end_bits: ... x 1 | 0 0 | || 0 x x ... // +-------+ // +-----------+ // d) beg_bits: ... x | 0 0 0 | || 0 x x ... // end_bits: ... 1 | 0 0 0 | || 0 x x ... // +-----------+ // +-------+ // e) beg_bits: ... 0 0 | 0 0 | || 0 x x ... // end_bits: ... 0 0 | 0 0 | || 0 x x ... // +-------+
// Initially assume case a, c or e will apply.
size_t obj_len = CollectedHeap::min_fill_size();
HeapWord* obj_beg = dense_prefix_end - obj_len;
#ifdef _LP64 if (MinObjAlignment > 1) { // object alignment > heap word size // Cases a, c or e.
} elseif (_mark_bitmap.is_obj_end(dense_prefix_bit - 2)) { // Case b above.
obj_beg = dense_prefix_end - 1;
} elseif (!_mark_bitmap.is_obj_end(dense_prefix_bit - 3) &&
_mark_bitmap.is_obj_end(dense_prefix_bit - 4)) { // Case d above.
obj_beg = dense_prefix_end - 3;
obj_len = 3;
} #endif// #ifdef _LP64
void
PSParallelCompact::summarize_space(SpaceId id, bool maximum_compaction)
{
assert(id < last_space_id, "id out of range");
assert(_space_info[id].dense_prefix() == _space_info[id].space()->bottom(), "should have been reset in summarize_spaces_quick()");
const MutableSpace* space = _space_info[id].space(); if (_space_info[id].new_top() != space->bottom()) {
HeapWord* dense_prefix_end = compute_dense_prefix(id, maximum_compaction);
_space_info[id].set_dense_prefix(dense_prefix_end);
// Recompute the summary data, taking into account the dense prefix. If // every last byte will be reclaimed, then the existing summary data which // compacts everything can be left in place. if (!maximum_compaction && dense_prefix_end != space->bottom()) { // If dead space crosses the dense prefix boundary, it is (at least // partially) filled with a dummy object, marked live and added to the // summary data. This simplifies the copy/update phase and must be done // before the final locations of objects are determined, to prevent // leaving a fragment of dead space that is too small to fill.
fill_dense_prefix_end(id);
// Compute the destination of each Region, and thus each object.
_summary_data.summarize_dense_prefix(space->bottom(), dense_prefix_end);
_summary_data.summarize(_space_info[id].split_info(),
dense_prefix_end, space->top(), NULL,
dense_prefix_end, space->end(),
_space_info[id].new_top_addr());
}
}
// Quick summarization of each space into itself, to see how much is live.
summarize_spaces_quick();
log_develop_trace(gc, compaction)("summary phase: after summarizing each space to self");
NOT_PRODUCT(print_region_ranges());
NOT_PRODUCT(print_initial_summary_data(_summary_data, _space_info));
// The amount of live data that will end up in old space (assuming it fits).
size_t old_space_total_live = 0; for (unsignedint id = old_space_id; id < last_space_id; ++id) {
old_space_total_live += pointer_delta(_space_info[id].new_top(),
_space_info[id].space()->bottom());
}
MutableSpace* const old_space = _space_info[old_space_id].space(); const size_t old_capacity = old_space->capacity_in_words(); if (old_space_total_live > old_capacity) { // XXX - should also try to expand
maximum_compaction = true;
}
// Old generations.
summarize_space(old_space_id, maximum_compaction);
// Summarize the remaining spaces in the young gen. The initial target space // is the old gen. If a space does not fit entirely into the target, then the // remainder is compacted into the space itself and that space becomes the new // target.
SpaceId dst_space_id = old_space_id;
HeapWord* dst_space_end = old_space->end();
HeapWord** new_top_addr = _space_info[dst_space_id].new_top_addr(); for (unsignedint id = eden_space_id; id < last_space_id; ++id) { const MutableSpace* space = _space_info[id].space(); const size_t live = pointer_delta(_space_info[id].new_top(),
space->bottom()); const size_t available = pointer_delta(dst_space_end, *new_top_addr);
NOT_PRODUCT(summary_phase_msg(dst_space_id, *new_top_addr, dst_space_end,
SpaceId(id), space->bottom(), space->top());) if (live > 0 && live <= available) { // All the live data will fit. bool done = _summary_data.summarize(_space_info[id].split_info(),
space->bottom(), space->top(),
NULL,
*new_top_addr, dst_space_end,
new_top_addr);
assert(done, "space must fit into old gen");
// Reset the new_top value for the space.
_space_info[id].set_new_top(space->bottom());
} elseif (live > 0) { // Attempt to fit part of the source space into the target space.
HeapWord* next_src_addr = NULL; bool done = _summary_data.summarize(_space_info[id].split_info(),
space->bottom(), space->top(),
&next_src_addr,
*new_top_addr, dst_space_end,
new_top_addr);
assert(!done, "space should not fit into old gen");
assert(next_src_addr != NULL, "sanity");
// The source space becomes the new target, so the remainder is compacted // within the space itself.
dst_space_id = SpaceId(id);
dst_space_end = space->end();
new_top_addr = _space_info[id].new_top_addr();
NOT_PRODUCT(summary_phase_msg(dst_space_id,
space->bottom(), dst_space_end,
SpaceId(id), next_src_addr, space->top());)
done = _summary_data.summarize(_space_info[id].split_info(),
next_src_addr, space->top(),
NULL,
space->bottom(), dst_space_end,
new_top_addr);
assert(done, "space must fit when compacted into itself");
assert(*new_top_addr <= space->top(), "usage should not grow");
}
}
log_develop_trace(gc, compaction)("Summary_phase: after final summarization");
NOT_PRODUCT(print_region_ranges());
NOT_PRODUCT(print_initial_summary_data(_summary_data, _space_info));
}
// This method should contain all heap-specific policy for invoking a full // collection. invoke_no_policy() will only attempt to compact the heap; it // will do nothing further. If we need to bail out for policy reasons, scavenge // before full gc, or any other specialized behavior, it needs to be added here. // // Note that this method should only be called from the vm_thread while at a // safepoint. // // Note that the all_soft_refs_clear flag in the soft ref policy // may be true because this method can be called without intervening // activity. For example when the heap space is tight and full measure // are being taken to free space. void PSParallelCompact::invoke(bool maximum_heap_compaction) {
assert(SafepointSynchronize::is_at_safepoint(), "should be at safepoint");
assert(Thread::current() == (Thread*)VMThread::vm_thread(), "should be in vm thread");
// This method contains no policy. You should probably // be calling invoke() instead. bool PSParallelCompact::invoke_no_policy(bool maximum_heap_compaction) {
assert(SafepointSynchronize::is_at_safepoint(), "must be at a safepoint");
assert(ref_processor() != NULL, "Sanity");
if (GCLocker::check_active_before_gc()) { returnfalse;
}
// The scope of casr should end after code that can change // SoftRefPolicy::_should_clear_all_soft_refs.
ClearedAllSoftRefs casr(maximum_heap_compaction,
heap->soft_ref_policy());
if (ZapUnusedHeapArea) { // Save information needed to minimize mangling
heap->record_gen_tops_before_GC();
}
// Make sure data structures are sane, make the heap parsable, and do other // miscellaneous bookkeeping.
pre_compact();
// Don't check if the size_policy is ready here. Let // the size_policy check that internally. if (UseAdaptiveGenerationSizePolicyAtMajorCollection &&
AdaptiveSizePolicy::should_update_promo_stats(gc_cause)) { // Swap the survivor spaces if from_space is empty. The // resize_young_gen() called below is normally used after // a successful young GC and swapping of survivor spaces; // otherwise, it will fail to resize the young gen with // the current implementation. if (young_gen->from_space()->is_empty()) {
young_gen->from_space()->clear(SpaceDecorator::Mangle);
young_gen->swap_spaces();
}
// Calculate optimal free space amounts
assert(young_gen->max_gen_size() >
young_gen->from_space()->capacity_in_bytes() +
young_gen->to_space()->capacity_in_bytes(), "Sizes of space in young gen are out-of-bounds");
void PSParallelCompact::marking_phase(ParallelOldTracer *gc_tracer) { // Recursively traverse all live objects and mark them
GCTraceTime(Info, gc, phases) tm("Marking Phase", &_gc_timer);
void PSParallelCompact::adjust_roots() { // Adjust the pointers to reflect the new locations
GCTraceTime(Info, gc, phases) tm("Adjust Roots", &_gc_timer);
uint nworkers = ParallelScavengeHeap::heap()->workers().active_workers();
PSAdjustTask task(nworkers);
ParallelScavengeHeap::heap()->workers().run_task(&task);
}
// Helper class to print 8 region numbers per line and then print the total at the end. class FillableRegionLogger : public StackObj { private:
Log(gc, compaction) log; staticconstint LineLength = 8;
size_t _regions[LineLength]; int _next_index; bool _enabled;
size_t _total_regions; public:
FillableRegionLogger() : _next_index(0), _enabled(log_develop_is_enabled(Trace, gc, compaction)), _total_regions(0) { }
~FillableRegionLogger() {
log.trace(SIZE_FORMAT " initially fillable regions", _total_regions);
}
void print_line() { if (!_enabled || _next_index == 0) { return;
}
FormatBuffer<> line("Fillable: "); for (int i = 0; i < _next_index; i++) {
line.append(" " SIZE_FORMAT_W(7), _regions[i]);
}
log.trace("%s", line.buffer());
_next_index = 0;
}
// Find the threads that are active
uint worker_id = 0;
// Find all regions that are available (can be filled immediately) and // distribute them to the thread stacks. The iteration is done in reverse // order (high to low) so the regions will be removed in ascending order.
// id + 1 is used to test termination so unsigned can // be used with an old_space_id == 0.
FillableRegionLogger region_logger; for (unsignedint id = to_space_id; id + 1 > old_space_id; --id) {
SpaceInfo* const space_info = _space_info + id;
HeapWord* const new_top = space_info->new_top();
for (size_t cur = end_region - 1; cur + 1 > beg_region; --cur) { if (sd.region(cur)->claim_unsafe()) {
ParCompactionManager* cm = ParCompactionManager::gc_thread_compaction_manager(worker_id); bool result = sd.region(cur)->mark_normal();
assert(result, "Must succeed at this point.");
cm->region_stack()->push(cur);
region_logger.handle(cur); // Assign regions to tasks in round-robin fashion. if (++worker_id == parallel_gc_threads) {
worker_id = 0;
}
}
}
region_logger.print_line();
}
}
// Iterate over all the spaces adding tasks for updating // regions in the dense prefix. Assume that 1 gc thread // will work on opening the gaps and the remaining gc threads // will work on the dense prefix. unsignedint space_id; for (space_id = old_space_id; space_id < last_space_id; ++ space_id) {
HeapWord* const dense_prefix_end = _space_info[space_id].dense_prefix(); const MutableSpace* const space = _space_info[space_id].space();
if (dense_prefix_end == space->bottom()) { // There is no dense prefix for this space. continue;
}
// The dense prefix is before this region.
size_t region_index_end_dense_prefix =
sd.addr_to_region_idx(dense_prefix_end);
RegionData* const dense_prefix_cp =
sd.region(region_index_end_dense_prefix);
assert(dense_prefix_end == space->end() ||
dense_prefix_cp->available() ||
dense_prefix_cp->claimed(), "The region after the dense prefix should always be ready to fill");
// Is there dense prefix work?
size_t total_dense_prefix_regions =
region_index_end_dense_prefix - region_index_start; // How many regions of the dense prefix should be given to // each thread? if (total_dense_prefix_regions > 0) {
uint tasks_for_dense_prefix = 1; if (total_dense_prefix_regions <=
(parallel_gc_threads * PAR_OLD_DENSE_PREFIX_OVER_PARTITIONING)) { // Don't over partition. This assumes that // PAR_OLD_DENSE_PREFIX_OVER_PARTITIONING is a small integer value // so there are not many regions to process.
tasks_for_dense_prefix = parallel_gc_threads;
} else { // Over partition
tasks_for_dense_prefix = parallel_gc_threads *
PAR_OLD_DENSE_PREFIX_OVER_PARTITIONING;
}
size_t regions_per_thread = total_dense_prefix_regions /
tasks_for_dense_prefix; // Give each thread at least 1 region. if (regions_per_thread == 0) {
regions_per_thread = 1;
}
for (uint k = 0; k < tasks_for_dense_prefix; k++) { if (region_index_start >= region_index_end_dense_prefix) { break;
} // region_index_end is not processed
size_t region_index_end = MIN2(region_index_start + regions_per_thread,
region_index_end_dense_prefix);
task_queue.push(UpdateDensePrefixTask(SpaceId(space_id),
region_index_start,
region_index_end));
region_index_start = region_index_end;
}
} // This gets any part of the dense prefix that did not // fit evenly. if (region_index_start < region_index_end_dense_prefix) {
task_queue.push(UpdateDensePrefixTask(SpaceId(space_id),
region_index_start,
region_index_end_dense_prefix));
}
}
}
#ifdef ASSERT // Write a histogram of the number of times the block table was filled for a // region. void PSParallelCompact::write_block_fill_histogram()
{ if (!log_develop_is_enabled(Trace, gc, compaction)) { return;
}
while (true) { if (ParCompactionManager::steal(worker_id, region_index)) {
PSParallelCompact::fill_and_update_region(cm, region_index);
cm->drain_region_stacks();
} elseif (PSParallelCompact::steal_unavailable_region(cm, region_index)) { // Fill and update an unavailable region with the help of a shadow region
PSParallelCompact::fill_and_update_shadow_region(cm, region_index);
cm->drain_region_stacks();
} else { if (terminator->offer_termination()) { break;
} // Go around again.
}
}
}
class UpdateDensePrefixAndCompactionTask: public WorkerTask {
TaskQueue& _tq;
TaskTerminator _terminator;
// Once a thread has drained it's stack, it should try to steal regions from // other threads.
compaction_with_stealing_work(&_terminator, worker_id);
// At this point all regions have been compacted, so it's now safe // to update the deferred objects that cross region boundaries.
cm->drain_deferred_objects();
}
};
#ifdef ASSERT // Verify that all regions have been processed. for (unsignedint id = old_space_id; id < last_space_id; ++id) {
verify_complete(SpaceId(id));
} #endif
}
DEBUG_ONLY(write_block_fill_histogram());
}
#ifdef ASSERT void PSParallelCompact::verify_complete(SpaceId space_id) { // All Regions between space bottom() to new_top() should be marked as filled // and all Regions between new_top() and top() should be available (i.e., // should have been emptied).
ParallelCompactData& sd = summary_data();
SpaceInfo si = _space_info[space_id];
HeapWord* new_top_addr = sd.region_align_up(si.new_top());
HeapWord* old_top_addr = sd.region_align_up(si.space()->top()); const size_t beg_region = sd.addr_to_region_idx(si.space()->bottom()); const size_t new_top_region = sd.addr_to_region_idx(new_top_addr); const size_t old_top_region = sd.addr_to_region_idx(old_top_addr);
bool issued_a_warning = false;
size_t cur_region; for (cur_region = beg_region; cur_region < new_top_region; ++cur_region) { const RegionData* const c = sd.region(cur_region); if (!c->completed()) {
log_warning(gc)("region " SIZE_FORMAT " not filled: destination_count=%u",
cur_region, c->destination_count());
issued_a_warning = true;
}
}
for (cur_region = new_top_region; cur_region < old_top_region; ++cur_region) { const RegionData* const c = sd.region(cur_region); if (!c->available()) {
log_warning(gc)("region " SIZE_FORMAT " not empty: destination_count=%u",
cur_region, c->destination_count());
issued_a_warning = true;
}
}
if (issued_a_warning) {
print_region_ranges();
}
} #endif// #ifdef ASSERT
// Update interior oops in the ranges of regions [beg_region, end_region). void
PSParallelCompact::update_and_deadwood_in_dense_prefix(ParCompactionManager* cm,
SpaceId space_id,
size_t beg_region,
size_t end_region) {
ParallelCompactData& sd = summary_data();
ParMarkBitMap* const mbm = mark_bitmap();
HeapWord* beg_addr = sd.region_to_addr(beg_region);
HeapWord* const end_addr = sd.region_to_addr(end_region);
assert(beg_region <= end_region, "bad region range");
assert(end_addr <= dense_prefix(space_id), "not in the dense prefix");
#ifdef ASSERT // Claim the regions to avoid triggering an assert when they are marked as // filled. for (size_t claim_region = beg_region; claim_region < end_region; ++claim_region) {
assert(sd.region(claim_region)->claim_unsafe(), "claim() failed");
} #endif// #ifdef ASSERT
if (beg_addr != space(space_id)->bottom()) { // Find the first live object or block of dead space that *starts* in this // range of regions. If a partial object crosses onto the region, skip it; // it will be marked for 'deferred update' when the object head is // processed. If dead space crosses onto the region, it is also skipped; it // will be filled when the prior region is processed. If neither of those // apply, the first word in the region is the start of a live object or dead // space.
assert(beg_addr > space(space_id)->bottom(), "sanity"); const RegionData* const cp = sd.region(beg_region); if (cp->partial_obj_size() != 0) {
beg_addr = sd.partial_obj_end(beg_region);
} elseif (dead_space_crosses_boundary(cp, mbm->addr_to_bit(beg_addr))) {
beg_addr = mbm->find_obj_beg(beg_addr, end_addr);
}
}
if (beg_addr < end_addr) { // A live object or block of dead space starts in this range of Regions.
HeapWord* const dense_prefix_end = dense_prefix(space_id);
// Create closures and iterate.
UpdateOnlyClosure update_closure(mbm, cm, space_id);
FillClosure fill_closure(cm, space_id);
ParMarkBitMap::IterationStatus status;
status = mbm->iterate(&update_closure, &fill_closure, beg_addr, end_addr,
dense_prefix_end); if (status == ParMarkBitMap::incomplete) {
update_closure.do_addr(update_closure.source());
}
}
// Mark the regions as filled.
RegionData* const beg_cp = sd.region(beg_region);
RegionData* const end_cp = sd.region(end_region); for (RegionData* cp = beg_cp; cp < end_cp; ++cp) {
cp->set_completed();
}
}
// Return the SpaceId for the space containing addr. If addr is not in the // heap, last_space_id is returned. In debug mode it expects the address to be // in the heap and asserts such.
PSParallelCompact::SpaceId PSParallelCompact::space_id(HeapWord* addr) {
assert(ParallelScavengeHeap::heap()->is_in_reserved(addr), "addr not in the heap");
for (unsignedint id = old_space_id; id < last_space_id; ++id) { if (_space_info[id].space()->contains(addr)) { return SpaceId(id);
}
}
assert(false, "no space contains the addr"); return last_space_id;
}
void PSParallelCompact::update_deferred_object(ParCompactionManager* cm, HeapWord *addr) { #ifdef ASSERT
ParallelCompactData& sd = summary_data();
size_t region_idx = sd.addr_to_region_idx(addr);
assert(sd.region(region_idx)->completed(), "first region must be completed before deferred updates");
assert(sd.region(region_idx + 1)->completed(), "second region must be completed before deferred updates"); #endif
cm->update_contents(cast_to_oop(addr));
assert(oopDesc::is_oop(cast_to_oop(addr)), "Expected an oop at " PTR_FORMAT, p2i(cast_to_oop(addr)));
}
// Skip over count live words starting from beg, and return the address of the // next live word. Unless marked, the word corresponding to beg is assumed to // be dead. Callers must either ensure beg does not correspond to the middle of // an object, or account for those live words in some other way. Callers must // also ensure that there are enough live words in the range [beg, end) to skip.
HeapWord*
PSParallelCompact::skip_live_words(HeapWord* beg, HeapWord* end, size_t count)
{
assert(count > 0, "sanity");
// Skipping the desired number of words landed just past the end of an object. // Find the start of the next object.
cur_beg = m->find_obj_beg(cur_beg, search_end);
assert(cur_beg < m->addr_to_bit(end), "not enough live words to skip"); return m->bit_to_addr(cur_beg);
}
const SplitInfo& split_info = _space_info[src_space_id].split_info(); if (split_info.dest_region_addr() == dest_addr) { // The partial object ending at the split point contains the first word to // be copied to dest_addr. return split_info.first_src_addr();
}
HeapWord* addr = src_region_beg; if (dest_addr == src_region_destination) { // Return the first live word in the source region. if (partial_obj_size == 0) {
addr = bitmap->find_obj_beg(addr, src_region_end);
assert(addr < src_region_end, "no objects start in src region");
} return addr;
}
// Must skip some live data.
size_t words_to_skip = dest_addr - src_region_destination;
assert(src_region_ptr->data_size() > words_to_skip, "wrong src region");
if (partial_obj_size >= words_to_skip) { // All the live words to skip are part of the partial object.
addr += words_to_skip; if (partial_obj_size == words_to_skip) { // Find the first live word past the partial object.
addr = bitmap->find_obj_beg(addr, src_region_end);
assert(addr < src_region_end, "wrong src region");
} return addr;
}
// Skip over the partial object (if any). if (partial_obj_size != 0) {
words_to_skip -= partial_obj_size;
addr += partial_obj_size;
}
// Skip over live words due to objects that start in the region.
addr = skip_live_words(addr, src_region_end, words_to_skip);
assert(addr < src_region_end, "wrong src region"); return addr;
}
#ifdef ASSERT
MutableSpace* const src_space = _space_info[src_space_id].space();
HeapWord* const beg_addr = sd.region_to_addr(beg_region);
assert(src_space->contains(beg_addr) || beg_addr == src_space->end(), "src_space_id does not match beg_addr");
assert(src_space->contains(end_addr) || end_addr == src_space->end(), "src_space_id does not match end_addr"); #endif// #ifdef ASSERT
RegionData* const beg = sd.region(beg_region);
RegionData* const end = sd.addr_to_region_ptr(sd.region_align_up(end_addr));
// Regions up to new_top() are enqueued if they become available.
HeapWord* const new_top = _space_info[src_space_id].new_top();
RegionData* const enqueue_end =
sd.addr_to_region_ptr(sd.region_align_up(new_top));
for (RegionData* cur = beg; cur < end; ++cur) {
assert(cur->data_size() > 0, "region must have live data");
cur->decrement_destination_count(); if (cur < enqueue_end && cur->available() && cur->claim()) { if (cur->mark_normal()) {
cm->push_region(sd.region(cur));
} elseif (cur->mark_copied()) { // Try to copy the content of the shadow region back to its corresponding // heap region if the shadow region is filled. Otherwise, the GC thread // fills the shadow region will copy the data back (see // MoveAndUpdateShadowClosure::complete_region).
copy_back(sd.region_to_addr(cur->shadow_region()), sd.region_to_addr(cur));
ParCompactionManager::push_shadow_region_mt_safe(cur->shadow_region());
cur->set_completed();
}
}
}
}
// Skip empty regions (if any) up to the top of the space.
HeapWord* const src_aligned_up = sd.region_align_up(end_addr);
RegionData* src_region_ptr = sd.addr_to_region_ptr(src_aligned_up);
HeapWord* const top_aligned_up = sd.region_align_up(src_space_top); const RegionData* const top_region_ptr =
sd.addr_to_region_ptr(top_aligned_up); while (src_region_ptr < top_region_ptr && src_region_ptr->data_size() == 0) {
++src_region_ptr;
}
if (src_region_ptr < top_region_ptr) { // The next source region is in the current space. Update src_region_idx // and the source address to match src_region_ptr.
src_region_idx = sd.region(src_region_ptr);
HeapWord* const src_region_addr = sd.region_to_addr(src_region_idx); if (src_region_addr > closure.source()) {
closure.set_source(src_region_addr);
} return src_region_idx;
}
// Switch to a new source space and find the first non-empty region. unsignedint space_id = src_space_id + 1;
assert(space_id < last_space_id, "not enough spaces");
do {
MutableSpace* space = _space_info[space_id].space();
HeapWord* const bottom = space->bottom(); const RegionData* const bottom_cp = sd.addr_to_region_ptr(bottom);
// Iterate over the spaces that do not compact into themselves. if (bottom_cp->destination() != bottom) {
HeapWord* const top_aligned_up = sd.region_align_up(space->top()); const RegionData* const top_cp = sd.addr_to_region_ptr(top_aligned_up);
for (const RegionData* src_cp = bottom_cp; src_cp < top_cp; ++src_cp) { if (src_cp->live_obj_size() > 0) { // Found it.
assert(src_cp->destination() == destination, "first live obj in the space must match the destination");
assert(src_cp->partial_obj_size() == 0, "a space cannot begin with a partial obj");
// Get the source region and related info.
size_t src_region_idx = region_ptr->source_region();
SpaceId src_space_id = space_id(sd.region_to_addr(src_region_idx));
HeapWord* src_space_top = _space_info[src_space_id].space()->top();
HeapWord* dest_addr = sd.region_to_addr(region_idx);
// Adjust src_region_idx to prepare for decrementing destination counts (the // destination count is not decremented when a region is copied to itself). if (src_region_idx == region_idx) {
src_region_idx += 1;
}
if (bitmap->is_unmarked(closure.source())) { // The first source word is in the middle of an object; copy the remainder // of the object or as much as will fit. The fact that pointer updates were // deferred will be noted when the object header is processed.
HeapWord* const old_src_addr = closure.source();
closure.copy_partial_obj(); if (closure.is_full()) {
decrement_destination_counts(cm, src_space_id, src_region_idx,
closure.source());
closure.complete_region(cm, dest_addr, region_ptr); return;
}
HeapWord* const end_addr = sd.region_align_down(closure.source()); if (sd.region_align_down(old_src_addr) != end_addr) { // The partial object was copied from more than one source region.
decrement_destination_counts(cm, src_space_id, src_region_idx, end_addr);
// Move to the next source region, possibly switching spaces as well. All // args except end_addr may be modified.
src_region_idx = next_src_region(closure, src_space_id, src_space_top,
end_addr);
}
}
if (status == ParMarkBitMap::incomplete) { // The last obj that starts in the source region does not end in the // region.
assert(closure.source() < end_addr, "sanity");
HeapWord* const obj_beg = closure.source();
HeapWord* const range_end = MIN2(obj_beg + closure.words_remaining(),
src_space_top);
HeapWord* const obj_end = bitmap->find_obj_end(obj_beg, range_end); if (obj_end < range_end) { // The end was found; the entire object will fit.
status = closure.do_addr(obj_beg, bitmap->obj_size(obj_beg, obj_end));
assert(status != ParMarkBitMap::would_overflow, "sanity");
} else { // The end was not found; the object will not fit.
assert(range_end < src_space_top, "obj cannot cross space boundary");
status = ParMarkBitMap::would_overflow;
}
}
if (status == ParMarkBitMap::would_overflow) { // The last object did not fit. Note that interior oop updates were // deferred, then copy enough of the object to fill the region.
cm->push_deferred_object(closure.destination());
status = closure.copy_until_full(); // copies from closure.source()
// Move to the next source region, possibly switching spaces as well. All // args except end_addr may be modified.
src_region_idx = next_src_region(closure, src_space_id, src_space_top,
end_addr);
} while (true);
}
void PSParallelCompact::fill_and_update_region(ParCompactionManager* cm, size_t region_idx)
{
MoveAndUpdateClosure cl(mark_bitmap(), cm, region_idx);
fill_region(cm, cl, region_idx);
}
void PSParallelCompact::fill_and_update_shadow_region(ParCompactionManager* cm, size_t region_idx)
{ // Get a shadow region first
ParallelCompactData& sd = summary_data();
RegionData* const region_ptr = sd.region(region_idx);
size_t shadow_region = ParCompactionManager::pop_shadow_region_mt_safe(region_ptr); // The InvalidShadow return value indicates the corresponding heap region is available, // so use MoveAndUpdateClosure to fill the normal region. Otherwise, use // MoveAndUpdateShadowClosure to fill the acquired shadow region. if (shadow_region == ParCompactionManager::InvalidShadow) {
MoveAndUpdateClosure cl(mark_bitmap(), cm, region_idx);
region_ptr->shadow_to_normal(); return fill_region(cm, cl, region_idx);
} else {
MoveAndUpdateShadowClosure cl(mark_bitmap(), cm, region_idx, shadow_region); return fill_region(cm, cl, region_idx);
}
}
while (next < old_new_top) { if (sd.region(next)->mark_shadow()) {
region_idx = next; returntrue;
}
next = cm->move_next_shadow_region_by(active_gc_threads);
}
returnfalse;
}
// The shadow region is an optimization to address region dependencies in full GC. The basic // idea is making more regions available by temporally storing their live objects in empty // shadow regions to resolve dependencies between them and the destination regions. Therefore, // GC threads need not wait destination regions to be available before processing sources. // // A typical workflow would be: // After draining its own stack and failing to steal from others, a GC worker would pick an // unavailable region (destination count > 0) and get a shadow region. Then the worker fills // the shadow region by copying live objects from source regions of the unavailable one. Once // the unavailable region becomes available, the data in the shadow region will be copied back. // Shadow regions are empty regions in the to-space and regions between top and end of other spaces. void PSParallelCompact::initialize_shadow_regions(uint parallel_gc_threads)
{ const ParallelCompactData& sd = PSParallelCompact::summary_data();
for (unsignedint id = old_space_id; id < last_space_id; ++id) {
SpaceInfo* const space_info = _space_info + id;
MutableSpace* const space = space_info->space();
for (size_t cur = beg_region; cur < end_region; ++cur) {
ParCompactionManager::push_shadow_region(cur);
}
}
size_t beg_region = sd.addr_to_region_idx(_space_info[old_space_id].dense_prefix()); for (uint i = 0; i < parallel_gc_threads; i++) {
ParCompactionManager *cm = ParCompactionManager::gc_thread_compaction_manager(i);
cm->set_next_shadow_region(beg_region + i);
}
}
void PSParallelCompact::fill_blocks(size_t region_idx)
{ // Fill in the block table elements for the specified region. Each block // table element holds the number of live words in the region that are to the // left of the first object that starts in the block. Thus only blocks in // which an object starts need to be filled. // // The algorithm scans the section of the bitmap that corresponds to the // region, keeping a running total of the live words. When an object start is // found, if it's the first to start in the block that contains it, the // current total is written to the block table element. const size_t Log2BlockSize = ParallelCompactData::Log2BlockSize; const size_t Log2RegionSize = ParallelCompactData::Log2RegionSize; const size_t RegionSize = ParallelCompactData::RegionSize;
ParallelCompactData& sd = summary_data(); const size_t partial_obj_size = sd.region(region_idx)->partial_obj_size(); if (partial_obj_size >= RegionSize) { return; // No objects start in this region.
}
// Ensure the first loop iteration decides that the block has changed.
size_t cur_block = sd.block_count();
// This test is necessary; if omitted, the pointer updates to a partial object // that crosses the dense prefix boundary could be overwritten. if (source() != copy_destination()) {
DEBUG_ONLY(PSParallelCompact::check_new_location(source(), destination());)
Copy::aligned_conjoint_words(source(), copy_destination(), words);
}
update_state(words);
}
void MoveAndUpdateClosure::complete_region(ParCompactionManager *cm, HeapWord *dest_addr,
PSParallelCompact::RegionData *region_ptr) {
assert(region_ptr->shadow_state() == ParallelCompactData::RegionData::NormalRegion, "Region should be finished");
region_ptr->set_completed();
}
oop moved_oop = cast_to_oop(copy_destination());
compaction_manager()->update_contents(moved_oop);
assert(oopDesc::is_oop_or_null(moved_oop), "Expected an oop or NULL at " PTR_FORMAT, p2i(moved_oop));
void MoveAndUpdateShadowClosure::complete_region(ParCompactionManager *cm, HeapWord *dest_addr,
PSParallelCompact::RegionData *region_ptr) {
assert(region_ptr->shadow_state() == ParallelCompactData::RegionData::ShadowRegion, "Region should be shadow"); // Record the shadow region index
region_ptr->set_shadow_region(_shadow); // Mark the shadow region as filled to indicate the data is ready to be // copied back
region_ptr->mark_filled(); // Try to copy the content of the shadow region back to its corresponding // heap region if available; the GC thread that decreases the destination // count to zero will do the copying otherwise (see // PSParallelCompact::decrement_destination_counts). if (((region_ptr->available() && region_ptr->claim()) || region_ptr->claimed()) && region_ptr->mark_copied()) {
region_ptr->set_completed();
PSParallelCompact::copy_back(PSParallelCompact::summary_data().region_to_addr(_shadow), dest_addr);
ParCompactionManager::push_shadow_region_mt_safe(_shadow);
}
}
// Updates the references in the object to their new values.
ParMarkBitMapClosure::IterationStatus
UpdateOnlyClosure::do_addr(HeapWord* addr, size_t words) {
do_addr(addr); return ParMarkBitMap::incomplete;
}
FillClosure::FillClosure(ParCompactionManager* cm, PSParallelCompact::SpaceId space_id) :
ParMarkBitMapClosure(PSParallelCompact::mark_bitmap(), cm),
_start_array(PSParallelCompact::start_array(space_id))
{
assert(space_id == PSParallelCompact::old_space_id, "cannot use FillClosure in the young gen");
}
ParMarkBitMapClosure::IterationStatus
FillClosure::do_addr(HeapWord* addr, size_t size) {
CollectedHeap::fill_with_objects(addr, size);
HeapWord* const end = addr + size; do {
_start_array->allocate_block(addr);
addr += cast_to_oop(addr)->size();
} while (addr < end); return ParMarkBitMap::incomplete;
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.40 Sekunden
(vorverarbeitet am 2026-04-28)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.