52 // This is needed by the GC and is extracted to a separate type to not
53 // pollute the OopClosure interface.
54 class ExtendedOopClosure : public OopClosure {
55 private:
56 ReferenceProcessor* _ref_processor;
57
58 protected:
59 ExtendedOopClosure(ReferenceProcessor* rp) : _ref_processor(rp) { }
60 ExtendedOopClosure() : _ref_processor(NULL) { }
61 ~ExtendedOopClosure() { }
62
63 void set_ref_processor_internal(ReferenceProcessor* rp) { _ref_processor = rp; }
64
65 public:
66 ReferenceProcessor* ref_processor() const { return _ref_processor; }
67
68 // Iteration of InstanceRefKlasses differ depending on the closure,
69 // the below enum describes the different alternatives.
70 enum ReferenceIterationMode {
71 DO_DISCOVERY, // Apply closure and discover references
72 DO_FIELDS // Apply closure to all fields
73 };
74
75 // The default iteration mode is to do discovery.
76 virtual ReferenceIterationMode reference_iteration_mode() { return DO_DISCOVERY; }
77
78 // If the do_metadata functions return "true",
79 // we invoke the following when running oop_iterate():
80 //
81 // 1) do_klass on the header klass pointer.
82 // 2) do_klass on the klass pointer in the mirrors.
83 // 3) do_cld on the class loader data in class loaders.
84 //
85 // The virtual (without suffix) and the non-virtual (with _nv suffix) need
86 // to be updated together, or else the devirtualization will break.
87 //
88 // Providing default implementations of the _nv functions unfortunately
89 // removes the compile-time safeness, but reduces the clutter for the
90 // ExtendedOopClosures that don't need to walk the metadata.
91 // Currently, only CMS and G1 need these.
92
93 bool do_metadata_nv() { return false; }
94 virtual bool do_metadata() { return do_metadata_nv(); }
95
96 void do_klass_nv(Klass* k) { ShouldNotReachHere(); }
97 virtual void do_klass(Klass* k) { do_klass_nv(k); }
98
99 void do_cld_nv(ClassLoaderData* cld) { ShouldNotReachHere(); }
100 virtual void do_cld(ClassLoaderData* cld) { do_cld_nv(cld); }
101
102 // True iff this closure may be safely applied more than once to an oop
103 // location without an intervening "major reset" (like the end of a GC).
104 virtual bool idempotent() { return false; }
105 virtual bool apply_to_weak_ref_discovered_field() { return false; }
106
107 #ifdef ASSERT
108 // Default verification of each visited oop field.
109 template <typename T> void verify(T* p);
110
111 // Can be used by subclasses to turn off the default verification of oop fields.
112 virtual bool should_verify_oops() { return true; }
113 #endif
114 };
115
116 // Wrapper closure only used to implement oop_iterate_no_header().
117 class NoHeaderExtendedOopClosure : public ExtendedOopClosure {
118 OopClosure* _wrapped_closure;
119 public:
120 NoHeaderExtendedOopClosure(OopClosure* cl) : _wrapped_closure(cl) {}
121 // Warning: this calls the virtual version do_oop in the the wrapped closure.
122 void do_oop_nv(oop* p) { _wrapped_closure->do_oop(p); }
123 void do_oop_nv(narrowOop* p) { _wrapped_closure->do_oop(p); }
124
125 void do_oop(oop* p) { assert(false, "Only the _nv versions should be used");
|
52 // This is needed by the GC and is extracted to a separate type to not
53 // pollute the OopClosure interface.
54 class ExtendedOopClosure : public OopClosure {
55 private:
56 ReferenceProcessor* _ref_processor;
57
58 protected:
59 ExtendedOopClosure(ReferenceProcessor* rp) : _ref_processor(rp) { }
60 ExtendedOopClosure() : _ref_processor(NULL) { }
61 ~ExtendedOopClosure() { }
62
63 void set_ref_processor_internal(ReferenceProcessor* rp) { _ref_processor = rp; }
64
65 public:
66 ReferenceProcessor* ref_processor() const { return _ref_processor; }
67
68 // Iteration of InstanceRefKlasses differ depending on the closure,
69 // the below enum describes the different alternatives.
70 enum ReferenceIterationMode {
71 DO_DISCOVERY, // Apply closure and discover references
72 DO_DISCOVERED_AND_DISCOVERY, // Apply closure to discovered field and do discovery
73 DO_FIELDS // Apply closure to all fields
74 };
75
76 // The default iteration mode is to do discovery.
77 virtual ReferenceIterationMode reference_iteration_mode() { return DO_DISCOVERY; }
78
79 // If the do_metadata functions return "true",
80 // we invoke the following when running oop_iterate():
81 //
82 // 1) do_klass on the header klass pointer.
83 // 2) do_klass on the klass pointer in the mirrors.
84 // 3) do_cld on the class loader data in class loaders.
85 //
86 // The virtual (without suffix) and the non-virtual (with _nv suffix) need
87 // to be updated together, or else the devirtualization will break.
88 //
89 // Providing default implementations of the _nv functions unfortunately
90 // removes the compile-time safeness, but reduces the clutter for the
91 // ExtendedOopClosures that don't need to walk the metadata.
92 // Currently, only CMS and G1 need these.
93
94 bool do_metadata_nv() { return false; }
95 virtual bool do_metadata() { return do_metadata_nv(); }
96
97 void do_klass_nv(Klass* k) { ShouldNotReachHere(); }
98 virtual void do_klass(Klass* k) { do_klass_nv(k); }
99
100 void do_cld_nv(ClassLoaderData* cld) { ShouldNotReachHere(); }
101 virtual void do_cld(ClassLoaderData* cld) { do_cld_nv(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
107 #ifdef ASSERT
108 // Default verification of each visited oop field.
109 template <typename T> void verify(T* p);
110
111 // Can be used by subclasses to turn off the default verification of oop fields.
112 virtual bool should_verify_oops() { return true; }
113 #endif
114 };
115
116 // Wrapper closure only used to implement oop_iterate_no_header().
117 class NoHeaderExtendedOopClosure : public ExtendedOopClosure {
118 OopClosure* _wrapped_closure;
119 public:
120 NoHeaderExtendedOopClosure(OopClosure* cl) : _wrapped_closure(cl) {}
121 // Warning: this calls the virtual version do_oop in the the wrapped closure.
122 void do_oop_nv(oop* p) { _wrapped_closure->do_oop(p); }
123 void do_oop_nv(narrowOop* p) { _wrapped_closure->do_oop(p); }
124
125 void do_oop(oop* p) { assert(false, "Only the _nv versions should be used");
|