< prev index next >

src/share/vm/gc/parallel/parMarkBitMap.hpp

Print this page
rev 9846 : [mq]: par-scav-patch
rev 9847 : 8146987: Improve Parallel GC Full GC by caching results of live_words_in_range()
Summary: A large part of time in the parallel scavenge collector is spent finding out the amount of live words within memory ranges to find out where to move an object to. Try to incrementally calculate this value.
Reviewed-by: tschatzl, mgerdin
Contributed-by: ray alex <sky1young@gmail.com>
   1 /*
   2  * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  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 #ifndef SHARE_VM_GC_PARALLEL_PARMARKBITMAP_HPP
  26 #define SHARE_VM_GC_PARALLEL_PARMARKBITMAP_HPP
  27 
  28 #include "memory/memRegion.hpp"
  29 #include "oops/oop.hpp"
  30 #include "utilities/bitMap.hpp"
  31 
  32 class ParMarkBitMapClosure;
  33 class PSVirtualSpace;

  34 
  35 class ParMarkBitMap: public CHeapObj<mtGC>
  36 {
  37 public:
  38   typedef BitMap::idx_t idx_t;
  39 
  40   // Values returned by the iterate() methods.
  41   enum IterationStatus { incomplete, complete, full, would_overflow };
  42 
  43   inline ParMarkBitMap();
  44   bool initialize(MemRegion covered_region);
  45 
  46   // Atomically mark an object as live.
  47   bool mark_obj(HeapWord* addr, size_t size);
  48   inline bool mark_obj(oop obj, int size);
  49 
  50   // Return whether the specified begin or end bit is set.
  51   inline bool is_obj_beg(idx_t bit) const;
  52   inline bool is_obj_end(idx_t bit) const;
  53 


 107   // marked, then dead space begins at that point and the dead_closure is
 108   // applied.  Thus callers must ensure that range_beg is not in the middle of a
 109   // live object.
 110   IterationStatus iterate(ParMarkBitMapClosure* live_closure,
 111                           ParMarkBitMapClosure* dead_closure,
 112                           idx_t range_beg, idx_t range_end,
 113                           idx_t dead_range_end) const;
 114   inline IterationStatus iterate(ParMarkBitMapClosure* live_closure,
 115                                  ParMarkBitMapClosure* dead_closure,
 116                                  HeapWord* range_beg,
 117                                  HeapWord* range_end,
 118                                  HeapWord* dead_range_end) const;
 119 
 120   // Return the number of live words in the range [beg_addr, end_obj) due to
 121   // objects that start in the range.  If a live object extends onto the range,
 122   // the caller must detect and account for any live words due to that object.
 123   // If a live object extends beyond the end of the range, only the words within
 124   // the range are included in the result. The end of the range must be a live object,
 125   // which is the case when updating pointers.  This allows a branch to be removed
 126   // from inside the loop.
 127   size_t live_words_in_range(HeapWord* beg_addr, oop end_obj) const;
 128 
 129   inline HeapWord* region_start() const;
 130   inline HeapWord* region_end() const;
 131   inline size_t    region_size() const;
 132   inline size_t    size() const;
 133 
 134   size_t reserved_byte_size() const { return _reserved_byte_size; }
 135 
 136   // Convert a heap address to/from a bit index.
 137   inline idx_t     addr_to_bit(HeapWord* addr) const;
 138   inline HeapWord* bit_to_addr(idx_t bit) const;
 139 
 140   // Return the bit index of the first marked object that begins (or ends,
 141   // respectively) in the range [beg, end).  If no object is found, return end.
 142   inline idx_t find_obj_beg(idx_t beg, idx_t end) const;
 143   inline idx_t find_obj_end(idx_t beg, idx_t end) const;
 144 
 145   inline HeapWord* find_obj_beg(HeapWord* beg, HeapWord* end) const;
 146   inline HeapWord* find_obj_end(HeapWord* beg, HeapWord* end) const;
 147 


 150   inline void clear_range(idx_t beg, idx_t end);
 151 
 152   // Return the number of bits required to represent the specified number of
 153   // HeapWords, or the specified region.
 154   static inline idx_t bits_required(size_t words);
 155   static inline idx_t bits_required(MemRegion covered_region);
 156 
 157   void print_on_error(outputStream* st) const {
 158     st->print_cr("Marking Bits: (ParMarkBitMap*) " PTR_FORMAT, p2i(this));
 159     _beg_bits.print_on_error(st, " Begin Bits: ");
 160     _end_bits.print_on_error(st, " End Bits:   ");
 161   }
 162 
 163 #ifdef  ASSERT
 164   void verify_clear() const;
 165   inline void verify_bit(idx_t bit) const;
 166   inline void verify_addr(HeapWord* addr) const;
 167 #endif  // #ifdef ASSERT
 168 
 169 private:






 170   // Each bit in the bitmap represents one unit of 'object granularity.' Objects
 171   // are double-word aligned in 32-bit VMs, but not in 64-bit VMs, so the 32-bit
 172   // granularity is 2, 64-bit is 1.
 173   static inline size_t obj_granularity() { return size_t(MinObjAlignment); }
 174   static inline int obj_granularity_shift() { return LogMinObjAlignment; }
 175 
 176   HeapWord*       _region_start;
 177   size_t          _region_size;
 178   BitMap          _beg_bits;
 179   BitMap          _end_bits;
 180   PSVirtualSpace* _virtual_space;
 181   size_t          _reserved_byte_size;
 182 };
 183 
 184 inline ParMarkBitMap::ParMarkBitMap():
 185   _beg_bits(), _end_bits(), _region_start(NULL), _region_size(0), _virtual_space(NULL), _reserved_byte_size(0)
 186 { }
 187 
 188 inline void ParMarkBitMap::clear_range(idx_t beg, idx_t end)
 189 {


   1 /*
   2  * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  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 #ifndef SHARE_VM_GC_PARALLEL_PARMARKBITMAP_HPP
  26 #define SHARE_VM_GC_PARALLEL_PARMARKBITMAP_HPP
  27 
  28 #include "memory/memRegion.hpp"
  29 #include "oops/oop.hpp"
  30 #include "utilities/bitMap.hpp"
  31 
  32 class ParMarkBitMapClosure;
  33 class PSVirtualSpace;
  34 class ParCompactionManager;
  35 
  36 class ParMarkBitMap: public CHeapObj<mtGC>
  37 {
  38 public:
  39   typedef BitMap::idx_t idx_t;
  40 
  41   // Values returned by the iterate() methods.
  42   enum IterationStatus { incomplete, complete, full, would_overflow };
  43 
  44   inline ParMarkBitMap();
  45   bool initialize(MemRegion covered_region);
  46 
  47   // Atomically mark an object as live.
  48   bool mark_obj(HeapWord* addr, size_t size);
  49   inline bool mark_obj(oop obj, int size);
  50 
  51   // Return whether the specified begin or end bit is set.
  52   inline bool is_obj_beg(idx_t bit) const;
  53   inline bool is_obj_end(idx_t bit) const;
  54 


 108   // marked, then dead space begins at that point and the dead_closure is
 109   // applied.  Thus callers must ensure that range_beg is not in the middle of a
 110   // live object.
 111   IterationStatus iterate(ParMarkBitMapClosure* live_closure,
 112                           ParMarkBitMapClosure* dead_closure,
 113                           idx_t range_beg, idx_t range_end,
 114                           idx_t dead_range_end) const;
 115   inline IterationStatus iterate(ParMarkBitMapClosure* live_closure,
 116                                  ParMarkBitMapClosure* dead_closure,
 117                                  HeapWord* range_beg,
 118                                  HeapWord* range_end,
 119                                  HeapWord* dead_range_end) const;
 120 
 121   // Return the number of live words in the range [beg_addr, end_obj) due to
 122   // objects that start in the range.  If a live object extends onto the range,
 123   // the caller must detect and account for any live words due to that object.
 124   // If a live object extends beyond the end of the range, only the words within
 125   // the range are included in the result. The end of the range must be a live object,
 126   // which is the case when updating pointers.  This allows a branch to be removed
 127   // from inside the loop.
 128   size_t live_words_in_range(ParCompactionManager* cm, HeapWord* beg_addr, oop end_obj) const;
 129 
 130   inline HeapWord* region_start() const;
 131   inline HeapWord* region_end() const;
 132   inline size_t    region_size() const;
 133   inline size_t    size() const;
 134 
 135   size_t reserved_byte_size() const { return _reserved_byte_size; }
 136 
 137   // Convert a heap address to/from a bit index.
 138   inline idx_t     addr_to_bit(HeapWord* addr) const;
 139   inline HeapWord* bit_to_addr(idx_t bit) const;
 140 
 141   // Return the bit index of the first marked object that begins (or ends,
 142   // respectively) in the range [beg, end).  If no object is found, return end.
 143   inline idx_t find_obj_beg(idx_t beg, idx_t end) const;
 144   inline idx_t find_obj_end(idx_t beg, idx_t end) const;
 145 
 146   inline HeapWord* find_obj_beg(HeapWord* beg, HeapWord* end) const;
 147   inline HeapWord* find_obj_end(HeapWord* beg, HeapWord* end) const;
 148 


 151   inline void clear_range(idx_t beg, idx_t end);
 152 
 153   // Return the number of bits required to represent the specified number of
 154   // HeapWords, or the specified region.
 155   static inline idx_t bits_required(size_t words);
 156   static inline idx_t bits_required(MemRegion covered_region);
 157 
 158   void print_on_error(outputStream* st) const {
 159     st->print_cr("Marking Bits: (ParMarkBitMap*) " PTR_FORMAT, p2i(this));
 160     _beg_bits.print_on_error(st, " Begin Bits: ");
 161     _end_bits.print_on_error(st, " End Bits:   ");
 162   }
 163 
 164 #ifdef  ASSERT
 165   void verify_clear() const;
 166   inline void verify_bit(idx_t bit) const;
 167   inline void verify_addr(HeapWord* addr) const;
 168 #endif  // #ifdef ASSERT
 169 
 170 private:
 171   size_t live_words_in_range_helper(HeapWord* beg_addr, oop end_obj) const;
 172   
 173   bool is_live_words_in_range_in_cache(ParCompactionManager* cm, HeapWord* beg_addr) const;
 174   size_t live_words_in_range_use_cache(ParCompactionManager* cm, HeapWord* beg_addr, oop end_obj) const;
 175   void update_live_words_in_range_cache(ParCompactionManager* cm, HeapWord* beg_addr, oop end_obj, size_t result) const;
 176 
 177   // Each bit in the bitmap represents one unit of 'object granularity.' Objects
 178   // are double-word aligned in 32-bit VMs, but not in 64-bit VMs, so the 32-bit
 179   // granularity is 2, 64-bit is 1.
 180   static inline size_t obj_granularity() { return size_t(MinObjAlignment); }
 181   static inline int obj_granularity_shift() { return LogMinObjAlignment; }
 182 
 183   HeapWord*       _region_start;
 184   size_t          _region_size;
 185   BitMap          _beg_bits;
 186   BitMap          _end_bits;
 187   PSVirtualSpace* _virtual_space;
 188   size_t          _reserved_byte_size;
 189 };
 190 
 191 inline ParMarkBitMap::ParMarkBitMap():
 192   _beg_bits(), _end_bits(), _region_start(NULL), _region_size(0), _virtual_space(NULL), _reserved_byte_size(0)
 193 { }
 194 
 195 inline void ParMarkBitMap::clear_range(idx_t beg, idx_t end)
 196 {


< prev index next >