Thu, 12 Jun 2008 13:50:55 -0700
Merge
duke@435 | 1 | /* |
duke@435 | 2 | * Copyright 2001-2006 Sun Microsystems, Inc. All Rights Reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
duke@435 | 19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
duke@435 | 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
duke@435 | 21 | * have any questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
duke@435 | 25 | // The following OopClosure types get specialized versions of |
duke@435 | 26 | // "oop_oop_iterate" that invoke the closures' do_oop methods |
duke@435 | 27 | // non-virtually, using a mechanism defined in this file. Extend these |
duke@435 | 28 | // macros in the obvious way to add specializations for new closures. |
duke@435 | 29 | |
duke@435 | 30 | // Forward declarations. |
duke@435 | 31 | class OopClosure; |
duke@435 | 32 | class OopsInGenClosure; |
duke@435 | 33 | // DefNew |
duke@435 | 34 | class ScanClosure; |
duke@435 | 35 | class FastScanClosure; |
duke@435 | 36 | class FilteringClosure; |
duke@435 | 37 | // ParNew |
duke@435 | 38 | class ParScanWithBarrierClosure; |
duke@435 | 39 | class ParScanWithoutBarrierClosure; |
duke@435 | 40 | // CMS |
duke@435 | 41 | class MarkRefsIntoAndScanClosure; |
duke@435 | 42 | class Par_MarkRefsIntoAndScanClosure; |
duke@435 | 43 | class PushAndMarkClosure; |
duke@435 | 44 | class Par_PushAndMarkClosure; |
duke@435 | 45 | class PushOrMarkClosure; |
duke@435 | 46 | class Par_PushOrMarkClosure; |
duke@435 | 47 | class CMSKeepAliveClosure; |
duke@435 | 48 | class CMSInnerParMarkAndPushClosure; |
duke@435 | 49 | |
duke@435 | 50 | // This macro applies an argument macro to all OopClosures for which we |
duke@435 | 51 | // want specialized bodies of "oop_oop_iterate". The arguments to "f" are: |
duke@435 | 52 | // "f(closureType, non_virtual)" |
duke@435 | 53 | // where "closureType" is the name of the particular subclass of OopClosure, |
duke@435 | 54 | // and "non_virtual" will be the string "_nv" if the closure type should |
duke@435 | 55 | // have its "do_oop" method invoked non-virtually, or else the |
duke@435 | 56 | // string "_v". ("OopClosure" itself will be the only class in the latter |
duke@435 | 57 | // category.) |
duke@435 | 58 | |
duke@435 | 59 | // This is split into several because of a Visual C++ 6.0 compiler bug |
duke@435 | 60 | // where very long macros cause the compiler to crash |
duke@435 | 61 | |
ysr@777 | 62 | // Some other heap might define further specialized closures. |
ysr@777 | 63 | #ifndef FURTHER_SPECIALIZED_OOP_OOP_ITERATE_CLOSURES |
ysr@777 | 64 | #define FURTHER_SPECIALIZED_OOP_OOP_ITERATE_CLOSURES(f) \ |
ysr@777 | 65 | /* None */ |
ysr@777 | 66 | #endif |
ysr@777 | 67 | |
duke@435 | 68 | #define SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_S(f) \ |
duke@435 | 69 | f(ScanClosure,_nv) \ |
duke@435 | 70 | f(FastScanClosure,_nv) \ |
duke@435 | 71 | f(FilteringClosure,_nv) |
duke@435 | 72 | |
duke@435 | 73 | #ifndef SERIALGC |
duke@435 | 74 | #define SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_P(f) \ |
duke@435 | 75 | f(ParScanWithBarrierClosure,_nv) \ |
duke@435 | 76 | f(ParScanWithoutBarrierClosure,_nv) |
duke@435 | 77 | #else // SERIALGC |
duke@435 | 78 | #define SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_P(f) |
duke@435 | 79 | #endif // SERIALGC |
duke@435 | 80 | |
duke@435 | 81 | #define SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_1(f) \ |
duke@435 | 82 | SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_S(f) \ |
duke@435 | 83 | SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_P(f) |
duke@435 | 84 | |
duke@435 | 85 | #ifndef SERIALGC |
ysr@777 | 86 | #define SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_2(f) \ |
duke@435 | 87 | f(MarkRefsIntoAndScanClosure,_nv) \ |
duke@435 | 88 | f(Par_MarkRefsIntoAndScanClosure,_nv) \ |
duke@435 | 89 | f(PushAndMarkClosure,_nv) \ |
duke@435 | 90 | f(Par_PushAndMarkClosure,_nv) \ |
duke@435 | 91 | f(PushOrMarkClosure,_nv) \ |
duke@435 | 92 | f(Par_PushOrMarkClosure,_nv) \ |
duke@435 | 93 | f(CMSKeepAliveClosure,_nv) \ |
ysr@777 | 94 | f(CMSInnerParMarkAndPushClosure,_nv) \ |
ysr@777 | 95 | FURTHER_SPECIALIZED_OOP_OOP_ITERATE_CLOSURES(f) |
duke@435 | 96 | #else // SERIALGC |
ysr@777 | 97 | #define SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_2(f) |
duke@435 | 98 | #endif // SERIALGC |
duke@435 | 99 | |
ysr@777 | 100 | |
duke@435 | 101 | // We separate these out, because sometime the general one has |
duke@435 | 102 | // a different definition from the specialized ones, and sometimes it |
duke@435 | 103 | // doesn't. |
duke@435 | 104 | |
duke@435 | 105 | #define ALL_OOP_OOP_ITERATE_CLOSURES_1(f) \ |
duke@435 | 106 | f(OopClosure,_v) \ |
duke@435 | 107 | SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_1(f) |
duke@435 | 108 | |
ysr@777 | 109 | #define ALL_OOP_OOP_ITERATE_CLOSURES_2(f) \ |
ysr@777 | 110 | SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_2(f) |
duke@435 | 111 | |
duke@435 | 112 | #ifndef SERIALGC |
duke@435 | 113 | // This macro applies an argument macro to all OopClosures for which we |
duke@435 | 114 | // want specialized bodies of a family of methods related to |
duke@435 | 115 | // "par_oop_iterate". The arguments to f are the same as above. |
duke@435 | 116 | // The "root_class" is the most general class to define; this may be |
duke@435 | 117 | // "OopClosure" in some applications and "OopsInGenClosure" in others. |
duke@435 | 118 | |
duke@435 | 119 | #define SPECIALIZED_PAR_OOP_ITERATE_CLOSURES(f) \ |
duke@435 | 120 | f(MarkRefsIntoAndScanClosure,_nv) \ |
duke@435 | 121 | f(PushAndMarkClosure,_nv) \ |
duke@435 | 122 | f(Par_MarkRefsIntoAndScanClosure,_nv) \ |
duke@435 | 123 | f(Par_PushAndMarkClosure,_nv) |
duke@435 | 124 | |
duke@435 | 125 | #define ALL_PAR_OOP_ITERATE_CLOSURES(f) \ |
duke@435 | 126 | f(OopClosure,_v) \ |
duke@435 | 127 | SPECIALIZED_PAR_OOP_ITERATE_CLOSURES(f) |
duke@435 | 128 | #endif // SERIALGC |
duke@435 | 129 | |
duke@435 | 130 | // This macro applies an argument macro to all OopClosures for which we |
duke@435 | 131 | // want specialized bodies of a family of methods related to |
duke@435 | 132 | // "oops_since_save_marks_do". The arguments to f are the same as above. |
duke@435 | 133 | // The "root_class" is the most general class to define; this may be |
duke@435 | 134 | // "OopClosure" in some applications and "OopsInGenClosure" in others. |
duke@435 | 135 | |
ysr@777 | 136 | |
ysr@777 | 137 | // Some other heap might define further specialized closures. |
ysr@777 | 138 | #ifndef FURTHER_SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES |
ysr@777 | 139 | #define FURTHER_SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES(f) \ |
ysr@777 | 140 | /* None */ |
ysr@777 | 141 | #endif |
ysr@777 | 142 | |
duke@435 | 143 | #define SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES_YOUNG_S(f) \ |
duke@435 | 144 | f(ScanClosure,_nv) \ |
duke@435 | 145 | f(FastScanClosure,_nv) |
duke@435 | 146 | |
duke@435 | 147 | #ifndef SERIALGC |
duke@435 | 148 | #define SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES_YOUNG_P(f) \ |
duke@435 | 149 | f(ParScanWithBarrierClosure,_nv) \ |
ysr@777 | 150 | f(ParScanWithoutBarrierClosure,_nv) \ |
ysr@777 | 151 | FURTHER_SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES(f) |
duke@435 | 152 | #else // SERIALGC |
duke@435 | 153 | #define SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES_YOUNG_P(f) |
duke@435 | 154 | #endif // SERIALGC |
duke@435 | 155 | |
duke@435 | 156 | #define SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES_YOUNG(f) \ |
duke@435 | 157 | SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES_YOUNG_S(f) \ |
duke@435 | 158 | SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES_YOUNG_P(f) |
duke@435 | 159 | |
duke@435 | 160 | #define SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES(f) \ |
duke@435 | 161 | SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES_YOUNG(f) |
duke@435 | 162 | |
duke@435 | 163 | // We separate these out, because sometime the general one has |
duke@435 | 164 | // a different definition from the specialized ones, and sometimes it |
duke@435 | 165 | // doesn't. |
duke@435 | 166 | // NOTE: One of the valid criticisms of this |
duke@435 | 167 | // specialize-oop_oop_iterate-for-specific-closures idiom is that it is |
duke@435 | 168 | // easy to have a silent performance bug: if you fail to de-virtualize, |
duke@435 | 169 | // things still work, just slower. The "SpecializationStats" mode is |
duke@435 | 170 | // intended to at least make such a failure easy to detect. |
duke@435 | 171 | // *Not* using the ALL_SINCE_SAVE_MARKS_CLOSURES(f) macro defined |
duke@435 | 172 | // below means that *only* closures for which oop_oop_iterate specializations |
duke@435 | 173 | // exist above may be applied to "oops_since_save_marks". That is, |
duke@435 | 174 | // this form of the performance bug is caught statically. When you add |
duke@435 | 175 | // a definition for the general type, this property goes away. |
duke@435 | 176 | // Make sure you test with SpecializationStats to find such bugs |
duke@435 | 177 | // when introducing a new closure where you don't want virtual dispatch. |
duke@435 | 178 | |
duke@435 | 179 | #define ALL_SINCE_SAVE_MARKS_CLOSURES(f) \ |
duke@435 | 180 | f(OopsInGenClosure,_v) \ |
duke@435 | 181 | SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES(f) |
duke@435 | 182 | |
duke@435 | 183 | // For keeping stats on effectiveness. |
duke@435 | 184 | #define ENABLE_SPECIALIZATION_STATS 0 |
duke@435 | 185 | |
duke@435 | 186 | |
duke@435 | 187 | class SpecializationStats { |
duke@435 | 188 | public: |
duke@435 | 189 | enum Kind { |
duke@435 | 190 | ik, // instanceKlass |
duke@435 | 191 | irk, // instanceRefKlass |
duke@435 | 192 | oa, // objArrayKlass |
duke@435 | 193 | NUM_Kinds |
duke@435 | 194 | }; |
duke@435 | 195 | |
duke@435 | 196 | #if ENABLE_SPECIALIZATION_STATS |
duke@435 | 197 | private: |
ysr@777 | 198 | static bool _init; |
ysr@777 | 199 | static bool _wrapped; |
ysr@777 | 200 | static jint _numCallsAll; |
duke@435 | 201 | |
ysr@777 | 202 | static jint _numCallsTotal[NUM_Kinds]; |
ysr@777 | 203 | static jint _numCalls_nv[NUM_Kinds]; |
duke@435 | 204 | |
ysr@777 | 205 | static jint _numDoOopCallsTotal[NUM_Kinds]; |
ysr@777 | 206 | static jint _numDoOopCalls_nv[NUM_Kinds]; |
duke@435 | 207 | public: |
duke@435 | 208 | #endif |
duke@435 | 209 | static void clear() PRODUCT_RETURN; |
duke@435 | 210 | |
duke@435 | 211 | static inline void record_call() PRODUCT_RETURN; |
duke@435 | 212 | static inline void record_iterate_call_v(Kind k) PRODUCT_RETURN; |
duke@435 | 213 | static inline void record_iterate_call_nv(Kind k) PRODUCT_RETURN; |
duke@435 | 214 | static inline void record_do_oop_call_v(Kind k) PRODUCT_RETURN; |
duke@435 | 215 | static inline void record_do_oop_call_nv(Kind k) PRODUCT_RETURN; |
duke@435 | 216 | |
duke@435 | 217 | static void print() PRODUCT_RETURN; |
duke@435 | 218 | }; |
duke@435 | 219 | |
duke@435 | 220 | #ifndef PRODUCT |
duke@435 | 221 | #if ENABLE_SPECIALIZATION_STATS |
duke@435 | 222 | |
duke@435 | 223 | inline void SpecializationStats::record_call() { |
ysr@777 | 224 | Atomic::inc(&_numCallsAll); |
duke@435 | 225 | } |
duke@435 | 226 | inline void SpecializationStats::record_iterate_call_v(Kind k) { |
ysr@777 | 227 | Atomic::inc(&_numCallsTotal[k]); |
duke@435 | 228 | } |
duke@435 | 229 | inline void SpecializationStats::record_iterate_call_nv(Kind k) { |
ysr@777 | 230 | Atomic::inc(&_numCallsTotal[k]); |
ysr@777 | 231 | Atomic::inc(&_numCalls_nv[k]); |
duke@435 | 232 | } |
duke@435 | 233 | |
duke@435 | 234 | inline void SpecializationStats::record_do_oop_call_v(Kind k) { |
ysr@777 | 235 | Atomic::inc(&_numDoOopCallsTotal[k]); |
duke@435 | 236 | } |
duke@435 | 237 | inline void SpecializationStats::record_do_oop_call_nv(Kind k) { |
ysr@777 | 238 | Atomic::inc(&_numDoOopCallsTotal[k]); |
ysr@777 | 239 | Atomic::inc(&_numDoOopCalls_nv[k]); |
duke@435 | 240 | } |
duke@435 | 241 | |
duke@435 | 242 | #else // !ENABLE_SPECIALIZATION_STATS |
duke@435 | 243 | |
duke@435 | 244 | inline void SpecializationStats::record_call() {} |
duke@435 | 245 | inline void SpecializationStats::record_iterate_call_v(Kind k) {} |
duke@435 | 246 | inline void SpecializationStats::record_iterate_call_nv(Kind k) {} |
duke@435 | 247 | inline void SpecializationStats::record_do_oop_call_v(Kind k) {} |
duke@435 | 248 | inline void SpecializationStats::record_do_oop_call_nv(Kind k) {} |
duke@435 | 249 | inline void SpecializationStats::clear() {} |
duke@435 | 250 | inline void SpecializationStats::print() {} |
duke@435 | 251 | |
duke@435 | 252 | #endif // ENABLE_SPECIALIZATION_STATS |
duke@435 | 253 | #endif // !PRODUCT |