src/share/vm/memory/specialized_oop_closures.hpp

Fri, 07 Sep 2012 12:04:16 -0400

author
coleenp
date
Fri, 07 Sep 2012 12:04:16 -0400
changeset 4047
aed758eda82a
parent 4037
da91efe96a93
child 4142
d8ce2825b193
permissions
-rw-r--r--

7195833: NPG: Rename instanceClassLoaderKlass, instanceRefKlass and instanceMirrorKlass
Summary: Simple renaming to be consistent with instanceKlass->InstanceKlass renaming
Reviewed-by: stefank, jmasa

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

mercurial