49 // functions that the iteration should cease. |
51 // functions that the iteration should cease. |
50 bool abort() { return _abort; } |
52 bool abort() { return _abort; } |
51 void clear_abort() { _abort = false; } |
53 void clear_abort() { _abort = false; } |
52 }; |
54 }; |
53 |
55 |
54 // OopClosure is used for iterating through roots (oop*) |
56 // OopClosure is used for iterating through references to Java objects. |
55 |
57 |
56 class OopClosure : public Closure { |
58 class OopClosure : public Closure { |
57 public: |
59 public: |
58 ReferenceProcessor* _ref_processor; |
|
59 OopClosure(ReferenceProcessor* rp) : _ref_processor(rp) { } |
|
60 OopClosure() : _ref_processor(NULL) { } |
|
61 virtual void do_oop(oop* o) = 0; |
60 virtual void do_oop(oop* o) = 0; |
62 virtual void do_oop_v(oop* o) { do_oop(o); } |
61 virtual void do_oop_v(oop* o) { do_oop(o); } |
63 virtual void do_oop(narrowOop* o) = 0; |
62 virtual void do_oop(narrowOop* o) = 0; |
64 virtual void do_oop_v(narrowOop* o) { do_oop(o); } |
63 virtual void do_oop_v(narrowOop* o) { do_oop(o); } |
65 |
64 }; |
66 // In support of post-processing of weak links of KlassKlass objects; |
65 |
67 // see KlassKlass::oop_oop_iterate(). |
66 // ExtendedOopClosure adds extra code to be run during oop iterations. |
68 |
67 // This is needed by the GC and is extracted to a separate type to not |
69 virtual const bool should_remember_klasses() const { |
68 // pollute the OopClosure interface. |
70 assert(!must_remember_klasses(), "Should have overriden this method."); |
69 class ExtendedOopClosure : public OopClosure { |
71 return false; |
70 public: |
72 } |
71 ReferenceProcessor* _ref_processor; |
73 |
72 ExtendedOopClosure(ReferenceProcessor* rp) : _ref_processor(rp) { } |
74 virtual void remember_klass(Klass* k) { /* do nothing */ } |
73 ExtendedOopClosure() : OopClosure(), _ref_processor(NULL) { } |
75 |
74 |
76 // In support of post-processing of weak references in |
75 // If the do_metadata functions return "true", |
77 // ProfileData (MethodDataOop) objects; see, for example, |
76 // we invoke the following when running oop_iterate(): |
78 // VirtualCallData::oop_iterate(). |
77 // |
79 virtual const bool should_remember_mdo() const { return false; } |
78 // 1) do_klass on the header klass pointer. |
80 virtual void remember_mdo(DataLayout* v) { /* do nothing */ } |
79 // 2) do_klass on the klass pointer in the mirrors. |
81 |
80 // 3) do_class_loader_data on the class loader data in class loaders. |
82 // The methods below control how object iterations invoking this closure |
81 // |
83 // should be performed: |
82 // The virtual (without suffix) and the non-virtual (with _nv suffix) need |
84 |
83 // to be updated together, or else the devirtualization will break. |
85 // If "true", invoke on header klass field. |
84 // |
86 bool do_header() { return true; } // Note that this is non-virtual. |
85 // Providing default implementations of the _nv functions unfortunately |
|
86 // removes the compile-time safeness, but reduces the clutter for the |
|
87 // ExtendedOopClosures that don't need to walk the metadata. Currently, |
|
88 // only CMS needs these. |
|
89 |
|
90 virtual bool do_metadata() { return do_metadata_nv(); } |
|
91 bool do_metadata_v() { return do_metadata(); } |
|
92 bool do_metadata_nv() { return false; } |
|
93 |
|
94 virtual void do_klass(Klass* k) { do_klass_nv(k); } |
|
95 void do_klass_v(Klass* k) { do_klass(k); } |
|
96 void do_klass_nv(Klass* k) { ShouldNotReachHere(); } |
|
97 |
|
98 virtual void do_class_loader_data(ClassLoaderData* cld) { ShouldNotReachHere(); } |
|
99 |
87 // Controls how prefetching is done for invocations of this closure. |
100 // Controls how prefetching is done for invocations of this closure. |
88 Prefetch::style prefetch_style() { // Note that this is non-virtual. |
101 Prefetch::style prefetch_style() { // Note that this is non-virtual. |
89 return Prefetch::do_none; |
102 return Prefetch::do_none; |
90 } |
103 } |
91 |
104 |
92 // True iff this closure may be safely applied more than once to an oop |
105 // True iff this closure may be safely applied more than once to an oop |
93 // location without an intervening "major reset" (like the end of a GC). |
106 // location without an intervening "major reset" (like the end of a GC). |
94 virtual bool idempotent() { return false; } |
107 virtual bool idempotent() { return false; } |
95 virtual bool apply_to_weak_ref_discovered_field() { return false; } |
108 virtual bool apply_to_weak_ref_discovered_field() { return false; } |
96 |
109 }; |
97 #ifdef ASSERT |
110 |
98 static bool _must_remember_klasses; |
111 // Wrapper closure only used to implement oop_iterate_no_header(). |
99 static bool must_remember_klasses(); |
112 class NoHeaderExtendedOopClosure : public ExtendedOopClosure { |
100 static void set_must_remember_klasses(bool v); |
113 OopClosure* _wrapped_closure; |
101 #endif |
114 public: |
|
115 NoHeaderExtendedOopClosure(OopClosure* cl) : _wrapped_closure(cl) {} |
|
116 // Warning: this calls the virtual version do_oop in the the wrapped closure. |
|
117 void do_oop_nv(oop* p) { _wrapped_closure->do_oop(p); } |
|
118 void do_oop_nv(narrowOop* p) { _wrapped_closure->do_oop(p); } |
|
119 |
|
120 void do_oop(oop* p) { assert(false, "Only the _nv versions should be used"); |
|
121 _wrapped_closure->do_oop(p); } |
|
122 void do_oop(narrowOop* p) { assert(false, "Only the _nv versions should be used"); |
|
123 _wrapped_closure->do_oop(p);} |
|
124 }; |
|
125 |
|
126 class KlassClosure : public Closure { |
|
127 public: |
|
128 virtual void do_klass(Klass* k) = 0; |
102 }; |
129 }; |
103 |
130 |
104 // ObjectClosure is used for iterating through an object space |
131 // ObjectClosure is used for iterating through an object space |
105 |
132 |
106 class ObjectClosure : public Closure { |
133 class ObjectClosure : public Closure { |
261 virtual bool should_return() = 0; |
288 virtual bool should_return() = 0; |
262 }; |
289 }; |
263 |
290 |
264 // Abstract closure for serializing data (read or write). |
291 // Abstract closure for serializing data (read or write). |
265 |
292 |
266 class SerializeOopClosure : public OopClosure { |
293 class SerializeClosure : public Closure { |
267 public: |
294 public: |
268 // Return bool indicating whether closure implements read or write. |
295 // Return bool indicating whether closure implements read or write. |
269 virtual bool reading() const = 0; |
296 virtual bool reading() const = 0; |
270 |
297 |
271 // Read/write the int pointed to by i. |
|
272 virtual void do_int(int* i) = 0; |
|
273 |
|
274 // Read/write the size_t pointed to by i. |
|
275 virtual void do_size_t(size_t* i) = 0; |
|
276 |
|
277 // Read/write the void pointer pointed to by p. |
298 // Read/write the void pointer pointed to by p. |
278 virtual void do_ptr(void** p) = 0; |
299 virtual void do_ptr(void** p) = 0; |
279 |
|
280 // Read/write the HeapWord pointer pointed to be p. |
|
281 virtual void do_ptr(HeapWord** p) = 0; |
|
282 |
300 |
283 // Read/write the region specified. |
301 // Read/write the region specified. |
284 virtual void do_region(u_char* start, size_t size) = 0; |
302 virtual void do_region(u_char* start, size_t size) = 0; |
285 |
303 |
286 // Check/write the tag. If reading, then compare the tag against |
304 // Check/write the tag. If reading, then compare the tag against |
304 static void store_symbol(Symbol** p, Symbol* sym) { |
322 static void store_symbol(Symbol** p, Symbol* sym) { |
305 *p = (Symbol*)(intptr_t(sym) | (intptr_t(*p) & 1)); |
323 *p = (Symbol*)(intptr_t(sym) | (intptr_t(*p) & 1)); |
306 } |
324 } |
307 }; |
325 }; |
308 |
326 |
309 #ifdef ASSERT |
|
310 // This class is used to flag phases of a collection that |
|
311 // can unload classes and which should override the |
|
312 // should_remember_klasses() and remember_klass() of OopClosure. |
|
313 // The _must_remember_klasses is set in the contructor and restored |
|
314 // in the destructor. _must_remember_klasses is checked in assertions |
|
315 // in the OopClosure implementations of should_remember_klasses() and |
|
316 // remember_klass() and the expectation is that the OopClosure |
|
317 // implementation should not be in use if _must_remember_klasses is set. |
|
318 // Instances of RememberKlassesChecker can be place in |
|
319 // marking phases of collections which can do class unloading. |
|
320 // RememberKlassesChecker can be passed "false" to turn off checking. |
|
321 // It is used by CMS when CMS yields to a different collector. |
|
322 class RememberKlassesChecker: StackObj { |
|
323 bool _saved_state; |
|
324 bool _do_check; |
|
325 public: |
|
326 RememberKlassesChecker(bool checking_on) : _saved_state(false), |
|
327 _do_check(true) { |
|
328 // The ClassUnloading unloading flag affects the collectors except |
|
329 // for CMS. |
|
330 // CMS unloads classes if CMSClassUnloadingEnabled is true or |
|
331 // if ExplicitGCInvokesConcurrentAndUnloadsClasses is true and |
|
332 // the current collection is an explicit collection. Turning |
|
333 // on the checking in general for |
|
334 // ExplicitGCInvokesConcurrentAndUnloadsClasses and |
|
335 // UseConcMarkSweepGC should not lead to false positives. |
|
336 _do_check = |
|
337 ClassUnloading && !UseConcMarkSweepGC || |
|
338 CMSClassUnloadingEnabled && UseConcMarkSweepGC || |
|
339 ExplicitGCInvokesConcurrentAndUnloadsClasses && UseConcMarkSweepGC; |
|
340 if (_do_check) { |
|
341 _saved_state = OopClosure::must_remember_klasses(); |
|
342 OopClosure::set_must_remember_klasses(checking_on); |
|
343 } |
|
344 } |
|
345 ~RememberKlassesChecker() { |
|
346 if (_do_check) { |
|
347 OopClosure::set_must_remember_klasses(_saved_state); |
|
348 } |
|
349 } |
|
350 }; |
|
351 #endif // ASSERT |
|
352 |
|
353 #endif // SHARE_VM_MEMORY_ITERATOR_HPP |
327 #endif // SHARE_VM_MEMORY_ITERATOR_HPP |