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

Mon, 12 Aug 2019 18:30:40 +0300

author
apetushkov
date
Mon, 12 Aug 2019 18:30:40 +0300
changeset 9858
b985cbb00e68
parent 6680
78bbf4d43a14
child 6876
710a3c8b516e
permissions
-rw-r--r--

8223147: JFR Backport
8199712: Flight Recorder
8203346: JFR: Inconsistent signature of jfr_add_string_constant
8195817: JFR.stop should require name of recording
8195818: JFR.start should increase autogenerated name by one
8195819: Remove recording=x from jcmd JFR.check output
8203921: JFR thread sampling is missing fixes from JDK-8194552
8203929: Limit amount of data for JFR.dump
8203664: JFR start failure after AppCDS archive created with JFR StartFlightRecording
8003209: JFR events for network utilization
8207392: [PPC64] Implement JFR profiling
8202835: jfr/event/os/TestSystemProcess.java fails on missing events
Summary: Backport JFR from JDK11. Initial integration
Reviewed-by: neugens

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

mercurial