0N/A/*
1879N/A * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#include "precompiled.hpp"
1879N/A#include "gc_implementation/concurrentMarkSweep/cmsAdaptiveSizePolicy.hpp"
1879N/A#include "gc_implementation/concurrentMarkSweep/cmsGCAdaptivePolicyCounters.hpp"
1879N/A#include "gc_implementation/parNew/asParNewGeneration.hpp"
1879N/A#include "gc_implementation/parNew/parNewGeneration.hpp"
1879N/A#include "gc_implementation/shared/markSweep.inline.hpp"
1879N/A#include "gc_implementation/shared/spaceDecorator.hpp"
1879N/A#include "memory/defNewGeneration.inline.hpp"
1879N/A#include "memory/referencePolicy.hpp"
1879N/A#include "oops/markOop.inline.hpp"
1879N/A#include "oops/oop.pcgc.inline.hpp"
0N/A
0N/AASParNewGeneration::ASParNewGeneration(ReservedSpace rs,
0N/A size_t initial_byte_size,
0N/A size_t min_byte_size,
0N/A int level) :
0N/A ParNewGeneration(rs, initial_byte_size, level),
0N/A _min_gen_size(min_byte_size) {}
0N/A
0N/Aconst char* ASParNewGeneration::name() const {
0N/A return "adaptive size par new generation";
0N/A}
0N/A
0N/Avoid ASParNewGeneration::adjust_desired_tenuring_threshold() {
0N/A assert(UseAdaptiveSizePolicy,
0N/A "Should only be used with UseAdaptiveSizePolicy");
0N/A}
0N/A
0N/Avoid ASParNewGeneration::resize(size_t eden_size, size_t survivor_size) {
0N/A // Resize the generation if needed. If the generation resize
0N/A // reports false, do not attempt to resize the spaces.
0N/A if (resize_generation(eden_size, survivor_size)) {
0N/A // Then we lay out the spaces inside the generation
0N/A resize_spaces(eden_size, survivor_size);
0N/A
0N/A space_invariants();
0N/A
0N/A if (PrintAdaptiveSizePolicy && Verbose) {
0N/A gclog_or_tty->print_cr("Young generation size: "
0N/A "desired eden: " SIZE_FORMAT " survivor: " SIZE_FORMAT
0N/A " used: " SIZE_FORMAT " capacity: " SIZE_FORMAT
0N/A " gen limits: " SIZE_FORMAT " / " SIZE_FORMAT,
0N/A eden_size, survivor_size, used(), capacity(),
0N/A max_gen_size(), min_gen_size());
0N/A }
0N/A }
0N/A}
0N/A
0N/Asize_t ASParNewGeneration::available_to_min_gen() {
0N/A assert(virtual_space()->committed_size() >= min_gen_size(), "Invariant");
0N/A return virtual_space()->committed_size() - min_gen_size();
0N/A}
0N/A
0N/A// This method assumes that from-space has live data and that
0N/A// any shrinkage of the young gen is limited by location of
0N/A// from-space.
0N/Asize_t ASParNewGeneration::available_to_live() const {
0N/A#undef SHRINKS_AT_END_OF_EDEN
0N/A#ifdef SHRINKS_AT_END_OF_EDEN
0N/A size_t delta_in_survivor = 0;
0N/A ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
13N/A const size_t space_alignment = heap->intra_heap_alignment();
13N/A const size_t gen_alignment = heap->object_heap_alignment();
0N/A
0N/A MutableSpace* space_shrinking = NULL;
0N/A if (from_space()->end() > to_space()->end()) {
0N/A space_shrinking = from_space();
0N/A } else {
0N/A space_shrinking = to_space();
0N/A }
0N/A
0N/A // Include any space that is committed but not included in
0N/A // the survivor spaces.
0N/A assert(((HeapWord*)virtual_space()->high()) >= space_shrinking->end(),
0N/A "Survivor space beyond high end");
0N/A size_t unused_committed = pointer_delta(virtual_space()->high(),
0N/A space_shrinking->end(), sizeof(char));
0N/A
0N/A if (space_shrinking->is_empty()) {
0N/A // Don't let the space shrink to 0
0N/A assert(space_shrinking->capacity_in_bytes() >= space_alignment,
0N/A "Space is too small");
0N/A delta_in_survivor = space_shrinking->capacity_in_bytes() - space_alignment;
0N/A } else {
0N/A delta_in_survivor = pointer_delta(space_shrinking->end(),
0N/A space_shrinking->top(),
0N/A sizeof(char));
0N/A }
0N/A
0N/A size_t delta_in_bytes = unused_committed + delta_in_survivor;
0N/A delta_in_bytes = align_size_down(delta_in_bytes, gen_alignment);
0N/A return delta_in_bytes;
0N/A#else
0N/A // The only space available for shrinking is in to-space if it
0N/A // is above from-space.
0N/A if (to()->bottom() > from()->bottom()) {
0N/A const size_t alignment = os::vm_page_size();
0N/A if (to()->capacity() < alignment) {
0N/A return 0;
0N/A } else {
0N/A return to()->capacity() - alignment;
0N/A }
0N/A } else {
0N/A return 0;
0N/A }
0N/A#endif
0N/A}
0N/A
0N/A// Return the number of bytes available for resizing down the young
0N/A// generation. This is the minimum of
0N/A// input "bytes"
0N/A// bytes to the minimum young gen size
0N/A// bytes to the size currently being used + some small extra
0N/Asize_t ASParNewGeneration::limit_gen_shrink (size_t bytes) {
0N/A // Allow shrinkage into the current eden but keep eden large enough
0N/A // to maintain the minimum young gen size
0N/A bytes = MIN3(bytes, available_to_min_gen(), available_to_live());
0N/A return align_size_down(bytes, os::vm_page_size());
0N/A}
0N/A
0N/A// Note that the the alignment used is the OS page size as
0N/A// opposed to an alignment associated with the virtual space
0N/A// (as is done in the ASPSYoungGen/ASPSOldGen)
0N/Abool ASParNewGeneration::resize_generation(size_t eden_size,
0N/A size_t survivor_size) {
0N/A const size_t alignment = os::vm_page_size();
0N/A size_t orig_size = virtual_space()->committed_size();
0N/A bool size_changed = false;
0N/A
0N/A // There used to be this guarantee there.
0N/A // guarantee ((eden_size + 2*survivor_size) <= _max_gen_size, "incorrect input arguments");
0N/A // Code below forces this requirement. In addition the desired eden
0N/A // size and disired survivor sizes are desired goals and may
0N/A // exceed the total generation size.
0N/A
0N/A assert(min_gen_size() <= orig_size && orig_size <= max_gen_size(),
0N/A "just checking");
0N/A
0N/A // Adjust new generation size
0N/A const size_t eden_plus_survivors =
0N/A align_size_up(eden_size + 2 * survivor_size, alignment);
0N/A size_t desired_size = MAX2(MIN2(eden_plus_survivors, max_gen_size()),
0N/A min_gen_size());
0N/A assert(desired_size <= max_gen_size(), "just checking");
0N/A
0N/A if (desired_size > orig_size) {
0N/A // Grow the generation
0N/A size_t change = desired_size - orig_size;
0N/A assert(change % alignment == 0, "just checking");
263N/A if (expand(change)) {
0N/A return false; // Error if we fail to resize!
0N/A }
0N/A size_changed = true;
0N/A } else if (desired_size < orig_size) {
0N/A size_t desired_change = orig_size - desired_size;
0N/A assert(desired_change % alignment == 0, "just checking");
0N/A
0N/A desired_change = limit_gen_shrink(desired_change);
0N/A
0N/A if (desired_change > 0) {
0N/A virtual_space()->shrink_by(desired_change);
0N/A reset_survivors_after_shrink();
0N/A
0N/A size_changed = true;
0N/A }
0N/A } else {
0N/A if (Verbose && PrintGC) {
0N/A if (orig_size == max_gen_size()) {
0N/A gclog_or_tty->print_cr("ASParNew generation size at maximum: "
0N/A SIZE_FORMAT "K", orig_size/K);
0N/A } else if (orig_size == min_gen_size()) {
0N/A gclog_or_tty->print_cr("ASParNew generation size at minium: "
0N/A SIZE_FORMAT "K", orig_size/K);
0N/A }
0N/A }
0N/A }
0N/A
0N/A if (size_changed) {
0N/A MemRegion cmr((HeapWord*)virtual_space()->low(),
0N/A (HeapWord*)virtual_space()->high());
0N/A GenCollectedHeap::heap()->barrier_set()->resize_covered_region(cmr);
0N/A
0N/A if (Verbose && PrintGC) {
0N/A size_t current_size = virtual_space()->committed_size();
0N/A gclog_or_tty->print_cr("ASParNew generation size changed: "
0N/A SIZE_FORMAT "K->" SIZE_FORMAT "K",
0N/A orig_size/K, current_size/K);
0N/A }
0N/A }
0N/A
0N/A guarantee(eden_plus_survivors <= virtual_space()->committed_size() ||
0N/A virtual_space()->committed_size() == max_gen_size(), "Sanity");
0N/A
0N/A return true;
0N/A}
0N/A
0N/Avoid ASParNewGeneration::reset_survivors_after_shrink() {
0N/A
0N/A GenCollectedHeap* gch = GenCollectedHeap::heap();
0N/A HeapWord* new_end = (HeapWord*)virtual_space()->high();
0N/A
0N/A if (from()->end() > to()->end()) {
0N/A assert(new_end >= from()->end(), "Shrinking past from-space");
0N/A } else {
0N/A assert(new_end >= to()->bottom(), "Shrink was too large");
0N/A // Was there a shrink of the survivor space?
0N/A if (new_end < to()->end()) {
0N/A MemRegion mr(to()->bottom(), new_end);
263N/A to()->initialize(mr,
263N/A SpaceDecorator::DontClear,
263N/A SpaceDecorator::DontMangle);
0N/A }
0N/A }
0N/A}
0N/Avoid ASParNewGeneration::resize_spaces(size_t requested_eden_size,
0N/A size_t requested_survivor_size) {
0N/A assert(UseAdaptiveSizePolicy, "sanity check");
0N/A assert(requested_eden_size > 0 && requested_survivor_size > 0,
0N/A "just checking");
0N/A CollectedHeap* heap = Universe::heap();
0N/A assert(heap->kind() == CollectedHeap::GenCollectedHeap, "Sanity");
0N/A
0N/A
0N/A // We require eden and to space to be empty
0N/A if ((!eden()->is_empty()) || (!to()->is_empty())) {
0N/A return;
0N/A }
0N/A
0N/A size_t cur_eden_size = eden()->capacity();
0N/A
0N/A if (PrintAdaptiveSizePolicy && Verbose) {
0N/A gclog_or_tty->print_cr("ASParNew::resize_spaces(requested_eden_size: "
0N/A SIZE_FORMAT
0N/A ", requested_survivor_size: " SIZE_FORMAT ")",
0N/A requested_eden_size, requested_survivor_size);
0N/A gclog_or_tty->print_cr(" eden: [" PTR_FORMAT ".." PTR_FORMAT ") "
0N/A SIZE_FORMAT,
0N/A eden()->bottom(),
0N/A eden()->end(),
0N/A pointer_delta(eden()->end(),
0N/A eden()->bottom(),
0N/A sizeof(char)));
0N/A gclog_or_tty->print_cr(" from: [" PTR_FORMAT ".." PTR_FORMAT ") "
0N/A SIZE_FORMAT,
0N/A from()->bottom(),
0N/A from()->end(),
0N/A pointer_delta(from()->end(),
0N/A from()->bottom(),
0N/A sizeof(char)));
0N/A gclog_or_tty->print_cr(" to: [" PTR_FORMAT ".." PTR_FORMAT ") "
0N/A SIZE_FORMAT,
0N/A to()->bottom(),
0N/A to()->end(),
0N/A pointer_delta( to()->end(),
0N/A to()->bottom(),
0N/A sizeof(char)));
0N/A }
0N/A
0N/A // There's nothing to do if the new sizes are the same as the current
0N/A if (requested_survivor_size == to()->capacity() &&
0N/A requested_survivor_size == from()->capacity() &&
0N/A requested_eden_size == eden()->capacity()) {
0N/A if (PrintAdaptiveSizePolicy && Verbose) {
0N/A gclog_or_tty->print_cr(" capacities are the right sizes, returning");
0N/A }
0N/A return;
0N/A }
0N/A
0N/A char* eden_start = (char*)eden()->bottom();
0N/A char* eden_end = (char*)eden()->end();
0N/A char* from_start = (char*)from()->bottom();
0N/A char* from_end = (char*)from()->end();
0N/A char* to_start = (char*)to()->bottom();
0N/A char* to_end = (char*)to()->end();
0N/A
0N/A const size_t alignment = os::vm_page_size();
0N/A const bool maintain_minimum =
0N/A (requested_eden_size + 2 * requested_survivor_size) <= min_gen_size();
0N/A
0N/A // Check whether from space is below to space
0N/A if (from_start < to_start) {
0N/A // Eden, from, to
0N/A if (PrintAdaptiveSizePolicy && Verbose) {
0N/A gclog_or_tty->print_cr(" Eden, from, to:");
0N/A }
0N/A
0N/A // Set eden
0N/A // "requested_eden_size" is a goal for the size of eden
0N/A // and may not be attainable. "eden_size" below is
0N/A // calculated based on the location of from-space and
0N/A // the goal for the size of eden. from-space is
0N/A // fixed in place because it contains live data.
0N/A // The calculation is done this way to avoid 32bit
0N/A // overflow (i.e., eden_start + requested_eden_size
0N/A // may too large for representation in 32bits).
0N/A size_t eden_size;
0N/A if (maintain_minimum) {
0N/A // Only make eden larger than the requested size if
0N/A // the minimum size of the generation has to be maintained.
0N/A // This could be done in general but policy at a higher
0N/A // level is determining a requested size for eden and that
0N/A // should be honored unless there is a fundamental reason.
0N/A eden_size = pointer_delta(from_start,
0N/A eden_start,
0N/A sizeof(char));
0N/A } else {
0N/A eden_size = MIN2(requested_eden_size,
0N/A pointer_delta(from_start, eden_start, sizeof(char)));
0N/A }
0N/A
0N/A eden_size = align_size_down(eden_size, alignment);
0N/A eden_end = eden_start + eden_size;
1409N/A assert(eden_end >= eden_start, "addition overflowed");
0N/A
0N/A // To may resize into from space as long as it is clear of live data.
0N/A // From space must remain page aligned, though, so we need to do some
0N/A // extra calculations.
0N/A
0N/A // First calculate an optimal to-space
0N/A to_end = (char*)virtual_space()->high();
0N/A to_start = (char*)pointer_delta(to_end, (char*)requested_survivor_size,
0N/A sizeof(char));
0N/A
0N/A // Does the optimal to-space overlap from-space?
0N/A if (to_start < (char*)from()->end()) {
0N/A // Calculate the minimum offset possible for from_end
0N/A size_t from_size = pointer_delta(from()->top(), from_start, sizeof(char));
0N/A
0N/A // Should we be in this method if from_space is empty? Why not the set_space method? FIX ME!
0N/A if (from_size == 0) {
0N/A from_size = alignment;
0N/A } else {
0N/A from_size = align_size_up(from_size, alignment);
0N/A }
0N/A
0N/A from_end = from_start + from_size;
0N/A assert(from_end > from_start, "addition overflow or from_size problem");
0N/A
0N/A guarantee(from_end <= (char*)from()->end(), "from_end moved to the right");
0N/A
0N/A // Now update to_start with the new from_end
0N/A to_start = MAX2(from_end, to_start);
0N/A } else {
0N/A // If shrinking, move to-space down to abut the end of from-space
0N/A // so that shrinking will move to-space down. If not shrinking
0N/A // to-space is moving up to allow for growth on the next expansion.
0N/A if (requested_eden_size <= cur_eden_size) {
0N/A to_start = from_end;
0N/A if (to_start + requested_survivor_size > to_start) {
0N/A to_end = to_start + requested_survivor_size;
0N/A }
0N/A }
0N/A // else leave to_end pointing to the high end of the virtual space.
0N/A }
0N/A
0N/A guarantee(to_start != to_end, "to space is zero sized");
0N/A
0N/A if (PrintAdaptiveSizePolicy && Verbose) {
0N/A gclog_or_tty->print_cr(" [eden_start .. eden_end): "
0N/A "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT,
0N/A eden_start,
0N/A eden_end,
0N/A pointer_delta(eden_end, eden_start, sizeof(char)));
0N/A gclog_or_tty->print_cr(" [from_start .. from_end): "
0N/A "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT,
0N/A from_start,
0N/A from_end,
0N/A pointer_delta(from_end, from_start, sizeof(char)));
0N/A gclog_or_tty->print_cr(" [ to_start .. to_end): "
0N/A "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT,
0N/A to_start,
0N/A to_end,
0N/A pointer_delta( to_end, to_start, sizeof(char)));
0N/A }
0N/A } else {
0N/A // Eden, to, from
0N/A if (PrintAdaptiveSizePolicy && Verbose) {
0N/A gclog_or_tty->print_cr(" Eden, to, from:");
0N/A }
0N/A
0N/A // Calculate the to-space boundaries based on
0N/A // the start of from-space.
0N/A to_end = from_start;
0N/A to_start = (char*)pointer_delta(from_start,
0N/A (char*)requested_survivor_size,
0N/A sizeof(char));
0N/A // Calculate the ideal eden boundaries.
0N/A // eden_end is already at the bottom of the generation
0N/A assert(eden_start == virtual_space()->low(),
0N/A "Eden is not starting at the low end of the virtual space");
0N/A if (eden_start + requested_eden_size >= eden_start) {
0N/A eden_end = eden_start + requested_eden_size;
0N/A } else {
0N/A eden_end = to_start;
0N/A }
0N/A
0N/A // Does eden intrude into to-space? to-space
0N/A // gets priority but eden is not allowed to shrink
0N/A // to 0.
0N/A if (eden_end > to_start) {
0N/A eden_end = to_start;
0N/A }
0N/A
0N/A // Don't let eden shrink down to 0 or less.
0N/A eden_end = MAX2(eden_end, eden_start + alignment);
0N/A assert(eden_start + alignment >= eden_start, "Overflow");
0N/A
0N/A size_t eden_size;
0N/A if (maintain_minimum) {
0N/A // Use all the space available.
0N/A eden_end = MAX2(eden_end, to_start);
0N/A eden_size = pointer_delta(eden_end, eden_start, sizeof(char));
0N/A eden_size = MIN2(eden_size, cur_eden_size);
0N/A } else {
0N/A eden_size = pointer_delta(eden_end, eden_start, sizeof(char));
0N/A }
0N/A eden_size = align_size_down(eden_size, alignment);
0N/A assert(maintain_minimum || eden_size <= requested_eden_size,
0N/A "Eden size is too large");
0N/A assert(eden_size >= alignment, "Eden size is too small");
0N/A eden_end = eden_start + eden_size;
0N/A
0N/A // Move to-space down to eden.
0N/A if (requested_eden_size < cur_eden_size) {
0N/A to_start = eden_end;
0N/A if (to_start + requested_survivor_size > to_start) {
0N/A to_end = MIN2(from_start, to_start + requested_survivor_size);
0N/A } else {
0N/A to_end = from_start;
0N/A }
0N/A }
0N/A
0N/A // eden_end may have moved so again make sure
0N/A // the to-space and eden don't overlap.
0N/A to_start = MAX2(eden_end, to_start);
0N/A
0N/A // from-space
0N/A size_t from_used = from()->used();
0N/A if (requested_survivor_size > from_used) {
0N/A if (from_start + requested_survivor_size >= from_start) {
0N/A from_end = from_start + requested_survivor_size;
0N/A }
0N/A if (from_end > virtual_space()->high()) {
0N/A from_end = virtual_space()->high();
0N/A }
0N/A }
0N/A
0N/A assert(to_start >= eden_end, "to-space should be above eden");
0N/A if (PrintAdaptiveSizePolicy && Verbose) {
0N/A gclog_or_tty->print_cr(" [eden_start .. eden_end): "
0N/A "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT,
0N/A eden_start,
0N/A eden_end,
0N/A pointer_delta(eden_end, eden_start, sizeof(char)));
0N/A gclog_or_tty->print_cr(" [ to_start .. to_end): "
0N/A "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT,
0N/A to_start,
0N/A to_end,
0N/A pointer_delta( to_end, to_start, sizeof(char)));
0N/A gclog_or_tty->print_cr(" [from_start .. from_end): "
0N/A "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT,
0N/A from_start,
0N/A from_end,
0N/A pointer_delta(from_end, from_start, sizeof(char)));
0N/A }
0N/A }
0N/A
0N/A
0N/A guarantee((HeapWord*)from_start <= from()->bottom(),
0N/A "from start moved to the right");
0N/A guarantee((HeapWord*)from_end >= from()->top(),
0N/A "from end moved into live data");
0N/A assert(is_object_aligned((intptr_t)eden_start), "checking alignment");
0N/A assert(is_object_aligned((intptr_t)from_start), "checking alignment");
0N/A assert(is_object_aligned((intptr_t)to_start), "checking alignment");
0N/A
0N/A MemRegion edenMR((HeapWord*)eden_start, (HeapWord*)eden_end);
0N/A MemRegion toMR ((HeapWord*)to_start, (HeapWord*)to_end);
0N/A MemRegion fromMR((HeapWord*)from_start, (HeapWord*)from_end);
0N/A
0N/A // Let's make sure the call to initialize doesn't reset "top"!
0N/A HeapWord* old_from_top = from()->top();
0N/A
0N/A // For PrintAdaptiveSizePolicy block below
0N/A size_t old_from = from()->capacity();
0N/A size_t old_to = to()->capacity();
0N/A
263N/A // If not clearing the spaces, do some checking to verify that
263N/A // the spaces are already mangled.
263N/A
263N/A // Must check mangling before the spaces are reshaped. Otherwise,
263N/A // the bottom or end of one space may have moved into another
263N/A // a failure of the check may not correctly indicate which space
263N/A // is not properly mangled.
263N/A if (ZapUnusedHeapArea) {
263N/A HeapWord* limit = (HeapWord*) virtual_space()->high();
263N/A eden()->check_mangled_unused_area(limit);
263N/A from()->check_mangled_unused_area(limit);
263N/A to()->check_mangled_unused_area(limit);
263N/A }
263N/A
0N/A // The call to initialize NULL's the next compaction space
263N/A eden()->initialize(edenMR,
263N/A SpaceDecorator::Clear,
263N/A SpaceDecorator::DontMangle);
0N/A eden()->set_next_compaction_space(from());
263N/A to()->initialize(toMR ,
263N/A SpaceDecorator::Clear,
263N/A SpaceDecorator::DontMangle);
263N/A from()->initialize(fromMR,
263N/A SpaceDecorator::DontClear,
263N/A SpaceDecorator::DontMangle);
0N/A
0N/A assert(from()->top() == old_from_top, "from top changed!");
0N/A
0N/A if (PrintAdaptiveSizePolicy) {
0N/A GenCollectedHeap* gch = GenCollectedHeap::heap();
0N/A assert(gch->kind() == CollectedHeap::GenCollectedHeap, "Sanity");
0N/A
0N/A gclog_or_tty->print("AdaptiveSizePolicy::survivor space sizes: "
0N/A "collection: %d "
0N/A "(" SIZE_FORMAT ", " SIZE_FORMAT ") -> "
0N/A "(" SIZE_FORMAT ", " SIZE_FORMAT ") ",
0N/A gch->total_collections(),
0N/A old_from, old_to,
0N/A from()->capacity(),
0N/A to()->capacity());
0N/A gclog_or_tty->cr();
0N/A }
0N/A}
0N/A
0N/Avoid ASParNewGeneration::compute_new_size() {
0N/A GenCollectedHeap* gch = GenCollectedHeap::heap();
0N/A assert(gch->kind() == CollectedHeap::GenCollectedHeap,
0N/A "not a CMS generational heap");
0N/A
0N/A
0N/A CMSAdaptiveSizePolicy* size_policy =
0N/A (CMSAdaptiveSizePolicy*)gch->gen_policy()->size_policy();
0N/A assert(size_policy->is_gc_cms_adaptive_size_policy(),
0N/A "Wrong type of size policy");
0N/A
0N/A size_t survived = from()->used();
0N/A if (!survivor_overflow()) {
0N/A // Keep running averages on how much survived
0N/A size_policy->avg_survived()->sample(survived);
0N/A } else {
0N/A size_t promoted =
0N/A (size_t) next_gen()->gc_stats()->avg_promoted()->last_sample();
0N/A assert(promoted < gch->capacity(), "Conversion problem?");
0N/A size_t survived_guess = survived + promoted;
0N/A size_policy->avg_survived()->sample(survived_guess);
0N/A }
0N/A
0N/A size_t survivor_limit = max_survivor_size();
0N/A _tenuring_threshold =
0N/A size_policy->compute_survivor_space_size_and_threshold(
0N/A _survivor_overflow,
0N/A _tenuring_threshold,
0N/A survivor_limit);
0N/A size_policy->avg_young_live()->sample(used());
0N/A size_policy->avg_eden_live()->sample(eden()->used());
0N/A
0N/A size_policy->compute_young_generation_free_space(eden()->capacity(),
0N/A max_gen_size());
0N/A
0N/A resize(size_policy->calculated_eden_size_in_bytes(),
0N/A size_policy->calculated_survivor_size_in_bytes());
0N/A
0N/A if (UsePerfData) {
0N/A CMSGCAdaptivePolicyCounters* counters =
0N/A (CMSGCAdaptivePolicyCounters*) gch->collector_policy()->counters();
0N/A assert(counters->kind() ==
0N/A GCPolicyCounters::CMSGCAdaptivePolicyCountersKind,
0N/A "Wrong kind of counters");
0N/A counters->update_tenuring_threshold(_tenuring_threshold);
0N/A counters->update_survivor_overflowed(_survivor_overflow);
0N/A counters->update_young_capacity(capacity());
0N/A }
0N/A}
0N/A
0N/A
0N/A#ifndef PRODUCT
0N/A// Changes from PSYoungGen version
0N/A// value of "alignment"
0N/Avoid ASParNewGeneration::space_invariants() {
0N/A const size_t alignment = os::vm_page_size();
0N/A
0N/A // Currently, our eden size cannot shrink to zero
0N/A guarantee(eden()->capacity() >= alignment, "eden too small");
0N/A guarantee(from()->capacity() >= alignment, "from too small");
0N/A guarantee(to()->capacity() >= alignment, "to too small");
0N/A
0N/A // Relationship of spaces to each other
0N/A char* eden_start = (char*)eden()->bottom();
0N/A char* eden_end = (char*)eden()->end();
0N/A char* from_start = (char*)from()->bottom();
0N/A char* from_end = (char*)from()->end();
0N/A char* to_start = (char*)to()->bottom();
0N/A char* to_end = (char*)to()->end();
0N/A
0N/A guarantee(eden_start >= virtual_space()->low(), "eden bottom");
0N/A guarantee(eden_start < eden_end, "eden space consistency");
0N/A guarantee(from_start < from_end, "from space consistency");
0N/A guarantee(to_start < to_end, "to space consistency");
0N/A
0N/A // Check whether from space is below to space
0N/A if (from_start < to_start) {
0N/A // Eden, from, to
0N/A guarantee(eden_end <= from_start, "eden/from boundary");
0N/A guarantee(from_end <= to_start, "from/to boundary");
0N/A guarantee(to_end <= virtual_space()->high(), "to end");
0N/A } else {
0N/A // Eden, to, from
0N/A guarantee(eden_end <= to_start, "eden/to boundary");
0N/A guarantee(to_end <= from_start, "to/from boundary");
0N/A guarantee(from_end <= virtual_space()->high(), "from end");
0N/A }
0N/A
0N/A // More checks that the virtual space is consistent with the spaces
0N/A assert(virtual_space()->committed_size() >=
0N/A (eden()->capacity() +
0N/A to()->capacity() +
0N/A from()->capacity()), "Committed size is inconsistent");
0N/A assert(virtual_space()->committed_size() <= virtual_space()->reserved_size(),
0N/A "Space invariant");
0N/A char* eden_top = (char*)eden()->top();
0N/A char* from_top = (char*)from()->top();
0N/A char* to_top = (char*)to()->top();
0N/A assert(eden_top <= virtual_space()->high(), "eden top");
0N/A assert(from_top <= virtual_space()->high(), "from top");
0N/A assert(to_top <= virtual_space()->high(), "to top");
0N/A}
0N/A#endif