< prev index next >

src/share/vm/gc/shared/cardGeneration.cpp

Print this page




  93     // Expand space -- also expands space's BOT
  94     // (which uses (part of) shared array above)
  95     space()->set_end((HeapWord*)_virtual_space.high());
  96 
  97     // update the space and generation capacity counters
  98     update_counters();
  99 
 100     size_t new_mem_size = _virtual_space.committed_size();
 101     size_t old_mem_size = new_mem_size - bytes;
 102     log_trace(gc, heap)("Expanding %s from " SIZE_FORMAT "K by " SIZE_FORMAT "K to " SIZE_FORMAT "K",
 103                     name(), old_mem_size/K, bytes/K, new_mem_size/K);
 104   }
 105   return result;
 106 }
 107 
 108 bool CardGeneration::expand(size_t bytes, size_t expand_bytes) {
 109   assert_locked_or_safepoint(Heap_lock);
 110   if (bytes == 0) {
 111     return true;  // That's what grow_by(0) would return
 112   }
 113   size_t aligned_bytes  = ReservedSpace::page_align_size_up(bytes);
 114   if (aligned_bytes == 0){
 115     // The alignment caused the number of bytes to wrap.  An expand_by(0) will
 116     // return true with the implication that an expansion was done when it
 117     // was not.  A call to expand implies a best effort to expand by "bytes"
 118     // but not a guarantee.  Align down to give a best effort.  This is likely
 119     // the most that the generation can expand since it has some capacity to
 120     // start with.
 121     aligned_bytes = ReservedSpace::page_align_size_down(bytes);
 122   }
 123   size_t aligned_expand_bytes = ReservedSpace::page_align_size_up(expand_bytes);
 124   bool success = false;
 125   if (aligned_expand_bytes > aligned_bytes) {
 126     success = grow_by(aligned_expand_bytes);
 127   }
 128   if (!success) {
 129     success = grow_by(aligned_bytes);
 130   }
 131   if (!success) {
 132     success = grow_to_reserved();
 133   }
 134   if (success && GCLocker::is_active_and_needs_gc()) {
 135     log_trace(gc, heap)("Garbage collection disabled, expanded heap instead");
 136   }
 137 
 138   return success;
 139 }
 140 
 141 bool CardGeneration::grow_to_reserved() {
 142   assert_correct_size_change_locking();
 143   bool success = true;
 144   const size_t remaining_bytes = _virtual_space.uncommitted_size();
 145   if (remaining_bytes > 0) {
 146     success = grow_by(remaining_bytes);
 147     DEBUG_ONLY(if (!success) log_warning(gc)("grow to reserved failed");)
 148   }
 149   return success;
 150 }
 151 
 152 void CardGeneration::shrink(size_t bytes) {
 153   assert_correct_size_change_locking();
 154 
 155   size_t size = ReservedSpace::page_align_size_down(bytes);
 156   if (size == 0) {
 157     return;
 158   }
 159 
 160   // Shrink committed space
 161   _virtual_space.shrink_by(size);
 162   // Shrink space; this also shrinks the space's BOT
 163   space()->set_end((HeapWord*) _virtual_space.high());
 164   size_t new_word_size = heap_word_size(space()->capacity());
 165   // Shrink the shared block offset array
 166   _bts->resize(new_word_size);
 167   MemRegion mr(space()->bottom(), new_word_size);
 168   // Shrink the card table
 169   GenCollectedHeap::heap()->barrier_set()->resize_covered_region(mr);
 170 
 171   size_t new_mem_size = _virtual_space.committed_size();
 172   size_t old_mem_size = new_mem_size + size;
 173   log_trace(gc, heap)("Shrinking %s from " SIZE_FORMAT "K to " SIZE_FORMAT "K",
 174                       name(), old_mem_size/K, new_mem_size/K);
 175 }




  93     // Expand space -- also expands space's BOT
  94     // (which uses (part of) shared array above)
  95     space()->set_end((HeapWord*)_virtual_space.high());
  96 
  97     // update the space and generation capacity counters
  98     update_counters();
  99 
 100     size_t new_mem_size = _virtual_space.committed_size();
 101     size_t old_mem_size = new_mem_size - bytes;
 102     log_trace(gc, heap)("Expanding %s from " SIZE_FORMAT "K by " SIZE_FORMAT "K to " SIZE_FORMAT "K",
 103                     name(), old_mem_size/K, bytes/K, new_mem_size/K);
 104   }
 105   return result;
 106 }
 107 
 108 bool CardGeneration::expand(size_t bytes, size_t expand_bytes) {
 109   assert_locked_or_safepoint(Heap_lock);
 110   if (bytes == 0) {
 111     return true;  // That's what grow_by(0) would return
 112   }
 113   size_t aligned_bytes  = ReservedSpace::page_align_up(bytes);
 114   if (aligned_bytes == 0){
 115     // The alignment caused the number of bytes to wrap.  An expand_by(0) will
 116     // return true with the implication that an expansion was done when it
 117     // was not.  A call to expand implies a best effort to expand by "bytes"
 118     // but not a guarantee.  Align down to give a best effort.  This is likely
 119     // the most that the generation can expand since it has some capacity to
 120     // start with.
 121     aligned_bytes = ReservedSpace::page_align_down(bytes);
 122   }
 123   size_t aligned_expand_bytes = ReservedSpace::page_align_up(expand_bytes);
 124   bool success = false;
 125   if (aligned_expand_bytes > aligned_bytes) {
 126     success = grow_by(aligned_expand_bytes);
 127   }
 128   if (!success) {
 129     success = grow_by(aligned_bytes);
 130   }
 131   if (!success) {
 132     success = grow_to_reserved();
 133   }
 134   if (success && GCLocker::is_active_and_needs_gc()) {
 135     log_trace(gc, heap)("Garbage collection disabled, expanded heap instead");
 136   }
 137 
 138   return success;
 139 }
 140 
 141 bool CardGeneration::grow_to_reserved() {
 142   assert_correct_size_change_locking();
 143   bool success = true;
 144   const size_t remaining_bytes = _virtual_space.uncommitted_size();
 145   if (remaining_bytes > 0) {
 146     success = grow_by(remaining_bytes);
 147     DEBUG_ONLY(if (!success) log_warning(gc)("grow to reserved failed");)
 148   }
 149   return success;
 150 }
 151 
 152 void CardGeneration::shrink(size_t bytes) {
 153   assert_correct_size_change_locking();
 154 
 155   size_t size = ReservedSpace::page_align_down(bytes);
 156   if (size == 0) {
 157     return;
 158   }
 159 
 160   // Shrink committed space
 161   _virtual_space.shrink_by(size);
 162   // Shrink space; this also shrinks the space's BOT
 163   space()->set_end((HeapWord*) _virtual_space.high());
 164   size_t new_word_size = heap_word_size(space()->capacity());
 165   // Shrink the shared block offset array
 166   _bts->resize(new_word_size);
 167   MemRegion mr(space()->bottom(), new_word_size);
 168   // Shrink the card table
 169   GenCollectedHeap::heap()->barrier_set()->resize_covered_region(mr);
 170 
 171   size_t new_mem_size = _virtual_space.committed_size();
 172   size_t old_mem_size = new_mem_size + size;
 173   log_trace(gc, heap)("Shrinking %s from " SIZE_FORMAT "K to " SIZE_FORMAT "K",
 174                       name(), old_mem_size/K, new_mem_size/K);
 175 }


< prev index next >