src/java.base/share/classes/java/lang/ref/Reference.java

Print this page

        

@@ -309,6 +309,22 @@
     Reference(T referent, ReferenceQueue<? super T> queue) {
         this.referent = referent;
         this.queue = (queue == null) ? ReferenceQueue.NULL : queue;
     }
 
+    /**
+     * Ensures that the object referenced by the given reference
+     * remains <em>strongly reachable</em> (as defined in the {@link
+     * java.lang.ref} package documentation), regardless of any prior
+     * actions of the program that might otherwise cause the object to
+     * become unreachable; thus, the referenced object is not
+     * reclaimable by garbage collection at least until after the
+     * invocation of this method. Invocation of this method does not
+     * itself initiate garbage collection or finalization.
+     *
+     * @implNote This method is treated specially in VM.
+     * @param ref the reference. If null, this method has no effect.
+     */
+    @HotSpotIntrinsicCandidate
+    public static void reachabilityFence(Object ref) {}
+
 }