< prev index next >

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

Print this page
rev 7472 : [mq]: 8060025-mikael-review1
rev 7473 : imported patch mikael-refactor-cset-state

@@ -26,15 +26,23 @@
 #define SHARE_VM_GC_IMPLEMENTATION_G1_G1INCSETSTATE_HPP
 
 #include "gc_implementation/g1/g1BiasedArray.hpp"
 #include "memory/allocation.hpp"
 
-typedef int8_t in_cset_state_t;
+// Per-region state during garbage collection.
+struct InCSetState {
+  // We use different types to represent the state value. Particularly SPARC puts
+  // values in structs from "left to right", i.e. MSB to LSB. This results in many
+  // unnecessary shift operations when loading and storing values of this type.
+  // This degrades performance significantly (>10%) on that platform.
+  // Other tested ABIs do not seem to have this problem, and actually tend to
+  // favor smaller types, so we use the smallest usable type there.
+  SPARC_ONLY(typedef intptr_t in_cset_state_t;)
+  NOT_SPARC(typedef int8_t in_cset_state_t;)
 
-// Helper class used to examine in_cset_t values.
-class InCSetState : AllStatic {
-public:
+  in_cset_state_t _value;
+ public:
   enum {
     // Selection of the values were driven to micro-optimize the encoding and
     // frequency of the checks.
     // The most common check is whether the region is in the collection set or not.
     // This encoding allows us to use an != 0 check which in some architectures

@@ -49,14 +57,29 @@
     Young        =  1,    // The region is in the collection set and a young region.
     Old          =  2,    // The region is in the collection set and an old region.
     Num
   };
 
-  static bool is_not_in_cset(in_cset_state_t state) { return state == NotInCSet; }
-  static bool is_in_cset_or_humongous(in_cset_state_t state) { return state != NotInCSet; }
-  static bool is_in_cset(in_cset_state_t state) { return state > NotInCSet; }
-  static bool is_humongous(in_cset_state_t state) { return state < NotInCSet; }
+  InCSetState() { _value = NotInCSet; }
+  InCSetState(in_cset_state_t value)   { _value = value; }
+
+  in_cset_state_t value() const        { return _value; }
+
+  void set_old()                       { _value = Old; }
+
+  bool is_not_in_cset() const          { return _value == NotInCSet; }
+  bool is_in_cset_or_humongous() const { return _value != NotInCSet; }
+  bool is_in_cset() const              { return _value > NotInCSet; }
+  bool is_humongous() const            { return _value < NotInCSet; }
+  bool is_young() const                { return _value == Young; }
+  bool is_old() const                  { return _value == Old; }
+
+#ifdef ASSERT
+  bool is_default() const              { return is_not_in_cset(); }
+  bool is_valid() const                { return _value < Num; }
+  bool is_valid_gen() const            { return (_value >= Young && _value <= Old); }
+#endif
 };
 
 // Instances of this class are used for quick tests on whether a reference points
 // into the collection set and into which generation or is a humongous object
 //

@@ -66,35 +89,38 @@
 // We use this to speed up reference processing during young collection and
 // quickly reclaim humongous objects. For the latter, by making a humongous region
 // succeed this test, we sort-of add it to the collection set. During the reference
 // iteration closures, when we see a humongous region, we then simply mark it as
 // referenced, i.e. live.
-class G1InCSetStateFastTestBiasedMappedArray : public G1BiasedMappedArray<in_cset_state_t> {
+class G1InCSetStateFastTestBiasedMappedArray : public G1BiasedMappedArray<InCSetState> {
  protected:
-  in_cset_state_t default_value() const { return InCSetState::NotInCSet; }
+  InCSetState default_value() const { return InCSetState::NotInCSet; }
  public:
   void set_humongous(uintptr_t index) {
-    assert(get_by_index(index) == default_value(), "should be default");
+    assert(get_by_index(index).is_default(),
+           err_msg("State at index " INTPTR_FORMAT" should be default but is %d", index, get_by_index(index).value()));
     set_by_index(index, InCSetState::Humongous);
   }
 
   void clear_humongous(uintptr_t index) {
     set_by_index(index, InCSetState::NotInCSet);
   }
 
   void set_in_young(uintptr_t index) {
-    assert(get_by_index(index) == default_value(), "should be default");
+    assert(get_by_index(index).is_default(),
+           err_msg("State at index " INTPTR_FORMAT" should be default but is %d", index, get_by_index(index).value()));
     set_by_index(index, InCSetState::Young);
   }
 
   void set_in_old(uintptr_t index) {
-    assert(get_by_index(index) == default_value(), "should be default");
+    assert(get_by_index(index).is_default(),
+           err_msg("State at index " INTPTR_FORMAT" should be default but is %d", index, get_by_index(index).value()));
     set_by_index(index, InCSetState::Old);
   }
 
-  bool is_in_cset_or_humongous(HeapWord* addr) const { return InCSetState::is_in_cset_or_humongous(at(addr)); }
-  bool is_in_cset(HeapWord* addr) const { return InCSetState::is_in_cset(at(addr)); }
-  in_cset_state_t at(HeapWord* addr) const { return (in_cset_state_t) get_by_address(addr); }
-  void clear() { G1BiasedMappedArray<in_cset_state_t>::clear(); }
+  bool is_in_cset_or_humongous(HeapWord* addr) const { return at(addr).is_in_cset_or_humongous(); }
+  bool is_in_cset(HeapWord* addr) const { return at(addr).is_in_cset(); }
+  InCSetState at(HeapWord* addr) const { return get_by_address(addr); }
+  void clear() { G1BiasedMappedArray<InCSetState>::clear(); }
 };
 
 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1INCSETSTATE_HPP
< prev index next >