--- old/test/java/lang/ref/ReferenceEnqueuePending.java 2016-02-01 18:34:40.799330818 -0500 +++ new/test/java/lang/ref/ReferenceEnqueuePending.java 2016-02-01 18:34:40.623329945 -0500 @@ -94,13 +94,21 @@ } // Do a final collection to discover and process all - // Reference objects created above, allowing enough time + // Reference objects created above, allowing some time // for the ReferenceHandler thread to queue the References. forceGc(100); forceGc(100); // Verify that all WeakReference objects ended up queued. - checkResult(refQueue, obj, iterations-1); + checkResult(refQueue, iterations-1); + + // Ensure the final weaky is live but won't be enqueued during + // result checking, by ensuring its referent remains live. + // This eliminates behavior changes resulting from different + // compiler optimizations. + Reference.reachabilityFence(weaky); + Reference.reachabilityFence(obj); + System.out.println("Test passed."); } @@ -113,7 +121,6 @@ } private static void checkResult(ReferenceQueue queue, - Integer obj, int expected) { if (debug) { System.out.println("Reading the queue"); @@ -133,8 +140,6 @@ if (debug) { System.out.println("Reference Queue had " + length + " elements"); } - // Use the last Reference object of those created above, so as to keep it "alive". - System.out.println("I must write " + obj + " to prevent compiler optimizations."); // verify the queued references: all but the last Reference object