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

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #include "precompiled.hpp"
aoqi@0 26 #include "gc_implementation/parallelScavenge/asPSYoungGen.hpp"
aoqi@0 27 #include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp"
aoqi@0 28 #include "gc_implementation/parallelScavenge/psMarkSweepDecorator.hpp"
aoqi@0 29 #include "gc_implementation/parallelScavenge/psScavenge.hpp"
aoqi@0 30 #include "gc_implementation/parallelScavenge/psYoungGen.hpp"
aoqi@0 31 #include "gc_implementation/shared/gcUtil.hpp"
aoqi@0 32 #include "gc_implementation/shared/spaceDecorator.hpp"
aoqi@0 33 #include "oops/oop.inline.hpp"
aoqi@0 34 #include "runtime/java.hpp"
aoqi@0 35
aoqi@0 36 ASPSYoungGen::ASPSYoungGen(size_t init_byte_size,
aoqi@0 37 size_t minimum_byte_size,
aoqi@0 38 size_t byte_size_limit) :
aoqi@0 39 PSYoungGen(init_byte_size, minimum_byte_size, byte_size_limit),
aoqi@0 40 _gen_size_limit(byte_size_limit) {
aoqi@0 41 }
aoqi@0 42
aoqi@0 43
aoqi@0 44 ASPSYoungGen::ASPSYoungGen(PSVirtualSpace* vs,
aoqi@0 45 size_t init_byte_size,
aoqi@0 46 size_t minimum_byte_size,
aoqi@0 47 size_t byte_size_limit) :
aoqi@0 48 //PSYoungGen(init_byte_size, minimum_byte_size, byte_size_limit),
aoqi@0 49 PSYoungGen(vs->committed_size(), minimum_byte_size, byte_size_limit),
aoqi@0 50 _gen_size_limit(byte_size_limit) {
aoqi@0 51
aoqi@0 52 assert(vs->committed_size() == init_byte_size, "Cannot replace with");
aoqi@0 53
aoqi@0 54 _virtual_space = vs;
aoqi@0 55 }
aoqi@0 56
aoqi@0 57 void ASPSYoungGen::initialize_virtual_space(ReservedSpace rs,
aoqi@0 58 size_t alignment) {
aoqi@0 59 assert(_init_gen_size != 0, "Should have a finite size");
aoqi@0 60 _virtual_space = new PSVirtualSpaceHighToLow(rs, alignment);
aoqi@0 61 if (!_virtual_space->expand_by(_init_gen_size)) {
aoqi@0 62 vm_exit_during_initialization("Could not reserve enough space for "
aoqi@0 63 "object heap");
aoqi@0 64 }
aoqi@0 65 }
aoqi@0 66
aoqi@0 67 void ASPSYoungGen::initialize(ReservedSpace rs, size_t alignment) {
aoqi@0 68 initialize_virtual_space(rs, alignment);
aoqi@0 69 initialize_work();
aoqi@0 70 }
aoqi@0 71
aoqi@0 72 size_t ASPSYoungGen::available_for_expansion() {
aoqi@0 73 size_t current_committed_size = virtual_space()->committed_size();
aoqi@0 74 assert((gen_size_limit() >= current_committed_size),
aoqi@0 75 "generation size limit is wrong");
aoqi@0 76 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
aoqi@0 77 size_t result = gen_size_limit() - current_committed_size;
aoqi@0 78 size_t result_aligned = align_size_down(result, heap->generation_alignment());
aoqi@0 79 return result_aligned;
aoqi@0 80 }
aoqi@0 81
aoqi@0 82 // Return the number of bytes the young gen is willing give up.
aoqi@0 83 //
aoqi@0 84 // Future implementations could check the survivors and if to_space is in the
aoqi@0 85 // right place (below from_space), take a chunk from to_space.
aoqi@0 86 size_t ASPSYoungGen::available_for_contraction() {
aoqi@0 87 size_t uncommitted_bytes = virtual_space()->uncommitted_size();
aoqi@0 88 if (uncommitted_bytes != 0) {
aoqi@0 89 return uncommitted_bytes;
aoqi@0 90 }
aoqi@0 91
aoqi@0 92 if (eden_space()->is_empty()) {
aoqi@0 93 // Respect the minimum size for eden and for the young gen as a whole.
aoqi@0 94 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
aoqi@0 95 const size_t eden_alignment = heap->space_alignment();
aoqi@0 96 const size_t gen_alignment = heap->generation_alignment();
aoqi@0 97
aoqi@0 98 assert(eden_space()->capacity_in_bytes() >= eden_alignment,
aoqi@0 99 "Alignment is wrong");
aoqi@0 100 size_t eden_avail = eden_space()->capacity_in_bytes() - eden_alignment;
aoqi@0 101 eden_avail = align_size_down(eden_avail, gen_alignment);
aoqi@0 102
aoqi@0 103 assert(virtual_space()->committed_size() >= min_gen_size(),
aoqi@0 104 "minimum gen size is wrong");
aoqi@0 105 size_t gen_avail = virtual_space()->committed_size() - min_gen_size();
aoqi@0 106 assert(virtual_space()->is_aligned(gen_avail), "not aligned");
aoqi@0 107
aoqi@0 108 const size_t max_contraction = MIN2(eden_avail, gen_avail);
aoqi@0 109 // See comment for ASPSOldGen::available_for_contraction()
aoqi@0 110 // for reasons the "increment" fraction is used.
aoqi@0 111 PSAdaptiveSizePolicy* policy = heap->size_policy();
aoqi@0 112 size_t result = policy->eden_increment_aligned_down(max_contraction);
aoqi@0 113 size_t result_aligned = align_size_down(result, gen_alignment);
aoqi@0 114 if (PrintAdaptiveSizePolicy && Verbose) {
aoqi@0 115 gclog_or_tty->print_cr("ASPSYoungGen::available_for_contraction: " SIZE_FORMAT " K",
aoqi@0 116 result_aligned/K);
aoqi@0 117 gclog_or_tty->print_cr(" max_contraction " SIZE_FORMAT " K", max_contraction/K);
aoqi@0 118 gclog_or_tty->print_cr(" eden_avail " SIZE_FORMAT " K", eden_avail/K);
aoqi@0 119 gclog_or_tty->print_cr(" gen_avail " SIZE_FORMAT " K", gen_avail/K);
aoqi@0 120 }
aoqi@0 121 return result_aligned;
aoqi@0 122 }
aoqi@0 123
aoqi@0 124 return 0;
aoqi@0 125 }
aoqi@0 126
aoqi@0 127 // The current implementation only considers to the end of eden.
aoqi@0 128 // If to_space is below from_space, to_space is not considered.
aoqi@0 129 // to_space can be.
aoqi@0 130 size_t ASPSYoungGen::available_to_live() {
aoqi@0 131 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
aoqi@0 132 const size_t alignment = heap->space_alignment();
aoqi@0 133
aoqi@0 134 // Include any space that is committed but is not in eden.
aoqi@0 135 size_t available = pointer_delta(eden_space()->bottom(),
aoqi@0 136 virtual_space()->low(),
aoqi@0 137 sizeof(char));
aoqi@0 138
aoqi@0 139 const size_t eden_capacity = eden_space()->capacity_in_bytes();
aoqi@0 140 if (eden_space()->is_empty() && eden_capacity > alignment) {
aoqi@0 141 available += eden_capacity - alignment;
aoqi@0 142 }
aoqi@0 143 return available;
aoqi@0 144 }
aoqi@0 145
aoqi@0 146 // Similar to PSYoungGen::resize_generation() but
aoqi@0 147 // allows sum of eden_size and 2 * survivor_size to exceed _max_gen_size
aoqi@0 148 // expands at the low end of the virtual space
aoqi@0 149 // moves the boundary between the generations in order to expand
aoqi@0 150 // some additional diagnostics
aoqi@0 151 // If no additional changes are required, this can be deleted
aoqi@0 152 // and the changes factored back into PSYoungGen::resize_generation().
aoqi@0 153 bool ASPSYoungGen::resize_generation(size_t eden_size, size_t survivor_size) {
aoqi@0 154 const size_t alignment = virtual_space()->alignment();
aoqi@0 155 size_t orig_size = virtual_space()->committed_size();
aoqi@0 156 bool size_changed = false;
aoqi@0 157
aoqi@0 158 // There used to be a guarantee here that
aoqi@0 159 // (eden_size + 2*survivor_size) <= _max_gen_size
aoqi@0 160 // This requirement is enforced by the calculation of desired_size
aoqi@0 161 // below. It may not be true on entry since the size of the
aoqi@0 162 // eden_size is no bounded by the generation size.
aoqi@0 163
aoqi@0 164 assert(max_size() == reserved().byte_size(), "max gen size problem?");
aoqi@0 165 assert(min_gen_size() <= orig_size && orig_size <= max_size(),
aoqi@0 166 "just checking");
aoqi@0 167
aoqi@0 168 // Adjust new generation size
aoqi@0 169 const size_t eden_plus_survivors =
aoqi@0 170 align_size_up(eden_size + 2 * survivor_size, alignment);
aoqi@0 171 size_t desired_size = MAX2(MIN2(eden_plus_survivors, gen_size_limit()),
aoqi@0 172 min_gen_size());
aoqi@0 173 assert(desired_size <= gen_size_limit(), "just checking");
aoqi@0 174
aoqi@0 175 if (desired_size > orig_size) {
aoqi@0 176 // Grow the generation
aoqi@0 177 size_t change = desired_size - orig_size;
aoqi@0 178 HeapWord* prev_low = (HeapWord*) virtual_space()->low();
aoqi@0 179 if (!virtual_space()->expand_by(change)) {
aoqi@0 180 return false;
aoqi@0 181 }
aoqi@0 182 if (ZapUnusedHeapArea) {
aoqi@0 183 // Mangle newly committed space immediately because it
aoqi@0 184 // can be done here more simply that after the new
aoqi@0 185 // spaces have been computed.
aoqi@0 186 HeapWord* new_low = (HeapWord*) virtual_space()->low();
aoqi@0 187 assert(new_low < prev_low, "Did not grow");
aoqi@0 188
aoqi@0 189 MemRegion mangle_region(new_low, prev_low);
aoqi@0 190 SpaceMangler::mangle_region(mangle_region);
aoqi@0 191 }
aoqi@0 192 size_changed = true;
aoqi@0 193 } else if (desired_size < orig_size) {
aoqi@0 194 size_t desired_change = orig_size - desired_size;
aoqi@0 195
aoqi@0 196 // How much is available for shrinking.
aoqi@0 197 size_t available_bytes = limit_gen_shrink(desired_change);
aoqi@0 198 size_t change = MIN2(desired_change, available_bytes);
aoqi@0 199 virtual_space()->shrink_by(change);
aoqi@0 200 size_changed = true;
aoqi@0 201 } else {
aoqi@0 202 if (Verbose && PrintGC) {
aoqi@0 203 if (orig_size == gen_size_limit()) {
aoqi@0 204 gclog_or_tty->print_cr("ASPSYoung generation size at maximum: "
aoqi@0 205 SIZE_FORMAT "K", orig_size/K);
aoqi@0 206 } else if (orig_size == min_gen_size()) {
aoqi@0 207 gclog_or_tty->print_cr("ASPSYoung generation size at minium: "
aoqi@0 208 SIZE_FORMAT "K", orig_size/K);
aoqi@0 209 }
aoqi@0 210 }
aoqi@0 211 }
aoqi@0 212
aoqi@0 213 if (size_changed) {
aoqi@0 214 reset_after_change();
aoqi@0 215 if (Verbose && PrintGC) {
aoqi@0 216 size_t current_size = virtual_space()->committed_size();
aoqi@0 217 gclog_or_tty->print_cr("ASPSYoung generation size changed: "
aoqi@0 218 SIZE_FORMAT "K->" SIZE_FORMAT "K",
aoqi@0 219 orig_size/K, current_size/K);
aoqi@0 220 }
aoqi@0 221 }
aoqi@0 222
aoqi@0 223 guarantee(eden_plus_survivors <= virtual_space()->committed_size() ||
aoqi@0 224 virtual_space()->committed_size() == max_size(), "Sanity");
aoqi@0 225
aoqi@0 226 return true;
aoqi@0 227 }
aoqi@0 228
aoqi@0 229 // Similar to PSYoungGen::resize_spaces() but
aoqi@0 230 // eden always starts at the low end of the committed virtual space
aoqi@0 231 // current implementation does not allow holes between the spaces
aoqi@0 232 // _young_generation_boundary has to be reset because it changes.
aoqi@0 233 // so additional verification
aoqi@0 234
aoqi@0 235 void ASPSYoungGen::resize_spaces(size_t requested_eden_size,
aoqi@0 236 size_t requested_survivor_size) {
aoqi@0 237 assert(UseAdaptiveSizePolicy, "sanity check");
aoqi@0 238 assert(requested_eden_size > 0 && requested_survivor_size > 0,
aoqi@0 239 "just checking");
aoqi@0 240
aoqi@0 241 space_invariants();
aoqi@0 242
aoqi@0 243 // We require eden and to space to be empty
aoqi@0 244 if ((!eden_space()->is_empty()) || (!to_space()->is_empty())) {
aoqi@0 245 return;
aoqi@0 246 }
aoqi@0 247
aoqi@0 248 if (PrintAdaptiveSizePolicy && Verbose) {
aoqi@0 249 gclog_or_tty->print_cr("PSYoungGen::resize_spaces(requested_eden_size: "
aoqi@0 250 SIZE_FORMAT
aoqi@0 251 ", requested_survivor_size: " SIZE_FORMAT ")",
aoqi@0 252 requested_eden_size, requested_survivor_size);
aoqi@0 253 gclog_or_tty->print_cr(" eden: [" PTR_FORMAT ".." PTR_FORMAT ") "
aoqi@0 254 SIZE_FORMAT,
aoqi@0 255 p2i(eden_space()->bottom()),
aoqi@0 256 p2i(eden_space()->end()),
aoqi@0 257 pointer_delta(eden_space()->end(),
aoqi@0 258 eden_space()->bottom(),
aoqi@0 259 sizeof(char)));
aoqi@0 260 gclog_or_tty->print_cr(" from: [" PTR_FORMAT ".." PTR_FORMAT ") "
aoqi@0 261 SIZE_FORMAT,
aoqi@0 262 p2i(from_space()->bottom()),
aoqi@0 263 p2i(from_space()->end()),
aoqi@0 264 pointer_delta(from_space()->end(),
aoqi@0 265 from_space()->bottom(),
aoqi@0 266 sizeof(char)));
aoqi@0 267 gclog_or_tty->print_cr(" to: [" PTR_FORMAT ".." PTR_FORMAT ") "
aoqi@0 268 SIZE_FORMAT,
aoqi@0 269 p2i(to_space()->bottom()),
aoqi@0 270 p2i(to_space()->end()),
aoqi@0 271 pointer_delta( to_space()->end(),
aoqi@0 272 to_space()->bottom(),
aoqi@0 273 sizeof(char)));
aoqi@0 274 }
aoqi@0 275
aoqi@0 276 // There's nothing to do if the new sizes are the same as the current
aoqi@0 277 if (requested_survivor_size == to_space()->capacity_in_bytes() &&
aoqi@0 278 requested_survivor_size == from_space()->capacity_in_bytes() &&
aoqi@0 279 requested_eden_size == eden_space()->capacity_in_bytes()) {
aoqi@0 280 if (PrintAdaptiveSizePolicy && Verbose) {
aoqi@0 281 gclog_or_tty->print_cr(" capacities are the right sizes, returning");
aoqi@0 282 }
aoqi@0 283 return;
aoqi@0 284 }
aoqi@0 285
aoqi@0 286 char* eden_start = (char*)virtual_space()->low();
aoqi@0 287 char* eden_end = (char*)eden_space()->end();
aoqi@0 288 char* from_start = (char*)from_space()->bottom();
aoqi@0 289 char* from_end = (char*)from_space()->end();
aoqi@0 290 char* to_start = (char*)to_space()->bottom();
aoqi@0 291 char* to_end = (char*)to_space()->end();
aoqi@0 292
aoqi@0 293 assert(eden_start < from_start, "Cannot push into from_space");
aoqi@0 294
aoqi@0 295 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
aoqi@0 296 const size_t alignment = heap->space_alignment();
aoqi@0 297 const bool maintain_minimum =
aoqi@0 298 (requested_eden_size + 2 * requested_survivor_size) <= min_gen_size();
aoqi@0 299
aoqi@0 300 bool eden_from_to_order = from_start < to_start;
aoqi@0 301 // Check whether from space is below to space
aoqi@0 302 if (eden_from_to_order) {
aoqi@0 303 // Eden, from, to
aoqi@0 304
aoqi@0 305 if (PrintAdaptiveSizePolicy && Verbose) {
aoqi@0 306 gclog_or_tty->print_cr(" Eden, from, to:");
aoqi@0 307 }
aoqi@0 308
aoqi@0 309 // Set eden
aoqi@0 310 // "requested_eden_size" is a goal for the size of eden
aoqi@0 311 // and may not be attainable. "eden_size" below is
aoqi@0 312 // calculated based on the location of from-space and
aoqi@0 313 // the goal for the size of eden. from-space is
aoqi@0 314 // fixed in place because it contains live data.
aoqi@0 315 // The calculation is done this way to avoid 32bit
aoqi@0 316 // overflow (i.e., eden_start + requested_eden_size
aoqi@0 317 // may too large for representation in 32bits).
aoqi@0 318 size_t eden_size;
aoqi@0 319 if (maintain_minimum) {
aoqi@0 320 // Only make eden larger than the requested size if
aoqi@0 321 // the minimum size of the generation has to be maintained.
aoqi@0 322 // This could be done in general but policy at a higher
aoqi@0 323 // level is determining a requested size for eden and that
aoqi@0 324 // should be honored unless there is a fundamental reason.
aoqi@0 325 eden_size = pointer_delta(from_start,
aoqi@0 326 eden_start,
aoqi@0 327 sizeof(char));
aoqi@0 328 } else {
aoqi@0 329 eden_size = MIN2(requested_eden_size,
aoqi@0 330 pointer_delta(from_start, eden_start, sizeof(char)));
aoqi@0 331 }
aoqi@0 332
aoqi@0 333 eden_end = eden_start + eden_size;
aoqi@0 334 assert(eden_end >= eden_start, "addition overflowed");
aoqi@0 335
aoqi@0 336 // To may resize into from space as long as it is clear of live data.
aoqi@0 337 // From space must remain page aligned, though, so we need to do some
aoqi@0 338 // extra calculations.
aoqi@0 339
aoqi@0 340 // First calculate an optimal to-space
aoqi@0 341 to_end = (char*)virtual_space()->high();
aoqi@0 342 to_start = (char*)pointer_delta(to_end,
aoqi@0 343 (char*)requested_survivor_size,
aoqi@0 344 sizeof(char));
aoqi@0 345
aoqi@0 346 // Does the optimal to-space overlap from-space?
aoqi@0 347 if (to_start < (char*)from_space()->end()) {
aoqi@0 348 assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
aoqi@0 349
aoqi@0 350 // Calculate the minimum offset possible for from_end
aoqi@0 351 size_t from_size =
aoqi@0 352 pointer_delta(from_space()->top(), from_start, sizeof(char));
aoqi@0 353
aoqi@0 354 // Should we be in this method if from_space is empty? Why not the set_space method? FIX ME!
aoqi@0 355 if (from_size == 0) {
aoqi@0 356 from_size = alignment;
aoqi@0 357 } else {
aoqi@0 358 from_size = align_size_up(from_size, alignment);
aoqi@0 359 }
aoqi@0 360
aoqi@0 361 from_end = from_start + from_size;
aoqi@0 362 assert(from_end > from_start, "addition overflow or from_size problem");
aoqi@0 363
aoqi@0 364 guarantee(from_end <= (char*)from_space()->end(),
aoqi@0 365 "from_end moved to the right");
aoqi@0 366
aoqi@0 367 // Now update to_start with the new from_end
aoqi@0 368 to_start = MAX2(from_end, to_start);
aoqi@0 369 }
aoqi@0 370
aoqi@0 371 guarantee(to_start != to_end, "to space is zero sized");
aoqi@0 372
aoqi@0 373 if (PrintAdaptiveSizePolicy && Verbose) {
aoqi@0 374 gclog_or_tty->print_cr(" [eden_start .. eden_end): "
aoqi@0 375 "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT,
aoqi@0 376 p2i(eden_start),
aoqi@0 377 p2i(eden_end),
aoqi@0 378 pointer_delta(eden_end, eden_start, sizeof(char)));
aoqi@0 379 gclog_or_tty->print_cr(" [from_start .. from_end): "
aoqi@0 380 "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT,
aoqi@0 381 p2i(from_start),
aoqi@0 382 p2i(from_end),
aoqi@0 383 pointer_delta(from_end, from_start, sizeof(char)));
aoqi@0 384 gclog_or_tty->print_cr(" [ to_start .. to_end): "
aoqi@0 385 "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT,
aoqi@0 386 p2i(to_start),
aoqi@0 387 p2i(to_end),
aoqi@0 388 pointer_delta( to_end, to_start, sizeof(char)));
aoqi@0 389 }
aoqi@0 390 } else {
aoqi@0 391 // Eden, to, from
aoqi@0 392 if (PrintAdaptiveSizePolicy && Verbose) {
aoqi@0 393 gclog_or_tty->print_cr(" Eden, to, from:");
aoqi@0 394 }
aoqi@0 395
aoqi@0 396 // To space gets priority over eden resizing. Note that we position
aoqi@0 397 // to space as if we were able to resize from space, even though from
aoqi@0 398 // space is not modified.
aoqi@0 399 // Giving eden priority was tried and gave poorer performance.
aoqi@0 400 to_end = (char*)pointer_delta(virtual_space()->high(),
aoqi@0 401 (char*)requested_survivor_size,
aoqi@0 402 sizeof(char));
aoqi@0 403 to_end = MIN2(to_end, from_start);
aoqi@0 404 to_start = (char*)pointer_delta(to_end, (char*)requested_survivor_size,
aoqi@0 405 sizeof(char));
aoqi@0 406 // if the space sizes are to be increased by several times then
aoqi@0 407 // 'to_start' will point beyond the young generation. In this case
aoqi@0 408 // 'to_start' should be adjusted.
aoqi@0 409 to_start = MAX2(to_start, eden_start + alignment);
aoqi@0 410
aoqi@0 411 // Compute how big eden can be, then adjust end.
aoqi@0 412 // See comments above on calculating eden_end.
aoqi@0 413 size_t eden_size;
aoqi@0 414 if (maintain_minimum) {
aoqi@0 415 eden_size = pointer_delta(to_start, eden_start, sizeof(char));
aoqi@0 416 } else {
aoqi@0 417 eden_size = MIN2(requested_eden_size,
aoqi@0 418 pointer_delta(to_start, eden_start, sizeof(char)));
aoqi@0 419 }
aoqi@0 420 eden_end = eden_start + eden_size;
aoqi@0 421 assert(eden_end >= eden_start, "addition overflowed");
aoqi@0 422
aoqi@0 423 // Don't let eden shrink down to 0 or less.
aoqi@0 424 eden_end = MAX2(eden_end, eden_start + alignment);
aoqi@0 425 to_start = MAX2(to_start, eden_end);
aoqi@0 426
aoqi@0 427 if (PrintAdaptiveSizePolicy && Verbose) {
aoqi@0 428 gclog_or_tty->print_cr(" [eden_start .. eden_end): "
aoqi@0 429 "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT,
aoqi@0 430 p2i(eden_start),
aoqi@0 431 p2i(eden_end),
aoqi@0 432 pointer_delta(eden_end, eden_start, sizeof(char)));
aoqi@0 433 gclog_or_tty->print_cr(" [ to_start .. to_end): "
aoqi@0 434 "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT,
aoqi@0 435 p2i(to_start),
aoqi@0 436 p2i(to_end),
aoqi@0 437 pointer_delta( to_end, to_start, sizeof(char)));
aoqi@0 438 gclog_or_tty->print_cr(" [from_start .. from_end): "
aoqi@0 439 "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT,
aoqi@0 440 p2i(from_start),
aoqi@0 441 p2i(from_end),
aoqi@0 442 pointer_delta(from_end, from_start, sizeof(char)));
aoqi@0 443 }
aoqi@0 444 }
aoqi@0 445
aoqi@0 446
aoqi@0 447 guarantee((HeapWord*)from_start <= from_space()->bottom(),
aoqi@0 448 "from start moved to the right");
aoqi@0 449 guarantee((HeapWord*)from_end >= from_space()->top(),
aoqi@0 450 "from end moved into live data");
aoqi@0 451 assert(is_object_aligned((intptr_t)eden_start), "checking alignment");
aoqi@0 452 assert(is_object_aligned((intptr_t)from_start), "checking alignment");
aoqi@0 453 assert(is_object_aligned((intptr_t)to_start), "checking alignment");
aoqi@0 454
aoqi@0 455 MemRegion edenMR((HeapWord*)eden_start, (HeapWord*)eden_end);
aoqi@0 456 MemRegion toMR ((HeapWord*)to_start, (HeapWord*)to_end);
aoqi@0 457 MemRegion fromMR((HeapWord*)from_start, (HeapWord*)from_end);
aoqi@0 458
aoqi@0 459 // Let's make sure the call to initialize doesn't reset "top"!
aoqi@0 460 DEBUG_ONLY(HeapWord* old_from_top = from_space()->top();)
aoqi@0 461
aoqi@0 462 // For PrintAdaptiveSizePolicy block below
aoqi@0 463 size_t old_from = from_space()->capacity_in_bytes();
aoqi@0 464 size_t old_to = to_space()->capacity_in_bytes();
aoqi@0 465
aoqi@0 466 if (ZapUnusedHeapArea) {
aoqi@0 467 // NUMA is a special case because a numa space is not mangled
aoqi@0 468 // in order to not prematurely bind its address to memory to
aoqi@0 469 // the wrong memory (i.e., don't want the GC thread to first
aoqi@0 470 // touch the memory). The survivor spaces are not numa
aoqi@0 471 // spaces and are mangled.
aoqi@0 472 if (UseNUMA) {
aoqi@0 473 if (eden_from_to_order) {
aoqi@0 474 mangle_survivors(from_space(), fromMR, to_space(), toMR);
aoqi@0 475 } else {
aoqi@0 476 mangle_survivors(to_space(), toMR, from_space(), fromMR);
aoqi@0 477 }
aoqi@0 478 }
aoqi@0 479
aoqi@0 480 // If not mangling the spaces, do some checking to verify that
aoqi@0 481 // the spaces are already mangled.
aoqi@0 482 // The spaces should be correctly mangled at this point so
aoqi@0 483 // do some checking here. Note that they are not being mangled
aoqi@0 484 // in the calls to initialize().
aoqi@0 485 // Must check mangling before the spaces are reshaped. Otherwise,
aoqi@0 486 // the bottom or end of one space may have moved into an area
aoqi@0 487 // covered by another space and a failure of the check may
aoqi@0 488 // not correctly indicate which space is not properly mangled.
aoqi@0 489
aoqi@0 490 HeapWord* limit = (HeapWord*) virtual_space()->high();
aoqi@0 491 eden_space()->check_mangled_unused_area(limit);
aoqi@0 492 from_space()->check_mangled_unused_area(limit);
aoqi@0 493 to_space()->check_mangled_unused_area(limit);
aoqi@0 494 }
aoqi@0 495 // When an existing space is being initialized, it is not
aoqi@0 496 // mangled because the space has been previously mangled.
aoqi@0 497 eden_space()->initialize(edenMR,
aoqi@0 498 SpaceDecorator::Clear,
aoqi@0 499 SpaceDecorator::DontMangle);
aoqi@0 500 to_space()->initialize(toMR,
aoqi@0 501 SpaceDecorator::Clear,
aoqi@0 502 SpaceDecorator::DontMangle);
aoqi@0 503 from_space()->initialize(fromMR,
aoqi@0 504 SpaceDecorator::DontClear,
aoqi@0 505 SpaceDecorator::DontMangle);
aoqi@0 506
aoqi@0 507 PSScavenge::set_young_generation_boundary(eden_space()->bottom());
aoqi@0 508
aoqi@0 509 assert(from_space()->top() == old_from_top, "from top changed!");
aoqi@0 510
aoqi@0 511 if (PrintAdaptiveSizePolicy) {
aoqi@0 512 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
aoqi@0 513 assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
aoqi@0 514
aoqi@0 515 gclog_or_tty->print("AdaptiveSizePolicy::survivor space sizes: "
aoqi@0 516 "collection: %d "
aoqi@0 517 "(" SIZE_FORMAT ", " SIZE_FORMAT ") -> "
aoqi@0 518 "(" SIZE_FORMAT ", " SIZE_FORMAT ") ",
aoqi@0 519 heap->total_collections(),
aoqi@0 520 old_from, old_to,
aoqi@0 521 from_space()->capacity_in_bytes(),
aoqi@0 522 to_space()->capacity_in_bytes());
aoqi@0 523 gclog_or_tty->cr();
aoqi@0 524 }
aoqi@0 525 space_invariants();
aoqi@0 526 }
aoqi@0 527 void ASPSYoungGen::reset_after_change() {
aoqi@0 528 assert_locked_or_safepoint(Heap_lock);
aoqi@0 529
aoqi@0 530 _reserved = MemRegion((HeapWord*)virtual_space()->low_boundary(),
aoqi@0 531 (HeapWord*)virtual_space()->high_boundary());
aoqi@0 532 PSScavenge::reference_processor()->set_span(_reserved);
aoqi@0 533
aoqi@0 534 HeapWord* new_eden_bottom = (HeapWord*)virtual_space()->low();
aoqi@0 535 HeapWord* eden_bottom = eden_space()->bottom();
aoqi@0 536 if (new_eden_bottom != eden_bottom) {
aoqi@0 537 MemRegion eden_mr(new_eden_bottom, eden_space()->end());
aoqi@0 538 eden_space()->initialize(eden_mr,
aoqi@0 539 SpaceDecorator::Clear,
aoqi@0 540 SpaceDecorator::Mangle);
aoqi@0 541 PSScavenge::set_young_generation_boundary(eden_space()->bottom());
aoqi@0 542 }
aoqi@0 543 MemRegion cmr((HeapWord*)virtual_space()->low(),
aoqi@0 544 (HeapWord*)virtual_space()->high());
aoqi@0 545 Universe::heap()->barrier_set()->resize_covered_region(cmr);
aoqi@0 546
aoqi@0 547 space_invariants();
aoqi@0 548 }

mercurial