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

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

mercurial