FULL PRODUCT VERSION :
java version "1.5.0_09"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_09-b01)
Java HotSpot(TM) Client VM (build 1.5.0_09-b01, mixed mode)
FULL OS VERSION :
Windows XP SP2
A DESCRIPTION OF THE PROBLEM :
OutOfMemoryException is regulary thrown in our application. Analyze of the heap dumps showed that there is a lot of objects waiting on finalization ( typically 100000 objects !!) and so it is not simple leak in our code.
All these issues have one common: the JVM stack trace shows the finalizer thread waiting for a native method:
"Finalizer" daemon prio=8 tid=0x00a88ee8 nid=0x1738 runnable [0x0ab8f000..0x0ab8fa68]
at sun.awt.windows.WRobotPeer._dispose(Native Method)
at sun.awt.windows.WRobotPeer.disposeImpl(WRobotPeer.java:33)
at sun.awt.windows.WObjectPeer.dispose(WObjectPeer.java:55)
at sun.awt.windows.WObjectPeer.finalize(WObjectPeer.java:65)
at java.lang.ref.Finalizer.invokeFinalizeMethod(Native Method)
at java.lang.ref.Finalizer.runFinalizer(Finalizer.java:83)
at java.lang.ref.Finalizer.access$100(Finalizer.java:14)
at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:160)
The attached simple test application reproduced this bug in very short time for the 1.5.09 JVM. ( 1.5.10 shows also this behavior)
Very funny is the behavior of the 1.6 JVM: The JVM does not show the OutOfMemoryException, but it has a massive memory leak. The virtual memory consumption of the JVM raised after short time above 1GB, I have killed the process at 1.7GB virtual memory consuption.
THE PROBLEM WAS REPRODUCIBLE WITH -Xint FLAG: Did not try
THE PROBLEM WAS REPRODUCIBLE WITH -server FLAG: Did not try
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile and start the example code below. You get the OutOfMemoryException after one or two minutes.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
C:\tmp\t>\java\jdk1.5.0_09\bin\java -cp . Test
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
Full thread dump Java HotSpot(TM) Client VM (1.5.0_09-b01 mixed mode):
"JMX server connection timeout 18" daemon prio=6 tid=0x0fc8d6b0 nid=0x120c in Object.wait() [0x0fe6f000..0x0fe6fbe8]
at java.lang.Object.wait(Native Method)
- waiting on <0x02f59050> (a [I)
at com.sun.jmx.remote.internal.ServerCommunicatorAdmin$Timeout.run(ServerCommunicatorAdmin.java:150)
- locked <0x02f59050> (a [I)
at java.lang.Thread.run(Thread.java:595)
"RMI LeaseChecker" daemon prio=6 tid=0x0fc8ca78 nid=0x810 waiting on condition [0x0fe2f000..0x0fe2fc68]
at java.lang.Thread.sleep(Native Method)
at sun.rmi.transport.DGCImpl$LeaseChecker.run(DGCImpl.java:310)
at java.lang.Thread.run(Thread.java:595)
"DestroyJavaVM" prio=6 tid=0x00035c70 nid=0x137c waiting on condition [0x00000000..0x0007fae8]
"AWT-EventQueue-0" prio=6 tid=0x0ad42ab0 nid=0x1390 in Object.wait() [0x0b13f000..0x0b13fd68]
at java.lang.Object.wait(Native Method)
- waiting on <0x02ff36f8> (a java.awt.EventQueue)
at java.lang.Object.wait(Object.java:474)
at java.awt.EventQueue.getNextEvent(EventQueue.java:345)
- locked <0x02ff36f8> (a java.awt.EventQueue)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:189)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
"AWT-Windows" daemon prio=6 tid=0x0ad2b0c8 nid=0x1214 runnable [0x0b0af000..0x0b0af9e8]
at sun.awt.windows.WToolkit.eventLoop(Native Method)
at sun.awt.windows.WToolkit.run(WToolkit.java:269)
at java.lang.Thread.run(Thread.java:595)
"AWT-Shutdown" prio=6 tid=0x0ad3dd68 nid=0x13ac in Object.wait() [0x0b06f000..0x0b06fa68]
at java.lang.Object.wait(Native Method)
- waiting on <0x030044f0> (a java.lang.Object)
at java.lang.Object.wait(Object.java:474)
at sun.awt.AWTAutoShutdown.run(AWTAutoShutdown.java:259)
- locked <0x030044f0> (a java.lang.Object)
at java.lang.Thread.run(Thread.java:595)
"Java2D Disposer" daemon prio=10 tid=0x0ad3b218 nid=0x1220 in Object.wait() [0x0b02f000..0x0b02fae8]
at java.lang.Object.wait(Native Method)
- waiting on <0x03004578> (a java.lang.ref.ReferenceQueue$Lock)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:116)
- locked <0x03004578> (a java.lang.ref.ReferenceQueue$Lock)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:132)
at sun.java2d.Disposer.run(Disposer.java:107)
at java.lang.Thread.run(Thread.java:595)
"RMI TCP Accept-0" daemon prio=6 tid=0x0ad0a2a8 nid=0xef0 runnable [0x0af4f000..0x0af4fbe8]
at java.net.PlainSocketImpl.socketAccept(Native Method)
at java.net.PlainSocketImpl.accept(PlainSocketImpl.java:384)
- locked <0x03004630> (a java.net.SocksSocketImpl)
at java.net.ServerSocket.implAccept(ServerSocket.java:450)
at java.net.ServerSocket.accept(ServerSocket.java:421)
at sun.rmi.transport.tcp.TCPTransport.run(TCPTransport.java:340)
at java.lang.Thread.run(Thread.java:595)
"Timer-0" daemon prio=6 tid=0x0ad03408 nid=0x1644 in Object.wait() [0x0af0f000..0x0af0fc68]
at java.lang.Object.wait(Native Method)
- waiting on <0x030047e0> (a java.util.TaskQueue)
at java.util.TimerThread.mainLoop(Timer.java:509)
- locked <0x030047e0> (a java.util.TaskQueue)
at java.util.TimerThread.run(Timer.java:462)
"Low Memory Detector" daemon prio=6 tid=0x00a93fd0 nid=0x14d0 runnable [0x00000000..0x00000000]
"CompilerThread0" daemon prio=10 tid=0x00a92c30 nid=0x13f4 waiting on condition [0x00000000..0x0ac0fa48]
"Signal Dispatcher" daemon prio=10 tid=0x00a91f28 nid=0xf9c waiting on condition [0x00000000..0x00000000]
"Finalizer" daemon prio=8 tid=0x00a88ee8 nid=0x1738 runnable [0x0ab8f000..0x0ab8fa68]
at sun.awt.windows.WRobotPeer._dispose(Native Method)
at sun.awt.windows.WRobotPeer.disposeImpl(WRobotPeer.java:33)
at sun.awt.windows.WObjectPeer.dispose(WObjectPeer.java:55)
at sun.awt.windows.WObjectPeer.finalize(WObjectPeer.java:65)
at java.lang.ref.Finalizer.invokeFinalizeMethod(Native Method)
at java.lang.ref.Finalizer.runFinalizer(Finalizer.java:83)
at java.lang.ref.Finalizer.access$100(Finalizer.java:14)
at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:160)
"Reference Handler" daemon prio=10 tid=0x00a87aa0 nid=0xf6c in Object.wait() [0x0ab4f000..0x0ab4fae8]
at java.lang.Object.wait(Native Method)
- waiting on <0x02fd2590> (a java.lang.ref.Reference$Lock)
at java.lang.Object.wait(Object.java:474)
at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:116)
- locked <0x02fd2590> (a java.lang.ref.Reference$Lock)
"VM Thread" prio=10 tid=0x00a47fd0 nid=0x1488 runnable
"VM Periodic Task Thread" prio=10 tid=0x0ac61fe0 nid=0x4d4 waiting on condition
REPRODUCIBILITY :
This bug can be reproduced often.
---------- BEGIN SOURCE ----------
import java.awt.*;
import javax.swing.*;
public class Test
{
public static void main(String [] arg)
{
JFrame f = new JFrame();
f.setSize(new Dimension(200,200));
f.setVisible(true);
while(true)
{
try
{
new Robot().mouseMove(100,100);
}
catch(AWTException e)
{
System.out.println(e);
}
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Use the Robot class as a singleton