hotspot/src/share/vm/memory/cardGeneration.cpp
changeset 28033 ab63acbd99ec
parent 28031 10aec24d2b61
child 30173 13cf7580b000
equal deleted inserted replaced
28032:195f814dfa62 28033:ab63acbd99ec
    21  * questions.
    21  * questions.
    22  *
    22  *
    23  */
    23  */
    24 
    24 
    25 #include "precompiled.hpp"
    25 #include "precompiled.hpp"
       
    26 
    26 #include "memory/blockOffsetTable.inline.hpp"
    27 #include "memory/blockOffsetTable.inline.hpp"
       
    28 #include "memory/cardGeneration.inline.hpp"
    27 #include "memory/gcLocker.hpp"
    29 #include "memory/gcLocker.hpp"
    28 #include "memory/generationSpec.hpp"
    30 #include "memory/generationSpec.hpp"
    29 #include "memory/genOopClosures.inline.hpp"
    31 #include "memory/genOopClosures.inline.hpp"
    30 #include "memory/genRemSet.hpp"
    32 #include "memory/genRemSet.hpp"
    31 #include "memory/iterator.hpp"
    33 #include "memory/iterator.hpp"
    47   MemRegion reserved_mr(start, heap_word_size(reserved_byte_size));
    49   MemRegion reserved_mr(start, heap_word_size(reserved_byte_size));
    48   _bts = new BlockOffsetSharedArray(reserved_mr,
    50   _bts = new BlockOffsetSharedArray(reserved_mr,
    49                                     heap_word_size(initial_byte_size));
    51                                     heap_word_size(initial_byte_size));
    50   MemRegion committed_mr(start, heap_word_size(initial_byte_size));
    52   MemRegion committed_mr(start, heap_word_size(initial_byte_size));
    51   _rs->resize_covered_region(committed_mr);
    53   _rs->resize_covered_region(committed_mr);
    52   if (_bts == NULL)
    54   if (_bts == NULL) {
    53     vm_exit_during_initialization("Could not allocate a BlockOffsetArray");
    55     vm_exit_during_initialization("Could not allocate a BlockOffsetArray");
       
    56   }
    54 
    57 
    55   // Verify that the start and end of this generation is the start of a card.
    58   // Verify that the start and end of this generation is the start of a card.
    56   // If this wasn't true, a single card could span more than on generation,
    59   // If this wasn't true, a single card could span more than on generation,
    57   // which would cause problems when we commit/uncommit memory, and when we
    60   // which would cause problems when we commit/uncommit memory, and when we
    58   // clear and dirty cards.
    61   // clear and dirty cards.
    65   _min_heap_delta_bytes = MinHeapDeltaBytes;
    68   _min_heap_delta_bytes = MinHeapDeltaBytes;
    66   _capacity_at_prologue = initial_byte_size;
    69   _capacity_at_prologue = initial_byte_size;
    67   _used_at_prologue = 0;
    70   _used_at_prologue = 0;
    68 }
    71 }
    69 
    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;
       
   102       gclog_or_tty->print_cr("Expanding %s from " SIZE_FORMAT "K by "
       
   103                       SIZE_FORMAT "K to " SIZE_FORMAT "K",
       
   104                       name(), old_mem_size/K, bytes/K, new_mem_size/K);
       
   105     }
       
   106   }
       
   107   return result;
       
   108 }
       
   109 
    70 bool CardGeneration::expand(size_t bytes, size_t expand_bytes) {
   110 bool CardGeneration::expand(size_t bytes, size_t expand_bytes) {
    71   assert_locked_or_safepoint(Heap_lock);
   111   assert_locked_or_safepoint(Heap_lock);
    72   if (bytes == 0) {
   112   if (bytes == 0) {
    73     return true;  // That's what grow_by(0) would return
   113     return true;  // That's what grow_by(0) would return
    74   }
   114   }
    98       gclog_or_tty->print_cr("Garbage collection disabled, expanded heap instead");
   138       gclog_or_tty->print_cr("Garbage collection disabled, expanded heap instead");
    99     }
   139     }
   100   }
   140   }
   101 
   141 
   102   return success;
   142   return success;
       
   143 }
       
   144 
       
   145 bool CardGeneration::grow_to_reserved() {
       
   146   assert_correct_size_change_locking();
       
   147   bool success = true;
       
   148   const size_t remaining_bytes = _virtual_space.uncommitted_size();
       
   149   if (remaining_bytes > 0) {
       
   150     success = grow_by(remaining_bytes);
       
   151     DEBUG_ONLY(if (!success) warning("grow to reserved failed");)
       
   152   }
       
   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   }
   103 }
   181 }
   104 
   182 
   105 // No young generation references, clear this generation's cards.
   183 // No young generation references, clear this generation's cards.
   106 void CardGeneration::clear_remembered_set() {
   184 void CardGeneration::clear_remembered_set() {
   107   _rs->clear(reserved());
   185   _rs->clear(reserved());
   267   }
   345   }
   268 }
   346 }
   269 
   347 
   270 // Currently nothing to do.
   348 // Currently nothing to do.
   271 void CardGeneration::prepare_for_verify() {}
   349 void CardGeneration::prepare_for_verify() {}
       
   350 
       
   351 void CardGeneration::space_iterate(SpaceClosure* blk,
       
   352                                                  bool usedOnly) {
       
   353   blk->do_space(space());
       
   354 }
       
   355 
       
   356 void CardGeneration::younger_refs_iterate(OopsInGenClosure* blk) {
       
   357   blk->set_generation(this);
       
   358   younger_refs_in_space_iterate(space(), blk);
       
   359   blk->reset_generation();
       
   360 }