94 ParallelScavengeHeap* heap = ParallelScavengeHeap::heap(); 95 const size_t eden_alignment = heap->space_alignment(); 96 const size_t gen_alignment = heap->generation_alignment(); 97 98 assert(eden_space()->capacity_in_bytes() >= eden_alignment, 99 "Alignment is wrong"); 100 size_t eden_avail = eden_space()->capacity_in_bytes() - eden_alignment; 101 eden_avail = align_size_down(eden_avail, gen_alignment); 102 103 assert(virtual_space()->committed_size() >= min_gen_size(), 104 "minimum gen size is wrong"); 105 size_t gen_avail = virtual_space()->committed_size() - min_gen_size(); 106 assert(virtual_space()->is_aligned(gen_avail), "not aligned"); 107 108 const size_t max_contraction = MIN2(eden_avail, gen_avail); 109 // See comment for ASPSOldGen::available_for_contraction() 110 // for reasons the "increment" fraction is used. 111 PSAdaptiveSizePolicy* policy = heap->size_policy(); 112 size_t result = policy->eden_increment_aligned_down(max_contraction); 113 size_t result_aligned = align_size_down(result, gen_alignment); 114 if (PrintAdaptiveSizePolicy && Verbose) { 115 gclog_or_tty->print_cr("ASPSYoungGen::available_for_contraction: " SIZE_FORMAT " K", 116 result_aligned/K); 117 gclog_or_tty->print_cr(" max_contraction " SIZE_FORMAT " K", max_contraction/K); 118 gclog_or_tty->print_cr(" eden_avail " SIZE_FORMAT " K", eden_avail/K); 119 gclog_or_tty->print_cr(" gen_avail " SIZE_FORMAT " K", gen_avail/K); 120 } 121 return result_aligned; 122 } 123 124 return 0; 125 } 126 127 // The current implementation only considers to the end of eden. 128 // If to_space is below from_space, to_space is not considered. 129 // to_space can be. 130 size_t ASPSYoungGen::available_to_live() { 131 ParallelScavengeHeap* heap = ParallelScavengeHeap::heap(); 132 const size_t alignment = heap->space_alignment(); 133 134 // Include any space that is committed but is not in eden. 135 size_t available = pointer_delta(eden_space()->bottom(), 136 virtual_space()->low(), 137 sizeof(char)); 138 139 const size_t eden_capacity = eden_space()->capacity_in_bytes(); 140 if (eden_space()->is_empty() && eden_capacity > alignment) { 182 if (ZapUnusedHeapArea) { 183 // Mangle newly committed space immediately because it 184 // can be done here more simply that after the new 185 // spaces have been computed. 186 HeapWord* new_low = (HeapWord*) virtual_space()->low(); 187 assert(new_low < prev_low, "Did not grow"); 188 189 MemRegion mangle_region(new_low, prev_low); 190 SpaceMangler::mangle_region(mangle_region); 191 } 192 size_changed = true; 193 } else if (desired_size < orig_size) { 194 size_t desired_change = orig_size - desired_size; 195 196 // How much is available for shrinking. 197 size_t available_bytes = limit_gen_shrink(desired_change); 198 size_t change = MIN2(desired_change, available_bytes); 199 virtual_space()->shrink_by(change); 200 size_changed = true; 201 } else { 202 if (Verbose && PrintGC) { 203 if (orig_size == gen_size_limit()) { 204 gclog_or_tty->print_cr("ASPSYoung generation size at maximum: " 205 SIZE_FORMAT "K", orig_size/K); 206 } else if (orig_size == min_gen_size()) { 207 gclog_or_tty->print_cr("ASPSYoung generation size at minium: " 208 SIZE_FORMAT "K", orig_size/K); 209 } 210 } 211 } 212 213 if (size_changed) { 214 reset_after_change(); 215 if (Verbose && PrintGC) { 216 size_t current_size = virtual_space()->committed_size(); 217 gclog_or_tty->print_cr("ASPSYoung generation size changed: " 218 SIZE_FORMAT "K->" SIZE_FORMAT "K", 219 orig_size/K, current_size/K); 220 } 221 } 222 223 guarantee(eden_plus_survivors <= virtual_space()->committed_size() || 224 virtual_space()->committed_size() == max_size(), "Sanity"); 225 226 return true; 227 } 228 229 // Similar to PSYoungGen::resize_spaces() but 230 // eden always starts at the low end of the committed virtual space 231 // current implementation does not allow holes between the spaces 232 // _young_generation_boundary has to be reset because it changes. 233 // so additional verification 234 235 void ASPSYoungGen::resize_spaces(size_t requested_eden_size, 236 size_t requested_survivor_size) { 237 assert(UseAdaptiveSizePolicy, "sanity check"); 238 assert(requested_eden_size > 0 && requested_survivor_size > 0, 239 "just checking"); 240 241 space_invariants(); 242 243 // We require eden and to space to be empty 244 if ((!eden_space()->is_empty()) || (!to_space()->is_empty())) { 245 return; 246 } 247 248 if (PrintAdaptiveSizePolicy && Verbose) { 249 gclog_or_tty->print_cr("PSYoungGen::resize_spaces(requested_eden_size: " 250 SIZE_FORMAT 251 ", requested_survivor_size: " SIZE_FORMAT ")", 252 requested_eden_size, requested_survivor_size); 253 gclog_or_tty->print_cr(" eden: [" PTR_FORMAT ".." PTR_FORMAT ") " 254 SIZE_FORMAT, 255 p2i(eden_space()->bottom()), 256 p2i(eden_space()->end()), 257 pointer_delta(eden_space()->end(), 258 eden_space()->bottom(), 259 sizeof(char))); 260 gclog_or_tty->print_cr(" from: [" PTR_FORMAT ".." PTR_FORMAT ") " 261 SIZE_FORMAT, 262 p2i(from_space()->bottom()), 263 p2i(from_space()->end()), 264 pointer_delta(from_space()->end(), 265 from_space()->bottom(), 266 sizeof(char))); 267 gclog_or_tty->print_cr(" to: [" PTR_FORMAT ".." PTR_FORMAT ") " 268 SIZE_FORMAT, 269 p2i(to_space()->bottom()), 270 p2i(to_space()->end()), 271 pointer_delta( to_space()->end(), 272 to_space()->bottom(), 273 sizeof(char))); 274 } 275 276 // There's nothing to do if the new sizes are the same as the current 277 if (requested_survivor_size == to_space()->capacity_in_bytes() && 278 requested_survivor_size == from_space()->capacity_in_bytes() && 279 requested_eden_size == eden_space()->capacity_in_bytes()) { 280 if (PrintAdaptiveSizePolicy && Verbose) { 281 gclog_or_tty->print_cr(" capacities are the right sizes, returning"); 282 } 283 return; 284 } 285 286 char* eden_start = (char*)virtual_space()->low(); 287 char* eden_end = (char*)eden_space()->end(); 288 char* from_start = (char*)from_space()->bottom(); 289 char* from_end = (char*)from_space()->end(); 290 char* to_start = (char*)to_space()->bottom(); 291 char* to_end = (char*)to_space()->end(); 292 293 assert(eden_start < from_start, "Cannot push into from_space"); 294 295 ParallelScavengeHeap* heap = ParallelScavengeHeap::heap(); 296 const size_t alignment = heap->space_alignment(); 297 const bool maintain_minimum = 298 (requested_eden_size + 2 * requested_survivor_size) <= min_gen_size(); 299 300 bool eden_from_to_order = from_start < to_start; 301 // Check whether from space is below to space 302 if (eden_from_to_order) { 303 // Eden, from, to 304 305 if (PrintAdaptiveSizePolicy && Verbose) { 306 gclog_or_tty->print_cr(" Eden, from, to:"); 307 } 308 309 // Set eden 310 // "requested_eden_size" is a goal for the size of eden 311 // and may not be attainable. "eden_size" below is 312 // calculated based on the location of from-space and 313 // the goal for the size of eden. from-space is 314 // fixed in place because it contains live data. 315 // The calculation is done this way to avoid 32bit 316 // overflow (i.e., eden_start + requested_eden_size 317 // may too large for representation in 32bits). 318 size_t eden_size; 319 if (maintain_minimum) { 320 // Only make eden larger than the requested size if 321 // the minimum size of the generation has to be maintained. 322 // This could be done in general but policy at a higher 323 // level is determining a requested size for eden and that 324 // should be honored unless there is a fundamental reason. 325 eden_size = pointer_delta(from_start, 326 eden_start, 327 sizeof(char)); 351 352 // Should we be in this method if from_space is empty? Why not the set_space method? FIX ME! 353 if (from_size == 0) { 354 from_size = alignment; 355 } else { 356 from_size = align_size_up(from_size, alignment); 357 } 358 359 from_end = from_start + from_size; 360 assert(from_end > from_start, "addition overflow or from_size problem"); 361 362 guarantee(from_end <= (char*)from_space()->end(), 363 "from_end moved to the right"); 364 365 // Now update to_start with the new from_end 366 to_start = MAX2(from_end, to_start); 367 } 368 369 guarantee(to_start != to_end, "to space is zero sized"); 370 371 if (PrintAdaptiveSizePolicy && Verbose) { 372 gclog_or_tty->print_cr(" [eden_start .. eden_end): " 373 "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT, 374 p2i(eden_start), 375 p2i(eden_end), 376 pointer_delta(eden_end, eden_start, sizeof(char))); 377 gclog_or_tty->print_cr(" [from_start .. from_end): " 378 "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT, 379 p2i(from_start), 380 p2i(from_end), 381 pointer_delta(from_end, from_start, sizeof(char))); 382 gclog_or_tty->print_cr(" [ to_start .. to_end): " 383 "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT, 384 p2i(to_start), 385 p2i(to_end), 386 pointer_delta( to_end, to_start, sizeof(char))); 387 } 388 } else { 389 // Eden, to, from 390 if (PrintAdaptiveSizePolicy && Verbose) { 391 gclog_or_tty->print_cr(" Eden, to, from:"); 392 } 393 394 // To space gets priority over eden resizing. Note that we position 395 // to space as if we were able to resize from space, even though from 396 // space is not modified. 397 // Giving eden priority was tried and gave poorer performance. 398 to_end = (char*)pointer_delta(virtual_space()->high(), 399 (char*)requested_survivor_size, 400 sizeof(char)); 401 to_end = MIN2(to_end, from_start); 402 to_start = (char*)pointer_delta(to_end, (char*)requested_survivor_size, 403 sizeof(char)); 404 // if the space sizes are to be increased by several times then 405 // 'to_start' will point beyond the young generation. In this case 406 // 'to_start' should be adjusted. 407 to_start = MAX2(to_start, eden_start + alignment); 408 409 // Compute how big eden can be, then adjust end. 410 // See comments above on calculating eden_end. 411 size_t eden_size; 412 if (maintain_minimum) { 413 eden_size = pointer_delta(to_start, eden_start, sizeof(char)); 414 } else { 415 eden_size = MIN2(requested_eden_size, 416 pointer_delta(to_start, eden_start, sizeof(char))); 417 } 418 eden_end = eden_start + eden_size; 419 assert(eden_end >= eden_start, "addition overflowed"); 420 421 // Don't let eden shrink down to 0 or less. 422 eden_end = MAX2(eden_end, eden_start + alignment); 423 to_start = MAX2(to_start, eden_end); 424 425 if (PrintAdaptiveSizePolicy && Verbose) { 426 gclog_or_tty->print_cr(" [eden_start .. eden_end): " 427 "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT, 428 p2i(eden_start), 429 p2i(eden_end), 430 pointer_delta(eden_end, eden_start, sizeof(char))); 431 gclog_or_tty->print_cr(" [ to_start .. to_end): " 432 "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT, 433 p2i(to_start), 434 p2i(to_end), 435 pointer_delta( to_end, to_start, sizeof(char))); 436 gclog_or_tty->print_cr(" [from_start .. from_end): " 437 "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT, 438 p2i(from_start), 439 p2i(from_end), 440 pointer_delta(from_end, from_start, sizeof(char))); 441 } 442 } 443 444 445 guarantee((HeapWord*)from_start <= from_space()->bottom(), 446 "from start moved to the right"); 447 guarantee((HeapWord*)from_end >= from_space()->top(), 448 "from end moved into live data"); 449 assert(is_object_aligned((intptr_t)eden_start), "checking alignment"); 450 assert(is_object_aligned((intptr_t)from_start), "checking alignment"); 451 assert(is_object_aligned((intptr_t)to_start), "checking alignment"); 452 453 MemRegion edenMR((HeapWord*)eden_start, (HeapWord*)eden_end); 454 MemRegion toMR ((HeapWord*)to_start, (HeapWord*)to_end); 455 MemRegion fromMR((HeapWord*)from_start, (HeapWord*)from_end); 456 457 // Let's make sure the call to initialize doesn't reset "top"! 458 DEBUG_ONLY(HeapWord* old_from_top = from_space()->top();) 459 460 // For PrintAdaptiveSizePolicy block below 461 size_t old_from = from_space()->capacity_in_bytes(); 462 size_t old_to = to_space()->capacity_in_bytes(); 463 464 if (ZapUnusedHeapArea) { 465 // NUMA is a special case because a numa space is not mangled 466 // in order to not prematurely bind its address to memory to 467 // the wrong memory (i.e., don't want the GC thread to first 468 // touch the memory). The survivor spaces are not numa 469 // spaces and are mangled. 470 if (UseNUMA) { 471 if (eden_from_to_order) { 472 mangle_survivors(from_space(), fromMR, to_space(), toMR); 473 } else { 474 mangle_survivors(to_space(), toMR, from_space(), fromMR); 475 } 476 } 477 478 // If not mangling the spaces, do some checking to verify that 479 // the spaces are already mangled. 480 // The spaces should be correctly mangled at this point so 489 eden_space()->check_mangled_unused_area(limit); 490 from_space()->check_mangled_unused_area(limit); 491 to_space()->check_mangled_unused_area(limit); 492 } 493 // When an existing space is being initialized, it is not 494 // mangled because the space has been previously mangled. 495 eden_space()->initialize(edenMR, 496 SpaceDecorator::Clear, 497 SpaceDecorator::DontMangle); 498 to_space()->initialize(toMR, 499 SpaceDecorator::Clear, 500 SpaceDecorator::DontMangle); 501 from_space()->initialize(fromMR, 502 SpaceDecorator::DontClear, 503 SpaceDecorator::DontMangle); 504 505 PSScavenge::set_young_generation_boundary(eden_space()->bottom()); 506 507 assert(from_space()->top() == old_from_top, "from top changed!"); 508 509 if (PrintAdaptiveSizePolicy) { 510 ParallelScavengeHeap* heap = ParallelScavengeHeap::heap(); 511 gclog_or_tty->print("AdaptiveSizePolicy::survivor space sizes: " 512 "collection: %d " 513 "(" SIZE_FORMAT ", " SIZE_FORMAT ") -> " 514 "(" SIZE_FORMAT ", " SIZE_FORMAT ") ", 515 heap->total_collections(), 516 old_from, old_to, 517 from_space()->capacity_in_bytes(), 518 to_space()->capacity_in_bytes()); 519 gclog_or_tty->cr(); 520 } 521 space_invariants(); 522 } 523 void ASPSYoungGen::reset_after_change() { 524 assert_locked_or_safepoint(Heap_lock); 525 526 _reserved = MemRegion((HeapWord*)virtual_space()->low_boundary(), 527 (HeapWord*)virtual_space()->high_boundary()); 528 PSScavenge::reference_processor()->set_span(_reserved); 529 530 HeapWord* new_eden_bottom = (HeapWord*)virtual_space()->low(); 531 HeapWord* eden_bottom = eden_space()->bottom(); 532 if (new_eden_bottom != eden_bottom) { 533 MemRegion eden_mr(new_eden_bottom, eden_space()->end()); 534 eden_space()->initialize(eden_mr, 535 SpaceDecorator::Clear, 536 SpaceDecorator::Mangle); 537 PSScavenge::set_young_generation_boundary(eden_space()->bottom()); 538 } 539 MemRegion cmr((HeapWord*)virtual_space()->low(), 540 (HeapWord*)virtual_space()->high()); | 94 ParallelScavengeHeap* heap = ParallelScavengeHeap::heap(); 95 const size_t eden_alignment = heap->space_alignment(); 96 const size_t gen_alignment = heap->generation_alignment(); 97 98 assert(eden_space()->capacity_in_bytes() >= eden_alignment, 99 "Alignment is wrong"); 100 size_t eden_avail = eden_space()->capacity_in_bytes() - eden_alignment; 101 eden_avail = align_size_down(eden_avail, gen_alignment); 102 103 assert(virtual_space()->committed_size() >= min_gen_size(), 104 "minimum gen size is wrong"); 105 size_t gen_avail = virtual_space()->committed_size() - min_gen_size(); 106 assert(virtual_space()->is_aligned(gen_avail), "not aligned"); 107 108 const size_t max_contraction = MIN2(eden_avail, gen_avail); 109 // See comment for ASPSOldGen::available_for_contraction() 110 // for reasons the "increment" fraction is used. 111 PSAdaptiveSizePolicy* policy = heap->size_policy(); 112 size_t result = policy->eden_increment_aligned_down(max_contraction); 113 size_t result_aligned = align_size_down(result, gen_alignment); 114 115 log_trace(gc, ergo)("ASPSYoungGen::available_for_contraction: " SIZE_FORMAT " K", result_aligned/K); 116 log_trace(gc, ergo)(" max_contraction " SIZE_FORMAT " K", max_contraction/K); 117 log_trace(gc, ergo)(" eden_avail " SIZE_FORMAT " K", eden_avail/K); 118 log_trace(gc, ergo)(" gen_avail " SIZE_FORMAT " K", gen_avail/K); 119 120 return result_aligned; 121 } 122 123 return 0; 124 } 125 126 // The current implementation only considers to the end of eden. 127 // If to_space is below from_space, to_space is not considered. 128 // to_space can be. 129 size_t ASPSYoungGen::available_to_live() { 130 ParallelScavengeHeap* heap = ParallelScavengeHeap::heap(); 131 const size_t alignment = heap->space_alignment(); 132 133 // Include any space that is committed but is not in eden. 134 size_t available = pointer_delta(eden_space()->bottom(), 135 virtual_space()->low(), 136 sizeof(char)); 137 138 const size_t eden_capacity = eden_space()->capacity_in_bytes(); 139 if (eden_space()->is_empty() && eden_capacity > alignment) { 181 if (ZapUnusedHeapArea) { 182 // Mangle newly committed space immediately because it 183 // can be done here more simply that after the new 184 // spaces have been computed. 185 HeapWord* new_low = (HeapWord*) virtual_space()->low(); 186 assert(new_low < prev_low, "Did not grow"); 187 188 MemRegion mangle_region(new_low, prev_low); 189 SpaceMangler::mangle_region(mangle_region); 190 } 191 size_changed = true; 192 } else if (desired_size < orig_size) { 193 size_t desired_change = orig_size - desired_size; 194 195 // How much is available for shrinking. 196 size_t available_bytes = limit_gen_shrink(desired_change); 197 size_t change = MIN2(desired_change, available_bytes); 198 virtual_space()->shrink_by(change); 199 size_changed = true; 200 } else { 201 if (orig_size == gen_size_limit()) { 202 log_trace(gc)("ASPSYoung generation size at maximum: " SIZE_FORMAT "K", orig_size/K); 203 } else if (orig_size == min_gen_size()) { 204 log_trace(gc)("ASPSYoung generation size at minium: " SIZE_FORMAT "K", orig_size/K); 205 } 206 } 207 208 if (size_changed) { 209 reset_after_change(); 210 log_trace(gc)("ASPSYoung generation size changed: " SIZE_FORMAT "K->" SIZE_FORMAT "K", 211 orig_size/K, virtual_space()->committed_size()/K); 212 } 213 214 guarantee(eden_plus_survivors <= virtual_space()->committed_size() || 215 virtual_space()->committed_size() == max_size(), "Sanity"); 216 217 return true; 218 } 219 220 // Similar to PSYoungGen::resize_spaces() but 221 // eden always starts at the low end of the committed virtual space 222 // current implementation does not allow holes between the spaces 223 // _young_generation_boundary has to be reset because it changes. 224 // so additional verification 225 226 void ASPSYoungGen::resize_spaces(size_t requested_eden_size, 227 size_t requested_survivor_size) { 228 assert(UseAdaptiveSizePolicy, "sanity check"); 229 assert(requested_eden_size > 0 && requested_survivor_size > 0, 230 "just checking"); 231 232 space_invariants(); 233 234 // We require eden and to space to be empty 235 if ((!eden_space()->is_empty()) || (!to_space()->is_empty())) { 236 return; 237 } 238 239 log_trace(gc, ergo)("PSYoungGen::resize_spaces(requested_eden_size: " 240 SIZE_FORMAT 241 ", requested_survivor_size: " SIZE_FORMAT ")", 242 requested_eden_size, requested_survivor_size); 243 log_trace(gc, ergo)(" eden: [" PTR_FORMAT ".." PTR_FORMAT ") " 244 SIZE_FORMAT, 245 p2i(eden_space()->bottom()), 246 p2i(eden_space()->end()), 247 pointer_delta(eden_space()->end(), eden_space()->bottom(), sizeof(char))); 248 log_trace(gc, ergo)(" from: [" PTR_FORMAT ".." PTR_FORMAT ") " 249 SIZE_FORMAT, 250 p2i(from_space()->bottom()), 251 p2i(from_space()->end()), 252 pointer_delta(from_space()->end(), from_space()->bottom(), sizeof(char))); 253 log_trace(gc, ergo)(" to: [" PTR_FORMAT ".." PTR_FORMAT ") " 254 SIZE_FORMAT, 255 p2i(to_space()->bottom()), 256 p2i(to_space()->end()), 257 pointer_delta( to_space()->end(), to_space()->bottom(), sizeof(char))); 258 259 // There's nothing to do if the new sizes are the same as the current 260 if (requested_survivor_size == to_space()->capacity_in_bytes() && 261 requested_survivor_size == from_space()->capacity_in_bytes() && 262 requested_eden_size == eden_space()->capacity_in_bytes()) { 263 log_trace(gc, ergo)(" capacities are the right sizes, returning"); 264 return; 265 } 266 267 char* eden_start = (char*)virtual_space()->low(); 268 char* eden_end = (char*)eden_space()->end(); 269 char* from_start = (char*)from_space()->bottom(); 270 char* from_end = (char*)from_space()->end(); 271 char* to_start = (char*)to_space()->bottom(); 272 char* to_end = (char*)to_space()->end(); 273 274 assert(eden_start < from_start, "Cannot push into from_space"); 275 276 ParallelScavengeHeap* heap = ParallelScavengeHeap::heap(); 277 const size_t alignment = heap->space_alignment(); 278 const bool maintain_minimum = 279 (requested_eden_size + 2 * requested_survivor_size) <= min_gen_size(); 280 281 bool eden_from_to_order = from_start < to_start; 282 // Check whether from space is below to space 283 if (eden_from_to_order) { 284 // Eden, from, to 285 286 log_trace(gc, ergo)(" Eden, from, to:"); 287 288 // Set eden 289 // "requested_eden_size" is a goal for the size of eden 290 // and may not be attainable. "eden_size" below is 291 // calculated based on the location of from-space and 292 // the goal for the size of eden. from-space is 293 // fixed in place because it contains live data. 294 // The calculation is done this way to avoid 32bit 295 // overflow (i.e., eden_start + requested_eden_size 296 // may too large for representation in 32bits). 297 size_t eden_size; 298 if (maintain_minimum) { 299 // Only make eden larger than the requested size if 300 // the minimum size of the generation has to be maintained. 301 // This could be done in general but policy at a higher 302 // level is determining a requested size for eden and that 303 // should be honored unless there is a fundamental reason. 304 eden_size = pointer_delta(from_start, 305 eden_start, 306 sizeof(char)); 330 331 // Should we be in this method if from_space is empty? Why not the set_space method? FIX ME! 332 if (from_size == 0) { 333 from_size = alignment; 334 } else { 335 from_size = align_size_up(from_size, alignment); 336 } 337 338 from_end = from_start + from_size; 339 assert(from_end > from_start, "addition overflow or from_size problem"); 340 341 guarantee(from_end <= (char*)from_space()->end(), 342 "from_end moved to the right"); 343 344 // Now update to_start with the new from_end 345 to_start = MAX2(from_end, to_start); 346 } 347 348 guarantee(to_start != to_end, "to space is zero sized"); 349 350 log_trace(gc, ergo)(" [eden_start .. eden_end): " 351 "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT, 352 p2i(eden_start), 353 p2i(eden_end), 354 pointer_delta(eden_end, eden_start, sizeof(char))); 355 log_trace(gc, ergo)(" [from_start .. from_end): " 356 "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT, 357 p2i(from_start), 358 p2i(from_end), 359 pointer_delta(from_end, from_start, sizeof(char))); 360 log_trace(gc, ergo)(" [ to_start .. to_end): " 361 "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT, 362 p2i(to_start), 363 p2i(to_end), 364 pointer_delta( to_end, to_start, sizeof(char))); 365 } else { 366 // Eden, to, from 367 log_trace(gc, ergo)(" Eden, to, from:"); 368 369 // To space gets priority over eden resizing. Note that we position 370 // to space as if we were able to resize from space, even though from 371 // space is not modified. 372 // Giving eden priority was tried and gave poorer performance. 373 to_end = (char*)pointer_delta(virtual_space()->high(), 374 (char*)requested_survivor_size, 375 sizeof(char)); 376 to_end = MIN2(to_end, from_start); 377 to_start = (char*)pointer_delta(to_end, (char*)requested_survivor_size, 378 sizeof(char)); 379 // if the space sizes are to be increased by several times then 380 // 'to_start' will point beyond the young generation. In this case 381 // 'to_start' should be adjusted. 382 to_start = MAX2(to_start, eden_start + alignment); 383 384 // Compute how big eden can be, then adjust end. 385 // See comments above on calculating eden_end. 386 size_t eden_size; 387 if (maintain_minimum) { 388 eden_size = pointer_delta(to_start, eden_start, sizeof(char)); 389 } else { 390 eden_size = MIN2(requested_eden_size, 391 pointer_delta(to_start, eden_start, sizeof(char))); 392 } 393 eden_end = eden_start + eden_size; 394 assert(eden_end >= eden_start, "addition overflowed"); 395 396 // Don't let eden shrink down to 0 or less. 397 eden_end = MAX2(eden_end, eden_start + alignment); 398 to_start = MAX2(to_start, eden_end); 399 400 log_trace(gc, ergo)(" [eden_start .. eden_end): " 401 "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT, 402 p2i(eden_start), 403 p2i(eden_end), 404 pointer_delta(eden_end, eden_start, sizeof(char))); 405 log_trace(gc, ergo)(" [ to_start .. to_end): " 406 "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT, 407 p2i(to_start), 408 p2i(to_end), 409 pointer_delta( to_end, to_start, sizeof(char))); 410 log_trace(gc, ergo)(" [from_start .. from_end): " 411 "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT, 412 p2i(from_start), 413 p2i(from_end), 414 pointer_delta(from_end, from_start, sizeof(char))); 415 } 416 417 418 guarantee((HeapWord*)from_start <= from_space()->bottom(), 419 "from start moved to the right"); 420 guarantee((HeapWord*)from_end >= from_space()->top(), 421 "from end moved into live data"); 422 assert(is_object_aligned((intptr_t)eden_start), "checking alignment"); 423 assert(is_object_aligned((intptr_t)from_start), "checking alignment"); 424 assert(is_object_aligned((intptr_t)to_start), "checking alignment"); 425 426 MemRegion edenMR((HeapWord*)eden_start, (HeapWord*)eden_end); 427 MemRegion toMR ((HeapWord*)to_start, (HeapWord*)to_end); 428 MemRegion fromMR((HeapWord*)from_start, (HeapWord*)from_end); 429 430 // Let's make sure the call to initialize doesn't reset "top"! 431 DEBUG_ONLY(HeapWord* old_from_top = from_space()->top();) 432 433 // For logging block below 434 size_t old_from = from_space()->capacity_in_bytes(); 435 size_t old_to = to_space()->capacity_in_bytes(); 436 437 if (ZapUnusedHeapArea) { 438 // NUMA is a special case because a numa space is not mangled 439 // in order to not prematurely bind its address to memory to 440 // the wrong memory (i.e., don't want the GC thread to first 441 // touch the memory). The survivor spaces are not numa 442 // spaces and are mangled. 443 if (UseNUMA) { 444 if (eden_from_to_order) { 445 mangle_survivors(from_space(), fromMR, to_space(), toMR); 446 } else { 447 mangle_survivors(to_space(), toMR, from_space(), fromMR); 448 } 449 } 450 451 // If not mangling the spaces, do some checking to verify that 452 // the spaces are already mangled. 453 // The spaces should be correctly mangled at this point so 462 eden_space()->check_mangled_unused_area(limit); 463 from_space()->check_mangled_unused_area(limit); 464 to_space()->check_mangled_unused_area(limit); 465 } 466 // When an existing space is being initialized, it is not 467 // mangled because the space has been previously mangled. 468 eden_space()->initialize(edenMR, 469 SpaceDecorator::Clear, 470 SpaceDecorator::DontMangle); 471 to_space()->initialize(toMR, 472 SpaceDecorator::Clear, 473 SpaceDecorator::DontMangle); 474 from_space()->initialize(fromMR, 475 SpaceDecorator::DontClear, 476 SpaceDecorator::DontMangle); 477 478 PSScavenge::set_young_generation_boundary(eden_space()->bottom()); 479 480 assert(from_space()->top() == old_from_top, "from top changed!"); 481 482 log_trace(gc, ergo)("AdaptiveSizePolicy::survivor space sizes: " 483 "collection: %d " 484 "(" SIZE_FORMAT ", " SIZE_FORMAT ") -> " 485 "(" SIZE_FORMAT ", " SIZE_FORMAT ") ", 486 ParallelScavengeHeap::heap()->total_collections(), 487 old_from, old_to, 488 from_space()->capacity_in_bytes(), 489 to_space()->capacity_in_bytes()); 490 491 space_invariants(); 492 } 493 void ASPSYoungGen::reset_after_change() { 494 assert_locked_or_safepoint(Heap_lock); 495 496 _reserved = MemRegion((HeapWord*)virtual_space()->low_boundary(), 497 (HeapWord*)virtual_space()->high_boundary()); 498 PSScavenge::reference_processor()->set_span(_reserved); 499 500 HeapWord* new_eden_bottom = (HeapWord*)virtual_space()->low(); 501 HeapWord* eden_bottom = eden_space()->bottom(); 502 if (new_eden_bottom != eden_bottom) { 503 MemRegion eden_mr(new_eden_bottom, eden_space()->end()); 504 eden_space()->initialize(eden_mr, 505 SpaceDecorator::Clear, 506 SpaceDecorator::Mangle); 507 PSScavenge::set_young_generation_boundary(eden_space()->bottom()); 508 } 509 MemRegion cmr((HeapWord*)virtual_space()->low(), 510 (HeapWord*)virtual_space()->high()); |