< prev index next >

src/hotspot/share/memory/iterator.hpp

Print this page

 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 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_HPP
 26 #define SHARE_MEMORY_ITERATOR_HPP
 27 
 28 #include "memory/allocation.hpp"
 29 #include "memory/memRegion.hpp"
 30 #include "oops/oopsHierarchy.hpp"

 31 
 32 class CodeBlob;
 33 class nmethod;
 34 class ReferenceDiscoverer;
 35 class DataLayout;
 36 class KlassClosure;
 37 class ClassLoaderData;
 38 class Symbol;
 39 class Metadata;
 40 class Thread;
 41 
 42 // The following classes are C++ `closures` for iterating over objects, roots and spaces
 43 
 44 class Closure : public StackObj { };
 45 
 46 // Thread iterator
 47 class ThreadClosure {
 48  public:
 49   virtual void do_thread(Thread* thread) = 0;
 50 };

 85   enum ReferenceIterationMode {
 86     DO_DISCOVERY,                // Apply closure and discover references
 87     DO_DISCOVERED_AND_DISCOVERY, // Apply closure to discovered field and do discovery
 88     DO_FIELDS,                   // Apply closure to all fields
 89     DO_FIELDS_EXCEPT_REFERENT    // Apply closure to all fields except the referent field
 90   };
 91 
 92   // The default iteration mode is to do discovery.
 93   virtual ReferenceIterationMode reference_iteration_mode() { return DO_DISCOVERY; }
 94 
 95   // If the do_metadata functions return "true",
 96   // we invoke the following when running oop_iterate():
 97   //
 98   // 1) do_klass on the header klass pointer.
 99   // 2) do_klass on the klass pointer in the mirrors.
100   // 3) do_cld   on the class loader data in class loaders.
101 
102   virtual bool do_metadata() = 0;
103   virtual void do_klass(Klass* k) = 0;
104   virtual void do_cld(ClassLoaderData* cld) = 0;


105 };
106 
107 // An OopIterateClosure that can be used when there's no need to visit the Metadata.
108 class BasicOopIterateClosure : public OopIterateClosure {
109 public:
110   BasicOopIterateClosure(ReferenceDiscoverer* rd = NULL) : OopIterateClosure(rd) {}
111 
112   virtual bool do_metadata() { return false; }
113   virtual void do_klass(Klass* k) { ShouldNotReachHere(); }
114   virtual void do_cld(ClassLoaderData* cld) { ShouldNotReachHere(); }









115 };
116 
117 class KlassClosure : public Closure {
118  public:
119   virtual void do_klass(Klass* k) = 0;
120 };
121 
122 class CLDClosure : public Closure {
123  public:
124   virtual void do_cld(ClassLoaderData* cld) = 0;
125 };
126 
127 class MetadataClosure : public Closure {
128  public:
129   virtual void do_metadata(Metadata* md) = 0;
130 };
131 
132 
133 class CLDToOopClosure : public CLDClosure {
134   OopClosure*       _oop_closure;

144 };
145 
146 template <int claim>
147 class ClaimingCLDToOopClosure : public CLDToOopClosure {
148 public:
149   ClaimingCLDToOopClosure(OopClosure* cl) : CLDToOopClosure(cl, claim) {}
150 };
151 
152 class ClaimMetadataVisitingOopIterateClosure : public OopIterateClosure {
153  protected:
154   const int _claim;
155 
156  public:
157   ClaimMetadataVisitingOopIterateClosure(int claim, ReferenceDiscoverer* rd = NULL) :
158       OopIterateClosure(rd),
159       _claim(claim) { }
160 
161   virtual bool do_metadata() { return true; }
162   virtual void do_klass(Klass* k);
163   virtual void do_cld(ClassLoaderData* cld);


164 };
165 
166 // The base class for all concurrent marking closures,
167 // that participates in class unloading.
168 // It's used to proxy through the metadata to the oops defined in them.
169 class MetadataVisitingOopIterateClosure: public ClaimMetadataVisitingOopIterateClosure {
170  public:
171   MetadataVisitingOopIterateClosure(ReferenceDiscoverer* rd = NULL);
172 };
173 
174 // ObjectClosure is used for iterating through an object space
175 
176 class ObjectClosure : public Closure {
177  public:
178   // Called for each object.
179   virtual void do_object(oop obj) = 0;
180 };
181 
182 
183 class BoolObjectClosure : public Closure {

217 
218 class CompactibleSpaceClosure : public StackObj {
219  public:
220   // Called for each compactible space
221   virtual void do_space(CompactibleSpace* s) = 0;
222 };
223 
224 
225 // CodeBlobClosure is used for iterating through code blobs
226 // in the code cache or on thread stacks
227 
228 class CodeBlobClosure : public Closure {
229  public:
230   // Called for each code blob.
231   virtual void do_code_blob(CodeBlob* cb) = 0;
232 };
233 
234 // Applies an oop closure to all ref fields in code blobs
235 // iterated over in an object iteration.
236 class CodeBlobToOopClosure : public CodeBlobClosure {

237   OopClosure* _cl;
238   bool _fix_relocations;
239  protected:
240   void do_nmethod(nmethod* nm);
241  public:
242   // If fix_relocations(), then cl must copy objects to their new location immediately to avoid
243   // patching nmethods with the old locations.
244   CodeBlobToOopClosure(OopClosure* cl, bool fix_relocations) : _cl(cl), _fix_relocations(fix_relocations) {}
245   virtual void do_code_blob(CodeBlob* cb);
246 
247   bool fix_relocations() const { return _fix_relocations; }
248   const static bool FixRelocations = true;
249 };
250 
251 class MarkingCodeBlobClosure : public CodeBlobToOopClosure {


252  public:
253   MarkingCodeBlobClosure(OopClosure* cl, bool fix_relocations) : CodeBlobToOopClosure(cl, fix_relocations) {}


254   // Called for each code blob, but at most once per unique blob.
255 
256   virtual void do_code_blob(CodeBlob* cb);
257 };
258 
259 class NMethodClosure : public Closure {
260  public:
261   virtual void do_nmethod(nmethod* n) = 0;
262 };
263 
264 class CodeBlobToNMethodClosure : public CodeBlobClosure {
265   NMethodClosure* const _nm_cl;
266 
267  public:
268   CodeBlobToNMethodClosure(NMethodClosure* nm_cl) : _nm_cl(nm_cl) {}
269 
270   virtual void do_code_blob(CodeBlob* cb);
271 };
272 
273 // MonitorClosure is used for iterating over monitors in the monitors cache

338 
339 class SymbolClosure : public StackObj {
340  public:
341   virtual void do_symbol(Symbol**) = 0;
342 };
343 
344 template <typename E>
345 class CompareClosure : public Closure {
346 public:
347     virtual int do_compare(const E&, const E&) = 0;
348 };
349 
350 // Dispatches to the non-virtual functions if OopClosureType has
351 // a concrete implementation, otherwise a virtual call is taken.
352 class Devirtualizer {
353  public:
354   template <typename OopClosureType, typename T> static void do_oop(OopClosureType* closure, T* p);
355   template <typename OopClosureType>             static void do_klass(OopClosureType* closure, Klass* k);
356   template <typename OopClosureType>             static void do_cld(OopClosureType* closure, ClassLoaderData* cld);
357   template <typename OopClosureType>             static bool do_metadata(OopClosureType* closure);


358 };
359 
360 class OopIteratorClosureDispatch {
361  public:
362   template <typename OopClosureType> static void oop_oop_iterate(OopClosureType* cl, oop obj, Klass* klass);
363   template <typename OopClosureType> static void oop_oop_iterate(OopClosureType* cl, oop obj, Klass* klass, MemRegion mr);
364   template <typename OopClosureType> static void oop_oop_iterate_backwards(OopClosureType* cl, oop obj, Klass* klass);
365 };
366 
367 #endif // SHARE_MEMORY_ITERATOR_HPP

 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 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_HPP
 26 #define SHARE_MEMORY_ITERATOR_HPP
 27 
 28 #include "memory/allocation.hpp"
 29 #include "memory/memRegion.hpp"
 30 #include "oops/oopsHierarchy.hpp"
 31 #include "utilities/bitMap.hpp"
 32 
 33 class CodeBlob;
 34 class nmethod;
 35 class ReferenceDiscoverer;
 36 class DataLayout;
 37 class KlassClosure;
 38 class ClassLoaderData;
 39 class Symbol;
 40 class Metadata;
 41 class Thread;
 42 
 43 // The following classes are C++ `closures` for iterating over objects, roots and spaces
 44 
 45 class Closure : public StackObj { };
 46 
 47 // Thread iterator
 48 class ThreadClosure {
 49  public:
 50   virtual void do_thread(Thread* thread) = 0;
 51 };

 86   enum ReferenceIterationMode {
 87     DO_DISCOVERY,                // Apply closure and discover references
 88     DO_DISCOVERED_AND_DISCOVERY, // Apply closure to discovered field and do discovery
 89     DO_FIELDS,                   // Apply closure to all fields
 90     DO_FIELDS_EXCEPT_REFERENT    // Apply closure to all fields except the referent field
 91   };
 92 
 93   // The default iteration mode is to do discovery.
 94   virtual ReferenceIterationMode reference_iteration_mode() { return DO_DISCOVERY; }
 95 
 96   // If the do_metadata functions return "true",
 97   // we invoke the following when running oop_iterate():
 98   //
 99   // 1) do_klass on the header klass pointer.
100   // 2) do_klass on the klass pointer in the mirrors.
101   // 3) do_cld   on the class loader data in class loaders.
102 
103   virtual bool do_metadata() = 0;
104   virtual void do_klass(Klass* k) = 0;
105   virtual void do_cld(ClassLoaderData* cld) = 0;
106   virtual void do_method(Method* m) = 0;
107   virtual void do_nmethod(nmethod* nm) = 0;
108 };
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   virtual void do_method(Method* m) { ShouldNotReachHere(); }
119   virtual void do_nmethod(nmethod* nm) { ShouldNotReachHere(); }
120 };
121 
122 enum class derived_pointer : intptr_t;
123 class DerivedOopClosure : public Closure {
124  public:
125   enum { SkipNull = true };
126   virtual void do_derived_oop(oop* base, derived_pointer* derived) = 0;
127 };
128 
129 class KlassClosure : public Closure {
130  public:
131   virtual void do_klass(Klass* k) = 0;
132 };
133 
134 class CLDClosure : public Closure {
135  public:
136   virtual void do_cld(ClassLoaderData* cld) = 0;
137 };
138 
139 class MetadataClosure : public Closure {
140  public:
141   virtual void do_metadata(Metadata* md) = 0;
142 };
143 
144 
145 class CLDToOopClosure : public CLDClosure {
146   OopClosure*       _oop_closure;

156 };
157 
158 template <int claim>
159 class ClaimingCLDToOopClosure : public CLDToOopClosure {
160 public:
161   ClaimingCLDToOopClosure(OopClosure* cl) : CLDToOopClosure(cl, claim) {}
162 };
163 
164 class ClaimMetadataVisitingOopIterateClosure : public OopIterateClosure {
165  protected:
166   const int _claim;
167 
168  public:
169   ClaimMetadataVisitingOopIterateClosure(int claim, ReferenceDiscoverer* rd = NULL) :
170       OopIterateClosure(rd),
171       _claim(claim) { }
172 
173   virtual bool do_metadata() { return true; }
174   virtual void do_klass(Klass* k);
175   virtual void do_cld(ClassLoaderData* cld);
176   virtual void do_method(Method* m);
177   virtual void do_nmethod(nmethod* nm);
178 };
179 
180 // The base class for all concurrent marking closures,
181 // that participates in class unloading.
182 // It's used to proxy through the metadata to the oops defined in them.
183 class MetadataVisitingOopIterateClosure: public ClaimMetadataVisitingOopIterateClosure {
184  public:
185   MetadataVisitingOopIterateClosure(ReferenceDiscoverer* rd = NULL);
186 };
187 
188 // ObjectClosure is used for iterating through an object space
189 
190 class ObjectClosure : public Closure {
191  public:
192   // Called for each object.
193   virtual void do_object(oop obj) = 0;
194 };
195 
196 
197 class BoolObjectClosure : public Closure {

231 
232 class CompactibleSpaceClosure : public StackObj {
233  public:
234   // Called for each compactible space
235   virtual void do_space(CompactibleSpace* s) = 0;
236 };
237 
238 
239 // CodeBlobClosure is used for iterating through code blobs
240 // in the code cache or on thread stacks
241 
242 class CodeBlobClosure : public Closure {
243  public:
244   // Called for each code blob.
245   virtual void do_code_blob(CodeBlob* cb) = 0;
246 };
247 
248 // Applies an oop closure to all ref fields in code blobs
249 // iterated over in an object iteration.
250 class CodeBlobToOopClosure : public CodeBlobClosure {
251  protected:
252   OopClosure* _cl;
253   bool _fix_relocations;

254   void do_nmethod(nmethod* nm);
255  public:
256   // If fix_relocations(), then cl must copy objects to their new location immediately to avoid
257   // patching nmethods with the old locations.
258   CodeBlobToOopClosure(OopClosure* cl, bool fix_relocations) : _cl(cl), _fix_relocations(fix_relocations) {}
259   virtual void do_code_blob(CodeBlob* cb);
260 
261   bool fix_relocations() const { return _fix_relocations; }
262   const static bool FixRelocations = true;
263 };
264 
265 class MarkingCodeBlobClosure : public CodeBlobToOopClosure {
266   bool _keepalive_nmethods;
267 
268  public:
269   MarkingCodeBlobClosure(OopClosure* cl, bool fix_relocations, bool keepalive_nmethods) :
270       CodeBlobToOopClosure(cl, fix_relocations),
271       _keepalive_nmethods(keepalive_nmethods) {}
272   // Called for each code blob, but at most once per unique blob.
273 
274   virtual void do_code_blob(CodeBlob* cb);
275 };
276 
277 class NMethodClosure : public Closure {
278  public:
279   virtual void do_nmethod(nmethod* n) = 0;
280 };
281 
282 class CodeBlobToNMethodClosure : public CodeBlobClosure {
283   NMethodClosure* const _nm_cl;
284 
285  public:
286   CodeBlobToNMethodClosure(NMethodClosure* nm_cl) : _nm_cl(nm_cl) {}
287 
288   virtual void do_code_blob(CodeBlob* cb);
289 };
290 
291 // MonitorClosure is used for iterating over monitors in the monitors cache

356 
357 class SymbolClosure : public StackObj {
358  public:
359   virtual void do_symbol(Symbol**) = 0;
360 };
361 
362 template <typename E>
363 class CompareClosure : public Closure {
364 public:
365     virtual int do_compare(const E&, const E&) = 0;
366 };
367 
368 // Dispatches to the non-virtual functions if OopClosureType has
369 // a concrete implementation, otherwise a virtual call is taken.
370 class Devirtualizer {
371  public:
372   template <typename OopClosureType, typename T> static void do_oop(OopClosureType* closure, T* p);
373   template <typename OopClosureType>             static void do_klass(OopClosureType* closure, Klass* k);
374   template <typename OopClosureType>             static void do_cld(OopClosureType* closure, ClassLoaderData* cld);
375   template <typename OopClosureType>             static bool do_metadata(OopClosureType* closure);
376   template <typename DerivedOopClosureType>      static void do_derived_oop(DerivedOopClosureType* closure, oop* base, derived_pointer* derived);
377   template <typename BitMapClosureType>          static bool do_bit(BitMapClosureType* closure, BitMap::idx_t index);
378 };
379 
380 class OopIteratorClosureDispatch {
381  public:
382   template <typename OopClosureType> static void oop_oop_iterate(OopClosureType* cl, oop obj, Klass* klass);
383   template <typename OopClosureType> static void oop_oop_iterate(OopClosureType* cl, oop obj, Klass* klass, MemRegion mr);
384   template <typename OopClosureType> static void oop_oop_iterate_backwards(OopClosureType* cl, oop obj, Klass* klass);
385 };
386 
387 #endif // SHARE_MEMORY_ITERATOR_HPP
< prev index next >