242 assert(requested_eden_size > 0 && requested_survivor_size > 0, 243 "just checking"); 244 CollectedHeap* heap = Universe::heap(); 245 assert(heap->kind() == CollectedHeap::GenCollectedHeap, "Sanity"); 246 247 248 // We require eden and to space to be empty 249 if ((!eden()->is_empty()) || (!to()->is_empty())) { 250 return; 251 } 252 253 size_t cur_eden_size = eden()->capacity(); 254 255 if (PrintAdaptiveSizePolicy && Verbose) { 256 gclog_or_tty->print_cr("ASParNew::resize_spaces(requested_eden_size: " 257 SIZE_FORMAT 258 ", requested_survivor_size: " SIZE_FORMAT ")", 259 requested_eden_size, requested_survivor_size); 260 gclog_or_tty->print_cr(" eden: [" PTR_FORMAT ".." PTR_FORMAT ") " 261 SIZE_FORMAT, 262 eden()->bottom(), 263 eden()->end(), 264 pointer_delta(eden()->end(), 265 eden()->bottom(), 266 sizeof(char))); 267 gclog_or_tty->print_cr(" from: [" PTR_FORMAT ".." PTR_FORMAT ") " 268 SIZE_FORMAT, 269 from()->bottom(), 270 from()->end(), 271 pointer_delta(from()->end(), 272 from()->bottom(), 273 sizeof(char))); 274 gclog_or_tty->print_cr(" to: [" PTR_FORMAT ".." PTR_FORMAT ") " 275 SIZE_FORMAT, 276 to()->bottom(), 277 to()->end(), 278 pointer_delta( to()->end(), 279 to()->bottom(), 280 sizeof(char))); 281 } 282 283 // There's nothing to do if the new sizes are the same as the current 284 if (requested_survivor_size == to()->capacity() && 285 requested_survivor_size == from()->capacity() && 286 requested_eden_size == eden()->capacity()) { 287 if (PrintAdaptiveSizePolicy && Verbose) { 288 gclog_or_tty->print_cr(" capacities are the right sizes, returning"); 289 } 290 return; 291 } 292 293 char* eden_start = (char*)eden()->bottom(); 294 char* eden_end = (char*)eden()->end(); 295 char* from_start = (char*)from()->bottom(); 296 char* from_end = (char*)from()->end(); 297 char* to_start = (char*)to()->bottom(); 365 // Now update to_start with the new from_end 366 to_start = MAX2(from_end, to_start); 367 } else { 368 // If shrinking, move to-space down to abut the end of from-space 369 // so that shrinking will move to-space down. If not shrinking 370 // to-space is moving up to allow for growth on the next expansion. 371 if (requested_eden_size <= cur_eden_size) { 372 to_start = from_end; 373 if (to_start + requested_survivor_size > to_start) { 374 to_end = to_start + requested_survivor_size; 375 } 376 } 377 // else leave to_end pointing to the high end of the virtual space. 378 } 379 380 guarantee(to_start != to_end, "to space is zero sized"); 381 382 if (PrintAdaptiveSizePolicy && Verbose) { 383 gclog_or_tty->print_cr(" [eden_start .. eden_end): " 384 "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT, 385 eden_start, 386 eden_end, 387 pointer_delta(eden_end, eden_start, sizeof(char))); 388 gclog_or_tty->print_cr(" [from_start .. from_end): " 389 "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT, 390 from_start, 391 from_end, 392 pointer_delta(from_end, from_start, sizeof(char))); 393 gclog_or_tty->print_cr(" [ to_start .. to_end): " 394 "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT, 395 to_start, 396 to_end, 397 pointer_delta( to_end, to_start, sizeof(char))); 398 } 399 } else { 400 // Eden, to, from 401 if (PrintAdaptiveSizePolicy && Verbose) { 402 gclog_or_tty->print_cr(" Eden, to, from:"); 403 } 404 405 // Calculate the to-space boundaries based on 406 // the start of from-space. 407 to_end = from_start; 408 to_start = (char*)pointer_delta(from_start, 409 (char*)requested_survivor_size, 410 sizeof(char)); 411 // Calculate the ideal eden boundaries. 412 // eden_end is already at the bottom of the generation 413 assert(eden_start == virtual_space()->low(), 414 "Eden is not starting at the low end of the virtual space"); 415 if (eden_start + requested_eden_size >= eden_start) { 416 eden_end = eden_start + requested_eden_size; 456 457 // eden_end may have moved so again make sure 458 // the to-space and eden don't overlap. 459 to_start = MAX2(eden_end, to_start); 460 461 // from-space 462 size_t from_used = from()->used(); 463 if (requested_survivor_size > from_used) { 464 if (from_start + requested_survivor_size >= from_start) { 465 from_end = from_start + requested_survivor_size; 466 } 467 if (from_end > virtual_space()->high()) { 468 from_end = virtual_space()->high(); 469 } 470 } 471 472 assert(to_start >= eden_end, "to-space should be above eden"); 473 if (PrintAdaptiveSizePolicy && Verbose) { 474 gclog_or_tty->print_cr(" [eden_start .. eden_end): " 475 "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT, 476 eden_start, 477 eden_end, 478 pointer_delta(eden_end, eden_start, sizeof(char))); 479 gclog_or_tty->print_cr(" [ to_start .. to_end): " 480 "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT, 481 to_start, 482 to_end, 483 pointer_delta( to_end, to_start, sizeof(char))); 484 gclog_or_tty->print_cr(" [from_start .. from_end): " 485 "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT, 486 from_start, 487 from_end, 488 pointer_delta(from_end, from_start, sizeof(char))); 489 } 490 } 491 492 493 guarantee((HeapWord*)from_start <= from()->bottom(), 494 "from start moved to the right"); 495 guarantee((HeapWord*)from_end >= from()->top(), 496 "from end moved into live data"); 497 assert(is_object_aligned((intptr_t)eden_start), "checking alignment"); 498 assert(is_object_aligned((intptr_t)from_start), "checking alignment"); 499 assert(is_object_aligned((intptr_t)to_start), "checking alignment"); 500 501 MemRegion edenMR((HeapWord*)eden_start, (HeapWord*)eden_end); 502 MemRegion toMR ((HeapWord*)to_start, (HeapWord*)to_end); 503 MemRegion fromMR((HeapWord*)from_start, (HeapWord*)from_end); 504 505 // Let's make sure the call to initialize doesn't reset "top"! 506 HeapWord* old_from_top = from()->top(); 507 | 242 assert(requested_eden_size > 0 && requested_survivor_size > 0, 243 "just checking"); 244 CollectedHeap* heap = Universe::heap(); 245 assert(heap->kind() == CollectedHeap::GenCollectedHeap, "Sanity"); 246 247 248 // We require eden and to space to be empty 249 if ((!eden()->is_empty()) || (!to()->is_empty())) { 250 return; 251 } 252 253 size_t cur_eden_size = eden()->capacity(); 254 255 if (PrintAdaptiveSizePolicy && Verbose) { 256 gclog_or_tty->print_cr("ASParNew::resize_spaces(requested_eden_size: " 257 SIZE_FORMAT 258 ", requested_survivor_size: " SIZE_FORMAT ")", 259 requested_eden_size, requested_survivor_size); 260 gclog_or_tty->print_cr(" eden: [" PTR_FORMAT ".." PTR_FORMAT ") " 261 SIZE_FORMAT, 262 p2i(eden()->bottom()), 263 p2i(eden()->end()), 264 pointer_delta(eden()->end(), 265 eden()->bottom(), 266 sizeof(char))); 267 gclog_or_tty->print_cr(" from: [" PTR_FORMAT ".." PTR_FORMAT ") " 268 SIZE_FORMAT, 269 p2i(from()->bottom()), 270 p2i(from()->end()), 271 pointer_delta(from()->end(), 272 from()->bottom(), 273 sizeof(char))); 274 gclog_or_tty->print_cr(" to: [" PTR_FORMAT ".." PTR_FORMAT ") " 275 SIZE_FORMAT, 276 p2i(to()->bottom()), 277 p2i(to()->end()), 278 pointer_delta( to()->end(), 279 to()->bottom(), 280 sizeof(char))); 281 } 282 283 // There's nothing to do if the new sizes are the same as the current 284 if (requested_survivor_size == to()->capacity() && 285 requested_survivor_size == from()->capacity() && 286 requested_eden_size == eden()->capacity()) { 287 if (PrintAdaptiveSizePolicy && Verbose) { 288 gclog_or_tty->print_cr(" capacities are the right sizes, returning"); 289 } 290 return; 291 } 292 293 char* eden_start = (char*)eden()->bottom(); 294 char* eden_end = (char*)eden()->end(); 295 char* from_start = (char*)from()->bottom(); 296 char* from_end = (char*)from()->end(); 297 char* to_start = (char*)to()->bottom(); 365 // Now update to_start with the new from_end 366 to_start = MAX2(from_end, to_start); 367 } else { 368 // If shrinking, move to-space down to abut the end of from-space 369 // so that shrinking will move to-space down. If not shrinking 370 // to-space is moving up to allow for growth on the next expansion. 371 if (requested_eden_size <= cur_eden_size) { 372 to_start = from_end; 373 if (to_start + requested_survivor_size > to_start) { 374 to_end = to_start + requested_survivor_size; 375 } 376 } 377 // else leave to_end pointing to the high end of the virtual space. 378 } 379 380 guarantee(to_start != to_end, "to space is zero sized"); 381 382 if (PrintAdaptiveSizePolicy && Verbose) { 383 gclog_or_tty->print_cr(" [eden_start .. eden_end): " 384 "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT, 385 p2i(eden_start), 386 p2i(eden_end), 387 pointer_delta(eden_end, eden_start, sizeof(char))); 388 gclog_or_tty->print_cr(" [from_start .. from_end): " 389 "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT, 390 p2i(from_start), 391 p2i(from_end), 392 pointer_delta(from_end, from_start, sizeof(char))); 393 gclog_or_tty->print_cr(" [ to_start .. to_end): " 394 "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT, 395 p2i(to_start), 396 p2i(to_end), 397 pointer_delta( to_end, to_start, sizeof(char))); 398 } 399 } else { 400 // Eden, to, from 401 if (PrintAdaptiveSizePolicy && Verbose) { 402 gclog_or_tty->print_cr(" Eden, to, from:"); 403 } 404 405 // Calculate the to-space boundaries based on 406 // the start of from-space. 407 to_end = from_start; 408 to_start = (char*)pointer_delta(from_start, 409 (char*)requested_survivor_size, 410 sizeof(char)); 411 // Calculate the ideal eden boundaries. 412 // eden_end is already at the bottom of the generation 413 assert(eden_start == virtual_space()->low(), 414 "Eden is not starting at the low end of the virtual space"); 415 if (eden_start + requested_eden_size >= eden_start) { 416 eden_end = eden_start + requested_eden_size; 456 457 // eden_end may have moved so again make sure 458 // the to-space and eden don't overlap. 459 to_start = MAX2(eden_end, to_start); 460 461 // from-space 462 size_t from_used = from()->used(); 463 if (requested_survivor_size > from_used) { 464 if (from_start + requested_survivor_size >= from_start) { 465 from_end = from_start + requested_survivor_size; 466 } 467 if (from_end > virtual_space()->high()) { 468 from_end = virtual_space()->high(); 469 } 470 } 471 472 assert(to_start >= eden_end, "to-space should be above eden"); 473 if (PrintAdaptiveSizePolicy && Verbose) { 474 gclog_or_tty->print_cr(" [eden_start .. eden_end): " 475 "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT, 476 p2i(eden_start), 477 p2i(eden_end), 478 pointer_delta(eden_end, eden_start, sizeof(char))); 479 gclog_or_tty->print_cr(" [ to_start .. to_end): " 480 "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT, 481 p2i(to_start), 482 p2i(to_end), 483 pointer_delta( to_end, to_start, sizeof(char))); 484 gclog_or_tty->print_cr(" [from_start .. from_end): " 485 "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT, 486 p2i(from_start), 487 p2i(from_end), 488 pointer_delta(from_end, from_start, sizeof(char))); 489 } 490 } 491 492 493 guarantee((HeapWord*)from_start <= from()->bottom(), 494 "from start moved to the right"); 495 guarantee((HeapWord*)from_end >= from()->top(), 496 "from end moved into live data"); 497 assert(is_object_aligned((intptr_t)eden_start), "checking alignment"); 498 assert(is_object_aligned((intptr_t)from_start), "checking alignment"); 499 assert(is_object_aligned((intptr_t)to_start), "checking alignment"); 500 501 MemRegion edenMR((HeapWord*)eden_start, (HeapWord*)eden_end); 502 MemRegion toMR ((HeapWord*)to_start, (HeapWord*)to_end); 503 MemRegion fromMR((HeapWord*)from_start, (HeapWord*)from_end); 504 505 // Let's make sure the call to initialize doesn't reset "top"! 506 HeapWord* old_from_top = from()->top(); 507 |