changeset 46445:825b002e05ae

8138888: Remove ExtendedOopClosure::apply_to_weak_ref_discovered_field Reviewed-by: kbarrett, tschatzl
author sjohanss
date Tue, 09 May 2017 11:03:45 +0200
parents 677be3444372
children ababb65abf24
files hotspot/src/share/vm/gc/g1/g1OopClosures.hpp hotspot/src/share/vm/memory/iterator.hpp hotspot/src/share/vm/oops/instanceRefKlass.hpp hotspot/src/share/vm/oops/instanceRefKlass.inline.hpp
diffstat 4 files changed, 25 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/hotspot/src/share/vm/gc/g1/g1OopClosures.hpp	Mon May 08 09:45:24 2017 -0400
+++ b/hotspot/src/share/vm/gc/g1/g1OopClosures.hpp	Tue May 09 11:03:45 2017 +0200
@@ -56,7 +56,8 @@
   ~G1ParClosureSuper() { }
 
 public:
-  virtual bool apply_to_weak_ref_discovered_field() { return true; }
+  // This closure needs special handling for InstanceRefKlass.
+  virtual ReferenceIterationMode reference_iteration_mode() { return DO_DISCOVERED_AND_DISCOVERY; }
 };
 
 class G1ParPushHeapRSClosure : public G1ParClosureSuper {
@@ -189,8 +190,6 @@
     _from = from;
   }
 
-  bool apply_to_weak_ref_discovered_field() { return true; }
-
   bool self_forwarded(oop obj) {
     markOop m = obj->mark();
     bool result = (m->is_marked() && ((oop)m->decode_pointer() == obj));
@@ -202,6 +201,9 @@
   template <class T> inline void do_oop_nv(T* p);
   virtual inline void do_oop(narrowOop* p);
   virtual inline void do_oop(oop* p);
+
+  // This closure needs special handling for InstanceRefKlass.
+  virtual ReferenceIterationMode reference_iteration_mode() { return DO_DISCOVERED_AND_DISCOVERY; }
 };
 
 #endif // SHARE_VM_GC_G1_G1OOPCLOSURES_HPP
--- a/hotspot/src/share/vm/memory/iterator.hpp	Mon May 08 09:45:24 2017 -0400
+++ b/hotspot/src/share/vm/memory/iterator.hpp	Tue May 09 11:03:45 2017 +0200
@@ -68,8 +68,9 @@
   // Iteration of InstanceRefKlasses differ depending on the closure,
   // the below enum describes the different alternatives.
   enum ReferenceIterationMode {
-    DO_DISCOVERY, // Apply closure and discover references
-    DO_FIELDS     // Apply closure to all fields
+    DO_DISCOVERY,                // Apply closure and discover references
+    DO_DISCOVERED_AND_DISCOVERY, // Apply closure to discovered field and do discovery
+    DO_FIELDS                    // Apply closure to all fields
   };
 
   // The default iteration mode is to do discovery.
@@ -102,7 +103,6 @@
   // 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; }
 
 #ifdef ASSERT
   // Default verification of each visited oop field.
--- a/hotspot/src/share/vm/oops/instanceRefKlass.hpp	Mon May 08 09:45:24 2017 -0400
+++ b/hotspot/src/share/vm/oops/instanceRefKlass.hpp	Tue May 09 11:03:45 2017 +0200
@@ -123,6 +123,12 @@
   template <bool nv, typename T, class OopClosureType, class Contains>
   static void oop_oop_iterate_discovery(oop obj, ReferenceType type, OopClosureType* closure, Contains& contains);
 
+  // Used for a special case in G1 where the closure needs to be applied
+  // to the discovered field. Reference discovery is also done if the
+  // closure provides a ReferenceProcessor.
+  template <bool nv, typename T, class OopClosureType, class Contains>
+  static void oop_oop_iterate_discovered_and_discovery(oop obj, ReferenceType type, OopClosureType* closure, Contains& contains);
+
   // Apply the closure to all fields. No reference discovery is done.
   template <bool nv, typename T, class OopClosureType, class Contains>
   static void oop_oop_iterate_fields(oop obj, OopClosureType* closure, Contains& contains);
--- a/hotspot/src/share/vm/oops/instanceRefKlass.inline.hpp	Mon May 08 09:45:24 2017 -0400
+++ b/hotspot/src/share/vm/oops/instanceRefKlass.inline.hpp	Tue May 09 11:03:45 2017 +0200
@@ -79,11 +79,6 @@
 void InstanceRefKlass::oop_oop_iterate_discovery(oop obj, ReferenceType type, OopClosureType* closure, Contains& contains) {
   log_develop_trace(gc, ref)("Process reference with discovery " PTR_FORMAT, p2i(obj));
 
-  // Special case for some closures.
-  if (closure->apply_to_weak_ref_discovered_field()) {
-    do_discovered<nv, T>(obj, closure, contains);
-  }
-
   // Try to discover reference and return if it succeeds.
   if (try_discover<T>(obj, type, closure)) {
     return;
@@ -116,11 +111,22 @@
 }
 
 template <bool nv, typename T, class OopClosureType, class Contains>
+void InstanceRefKlass::oop_oop_iterate_discovered_and_discovery(oop obj, ReferenceType type, OopClosureType* closure, Contains& contains) {
+  // Explicitly apply closure to the discovered field.
+  do_discovered<nv, T>(obj, closure, contains);
+  // Then do normal reference processing with discovery.
+  oop_oop_iterate_discovery<nv, T>(obj, type, closure, contains);
+}
+
+template <bool nv, typename T, class OopClosureType, class Contains>
 void InstanceRefKlass::oop_oop_iterate_ref_processing_specialized(oop obj, OopClosureType* closure, Contains& contains) {
   switch (closure->reference_iteration_mode()) {
     case ExtendedOopClosure::DO_DISCOVERY:
       oop_oop_iterate_discovery<nv, T>(obj, reference_type(), closure, contains);
       break;
+    case ExtendedOopClosure::DO_DISCOVERED_AND_DISCOVERY:
+      oop_oop_iterate_discovered_and_discovery<nv, T>(obj, reference_type(), closure, contains);
+      break;
     case ExtendedOopClosure::DO_FIELDS:
       oop_oop_iterate_fields<nv, T>(obj, closure, contains);
       break;