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

DirectMemory is not getting released resulting in out of memory exception

XMLWordPrintable

    • x86_64
    • linux_ubuntu

      FULL PRODUCT VERSION :
      java version "1.7.0_80-ea"
      Java(TM) SE Runtime Environment (build 1.7.0_80-ea-b05)
      Java HotSpot(TM) 64-Bit Server VM (build 24.80-b07, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Linux 3.2.0-70-generic #105-Ubuntu SMP Wed Sep 24 19:49:16 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      When running a test program to allocate Direct Memory of 1 GB in the following loop, we are getting a OOM error if we execute the logic where the OOM error is not handled and gc is not called explicitly. When we make an explicit gc call the allocation goes through fine. Looking at the java.nio.Bits code (https://github.com/openjdk-mirror/jdk/blob/jdk7u/jdk7u6/master/src/share/classes/java/nio/Bits.java#L649) there is an System.gc() call and this doesn't seem to have any effect in the Ubuntu platform but works fine in redhat.

      loop:
                  for (int i = 0; i < 32; i++) {
                   try {
                     buffer = ByteBuffer.allocateDirect(1 * 1024 * 1024 * 1024);
                   } catch(OutOfMemoryError e) {
                     if (args.length > 1) {
                       System.gc();
                       continue;
                     } else
                        throw(e);
                   }
       Error:
      Exception in thread "main" java.lang.OutOfMemoryError: Direct buffer memory
       at java.nio.Bits.reserveMemory(Bits.java:658)
       at java.nio.DirectByteBuffer.<init>(DirectByteBuffer.java:123)
       at java.nio.ByteBuffer.allocateDirect(ByteBuffer.java:306)
       at DirectByteBufferExample.main(DirectByteBufferExample.java:37)


      REPRODUCIBILITY :
      This bug can be reproduced always.

            igerasim Ivan Gerasimov
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: