JDK-4869985 : OutOfMemoryError with repeated small FileChannel reads
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 1.4.2
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2003-05-27
  • Updated: 2003-08-23
  • Resolved: 2003-08-23
Related Reports
Duplicate :  
Description

Name: rmT116609			Date: 05/27/2003


FULL PRODUCT VERSION :
java version "1.4.2-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-beta-b19)
Java HotSpot(TM) Client VM (build 1.4.2-beta-b19, mixed mode)

FULL OS VERSION :
Microsoft Windows 2000 [Version 5.00.2195]

EXTRA RELEVANT SYSTEM CONFIGURATION :
Pentium III @ 700MHz, 768MB Physical Memory

A DESCRIPTION OF THE PROBLEM :
Peculiar OutOfMemoryError.  Does not happen in JDK 1.4.1_02.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
>java NIOTest

to run the supplied code.  Fails with -Xmx512M.  Fails with -server, -client.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Constant and reasonable memory utilization.
ACTUAL -
See stack trace.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "main" java.lang.OutOfMemoryError
        at java.nio.Bits.reserveMemory(Bits.java:618)
        at java.nio.DirectByteBuffer.<init>(DirectByteBuffer.java:95)
        at java.nio.ByteBuffer.allocateDirect(ByteBuffer.java:285)
        at sun.nio.ch.Util.getTemporaryDirectBuffer(Util.java:54)
        at sun.nio.ch.IOUtil.read(IOUtil.java:205)
        at sun.nio.ch.FileChannelImpl.read(FileChannelImpl.java:591)
        at NIOTest.main(NIOTest.java:20)


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class NIOTest
{
    public static void main(String[] args)
    throws Exception
    {
        RandomAccessFile raf = new RandomAccessFile("test.dat", "rw");
        raf.setLength(16384);
        FileChannel fc = raf.getChannel();
        ByteBuffer bb = ByteBuffer.allocate(16384);
        bb.limit(512);      //any value > 0 & < 16384
        fc.read(bb);        //also fails with fc.write(bb);
        
        for (int count = 0; count < 50000; count++)
        {
            bb.clear();
            fc.read(bb, 0);
            if (count % 500 == 0) System.out.println(count);
        }
    }
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Use 1.4.1_02

Release Regression From : 1.4.1_02
The above release value was the last known release where this 
bug was known to work. Since then there has been a regression.

(Review ID: 186524) 
======================================================================

Comments
EVALUATION Not for Mantis. -- ###@###.### 2003/5/28
05-11-0194

WORK AROUND Increase the maximum direct-memory size via the command-line flag -XX:MaxDirectMemorySize=1G -- ###@###.### 2003/8/23
08-11-0189