comparison src/share/vm/memory/specialized_oop_closures.hpp @ 0:a61af66fc99e jdk7-b24

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