src/share/vm/gc_implementation/parallelScavenge/adjoiningGenerations.cpp

changeset 0
f90c822e73f8
child 6876
710a3c8b516e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/gc_implementation/parallelScavenge/adjoiningGenerations.cpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,283 @@
     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/adjoiningGenerations.hpp"
    1.30 +#include "gc_implementation/parallelScavenge/adjoiningVirtualSpaces.hpp"
    1.31 +#include "gc_implementation/parallelScavenge/generationSizer.hpp"
    1.32 +#include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp"
    1.33 +
    1.34 +// If boundary moving is being used, create the young gen and old
    1.35 +// gen with ASPSYoungGen and ASPSOldGen, respectively.  Revert to
    1.36 +// the old behavior otherwise (with PSYoungGen and PSOldGen).
    1.37 +
    1.38 +AdjoiningGenerations::AdjoiningGenerations(ReservedSpace old_young_rs,
    1.39 +                                           GenerationSizer* policy,
    1.40 +                                           size_t alignment) :
    1.41 +  _virtual_spaces(old_young_rs, policy->min_gen1_size(),
    1.42 +                  policy->min_gen0_size(), alignment) {
    1.43 +  size_t init_low_byte_size = policy->initial_gen1_size();
    1.44 +  size_t min_low_byte_size = policy->min_gen1_size();
    1.45 +  size_t max_low_byte_size = policy->max_gen1_size();
    1.46 +  size_t init_high_byte_size = policy->initial_gen0_size();
    1.47 +  size_t min_high_byte_size = policy->min_gen0_size();
    1.48 +  size_t max_high_byte_size = policy->max_gen0_size();
    1.49 +
    1.50 +  assert(min_low_byte_size <= init_low_byte_size &&
    1.51 +         init_low_byte_size <= max_low_byte_size, "Parameter check");
    1.52 +  assert(min_high_byte_size <= init_high_byte_size &&
    1.53 +         init_high_byte_size <= max_high_byte_size, "Parameter check");
    1.54 +  // Create the generations differently based on the option to
    1.55 +  // move the boundary.
    1.56 +  if (UseAdaptiveGCBoundary) {
    1.57 +    // Initialize the adjoining virtual spaces.  Then pass the
    1.58 +    // a virtual to each generation for initialization of the
    1.59 +    // generation.
    1.60 +
    1.61 +    // Does the actual creation of the virtual spaces
    1.62 +    _virtual_spaces.initialize(max_low_byte_size,
    1.63 +                               init_low_byte_size,
    1.64 +                               init_high_byte_size);
    1.65 +
    1.66 +    // Place the young gen at the high end.  Passes in the virtual space.
    1.67 +    _young_gen = new ASPSYoungGen(_virtual_spaces.high(),
    1.68 +                                  _virtual_spaces.high()->committed_size(),
    1.69 +                                  min_high_byte_size,
    1.70 +                                  _virtual_spaces.high_byte_size_limit());
    1.71 +
    1.72 +    // Place the old gen at the low end. Passes in the virtual space.
    1.73 +    _old_gen = new ASPSOldGen(_virtual_spaces.low(),
    1.74 +                              _virtual_spaces.low()->committed_size(),
    1.75 +                              min_low_byte_size,
    1.76 +                              _virtual_spaces.low_byte_size_limit(),
    1.77 +                              "old", 1);
    1.78 +
    1.79 +    young_gen()->initialize_work();
    1.80 +    assert(young_gen()->reserved().byte_size() <= young_gen()->gen_size_limit(),
    1.81 +     "Consistency check");
    1.82 +    assert(old_young_rs.size() >= young_gen()->gen_size_limit(),
    1.83 +     "Consistency check");
    1.84 +
    1.85 +    old_gen()->initialize_work("old", 1);
    1.86 +    assert(old_gen()->reserved().byte_size() <= old_gen()->gen_size_limit(),
    1.87 +     "Consistency check");
    1.88 +    assert(old_young_rs.size() >= old_gen()->gen_size_limit(),
    1.89 +     "Consistency check");
    1.90 +  } else {
    1.91 +
    1.92 +    // Layout the reserved space for the generations.
    1.93 +    ReservedSpace old_rs   =
    1.94 +      virtual_spaces()->reserved_space().first_part(max_low_byte_size);
    1.95 +    ReservedSpace heap_rs  =
    1.96 +      virtual_spaces()->reserved_space().last_part(max_low_byte_size);
    1.97 +    ReservedSpace young_rs = heap_rs.first_part(max_high_byte_size);
    1.98 +    assert(young_rs.size() == heap_rs.size(), "Didn't reserve all of the heap");
    1.99 +
   1.100 +    // Create the generations.  Virtual spaces are not passed in.
   1.101 +    _young_gen = new PSYoungGen(init_high_byte_size,
   1.102 +                                min_high_byte_size,
   1.103 +                                max_high_byte_size);
   1.104 +    _old_gen = new PSOldGen(init_low_byte_size,
   1.105 +                            min_low_byte_size,
   1.106 +                            max_low_byte_size,
   1.107 +                            "old", 1);
   1.108 +
   1.109 +    // The virtual spaces are created by the initialization of the gens.
   1.110 +    _young_gen->initialize(young_rs, alignment);
   1.111 +    assert(young_gen()->gen_size_limit() == young_rs.size(),
   1.112 +      "Consistency check");
   1.113 +    _old_gen->initialize(old_rs, alignment, "old", 1);
   1.114 +    assert(old_gen()->gen_size_limit() == old_rs.size(), "Consistency check");
   1.115 +  }
   1.116 +}
   1.117 +
   1.118 +size_t AdjoiningGenerations::reserved_byte_size() {
   1.119 +  return virtual_spaces()->reserved_space().size();
   1.120 +}
   1.121 +
   1.122 +
   1.123 +// Make checks on the current sizes of the generations and
   1.124 +// the contraints on the sizes of the generations.  Push
   1.125 +// up the boundary within the contraints.  A partial
   1.126 +// push can occur.
   1.127 +void AdjoiningGenerations::request_old_gen_expansion(size_t expand_in_bytes) {
   1.128 +  assert(UseAdaptiveSizePolicy && UseAdaptiveGCBoundary, "runtime check");
   1.129 +
   1.130 +  assert_lock_strong(ExpandHeap_lock);
   1.131 +  assert_locked_or_safepoint(Heap_lock);
   1.132 +
   1.133 +  // These sizes limit the amount the boundaries can move.  Effectively,
   1.134 +  // the generation says how much it is willing to yield to the other
   1.135 +  // generation.
   1.136 +  const size_t young_gen_available = young_gen()->available_for_contraction();
   1.137 +  const size_t old_gen_available = old_gen()->available_for_expansion();
   1.138 +  const size_t alignment = virtual_spaces()->alignment();
   1.139 +  size_t change_in_bytes = MIN3(young_gen_available,
   1.140 +                                old_gen_available,
   1.141 +                                align_size_up_(expand_in_bytes, alignment));
   1.142 +
   1.143 +  if (change_in_bytes == 0) {
   1.144 +    return;
   1.145 +  }
   1.146 +
   1.147 +  if (TraceAdaptiveGCBoundary) {
   1.148 +    gclog_or_tty->print_cr("Before expansion of old gen with boundary move");
   1.149 +    gclog_or_tty->print_cr("  Requested change: " SIZE_FORMAT_HEX "  Attempted change: " SIZE_FORMAT_HEX,
   1.150 +      expand_in_bytes, change_in_bytes);
   1.151 +    if (!PrintHeapAtGC) {
   1.152 +      Universe::print_on(gclog_or_tty);
   1.153 +    }
   1.154 +    gclog_or_tty->print_cr("  PSOldGen max size: " SIZE_FORMAT "K",
   1.155 +      old_gen()->max_gen_size()/K);
   1.156 +  }
   1.157 +
   1.158 +  // Move the boundary between the generations up (smaller young gen).
   1.159 +  if (virtual_spaces()->adjust_boundary_up(change_in_bytes)) {
   1.160 +    young_gen()->reset_after_change();
   1.161 +    old_gen()->reset_after_change();
   1.162 +  }
   1.163 +
   1.164 +  // The total reserved for the generations should match the sum
   1.165 +  // of the two even if the boundary is moving.
   1.166 +  assert(reserved_byte_size() ==
   1.167 +         old_gen()->max_gen_size() + young_gen()->max_size(),
   1.168 +         "Space is missing");
   1.169 +  young_gen()->space_invariants();
   1.170 +  old_gen()->space_invariants();
   1.171 +
   1.172 +  if (TraceAdaptiveGCBoundary) {
   1.173 +    gclog_or_tty->print_cr("After expansion of old gen with boundary move");
   1.174 +    if (!PrintHeapAtGC) {
   1.175 +      Universe::print_on(gclog_or_tty);
   1.176 +    }
   1.177 +    gclog_or_tty->print_cr("  PSOldGen max size: " SIZE_FORMAT "K",
   1.178 +      old_gen()->max_gen_size()/K);
   1.179 +  }
   1.180 +}
   1.181 +
   1.182 +// See comments on request_old_gen_expansion()
   1.183 +bool AdjoiningGenerations::request_young_gen_expansion(size_t expand_in_bytes) {
   1.184 +  assert(UseAdaptiveSizePolicy && UseAdaptiveGCBoundary, "runtime check");
   1.185 +
   1.186 +  // If eden is not empty, the boundary can be moved but no advantage
   1.187 +  // can be made of the move since eden cannot be moved.
   1.188 +  if (!young_gen()->eden_space()->is_empty()) {
   1.189 +    return false;
   1.190 +  }
   1.191 +
   1.192 +
   1.193 +  bool result = false;
   1.194 +  const size_t young_gen_available = young_gen()->available_for_expansion();
   1.195 +  const size_t old_gen_available = old_gen()->available_for_contraction();
   1.196 +  const size_t alignment = virtual_spaces()->alignment();
   1.197 +  size_t change_in_bytes = MIN3(young_gen_available,
   1.198 +                                old_gen_available,
   1.199 +                                align_size_up_(expand_in_bytes, alignment));
   1.200 +
   1.201 +  if (change_in_bytes == 0) {
   1.202 +    return false;
   1.203 +  }
   1.204 +
   1.205 +  if (TraceAdaptiveGCBoundary) {
   1.206 +    gclog_or_tty->print_cr("Before expansion of young gen with boundary move");
   1.207 +    gclog_or_tty->print_cr("  Requested change: " SIZE_FORMAT_HEX "  Attempted change: " SIZE_FORMAT_HEX,
   1.208 +      expand_in_bytes, change_in_bytes);
   1.209 +    if (!PrintHeapAtGC) {
   1.210 +      Universe::print_on(gclog_or_tty);
   1.211 +    }
   1.212 +    gclog_or_tty->print_cr("  PSYoungGen max size: " SIZE_FORMAT "K",
   1.213 +      young_gen()->max_size()/K);
   1.214 +  }
   1.215 +
   1.216 +  // Move the boundary between the generations down (smaller old gen).
   1.217 +  MutexLocker x(ExpandHeap_lock);
   1.218 +  if (virtual_spaces()->adjust_boundary_down(change_in_bytes)) {
   1.219 +    young_gen()->reset_after_change();
   1.220 +    old_gen()->reset_after_change();
   1.221 +    result = true;
   1.222 +  }
   1.223 +
   1.224 +  // The total reserved for the generations should match the sum
   1.225 +  // of the two even if the boundary is moving.
   1.226 +  assert(reserved_byte_size() ==
   1.227 +         old_gen()->max_gen_size() + young_gen()->max_size(),
   1.228 +         "Space is missing");
   1.229 +  young_gen()->space_invariants();
   1.230 +  old_gen()->space_invariants();
   1.231 +
   1.232 +  if (TraceAdaptiveGCBoundary) {
   1.233 +    gclog_or_tty->print_cr("After expansion of young gen with boundary move");
   1.234 +    if (!PrintHeapAtGC) {
   1.235 +      Universe::print_on(gclog_or_tty);
   1.236 +    }
   1.237 +    gclog_or_tty->print_cr("  PSYoungGen max size: " SIZE_FORMAT "K",
   1.238 +      young_gen()->max_size()/K);
   1.239 +  }
   1.240 +
   1.241 +  return result;
   1.242 +}
   1.243 +
   1.244 +// Additional space is needed in the old generation.  Try to move the boundary
   1.245 +// up to meet the need.  Moves boundary up only
   1.246 +void AdjoiningGenerations::adjust_boundary_for_old_gen_needs(
   1.247 +  size_t desired_free_space) {
   1.248 +  assert(UseAdaptiveSizePolicy && UseAdaptiveGCBoundary, "runtime check");
   1.249 +
   1.250 +  // Stress testing.
   1.251 +  if (PSAdaptiveSizePolicyResizeVirtualSpaceAlot == 1) {
   1.252 +    MutexLocker x(ExpandHeap_lock);
   1.253 +    request_old_gen_expansion(virtual_spaces()->alignment() * 3 / 2);
   1.254 +  }
   1.255 +
   1.256 +  // Expand only if the entire generation is already committed.
   1.257 +  if (old_gen()->virtual_space()->uncommitted_size() == 0) {
   1.258 +    if (old_gen()->free_in_bytes() < desired_free_space) {
   1.259 +      MutexLocker x(ExpandHeap_lock);
   1.260 +      request_old_gen_expansion(desired_free_space);
   1.261 +    }
   1.262 +  }
   1.263 +}
   1.264 +
   1.265 +// See comment on adjust_boundary_for_old_gen_needss().
   1.266 +// Adjust boundary down only.
   1.267 +void AdjoiningGenerations::adjust_boundary_for_young_gen_needs(size_t eden_size,
   1.268 +    size_t survivor_size) {
   1.269 +
   1.270 +  assert(UseAdaptiveSizePolicy && UseAdaptiveGCBoundary, "runtime check");
   1.271 +
   1.272 +  // Stress testing.
   1.273 +  if (PSAdaptiveSizePolicyResizeVirtualSpaceAlot == 0) {
   1.274 +    request_young_gen_expansion(virtual_spaces()->alignment() * 3 / 2);
   1.275 +    eden_size = young_gen()->eden_space()->capacity_in_bytes();
   1.276 +  }
   1.277 +
   1.278 +  // Expand only if the entire generation is already committed.
   1.279 +  if (young_gen()->virtual_space()->uncommitted_size() == 0) {
   1.280 +    size_t desired_size = eden_size + 2 * survivor_size;
   1.281 +    const size_t committed = young_gen()->virtual_space()->committed_size();
   1.282 +    if (desired_size > committed) {
   1.283 +      request_young_gen_expansion(desired_size - committed);
   1.284 +    }
   1.285 +  }
   1.286 +}

mercurial