< prev index next >

src/share/vm/memory/generation.cpp

Print this page
rev 7420 : [mq]: removeOneContigSpaceGeneration


  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "gc_implementation/shared/gcTimer.hpp"
  27 #include "gc_implementation/shared/gcTrace.hpp"
  28 #include "gc_implementation/shared/spaceDecorator.hpp"
  29 #include "gc_interface/collectedHeap.inline.hpp"
  30 #include "memory/allocation.inline.hpp"
  31 #include "memory/blockOffsetTable.inline.hpp"
  32 #include "memory/cardTableRS.hpp"
  33 #include "memory/gcLocker.inline.hpp"
  34 #include "memory/genCollectedHeap.hpp"
  35 #include "memory/genMarkSweep.hpp"
  36 #include "memory/genOopClosures.hpp"
  37 #include "memory/genOopClosures.inline.hpp"
  38 #include "memory/generation.hpp"
  39 #include "memory/generation.inline.hpp"
  40 #include "memory/space.inline.hpp"
  41 #include "oops/oop.inline.hpp"
  42 #include "runtime/java.hpp"
  43 #include "utilities/copy.hpp"
  44 #include "utilities/events.hpp"
  45 
  46 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
  47 
  48 Generation::Generation(ReservedSpace rs, size_t initial_size, int level) :
  49   _level(level),
  50   _ref_processor(NULL) {
  51   if (!_virtual_space.initialize(rs, initial_size)) {
  52     vm_exit_during_initialization("Could not reserve enough space for "
  53                     "object heap");
  54   }
  55   // Mangle all of the the initial generation.
  56   if (ZapUnusedHeapArea) {
  57     MemRegion mangle_region((HeapWord*)_virtual_space.low(),
  58       (HeapWord*)_virtual_space.high());
  59     SpaceMangler::mangle_region(mangle_region);


 593                              "  aggressive shrinking:"
 594                              "  _capacity_at_prologue: %.1fK"
 595                              "  capacity_after_gc: %.1fK"
 596                              "  expansion_for_promotion: %.1fK"
 597                              "  shrink_bytes: %.1fK",
 598                              capacity_after_gc / (double) K,
 599                              _capacity_at_prologue / (double) K,
 600                              expansion_for_promotion / (double) K,
 601                              shrink_bytes / (double) K);
 602     }
 603   }
 604   // Don't shrink unless it's significant
 605   if (shrink_bytes >= _min_heap_delta_bytes) {
 606     shrink(shrink_bytes);
 607   }
 608 }
 609 
 610 // Currently nothing to do.
 611 void CardGeneration::prepare_for_verify() {}
 612 
 613 
 614 void OneContigSpaceCardGeneration::collect(bool   full,
 615                                            bool   clear_all_soft_refs,
 616                                            size_t size,
 617                                            bool   is_tlab) {
 618   GenCollectedHeap* gch = GenCollectedHeap::heap();
 619 
 620   SpecializationStats::clear();
 621   // Temporarily expand the span of our ref processor, so
 622   // refs discovery is over the entire heap, not just this generation
 623   ReferenceProcessorSpanMutator
 624     x(ref_processor(), gch->reserved_region());
 625 
 626   STWGCTimer* gc_timer = GenMarkSweep::gc_timer();
 627   gc_timer->register_gc_start();
 628 
 629   SerialOldTracer* gc_tracer = GenMarkSweep::gc_tracer();
 630   gc_tracer->report_gc_start(gch->gc_cause(), gc_timer->gc_start());
 631 
 632   GenMarkSweep::invoke_at_safepoint(_level, ref_processor(), clear_all_soft_refs);
 633 
 634   gc_timer->register_gc_end();
 635 
 636   gc_tracer->report_gc_end(gc_timer->gc_end(), gc_timer->time_partitions());
 637 
 638   SpecializationStats::print();
 639 }
 640 
 641 HeapWord*
 642 OneContigSpaceCardGeneration::expand_and_allocate(size_t word_size,
 643                                                   bool is_tlab,
 644                                                   bool parallel) {
 645   assert(!is_tlab, "OneContigSpaceCardGeneration does not support TLAB allocation");
 646   if (parallel) {
 647     MutexLocker x(ParGCRareEvent_lock);
 648     HeapWord* result = NULL;
 649     size_t byte_size = word_size * HeapWordSize;
 650     while (true) {
 651       expand(byte_size, _min_heap_delta_bytes);
 652       if (GCExpandToAllocateDelayMillis > 0) {
 653         os::sleep(Thread::current(), GCExpandToAllocateDelayMillis, false);
 654       }
 655       result = _the_space->par_allocate(word_size);
 656       if ( result != NULL) {
 657         return result;
 658       } else {
 659         // If there's not enough expansion space available, give up.
 660         if (_virtual_space.uncommitted_size() < byte_size) {
 661           return NULL;
 662         }
 663         // else try again
 664       }
 665     }
 666   } else {
 667     expand(word_size*HeapWordSize, _min_heap_delta_bytes);
 668     return _the_space->allocate(word_size);
 669   }
 670 }
 671 
 672 bool OneContigSpaceCardGeneration::expand(size_t bytes, size_t expand_bytes) {
 673   GCMutexLocker x(ExpandHeap_lock);
 674   return CardGeneration::expand(bytes, expand_bytes);
 675 }
 676 
 677 
 678 void OneContigSpaceCardGeneration::shrink(size_t bytes) {
 679   assert_locked_or_safepoint(ExpandHeap_lock);
 680   size_t size = ReservedSpace::page_align_size_down(bytes);
 681   if (size > 0) {
 682     shrink_by(size);
 683   }
 684 }
 685 
 686 
 687 size_t OneContigSpaceCardGeneration::capacity() const {
 688   return _the_space->capacity();
 689 }
 690 
 691 
 692 size_t OneContigSpaceCardGeneration::used() const {
 693   return _the_space->used();
 694 }
 695 
 696 
 697 size_t OneContigSpaceCardGeneration::free() const {
 698   return _the_space->free();
 699 }
 700 
 701 MemRegion OneContigSpaceCardGeneration::used_region() const {
 702   return the_space()->used_region();
 703 }
 704 
 705 size_t OneContigSpaceCardGeneration::unsafe_max_alloc_nogc() const {
 706   return _the_space->free();
 707 }
 708 
 709 size_t OneContigSpaceCardGeneration::contiguous_available() const {
 710   return _the_space->free() + _virtual_space.uncommitted_size();
 711 }
 712 
 713 bool OneContigSpaceCardGeneration::grow_by(size_t bytes) {
 714   assert_locked_or_safepoint(ExpandHeap_lock);
 715   bool result = _virtual_space.expand_by(bytes);
 716   if (result) {
 717     size_t new_word_size =
 718        heap_word_size(_virtual_space.committed_size());
 719     MemRegion mr(_the_space->bottom(), new_word_size);
 720     // Expand card table
 721     Universe::heap()->barrier_set()->resize_covered_region(mr);
 722     // Expand shared block offset array
 723     _bts->resize(new_word_size);
 724 
 725     // Fix for bug #4668531
 726     if (ZapUnusedHeapArea) {
 727       MemRegion mangle_region(_the_space->end(),
 728       (HeapWord*)_virtual_space.high());
 729       SpaceMangler::mangle_region(mangle_region);
 730     }
 731 
 732     // Expand space -- also expands space's BOT
 733     // (which uses (part of) shared array above)
 734     _the_space->set_end((HeapWord*)_virtual_space.high());
 735 
 736     // update the space and generation capacity counters
 737     update_counters();
 738 
 739     if (Verbose && PrintGC) {
 740       size_t new_mem_size = _virtual_space.committed_size();
 741       size_t old_mem_size = new_mem_size - bytes;
 742       gclog_or_tty->print_cr("Expanding %s from " SIZE_FORMAT "K by "
 743                       SIZE_FORMAT "K to " SIZE_FORMAT "K",
 744                       name(), old_mem_size/K, bytes/K, new_mem_size/K);
 745     }
 746   }
 747   return result;
 748 }
 749 
 750 
 751 bool OneContigSpaceCardGeneration::grow_to_reserved() {
 752   assert_locked_or_safepoint(ExpandHeap_lock);
 753   bool success = true;
 754   const size_t remaining_bytes = _virtual_space.uncommitted_size();
 755   if (remaining_bytes > 0) {
 756     success = grow_by(remaining_bytes);
 757     DEBUG_ONLY(if (!success) warning("grow to reserved failed");)
 758   }
 759   return success;
 760 }
 761 
 762 void OneContigSpaceCardGeneration::shrink_by(size_t bytes) {
 763   assert_locked_or_safepoint(ExpandHeap_lock);
 764   // Shrink committed space
 765   _virtual_space.shrink_by(bytes);
 766   // Shrink space; this also shrinks the space's BOT
 767   _the_space->set_end((HeapWord*) _virtual_space.high());
 768   size_t new_word_size = heap_word_size(_the_space->capacity());
 769   // Shrink the shared block offset array
 770   _bts->resize(new_word_size);
 771   MemRegion mr(_the_space->bottom(), new_word_size);
 772   // Shrink the card table
 773   Universe::heap()->barrier_set()->resize_covered_region(mr);
 774 
 775   if (Verbose && PrintGC) {
 776     size_t new_mem_size = _virtual_space.committed_size();
 777     size_t old_mem_size = new_mem_size + bytes;
 778     gclog_or_tty->print_cr("Shrinking %s from " SIZE_FORMAT "K to " SIZE_FORMAT "K",
 779                   name(), old_mem_size/K, new_mem_size/K);
 780   }
 781 }
 782 
 783 // Currently nothing to do.
 784 void OneContigSpaceCardGeneration::prepare_for_verify() {}
 785 
 786 
 787 // Override for a card-table generation with one contiguous
 788 // space. NOTE: For reasons that are lost in the fog of history,
 789 // this code is used when you iterate over perm gen objects,
 790 // even when one uses CDS, where the perm gen has a couple of
 791 // other spaces; this is because CompactingPermGenGen derives
 792 // from OneContigSpaceCardGeneration. This should be cleaned up,
 793 // see CR 6897789..
 794 void OneContigSpaceCardGeneration::object_iterate(ObjectClosure* blk) {
 795   _the_space->object_iterate(blk);
 796 }
 797 
 798 void OneContigSpaceCardGeneration::space_iterate(SpaceClosure* blk,
 799                                                  bool usedOnly) {
 800   blk->do_space(_the_space);
 801 }
 802 
 803 void OneContigSpaceCardGeneration::younger_refs_iterate(OopsInGenClosure* blk) {
 804   blk->set_generation(this);
 805   younger_refs_in_space_iterate(_the_space, blk);
 806   blk->reset_generation();
 807 }
 808 
 809 void OneContigSpaceCardGeneration::save_marks() {
 810   _the_space->set_saved_mark();
 811 }
 812 
 813 
 814 void OneContigSpaceCardGeneration::reset_saved_marks() {
 815   _the_space->reset_saved_mark();
 816 }
 817 
 818 
 819 bool OneContigSpaceCardGeneration::no_allocs_since_save_marks() {
 820   return _the_space->saved_mark_at_top();
 821 }
 822 
 823 #define OneContig_SINCE_SAVE_MARKS_ITERATE_DEFN(OopClosureType, nv_suffix)      \
 824                                                                                 \
 825 void OneContigSpaceCardGeneration::                                             \
 826 oop_since_save_marks_iterate##nv_suffix(OopClosureType* blk) {                  \
 827   blk->set_generation(this);                                                    \
 828   _the_space->oop_since_save_marks_iterate##nv_suffix(blk);                     \
 829   blk->reset_generation();                                                      \
 830   save_marks();                                                                 \
 831 }
 832 
 833 ALL_SINCE_SAVE_MARKS_CLOSURES(OneContig_SINCE_SAVE_MARKS_ITERATE_DEFN)
 834 
 835 #undef OneContig_SINCE_SAVE_MARKS_ITERATE_DEFN
 836 
 837 
 838 void OneContigSpaceCardGeneration::gc_epilogue(bool full) {
 839   _last_gc = WaterMark(the_space(), the_space()->top());
 840 
 841   // update the generation and space performance counters
 842   update_counters();
 843   if (ZapUnusedHeapArea) {
 844     the_space()->check_mangled_unused_area_complete();
 845   }
 846 }
 847 
 848 void OneContigSpaceCardGeneration::record_spaces_top() {
 849   assert(ZapUnusedHeapArea, "Not mangling unused space");
 850   the_space()->set_top_for_allocations();
 851 }
 852 
 853 void OneContigSpaceCardGeneration::verify() {
 854   the_space()->verify();
 855 }
 856 
 857 void OneContigSpaceCardGeneration::print_on(outputStream* st)  const {
 858   Generation::print_on(st);
 859   st->print("   the");
 860   the_space()->print_on(st);
 861 }


  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "gc_implementation/shared/gcTimer.hpp"
  27 #include "gc_implementation/shared/gcTrace.hpp"
  28 #include "gc_implementation/shared/spaceDecorator.hpp"
  29 #include "gc_interface/collectedHeap.inline.hpp"
  30 #include "memory/allocation.inline.hpp"
  31 #include "memory/blockOffsetTable.inline.hpp"
  32 #include "memory/cardTableRS.hpp"
  33 #include "memory/gcLocker.inline.hpp"
  34 #include "memory/genCollectedHeap.hpp"
  35 #include "memory/genMarkSweep.hpp"
  36 #include "memory/genOopClosures.hpp"
  37 #include "memory/genOopClosures.inline.hpp"
  38 #include "memory/generation.hpp"

  39 #include "memory/space.inline.hpp"
  40 #include "oops/oop.inline.hpp"
  41 #include "runtime/java.hpp"
  42 #include "utilities/copy.hpp"
  43 #include "utilities/events.hpp"
  44 
  45 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
  46 
  47 Generation::Generation(ReservedSpace rs, size_t initial_size, int level) :
  48   _level(level),
  49   _ref_processor(NULL) {
  50   if (!_virtual_space.initialize(rs, initial_size)) {
  51     vm_exit_during_initialization("Could not reserve enough space for "
  52                     "object heap");
  53   }
  54   // Mangle all of the the initial generation.
  55   if (ZapUnusedHeapArea) {
  56     MemRegion mangle_region((HeapWord*)_virtual_space.low(),
  57       (HeapWord*)_virtual_space.high());
  58     SpaceMangler::mangle_region(mangle_region);


 592                              "  aggressive shrinking:"
 593                              "  _capacity_at_prologue: %.1fK"
 594                              "  capacity_after_gc: %.1fK"
 595                              "  expansion_for_promotion: %.1fK"
 596                              "  shrink_bytes: %.1fK",
 597                              capacity_after_gc / (double) K,
 598                              _capacity_at_prologue / (double) K,
 599                              expansion_for_promotion / (double) K,
 600                              shrink_bytes / (double) K);
 601     }
 602   }
 603   // Don't shrink unless it's significant
 604   if (shrink_bytes >= _min_heap_delta_bytes) {
 605     shrink(shrink_bytes);
 606   }
 607 }
 608 
 609 // Currently nothing to do.
 610 void CardGeneration::prepare_for_verify() {}
 611 

























































































































































































































































< prev index next >