Wed, 27 Apr 2016 01:25:04 +0800
Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. |
aoqi@0 | 8 | * |
aoqi@0 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 13 | * accompanied this code). |
aoqi@0 | 14 | * |
aoqi@0 | 15 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 18 | * |
aoqi@0 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 20 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 21 | * questions. |
aoqi@0 | 22 | * |
aoqi@0 | 23 | */ |
aoqi@0 | 24 | |
aoqi@0 | 25 | #include "precompiled.hpp" |
aoqi@0 | 26 | #include "gc_implementation/parallelScavenge/adjoiningGenerations.hpp" |
aoqi@0 | 27 | #include "gc_implementation/parallelScavenge/adjoiningVirtualSpaces.hpp" |
aoqi@0 | 28 | #include "gc_implementation/parallelScavenge/generationSizer.hpp" |
aoqi@0 | 29 | #include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp" |
aoqi@0 | 30 | |
aoqi@0 | 31 | // If boundary moving is being used, create the young gen and old |
aoqi@0 | 32 | // gen with ASPSYoungGen and ASPSOldGen, respectively. Revert to |
aoqi@0 | 33 | // the old behavior otherwise (with PSYoungGen and PSOldGen). |
aoqi@0 | 34 | |
aoqi@0 | 35 | AdjoiningGenerations::AdjoiningGenerations(ReservedSpace old_young_rs, |
aoqi@0 | 36 | GenerationSizer* policy, |
aoqi@0 | 37 | size_t alignment) : |
aoqi@0 | 38 | _virtual_spaces(old_young_rs, policy->min_gen1_size(), |
aoqi@0 | 39 | policy->min_gen0_size(), alignment) { |
aoqi@0 | 40 | size_t init_low_byte_size = policy->initial_gen1_size(); |
aoqi@0 | 41 | size_t min_low_byte_size = policy->min_gen1_size(); |
aoqi@0 | 42 | size_t max_low_byte_size = policy->max_gen1_size(); |
aoqi@0 | 43 | size_t init_high_byte_size = policy->initial_gen0_size(); |
aoqi@0 | 44 | size_t min_high_byte_size = policy->min_gen0_size(); |
aoqi@0 | 45 | size_t max_high_byte_size = policy->max_gen0_size(); |
aoqi@0 | 46 | |
aoqi@0 | 47 | assert(min_low_byte_size <= init_low_byte_size && |
aoqi@0 | 48 | init_low_byte_size <= max_low_byte_size, "Parameter check"); |
aoqi@0 | 49 | assert(min_high_byte_size <= init_high_byte_size && |
aoqi@0 | 50 | init_high_byte_size <= max_high_byte_size, "Parameter check"); |
aoqi@0 | 51 | // Create the generations differently based on the option to |
aoqi@0 | 52 | // move the boundary. |
aoqi@0 | 53 | if (UseAdaptiveGCBoundary) { |
aoqi@0 | 54 | // Initialize the adjoining virtual spaces. Then pass the |
aoqi@0 | 55 | // a virtual to each generation for initialization of the |
aoqi@0 | 56 | // generation. |
aoqi@0 | 57 | |
aoqi@0 | 58 | // Does the actual creation of the virtual spaces |
aoqi@0 | 59 | _virtual_spaces.initialize(max_low_byte_size, |
aoqi@0 | 60 | init_low_byte_size, |
aoqi@0 | 61 | init_high_byte_size); |
aoqi@0 | 62 | |
aoqi@0 | 63 | // Place the young gen at the high end. Passes in the virtual space. |
aoqi@0 | 64 | _young_gen = new ASPSYoungGen(_virtual_spaces.high(), |
aoqi@0 | 65 | _virtual_spaces.high()->committed_size(), |
aoqi@0 | 66 | min_high_byte_size, |
aoqi@0 | 67 | _virtual_spaces.high_byte_size_limit()); |
aoqi@0 | 68 | |
aoqi@0 | 69 | // Place the old gen at the low end. Passes in the virtual space. |
aoqi@0 | 70 | _old_gen = new ASPSOldGen(_virtual_spaces.low(), |
aoqi@0 | 71 | _virtual_spaces.low()->committed_size(), |
aoqi@0 | 72 | min_low_byte_size, |
aoqi@0 | 73 | _virtual_spaces.low_byte_size_limit(), |
aoqi@0 | 74 | "old", 1); |
aoqi@0 | 75 | |
aoqi@0 | 76 | young_gen()->initialize_work(); |
aoqi@0 | 77 | assert(young_gen()->reserved().byte_size() <= young_gen()->gen_size_limit(), |
aoqi@0 | 78 | "Consistency check"); |
aoqi@0 | 79 | assert(old_young_rs.size() >= young_gen()->gen_size_limit(), |
aoqi@0 | 80 | "Consistency check"); |
aoqi@0 | 81 | |
aoqi@0 | 82 | old_gen()->initialize_work("old", 1); |
aoqi@0 | 83 | assert(old_gen()->reserved().byte_size() <= old_gen()->gen_size_limit(), |
aoqi@0 | 84 | "Consistency check"); |
aoqi@0 | 85 | assert(old_young_rs.size() >= old_gen()->gen_size_limit(), |
aoqi@0 | 86 | "Consistency check"); |
aoqi@0 | 87 | } else { |
aoqi@0 | 88 | |
aoqi@0 | 89 | // Layout the reserved space for the generations. |
aoqi@0 | 90 | ReservedSpace old_rs = |
aoqi@0 | 91 | virtual_spaces()->reserved_space().first_part(max_low_byte_size); |
aoqi@0 | 92 | ReservedSpace heap_rs = |
aoqi@0 | 93 | virtual_spaces()->reserved_space().last_part(max_low_byte_size); |
aoqi@0 | 94 | ReservedSpace young_rs = heap_rs.first_part(max_high_byte_size); |
aoqi@0 | 95 | assert(young_rs.size() == heap_rs.size(), "Didn't reserve all of the heap"); |
aoqi@0 | 96 | |
aoqi@0 | 97 | // Create the generations. Virtual spaces are not passed in. |
aoqi@0 | 98 | _young_gen = new PSYoungGen(init_high_byte_size, |
aoqi@0 | 99 | min_high_byte_size, |
aoqi@0 | 100 | max_high_byte_size); |
aoqi@0 | 101 | _old_gen = new PSOldGen(init_low_byte_size, |
aoqi@0 | 102 | min_low_byte_size, |
aoqi@0 | 103 | max_low_byte_size, |
aoqi@0 | 104 | "old", 1); |
aoqi@0 | 105 | |
aoqi@0 | 106 | // The virtual spaces are created by the initialization of the gens. |
aoqi@0 | 107 | _young_gen->initialize(young_rs, alignment); |
aoqi@0 | 108 | assert(young_gen()->gen_size_limit() == young_rs.size(), |
aoqi@0 | 109 | "Consistency check"); |
aoqi@0 | 110 | _old_gen->initialize(old_rs, alignment, "old", 1); |
aoqi@0 | 111 | assert(old_gen()->gen_size_limit() == old_rs.size(), "Consistency check"); |
aoqi@0 | 112 | } |
aoqi@0 | 113 | } |
aoqi@0 | 114 | |
aoqi@0 | 115 | size_t AdjoiningGenerations::reserved_byte_size() { |
aoqi@0 | 116 | return virtual_spaces()->reserved_space().size(); |
aoqi@0 | 117 | } |
aoqi@0 | 118 | |
aoqi@0 | 119 | |
aoqi@0 | 120 | // Make checks on the current sizes of the generations and |
aoqi@0 | 121 | // the contraints on the sizes of the generations. Push |
aoqi@0 | 122 | // up the boundary within the contraints. A partial |
aoqi@0 | 123 | // push can occur. |
aoqi@0 | 124 | void AdjoiningGenerations::request_old_gen_expansion(size_t expand_in_bytes) { |
aoqi@0 | 125 | assert(UseAdaptiveSizePolicy && UseAdaptiveGCBoundary, "runtime check"); |
aoqi@0 | 126 | |
aoqi@0 | 127 | assert_lock_strong(ExpandHeap_lock); |
aoqi@0 | 128 | assert_locked_or_safepoint(Heap_lock); |
aoqi@0 | 129 | |
aoqi@0 | 130 | // These sizes limit the amount the boundaries can move. Effectively, |
aoqi@0 | 131 | // the generation says how much it is willing to yield to the other |
aoqi@0 | 132 | // generation. |
aoqi@0 | 133 | const size_t young_gen_available = young_gen()->available_for_contraction(); |
aoqi@0 | 134 | const size_t old_gen_available = old_gen()->available_for_expansion(); |
aoqi@0 | 135 | const size_t alignment = virtual_spaces()->alignment(); |
aoqi@0 | 136 | size_t change_in_bytes = MIN3(young_gen_available, |
aoqi@0 | 137 | old_gen_available, |
aoqi@0 | 138 | align_size_up_(expand_in_bytes, alignment)); |
aoqi@0 | 139 | |
aoqi@0 | 140 | if (change_in_bytes == 0) { |
aoqi@0 | 141 | return; |
aoqi@0 | 142 | } |
aoqi@0 | 143 | |
aoqi@0 | 144 | if (TraceAdaptiveGCBoundary) { |
aoqi@0 | 145 | gclog_or_tty->print_cr("Before expansion of old gen with boundary move"); |
aoqi@0 | 146 | gclog_or_tty->print_cr(" Requested change: " SIZE_FORMAT_HEX " Attempted change: " SIZE_FORMAT_HEX, |
aoqi@0 | 147 | expand_in_bytes, change_in_bytes); |
aoqi@0 | 148 | if (!PrintHeapAtGC) { |
aoqi@0 | 149 | Universe::print_on(gclog_or_tty); |
aoqi@0 | 150 | } |
aoqi@0 | 151 | gclog_or_tty->print_cr(" PSOldGen max size: " SIZE_FORMAT "K", |
aoqi@0 | 152 | old_gen()->max_gen_size()/K); |
aoqi@0 | 153 | } |
aoqi@0 | 154 | |
aoqi@0 | 155 | // Move the boundary between the generations up (smaller young gen). |
aoqi@0 | 156 | if (virtual_spaces()->adjust_boundary_up(change_in_bytes)) { |
aoqi@0 | 157 | young_gen()->reset_after_change(); |
aoqi@0 | 158 | old_gen()->reset_after_change(); |
aoqi@0 | 159 | } |
aoqi@0 | 160 | |
aoqi@0 | 161 | // The total reserved for the generations should match the sum |
aoqi@0 | 162 | // of the two even if the boundary is moving. |
aoqi@0 | 163 | assert(reserved_byte_size() == |
aoqi@0 | 164 | old_gen()->max_gen_size() + young_gen()->max_size(), |
aoqi@0 | 165 | "Space is missing"); |
aoqi@0 | 166 | young_gen()->space_invariants(); |
aoqi@0 | 167 | old_gen()->space_invariants(); |
aoqi@0 | 168 | |
aoqi@0 | 169 | if (TraceAdaptiveGCBoundary) { |
aoqi@0 | 170 | gclog_or_tty->print_cr("After expansion of old gen with boundary move"); |
aoqi@0 | 171 | if (!PrintHeapAtGC) { |
aoqi@0 | 172 | Universe::print_on(gclog_or_tty); |
aoqi@0 | 173 | } |
aoqi@0 | 174 | gclog_or_tty->print_cr(" PSOldGen max size: " SIZE_FORMAT "K", |
aoqi@0 | 175 | old_gen()->max_gen_size()/K); |
aoqi@0 | 176 | } |
aoqi@0 | 177 | } |
aoqi@0 | 178 | |
aoqi@0 | 179 | // See comments on request_old_gen_expansion() |
aoqi@0 | 180 | bool AdjoiningGenerations::request_young_gen_expansion(size_t expand_in_bytes) { |
aoqi@0 | 181 | assert(UseAdaptiveSizePolicy && UseAdaptiveGCBoundary, "runtime check"); |
aoqi@0 | 182 | |
aoqi@0 | 183 | // If eden is not empty, the boundary can be moved but no advantage |
aoqi@0 | 184 | // can be made of the move since eden cannot be moved. |
aoqi@0 | 185 | if (!young_gen()->eden_space()->is_empty()) { |
aoqi@0 | 186 | return false; |
aoqi@0 | 187 | } |
aoqi@0 | 188 | |
aoqi@0 | 189 | |
aoqi@0 | 190 | bool result = false; |
aoqi@0 | 191 | const size_t young_gen_available = young_gen()->available_for_expansion(); |
aoqi@0 | 192 | const size_t old_gen_available = old_gen()->available_for_contraction(); |
aoqi@0 | 193 | const size_t alignment = virtual_spaces()->alignment(); |
aoqi@0 | 194 | size_t change_in_bytes = MIN3(young_gen_available, |
aoqi@0 | 195 | old_gen_available, |
aoqi@0 | 196 | align_size_up_(expand_in_bytes, alignment)); |
aoqi@0 | 197 | |
aoqi@0 | 198 | if (change_in_bytes == 0) { |
aoqi@0 | 199 | return false; |
aoqi@0 | 200 | } |
aoqi@0 | 201 | |
aoqi@0 | 202 | if (TraceAdaptiveGCBoundary) { |
aoqi@0 | 203 | gclog_or_tty->print_cr("Before expansion of young gen with boundary move"); |
aoqi@0 | 204 | gclog_or_tty->print_cr(" Requested change: " SIZE_FORMAT_HEX " Attempted change: " SIZE_FORMAT_HEX, |
aoqi@0 | 205 | expand_in_bytes, change_in_bytes); |
aoqi@0 | 206 | if (!PrintHeapAtGC) { |
aoqi@0 | 207 | Universe::print_on(gclog_or_tty); |
aoqi@0 | 208 | } |
aoqi@0 | 209 | gclog_or_tty->print_cr(" PSYoungGen max size: " SIZE_FORMAT "K", |
aoqi@0 | 210 | young_gen()->max_size()/K); |
aoqi@0 | 211 | } |
aoqi@0 | 212 | |
aoqi@0 | 213 | // Move the boundary between the generations down (smaller old gen). |
aoqi@0 | 214 | MutexLocker x(ExpandHeap_lock); |
aoqi@0 | 215 | if (virtual_spaces()->adjust_boundary_down(change_in_bytes)) { |
aoqi@0 | 216 | young_gen()->reset_after_change(); |
aoqi@0 | 217 | old_gen()->reset_after_change(); |
aoqi@0 | 218 | result = true; |
aoqi@0 | 219 | } |
aoqi@0 | 220 | |
aoqi@0 | 221 | // The total reserved for the generations should match the sum |
aoqi@0 | 222 | // of the two even if the boundary is moving. |
aoqi@0 | 223 | assert(reserved_byte_size() == |
aoqi@0 | 224 | old_gen()->max_gen_size() + young_gen()->max_size(), |
aoqi@0 | 225 | "Space is missing"); |
aoqi@0 | 226 | young_gen()->space_invariants(); |
aoqi@0 | 227 | old_gen()->space_invariants(); |
aoqi@0 | 228 | |
aoqi@0 | 229 | if (TraceAdaptiveGCBoundary) { |
aoqi@0 | 230 | gclog_or_tty->print_cr("After expansion of young gen with boundary move"); |
aoqi@0 | 231 | if (!PrintHeapAtGC) { |
aoqi@0 | 232 | Universe::print_on(gclog_or_tty); |
aoqi@0 | 233 | } |
aoqi@0 | 234 | gclog_or_tty->print_cr(" PSYoungGen max size: " SIZE_FORMAT "K", |
aoqi@0 | 235 | young_gen()->max_size()/K); |
aoqi@0 | 236 | } |
aoqi@0 | 237 | |
aoqi@0 | 238 | return result; |
aoqi@0 | 239 | } |
aoqi@0 | 240 | |
aoqi@0 | 241 | // Additional space is needed in the old generation. Try to move the boundary |
aoqi@0 | 242 | // up to meet the need. Moves boundary up only |
aoqi@0 | 243 | void AdjoiningGenerations::adjust_boundary_for_old_gen_needs( |
aoqi@0 | 244 | size_t desired_free_space) { |
aoqi@0 | 245 | assert(UseAdaptiveSizePolicy && UseAdaptiveGCBoundary, "runtime check"); |
aoqi@0 | 246 | |
aoqi@0 | 247 | // Stress testing. |
aoqi@0 | 248 | if (PSAdaptiveSizePolicyResizeVirtualSpaceAlot == 1) { |
aoqi@0 | 249 | MutexLocker x(ExpandHeap_lock); |
aoqi@0 | 250 | request_old_gen_expansion(virtual_spaces()->alignment() * 3 / 2); |
aoqi@0 | 251 | } |
aoqi@0 | 252 | |
aoqi@0 | 253 | // Expand only if the entire generation is already committed. |
aoqi@0 | 254 | if (old_gen()->virtual_space()->uncommitted_size() == 0) { |
aoqi@0 | 255 | if (old_gen()->free_in_bytes() < desired_free_space) { |
aoqi@0 | 256 | MutexLocker x(ExpandHeap_lock); |
aoqi@0 | 257 | request_old_gen_expansion(desired_free_space); |
aoqi@0 | 258 | } |
aoqi@0 | 259 | } |
aoqi@0 | 260 | } |
aoqi@0 | 261 | |
aoqi@0 | 262 | // See comment on adjust_boundary_for_old_gen_needss(). |
aoqi@0 | 263 | // Adjust boundary down only. |
aoqi@0 | 264 | void AdjoiningGenerations::adjust_boundary_for_young_gen_needs(size_t eden_size, |
aoqi@0 | 265 | size_t survivor_size) { |
aoqi@0 | 266 | |
aoqi@0 | 267 | assert(UseAdaptiveSizePolicy && UseAdaptiveGCBoundary, "runtime check"); |
aoqi@0 | 268 | |
aoqi@0 | 269 | // Stress testing. |
aoqi@0 | 270 | if (PSAdaptiveSizePolicyResizeVirtualSpaceAlot == 0) { |
aoqi@0 | 271 | request_young_gen_expansion(virtual_spaces()->alignment() * 3 / 2); |
aoqi@0 | 272 | eden_size = young_gen()->eden_space()->capacity_in_bytes(); |
aoqi@0 | 273 | } |
aoqi@0 | 274 | |
aoqi@0 | 275 | // Expand only if the entire generation is already committed. |
aoqi@0 | 276 | if (young_gen()->virtual_space()->uncommitted_size() == 0) { |
aoqi@0 | 277 | size_t desired_size = eden_size + 2 * survivor_size; |
aoqi@0 | 278 | const size_t committed = young_gen()->virtual_space()->committed_size(); |
aoqi@0 | 279 | if (desired_size > committed) { |
aoqi@0 | 280 | request_young_gen_expansion(desired_size - committed); |
aoqi@0 | 281 | } |
aoqi@0 | 282 | } |
aoqi@0 | 283 | } |