53 virtual void do_oop(oop* p) {} |
53 virtual void do_oop(oop* p) {} |
54 virtual void do_oop(narrowOop* p) {} |
54 virtual void do_oop(narrowOop* p) {} |
55 }; |
55 }; |
56 extern DoNothingClosure do_nothing_cl; |
56 extern DoNothingClosure do_nothing_cl; |
57 |
57 |
58 // ExtendedOopClosure adds extra code to be run during oop iterations. |
58 // OopIterateClosure adds extra code to be run during oop iterations. |
59 // This is needed by the GC and is extracted to a separate type to not |
59 // This is needed by the GC and is extracted to a separate type to not |
60 // pollute the OopClosure interface. |
60 // pollute the OopClosure interface. |
61 class ExtendedOopClosure : public OopClosure { |
61 class OopIterateClosure : public OopClosure { |
62 private: |
62 private: |
63 ReferenceDiscoverer* _ref_discoverer; |
63 ReferenceDiscoverer* _ref_discoverer; |
64 |
64 |
65 protected: |
65 protected: |
66 ExtendedOopClosure(ReferenceDiscoverer* rd) : _ref_discoverer(rd) { } |
66 OopIterateClosure(ReferenceDiscoverer* rd) : _ref_discoverer(rd) { } |
67 ExtendedOopClosure() : _ref_discoverer(NULL) { } |
67 OopIterateClosure() : _ref_discoverer(NULL) { } |
68 ~ExtendedOopClosure() { } |
68 ~OopIterateClosure() { } |
69 |
69 |
70 void set_ref_discoverer_internal(ReferenceDiscoverer* rd) { _ref_discoverer = rd; } |
70 void set_ref_discoverer_internal(ReferenceDiscoverer* rd) { _ref_discoverer = rd; } |
71 |
71 |
72 public: |
72 public: |
73 ReferenceDiscoverer* ref_discoverer() const { return _ref_discoverer; } |
73 ReferenceDiscoverer* ref_discoverer() const { return _ref_discoverer; } |
87 // we invoke the following when running oop_iterate(): |
87 // we invoke the following when running oop_iterate(): |
88 // |
88 // |
89 // 1) do_klass on the header klass pointer. |
89 // 1) do_klass on the header klass pointer. |
90 // 2) do_klass on the klass pointer in the mirrors. |
90 // 2) do_klass on the klass pointer in the mirrors. |
91 // 3) do_cld on the class loader data in class loaders. |
91 // 3) do_cld on the class loader data in class loaders. |
92 // |
92 |
93 // The virtual (without suffix) and the non-virtual (with _nv suffix) need |
93 virtual bool do_metadata() = 0; |
94 // to be updated together, or else the devirtualization will break. |
94 virtual void do_klass(Klass* k) = 0; |
95 // |
95 virtual void do_cld(ClassLoaderData* cld) = 0; |
96 // Providing default implementations of the _nv functions unfortunately |
|
97 // removes the compile-time safeness, but reduces the clutter for the |
|
98 // ExtendedOopClosures that don't need to walk the metadata. |
|
99 // Currently, only CMS and G1 need these. |
|
100 |
|
101 bool do_metadata_nv() { return false; } |
|
102 virtual bool do_metadata() { return do_metadata_nv(); } |
|
103 |
|
104 void do_klass_nv(Klass* k) { ShouldNotReachHere(); } |
|
105 virtual void do_klass(Klass* k) { do_klass_nv(k); } |
|
106 |
|
107 void do_cld_nv(ClassLoaderData* cld) { ShouldNotReachHere(); } |
|
108 virtual void do_cld(ClassLoaderData* cld) { do_cld_nv(cld); } |
|
109 |
96 |
110 // True iff this closure may be safely applied more than once to an oop |
97 // True iff this closure may be safely applied more than once to an oop |
111 // location without an intervening "major reset" (like the end of a GC). |
98 // location without an intervening "major reset" (like the end of a GC). |
112 virtual bool idempotent() { return false; } |
99 virtual bool idempotent() { return false; } |
113 |
100 |
118 // Can be used by subclasses to turn off the default verification of oop fields. |
105 // Can be used by subclasses to turn off the default verification of oop fields. |
119 virtual bool should_verify_oops() { return true; } |
106 virtual bool should_verify_oops() { return true; } |
120 #endif |
107 #endif |
121 }; |
108 }; |
122 |
109 |
|
110 // An OopIterateClosure that can be used when there's no need to visit the Metadata. |
|
111 class BasicOopIterateClosure : public OopIterateClosure { |
|
112 public: |
|
113 BasicOopIterateClosure(ReferenceDiscoverer* rd = NULL) : OopIterateClosure(rd) {} |
|
114 |
|
115 virtual bool do_metadata() { return false; } |
|
116 virtual void do_klass(Klass* k) { ShouldNotReachHere(); } |
|
117 virtual void do_cld(ClassLoaderData* cld) { ShouldNotReachHere(); } |
|
118 }; |
|
119 |
123 // Wrapper closure only used to implement oop_iterate_no_header(). |
120 // Wrapper closure only used to implement oop_iterate_no_header(). |
124 class NoHeaderExtendedOopClosure : public ExtendedOopClosure { |
121 class NoHeaderExtendedOopClosure : public BasicOopIterateClosure { |
125 OopClosure* _wrapped_closure; |
122 OopClosure* _wrapped_closure; |
126 public: |
123 public: |
127 NoHeaderExtendedOopClosure(OopClosure* cl) : _wrapped_closure(cl) {} |
124 NoHeaderExtendedOopClosure(OopClosure* cl) : _wrapped_closure(cl) {} |
128 // Warning: this calls the virtual version do_oop in the the wrapped closure. |
125 // Warning: this calls the virtual version do_oop in the the wrapped closure. |
129 void do_oop_nv(oop* p) { _wrapped_closure->do_oop(p); } |
126 virtual void do_oop(oop* p) { _wrapped_closure->do_oop(p); } |
130 void do_oop_nv(narrowOop* p) { _wrapped_closure->do_oop(p); } |
127 virtual void do_oop(narrowOop* p) { _wrapped_closure->do_oop(p); } |
131 |
|
132 void do_oop(oop* p) { assert(false, "Only the _nv versions should be used"); |
|
133 _wrapped_closure->do_oop(p); } |
|
134 void do_oop(narrowOop* p) { assert(false, "Only the _nv versions should be used"); |
|
135 _wrapped_closure->do_oop(p);} |
|
136 }; |
128 }; |
137 |
129 |
138 class KlassClosure : public Closure { |
130 class KlassClosure : public Closure { |
139 public: |
131 public: |
140 virtual void do_klass(Klass* k) = 0; |
132 virtual void do_klass(Klass* k) = 0; |
159 }; |
151 }; |
160 |
152 |
161 // The base class for all concurrent marking closures, |
153 // The base class for all concurrent marking closures, |
162 // that participates in class unloading. |
154 // that participates in class unloading. |
163 // It's used to proxy through the metadata to the oops defined in them. |
155 // It's used to proxy through the metadata to the oops defined in them. |
164 class MetadataAwareOopClosure: public ExtendedOopClosure { |
156 class MetadataVisitingOopIterateClosure: public OopIterateClosure { |
165 |
157 public: |
166 public: |
158 MetadataVisitingOopIterateClosure(ReferenceDiscoverer* rd = NULL) : OopIterateClosure(rd) { } |
167 MetadataAwareOopClosure() : ExtendedOopClosure() { } |
159 |
168 MetadataAwareOopClosure(ReferenceDiscoverer* rd) : ExtendedOopClosure(rd) { } |
160 virtual bool do_metadata() { return true; } |
169 |
161 virtual void do_klass(Klass* k); |
170 bool do_metadata_nv() { return true; } |
162 virtual void do_cld(ClassLoaderData* cld); |
171 virtual bool do_metadata() { return do_metadata_nv(); } |
|
172 |
|
173 void do_klass_nv(Klass* k); |
|
174 virtual void do_klass(Klass* k) { do_klass_nv(k); } |
|
175 |
|
176 void do_cld_nv(ClassLoaderData* cld); |
|
177 virtual void do_cld(ClassLoaderData* cld) { do_cld_nv(cld); } |
|
178 }; |
163 }; |
179 |
164 |
180 // ObjectClosure is used for iterating through an object space |
165 // ObjectClosure is used for iterating through an object space |
181 |
166 |
182 class ObjectClosure : public Closure { |
167 class ObjectClosure : public Closure { |
202 }; |
187 }; |
203 |
188 |
204 // Applies an oop closure to all ref fields in objects iterated over in an |
189 // Applies an oop closure to all ref fields in objects iterated over in an |
205 // object iteration. |
190 // object iteration. |
206 class ObjectToOopClosure: public ObjectClosure { |
191 class ObjectToOopClosure: public ObjectClosure { |
207 ExtendedOopClosure* _cl; |
192 OopIterateClosure* _cl; |
208 public: |
193 public: |
209 void do_object(oop obj); |
194 void do_object(oop obj); |
210 ObjectToOopClosure(ExtendedOopClosure* cl) : _cl(cl) {} |
195 ObjectToOopClosure(OopIterateClosure* cl) : _cl(cl) {} |
211 }; |
196 }; |
212 |
197 |
213 // A version of ObjectClosure that is expected to be robust |
198 // A version of ObjectClosure that is expected to be robust |
214 // in the face of possibly uninitialized objects. |
199 // in the face of possibly uninitialized objects. |
215 class ObjectClosureCareful : public ObjectClosure { |
200 class ObjectClosureCareful : public ObjectClosure { |
369 static void store_symbol(Symbol** p, Symbol* sym) { |
354 static void store_symbol(Symbol** p, Symbol* sym) { |
370 *p = (Symbol*)(intptr_t(sym) | (intptr_t(*p) & 1)); |
355 *p = (Symbol*)(intptr_t(sym) | (intptr_t(*p) & 1)); |
371 } |
356 } |
372 }; |
357 }; |
373 |
358 |
374 // The two class template specializations are used to dispatch calls |
359 // Dispatches to the non-virtual functions if OopClosureType has |
375 // to the ExtendedOopClosure functions. If use_non_virtual_call is true, |
360 // a concrete implementation, otherwise a virtual call is taken. |
376 // the non-virtual versions are called (E.g. do_oop_nv), otherwise the |
361 class Devirtualizer { |
377 // virtual versions are called (E.g. do_oop). |
362 public: |
378 |
363 template <typename OopClosureType, typename T> static void do_oop_no_verify(OopClosureType* closure, T* p); |
379 template <bool use_non_virtual_call> |
364 template <typename OopClosureType, typename T> static void do_oop(OopClosureType* closure, T* p); |
380 class Devirtualizer {}; |
365 template <typename OopClosureType> static void do_klass(OopClosureType* closure, Klass* k); |
381 |
366 template <typename OopClosureType> static void do_cld(OopClosureType* closure, ClassLoaderData* cld); |
382 // Dispatches to the non-virtual functions. |
367 template <typename OopClosureType> static bool do_metadata(OopClosureType* closure); |
383 template <> class Devirtualizer<true> { |
368 }; |
384 public: |
369 |
385 template <class OopClosureType, typename T> static void do_oop(OopClosureType* closure, T* p); |
370 class OopIteratorClosureDispatch { |
386 template <class OopClosureType> static void do_klass(OopClosureType* closure, Klass* k); |
371 public: |
387 template <class OopClosureType> static void do_cld(OopClosureType* closure, ClassLoaderData* cld); |
372 template <typename OopClosureType> static void oop_oop_iterate(OopClosureType* cl, oop obj, Klass* klass); |
388 template <class OopClosureType> static bool do_metadata(OopClosureType* closure); |
373 template <typename OopClosureType> static void oop_oop_iterate(OopClosureType* cl, oop obj, Klass* klass, MemRegion mr); |
389 }; |
374 template <typename OopClosureType> static void oop_oop_iterate_backwards(OopClosureType* cl, oop obj, Klass* klass); |
390 |
|
391 // Dispatches to the virtual functions. |
|
392 template <> class Devirtualizer<false> { |
|
393 public: |
|
394 template <class OopClosureType, typename T> static void do_oop(OopClosureType* closure, T* p); |
|
395 template <class OopClosureType> static void do_klass(OopClosureType* closure, Klass* k); |
|
396 template <class OopClosureType> static void do_cld(OopClosureType* closure, ClassLoaderData* cld); |
|
397 template <class OopClosureType> static bool do_metadata(OopClosureType* closure); |
|
398 }; |
375 }; |
399 |
376 |
400 #endif // SHARE_VM_MEMORY_ITERATOR_HPP |
377 #endif // SHARE_VM_MEMORY_ITERATOR_HPP |