src/share/vm/gc_implementation/parNew/asParNewGeneration.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/parNew/asParNewGeneration.cpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,657 @@
     1.4 +/*
     1.5 + * Copyright (c) 2005, 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/concurrentMarkSweep/cmsAdaptiveSizePolicy.hpp"
    1.30 +#include "gc_implementation/concurrentMarkSweep/cmsGCAdaptivePolicyCounters.hpp"
    1.31 +#include "gc_implementation/parNew/asParNewGeneration.hpp"
    1.32 +#include "gc_implementation/parNew/parNewGeneration.hpp"
    1.33 +#include "gc_implementation/shared/markSweep.inline.hpp"
    1.34 +#include "gc_implementation/shared/spaceDecorator.hpp"
    1.35 +#include "memory/defNewGeneration.inline.hpp"
    1.36 +#include "memory/referencePolicy.hpp"
    1.37 +#include "oops/markOop.inline.hpp"
    1.38 +#include "oops/oop.pcgc.inline.hpp"
    1.39 +
    1.40 +ASParNewGeneration::ASParNewGeneration(ReservedSpace rs,
    1.41 +                                       size_t initial_byte_size,
    1.42 +                                       size_t min_byte_size,
    1.43 +                                       int level) :
    1.44 +  ParNewGeneration(rs, initial_byte_size, level),
    1.45 +  _min_gen_size(min_byte_size) {}
    1.46 +
    1.47 +const char* ASParNewGeneration::name() const {
    1.48 +  return "adaptive size par new generation";
    1.49 +}
    1.50 +
    1.51 +void ASParNewGeneration::adjust_desired_tenuring_threshold() {
    1.52 +  assert(UseAdaptiveSizePolicy,
    1.53 +    "Should only be used with UseAdaptiveSizePolicy");
    1.54 +}
    1.55 +
    1.56 +void ASParNewGeneration::resize(size_t eden_size, size_t survivor_size) {
    1.57 +  // Resize the generation if needed. If the generation resize
    1.58 +  // reports false, do not attempt to resize the spaces.
    1.59 +  if (resize_generation(eden_size, survivor_size)) {
    1.60 +    // Then we lay out the spaces inside the generation
    1.61 +    resize_spaces(eden_size, survivor_size);
    1.62 +
    1.63 +    space_invariants();
    1.64 +
    1.65 +    if (PrintAdaptiveSizePolicy && Verbose) {
    1.66 +      gclog_or_tty->print_cr("Young generation size: "
    1.67 +        "desired eden: " SIZE_FORMAT " survivor: " SIZE_FORMAT
    1.68 +        " used: " SIZE_FORMAT " capacity: " SIZE_FORMAT
    1.69 +        " gen limits: " SIZE_FORMAT " / " SIZE_FORMAT,
    1.70 +        eden_size, survivor_size, used(), capacity(),
    1.71 +        max_gen_size(), min_gen_size());
    1.72 +    }
    1.73 +  }
    1.74 +}
    1.75 +
    1.76 +size_t ASParNewGeneration::available_to_min_gen() {
    1.77 +  assert(virtual_space()->committed_size() >= min_gen_size(), "Invariant");
    1.78 +  return virtual_space()->committed_size() - min_gen_size();
    1.79 +}
    1.80 +
    1.81 +// This method assumes that from-space has live data and that
    1.82 +// any shrinkage of the young gen is limited by location of
    1.83 +// from-space.
    1.84 +size_t ASParNewGeneration::available_to_live() const {
    1.85 +#undef SHRINKS_AT_END_OF_EDEN
    1.86 +#ifdef SHRINKS_AT_END_OF_EDEN
    1.87 +  size_t delta_in_survivor = 0;
    1.88 +  ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
    1.89 +  const size_t space_alignment = heap->intra_heap_alignment();
    1.90 +  const size_t gen_alignment = heap->object_heap_alignment();
    1.91 +
    1.92 +  MutableSpace* space_shrinking = NULL;
    1.93 +  if (from_space()->end() > to_space()->end()) {
    1.94 +    space_shrinking = from_space();
    1.95 +  } else {
    1.96 +    space_shrinking = to_space();
    1.97 +  }
    1.98 +
    1.99 +  // Include any space that is committed but not included in
   1.100 +  // the survivor spaces.
   1.101 +  assert(((HeapWord*)virtual_space()->high()) >= space_shrinking->end(),
   1.102 +    "Survivor space beyond high end");
   1.103 +  size_t unused_committed = pointer_delta(virtual_space()->high(),
   1.104 +    space_shrinking->end(), sizeof(char));
   1.105 +
   1.106 +  if (space_shrinking->is_empty()) {
   1.107 +    // Don't let the space shrink to 0
   1.108 +    assert(space_shrinking->capacity_in_bytes() >= space_alignment,
   1.109 +      "Space is too small");
   1.110 +    delta_in_survivor = space_shrinking->capacity_in_bytes() - space_alignment;
   1.111 +  } else {
   1.112 +    delta_in_survivor = pointer_delta(space_shrinking->end(),
   1.113 +                                      space_shrinking->top(),
   1.114 +                                      sizeof(char));
   1.115 +  }
   1.116 +
   1.117 +  size_t delta_in_bytes = unused_committed + delta_in_survivor;
   1.118 +  delta_in_bytes = align_size_down(delta_in_bytes, gen_alignment);
   1.119 +  return delta_in_bytes;
   1.120 +#else
   1.121 +  // The only space available for shrinking is in to-space if it
   1.122 +  // is above from-space.
   1.123 +  if (to()->bottom() > from()->bottom()) {
   1.124 +    const size_t alignment = os::vm_page_size();
   1.125 +    if (to()->capacity() < alignment) {
   1.126 +      return 0;
   1.127 +    } else {
   1.128 +      return to()->capacity() - alignment;
   1.129 +    }
   1.130 +  } else {
   1.131 +    return 0;
   1.132 +  }
   1.133 +#endif
   1.134 +}
   1.135 +
   1.136 +// Return the number of bytes available for resizing down the young
   1.137 +// generation.  This is the minimum of
   1.138 +//      input "bytes"
   1.139 +//      bytes to the minimum young gen size
   1.140 +//      bytes to the size currently being used + some small extra
   1.141 +size_t ASParNewGeneration::limit_gen_shrink (size_t bytes) {
   1.142 +  // Allow shrinkage into the current eden but keep eden large enough
   1.143 +  // to maintain the minimum young gen size
   1.144 +  bytes = MIN3(bytes, available_to_min_gen(), available_to_live());
   1.145 +  return align_size_down(bytes, os::vm_page_size());
   1.146 +}
   1.147 +
   1.148 +// Note that the the alignment used is the OS page size as
   1.149 +// opposed to an alignment associated with the virtual space
   1.150 +// (as is done in the ASPSYoungGen/ASPSOldGen)
   1.151 +bool ASParNewGeneration::resize_generation(size_t eden_size,
   1.152 +                                           size_t survivor_size) {
   1.153 +  const size_t alignment = os::vm_page_size();
   1.154 +  size_t orig_size = virtual_space()->committed_size();
   1.155 +  bool size_changed = false;
   1.156 +
   1.157 +  // There used to be this guarantee there.
   1.158 +  // guarantee ((eden_size + 2*survivor_size)  <= _max_gen_size, "incorrect input arguments");
   1.159 +  // Code below forces this requirement.  In addition the desired eden
   1.160 +  // size and disired survivor sizes are desired goals and may
   1.161 +  // exceed the total generation size.
   1.162 +
   1.163 +  assert(min_gen_size() <= orig_size && orig_size <= max_gen_size(),
   1.164 +    "just checking");
   1.165 +
   1.166 +  // Adjust new generation size
   1.167 +  const size_t eden_plus_survivors =
   1.168 +          align_size_up(eden_size + 2 * survivor_size, alignment);
   1.169 +  size_t desired_size = MAX2(MIN2(eden_plus_survivors, max_gen_size()),
   1.170 +                             min_gen_size());
   1.171 +  assert(desired_size <= max_gen_size(), "just checking");
   1.172 +
   1.173 +  if (desired_size > orig_size) {
   1.174 +    // Grow the generation
   1.175 +    size_t change = desired_size - orig_size;
   1.176 +    assert(change % alignment == 0, "just checking");
   1.177 +    if (expand(change)) {
   1.178 +      return false; // Error if we fail to resize!
   1.179 +    }
   1.180 +    size_changed = true;
   1.181 +  } else if (desired_size < orig_size) {
   1.182 +    size_t desired_change = orig_size - desired_size;
   1.183 +    assert(desired_change % alignment == 0, "just checking");
   1.184 +
   1.185 +    desired_change = limit_gen_shrink(desired_change);
   1.186 +
   1.187 +    if (desired_change > 0) {
   1.188 +      virtual_space()->shrink_by(desired_change);
   1.189 +      reset_survivors_after_shrink();
   1.190 +
   1.191 +      size_changed = true;
   1.192 +    }
   1.193 +  } else {
   1.194 +    if (Verbose && PrintGC) {
   1.195 +      if (orig_size == max_gen_size()) {
   1.196 +        gclog_or_tty->print_cr("ASParNew generation size at maximum: "
   1.197 +          SIZE_FORMAT "K", orig_size/K);
   1.198 +      } else if (orig_size == min_gen_size()) {
   1.199 +        gclog_or_tty->print_cr("ASParNew generation size at minium: "
   1.200 +          SIZE_FORMAT "K", orig_size/K);
   1.201 +      }
   1.202 +    }
   1.203 +  }
   1.204 +
   1.205 +  if (size_changed) {
   1.206 +    MemRegion cmr((HeapWord*)virtual_space()->low(),
   1.207 +                  (HeapWord*)virtual_space()->high());
   1.208 +    GenCollectedHeap::heap()->barrier_set()->resize_covered_region(cmr);
   1.209 +
   1.210 +    if (Verbose && PrintGC) {
   1.211 +      size_t current_size  = virtual_space()->committed_size();
   1.212 +      gclog_or_tty->print_cr("ASParNew generation size changed: "
   1.213 +                             SIZE_FORMAT "K->" SIZE_FORMAT "K",
   1.214 +                             orig_size/K, current_size/K);
   1.215 +    }
   1.216 +  }
   1.217 +
   1.218 +  guarantee(eden_plus_survivors <= virtual_space()->committed_size() ||
   1.219 +            virtual_space()->committed_size() == max_gen_size(), "Sanity");
   1.220 +
   1.221 +  return true;
   1.222 +}
   1.223 +
   1.224 +void ASParNewGeneration::reset_survivors_after_shrink() {
   1.225 +
   1.226 +  GenCollectedHeap* gch = GenCollectedHeap::heap();
   1.227 +  HeapWord* new_end = (HeapWord*)virtual_space()->high();
   1.228 +
   1.229 +  if (from()->end() > to()->end()) {
   1.230 +    assert(new_end >= from()->end(), "Shrinking past from-space");
   1.231 +  } else {
   1.232 +    assert(new_end >= to()->bottom(), "Shrink was too large");
   1.233 +    // Was there a shrink of the survivor space?
   1.234 +    if (new_end < to()->end()) {
   1.235 +      MemRegion mr(to()->bottom(), new_end);
   1.236 +      to()->initialize(mr,
   1.237 +                       SpaceDecorator::DontClear,
   1.238 +                       SpaceDecorator::DontMangle);
   1.239 +    }
   1.240 +  }
   1.241 +}
   1.242 +void ASParNewGeneration::resize_spaces(size_t requested_eden_size,
   1.243 +                                       size_t requested_survivor_size) {
   1.244 +  assert(UseAdaptiveSizePolicy, "sanity check");
   1.245 +  assert(requested_eden_size > 0  && requested_survivor_size > 0,
   1.246 +         "just checking");
   1.247 +  CollectedHeap* heap = Universe::heap();
   1.248 +  assert(heap->kind() == CollectedHeap::GenCollectedHeap, "Sanity");
   1.249 +
   1.250 +
   1.251 +  // We require eden and to space to be empty
   1.252 +  if ((!eden()->is_empty()) || (!to()->is_empty())) {
   1.253 +    return;
   1.254 +  }
   1.255 +
   1.256 +  size_t cur_eden_size = eden()->capacity();
   1.257 +
   1.258 +  if (PrintAdaptiveSizePolicy && Verbose) {
   1.259 +    gclog_or_tty->print_cr("ASParNew::resize_spaces(requested_eden_size: "
   1.260 +                  SIZE_FORMAT
   1.261 +                  ", requested_survivor_size: " SIZE_FORMAT ")",
   1.262 +                  requested_eden_size, requested_survivor_size);
   1.263 +    gclog_or_tty->print_cr("    eden: [" PTR_FORMAT ".." PTR_FORMAT ") "
   1.264 +                  SIZE_FORMAT,
   1.265 +                  p2i(eden()->bottom()),
   1.266 +                  p2i(eden()->end()),
   1.267 +                  pointer_delta(eden()->end(),
   1.268 +                                eden()->bottom(),
   1.269 +                                sizeof(char)));
   1.270 +    gclog_or_tty->print_cr("    from: [" PTR_FORMAT ".." PTR_FORMAT ") "
   1.271 +                  SIZE_FORMAT,
   1.272 +                  p2i(from()->bottom()),
   1.273 +                  p2i(from()->end()),
   1.274 +                  pointer_delta(from()->end(),
   1.275 +                                from()->bottom(),
   1.276 +                                sizeof(char)));
   1.277 +    gclog_or_tty->print_cr("      to: [" PTR_FORMAT ".." PTR_FORMAT ") "
   1.278 +                  SIZE_FORMAT,
   1.279 +                  p2i(to()->bottom()),
   1.280 +                  p2i(to()->end()),
   1.281 +                  pointer_delta(  to()->end(),
   1.282 +                                  to()->bottom(),
   1.283 +                                  sizeof(char)));
   1.284 +  }
   1.285 +
   1.286 +  // There's nothing to do if the new sizes are the same as the current
   1.287 +  if (requested_survivor_size == to()->capacity() &&
   1.288 +      requested_survivor_size == from()->capacity() &&
   1.289 +      requested_eden_size == eden()->capacity()) {
   1.290 +    if (PrintAdaptiveSizePolicy && Verbose) {
   1.291 +      gclog_or_tty->print_cr("    capacities are the right sizes, returning");
   1.292 +    }
   1.293 +    return;
   1.294 +  }
   1.295 +
   1.296 +  char* eden_start = (char*)eden()->bottom();
   1.297 +  char* eden_end   = (char*)eden()->end();
   1.298 +  char* from_start = (char*)from()->bottom();
   1.299 +  char* from_end   = (char*)from()->end();
   1.300 +  char* to_start   = (char*)to()->bottom();
   1.301 +  char* to_end     = (char*)to()->end();
   1.302 +
   1.303 +  const size_t alignment = os::vm_page_size();
   1.304 +  const bool maintain_minimum =
   1.305 +    (requested_eden_size + 2 * requested_survivor_size) <= min_gen_size();
   1.306 +
   1.307 +  // Check whether from space is below to space
   1.308 +  if (from_start < to_start) {
   1.309 +    // Eden, from, to
   1.310 +    if (PrintAdaptiveSizePolicy && Verbose) {
   1.311 +      gclog_or_tty->print_cr("  Eden, from, to:");
   1.312 +    }
   1.313 +
   1.314 +    // Set eden
   1.315 +    // "requested_eden_size" is a goal for the size of eden
   1.316 +    // and may not be attainable.  "eden_size" below is
   1.317 +    // calculated based on the location of from-space and
   1.318 +    // the goal for the size of eden.  from-space is
   1.319 +    // fixed in place because it contains live data.
   1.320 +    // The calculation is done this way to avoid 32bit
   1.321 +    // overflow (i.e., eden_start + requested_eden_size
   1.322 +    // may too large for representation in 32bits).
   1.323 +    size_t eden_size;
   1.324 +    if (maintain_minimum) {
   1.325 +      // Only make eden larger than the requested size if
   1.326 +      // the minimum size of the generation has to be maintained.
   1.327 +      // This could be done in general but policy at a higher
   1.328 +      // level is determining a requested size for eden and that
   1.329 +      // should be honored unless there is a fundamental reason.
   1.330 +      eden_size = pointer_delta(from_start,
   1.331 +                                eden_start,
   1.332 +                                sizeof(char));
   1.333 +    } else {
   1.334 +      eden_size = MIN2(requested_eden_size,
   1.335 +                       pointer_delta(from_start, eden_start, sizeof(char)));
   1.336 +    }
   1.337 +
   1.338 +    eden_size = align_size_down(eden_size, alignment);
   1.339 +    eden_end = eden_start + eden_size;
   1.340 +    assert(eden_end >= eden_start, "addition overflowed");
   1.341 +
   1.342 +    // To may resize into from space as long as it is clear of live data.
   1.343 +    // From space must remain page aligned, though, so we need to do some
   1.344 +    // extra calculations.
   1.345 +
   1.346 +    // First calculate an optimal to-space
   1.347 +    to_end   = (char*)virtual_space()->high();
   1.348 +    to_start = (char*)pointer_delta(to_end, (char*)requested_survivor_size,
   1.349 +                                    sizeof(char));
   1.350 +
   1.351 +    // Does the optimal to-space overlap from-space?
   1.352 +    if (to_start < (char*)from()->end()) {
   1.353 +      // Calculate the minimum offset possible for from_end
   1.354 +      size_t from_size = pointer_delta(from()->top(), from_start, sizeof(char));
   1.355 +
   1.356 +      // Should we be in this method if from_space is empty? Why not the set_space method? FIX ME!
   1.357 +      if (from_size == 0) {
   1.358 +        from_size = alignment;
   1.359 +      } else {
   1.360 +        from_size = align_size_up(from_size, alignment);
   1.361 +      }
   1.362 +
   1.363 +      from_end = from_start + from_size;
   1.364 +      assert(from_end > from_start, "addition overflow or from_size problem");
   1.365 +
   1.366 +      guarantee(from_end <= (char*)from()->end(), "from_end moved to the right");
   1.367 +
   1.368 +      // Now update to_start with the new from_end
   1.369 +      to_start = MAX2(from_end, to_start);
   1.370 +    } else {
   1.371 +      // If shrinking, move to-space down to abut the end of from-space
   1.372 +      // so that shrinking will move to-space down.  If not shrinking
   1.373 +      // to-space is moving up to allow for growth on the next expansion.
   1.374 +      if (requested_eden_size <= cur_eden_size) {
   1.375 +        to_start = from_end;
   1.376 +        if (to_start + requested_survivor_size > to_start) {
   1.377 +          to_end = to_start + requested_survivor_size;
   1.378 +        }
   1.379 +      }
   1.380 +      // else leave to_end pointing to the high end of the virtual space.
   1.381 +    }
   1.382 +
   1.383 +    guarantee(to_start != to_end, "to space is zero sized");
   1.384 +
   1.385 +    if (PrintAdaptiveSizePolicy && Verbose) {
   1.386 +      gclog_or_tty->print_cr("    [eden_start .. eden_end): "
   1.387 +                    "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT,
   1.388 +                    p2i(eden_start),
   1.389 +                    p2i(eden_end),
   1.390 +                    pointer_delta(eden_end, eden_start, sizeof(char)));
   1.391 +      gclog_or_tty->print_cr("    [from_start .. from_end): "
   1.392 +                    "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT,
   1.393 +                    p2i(from_start),
   1.394 +                    p2i(from_end),
   1.395 +                    pointer_delta(from_end, from_start, sizeof(char)));
   1.396 +      gclog_or_tty->print_cr("    [  to_start ..   to_end): "
   1.397 +                    "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT,
   1.398 +                    p2i(to_start),
   1.399 +                    p2i(to_end),
   1.400 +                    pointer_delta(  to_end,   to_start, sizeof(char)));
   1.401 +    }
   1.402 +  } else {
   1.403 +    // Eden, to, from
   1.404 +    if (PrintAdaptiveSizePolicy && Verbose) {
   1.405 +      gclog_or_tty->print_cr("  Eden, to, from:");
   1.406 +    }
   1.407 +
   1.408 +    // Calculate the to-space boundaries based on
   1.409 +    // the start of from-space.
   1.410 +    to_end = from_start;
   1.411 +    to_start = (char*)pointer_delta(from_start,
   1.412 +                                    (char*)requested_survivor_size,
   1.413 +                                    sizeof(char));
   1.414 +    // Calculate the ideal eden boundaries.
   1.415 +    // eden_end is already at the bottom of the generation
   1.416 +    assert(eden_start == virtual_space()->low(),
   1.417 +      "Eden is not starting at the low end of the virtual space");
   1.418 +    if (eden_start + requested_eden_size >= eden_start) {
   1.419 +      eden_end = eden_start + requested_eden_size;
   1.420 +    } else {
   1.421 +      eden_end = to_start;
   1.422 +    }
   1.423 +
   1.424 +    // Does eden intrude into to-space?  to-space
   1.425 +    // gets priority but eden is not allowed to shrink
   1.426 +    // to 0.
   1.427 +    if (eden_end > to_start) {
   1.428 +      eden_end = to_start;
   1.429 +    }
   1.430 +
   1.431 +    // Don't let eden shrink down to 0 or less.
   1.432 +    eden_end = MAX2(eden_end, eden_start + alignment);
   1.433 +    assert(eden_start + alignment >= eden_start, "Overflow");
   1.434 +
   1.435 +    size_t eden_size;
   1.436 +    if (maintain_minimum) {
   1.437 +      // Use all the space available.
   1.438 +      eden_end = MAX2(eden_end, to_start);
   1.439 +      eden_size = pointer_delta(eden_end, eden_start, sizeof(char));
   1.440 +      eden_size = MIN2(eden_size, cur_eden_size);
   1.441 +    } else {
   1.442 +      eden_size = pointer_delta(eden_end, eden_start, sizeof(char));
   1.443 +    }
   1.444 +    eden_size = align_size_down(eden_size, alignment);
   1.445 +    assert(maintain_minimum || eden_size <= requested_eden_size,
   1.446 +      "Eden size is too large");
   1.447 +    assert(eden_size >= alignment, "Eden size is too small");
   1.448 +    eden_end = eden_start + eden_size;
   1.449 +
   1.450 +    // Move to-space down to eden.
   1.451 +    if (requested_eden_size < cur_eden_size) {
   1.452 +      to_start = eden_end;
   1.453 +      if (to_start + requested_survivor_size > to_start) {
   1.454 +        to_end = MIN2(from_start, to_start + requested_survivor_size);
   1.455 +      } else {
   1.456 +        to_end = from_start;
   1.457 +      }
   1.458 +    }
   1.459 +
   1.460 +    // eden_end may have moved so again make sure
   1.461 +    // the to-space and eden don't overlap.
   1.462 +    to_start = MAX2(eden_end, to_start);
   1.463 +
   1.464 +    // from-space
   1.465 +    size_t from_used = from()->used();
   1.466 +    if (requested_survivor_size > from_used) {
   1.467 +      if (from_start + requested_survivor_size >= from_start) {
   1.468 +        from_end = from_start + requested_survivor_size;
   1.469 +      }
   1.470 +      if (from_end > virtual_space()->high()) {
   1.471 +        from_end = virtual_space()->high();
   1.472 +      }
   1.473 +    }
   1.474 +
   1.475 +    assert(to_start >= eden_end, "to-space should be above eden");
   1.476 +    if (PrintAdaptiveSizePolicy && Verbose) {
   1.477 +      gclog_or_tty->print_cr("    [eden_start .. eden_end): "
   1.478 +                    "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT,
   1.479 +                    p2i(eden_start),
   1.480 +                    p2i(eden_end),
   1.481 +                    pointer_delta(eden_end, eden_start, sizeof(char)));
   1.482 +      gclog_or_tty->print_cr("    [  to_start ..   to_end): "
   1.483 +                    "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT,
   1.484 +                    p2i(to_start),
   1.485 +                    p2i(to_end),
   1.486 +                    pointer_delta(  to_end,   to_start, sizeof(char)));
   1.487 +      gclog_or_tty->print_cr("    [from_start .. from_end): "
   1.488 +                    "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT,
   1.489 +                    p2i(from_start),
   1.490 +                    p2i(from_end),
   1.491 +                    pointer_delta(from_end, from_start, sizeof(char)));
   1.492 +    }
   1.493 +  }
   1.494 +
   1.495 +
   1.496 +  guarantee((HeapWord*)from_start <= from()->bottom(),
   1.497 +            "from start moved to the right");
   1.498 +  guarantee((HeapWord*)from_end >= from()->top(),
   1.499 +            "from end moved into live data");
   1.500 +  assert(is_object_aligned((intptr_t)eden_start), "checking alignment");
   1.501 +  assert(is_object_aligned((intptr_t)from_start), "checking alignment");
   1.502 +  assert(is_object_aligned((intptr_t)to_start), "checking alignment");
   1.503 +
   1.504 +  MemRegion edenMR((HeapWord*)eden_start, (HeapWord*)eden_end);
   1.505 +  MemRegion toMR  ((HeapWord*)to_start,   (HeapWord*)to_end);
   1.506 +  MemRegion fromMR((HeapWord*)from_start, (HeapWord*)from_end);
   1.507 +
   1.508 +  // Let's make sure the call to initialize doesn't reset "top"!
   1.509 +  HeapWord* old_from_top = from()->top();
   1.510 +
   1.511 +  // For PrintAdaptiveSizePolicy block  below
   1.512 +  size_t old_from = from()->capacity();
   1.513 +  size_t old_to   = to()->capacity();
   1.514 +
   1.515 +  // If not clearing the spaces, do some checking to verify that
   1.516 +  // the spaces are already mangled.
   1.517 +
   1.518 +  // Must check mangling before the spaces are reshaped.  Otherwise,
   1.519 +  // the bottom or end of one space may have moved into another
   1.520 +  // a failure of the check may not correctly indicate which space
   1.521 +  // is not properly mangled.
   1.522 +  if (ZapUnusedHeapArea) {
   1.523 +    HeapWord* limit = (HeapWord*) virtual_space()->high();
   1.524 +    eden()->check_mangled_unused_area(limit);
   1.525 +    from()->check_mangled_unused_area(limit);
   1.526 +      to()->check_mangled_unused_area(limit);
   1.527 +  }
   1.528 +
   1.529 +  // The call to initialize NULL's the next compaction space
   1.530 +  eden()->initialize(edenMR,
   1.531 +                     SpaceDecorator::Clear,
   1.532 +                     SpaceDecorator::DontMangle);
   1.533 +  eden()->set_next_compaction_space(from());
   1.534 +    to()->initialize(toMR  ,
   1.535 +                     SpaceDecorator::Clear,
   1.536 +                     SpaceDecorator::DontMangle);
   1.537 +  from()->initialize(fromMR,
   1.538 +                     SpaceDecorator::DontClear,
   1.539 +                     SpaceDecorator::DontMangle);
   1.540 +
   1.541 +  assert(from()->top() == old_from_top, "from top changed!");
   1.542 +
   1.543 +  if (PrintAdaptiveSizePolicy) {
   1.544 +    GenCollectedHeap* gch = GenCollectedHeap::heap();
   1.545 +    assert(gch->kind() == CollectedHeap::GenCollectedHeap, "Sanity");
   1.546 +
   1.547 +    gclog_or_tty->print("AdaptiveSizePolicy::survivor space sizes: "
   1.548 +                  "collection: %d "
   1.549 +                  "(" SIZE_FORMAT ", " SIZE_FORMAT ") -> "
   1.550 +                  "(" SIZE_FORMAT ", " SIZE_FORMAT ") ",
   1.551 +                  gch->total_collections(),
   1.552 +                  old_from, old_to,
   1.553 +                  from()->capacity(),
   1.554 +                  to()->capacity());
   1.555 +    gclog_or_tty->cr();
   1.556 +  }
   1.557 +}
   1.558 +
   1.559 +void ASParNewGeneration::compute_new_size() {
   1.560 +  GenCollectedHeap* gch = GenCollectedHeap::heap();
   1.561 +  assert(gch->kind() == CollectedHeap::GenCollectedHeap,
   1.562 +    "not a CMS generational heap");
   1.563 +
   1.564 +
   1.565 +  CMSAdaptiveSizePolicy* size_policy =
   1.566 +    (CMSAdaptiveSizePolicy*)gch->gen_policy()->size_policy();
   1.567 +  assert(size_policy->is_gc_cms_adaptive_size_policy(),
   1.568 +    "Wrong type of size policy");
   1.569 +
   1.570 +  size_t survived = from()->used();
   1.571 +  if (!survivor_overflow()) {
   1.572 +    // Keep running averages on how much survived
   1.573 +    size_policy->avg_survived()->sample(survived);
   1.574 +  } else {
   1.575 +    size_t promoted =
   1.576 +      (size_t) next_gen()->gc_stats()->avg_promoted()->last_sample();
   1.577 +    assert(promoted < gch->capacity(), "Conversion problem?");
   1.578 +    size_t survived_guess = survived + promoted;
   1.579 +    size_policy->avg_survived()->sample(survived_guess);
   1.580 +  }
   1.581 +
   1.582 +  size_t survivor_limit = max_survivor_size();
   1.583 +  _tenuring_threshold =
   1.584 +    size_policy->compute_survivor_space_size_and_threshold(
   1.585 +                                                     _survivor_overflow,
   1.586 +                                                     _tenuring_threshold,
   1.587 +                                                     survivor_limit);
   1.588 +  size_policy->avg_young_live()->sample(used());
   1.589 +  size_policy->avg_eden_live()->sample(eden()->used());
   1.590 +
   1.591 +  size_policy->compute_eden_space_size(eden()->capacity(), max_gen_size());
   1.592 +
   1.593 +  resize(size_policy->calculated_eden_size_in_bytes(),
   1.594 +         size_policy->calculated_survivor_size_in_bytes());
   1.595 +
   1.596 +  if (UsePerfData) {
   1.597 +    CMSGCAdaptivePolicyCounters* counters =
   1.598 +      (CMSGCAdaptivePolicyCounters*) gch->collector_policy()->counters();
   1.599 +    assert(counters->kind() ==
   1.600 +           GCPolicyCounters::CMSGCAdaptivePolicyCountersKind,
   1.601 +      "Wrong kind of counters");
   1.602 +    counters->update_tenuring_threshold(_tenuring_threshold);
   1.603 +    counters->update_survivor_overflowed(_survivor_overflow);
   1.604 +    counters->update_young_capacity(capacity());
   1.605 +  }
   1.606 +}
   1.607 +
   1.608 +
   1.609 +#ifndef PRODUCT
   1.610 +// Changes from PSYoungGen version
   1.611 +//      value of "alignment"
   1.612 +void ASParNewGeneration::space_invariants() {
   1.613 +  const size_t alignment = os::vm_page_size();
   1.614 +
   1.615 +  // Currently, our eden size cannot shrink to zero
   1.616 +  guarantee(eden()->capacity() >= alignment, "eden too small");
   1.617 +  guarantee(from()->capacity() >= alignment, "from too small");
   1.618 +  guarantee(to()->capacity() >= alignment, "to too small");
   1.619 +
   1.620 +  // Relationship of spaces to each other
   1.621 +  char* eden_start = (char*)eden()->bottom();
   1.622 +  char* eden_end   = (char*)eden()->end();
   1.623 +  char* from_start = (char*)from()->bottom();
   1.624 +  char* from_end   = (char*)from()->end();
   1.625 +  char* to_start   = (char*)to()->bottom();
   1.626 +  char* to_end     = (char*)to()->end();
   1.627 +
   1.628 +  guarantee(eden_start >= virtual_space()->low(), "eden bottom");
   1.629 +  guarantee(eden_start < eden_end, "eden space consistency");
   1.630 +  guarantee(from_start < from_end, "from space consistency");
   1.631 +  guarantee(to_start < to_end, "to space consistency");
   1.632 +
   1.633 +  // Check whether from space is below to space
   1.634 +  if (from_start < to_start) {
   1.635 +    // Eden, from, to
   1.636 +    guarantee(eden_end <= from_start, "eden/from boundary");
   1.637 +    guarantee(from_end <= to_start,   "from/to boundary");
   1.638 +    guarantee(to_end <= virtual_space()->high(), "to end");
   1.639 +  } else {
   1.640 +    // Eden, to, from
   1.641 +    guarantee(eden_end <= to_start, "eden/to boundary");
   1.642 +    guarantee(to_end <= from_start, "to/from boundary");
   1.643 +    guarantee(from_end <= virtual_space()->high(), "from end");
   1.644 +  }
   1.645 +
   1.646 +  // More checks that the virtual space is consistent with the spaces
   1.647 +  assert(virtual_space()->committed_size() >=
   1.648 +    (eden()->capacity() +
   1.649 +     to()->capacity() +
   1.650 +     from()->capacity()), "Committed size is inconsistent");
   1.651 +  assert(virtual_space()->committed_size() <= virtual_space()->reserved_size(),
   1.652 +    "Space invariant");
   1.653 +  char* eden_top = (char*)eden()->top();
   1.654 +  char* from_top = (char*)from()->top();
   1.655 +  char* to_top = (char*)to()->top();
   1.656 +  assert(eden_top <= virtual_space()->high(), "eden top");
   1.657 +  assert(from_top <= virtual_space()->high(), "from top");
   1.658 +  assert(to_top <= virtual_space()->high(), "to top");
   1.659 +}
   1.660 +#endif

mercurial