Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8169000

Define reference reachability more precisely in java.lang.ref package

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P5
    • Resolution: Not an Issue
    • Affects Version/s: 6, 7, 8, 9, 10
    • Fix Version/s: tbd_major
    • Component/s: core-libs
    • Labels:

      Description

      Phantom referenced objects may not appear in the ReferenceQueue if VM run with -Xcomp.

      The minimal test demonstrating the bug looks like:
      --- 8< ------- Phantom.java --------------------
      import java.lang.ref.PhantomReference;
      import java.lang.ref.Reference;
      import java.lang.ref.ReferenceQueue;

      public class Phantom {
          static ReferenceQueue rq = new ReferenceQueue();
          public static void main(final String[] args) throws Exception {
              PhantomReference ref = new PhantomReference(new Object(), rq);
              System.out.println("ref: " + ref);
              System.gc();

              Reference rmRef = rq.remove(1000);
              if (rmRef == null) {
                  for (int i = 0; i < 10; i++) {
                      System.gc();
                  }
                  rmRef = rq.remove(1000);
                  if (rmRef == null) {
                      throw new Error("Test failed");
                  }
              }
              System.out.println("Test passed");
          }
      }
      --- 8< ---------------------------------------------------------

      # java Phantom
      ref: java.lang.ref.PhantomReference@614c5515
      Test passed
      # java -Xcomp Phantom
      ref: java.lang.ref.PhantomReference@614c5515
      Exception in thread "main" java.lang.Error: Test failed
              at Phantom.main(Phantom.java:19)

      Please note: Declaring 'PhantomReference ref' as a static member of the Phantom class, not as a local variable, will make the test pass.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                mchung Mandy Chung
                Reporter:
                dfazunen Dmitry Fazunenko (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                11 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: