8145459: Cleaner - use Reference.reachabilityFence
authorrriggs
Wed, 20 Jan 2016 11:33:28 -0500
changeset 35278 9cadaa13225e
parent 35277 eb4794f43d20
child 35300 30eaec7fded0
8145459: Cleaner - use Reference.reachabilityFence Reviewed-by: psandoz, mchung, chegar
jdk/src/java.base/share/classes/jdk/internal/ref/PhantomCleanable.java
jdk/src/java.base/share/classes/jdk/internal/ref/SoftCleanable.java
jdk/src/java.base/share/classes/jdk/internal/ref/WeakCleanable.java
--- a/jdk/src/java.base/share/classes/jdk/internal/ref/PhantomCleanable.java	Wed Jan 20 07:36:42 2016 -0500
+++ b/jdk/src/java.base/share/classes/jdk/internal/ref/PhantomCleanable.java	Wed Jan 20 11:33:28 2016 -0500
@@ -26,6 +26,7 @@
 package jdk.internal.ref;
 
 import java.lang.ref.Cleaner;
+import java.lang.ref.Reference;
 import java.lang.ref.PhantomReference;
 import java.util.Objects;
 
@@ -66,9 +67,9 @@
         this.list = CleanerImpl.getCleanerImpl(cleaner).phantomCleanableList;
         insert();
 
-        // TODO: Replace getClass() with ReachabilityFence when it is available
-        cleaner.getClass();
-        referent.getClass();
+        // Ensure referent and cleaner remain accessible
+        Reference.reachabilityFence(referent);
+        Reference.reachabilityFence(cleaner);
     }
 
     /**
--- a/jdk/src/java.base/share/classes/jdk/internal/ref/SoftCleanable.java	Wed Jan 20 07:36:42 2016 -0500
+++ b/jdk/src/java.base/share/classes/jdk/internal/ref/SoftCleanable.java	Wed Jan 20 11:33:28 2016 -0500
@@ -26,6 +26,7 @@
 package jdk.internal.ref;
 
 import java.lang.ref.Cleaner;
+import java.lang.ref.Reference;
 import java.lang.ref.SoftReference;
 import java.util.Objects;
 
@@ -66,9 +67,9 @@
         list = CleanerImpl.getCleanerImpl(cleaner).softCleanableList;
         insert();
 
-        // TODO: Replace getClass() with ReachabilityFence when it is available
-        cleaner.getClass();
-        referent.getClass();
+        // Ensure referent and cleaner remain accessible
+        Reference.reachabilityFence(referent);
+        Reference.reachabilityFence(cleaner);
     }
 
     /**
--- a/jdk/src/java.base/share/classes/jdk/internal/ref/WeakCleanable.java	Wed Jan 20 07:36:42 2016 -0500
+++ b/jdk/src/java.base/share/classes/jdk/internal/ref/WeakCleanable.java	Wed Jan 20 11:33:28 2016 -0500
@@ -26,6 +26,7 @@
  */
 
 import java.lang.ref.Cleaner;
+import java.lang.ref.Reference;
 import java.lang.ref.WeakReference;
 import java.util.Objects;
 
@@ -66,9 +67,10 @@
         list = CleanerImpl.getCleanerImpl(cleaner).weakCleanableList;
         insert();
 
-        // TODO: Replace getClass() with ReachabilityFence when it is available
-        cleaner.getClass();
-        referent.getClass();
+        // Ensure referent and cleaner remain accessible
+        Reference.reachabilityFence(referent);
+        Reference.reachabilityFence(cleaner);
+
     }
 
     /**