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

Issue with compiled method and ReferenceQueue.poll()

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P3 P3
    • 9
    • 9
    • hotspot
    • None
    • gc

      Please see testcase below.

      Start it with:
      $ /java/jdk1.9.0/bin/java -Xbatch -XX:-BackgroundCompilation -XX:+PrintCompilation -XX:CompileCommand=compileonly,TestBug::test -XX:-UseOnStackReplacement TestBug

      It hangs once test method was compiled.
      ----> Iteration #125, count = 127043862
      ----> Iteration #126, count = 128052649
        13439 1 b 3 TestBug::test (47 bytes)
      ----> Iteration #127, count = 129157852
        13544 2 % b 4 TestBug::test @ 31 (47 bytes)
        13545 3 b 4 TestBug::test (47 bytes)
        13548 1 3 TestBug::test (47 bytes) made not entrant

      Testcase:
      import java.lang.ref.ReferenceQueue;
      import java.lang.ref.WeakReference;
      import java.lang.ref.Reference;

      public class TestBug {
          private static long test() throws Exception {
              long count = 0;
              ReferenceQueue<Object> q = new ReferenceQueue<Object>();

              {
                  Object obj = new Object();
                  WeakReference<Object> ref = new WeakReference<Object>(obj, q);
                  obj = null;
              }

              while (q.poll() == null) {
                  count++;
              }

              return count;
          }

          public static void main(String[] args) throws Exception {
              new Thread() {
                  public void run() {
                      while (true) {
                          try {
                              Thread.sleep(100);
                          } catch (InterruptedException e) {
                          }

                          System.gc();
                      }
                  }
              }.start();

              long count = 0;

              for (int i = 0; i < 400; i++) {
                  count += test();
                  System.out.println("----> Iteration #" + i + ", count = " + count);
              }

              System.out.println(count);
          }
      }

            kbarrett Kim Barrett
            bmoloden Boris Molodenkov
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: