42 |
42 |
43 // OopClosure is used for iterating through references to Java objects. |
43 // OopClosure is used for iterating through references to Java objects. |
44 class OopClosure : public Closure { |
44 class OopClosure : public Closure { |
45 public: |
45 public: |
46 virtual void do_oop(oop* o) = 0; |
46 virtual void do_oop(oop* o) = 0; |
47 virtual void do_oop_v(oop* o) { do_oop(o); } |
|
48 virtual void do_oop(narrowOop* o) = 0; |
47 virtual void do_oop(narrowOop* o) = 0; |
49 virtual void do_oop_v(narrowOop* o) { do_oop(o); } |
|
50 }; |
48 }; |
51 |
49 |
52 // ExtendedOopClosure adds extra code to be run during oop iterations. |
50 // ExtendedOopClosure adds extra code to be run during oop iterations. |
53 // This is needed by the GC and is extracted to a separate type to not |
51 // This is needed by the GC and is extracted to a separate type to not |
54 // pollute the OopClosure interface. |
52 // pollute the OopClosure interface. |
72 // removes the compile-time safeness, but reduces the clutter for the |
70 // removes the compile-time safeness, but reduces the clutter for the |
73 // ExtendedOopClosures that don't need to walk the metadata. |
71 // ExtendedOopClosures that don't need to walk the metadata. |
74 // Currently, only CMS and G1 need these. |
72 // Currently, only CMS and G1 need these. |
75 |
73 |
76 virtual bool do_metadata() { return do_metadata_nv(); } |
74 virtual bool do_metadata() { return do_metadata_nv(); } |
77 bool do_metadata_v() { return do_metadata(); } |
|
78 bool do_metadata_nv() { return false; } |
75 bool do_metadata_nv() { return false; } |
79 |
76 |
80 virtual void do_klass(Klass* k) { do_klass_nv(k); } |
77 virtual void do_klass(Klass* k) { do_klass_nv(k); } |
81 void do_klass_v(Klass* k) { do_klass(k); } |
|
82 void do_klass_nv(Klass* k) { ShouldNotReachHere(); } |
78 void do_klass_nv(Klass* k) { ShouldNotReachHere(); } |
83 |
79 |
84 virtual void do_class_loader_data(ClassLoaderData* cld) { ShouldNotReachHere(); } |
80 virtual void do_class_loader_data(ClassLoaderData* cld) { ShouldNotReachHere(); } |
85 |
81 |
86 // True iff this closure may be safely applied more than once to an oop |
82 // True iff this closure may be safely applied more than once to an oop |
87 // location without an intervening "major reset" (like the end of a GC). |
83 // location without an intervening "major reset" (like the end of a GC). |
88 virtual bool idempotent() { return false; } |
84 virtual bool idempotent() { return false; } |
89 virtual bool apply_to_weak_ref_discovered_field() { return false; } |
85 virtual bool apply_to_weak_ref_discovered_field() { return false; } |
|
86 |
|
87 #ifdef ASSERT |
|
88 // Default verification of each visited oop field. |
|
89 template <typename T> void verify(T* p); |
|
90 |
|
91 // Can be used by subclasses to turn off the default verification of oop fields. |
|
92 virtual bool should_verify_oops() { return true; } |
|
93 #endif |
90 }; |
94 }; |
91 |
95 |
92 // Wrapper closure only used to implement oop_iterate_no_header(). |
96 // Wrapper closure only used to implement oop_iterate_no_header(). |
93 class NoHeaderExtendedOopClosure : public ExtendedOopClosure { |
97 class NoHeaderExtendedOopClosure : public ExtendedOopClosure { |
94 OopClosure* _wrapped_closure; |
98 OopClosure* _wrapped_closure; |
362 static void store_symbol(Symbol** p, Symbol* sym) { |
366 static void store_symbol(Symbol** p, Symbol* sym) { |
363 *p = (Symbol*)(intptr_t(sym) | (intptr_t(*p) & 1)); |
367 *p = (Symbol*)(intptr_t(sym) | (intptr_t(*p) & 1)); |
364 } |
368 } |
365 }; |
369 }; |
366 |
370 |
367 |
371 // The two class template specializations are used to dispatch calls |
368 // Helper defines for ExtendOopClosure |
372 // to the ExtendedOopClosure functions. If use_non_virtual_call is true, |
369 |
373 // the non-virtual versions are called (E.g. do_oop_nv), otherwise the |
370 #define if_do_metadata_checked(closure, nv_suffix) \ |
374 // virtual versions are called (E.g. do_oop). |
371 /* Make sure the non-virtual and the virtual versions match. */ \ |
375 |
372 assert(closure->do_metadata##nv_suffix() == closure->do_metadata(), \ |
376 template <bool use_non_virtual_call> |
373 "Inconsistency in do_metadata"); \ |
377 class Devirtualizer {}; |
374 if (closure->do_metadata##nv_suffix()) |
378 |
375 |
379 // Dispatches to the non-virtual functions. |
376 #define assert_should_ignore_metadata(closure, nv_suffix) \ |
380 template <> class Devirtualizer<true> { |
377 assert(!closure->do_metadata##nv_suffix(), "Code to handle metadata is not implemented") |
381 public: |
|
382 template <class OopClosureType, typename T> static void do_oop(OopClosureType* closure, T* p); |
|
383 template <class OopClosureType> static void do_klass(OopClosureType* closure, Klass* k); |
|
384 template <class OopClosureType> static bool do_metadata(OopClosureType* closure); |
|
385 }; |
|
386 |
|
387 // Dispatches to the virtual functions. |
|
388 template <> class Devirtualizer<false> { |
|
389 public: |
|
390 template <class OopClosureType, typename T> static void do_oop(OopClosureType* closure, T* p); |
|
391 template <class OopClosureType> static void do_klass(OopClosureType* closure, Klass* k); |
|
392 template <class OopClosureType> static bool do_metadata(OopClosureType* closure); |
|
393 }; |
|
394 |
|
395 // Helper to convert the oop iterate macro suffixes into bool values that can be used by template functions. |
|
396 #define nvs_nv_to_bool true |
|
397 #define nvs_v_to_bool false |
|
398 #define nvs_to_bool(nv_suffix) nvs##nv_suffix##_to_bool |
378 |
399 |
379 #endif // SHARE_VM_MEMORY_ITERATOR_HPP |
400 #endif // SHARE_VM_MEMORY_ITERATOR_HPP |