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