hotspot/src/share/vm/memory/specialized_oop_closures.hpp

Print this page
rev 611 : Merge


  45 class Par_MarkRefsIntoAndScanClosure;
  46 class PushAndMarkClosure;
  47 class Par_PushAndMarkClosure;
  48 class PushOrMarkClosure;
  49 class Par_PushOrMarkClosure;
  50 class CMSKeepAliveClosure;
  51 class CMSInnerParMarkAndPushClosure;
  52 
  53 // This macro applies an argument macro to all OopClosures for which we
  54 // want specialized bodies of "oop_oop_iterate".  The arguments to "f" are:
  55 //   "f(closureType, non_virtual)"
  56 // where "closureType" is the name of the particular subclass of OopClosure,
  57 // and "non_virtual" will be the string "_nv" if the closure type should
  58 // have its "do_oop" method invoked non-virtually, or else the
  59 // string "_v".  ("OopClosure" itself will be the only class in the latter
  60 // category.)
  61 
  62 // This is split into several because of a Visual C++ 6.0 compiler bug
  63 // where very long macros cause the compiler to crash
  64 






  65 #define SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_S(f)       \
  66   f(ScanClosure,_nv)                                    \
  67   f(FastScanClosure,_nv)                                \
  68   f(FilteringClosure,_nv)
  69 
  70 #ifndef SERIALGC
  71 #define SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_P(f)       \
  72   f(ParScanWithBarrierClosure,_nv)                      \
  73   f(ParScanWithoutBarrierClosure,_nv)
  74 #else  // SERIALGC
  75 #define SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_P(f)
  76 #endif // SERIALGC
  77 
  78 #define SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_1(f)       \
  79   SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_S(f)             \
  80   SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_P(f)
  81 
  82 #ifndef SERIALGC
  83 #define SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_3(f)       \
  84   f(MarkRefsIntoAndScanClosure,_nv)                     \
  85   f(Par_MarkRefsIntoAndScanClosure,_nv)                 \
  86   f(PushAndMarkClosure,_nv)                             \
  87   f(Par_PushAndMarkClosure,_nv)                         \
  88   f(PushOrMarkClosure,_nv)                              \
  89   f(Par_PushOrMarkClosure,_nv)                          \
  90   f(CMSKeepAliveClosure,_nv)                            \
  91   f(CMSInnerParMarkAndPushClosure,_nv)

  92 #else  // SERIALGC
  93 #define SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_3(f)
  94 #endif // SERIALGC
  95 

  96 // We separate these out, because sometime the general one has
  97 // a different definition from the specialized ones, and sometimes it
  98 // doesn't.
  99 
 100 #define ALL_OOP_OOP_ITERATE_CLOSURES_1(f)               \
 101   f(OopClosure,_v)                                      \
 102   SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_1(f)
 103 
 104 #define ALL_OOP_OOP_ITERATE_CLOSURES_3(f)               \
 105   SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_3(f)
 106 
 107 #ifndef SERIALGC
 108 // This macro applies an argument macro to all OopClosures for which we
 109 // want specialized bodies of a family of methods related to
 110 // "par_oop_iterate".  The arguments to f are the same as above.
 111 // The "root_class" is the most general class to define; this may be
 112 // "OopClosure" in some applications and "OopsInGenClosure" in others.
 113 
 114 #define SPECIALIZED_PAR_OOP_ITERATE_CLOSURES(f)        \
 115   f(MarkRefsIntoAndScanClosure,_nv)                    \
 116   f(PushAndMarkClosure,_nv)                            \
 117   f(Par_MarkRefsIntoAndScanClosure,_nv)                \
 118   f(Par_PushAndMarkClosure,_nv)
 119 
 120 #define ALL_PAR_OOP_ITERATE_CLOSURES(f)                \
 121   f(OopClosure,_v)                                     \
 122   SPECIALIZED_PAR_OOP_ITERATE_CLOSURES(f)
 123 #endif // SERIALGC
 124 
 125 // This macro applies an argument macro to all OopClosures for which we
 126 // want specialized bodies of a family of methods related to
 127 // "oops_since_save_marks_do".  The arguments to f are the same as above.
 128 // The "root_class" is the most general class to define; this may be
 129 // "OopClosure" in some applications and "OopsInGenClosure" in others.
 130 







 131 #define SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES_YOUNG_S(f) \
 132   f(ScanClosure,_nv)                                     \
 133   f(FastScanClosure,_nv)
 134 
 135 #ifndef SERIALGC
 136 #define SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES_YOUNG_P(f) \
 137   f(ParScanWithBarrierClosure,_nv)                       \
 138   f(ParScanWithoutBarrierClosure,_nv)

 139 #else  // SERIALGC
 140 #define SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES_YOUNG_P(f)
 141 #endif // SERIALGC
 142 
 143 #define SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES_YOUNG(f)  \
 144   SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES_YOUNG_S(f)      \
 145   SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES_YOUNG_P(f)
 146 
 147 #define SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES(f)        \
 148   SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES_YOUNG(f)
 149 
 150 // We separate these out, because sometime the general one has
 151 // a different definition from the specialized ones, and sometimes it
 152 // doesn't.
 153 // NOTE:   One of the valid criticisms of this
 154 // specialize-oop_oop_iterate-for-specific-closures idiom is that it is
 155 // easy to have a silent performance bug: if you fail to de-virtualize,
 156 // things still work, just slower.  The "SpecializationStats" mode is
 157 // intended to at least make such a failure easy to detect.
 158 // *Not* using the ALL_SINCE_SAVE_MARKS_CLOSURES(f) macro defined


 165 
 166 #define ALL_SINCE_SAVE_MARKS_CLOSURES(f)                \
 167   f(OopsInGenClosure,_v)                                \
 168   SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES(f)
 169 
 170 // For keeping stats on effectiveness.
 171 #define ENABLE_SPECIALIZATION_STATS 0
 172 
 173 
 174 class SpecializationStats {
 175 public:
 176   enum Kind {
 177     ik,             // instanceKlass
 178     irk,            // instanceRefKlass
 179     oa,             // objArrayKlass
 180     NUM_Kinds
 181   };
 182 
 183 #if ENABLE_SPECIALIZATION_STATS
 184 private:
 185   static int _numCallsAll;


 186 
 187   static int _numCallsTotal[NUM_Kinds];
 188   static int _numCalls_nv[NUM_Kinds];
 189 
 190   static int _numDoOopCallsTotal[NUM_Kinds];
 191   static int _numDoOopCalls_nv[NUM_Kinds];
 192 public:
 193 #endif
 194   static void clear()  PRODUCT_RETURN;
 195 
 196   static inline void record_call()  PRODUCT_RETURN;
 197   static inline void record_iterate_call_v(Kind k)  PRODUCT_RETURN;
 198   static inline void record_iterate_call_nv(Kind k)  PRODUCT_RETURN;
 199   static inline void record_do_oop_call_v(Kind k)  PRODUCT_RETURN;
 200   static inline void record_do_oop_call_nv(Kind k)  PRODUCT_RETURN;
 201 
 202   static void print() PRODUCT_RETURN;
 203 };  
 204 
 205 #ifndef PRODUCT
 206 #if ENABLE_SPECIALIZATION_STATS
 207 
 208 inline void SpecializationStats::record_call() {
 209   _numCallsAll++;;
 210 }
 211 inline void SpecializationStats::record_iterate_call_v(Kind k) {
 212   _numCallsTotal[k]++;
 213 }
 214 inline void SpecializationStats::record_iterate_call_nv(Kind k) {
 215   _numCallsTotal[k]++;
 216   _numCalls_nv[k]++;
 217 }
 218 
 219 inline void SpecializationStats::record_do_oop_call_v(Kind k) {
 220   _numDoOopCallsTotal[k]++;
 221 }
 222 inline void SpecializationStats::record_do_oop_call_nv(Kind k) {
 223   _numDoOopCallsTotal[k]++;
 224   _numDoOopCalls_nv[k]++;
 225 }
 226 
 227 #else   // !ENABLE_SPECIALIZATION_STATS
 228 
 229 inline void SpecializationStats::record_call() {}
 230 inline void SpecializationStats::record_iterate_call_v(Kind k) {}
 231 inline void SpecializationStats::record_iterate_call_nv(Kind k) {}
 232 inline void SpecializationStats::record_do_oop_call_v(Kind k) {}
 233 inline void SpecializationStats::record_do_oop_call_nv(Kind k) {}
 234 inline void SpecializationStats::clear() {}
 235 inline void SpecializationStats::print() {}
 236 
 237 #endif  // ENABLE_SPECIALIZATION_STATS
 238 #endif  // !PRODUCT


  45 class Par_MarkRefsIntoAndScanClosure;
  46 class PushAndMarkClosure;
  47 class Par_PushAndMarkClosure;
  48 class PushOrMarkClosure;
  49 class Par_PushOrMarkClosure;
  50 class CMSKeepAliveClosure;
  51 class CMSInnerParMarkAndPushClosure;
  52 
  53 // This macro applies an argument macro to all OopClosures for which we
  54 // want specialized bodies of "oop_oop_iterate".  The arguments to "f" are:
  55 //   "f(closureType, non_virtual)"
  56 // where "closureType" is the name of the particular subclass of OopClosure,
  57 // and "non_virtual" will be the string "_nv" if the closure type should
  58 // have its "do_oop" method invoked non-virtually, or else the
  59 // string "_v".  ("OopClosure" itself will be the only class in the latter
  60 // category.)
  61 
  62 // This is split into several because of a Visual C++ 6.0 compiler bug
  63 // where very long macros cause the compiler to crash
  64 
  65 // Some other heap might define further specialized closures.
  66 #ifndef FURTHER_SPECIALIZED_OOP_OOP_ITERATE_CLOSURES
  67 #define FURTHER_SPECIALIZED_OOP_OOP_ITERATE_CLOSURES(f) \
  68         /* None */
  69 #endif
  70 
  71 #define SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_S(f)       \
  72   f(ScanClosure,_nv)                                    \
  73   f(FastScanClosure,_nv)                                \
  74   f(FilteringClosure,_nv)
  75 
  76 #ifndef SERIALGC
  77 #define SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_P(f)       \
  78   f(ParScanWithBarrierClosure,_nv)                      \
  79   f(ParScanWithoutBarrierClosure,_nv)
  80 #else  // SERIALGC
  81 #define SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_P(f)
  82 #endif // SERIALGC
  83 
  84 #define SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_1(f)       \
  85   SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_S(f)             \
  86   SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_P(f)
  87 
  88 #ifndef SERIALGC
  89 #define SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_2(f)       \
  90   f(MarkRefsIntoAndScanClosure,_nv)                     \
  91   f(Par_MarkRefsIntoAndScanClosure,_nv)                 \
  92   f(PushAndMarkClosure,_nv)                             \
  93   f(Par_PushAndMarkClosure,_nv)                         \
  94   f(PushOrMarkClosure,_nv)                              \
  95   f(Par_PushOrMarkClosure,_nv)                          \
  96   f(CMSKeepAliveClosure,_nv)                            \
  97   f(CMSInnerParMarkAndPushClosure,_nv)                  \
  98   FURTHER_SPECIALIZED_OOP_OOP_ITERATE_CLOSURES(f)
  99 #else  // SERIALGC
 100 #define SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_2(f)
 101 #endif // SERIALGC
 102 
 103 
 104 // We separate these out, because sometime the general one has
 105 // a different definition from the specialized ones, and sometimes it
 106 // doesn't.
 107 
 108 #define ALL_OOP_OOP_ITERATE_CLOSURES_1(f)               \
 109   f(OopClosure,_v)                                      \
 110   SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_1(f)
 111 
 112 #define ALL_OOP_OOP_ITERATE_CLOSURES_2(f)               \
 113   SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_2(f)
 114 
 115 #ifndef SERIALGC
 116 // This macro applies an argument macro to all OopClosures for which we
 117 // want specialized bodies of a family of methods related to
 118 // "par_oop_iterate".  The arguments to f are the same as above.
 119 // The "root_class" is the most general class to define; this may be
 120 // "OopClosure" in some applications and "OopsInGenClosure" in others.
 121 
 122 #define SPECIALIZED_PAR_OOP_ITERATE_CLOSURES(f)        \
 123   f(MarkRefsIntoAndScanClosure,_nv)                    \
 124   f(PushAndMarkClosure,_nv)                            \
 125   f(Par_MarkRefsIntoAndScanClosure,_nv)                \
 126   f(Par_PushAndMarkClosure,_nv)
 127 
 128 #define ALL_PAR_OOP_ITERATE_CLOSURES(f)                \
 129   f(OopClosure,_v)                                     \
 130   SPECIALIZED_PAR_OOP_ITERATE_CLOSURES(f)
 131 #endif // SERIALGC
 132 
 133 // This macro applies an argument macro to all OopClosures for which we
 134 // want specialized bodies of a family of methods related to
 135 // "oops_since_save_marks_do".  The arguments to f are the same as above.
 136 // The "root_class" is the most general class to define; this may be
 137 // "OopClosure" in some applications and "OopsInGenClosure" in others.
 138 
 139 
 140 // Some other heap might define further specialized closures.
 141 #ifndef FURTHER_SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES
 142 #define FURTHER_SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES(f) \
 143         /* None */
 144 #endif
 145 
 146 #define SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES_YOUNG_S(f) \
 147   f(ScanClosure,_nv)                                     \
 148   f(FastScanClosure,_nv)
 149 
 150 #ifndef SERIALGC
 151 #define SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES_YOUNG_P(f) \
 152   f(ParScanWithBarrierClosure,_nv)                       \
 153   f(ParScanWithoutBarrierClosure,_nv)                    \
 154   FURTHER_SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES(f)
 155 #else  // SERIALGC
 156 #define SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES_YOUNG_P(f)
 157 #endif // SERIALGC
 158 
 159 #define SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES_YOUNG(f)  \
 160   SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES_YOUNG_S(f)      \
 161   SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES_YOUNG_P(f)
 162 
 163 #define SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES(f)        \
 164   SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES_YOUNG(f)
 165 
 166 // We separate these out, because sometime the general one has
 167 // a different definition from the specialized ones, and sometimes it
 168 // doesn't.
 169 // NOTE:   One of the valid criticisms of this
 170 // specialize-oop_oop_iterate-for-specific-closures idiom is that it is
 171 // easy to have a silent performance bug: if you fail to de-virtualize,
 172 // things still work, just slower.  The "SpecializationStats" mode is
 173 // intended to at least make such a failure easy to detect.
 174 // *Not* using the ALL_SINCE_SAVE_MARKS_CLOSURES(f) macro defined


 181 
 182 #define ALL_SINCE_SAVE_MARKS_CLOSURES(f)                \
 183   f(OopsInGenClosure,_v)                                \
 184   SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES(f)
 185 
 186 // For keeping stats on effectiveness.
 187 #define ENABLE_SPECIALIZATION_STATS 0
 188 
 189 
 190 class SpecializationStats {
 191 public:
 192   enum Kind {
 193     ik,             // instanceKlass
 194     irk,            // instanceRefKlass
 195     oa,             // objArrayKlass
 196     NUM_Kinds
 197   };
 198 
 199 #if ENABLE_SPECIALIZATION_STATS
 200 private:
 201   static bool _init;
 202   static bool _wrapped;
 203   static jint _numCallsAll;
 204 
 205   static jint _numCallsTotal[NUM_Kinds];
 206   static jint _numCalls_nv[NUM_Kinds];
 207 
 208   static jint _numDoOopCallsTotal[NUM_Kinds];
 209   static jint _numDoOopCalls_nv[NUM_Kinds];
 210 public:
 211 #endif
 212   static void clear()  PRODUCT_RETURN;
 213 
 214   static inline void record_call()  PRODUCT_RETURN;
 215   static inline void record_iterate_call_v(Kind k)  PRODUCT_RETURN;
 216   static inline void record_iterate_call_nv(Kind k)  PRODUCT_RETURN;
 217   static inline void record_do_oop_call_v(Kind k)  PRODUCT_RETURN;
 218   static inline void record_do_oop_call_nv(Kind k)  PRODUCT_RETURN;
 219 
 220   static void print() PRODUCT_RETURN;
 221 };  
 222 
 223 #ifndef PRODUCT
 224 #if ENABLE_SPECIALIZATION_STATS
 225 
 226 inline void SpecializationStats::record_call() {
 227   Atomic::inc(&_numCallsAll);
 228 }
 229 inline void SpecializationStats::record_iterate_call_v(Kind k) {
 230   Atomic::inc(&_numCallsTotal[k]);
 231 }
 232 inline void SpecializationStats::record_iterate_call_nv(Kind k) {
 233   Atomic::inc(&_numCallsTotal[k]);
 234   Atomic::inc(&_numCalls_nv[k]);
 235 }
 236 
 237 inline void SpecializationStats::record_do_oop_call_v(Kind k) {
 238   Atomic::inc(&_numDoOopCallsTotal[k]);
 239 }
 240 inline void SpecializationStats::record_do_oop_call_nv(Kind k) {
 241   Atomic::inc(&_numDoOopCallsTotal[k]);
 242   Atomic::inc(&_numDoOopCalls_nv[k]);
 243 }
 244 
 245 #else   // !ENABLE_SPECIALIZATION_STATS
 246 
 247 inline void SpecializationStats::record_call() {}
 248 inline void SpecializationStats::record_iterate_call_v(Kind k) {}
 249 inline void SpecializationStats::record_iterate_call_nv(Kind k) {}
 250 inline void SpecializationStats::record_do_oop_call_v(Kind k) {}
 251 inline void SpecializationStats::record_do_oop_call_nv(Kind k) {}
 252 inline void SpecializationStats::clear() {}
 253 inline void SpecializationStats::print() {}
 254 
 255 #endif  // ENABLE_SPECIALIZATION_STATS
 256 #endif  // !PRODUCT