1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/gc_implementation/parallelScavenge/asPSOldGen.cpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,149 @@ 1.4 +/* 1.5 + * Copyright (c) 2003, 2014, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#include "precompiled.hpp" 1.29 +#include "gc_implementation/parallelScavenge/asPSOldGen.hpp" 1.30 +#include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp" 1.31 +#include "gc_implementation/parallelScavenge/psAdaptiveSizePolicy.hpp" 1.32 +#include "gc_implementation/parallelScavenge/psMarkSweepDecorator.hpp" 1.33 +#include "memory/cardTableModRefBS.hpp" 1.34 +#include "oops/oop.inline.hpp" 1.35 +#include "runtime/java.hpp" 1.36 + 1.37 +// Whereas PSOldGen takes the maximum size of the generation 1.38 +// (which doesn't change in the case of PSOldGen) as a parameter, 1.39 +// ASPSOldGen takes the upper limit on the size of 1.40 +// the generation as a parameter. In ASPSOldGen the 1.41 +// maximum size of the generation can change as the boundary 1.42 +// moves. The "maximum size of the generation" is still a valid 1.43 +// concept since the generation can grow and shrink within that 1.44 +// maximum. There are lots of useful checks that use that 1.45 +// maximum. In PSOldGen the method max_gen_size() returns 1.46 +// _max_gen_size (as set by the PSOldGen constructor). This 1.47 +// is how it always worked. In ASPSOldGen max_gen_size() 1.48 +// returned the size of the reserved space for the generation. 1.49 +// That can change as the boundary moves. Below the limit of 1.50 +// the size of the generation is passed to the PSOldGen constructor 1.51 +// for "_max_gen_size" (have to pass something) but it is not used later. 1.52 +// 1.53 +ASPSOldGen::ASPSOldGen(size_t initial_size, 1.54 + size_t min_size, 1.55 + size_t size_limit, 1.56 + const char* gen_name, 1.57 + int level) : 1.58 + PSOldGen(initial_size, min_size, size_limit, gen_name, level), 1.59 + _gen_size_limit(size_limit) 1.60 +{} 1.61 + 1.62 +ASPSOldGen::ASPSOldGen(PSVirtualSpace* vs, 1.63 + size_t initial_size, 1.64 + size_t min_size, 1.65 + size_t size_limit, 1.66 + const char* gen_name, 1.67 + int level) : 1.68 + PSOldGen(initial_size, min_size, size_limit, gen_name, level), 1.69 + _gen_size_limit(size_limit) 1.70 +{ 1.71 + _virtual_space = vs; 1.72 +} 1.73 + 1.74 +void ASPSOldGen::initialize_work(const char* perf_data_name, int level) { 1.75 + PSOldGen::initialize_work(perf_data_name, level); 1.76 + 1.77 + // The old gen can grow to gen_size_limit(). _reserve reflects only 1.78 + // the current maximum that can be committed. 1.79 + assert(_reserved.byte_size() <= gen_size_limit(), "Consistency check"); 1.80 + 1.81 + initialize_performance_counters(perf_data_name, level); 1.82 +} 1.83 + 1.84 +void ASPSOldGen::reset_after_change() { 1.85 + _reserved = MemRegion((HeapWord*)virtual_space()->low_boundary(), 1.86 + (HeapWord*)virtual_space()->high_boundary()); 1.87 + post_resize(); 1.88 +} 1.89 + 1.90 + 1.91 +size_t ASPSOldGen::available_for_expansion() { 1.92 + assert(virtual_space()->is_aligned(gen_size_limit()), "not aligned"); 1.93 + assert(gen_size_limit() >= virtual_space()->committed_size(), "bad gen size"); 1.94 + 1.95 + ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap(); 1.96 + size_t result = gen_size_limit() - virtual_space()->committed_size(); 1.97 + size_t result_aligned = align_size_down(result, heap->generation_alignment()); 1.98 + return result_aligned; 1.99 +} 1.100 + 1.101 +size_t ASPSOldGen::available_for_contraction() { 1.102 + size_t uncommitted_bytes = virtual_space()->uncommitted_size(); 1.103 + if (uncommitted_bytes != 0) { 1.104 + return uncommitted_bytes; 1.105 + } 1.106 + 1.107 + ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap(); 1.108 + const size_t gen_alignment = heap->generation_alignment(); 1.109 + PSAdaptiveSizePolicy* policy = heap->size_policy(); 1.110 + const size_t working_size = 1.111 + used_in_bytes() + (size_t) policy->avg_promoted()->padded_average(); 1.112 + const size_t working_aligned = align_size_up(working_size, gen_alignment); 1.113 + const size_t working_or_min = MAX2(working_aligned, min_gen_size()); 1.114 + if (working_or_min > reserved().byte_size()) { 1.115 + // If the used or minimum gen size (aligned up) is greater 1.116 + // than the total reserved size, then the space available 1.117 + // for contraction should (after proper alignment) be 0 1.118 + return 0; 1.119 + } 1.120 + const size_t max_contraction = 1.121 + reserved().byte_size() - working_or_min; 1.122 + 1.123 + // Use the "increment" fraction instead of the "decrement" fraction 1.124 + // to allow the other gen to expand more aggressively. The 1.125 + // "decrement" fraction is conservative because its intent is to 1.126 + // only reduce the footprint. 1.127 + 1.128 + size_t result = policy->promo_increment_aligned_down(max_contraction); 1.129 + // Also adjust for inter-generational alignment 1.130 + size_t result_aligned = align_size_down(result, gen_alignment); 1.131 + if (PrintAdaptiveSizePolicy && Verbose) { 1.132 + gclog_or_tty->print_cr("\nASPSOldGen::available_for_contraction:" 1.133 + " " SSIZE_FORMAT " K / " SIZE_FORMAT_HEX, (result_aligned/K), result_aligned); 1.134 + gclog_or_tty->print_cr(" reserved().byte_size() " SSIZE_FORMAT " K / " SIZE_FORMAT_HEX " ", 1.135 + (reserved().byte_size()/K), reserved().byte_size()); 1.136 + size_t working_promoted = (size_t) policy->avg_promoted()->padded_average(); 1.137 + gclog_or_tty->print_cr(" padded promoted " SSIZE_FORMAT " K / " SIZE_FORMAT_HEX, 1.138 + (working_promoted/K), working_promoted); 1.139 + gclog_or_tty->print_cr(" used " SSIZE_FORMAT " K / " SIZE_FORMAT_HEX, 1.140 + (used_in_bytes()/K), used_in_bytes()); 1.141 + gclog_or_tty->print_cr(" min_gen_size() " SSIZE_FORMAT " K / " SIZE_FORMAT_HEX, 1.142 + (min_gen_size()/K), min_gen_size()); 1.143 + gclog_or_tty->print_cr(" max_contraction " SSIZE_FORMAT " K / " SIZE_FORMAT_HEX, 1.144 + (max_contraction/K), max_contraction); 1.145 + gclog_or_tty->print_cr(" without alignment " SSIZE_FORMAT " K / " SIZE_FORMAT_HEX, 1.146 + (policy->promo_increment(max_contraction)/K), 1.147 + policy->promo_increment(max_contraction)); 1.148 + gclog_or_tty->print_cr(" alignment " SIZE_FORMAT_HEX, gen_alignment); 1.149 + } 1.150 + assert(result_aligned <= max_contraction, "arithmetic is wrong"); 1.151 + return result_aligned; 1.152 +}