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

OutOfMemoryError with repeated small FileChannel reads

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.4.2
    • core-libs
    • x86
    • windows_2000



      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)
      ======================================================================

            mr Mark Reinhold
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: