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

timeouts cause garbage retention in java.util.concurrent lock classes

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • P4
    • 5.0u10
    • 5.0
    • core-libs

    Description

      FULL PRODUCT VERSION :
      $ bin/java -version
      java version "1.5.0_07"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_07-b03)
      Java HotSpot(TM) Client VM (build 1.5.0_07-b03, mixed mode, sharing)


      ADDITIONAL OS VERSION INFORMATION :
      Linux gojoblack 2.6.15-20-amd64-generic #1 SMP PREEMPT Tue Apr 4 17:45:39 UTC 2006 x86_64 GNU/Linux

      (But, this is a platform-independent Java issue.)

      A DESCRIPTION OF THE PROBLEM :
      I believe this is the same issue addressed in java 6 by bug 6236036 ( http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6236036 ): "Timeouts can cause garbage retention in lock classes".

      Specifically, with LinkedBlockqingQueue, poll()s which timeout create objects that are not released; a large number of timeouts without anything being added to the queue will eventually use all available heap memory causing an OutOfMemoryError. Demonstration code below.

      If the action for 6236036 fixes this in java 6, this bug is an appeal to backport the fix to a java 5 maintenance release.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Have one or more threads poll() an empty LinkedBlockedQueue that does not have anything in it (or added) for a long period.

      The class below (in source code section) demonstrates the bug (quickly in a small ~16m heap, eventually in a larger heap). Simply execute to trigger.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The example code runs forever, with threads timing out and then re-polling a LinkedBlockedQueue that's never filled.
      ACTUAL -
      An OutOfMemoryError. A heap histogram at the time of the OOME shows many megabytes of java.util.concurrent.locks.AbstractQueuedSynchronizer$Node instances.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------

      import java.util.concurrent.LinkedBlockingQueue;
      import java.util.concurrent.TimeUnit;

      public class LinkedBlockingQueueLeak implements Runnable {
          LinkedBlockingQueue q = new LinkedBlockingQueue();

          public static void main(String[] args) {
              new LinkedBlockingQueueLeak().instanceMain(args);
          }

          public void instanceMain(String[] args) {
              for (int i = 0; i < 50; i++) {
                  new Thread(this).start();
              }
          }

          public void run() {
              while(true) {
                  try {
                      q.poll(10,TimeUnit.MILLISECONDS);
                  } catch (InterruptedException e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                  }
              }
          }
      }
      ---------- END SOURCE ----------

      Attachments

        Issue Links

          Activity

            People

              martin Martin Buchholz
              ndcosta Nelson Dcosta (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: