< prev index next >

src/share/vm/memory/cardGeneration.cpp

Print this page
rev 8070 : imported patch gencollected_heap_cleanup


  43   _used_at_prologue()
  44 {
  45   HeapWord* start = (HeapWord*)rs.base();
  46   size_t reserved_byte_size = rs.size();
  47   assert((uintptr_t(start) & 3) == 0, "bad alignment");
  48   assert((reserved_byte_size & 3) == 0, "bad alignment");
  49   MemRegion reserved_mr(start, heap_word_size(reserved_byte_size));
  50   _bts = new BlockOffsetSharedArray(reserved_mr,
  51                                     heap_word_size(initial_byte_size));
  52   MemRegion committed_mr(start, heap_word_size(initial_byte_size));
  53   _rs->resize_covered_region(committed_mr);
  54   if (_bts == NULL) {
  55     vm_exit_during_initialization("Could not allocate a BlockOffsetArray");
  56   }
  57 
  58   // Verify that the start and end of this generation is the start of a card.
  59   // If this wasn't true, a single card could span more than on generation,
  60   // which would cause problems when we commit/uncommit memory, and when we
  61   // clear and dirty cards.
  62   guarantee(_rs->is_aligned(reserved_mr.start()), "generation must be card aligned");
  63   if (reserved_mr.end() != Universe::heap()->reserved_region().end()) {
  64     // Don't check at the very end of the heap as we'll assert that we're probing off
  65     // the end if we try.
  66     guarantee(_rs->is_aligned(reserved_mr.end()), "generation must be card aligned");
  67   }
  68   _min_heap_delta_bytes = MinHeapDeltaBytes;
  69   _capacity_at_prologue = initial_byte_size;
  70   _used_at_prologue = 0;
  71 }
  72 
  73 bool CardGeneration::grow_by(size_t bytes) {
  74   assert_correct_size_change_locking();
  75   bool result = _virtual_space.expand_by(bytes);
  76   if (result) {
  77     size_t new_word_size =
  78        heap_word_size(_virtual_space.committed_size());
  79     MemRegion mr(space()->bottom(), new_word_size);
  80     // Expand card table
  81     Universe::heap()->barrier_set()->resize_covered_region(mr);
  82     // Expand shared block offset array
  83     _bts->resize(new_word_size);
  84 
  85     // Fix for bug #4668531
  86     if (ZapUnusedHeapArea) {
  87       MemRegion mangle_region(space()->end(),
  88       (HeapWord*)_virtual_space.high());
  89       SpaceMangler::mangle_region(mangle_region);
  90     }
  91 
  92     // Expand space -- also expands space's BOT
  93     // (which uses (part of) shared array above)
  94     space()->set_end((HeapWord*)_virtual_space.high());
  95 
  96     // update the space and generation capacity counters
  97     update_counters();
  98 
  99     if (Verbose && PrintGC) {
 100       size_t new_mem_size = _virtual_space.committed_size();
 101       size_t old_mem_size = new_mem_size - bytes;


 153   return success;
 154 }
 155 
 156 void CardGeneration::shrink(size_t bytes) {
 157   assert_correct_size_change_locking();
 158 
 159   size_t size = ReservedSpace::page_align_size_down(bytes);
 160   if (size == 0) {
 161     return;
 162   }
 163 
 164   // Shrink committed space
 165   _virtual_space.shrink_by(size);
 166   // Shrink space; this also shrinks the space's BOT
 167   space()->set_end((HeapWord*) _virtual_space.high());
 168   size_t new_word_size = heap_word_size(space()->capacity());
 169   // Shrink the shared block offset array
 170   _bts->resize(new_word_size);
 171   MemRegion mr(space()->bottom(), new_word_size);
 172   // Shrink the card table
 173   Universe::heap()->barrier_set()->resize_covered_region(mr);
 174 
 175   if (Verbose && PrintGC) {
 176     size_t new_mem_size = _virtual_space.committed_size();
 177     size_t old_mem_size = new_mem_size + size;
 178     gclog_or_tty->print_cr("Shrinking %s from " SIZE_FORMAT "K to " SIZE_FORMAT "K",
 179                   name(), old_mem_size/K, new_mem_size/K);
 180   }
 181 }
 182 
 183 // No young generation references, clear this generation's cards.
 184 void CardGeneration::clear_remembered_set() {
 185   _rs->clear(reserved());
 186 }
 187 
 188 // Objects in this generation may have moved, invalidate this
 189 // generation's cards.
 190 void CardGeneration::invalidate_remembered_set() {
 191   _rs->invalidate(used_region());
 192 }
 193 




  43   _used_at_prologue()
  44 {
  45   HeapWord* start = (HeapWord*)rs.base();
  46   size_t reserved_byte_size = rs.size();
  47   assert((uintptr_t(start) & 3) == 0, "bad alignment");
  48   assert((reserved_byte_size & 3) == 0, "bad alignment");
  49   MemRegion reserved_mr(start, heap_word_size(reserved_byte_size));
  50   _bts = new BlockOffsetSharedArray(reserved_mr,
  51                                     heap_word_size(initial_byte_size));
  52   MemRegion committed_mr(start, heap_word_size(initial_byte_size));
  53   _rs->resize_covered_region(committed_mr);
  54   if (_bts == NULL) {
  55     vm_exit_during_initialization("Could not allocate a BlockOffsetArray");
  56   }
  57 
  58   // Verify that the start and end of this generation is the start of a card.
  59   // If this wasn't true, a single card could span more than on generation,
  60   // which would cause problems when we commit/uncommit memory, and when we
  61   // clear and dirty cards.
  62   guarantee(_rs->is_aligned(reserved_mr.start()), "generation must be card aligned");
  63   if (reserved_mr.end() != GenCollectedHeap::heap()->reserved_region().end()) {
  64     // Don't check at the very end of the heap as we'll assert that we're probing off
  65     // the end if we try.
  66     guarantee(_rs->is_aligned(reserved_mr.end()), "generation must be card aligned");
  67   }
  68   _min_heap_delta_bytes = MinHeapDeltaBytes;
  69   _capacity_at_prologue = initial_byte_size;
  70   _used_at_prologue = 0;
  71 }
  72 
  73 bool CardGeneration::grow_by(size_t bytes) {
  74   assert_correct_size_change_locking();
  75   bool result = _virtual_space.expand_by(bytes);
  76   if (result) {
  77     size_t new_word_size =
  78        heap_word_size(_virtual_space.committed_size());
  79     MemRegion mr(space()->bottom(), new_word_size);
  80     // Expand card table
  81     GenCollectedHeap::heap()->barrier_set()->resize_covered_region(mr);
  82     // Expand shared block offset array
  83     _bts->resize(new_word_size);
  84 
  85     // Fix for bug #4668531
  86     if (ZapUnusedHeapArea) {
  87       MemRegion mangle_region(space()->end(),
  88       (HeapWord*)_virtual_space.high());
  89       SpaceMangler::mangle_region(mangle_region);
  90     }
  91 
  92     // Expand space -- also expands space's BOT
  93     // (which uses (part of) shared array above)
  94     space()->set_end((HeapWord*)_virtual_space.high());
  95 
  96     // update the space and generation capacity counters
  97     update_counters();
  98 
  99     if (Verbose && PrintGC) {
 100       size_t new_mem_size = _virtual_space.committed_size();
 101       size_t old_mem_size = new_mem_size - bytes;


 153   return success;
 154 }
 155 
 156 void CardGeneration::shrink(size_t bytes) {
 157   assert_correct_size_change_locking();
 158 
 159   size_t size = ReservedSpace::page_align_size_down(bytes);
 160   if (size == 0) {
 161     return;
 162   }
 163 
 164   // Shrink committed space
 165   _virtual_space.shrink_by(size);
 166   // Shrink space; this also shrinks the space's BOT
 167   space()->set_end((HeapWord*) _virtual_space.high());
 168   size_t new_word_size = heap_word_size(space()->capacity());
 169   // Shrink the shared block offset array
 170   _bts->resize(new_word_size);
 171   MemRegion mr(space()->bottom(), new_word_size);
 172   // Shrink the card table
 173   GenCollectedHeap::heap()->barrier_set()->resize_covered_region(mr);
 174 
 175   if (Verbose && PrintGC) {
 176     size_t new_mem_size = _virtual_space.committed_size();
 177     size_t old_mem_size = new_mem_size + size;
 178     gclog_or_tty->print_cr("Shrinking %s from " SIZE_FORMAT "K to " SIZE_FORMAT "K",
 179                   name(), old_mem_size/K, new_mem_size/K);
 180   }
 181 }
 182 
 183 // No young generation references, clear this generation's cards.
 184 void CardGeneration::clear_remembered_set() {
 185   _rs->clear(reserved());
 186 }
 187 
 188 // Objects in this generation may have moved, invalidate this
 189 // generation's cards.
 190 void CardGeneration::invalidate_remembered_set() {
 191   _rs->invalidate(used_region());
 192 }
 193 


< prev index next >