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