< prev index next >
src/share/vm/memory/iterator.hpp
Print this page
rev 7183 : autospecialized oop_iterate using SFINAE and templates
@@ -45,10 +45,15 @@
public:
virtual void do_oop(oop* o) = 0;
virtual void do_oop_v(oop* o) { do_oop(o); }
virtual void do_oop(narrowOop* o) = 0;
virtual void do_oop_v(narrowOop* o) { do_oop(o); }
+
+ // Use SFINAE to dispatch to the "most appropriate" do_oop using OopClosureDispatcher.
+ // Read the specialized_oop_closures.hpp file how this works
+ template<class OopClosureType, class OopType>
+ void do_oop_auto(OopType* o);
};
// ExtendedOopClosure adds extra code to be run during oop iterations.
// This is needed by the GC and is extracted to a separate type to not
// pollute the OopClosure interface.
@@ -74,23 +79,47 @@
// Currently, only CMS and G1 need these.
virtual bool do_metadata() { return do_metadata_nv(); }
bool do_metadata_v() { return do_metadata(); }
bool do_metadata_nv() { return false; }
+ // Use SFINAE to dispatch to the "most appropriate" do_metadata using OopClosureDispatcher.
+ // Read the specialized_oop_closures.hpp file how this works
+ template<class OopClosureType>
+ bool do_metadata_auto();
virtual void do_klass(Klass* k) { do_klass_nv(k); }
void do_klass_v(Klass* k) { do_klass(k); }
void do_klass_nv(Klass* k) { ShouldNotReachHere(); }
+ // Use SFINAE to dispatch to the "most appropriate" do_klass using OopClosureDispatcher.
+ // Read the specialized_oop_closures.hpp file how this works
+ template<class OopClosureType>
+ void do_klass_auto(Klass* klass);
virtual void do_class_loader_data(ClassLoaderData* cld) { ShouldNotReachHere(); }
+ // Use SFINAE to dispatch to the "most appropriate" do_class_loader_data using OopClosureDispatcher.
+ // Read the specialized_oop_closures.hpp file how this works
+ template<class OopClosureType>
+ void do_class_loader_data_auto(ClassLoaderData* cld);
// True iff this closure may be safely applied more than once to an oop
// location without an intervening "major reset" (like the end of a GC).
virtual bool idempotent() { return false; }
virtual bool apply_to_weak_ref_discovered_field() { return false; }
};
+// Autospecialization uses an OopClosure rather than ExtendedOopClosure
+// for oop_iterate_no_header to make sure metadata methods are not called
+// in the first place using SFINAE type checks
+template<class OopClosureType>
+class NoHeaderOopClosure : public OopClosure {
+ OopClosureType* _cl;
+ public:
+ NoHeaderOopClosure(OopClosureType *cl) : _cl(cl) {}
+ void do_oop(oop *p) { _cl->template do_oop_auto<OopClosureType, oop>(p); }
+ void do_oop(narrowOop *p) { _cl->template do_oop_auto<OopClosureType, narrowOop>(p); }
+};
+
// Wrapper closure only used to implement oop_iterate_no_header().
class NoHeaderExtendedOopClosure : public ExtendedOopClosure {
OopClosure* _wrapped_closure;
public:
NoHeaderExtendedOopClosure(OopClosure* cl) : _wrapped_closure(cl) {}
< prev index next >