1 #ifdef USE_PRAGMA_IDENT_SRC
   2 #pragma ident "@(#)asParNewGeneration.cpp       1.11 07/05/05 17:05:25 JVM"
   3 #endif
   4 /*
   5  * Copyright 2005-2008 Sun Microsystems, Inc.  All Rights Reserved.
   6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   7  *
   8  * This code is free software; you can redistribute it and/or modify it
   9  * under the terms of the GNU General Public License version 2 only, as
  10  * published by the Free Software Foundation.
  11  *
  12  * This code is distributed in the hope that it will be useful, but WITHOUT
  13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15  * version 2 for more details (a copy is included in the LICENSE file that
  16  * accompanied this code).
  17  *
  18  * You should have received a copy of the GNU General Public License version
  19  * 2 along with this work; if not, write to the Free Software Foundation,
  20  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  21  *
  22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  23  * CA 95054 USA or visit www.sun.com if you need additional information or
  24  * have any questions.
  25  *  
  26  */
  27 
  28 # include "incls/_precompiled.incl"
  29 # include "incls/_asParNewGeneration.cpp.incl"
  30 
  31 ASParNewGeneration::ASParNewGeneration(ReservedSpace rs, 
  32                                        size_t initial_byte_size, 
  33                                        size_t min_byte_size,
  34                                        int level) :
  35   ParNewGeneration(rs, initial_byte_size, level), 
  36   _min_gen_size(min_byte_size) {}
  37 
  38 const char* ASParNewGeneration::name() const {
  39   return "adaptive size par new generation";
  40 }
  41 
  42 void ASParNewGeneration::adjust_desired_tenuring_threshold() {
  43   assert(UseAdaptiveSizePolicy, 
  44     "Should only be used with UseAdaptiveSizePolicy");
  45 }
  46 
  47 void ASParNewGeneration::resize(size_t eden_size, size_t survivor_size) {
  48   // Resize the generation if needed. If the generation resize
  49   // reports false, do not attempt to resize the spaces.
  50   if (resize_generation(eden_size, survivor_size)) {
  51     // Then we lay out the spaces inside the generation
  52     resize_spaces(eden_size, survivor_size);
  53 
  54     space_invariants();
  55 
  56     if (PrintAdaptiveSizePolicy && Verbose) {
  57       gclog_or_tty->print_cr("Young generation size: "
  58         "desired eden: " SIZE_FORMAT " survivor: " SIZE_FORMAT
  59         " used: " SIZE_FORMAT " capacity: " SIZE_FORMAT
  60         " gen limits: " SIZE_FORMAT " / " SIZE_FORMAT,
  61         eden_size, survivor_size, used(), capacity(),
  62         max_gen_size(), min_gen_size());
  63     }
  64   }
  65 }
  66 
  67 size_t ASParNewGeneration::available_to_min_gen() {
  68   assert(virtual_space()->committed_size() >= min_gen_size(), "Invariant");
  69   return virtual_space()->committed_size() - min_gen_size();
  70 }
  71 
  72 // This method assumes that from-space has live data and that
  73 // any shrinkage of the young gen is limited by location of
  74 // from-space.
  75 size_t ASParNewGeneration::available_to_live() const {
  76 #undef SHRINKS_AT_END_OF_EDEN
  77 #ifdef SHRINKS_AT_END_OF_EDEN
  78   size_t delta_in_survivor = 0;
  79   ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
  80   const size_t space_alignment = heap->intra_heap_alignment();
  81   const size_t gen_alignment = heap->object_heap_alignment();
  82 
  83   MutableSpace* space_shrinking = NULL;
  84   if (from_space()->end() > to_space()->end()) {
  85     space_shrinking = from_space();
  86   } else {
  87     space_shrinking = to_space();
  88   }
  89 
  90   // Include any space that is committed but not included in
  91   // the survivor spaces.
  92   assert(((HeapWord*)virtual_space()->high()) >= space_shrinking->end(),
  93     "Survivor space beyond high end");
  94   size_t unused_committed = pointer_delta(virtual_space()->high(),
  95     space_shrinking->end(), sizeof(char));   
  96 
  97   if (space_shrinking->is_empty()) {
  98     // Don't let the space shrink to 0
  99     assert(space_shrinking->capacity_in_bytes() >= space_alignment, 
 100       "Space is too small");
 101     delta_in_survivor = space_shrinking->capacity_in_bytes() - space_alignment;
 102   } else {
 103     delta_in_survivor = pointer_delta(space_shrinking->end(), 
 104                                       space_shrinking->top(),
 105                                       sizeof(char));
 106   }
 107 
 108   size_t delta_in_bytes = unused_committed + delta_in_survivor;
 109   delta_in_bytes = align_size_down(delta_in_bytes, gen_alignment);
 110   return delta_in_bytes;
 111 #else
 112   // The only space available for shrinking is in to-space if it
 113   // is above from-space.
 114   if (to()->bottom() > from()->bottom()) {
 115     const size_t alignment = os::vm_page_size();
 116     if (to()->capacity() < alignment) {
 117       return 0;
 118     } else {
 119       return to()->capacity() - alignment;
 120     }
 121   } else {
 122     return 0;
 123   }
 124 #endif
 125 }
 126 
 127 // Return the number of bytes available for resizing down the young
 128 // generation.  This is the minimum of
 129 //      input "bytes"
 130 //      bytes to the minimum young gen size
 131 //      bytes to the size currently being used + some small extra
 132 size_t ASParNewGeneration::limit_gen_shrink (size_t bytes) {
 133   // Allow shrinkage into the current eden but keep eden large enough
 134   // to maintain the minimum young gen size
 135   bytes = MIN3(bytes, available_to_min_gen(), available_to_live());
 136   return align_size_down(bytes, os::vm_page_size());
 137 }
 138 
 139 // Note that the the alignment used is the OS page size as
 140 // opposed to an alignment associated with the virtual space
 141 // (as is done in the ASPSYoungGen/ASPSOldGen)
 142 bool ASParNewGeneration::resize_generation(size_t eden_size, 
 143                                            size_t survivor_size) {
 144   const size_t alignment = os::vm_page_size();
 145   size_t orig_size = virtual_space()->committed_size();
 146   bool size_changed = false;
 147 
 148   // There used to be this guarantee there.
 149   // guarantee ((eden_size + 2*survivor_size)  <= _max_gen_size, "incorrect input arguments");
 150   // Code below forces this requirement.  In addition the desired eden
 151   // size and disired survivor sizes are desired goals and may
 152   // exceed the total generation size.
 153 
 154   assert(min_gen_size() <= orig_size && orig_size <= max_gen_size(), 
 155     "just checking");
 156 
 157   // Adjust new generation size
 158   const size_t eden_plus_survivors =
 159           align_size_up(eden_size + 2 * survivor_size, alignment);
 160   size_t desired_size = MAX2(MIN2(eden_plus_survivors, max_gen_size()), 
 161                              min_gen_size());
 162   assert(desired_size <= max_gen_size(), "just checking");
 163 
 164   if (desired_size > orig_size) {
 165     // Grow the generation
 166     size_t change = desired_size - orig_size;
 167     assert(change % alignment == 0, "just checking");
 168     if (expand(change)) {
 169       return false; // Error if we fail to resize!
 170     }
 171     size_changed = true;
 172   } else if (desired_size < orig_size) {
 173     size_t desired_change = orig_size - desired_size;
 174     assert(desired_change % alignment == 0, "just checking");
 175 
 176     desired_change = limit_gen_shrink(desired_change);
 177 
 178     if (desired_change > 0) {
 179       virtual_space()->shrink_by(desired_change);
 180       reset_survivors_after_shrink();
 181 
 182       size_changed = true;
 183     }
 184   } else {
 185     if (Verbose && PrintGC) {
 186       if (orig_size == max_gen_size()) {
 187         gclog_or_tty->print_cr("ASParNew generation size at maximum: "
 188           SIZE_FORMAT "K", orig_size/K);
 189       } else if (orig_size == min_gen_size()) {
 190         gclog_or_tty->print_cr("ASParNew generation size at minium: "
 191           SIZE_FORMAT "K", orig_size/K);
 192       }
 193     }
 194   }
 195 
 196   if (size_changed) {
 197     MemRegion cmr((HeapWord*)virtual_space()->low(),
 198                   (HeapWord*)virtual_space()->high());
 199     GenCollectedHeap::heap()->barrier_set()->resize_covered_region(cmr);
 200 
 201     if (Verbose && PrintGC) {
 202       size_t current_size  = virtual_space()->committed_size();
 203       gclog_or_tty->print_cr("ASParNew generation size changed: "
 204                              SIZE_FORMAT "K->" SIZE_FORMAT "K",
 205                              orig_size/K, current_size/K);
 206     }
 207   }
 208 
 209   guarantee(eden_plus_survivors <= virtual_space()->committed_size() ||
 210             virtual_space()->committed_size() == max_gen_size(), "Sanity");
 211 
 212   return true;
 213 }
 214 
 215 void ASParNewGeneration::reset_survivors_after_shrink() {
 216 
 217   GenCollectedHeap* gch = GenCollectedHeap::heap();
 218   HeapWord* new_end = (HeapWord*)virtual_space()->high();
 219   
 220   if (from()->end() > to()->end()) {
 221     assert(new_end >= from()->end(), "Shrinking past from-space");
 222   } else {
 223     assert(new_end >= to()->bottom(), "Shrink was too large");
 224     // Was there a shrink of the survivor space?
 225     if (new_end < to()->end()) {
 226       MemRegion mr(to()->bottom(), new_end);
 227       to()->initialize(mr,
 228                        SpaceDecorator::DontClear,
 229                        SpaceDecorator::DontMangle);
 230     }
 231   }
 232 }
 233 void ASParNewGeneration::resize_spaces(size_t requested_eden_size, 
 234                                        size_t requested_survivor_size) {
 235   assert(UseAdaptiveSizePolicy, "sanity check");
 236   assert(requested_eden_size > 0  && requested_survivor_size > 0, 
 237          "just checking");
 238   CollectedHeap* heap = Universe::heap();
 239   assert(heap->kind() == CollectedHeap::GenCollectedHeap, "Sanity");
 240       
 241 
 242   // We require eden and to space to be empty
 243   if ((!eden()->is_empty()) || (!to()->is_empty())) {
 244     return;
 245   }
 246 
 247   size_t cur_eden_size = eden()->capacity();
 248 
 249   if (PrintAdaptiveSizePolicy && Verbose) {
 250     gclog_or_tty->print_cr("ASParNew::resize_spaces(requested_eden_size: " 
 251                   SIZE_FORMAT 
 252                   ", requested_survivor_size: " SIZE_FORMAT ")",
 253                   requested_eden_size, requested_survivor_size);
 254     gclog_or_tty->print_cr("    eden: [" PTR_FORMAT ".." PTR_FORMAT ") " 
 255                   SIZE_FORMAT, 
 256                   eden()->bottom(), 
 257                   eden()->end(), 
 258                   pointer_delta(eden()->end(),
 259                                 eden()->bottom(),
 260                                 sizeof(char)));
 261     gclog_or_tty->print_cr("    from: [" PTR_FORMAT ".." PTR_FORMAT ") " 
 262                   SIZE_FORMAT, 
 263                   from()->bottom(), 
 264                   from()->end(), 
 265                   pointer_delta(from()->end(),
 266                                 from()->bottom(),
 267                                 sizeof(char)));
 268     gclog_or_tty->print_cr("      to: [" PTR_FORMAT ".." PTR_FORMAT ") " 
 269                   SIZE_FORMAT, 
 270                   to()->bottom(),   
 271                   to()->end(), 
 272                   pointer_delta(  to()->end(),
 273                                   to()->bottom(),
 274                                   sizeof(char)));
 275   }
 276 
 277   // There's nothing to do if the new sizes are the same as the current
 278   if (requested_survivor_size == to()->capacity() && 
 279       requested_survivor_size == from()->capacity() &&
 280       requested_eden_size == eden()->capacity()) {
 281     if (PrintAdaptiveSizePolicy && Verbose) {
 282       gclog_or_tty->print_cr("    capacities are the right sizes, returning");
 283     }
 284     return;
 285   }
 286   
 287   char* eden_start = (char*)eden()->bottom();
 288   char* eden_end   = (char*)eden()->end();   
 289   char* from_start = (char*)from()->bottom();
 290   char* from_end   = (char*)from()->end();
 291   char* to_start   = (char*)to()->bottom();
 292   char* to_end     = (char*)to()->end();
 293 
 294   const size_t alignment = os::vm_page_size();
 295   const bool maintain_minimum = 
 296     (requested_eden_size + 2 * requested_survivor_size) <= min_gen_size();
 297 
 298   // Check whether from space is below to space
 299   if (from_start < to_start) {
 300     // Eden, from, to
 301     if (PrintAdaptiveSizePolicy && Verbose) {
 302       gclog_or_tty->print_cr("  Eden, from, to:");
 303     }
 304 
 305     // Set eden
 306     // "requested_eden_size" is a goal for the size of eden
 307     // and may not be attainable.  "eden_size" below is
 308     // calculated based on the location of from-space and
 309     // the goal for the size of eden.  from-space is
 310     // fixed in place because it contains live data.
 311     // The calculation is done this way to avoid 32bit
 312     // overflow (i.e., eden_start + requested_eden_size
 313     // may too large for representation in 32bits).
 314     size_t eden_size;
 315     if (maintain_minimum) {
 316       // Only make eden larger than the requested size if
 317       // the minimum size of the generation has to be maintained.
 318       // This could be done in general but policy at a higher
 319       // level is determining a requested size for eden and that
 320       // should be honored unless there is a fundamental reason.
 321       eden_size = pointer_delta(from_start, 
 322                                 eden_start, 
 323                                 sizeof(char));
 324     } else {
 325       eden_size = MIN2(requested_eden_size,
 326                        pointer_delta(from_start, eden_start, sizeof(char)));
 327     }
 328 
 329     eden_size = align_size_down(eden_size, alignment);
 330     eden_end = eden_start + eden_size;
 331     assert(eden_end >= eden_start, "addition overflowed")
 332 
 333     // To may resize into from space as long as it is clear of live data.
 334     // From space must remain page aligned, though, so we need to do some
 335     // extra calculations.
 336 
 337     // First calculate an optimal to-space
 338     to_end   = (char*)virtual_space()->high();
 339     to_start = (char*)pointer_delta(to_end, (char*)requested_survivor_size, 
 340                                     sizeof(char));
 341 
 342     // Does the optimal to-space overlap from-space?
 343     if (to_start < (char*)from()->end()) {
 344       // Calculate the minimum offset possible for from_end
 345       size_t from_size = pointer_delta(from()->top(), from_start, sizeof(char));
 346 
 347       // Should we be in this method if from_space is empty? Why not the set_space method? FIX ME!
 348       if (from_size == 0) {
 349         from_size = alignment;
 350       } else {
 351         from_size = align_size_up(from_size, alignment);
 352       }
 353 
 354       from_end = from_start + from_size;
 355       assert(from_end > from_start, "addition overflow or from_size problem");
 356 
 357       guarantee(from_end <= (char*)from()->end(), "from_end moved to the right");
 358 
 359       // Now update to_start with the new from_end
 360       to_start = MAX2(from_end, to_start);
 361     } else {
 362       // If shrinking, move to-space down to abut the end of from-space
 363       // so that shrinking will move to-space down.  If not shrinking
 364       // to-space is moving up to allow for growth on the next expansion.
 365       if (requested_eden_size <= cur_eden_size) {
 366         to_start = from_end;
 367         if (to_start + requested_survivor_size > to_start) {
 368           to_end = to_start + requested_survivor_size;
 369         }
 370       }
 371       // else leave to_end pointing to the high end of the virtual space.
 372     }
 373 
 374     guarantee(to_start != to_end, "to space is zero sized");
 375       
 376     if (PrintAdaptiveSizePolicy && Verbose) {
 377       gclog_or_tty->print_cr("    [eden_start .. eden_end): "
 378                     "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT, 
 379                     eden_start, 
 380                     eden_end, 
 381                     pointer_delta(eden_end, eden_start, sizeof(char)));
 382       gclog_or_tty->print_cr("    [from_start .. from_end): "
 383                     "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT, 
 384                     from_start, 
 385                     from_end, 
 386                     pointer_delta(from_end, from_start, sizeof(char)));
 387       gclog_or_tty->print_cr("    [  to_start ..   to_end): "
 388                     "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT, 
 389                     to_start,   
 390                     to_end, 
 391                     pointer_delta(  to_end,   to_start, sizeof(char)));
 392     }
 393   } else {
 394     // Eden, to, from
 395     if (PrintAdaptiveSizePolicy && Verbose) {
 396       gclog_or_tty->print_cr("  Eden, to, from:");
 397     }
 398 
 399     // Calculate the to-space boundaries based on
 400     // the start of from-space.
 401     to_end = from_start;
 402     to_start = (char*)pointer_delta(from_start, 
 403                                     (char*)requested_survivor_size, 
 404                                     sizeof(char));
 405     // Calculate the ideal eden boundaries.
 406     // eden_end is already at the bottom of the generation
 407     assert(eden_start == virtual_space()->low(), 
 408       "Eden is not starting at the low end of the virtual space");
 409     if (eden_start + requested_eden_size >= eden_start) {
 410       eden_end = eden_start + requested_eden_size;
 411     } else {
 412       eden_end = to_start;
 413     }
 414 
 415     // Does eden intrude into to-space?  to-space
 416     // gets priority but eden is not allowed to shrink
 417     // to 0.
 418     if (eden_end > to_start) {
 419       eden_end = to_start;
 420     }
 421 
 422     // Don't let eden shrink down to 0 or less.
 423     eden_end = MAX2(eden_end, eden_start + alignment);
 424     assert(eden_start + alignment >= eden_start, "Overflow");
 425 
 426     size_t eden_size;
 427     if (maintain_minimum) {
 428       // Use all the space available.
 429       eden_end = MAX2(eden_end, to_start);
 430       eden_size = pointer_delta(eden_end, eden_start, sizeof(char));
 431       eden_size = MIN2(eden_size, cur_eden_size);
 432     } else {
 433       eden_size = pointer_delta(eden_end, eden_start, sizeof(char));
 434     }
 435     eden_size = align_size_down(eden_size, alignment);
 436     assert(maintain_minimum || eden_size <= requested_eden_size, 
 437       "Eden size is too large");
 438     assert(eden_size >= alignment, "Eden size is too small");
 439     eden_end = eden_start + eden_size;
 440 
 441     // Move to-space down to eden.
 442     if (requested_eden_size < cur_eden_size) {
 443       to_start = eden_end;
 444       if (to_start + requested_survivor_size > to_start) {
 445         to_end = MIN2(from_start, to_start + requested_survivor_size);
 446       } else {
 447         to_end = from_start;
 448       }
 449     }
 450 
 451     // eden_end may have moved so again make sure
 452     // the to-space and eden don't overlap.
 453     to_start = MAX2(eden_end, to_start);
 454 
 455     // from-space
 456     size_t from_used = from()->used();
 457     if (requested_survivor_size > from_used) {
 458       if (from_start + requested_survivor_size >= from_start) {
 459         from_end = from_start + requested_survivor_size;
 460       }
 461       if (from_end > virtual_space()->high()) {
 462         from_end = virtual_space()->high();
 463       }
 464     }
 465 
 466     assert(to_start >= eden_end, "to-space should be above eden");
 467     if (PrintAdaptiveSizePolicy && Verbose) {
 468       gclog_or_tty->print_cr("    [eden_start .. eden_end): "
 469                     "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT, 
 470                     eden_start, 
 471                     eden_end, 
 472                     pointer_delta(eden_end, eden_start, sizeof(char)));
 473       gclog_or_tty->print_cr("    [  to_start ..   to_end): " 
 474                     "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT, 
 475                     to_start,   
 476                     to_end, 
 477                     pointer_delta(  to_end,   to_start, sizeof(char)));
 478       gclog_or_tty->print_cr("    [from_start .. from_end): " 
 479                     "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT, 
 480                     from_start, 
 481                     from_end, 
 482                     pointer_delta(from_end, from_start, sizeof(char)));
 483     }
 484   }
 485   
 486 
 487   guarantee((HeapWord*)from_start <= from()->bottom(), 
 488             "from start moved to the right");
 489   guarantee((HeapWord*)from_end >= from()->top(),
 490             "from end moved into live data");
 491   assert(is_object_aligned((intptr_t)eden_start), "checking alignment");
 492   assert(is_object_aligned((intptr_t)from_start), "checking alignment");
 493   assert(is_object_aligned((intptr_t)to_start), "checking alignment");
 494 
 495   MemRegion edenMR((HeapWord*)eden_start, (HeapWord*)eden_end);
 496   MemRegion toMR  ((HeapWord*)to_start,   (HeapWord*)to_end);
 497   MemRegion fromMR((HeapWord*)from_start, (HeapWord*)from_end);
 498 
 499   // Let's make sure the call to initialize doesn't reset "top"!
 500   HeapWord* old_from_top = from()->top();
 501 
 502   // For PrintAdaptiveSizePolicy block  below
 503   size_t old_from = from()->capacity();
 504   size_t old_to   = to()->capacity();
 505 
 506   // If not clearing the spaces, do some checking to verify that
 507   // the spaces are already mangled.
 508 
 509   // Must check mangling before the spaces are reshaped.  Otherwise,
 510   // the bottom or end of one space may have moved into another
 511   // a failure of the check may not correctly indicate which space
 512   // is not properly mangled.
 513   if (ZapUnusedHeapArea) {
 514     HeapWord* limit = (HeapWord*) virtual_space()->high();
 515     eden()->check_mangled_unused_area(limit);
 516     from()->check_mangled_unused_area(limit);
 517       to()->check_mangled_unused_area(limit);
 518   }
 519 
 520   // The call to initialize NULL's the next compaction space
 521   eden()->initialize(edenMR,
 522                      SpaceDecorator::Clear,
 523                      SpaceDecorator::DontMangle);
 524   eden()->set_next_compaction_space(from());
 525     to()->initialize(toMR  ,
 526                      SpaceDecorator::Clear,
 527                      SpaceDecorator::DontMangle);
 528   from()->initialize(fromMR,
 529                      SpaceDecorator::DontClear,
 530                      SpaceDecorator::DontMangle);
 531 
 532   assert(from()->top() == old_from_top, "from top changed!");
 533 
 534   if (PrintAdaptiveSizePolicy) {
 535     GenCollectedHeap* gch = GenCollectedHeap::heap();
 536     assert(gch->kind() == CollectedHeap::GenCollectedHeap, "Sanity");
 537 
 538     gclog_or_tty->print("AdaptiveSizePolicy::survivor space sizes: "
 539                   "collection: %d "
 540                   "(" SIZE_FORMAT ", " SIZE_FORMAT ") -> "
 541                   "(" SIZE_FORMAT ", " SIZE_FORMAT ") ",
 542                   gch->total_collections(),
 543                   old_from, old_to,
 544                   from()->capacity(),
 545                   to()->capacity());
 546     gclog_or_tty->cr();
 547   }
 548 }
 549 
 550 void ASParNewGeneration::compute_new_size() {
 551   GenCollectedHeap* gch = GenCollectedHeap::heap();
 552   assert(gch->kind() == CollectedHeap::GenCollectedHeap,
 553     "not a CMS generational heap");
 554 
 555 
 556   CMSAdaptiveSizePolicy* size_policy = 
 557     (CMSAdaptiveSizePolicy*)gch->gen_policy()->size_policy();
 558   assert(size_policy->is_gc_cms_adaptive_size_policy(),
 559     "Wrong type of size policy");
 560 
 561   size_t survived = from()->used();
 562   if (!survivor_overflow()) {
 563     // Keep running averages on how much survived
 564     size_policy->avg_survived()->sample(survived);
 565   } else {
 566     size_t promoted = 
 567       (size_t) next_gen()->gc_stats()->avg_promoted()->last_sample();
 568     assert(promoted < gch->capacity(), "Conversion problem?");
 569     size_t survived_guess = survived + promoted;
 570     size_policy->avg_survived()->sample(survived_guess);
 571   }
 572 
 573   size_t survivor_limit = max_survivor_size();
 574   _tenuring_threshold =
 575     size_policy->compute_survivor_space_size_and_threshold(
 576                                                      _survivor_overflow,
 577                                                      _tenuring_threshold,
 578                                                      survivor_limit);
 579   size_policy->avg_young_live()->sample(used());
 580   size_policy->avg_eden_live()->sample(eden()->used());
 581 
 582   size_policy->compute_young_generation_free_space(eden()->capacity(),
 583                                                    max_gen_size());
 584 
 585   resize(size_policy->calculated_eden_size_in_bytes(), 
 586          size_policy->calculated_survivor_size_in_bytes());
 587 
 588   if (UsePerfData) {
 589     CMSGCAdaptivePolicyCounters* counters = 
 590       (CMSGCAdaptivePolicyCounters*) gch->collector_policy()->counters();
 591     assert(counters->kind() == 
 592            GCPolicyCounters::CMSGCAdaptivePolicyCountersKind,
 593       "Wrong kind of counters");
 594     counters->update_tenuring_threshold(_tenuring_threshold);
 595     counters->update_survivor_overflowed(_survivor_overflow);
 596     counters->update_young_capacity(capacity());
 597   }
 598 }
 599 
 600 
 601 #ifndef PRODUCT
 602 // Changes from PSYoungGen version
 603 //      value of "alignment"
 604 void ASParNewGeneration::space_invariants() {
 605   const size_t alignment = os::vm_page_size();
 606 
 607   // Currently, our eden size cannot shrink to zero
 608   guarantee(eden()->capacity() >= alignment, "eden too small");
 609   guarantee(from()->capacity() >= alignment, "from too small");
 610   guarantee(to()->capacity() >= alignment, "to too small");
 611 
 612   // Relationship of spaces to each other
 613   char* eden_start = (char*)eden()->bottom();
 614   char* eden_end   = (char*)eden()->end();   
 615   char* from_start = (char*)from()->bottom();
 616   char* from_end   = (char*)from()->end();
 617   char* to_start   = (char*)to()->bottom();
 618   char* to_end     = (char*)to()->end();
 619 
 620   guarantee(eden_start >= virtual_space()->low(), "eden bottom");
 621   guarantee(eden_start < eden_end, "eden space consistency");
 622   guarantee(from_start < from_end, "from space consistency");
 623   guarantee(to_start < to_end, "to space consistency");
 624 
 625   // Check whether from space is below to space
 626   if (from_start < to_start) {
 627     // Eden, from, to
 628     guarantee(eden_end <= from_start, "eden/from boundary");
 629     guarantee(from_end <= to_start,   "from/to boundary");
 630     guarantee(to_end <= virtual_space()->high(), "to end");
 631   } else {
 632     // Eden, to, from
 633     guarantee(eden_end <= to_start, "eden/to boundary");
 634     guarantee(to_end <= from_start, "to/from boundary");
 635     guarantee(from_end <= virtual_space()->high(), "from end");
 636   }
 637 
 638   // More checks that the virtual space is consistent with the spaces
 639   assert(virtual_space()->committed_size() >=
 640     (eden()->capacity() +
 641      to()->capacity() +
 642      from()->capacity()), "Committed size is inconsistent");
 643   assert(virtual_space()->committed_size() <= virtual_space()->reserved_size(),
 644     "Space invariant");
 645   char* eden_top = (char*)eden()->top();
 646   char* from_top = (char*)from()->top();
 647   char* to_top = (char*)to()->top();
 648   assert(eden_top <= virtual_space()->high(), "eden top");
 649   assert(from_top <= virtual_space()->high(), "from top");
 650   assert(to_top <= virtual_space()->high(), "to top");
 651 }
 652 #endif