src/share/vm/memory/specialized_oop_closures.hpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

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

mercurial