src/share/vm/memory/specialized_oop_closures.hpp

Sun, 01 Apr 2012 17:04:26 -0400

author
acorn
date
Sun, 01 Apr 2012 17:04:26 -0400
changeset 3686
749b1464aa81
parent 2314
f95d63e2154a
child 4037
da91efe96a93
permissions
-rw-r--r--

Merge

duke@435 1 /*
stefank@2314 2 * Copyright (c) 2001, 2010, Oracle and/or its affiliates. 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 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #ifndef SHARE_VM_MEMORY_SPECIALIZED_OOP_CLOSURES_HPP
stefank@2314 26 #define SHARE_VM_MEMORY_SPECIALIZED_OOP_CLOSURES_HPP
stefank@2314 27
stefank@2314 28 #include "runtime/atomic.hpp"
stefank@2314 29 #ifndef SERIALGC
stefank@2314 30 #include "gc_implementation/g1/g1_specialized_oop_closures.hpp"
stefank@2314 31 #endif
stefank@2314 32
duke@435 33 // The following OopClosure types get specialized versions of
duke@435 34 // "oop_oop_iterate" that invoke the closures' do_oop methods
duke@435 35 // non-virtually, using a mechanism defined in this file. Extend these
duke@435 36 // macros in the obvious way to add specializations for new closures.
duke@435 37
duke@435 38 // Forward declarations.
duke@435 39 class OopClosure;
duke@435 40 class OopsInGenClosure;
duke@435 41 // DefNew
duke@435 42 class ScanClosure;
duke@435 43 class FastScanClosure;
duke@435 44 class FilteringClosure;
duke@435 45 // ParNew
duke@435 46 class ParScanWithBarrierClosure;
duke@435 47 class ParScanWithoutBarrierClosure;
duke@435 48 // CMS
duke@435 49 class MarkRefsIntoAndScanClosure;
duke@435 50 class Par_MarkRefsIntoAndScanClosure;
duke@435 51 class PushAndMarkClosure;
duke@435 52 class Par_PushAndMarkClosure;
duke@435 53 class PushOrMarkClosure;
duke@435 54 class Par_PushOrMarkClosure;
duke@435 55 class CMSKeepAliveClosure;
duke@435 56 class CMSInnerParMarkAndPushClosure;
duke@435 57
duke@435 58 // This macro applies an argument macro to all OopClosures for which we
duke@435 59 // want specialized bodies of "oop_oop_iterate". The arguments to "f" are:
duke@435 60 // "f(closureType, non_virtual)"
duke@435 61 // where "closureType" is the name of the particular subclass of OopClosure,
duke@435 62 // and "non_virtual" will be the string "_nv" if the closure type should
duke@435 63 // have its "do_oop" method invoked non-virtually, or else the
duke@435 64 // string "_v". ("OopClosure" itself will be the only class in the latter
duke@435 65 // category.)
duke@435 66
duke@435 67 // This is split into several because of a Visual C++ 6.0 compiler bug
duke@435 68 // where very long macros cause the compiler to crash
duke@435 69
ysr@777 70 // Some other heap might define further specialized closures.
ysr@777 71 #ifndef FURTHER_SPECIALIZED_OOP_OOP_ITERATE_CLOSURES
ysr@777 72 #define FURTHER_SPECIALIZED_OOP_OOP_ITERATE_CLOSURES(f) \
ysr@777 73 /* None */
ysr@777 74 #endif
ysr@777 75
duke@435 76 #define SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_S(f) \
duke@435 77 f(ScanClosure,_nv) \
duke@435 78 f(FastScanClosure,_nv) \
duke@435 79 f(FilteringClosure,_nv)
duke@435 80
duke@435 81 #ifndef SERIALGC
duke@435 82 #define SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_P(f) \
duke@435 83 f(ParScanWithBarrierClosure,_nv) \
duke@435 84 f(ParScanWithoutBarrierClosure,_nv)
duke@435 85 #else // SERIALGC
duke@435 86 #define SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_P(f)
duke@435 87 #endif // SERIALGC
duke@435 88
duke@435 89 #define SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_1(f) \
duke@435 90 SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_S(f) \
duke@435 91 SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_P(f)
duke@435 92
duke@435 93 #ifndef SERIALGC
ysr@777 94 #define SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_2(f) \
duke@435 95 f(MarkRefsIntoAndScanClosure,_nv) \
duke@435 96 f(Par_MarkRefsIntoAndScanClosure,_nv) \
duke@435 97 f(PushAndMarkClosure,_nv) \
duke@435 98 f(Par_PushAndMarkClosure,_nv) \
duke@435 99 f(PushOrMarkClosure,_nv) \
duke@435 100 f(Par_PushOrMarkClosure,_nv) \
duke@435 101 f(CMSKeepAliveClosure,_nv) \
ysr@777 102 f(CMSInnerParMarkAndPushClosure,_nv) \
ysr@777 103 FURTHER_SPECIALIZED_OOP_OOP_ITERATE_CLOSURES(f)
duke@435 104 #else // SERIALGC
ysr@777 105 #define SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_2(f)
duke@435 106 #endif // SERIALGC
duke@435 107
ysr@777 108
duke@435 109 // We separate these out, because sometime the general one has
duke@435 110 // a different definition from the specialized ones, and sometimes it
duke@435 111 // doesn't.
duke@435 112
duke@435 113 #define ALL_OOP_OOP_ITERATE_CLOSURES_1(f) \
duke@435 114 f(OopClosure,_v) \
duke@435 115 SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_1(f)
duke@435 116
ysr@777 117 #define ALL_OOP_OOP_ITERATE_CLOSURES_2(f) \
ysr@777 118 SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_2(f)
duke@435 119
duke@435 120 #ifndef SERIALGC
duke@435 121 // This macro applies an argument macro to all OopClosures for which we
duke@435 122 // want specialized bodies of a family of methods related to
duke@435 123 // "par_oop_iterate". The arguments to f are the same as above.
duke@435 124 // The "root_class" is the most general class to define; this may be
duke@435 125 // "OopClosure" in some applications and "OopsInGenClosure" in others.
duke@435 126
duke@435 127 #define SPECIALIZED_PAR_OOP_ITERATE_CLOSURES(f) \
duke@435 128 f(MarkRefsIntoAndScanClosure,_nv) \
duke@435 129 f(PushAndMarkClosure,_nv) \
duke@435 130 f(Par_MarkRefsIntoAndScanClosure,_nv) \
duke@435 131 f(Par_PushAndMarkClosure,_nv)
duke@435 132
duke@435 133 #define ALL_PAR_OOP_ITERATE_CLOSURES(f) \
duke@435 134 f(OopClosure,_v) \
duke@435 135 SPECIALIZED_PAR_OOP_ITERATE_CLOSURES(f)
duke@435 136 #endif // SERIALGC
duke@435 137
duke@435 138 // This macro applies an argument macro to all OopClosures for which we
duke@435 139 // want specialized bodies of a family of methods related to
duke@435 140 // "oops_since_save_marks_do". The arguments to f are the same as above.
duke@435 141 // The "root_class" is the most general class to define; this may be
duke@435 142 // "OopClosure" in some applications and "OopsInGenClosure" in others.
duke@435 143
ysr@777 144
ysr@777 145 // Some other heap might define further specialized closures.
ysr@777 146 #ifndef FURTHER_SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES
ysr@777 147 #define FURTHER_SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES(f) \
ysr@777 148 /* None */
ysr@777 149 #endif
ysr@777 150
duke@435 151 #define SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES_YOUNG_S(f) \
duke@435 152 f(ScanClosure,_nv) \
duke@435 153 f(FastScanClosure,_nv)
duke@435 154
duke@435 155 #ifndef SERIALGC
duke@435 156 #define SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES_YOUNG_P(f) \
duke@435 157 f(ParScanWithBarrierClosure,_nv) \
ysr@777 158 f(ParScanWithoutBarrierClosure,_nv) \
ysr@777 159 FURTHER_SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES(f)
duke@435 160 #else // SERIALGC
duke@435 161 #define SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES_YOUNG_P(f)
duke@435 162 #endif // SERIALGC
duke@435 163
duke@435 164 #define SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES_YOUNG(f) \
duke@435 165 SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES_YOUNG_S(f) \
duke@435 166 SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES_YOUNG_P(f)
duke@435 167
duke@435 168 #define SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES(f) \
duke@435 169 SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES_YOUNG(f)
duke@435 170
duke@435 171 // We separate these out, because sometime the general one has
duke@435 172 // a different definition from the specialized ones, and sometimes it
duke@435 173 // doesn't.
duke@435 174 // NOTE: One of the valid criticisms of this
duke@435 175 // specialize-oop_oop_iterate-for-specific-closures idiom is that it is
duke@435 176 // easy to have a silent performance bug: if you fail to de-virtualize,
duke@435 177 // things still work, just slower. The "SpecializationStats" mode is
duke@435 178 // intended to at least make such a failure easy to detect.
duke@435 179 // *Not* using the ALL_SINCE_SAVE_MARKS_CLOSURES(f) macro defined
duke@435 180 // below means that *only* closures for which oop_oop_iterate specializations
duke@435 181 // exist above may be applied to "oops_since_save_marks". That is,
duke@435 182 // this form of the performance bug is caught statically. When you add
duke@435 183 // a definition for the general type, this property goes away.
duke@435 184 // Make sure you test with SpecializationStats to find such bugs
duke@435 185 // when introducing a new closure where you don't want virtual dispatch.
duke@435 186
duke@435 187 #define ALL_SINCE_SAVE_MARKS_CLOSURES(f) \
duke@435 188 f(OopsInGenClosure,_v) \
duke@435 189 SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES(f)
duke@435 190
duke@435 191 // For keeping stats on effectiveness.
duke@435 192 #define ENABLE_SPECIALIZATION_STATS 0
duke@435 193
duke@435 194
duke@435 195 class SpecializationStats {
duke@435 196 public:
duke@435 197 enum Kind {
duke@435 198 ik, // instanceKlass
duke@435 199 irk, // instanceRefKlass
duke@435 200 oa, // objArrayKlass
duke@435 201 NUM_Kinds
duke@435 202 };
duke@435 203
duke@435 204 #if ENABLE_SPECIALIZATION_STATS
duke@435 205 private:
ysr@777 206 static bool _init;
ysr@777 207 static bool _wrapped;
ysr@777 208 static jint _numCallsAll;
duke@435 209
ysr@777 210 static jint _numCallsTotal[NUM_Kinds];
ysr@777 211 static jint _numCalls_nv[NUM_Kinds];
duke@435 212
ysr@777 213 static jint _numDoOopCallsTotal[NUM_Kinds];
ysr@777 214 static jint _numDoOopCalls_nv[NUM_Kinds];
duke@435 215 public:
duke@435 216 #endif
duke@435 217 static void clear() PRODUCT_RETURN;
duke@435 218
duke@435 219 static inline void record_call() PRODUCT_RETURN;
duke@435 220 static inline void record_iterate_call_v(Kind k) PRODUCT_RETURN;
duke@435 221 static inline void record_iterate_call_nv(Kind k) PRODUCT_RETURN;
duke@435 222 static inline void record_do_oop_call_v(Kind k) PRODUCT_RETURN;
duke@435 223 static inline void record_do_oop_call_nv(Kind k) PRODUCT_RETURN;
duke@435 224
duke@435 225 static void print() PRODUCT_RETURN;
duke@435 226 };
duke@435 227
duke@435 228 #ifndef PRODUCT
duke@435 229 #if ENABLE_SPECIALIZATION_STATS
duke@435 230
duke@435 231 inline void SpecializationStats::record_call() {
ysr@777 232 Atomic::inc(&_numCallsAll);
duke@435 233 }
duke@435 234 inline void SpecializationStats::record_iterate_call_v(Kind k) {
ysr@777 235 Atomic::inc(&_numCallsTotal[k]);
duke@435 236 }
duke@435 237 inline void SpecializationStats::record_iterate_call_nv(Kind k) {
ysr@777 238 Atomic::inc(&_numCallsTotal[k]);
ysr@777 239 Atomic::inc(&_numCalls_nv[k]);
duke@435 240 }
duke@435 241
duke@435 242 inline void SpecializationStats::record_do_oop_call_v(Kind k) {
ysr@777 243 Atomic::inc(&_numDoOopCallsTotal[k]);
duke@435 244 }
duke@435 245 inline void SpecializationStats::record_do_oop_call_nv(Kind k) {
ysr@777 246 Atomic::inc(&_numDoOopCallsTotal[k]);
ysr@777 247 Atomic::inc(&_numDoOopCalls_nv[k]);
duke@435 248 }
duke@435 249
duke@435 250 #else // !ENABLE_SPECIALIZATION_STATS
duke@435 251
duke@435 252 inline void SpecializationStats::record_call() {}
duke@435 253 inline void SpecializationStats::record_iterate_call_v(Kind k) {}
duke@435 254 inline void SpecializationStats::record_iterate_call_nv(Kind k) {}
duke@435 255 inline void SpecializationStats::record_do_oop_call_v(Kind k) {}
duke@435 256 inline void SpecializationStats::record_do_oop_call_nv(Kind k) {}
duke@435 257 inline void SpecializationStats::clear() {}
duke@435 258 inline void SpecializationStats::print() {}
duke@435 259
duke@435 260 #endif // ENABLE_SPECIALIZATION_STATS
duke@435 261 #endif // !PRODUCT
stefank@2314 262
stefank@2314 263 #endif // SHARE_VM_MEMORY_SPECIALIZED_OOP_CLOSURES_HPP

mercurial