0N/A/*
1879N/A * Copyright (c) 2003, 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/parallelScavenge/asPSOldGen.hpp"
1879N/A#include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp"
1879N/A#include "gc_implementation/parallelScavenge/psAdaptiveSizePolicy.hpp"
1879N/A#include "gc_implementation/parallelScavenge/psMarkSweepDecorator.hpp"
1879N/A#include "memory/cardTableModRefBS.hpp"
1879N/A#include "oops/oop.inline.hpp"
1879N/A#include "runtime/java.hpp"
0N/A
0N/A// Whereas PSOldGen takes the maximum size of the generation
0N/A// (which doesn't change in the case of PSOldGen) as a parameter,
0N/A// ASPSOldGen takes the upper limit on the size of
0N/A// the generation as a parameter. In ASPSOldGen the
0N/A// maximum size of the generation can change as the boundary
0N/A// moves. The "maximum size of the generation" is still a valid
0N/A// concept since the generation can grow and shrink within that
0N/A// maximum. There are lots of useful checks that use that
0N/A// maximum. In PSOldGen the method max_gen_size() returns
0N/A// _max_gen_size (as set by the PSOldGen constructor). This
0N/A// is how it always worked. In ASPSOldGen max_gen_size()
0N/A// returned the size of the reserved space for the generation.
0N/A// That can change as the boundary moves. Below the limit of
0N/A// the size of the generation is passed to the PSOldGen constructor
0N/A// for "_max_gen_size" (have to pass something) but it is not used later.
0N/A//
0N/AASPSOldGen::ASPSOldGen(size_t initial_size,
0N/A size_t min_size,
0N/A size_t size_limit,
0N/A const char* gen_name,
0N/A int level) :
0N/A PSOldGen(initial_size, min_size, size_limit, gen_name, level),
0N/A _gen_size_limit(size_limit)
0N/A
0N/A{}
0N/A
0N/AASPSOldGen::ASPSOldGen(PSVirtualSpace* vs,
0N/A size_t initial_size,
0N/A size_t min_size,
0N/A size_t size_limit,
0N/A const char* gen_name,
0N/A int level) :
0N/A PSOldGen(initial_size, min_size, size_limit, gen_name, level),
0N/A _gen_size_limit(size_limit)
0N/A
0N/A{
0N/A _virtual_space = vs;
0N/A}
0N/A
0N/Avoid ASPSOldGen::reset_after_change() {
0N/A _reserved = MemRegion((HeapWord*)virtual_space()->low_boundary(),
0N/A (HeapWord*)virtual_space()->high_boundary());
0N/A post_resize();
0N/A}
0N/A
0N/A
0N/Asize_t ASPSOldGen::available_for_expansion() {
0N/A assert(virtual_space()->is_aligned(gen_size_limit()), "not aligned");
0N/A assert(gen_size_limit() >= virtual_space()->committed_size(), "bad gen size");
0N/A
0N/A ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
0N/A size_t result = gen_size_limit() - virtual_space()->committed_size();
0N/A size_t result_aligned = align_size_down(result, heap->old_gen_alignment());
0N/A return result_aligned;
0N/A}
0N/A
0N/Asize_t ASPSOldGen::available_for_contraction() {
0N/A size_t uncommitted_bytes = virtual_space()->uncommitted_size();
0N/A if (uncommitted_bytes != 0) {
0N/A return uncommitted_bytes;
0N/A }
0N/A
0N/A ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
0N/A const size_t gen_alignment = heap->old_gen_alignment();
0N/A PSAdaptiveSizePolicy* policy = heap->size_policy();
0N/A const size_t working_size =
0N/A used_in_bytes() + (size_t) policy->avg_promoted()->padded_average();
0N/A const size_t working_aligned = align_size_up(working_size, gen_alignment);
0N/A const size_t working_or_min = MAX2(working_aligned, min_gen_size());
0N/A if (working_or_min > reserved().byte_size()) {
0N/A // If the used or minimum gen size (aligned up) is greater
0N/A // than the total reserved size, then the space available
0N/A // for contraction should (after proper alignment) be 0
0N/A return 0;
0N/A }
0N/A const size_t max_contraction =
0N/A reserved().byte_size() - working_or_min;
0N/A
0N/A // Use the "increment" fraction instead of the "decrement" fraction
0N/A // to allow the other gen to expand more aggressively. The
0N/A // "decrement" fraction is conservative because its intent is to
0N/A // only reduce the footprint.
0N/A
0N/A size_t result = policy->promo_increment_aligned_down(max_contraction);
0N/A // Also adjust for inter-generational alignment
0N/A size_t result_aligned = align_size_down(result, gen_alignment);
0N/A if (PrintAdaptiveSizePolicy && Verbose) {
0N/A gclog_or_tty->print_cr("\nASPSOldGen::available_for_contraction:"
0N/A " %d K / 0x%x", result_aligned/K, result_aligned);
0N/A gclog_or_tty->print_cr(" reserved().byte_size() %d K / 0x%x ",
0N/A reserved().byte_size()/K, reserved().byte_size());
0N/A size_t working_promoted = (size_t) policy->avg_promoted()->padded_average();
0N/A gclog_or_tty->print_cr(" padded promoted %d K / 0x%x",
0N/A working_promoted/K, working_promoted);
0N/A gclog_or_tty->print_cr(" used %d K / 0x%x",
0N/A used_in_bytes()/K, used_in_bytes());
0N/A gclog_or_tty->print_cr(" min_gen_size() %d K / 0x%x",
0N/A min_gen_size()/K, min_gen_size());
0N/A gclog_or_tty->print_cr(" max_contraction %d K / 0x%x",
0N/A max_contraction/K, max_contraction);
0N/A gclog_or_tty->print_cr(" without alignment %d K / 0x%x",
0N/A policy->promo_increment(max_contraction)/K,
0N/A policy->promo_increment(max_contraction));
0N/A gclog_or_tty->print_cr(" alignment 0x%x", gen_alignment);
0N/A }
0N/A assert(result_aligned <= max_contraction, "arithmetic is wrong");
0N/A return result_aligned;
0N/A}