< prev index next >

src/share/vm/gc_implementation/g1/g1InCSetState.hpp

Print this page




  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_IMPLEMENTATION_G1_G1INCSETSTATE_HPP
  26 #define SHARE_VM_GC_IMPLEMENTATION_G1_G1INCSETSTATE_HPP
  27 
  28 #include "gc_implementation/g1/g1BiasedArray.hpp"
  29 #include "memory/allocation.hpp"
  30 
  31 // Per-region state during garbage collection.
  32 struct InCSetState {

  33   // We use different types to represent the state value. Particularly SPARC puts
  34   // values in structs from "left to right", i.e. MSB to LSB. This results in many
  35   // unnecessary shift operations when loading and storing values of this type.
  36   // This degrades performance significantly (>10%) on that platform.
  37   // Other tested ABIs do not seem to have this problem, and actually tend to
  38   // favor smaller types, so we use the smallest usable type there.
  39   SPARC_ONLY(typedef intptr_t in_cset_state_t;)
  40   NOT_SPARC(typedef int8_t in_cset_state_t;)
  41 





  42   in_cset_state_t _value;
  43  public:
  44   enum {
  45     // Selection of the values were driven to micro-optimize the encoding and
  46     // frequency of the checks.
  47     // The most common check is whether the region is in the collection set or not.
  48     // This encoding allows us to use an != 0 check which in some architectures
  49     // (x86*) can be encoded slightly more efficently than a normal comparison
  50     // against zero.
  51     // The same situation occurs when checking whether the region is humongous
  52     // or not, which is encoded by values < 0.
  53     // The other values are simply encoded in increasing generation order, which
  54     // makes getting the next generation fast by a simple increment.
  55     Humongous    = -1,    // The region is humongous - note that actually any value < 0 would be possible here.
  56     NotInCSet    =  0,    // The region is not in the collection set.
  57     Young        =  1,    // The region is in the collection set and a young region.
  58     Old          =  2,    // The region is in the collection set and an old region.
  59     Num
  60   };
  61 
  62   InCSetState() { _value = NotInCSet; }
  63   InCSetState(in_cset_state_t value)   { _value = value; }

  64 
  65   in_cset_state_t value() const        { return _value; }
  66 
  67   void set_old()                       { _value = Old; }
  68 
  69   bool is_not_in_cset() const          { return _value == NotInCSet; }
  70   bool is_in_cset_or_humongous() const { return _value != NotInCSet; }
  71   bool is_in_cset() const              { return _value > NotInCSet; }
  72   bool is_humongous() const            { return _value < NotInCSet; }
  73   bool is_young() const                { return _value == Young; }
  74   bool is_old() const                  { return _value == Old; }
  75 
  76 #ifdef ASSERT
  77   bool is_default() const              { return is_not_in_cset(); }
  78   bool is_valid() const                { return _value < Num; }
  79   bool is_valid_gen() const            { return (_value >= Young && _value <= Old); }
  80 #endif
  81 };
  82 
  83 // Instances of this class are used for quick tests on whether a reference points
  84 // into the collection set and into which generation or is a humongous object
  85 //
  86 // Each of the array's elements indicates whether the corresponding region is in
  87 // the collection set and if so in which generation, or a humongous region.
  88 //
  89 // We use this to speed up reference processing during young collection and
  90 // quickly reclaim humongous objects. For the latter, by making a humongous region
  91 // succeed this test, we sort-of add it to the collection set. During the reference
  92 // iteration closures, when we see a humongous region, we then simply mark it as
  93 // referenced, i.e. live.
  94 class G1InCSetStateFastTestBiasedMappedArray : public G1BiasedMappedArray<InCSetState> {
  95  protected:
  96   InCSetState default_value() const { return InCSetState::NotInCSet; }
  97  public:
  98   void set_humongous(uintptr_t index) {
  99     assert(get_by_index(index).is_default(),
 100            err_msg("State at index " INTPTR_FORMAT" should be default but is %d", index, get_by_index(index).value()));
 101     set_by_index(index, InCSetState::Humongous);
 102   }
 103 
 104   void clear_humongous(uintptr_t index) {
 105     set_by_index(index, InCSetState::NotInCSet);
 106   }
 107 
 108   void set_in_young(uintptr_t index) {
 109     assert(get_by_index(index).is_default(),
 110            err_msg("State at index " INTPTR_FORMAT" should be default but is %d", index, get_by_index(index).value()));
 111     set_by_index(index, InCSetState::Young);
 112   }
 113 
 114   void set_in_old(uintptr_t index) {
 115     assert(get_by_index(index).is_default(),
 116            err_msg("State at index " INTPTR_FORMAT" should be default but is %d", index, get_by_index(index).value()));
 117     set_by_index(index, InCSetState::Old);
 118   }
 119 
 120   bool is_in_cset_or_humongous(HeapWord* addr) const { return at(addr).is_in_cset_or_humongous(); }
 121   bool is_in_cset(HeapWord* addr) const { return at(addr).is_in_cset(); }
 122   InCSetState at(HeapWord* addr) const { return get_by_address(addr); }
 123   void clear() { G1BiasedMappedArray<InCSetState>::clear(); }
 124 };
 125 
 126 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1INCSETSTATE_HPP


  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_IMPLEMENTATION_G1_G1INCSETSTATE_HPP
  26 #define SHARE_VM_GC_IMPLEMENTATION_G1_G1INCSETSTATE_HPP
  27 
  28 #include "gc_implementation/g1/g1BiasedArray.hpp"
  29 #include "memory/allocation.hpp"
  30 
  31 // Per-region state during garbage collection.
  32 struct InCSetState {
  33  public:
  34   // We use different types to represent the state value. Particularly SPARC puts
  35   // values in structs from "left to right", i.e. MSB to LSB. This results in many
  36   // unnecessary shift operations when loading and storing values of this type.
  37   // This degrades performance significantly (>10%) on that platform.
  38   // Other tested ABIs do not seem to have this problem, and actually tend to
  39   // favor smaller types, so we use the smallest usable type there.
  40 #ifdef SPARC
  41   #define CSETSTATE_FORMAT INTPTR_FORMAT
  42   typedef intptr_t in_cset_state_t;
  43 #else
  44   #define CSETSTATE_FORMAT "%d"
  45   typedef int8_t in_cset_state_t;
  46 #endif
  47  private:
  48   in_cset_state_t _value;
  49  public:
  50   enum {
  51     // Selection of the values were driven to micro-optimize the encoding and
  52     // frequency of the checks.
  53     // The most common check is whether the region is in the collection set or not.
  54     // This encoding allows us to use an != 0 check which in some architectures
  55     // (x86*) can be encoded slightly more efficently than a normal comparison
  56     // against zero.
  57     // The same situation occurs when checking whether the region is humongous
  58     // or not, which is encoded by values < 0.
  59     // The other values are simply encoded in increasing generation order, which
  60     // makes getting the next generation fast by a simple increment.
  61     Humongous    = -1,    // The region is humongous - note that actually any value < 0 would be possible here.
  62     NotInCSet    =  0,    // The region is not in the collection set.
  63     Young        =  1,    // The region is in the collection set and a young region.
  64     Old          =  2,    // The region is in the collection set and an old region.
  65     Num
  66   };
  67 
  68   InCSetState(in_cset_state_t value = NotInCSet) : _value(value) {
  69     assert(is_valid(), err_msg("Invalid state %d", _value));
  70   }
  71 
  72   in_cset_state_t value() const        { return _value; }
  73 
  74   void set_old()                       { _value = Old; }
  75 

  76   bool is_in_cset_or_humongous() const { return _value != NotInCSet; }
  77   bool is_in_cset() const              { return _value > NotInCSet; }
  78   bool is_humongous() const            { return _value < NotInCSet; }
  79   bool is_young() const                { return _value == Young; }
  80   bool is_old() const                  { return _value == Old; }
  81 
  82 #ifdef ASSERT
  83   bool is_default() const              { return !is_in_cset_or_humongous(); }
  84   bool is_valid() const                { return (_value >= Humongous) && (_value < Num); }
  85   bool is_valid_gen() const            { return (_value >= Young && _value <= Old); }
  86 #endif
  87 };
  88 
  89 // Instances of this class are used for quick tests on whether a reference points
  90 // into the collection set and into which generation or is a humongous object
  91 //
  92 // Each of the array's elements indicates whether the corresponding region is in
  93 // the collection set and if so in which generation, or a humongous region.
  94 //
  95 // We use this to speed up reference processing during young collection and
  96 // quickly reclaim humongous objects. For the latter, by making a humongous region
  97 // succeed this test, we sort-of add it to the collection set. During the reference
  98 // iteration closures, when we see a humongous region, we then simply mark it as
  99 // referenced, i.e. live.
 100 class G1InCSetStateFastTestBiasedMappedArray : public G1BiasedMappedArray<InCSetState> {
 101  protected:
 102   InCSetState default_value() const { return InCSetState::NotInCSet; }
 103  public:
 104   void set_humongous(uintptr_t index) {
 105     assert(get_by_index(index).is_default(),
 106            err_msg("State at index " INTPTR_FORMAT" should be default but is " CSETSTATE_FORMAT, index, get_by_index(index).value()));
 107     set_by_index(index, InCSetState::Humongous);
 108   }
 109 
 110   void clear_humongous(uintptr_t index) {
 111     set_by_index(index, InCSetState::NotInCSet);
 112   }
 113 
 114   void set_in_young(uintptr_t index) {
 115     assert(get_by_index(index).is_default(),
 116            err_msg("State at index " INTPTR_FORMAT" should be default but is " CSETSTATE_FORMAT, index, get_by_index(index).value()));
 117     set_by_index(index, InCSetState::Young);
 118   }
 119 
 120   void set_in_old(uintptr_t index) {
 121     assert(get_by_index(index).is_default(),
 122            err_msg("State at index " INTPTR_FORMAT" should be default but is " CSETSTATE_FORMAT, index, get_by_index(index).value()));
 123     set_by_index(index, InCSetState::Old);
 124   }
 125 
 126   bool is_in_cset_or_humongous(HeapWord* addr) const { return at(addr).is_in_cset_or_humongous(); }
 127   bool is_in_cset(HeapWord* addr) const { return at(addr).is_in_cset(); }
 128   InCSetState at(HeapWord* addr) const { return get_by_address(addr); }
 129   void clear() { G1BiasedMappedArray<InCSetState>::clear(); }
 130 };
 131 
 132 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1INCSETSTATE_HPP
< prev index next >