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

Print this page




 291 bool PSOldGen::expand_to_reserved() {
 292   assert_lock_strong(ExpandHeap_lock);
 293   assert_locked_or_safepoint(Heap_lock);
 294 
 295   bool result = true;
 296   const size_t remaining_bytes = virtual_space()->uncommitted_size();
 297   if (remaining_bytes > 0) {
 298     result = expand_by(remaining_bytes);
 299     DEBUG_ONLY(if (!result) warning("grow to reserve failed"));
 300   }
 301   return result;
 302 }
 303 
 304 void PSOldGen::shrink(size_t bytes) {
 305   assert_lock_strong(ExpandHeap_lock);
 306   assert_locked_or_safepoint(Heap_lock);
 307 
 308   size_t size = align_size_down(bytes, virtual_space()->alignment());
 309   if (size > 0) {
 310     assert_lock_strong(ExpandHeap_lock);
 311     virtual_space()->shrink_by(bytes);
 312     post_resize();
 313 
 314     if (Verbose && PrintGC) {
 315       size_t new_mem_size = virtual_space()->committed_size();
 316       size_t old_mem_size = new_mem_size + bytes;
 317       gclog_or_tty->print_cr("Shrinking %s from " SIZE_FORMAT "K by "
 318                                          SIZE_FORMAT "K to "
 319                                          SIZE_FORMAT "K",
 320                       name(), old_mem_size/K, bytes/K, new_mem_size/K);
 321     }
 322   }
 323 }
 324 
 325 void PSOldGen::resize(size_t desired_free_space) {
 326   const size_t alignment = virtual_space()->alignment();
 327   const size_t size_before = virtual_space()->committed_size();
 328   size_t new_size = used_in_bytes() + desired_free_space;
 329   if (new_size < used_in_bytes()) {
 330     // Overflowed the addition.
 331     new_size = gen_size_limit();
 332   }
 333   // Adjust according to our min and max
 334   new_size = MAX2(MIN2(new_size, gen_size_limit()), min_gen_size());
 335 
 336   assert(gen_size_limit() >= reserved().byte_size(), "max new size problem?");
 337   new_size = align_size_up(new_size, alignment);
 338 
 339   const size_t current_size = capacity_in_bytes();
 340 


 480     _gen(gen), _start_array(start_array) { }
 481 
 482   virtual void do_object(oop obj) {
 483     HeapWord* test_addr = (HeapWord*)obj + 1;
 484     guarantee(_start_array->object_start(test_addr) == (HeapWord*)obj, "ObjectStartArray cannot find start of object");
 485     guarantee(_start_array->is_block_allocated((HeapWord*)obj), "ObjectStartArray missing block allocation");
 486   }
 487 };
 488 
 489 void PSOldGen::verify_object_start_array() {
 490   VerifyObjectStartArrayClosure check( this, &_start_array );
 491   object_iterate(&check);
 492 }
 493 
 494 #ifndef PRODUCT
 495 void PSOldGen::record_spaces_top() {
 496   assert(ZapUnusedHeapArea, "Not mangling unused space");
 497   object_space()->set_top_for_allocations();
 498 }
 499 #endif















































 291 bool PSOldGen::expand_to_reserved() {
 292   assert_lock_strong(ExpandHeap_lock);
 293   assert_locked_or_safepoint(Heap_lock);
 294 
 295   bool result = true;
 296   const size_t remaining_bytes = virtual_space()->uncommitted_size();
 297   if (remaining_bytes > 0) {
 298     result = expand_by(remaining_bytes);
 299     DEBUG_ONLY(if (!result) warning("grow to reserve failed"));
 300   }
 301   return result;
 302 }
 303 
 304 void PSOldGen::shrink(size_t bytes) {
 305   assert_lock_strong(ExpandHeap_lock);
 306   assert_locked_or_safepoint(Heap_lock);
 307 
 308   size_t size = align_size_down(bytes, virtual_space()->alignment());
 309   if (size > 0) {
 310     assert_lock_strong(ExpandHeap_lock);
 311     virtual_space()->shrink_by(size);
 312     post_resize();
 313 
 314     if (Verbose && PrintGC) {
 315       size_t new_mem_size = virtual_space()->committed_size();
 316       size_t old_mem_size = new_mem_size + size;
 317       gclog_or_tty->print_cr("Shrinking %s from " SIZE_FORMAT "K by "
 318                                          SIZE_FORMAT "K to "
 319                                          SIZE_FORMAT "K",
 320                       name(), old_mem_size/K, size/K, new_mem_size/K);
 321     }
 322   }
 323 }
 324 
 325 void PSOldGen::resize(size_t desired_free_space) {
 326   const size_t alignment = virtual_space()->alignment();
 327   const size_t size_before = virtual_space()->committed_size();
 328   size_t new_size = used_in_bytes() + desired_free_space;
 329   if (new_size < used_in_bytes()) {
 330     // Overflowed the addition.
 331     new_size = gen_size_limit();
 332   }
 333   // Adjust according to our min and max
 334   new_size = MAX2(MIN2(new_size, gen_size_limit()), min_gen_size());
 335 
 336   assert(gen_size_limit() >= reserved().byte_size(), "max new size problem?");
 337   new_size = align_size_up(new_size, alignment);
 338 
 339   const size_t current_size = capacity_in_bytes();
 340 


 480     _gen(gen), _start_array(start_array) { }
 481 
 482   virtual void do_object(oop obj) {
 483     HeapWord* test_addr = (HeapWord*)obj + 1;
 484     guarantee(_start_array->object_start(test_addr) == (HeapWord*)obj, "ObjectStartArray cannot find start of object");
 485     guarantee(_start_array->is_block_allocated((HeapWord*)obj), "ObjectStartArray missing block allocation");
 486   }
 487 };
 488 
 489 void PSOldGen::verify_object_start_array() {
 490   VerifyObjectStartArrayClosure check( this, &_start_array );
 491   object_iterate(&check);
 492 }
 493 
 494 #ifndef PRODUCT
 495 void PSOldGen::record_spaces_top() {
 496   assert(ZapUnusedHeapArea, "Not mangling unused space");
 497   object_space()->set_top_for_allocations();
 498 }
 499 #endif
 500 
 501 void PSOldGen::try_to_expand_by(size_t expand_bytes) {
 502   if (expand_bytes < MinHeapDeltaBytes ||
 503       capacity_in_bytes() + expand_bytes > max_gen_size()) {
 504     return;
 505   }
 506 
 507   if (PrintGC) {
 508     gclog_or_tty->print_cr(" Resizing old gen. expand_bytes=%d", expand_bytes);
 509     gclog_or_tty->print("BEFORE: Old Gen: ");
 510     gclog_or_tty->print("capacity : " SIZE_FORMAT ", ", capacity_in_bytes());
 511     gclog_or_tty->print_cr("used : " SIZE_FORMAT ", " , used_in_bytes());
 512   }
 513 
 514   expand(expand_bytes);
 515 
 516   if (PrintGC) {
 517     gclog_or_tty->print("AFTER: Old Gen: ");
 518     gclog_or_tty->print("capacity : " SIZE_FORMAT ", ", capacity_in_bytes());
 519     gclog_or_tty->print_cr("used : " SIZE_FORMAT ", " , used_in_bytes());
 520   }
 521 }
 522 
 523 void PSOldGen::try_to_shrink_by(size_t shrink_bytes) {
 524   if (shrink_bytes < MinHeapDeltaBytes ||
 525       capacity_in_bytes() - shrink_bytes < init_gen_size()) {
 526     return;
 527   }
 528 
 529   if (PrintGC) {
 530     gclog_or_tty->print_cr(" Resizing old gen. shrink_bytes=%d", shrink_bytes);
 531     gclog_or_tty->print("BEFORE: Old Gen: ");
 532     gclog_or_tty->print("capacity : " SIZE_FORMAT ", ", capacity_in_bytes());
 533     gclog_or_tty->print_cr("used : " SIZE_FORMAT ", " , used_in_bytes());
 534   }
 535 
 536   MutexLocker x(ExpandHeap_lock);
 537   shrink(shrink_bytes);
 538 
 539   if (PrintGC) {
 540     gclog_or_tty->print("AFTER: Old Gen: ");
 541     gclog_or_tty->print("capacity : " SIZE_FORMAT ", ", capacity_in_bytes());
 542     gclog_or_tty->print_cr("used : " SIZE_FORMAT ", " , used_in_bytes());
 543   }
 544 }