30 #include "utilities/top.hpp"
31
32 class CodeBlob;
33 class nmethod;
34 class ReferenceProcessor;
35 class DataLayout;
36 class KlassClosure;
37 class ClassLoaderData;
38
39 // The following classes are C++ `closures` for iterating over objects, roots and spaces
40
41 class Closure : public StackObj { };
42
43 // OopClosure is used for iterating through references to Java objects.
44 class OopClosure : public Closure {
45 public:
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;
49 virtual void do_oop_v(narrowOop* o) { do_oop(o); }
50 };
51
52 // 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
54 // pollute the OopClosure interface.
55 class ExtendedOopClosure : public OopClosure {
56 public:
57 ReferenceProcessor* _ref_processor;
58 ExtendedOopClosure(ReferenceProcessor* rp) : _ref_processor(rp) { }
59 ExtendedOopClosure() : OopClosure(), _ref_processor(NULL) { }
60
61 // If the do_metadata functions return "true",
62 // we invoke the following when running oop_iterate():
63 //
64 // 1) do_klass on the header klass pointer.
65 // 2) do_klass on the klass pointer in the mirrors.
66 // 3) do_class_loader_data on the class loader data in class loaders.
67 //
68 // The virtual (without suffix) and the non-virtual (with _nv suffix) need
69 // to be updated together, or else the devirtualization will break.
70 //
71 // Providing default implementations of the _nv functions unfortunately
72 // removes the compile-time safeness, but reduces the clutter for the
73 // ExtendedOopClosures that don't need to walk the metadata.
74 // Currently, only CMS and G1 need these.
75
76 virtual bool do_metadata() { return do_metadata_nv(); }
77 bool do_metadata_v() { return do_metadata(); }
78 bool do_metadata_nv() { return false; }
79
80 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(); }
83
84 virtual void do_class_loader_data(ClassLoaderData* cld) { ShouldNotReachHere(); }
85
86 // 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).
88 virtual bool idempotent() { return false; }
89 virtual bool apply_to_weak_ref_discovered_field() { return false; }
90 };
91
92 // Wrapper closure only used to implement oop_iterate_no_header().
93 class NoHeaderExtendedOopClosure : public ExtendedOopClosure {
94 OopClosure* _wrapped_closure;
95 public:
96 NoHeaderExtendedOopClosure(OopClosure* cl) : _wrapped_closure(cl) {}
97 // Warning: this calls the virtual version do_oop in the the wrapped closure.
98 void do_oop_nv(oop* p) { _wrapped_closure->do_oop(p); }
99 void do_oop_nv(narrowOop* p) { _wrapped_closure->do_oop(p); }
100
101 void do_oop(oop* p) { assert(false, "Only the _nv versions should be used");
102 _wrapped_closure->do_oop(p); }
103 void do_oop(narrowOop* p) { assert(false, "Only the _nv versions should be used");
104 _wrapped_closure->do_oop(p);}
105 };
106
107 class KlassClosure : public Closure {
108 public:
109 virtual void do_klass(Klass* k) = 0;
|
30 #include "utilities/top.hpp"
31
32 class CodeBlob;
33 class nmethod;
34 class ReferenceProcessor;
35 class DataLayout;
36 class KlassClosure;
37 class ClassLoaderData;
38
39 // The following classes are C++ `closures` for iterating over objects, roots and spaces
40
41 class Closure : public StackObj { };
42
43 // OopClosure is used for iterating through references to Java objects.
44 class OopClosure : public Closure {
45 public:
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;
49 virtual void do_oop_v(narrowOop* o) { do_oop(o); }
50
51 // Use SFINAE to dispatch to the "most appropriate" do_oop using OopClosureDispatcher.
52 // Read the specialized_oop_closures.hpp file how this works
53 template<class OopClosureType, class OopType>
54 void do_oop_auto(OopType* o);
55 };
56
57 // ExtendedOopClosure adds extra code to be run during oop iterations.
58 // This is needed by the GC and is extracted to a separate type to not
59 // pollute the OopClosure interface.
60 class ExtendedOopClosure : public OopClosure {
61 public:
62 ReferenceProcessor* _ref_processor;
63 ExtendedOopClosure(ReferenceProcessor* rp) : _ref_processor(rp) { }
64 ExtendedOopClosure() : OopClosure(), _ref_processor(NULL) { }
65
66 // If the do_metadata functions return "true",
67 // we invoke the following when running oop_iterate():
68 //
69 // 1) do_klass on the header klass pointer.
70 // 2) do_klass on the klass pointer in the mirrors.
71 // 3) do_class_loader_data on the class loader data in class loaders.
72 //
73 // The virtual (without suffix) and the non-virtual (with _nv suffix) need
74 // to be updated together, or else the devirtualization will break.
75 //
76 // Providing default implementations of the _nv functions unfortunately
77 // removes the compile-time safeness, but reduces the clutter for the
78 // ExtendedOopClosures that don't need to walk the metadata.
79 // Currently, only CMS and G1 need these.
80
81 virtual bool do_metadata() { return do_metadata_nv(); }
82 bool do_metadata_v() { return do_metadata(); }
83 bool do_metadata_nv() { return false; }
84 // Use SFINAE to dispatch to the "most appropriate" do_metadata using OopClosureDispatcher.
85 // Read the specialized_oop_closures.hpp file how this works
86 template<class OopClosureType>
87 bool do_metadata_auto();
88
89 virtual void do_klass(Klass* k) { do_klass_nv(k); }
90 void do_klass_v(Klass* k) { do_klass(k); }
91 void do_klass_nv(Klass* k) { ShouldNotReachHere(); }
92 // Use SFINAE to dispatch to the "most appropriate" do_klass using OopClosureDispatcher.
93 // Read the specialized_oop_closures.hpp file how this works
94 template<class OopClosureType>
95 void do_klass_auto(Klass* klass);
96
97 virtual void do_class_loader_data(ClassLoaderData* cld) { ShouldNotReachHere(); }
98 // Use SFINAE to dispatch to the "most appropriate" do_class_loader_data using OopClosureDispatcher.
99 // Read the specialized_oop_closures.hpp file how this works
100 template<class OopClosureType>
101 void do_class_loader_data_auto(ClassLoaderData* cld);
102
103 // True iff this closure may be safely applied more than once to an oop
104 // location without an intervening "major reset" (like the end of a GC).
105 virtual bool idempotent() { return false; }
106 virtual bool apply_to_weak_ref_discovered_field() { return false; }
107 };
108
109 // Autospecialization uses an OopClosure rather than ExtendedOopClosure
110 // for oop_iterate_no_header to make sure metadata methods are not called
111 // in the first place using SFINAE type checks
112 template<class OopClosureType>
113 class NoHeaderOopClosure : public OopClosure {
114 OopClosureType* _cl;
115 public:
116 NoHeaderOopClosure(OopClosureType *cl) : _cl(cl) {}
117 void do_oop(oop *p) { _cl->template do_oop_auto<OopClosureType, oop>(p); }
118 void do_oop(narrowOop *p) { _cl->template do_oop_auto<OopClosureType, narrowOop>(p); }
119 };
120
121 // Wrapper closure only used to implement oop_iterate_no_header().
122 class NoHeaderExtendedOopClosure : public ExtendedOopClosure {
123 OopClosure* _wrapped_closure;
124 public:
125 NoHeaderExtendedOopClosure(OopClosure* cl) : _wrapped_closure(cl) {}
126 // Warning: this calls the virtual version do_oop in the the wrapped closure.
127 void do_oop_nv(oop* p) { _wrapped_closure->do_oop(p); }
128 void do_oop_nv(narrowOop* p) { _wrapped_closure->do_oop(p); }
129
130 void do_oop(oop* p) { assert(false, "Only the _nv versions should be used");
131 _wrapped_closure->do_oop(p); }
132 void do_oop(narrowOop* p) { assert(false, "Only the _nv versions should be used");
133 _wrapped_closure->do_oop(p);}
134 };
135
136 class KlassClosure : public Closure {
137 public:
138 virtual void do_klass(Klass* k) = 0;
|