1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/gc_implementation/parallelScavenge/asPSOldGen.cpp Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,135 @@ 1.4 +/* 1.5 + * Copyright 2003-2006 Sun Microsystems, Inc. All Rights Reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.24 + * have any questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +# include "incls/_precompiled.incl" 1.29 +# include "incls/_asPSOldGen.cpp.incl" 1.30 + 1.31 +// Whereas PSOldGen takes the maximum size of the generation 1.32 +// (which doesn't change in the case of PSOldGen) as a parameter, 1.33 +// ASPSOldGen takes the upper limit on the size of 1.34 +// the generation as a parameter. In ASPSOldGen the 1.35 +// maximum size of the generation can change as the boundary 1.36 +// moves. The "maximum size of the generation" is still a valid 1.37 +// concept since the generation can grow and shrink within that 1.38 +// maximum. There are lots of useful checks that use that 1.39 +// maximum. In PSOldGen the method max_gen_size() returns 1.40 +// _max_gen_size (as set by the PSOldGen constructor). This 1.41 +// is how it always worked. In ASPSOldGen max_gen_size() 1.42 +// returned the size of the reserved space for the generation. 1.43 +// That can change as the boundary moves. Below the limit of 1.44 +// the size of the generation is passed to the PSOldGen constructor 1.45 +// for "_max_gen_size" (have to pass something) but it is not used later. 1.46 +// 1.47 +ASPSOldGen::ASPSOldGen(size_t initial_size, 1.48 + size_t min_size, 1.49 + size_t size_limit, 1.50 + const char* gen_name, 1.51 + int level) : 1.52 + PSOldGen(initial_size, min_size, size_limit, gen_name, level), 1.53 + _gen_size_limit(size_limit) 1.54 + 1.55 +{} 1.56 + 1.57 +ASPSOldGen::ASPSOldGen(PSVirtualSpace* vs, 1.58 + size_t initial_size, 1.59 + size_t min_size, 1.60 + size_t size_limit, 1.61 + const char* gen_name, 1.62 + int level) : 1.63 + PSOldGen(initial_size, min_size, size_limit, gen_name, level), 1.64 + _gen_size_limit(size_limit) 1.65 + 1.66 +{ 1.67 + _virtual_space = vs; 1.68 +} 1.69 + 1.70 +void ASPSOldGen::reset_after_change() { 1.71 + _reserved = MemRegion((HeapWord*)virtual_space()->low_boundary(), 1.72 + (HeapWord*)virtual_space()->high_boundary()); 1.73 + post_resize(); 1.74 +} 1.75 + 1.76 + 1.77 +size_t ASPSOldGen::available_for_expansion() { 1.78 + assert(virtual_space()->is_aligned(gen_size_limit()), "not aligned"); 1.79 + assert(gen_size_limit() >= virtual_space()->committed_size(), "bad gen size"); 1.80 + 1.81 + ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap(); 1.82 + size_t result = gen_size_limit() - virtual_space()->committed_size(); 1.83 + size_t result_aligned = align_size_down(result, heap->old_gen_alignment()); 1.84 + return result_aligned; 1.85 +} 1.86 + 1.87 +size_t ASPSOldGen::available_for_contraction() { 1.88 + size_t uncommitted_bytes = virtual_space()->uncommitted_size(); 1.89 + if (uncommitted_bytes != 0) { 1.90 + return uncommitted_bytes; 1.91 + } 1.92 + 1.93 + ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap(); 1.94 + const size_t gen_alignment = heap->old_gen_alignment(); 1.95 + PSAdaptiveSizePolicy* policy = heap->size_policy(); 1.96 + const size_t working_size = 1.97 + used_in_bytes() + (size_t) policy->avg_promoted()->padded_average(); 1.98 + const size_t working_aligned = align_size_up(working_size, gen_alignment); 1.99 + const size_t working_or_min = MAX2(working_aligned, min_gen_size()); 1.100 + if (working_or_min > reserved().byte_size()) { 1.101 + // If the used or minimum gen size (aligned up) is greater 1.102 + // than the total reserved size, then the space available 1.103 + // for contraction should (after proper alignment) be 0 1.104 + return 0; 1.105 + } 1.106 + const size_t max_contraction = 1.107 + reserved().byte_size() - working_or_min; 1.108 + 1.109 + // Use the "increment" fraction instead of the "decrement" fraction 1.110 + // to allow the other gen to expand more aggressively. The 1.111 + // "decrement" fraction is conservative because its intent is to 1.112 + // only reduce the footprint. 1.113 + 1.114 + size_t result = policy->promo_increment_aligned_down(max_contraction); 1.115 + // Also adjust for inter-generational alignment 1.116 + size_t result_aligned = align_size_down(result, gen_alignment); 1.117 + if (PrintAdaptiveSizePolicy && Verbose) { 1.118 + gclog_or_tty->print_cr("\nASPSOldGen::available_for_contraction:" 1.119 + " %d K / 0x%x", result_aligned/K, result_aligned); 1.120 + gclog_or_tty->print_cr(" reserved().byte_size() %d K / 0x%x ", 1.121 + reserved().byte_size()/K, reserved().byte_size()); 1.122 + size_t working_promoted = (size_t) policy->avg_promoted()->padded_average(); 1.123 + gclog_or_tty->print_cr(" padded promoted %d K / 0x%x", 1.124 + working_promoted/K, working_promoted); 1.125 + gclog_or_tty->print_cr(" used %d K / 0x%x", 1.126 + used_in_bytes()/K, used_in_bytes()); 1.127 + gclog_or_tty->print_cr(" min_gen_size() %d K / 0x%x", 1.128 + min_gen_size()/K, min_gen_size()); 1.129 + gclog_or_tty->print_cr(" max_contraction %d K / 0x%x", 1.130 + max_contraction/K, max_contraction); 1.131 + gclog_or_tty->print_cr(" without alignment %d K / 0x%x", 1.132 + policy->promo_increment(max_contraction)/K, 1.133 + policy->promo_increment(max_contraction)); 1.134 + gclog_or_tty->print_cr(" alignment 0x%x", gen_alignment); 1.135 + } 1.136 + assert(result_aligned <= max_contraction, "arithmetic is wrong"); 1.137 + return result_aligned; 1.138 +}