JDK-6457123 : timeouts cause garbage retention in java.util.concurrent lock classes
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util.concurrent
  • Affected Version: 5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86
  • Submitted: 2006-08-04
  • Updated: 2011-02-16
  • Resolved: 2006-08-04
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
5.0u10Resolved
Related Reports
Duplicate :  
Relates :  
Relates :  
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 ----------

Comments
EVALUATION As suggested by the submitter, This is a dup of 6236036: Timeouts can cause garbage retention in lock classes Here's the canonical minimal test case: ------------- import java.util.concurrent.*; public class Bug { public static void main(String[] args) throws Throwable { BlockingQueue<String> q = new LinkedBlockingQueue<String>(10); while (true) q.poll(10, TimeUnit.NANOSECONDS); } } ------------- I understand the submitter's appeal for a backport. We plan to deliver a more complete fix than 6236036 into jdk7, jdk6u2 and jdk5u12. This work is being done under 6460501: Synchronizer timed acquire still leaks memory http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6460501
04-08-2006