annotate src/share/vm/gc_implementation/parNew/asParNewGeneration.cpp @ 4857:14d3f71f831d

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