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

Some finalizers are never called with -XX:+UseParallelGC

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P2 P2
    • 5.0
    • 5.0
    • hotspot
    • gc
    • b32
    • sparc
    • solaris_8

      The following program ...

      import java.util.concurrent.atomic.AtomicLong;

      class Leak3 {
          public static class Resource {
      public static AtomicLong births = new AtomicLong(0);
      public static AtomicLong deaths = new AtomicLong(0);

      public Resource() { births.getAndIncrement(); }
      protected void finalize() { deaths.getAndIncrement(); }
          }

          public static void main(String[] args) throws Exception {
      long loops = 0;
      while (true) {
      Resource x = new Resource();
      if ((++loops % 10) == 0) {
      long before = Resource.births.get() - Resource.deaths.get();
      System.gc();
      System.runFinalization();
      Thread.sleep(3000);
      long after = Resource.births.get() - Resource.deaths.get();
      System.out.println(before + " ==> " + after);
      }
      }
          }
      }

      ... ought to repeatedly print "11 => 1" or perhaps "10 => 0", but
      in fact, on Solaris-sparc it prints something like

      10 ==> 1
      11 ==> 2
      12 ==> 3
      13 ==> 4
      14 ==> 5
      15 ==> 5
      15 ==> 6
      16 ==> 7
      17 ==> 7
      17 ==> 8
      18 ==> 9
      19 ==> 10
      20 ==> 10
      20 ==> 11
      ...

      "leaking" approximately one finalization per cycle.
      9 out of 10 finalizers do get called, so it's not as if the gc can't keep up.

      On Linux-i586 and Windows-i586, it does indeed print "11 => 1".

      (AtomicLong could just as well be plain `int')
      ###@###.### 2003-11-21

            pbk Peter Kessler
            martin Martin Buchholz
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: