changeset 17014:63a174bf063a

8178832: (ref) jdk.lang.ref.disableClearBeforeEnqueue property is ignored Summary: Delay property access to first use, and fix test. Reviewed-by: mchung
author kbarrett
date Wed, 19 Apr 2017 00:29:26 -0400
parents b2b769e0a708
children c2556da831ef
files src/java.base/share/classes/java/lang/ref/Reference.java test/java/lang/ref/ReferenceEnqueue.java
diffstat 2 files changed, 11 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/java/lang/ref/Reference.java	Tue Apr 18 11:35:29 2017 -0700
+++ b/src/java.base/share/classes/java/lang/ref/Reference.java	Wed Apr 19 00:29:26 2017 -0400
@@ -143,8 +143,10 @@
     /*
      * system property to disable clearing before enqueuing.
      */
-    private static final boolean disableClearBeforeEnqueue
-        = Boolean.getBoolean("jdk.lang.ref.disableClearBeforeEnqueue");
+    private static final class ClearBeforeEnqueue {
+        static final boolean DISABLE =
+            Boolean.getBoolean("jdk.lang.ref.disableClearBeforeEnqueue");
+    }
 
     /*
      * Atomically get and clear (set to null) the VM's pending list.
@@ -297,7 +299,7 @@
      *           it was not registered with a queue when it was created
      */
     public boolean enqueue() {
-        if (!disableClearBeforeEnqueue)
+        if (!ClearBeforeEnqueue.DISABLE)
             this.referent = null;
         return this.queue.enqueue(this);
     }
--- a/test/java/lang/ref/ReferenceEnqueue.java	Tue Apr 18 11:35:29 2017 -0700
+++ b/test/java/lang/ref/ReferenceEnqueue.java	Wed Apr 19 00:29:26 2017 -0400
@@ -25,7 +25,7 @@
  * @bug 4268317 8132306 8175797
  * @summary Test if Reference.enqueue() works properly with GC
  * @run main ReferenceEnqueue
- * @run main/othervm -Djdk.lang.ref.disableClearAndEnqueue=true ReferenceEnqueue
+ * @run main/othervm -Djdk.lang.ref.disableClearBeforeEnqueue=true ReferenceEnqueue
  */
 
 import java.lang.ref.*;
@@ -87,13 +87,13 @@
         final ReferenceQueue<Object> queue = new ReferenceQueue<>();
         final List<Reference<Object>> refs = new ArrayList<>();
         final int iterations = 1000;
-        final boolean disableClearAndEnqueue =
-            Boolean.parseBoolean("jdk.lang.ref.disableClearAndEnqueue");
+        final boolean disableClearBeforeEnqueue =
+            Boolean.getBoolean("jdk.lang.ref.disableClearBeforeEnqueue");
 
         ExplicitEnqueue() {
             this.refs.add(new SoftReference<>(new Object(), queue));
             this.refs.add(new WeakReference<>(new Object(), queue));
-            this.refs.add(new PhantomReference<>(new Object(), queue));
+            // Can't test PhantomReference because get() always returns null.
         }
 
         void run() throws InterruptedException {
@@ -101,10 +101,10 @@
                 if (ref.enqueue() == false) {
                     throw new RuntimeException("Error: enqueue failed");
                 }
-                if (disableClearAndEnqueue && ref.get() == null) {
+                if (disableClearBeforeEnqueue && ref.get() == null) {
                     throw new RuntimeException("Error: clearing should be disabled");
                 }
-                if (!disableClearAndEnqueue && ref.get() != null) {
+                if (!disableClearBeforeEnqueue && ref.get() != null) {
                     throw new RuntimeException("Error: referent must be cleared");
                 }
             }