< prev index next >

src/hotspot/share/memory/iterator.inline.hpp

Print this page

 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #ifndef SHARE_MEMORY_ITERATOR_INLINE_HPP
 26 #define SHARE_MEMORY_ITERATOR_INLINE_HPP
 27 
 28 #include "memory/iterator.hpp"
 29 
 30 #include "classfile/classLoaderData.hpp"
 31 #include "oops/access.inline.hpp"
 32 #include "oops/compressedOops.inline.hpp"
 33 #include "oops/klass.hpp"
 34 #include "oops/instanceKlass.inline.hpp"
 35 #include "oops/instanceMirrorKlass.inline.hpp"
 36 #include "oops/instanceClassLoaderKlass.inline.hpp"
 37 #include "oops/instanceRefKlass.inline.hpp"

 38 #include "oops/objArrayKlass.inline.hpp"
 39 #include "oops/typeArrayKlass.inline.hpp"
 40 #include "utilities/debug.hpp"
 41 
 42 // Defaults to strong claiming.
 43 inline MetadataVisitingOopIterateClosure::MetadataVisitingOopIterateClosure(ReferenceDiscoverer* rd) :
 44     ClaimMetadataVisitingOopIterateClosure(ClassLoaderData::_claim_strong, rd) {}
 45 
 46 inline void ClaimMetadataVisitingOopIterateClosure::do_cld(ClassLoaderData* cld) {
 47   cld->oops_do(this, _claim);
 48 }
 49 
 50 inline void ClaimMetadataVisitingOopIterateClosure::do_klass(Klass* k) {
 51   ClassLoaderData* cld = k->class_loader_data();
 52   ClaimMetadataVisitingOopIterateClosure::do_cld(cld);
 53 }
 54 









 55 // Implementation of the non-virtual do_oop dispatch.
 56 //
 57 // The same implementation is used for do_metadata, do_klass, and do_cld.
 58 //
 59 // Preconditions:
 60 //  - Base has a pure virtual do_oop
 61 //  - Only one of the classes in the inheritance chain from OopClosureType to
 62 //    Base implements do_oop.
 63 //
 64 // Given the preconditions:
 65 //  - If &OopClosureType::do_oop is resolved to &Base::do_oop, then there is no
 66 //    implementation of do_oop between Base and OopClosureType. However, there
 67 //    must be one implementation in one of the subclasses of OopClosureType.
 68 //    In this case we take the virtual call.
 69 //
 70 //  - Conversely, if &OopClosureType::do_oop is not resolved to &Base::do_oop,
 71 //    then we've found the one and only concrete implementation. In this case we
 72 //    take a non-virtual call.
 73 //
 74 // Because of this it's clear when we should call the virtual call and

152 
153 // Implementation of the non-virtual do_cld dispatch.
154 
155 template <typename Receiver, typename Base, typename OopClosureType>
156 static typename EnableIf<IsSame<Receiver, Base>::value, void>::type
157 call_do_cld(void (Receiver::*)(ClassLoaderData*), void (Base::*)(ClassLoaderData*), OopClosureType* closure, ClassLoaderData* cld) {
158   closure->do_cld(cld);
159 }
160 
161 template <typename Receiver, typename Base, typename OopClosureType>
162 static typename EnableIf<!IsSame<Receiver, Base>::value, void>::type
163 call_do_cld(void (Receiver::*)(ClassLoaderData*), void (Base::*)(ClassLoaderData*), OopClosureType* closure, ClassLoaderData* cld) {
164   closure->OopClosureType::do_cld(cld);
165 }
166 
167 template <typename OopClosureType>
168 void Devirtualizer::do_cld(OopClosureType* closure, ClassLoaderData* cld) {
169   call_do_cld(&OopClosureType::do_cld, &OopIterateClosure::do_cld, closure, cld);
170 }
171 




































172 // Dispatch table implementation for *Klass::oop_oop_iterate
173 //
174 // It allows for a single call to do a multi-dispatch to an optimized version
175 //   of oop_oop_iterate that statically know all these types:
176 //   - OopClosureType    : static type give at call site
177 //   - Klass*            : dynamic to static type through Klass::id() -> table index
178 //   - UseCompressedOops : dynamic to static value determined once
179 //
180 // when users call obj->oop_iterate(&cl).
181 //
182 // oopDesc::oop_iterate() calls OopOopIterateDispatch::function(klass)(cl, obj, klass),
183 //   which dispatches to an optimized version of
184 //   [Instance, ObjArry, etc]Klass::oop_oop_iterate(oop, OopClosureType)
185 //
186 // OopClosureType :
187 //   If OopClosureType has an implementation of do_oop (and do_metadata et.al.),
188 //   then the static type of OopClosureType will be used to allow inlining of
189 //   do_oop (even though do_oop is virtual). Otherwise, a virtual call will be
190 //   used when calling do_oop.
191 //

235         _function[KlassType::ID] = &oop_oop_iterate<KlassType, narrowOop>;
236       } else {
237         _function[KlassType::ID] = &oop_oop_iterate<KlassType, oop>;
238       }
239     }
240 
241     template <typename KlassType>
242     void set_resolve_function_and_execute(OopClosureType* cl, oop obj, Klass* k) {
243       set_resolve_function<KlassType>();
244       _function[KlassType::ID](cl, obj, k);
245     }
246 
247   public:
248     FunctionType _function[KLASS_ID_COUNT];
249 
250     Table(){
251       set_init_function<InstanceKlass>();
252       set_init_function<InstanceRefKlass>();
253       set_init_function<InstanceMirrorKlass>();
254       set_init_function<InstanceClassLoaderKlass>();

255       set_init_function<ObjArrayKlass>();
256       set_init_function<TypeArrayKlass>();
257     }
258   };
259 
260   static Table _table;
261 public:
262 
263   static FunctionType function(Klass* klass) {
264     return _table._function[klass->id()];
265   }
266 };
267 
268 template <typename OopClosureType>
269 typename OopOopIterateDispatch<OopClosureType>::Table OopOopIterateDispatch<OopClosureType>::_table;
270 
271 
272 template <typename OopClosureType>
273 class OopOopIterateBoundedDispatch {
274 private:

297         _function[KlassType::ID] = &oop_oop_iterate_bounded<KlassType, narrowOop>;
298       } else {
299         _function[KlassType::ID] = &oop_oop_iterate_bounded<KlassType, oop>;
300       }
301     }
302 
303     template <typename KlassType>
304     void set_resolve_function_and_execute(OopClosureType* cl, oop obj, Klass* k, MemRegion mr) {
305       set_resolve_function<KlassType>();
306       _function[KlassType::ID](cl, obj, k, mr);
307     }
308 
309   public:
310     FunctionType _function[KLASS_ID_COUNT];
311 
312     Table(){
313       set_init_function<InstanceKlass>();
314       set_init_function<InstanceRefKlass>();
315       set_init_function<InstanceMirrorKlass>();
316       set_init_function<InstanceClassLoaderKlass>();

317       set_init_function<ObjArrayKlass>();
318       set_init_function<TypeArrayKlass>();
319     }
320   };
321 
322   static Table _table;
323 public:
324 
325   static FunctionType function(Klass* klass) {
326     return _table._function[klass->id()];
327   }
328 };
329 
330 template <typename OopClosureType>
331 typename OopOopIterateBoundedDispatch<OopClosureType>::Table OopOopIterateBoundedDispatch<OopClosureType>::_table;
332 
333 
334 template <typename OopClosureType>
335 class OopOopIterateBackwardsDispatch {
336 private:

359         _function[KlassType::ID] = &oop_oop_iterate_backwards<KlassType, narrowOop>;
360       } else {
361         _function[KlassType::ID] = &oop_oop_iterate_backwards<KlassType, oop>;
362       }
363     }
364 
365     template <typename KlassType>
366     void set_resolve_function_and_execute(OopClosureType* cl, oop obj, Klass* k) {
367       set_resolve_function<KlassType>();
368       _function[KlassType::ID](cl, obj, k);
369     }
370 
371   public:
372     FunctionType _function[KLASS_ID_COUNT];
373 
374     Table(){
375       set_init_function<InstanceKlass>();
376       set_init_function<InstanceRefKlass>();
377       set_init_function<InstanceMirrorKlass>();
378       set_init_function<InstanceClassLoaderKlass>();

379       set_init_function<ObjArrayKlass>();
380       set_init_function<TypeArrayKlass>();
381     }
382   };
383 
384   static Table _table;
385 public:
386 
387   static FunctionType function(Klass* klass) {
388     return _table._function[klass->id()];
389   }
390 };
391 
392 template <typename OopClosureType>
393 typename OopOopIterateBackwardsDispatch<OopClosureType>::Table OopOopIterateBackwardsDispatch<OopClosureType>::_table;
394 
395 
396 template <typename OopClosureType>
397 void OopIteratorClosureDispatch::oop_oop_iterate(OopClosureType* cl, oop obj, Klass* klass) {
398   OopOopIterateDispatch<OopClosureType>::function(klass)(cl, obj, klass);

 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #ifndef SHARE_MEMORY_ITERATOR_INLINE_HPP
 26 #define SHARE_MEMORY_ITERATOR_INLINE_HPP
 27 
 28 #include "memory/iterator.hpp"
 29 
 30 #include "classfile/classLoaderData.hpp"
 31 #include "oops/access.inline.hpp"
 32 #include "oops/compressedOops.inline.hpp"
 33 #include "oops/klass.hpp"
 34 #include "oops/instanceKlass.inline.hpp"
 35 #include "oops/instanceMirrorKlass.inline.hpp"
 36 #include "oops/instanceClassLoaderKlass.inline.hpp"
 37 #include "oops/instanceRefKlass.inline.hpp"
 38 #include "oops/instanceStackChunkKlass.inline.hpp"
 39 #include "oops/objArrayKlass.inline.hpp"
 40 #include "oops/typeArrayKlass.inline.hpp"
 41 #include "utilities/debug.hpp"
 42 
 43 // Defaults to strong claiming.
 44 inline MetadataVisitingOopIterateClosure::MetadataVisitingOopIterateClosure(ReferenceDiscoverer* rd) :
 45     ClaimMetadataVisitingOopIterateClosure(ClassLoaderData::_claim_strong, rd) {}
 46 
 47 inline void ClaimMetadataVisitingOopIterateClosure::do_cld(ClassLoaderData* cld) {
 48   cld->oops_do(this, _claim);
 49 }
 50 
 51 inline void ClaimMetadataVisitingOopIterateClosure::do_klass(Klass* k) {
 52   ClassLoaderData* cld = k->class_loader_data();
 53   ClaimMetadataVisitingOopIterateClosure::do_cld(cld);
 54 }
 55 
 56 inline void ClaimMetadataVisitingOopIterateClosure::do_nmethod(nmethod* nm) {
 57   nm->follow_nmethod(this);
 58 }
 59 
 60 inline void ClaimMetadataVisitingOopIterateClosure::do_method(Method* m) {
 61   // Mark interpreted frames for marking_cycle
 62   m->record_marking_cycle();
 63 }
 64 
 65 // Implementation of the non-virtual do_oop dispatch.
 66 //
 67 // The same implementation is used for do_metadata, do_klass, and do_cld.
 68 //
 69 // Preconditions:
 70 //  - Base has a pure virtual do_oop
 71 //  - Only one of the classes in the inheritance chain from OopClosureType to
 72 //    Base implements do_oop.
 73 //
 74 // Given the preconditions:
 75 //  - If &OopClosureType::do_oop is resolved to &Base::do_oop, then there is no
 76 //    implementation of do_oop between Base and OopClosureType. However, there
 77 //    must be one implementation in one of the subclasses of OopClosureType.
 78 //    In this case we take the virtual call.
 79 //
 80 //  - Conversely, if &OopClosureType::do_oop is not resolved to &Base::do_oop,
 81 //    then we've found the one and only concrete implementation. In this case we
 82 //    take a non-virtual call.
 83 //
 84 // Because of this it's clear when we should call the virtual call and

162 
163 // Implementation of the non-virtual do_cld dispatch.
164 
165 template <typename Receiver, typename Base, typename OopClosureType>
166 static typename EnableIf<IsSame<Receiver, Base>::value, void>::type
167 call_do_cld(void (Receiver::*)(ClassLoaderData*), void (Base::*)(ClassLoaderData*), OopClosureType* closure, ClassLoaderData* cld) {
168   closure->do_cld(cld);
169 }
170 
171 template <typename Receiver, typename Base, typename OopClosureType>
172 static typename EnableIf<!IsSame<Receiver, Base>::value, void>::type
173 call_do_cld(void (Receiver::*)(ClassLoaderData*), void (Base::*)(ClassLoaderData*), OopClosureType* closure, ClassLoaderData* cld) {
174   closure->OopClosureType::do_cld(cld);
175 }
176 
177 template <typename OopClosureType>
178 void Devirtualizer::do_cld(OopClosureType* closure, ClassLoaderData* cld) {
179   call_do_cld(&OopClosureType::do_cld, &OopIterateClosure::do_cld, closure, cld);
180 }
181 
182 // Implementation of the non-virtual do_derived_oop dispatch.
183 
184 template <typename Receiver, typename Base, typename DerivedOopClosureType>
185 static typename EnableIf<IsSame<Receiver, Base>::value, void>::type
186 call_do_derived_oop(void (Receiver::*)(oop*, derived_pointer*), void (Base::*)(oop*, derived_pointer*), DerivedOopClosureType* closure, oop* base, derived_pointer* derived) {
187   closure->do_derived_oop(base, derived);
188 }
189 
190 template <typename Receiver, typename Base, typename DerivedOopClosureType>
191 static typename EnableIf<!IsSame<Receiver, Base>::value, void>::type
192 call_do_derived_oop(void (Receiver::*)(oop*, derived_pointer*), void (Base::*)(oop*, derived_pointer*), DerivedOopClosureType* closure, oop* base, derived_pointer* derived) {
193   closure->DerivedOopClosureType::do_derived_oop(base, derived);
194 }
195 
196 template <typename DerivedOopClosureType>
197 inline void Devirtualizer::do_derived_oop(DerivedOopClosureType* closure, oop* base, derived_pointer* derived) {
198   call_do_derived_oop(&DerivedOopClosureType::do_derived_oop, &DerivedOopClosure::do_derived_oop, closure, base, derived);
199 }
200 
201 template <typename Receiver, typename Base, typename BitMapClosureType>
202 static typename EnableIf<IsSame<Receiver, Base>::value, bool>::type
203 call_do_bit(bool (Receiver::*)(BitMap::idx_t), bool (Base::*)(BitMap::idx_t), BitMapClosureType* closure, BitMap::idx_t index) {
204   return closure->do_bit(index);
205 }
206 
207 template <typename Receiver, typename Base, typename BitMapClosureType>
208 static typename EnableIf<!IsSame<Receiver, Base>::value, bool>::type
209 call_do_bit(bool (Receiver::*)(BitMap::idx_t), bool (Base::*)(BitMap::idx_t), BitMapClosureType* closure, BitMap::idx_t index) {
210   return closure->BitMapClosureType::do_bit(index);
211 }
212 
213 template <typename BitMapClosureType>
214 inline bool Devirtualizer::do_bit(BitMapClosureType* closure, BitMap::idx_t index) {
215   return call_do_bit(&BitMapClosureType::do_bit, &BitMapClosure::do_bit, closure, index);
216 }
217 
218 // Dispatch table implementation for *Klass::oop_oop_iterate
219 //
220 // It allows for a single call to do a multi-dispatch to an optimized version
221 //   of oop_oop_iterate that statically know all these types:
222 //   - OopClosureType    : static type give at call site
223 //   - Klass*            : dynamic to static type through Klass::id() -> table index
224 //   - UseCompressedOops : dynamic to static value determined once
225 //
226 // when users call obj->oop_iterate(&cl).
227 //
228 // oopDesc::oop_iterate() calls OopOopIterateDispatch::function(klass)(cl, obj, klass),
229 //   which dispatches to an optimized version of
230 //   [Instance, ObjArry, etc]Klass::oop_oop_iterate(oop, OopClosureType)
231 //
232 // OopClosureType :
233 //   If OopClosureType has an implementation of do_oop (and do_metadata et.al.),
234 //   then the static type of OopClosureType will be used to allow inlining of
235 //   do_oop (even though do_oop is virtual). Otherwise, a virtual call will be
236 //   used when calling do_oop.
237 //

281         _function[KlassType::ID] = &oop_oop_iterate<KlassType, narrowOop>;
282       } else {
283         _function[KlassType::ID] = &oop_oop_iterate<KlassType, oop>;
284       }
285     }
286 
287     template <typename KlassType>
288     void set_resolve_function_and_execute(OopClosureType* cl, oop obj, Klass* k) {
289       set_resolve_function<KlassType>();
290       _function[KlassType::ID](cl, obj, k);
291     }
292 
293   public:
294     FunctionType _function[KLASS_ID_COUNT];
295 
296     Table(){
297       set_init_function<InstanceKlass>();
298       set_init_function<InstanceRefKlass>();
299       set_init_function<InstanceMirrorKlass>();
300       set_init_function<InstanceClassLoaderKlass>();
301       set_init_function<InstanceStackChunkKlass>();
302       set_init_function<ObjArrayKlass>();
303       set_init_function<TypeArrayKlass>();
304     }
305   };
306 
307   static Table _table;
308 public:
309 
310   static FunctionType function(Klass* klass) {
311     return _table._function[klass->id()];
312   }
313 };
314 
315 template <typename OopClosureType>
316 typename OopOopIterateDispatch<OopClosureType>::Table OopOopIterateDispatch<OopClosureType>::_table;
317 
318 
319 template <typename OopClosureType>
320 class OopOopIterateBoundedDispatch {
321 private:

344         _function[KlassType::ID] = &oop_oop_iterate_bounded<KlassType, narrowOop>;
345       } else {
346         _function[KlassType::ID] = &oop_oop_iterate_bounded<KlassType, oop>;
347       }
348     }
349 
350     template <typename KlassType>
351     void set_resolve_function_and_execute(OopClosureType* cl, oop obj, Klass* k, MemRegion mr) {
352       set_resolve_function<KlassType>();
353       _function[KlassType::ID](cl, obj, k, mr);
354     }
355 
356   public:
357     FunctionType _function[KLASS_ID_COUNT];
358 
359     Table(){
360       set_init_function<InstanceKlass>();
361       set_init_function<InstanceRefKlass>();
362       set_init_function<InstanceMirrorKlass>();
363       set_init_function<InstanceClassLoaderKlass>();
364       set_init_function<InstanceStackChunkKlass>();
365       set_init_function<ObjArrayKlass>();
366       set_init_function<TypeArrayKlass>();
367     }
368   };
369 
370   static Table _table;
371 public:
372 
373   static FunctionType function(Klass* klass) {
374     return _table._function[klass->id()];
375   }
376 };
377 
378 template <typename OopClosureType>
379 typename OopOopIterateBoundedDispatch<OopClosureType>::Table OopOopIterateBoundedDispatch<OopClosureType>::_table;
380 
381 
382 template <typename OopClosureType>
383 class OopOopIterateBackwardsDispatch {
384 private:

407         _function[KlassType::ID] = &oop_oop_iterate_backwards<KlassType, narrowOop>;
408       } else {
409         _function[KlassType::ID] = &oop_oop_iterate_backwards<KlassType, oop>;
410       }
411     }
412 
413     template <typename KlassType>
414     void set_resolve_function_and_execute(OopClosureType* cl, oop obj, Klass* k) {
415       set_resolve_function<KlassType>();
416       _function[KlassType::ID](cl, obj, k);
417     }
418 
419   public:
420     FunctionType _function[KLASS_ID_COUNT];
421 
422     Table(){
423       set_init_function<InstanceKlass>();
424       set_init_function<InstanceRefKlass>();
425       set_init_function<InstanceMirrorKlass>();
426       set_init_function<InstanceClassLoaderKlass>();
427       set_init_function<InstanceStackChunkKlass>();
428       set_init_function<ObjArrayKlass>();
429       set_init_function<TypeArrayKlass>();
430     }
431   };
432 
433   static Table _table;
434 public:
435 
436   static FunctionType function(Klass* klass) {
437     return _table._function[klass->id()];
438   }
439 };
440 
441 template <typename OopClosureType>
442 typename OopOopIterateBackwardsDispatch<OopClosureType>::Table OopOopIterateBackwardsDispatch<OopClosureType>::_table;
443 
444 
445 template <typename OopClosureType>
446 void OopIteratorClosureDispatch::oop_oop_iterate(OopClosureType* cl, oop obj, Klass* klass) {
447   OopOopIterateDispatch<OopClosureType>::function(klass)(cl, obj, klass);
< prev index next >