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

Cannot allocate array with Integer.MAX_VALUE elements

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Won't Fix
    • Affects Version/s: 7u67, 8u20, 8u40
    • Fix Version/s: 9
    • Component/s: hotspot
    • Labels:
    • Subcomponent:
      gc
    • CPU:
      x86
    • OS:
      linux_redhat_6.0

      Description

      FULL PRODUCT VERSION :
      $ java -version
      java version "1.7.0_67"
      Java(TM) SE Runtime Environment (build 1.7.0_67-b01)
      Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      $ uname -a
      Linux pinyon 2.6.32-431.29.2.el6.x86_64 #1 SMP Tue Sep 9 21:36:05 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux


      A DESCRIPTION OF THE PROBLEM :
      Attempting to allocate an array with Integer.MAX_VALUE or Integer.MAX_VALUE-1 elements results in out of memory error, regardless of heap space. The type of the array elements does not matter. Whether byte, float, or double, all allocations of Integer.MAX_VALUE or Integer.MAX_VALUE-1 elements fail with
         java.lang.OutOfMemoryError: Requested array size exceeds VM limit

      This fails in both Java 7 (7u67) and Java 8 (8u20). It works correctly in Java 6 (6u45).

      REGRESSION. Last worked in version 6u45

      ADDITIONAL REGRESSION INFORMATION:
      $ java -version
      java version "1.6.0_45"
      Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
      Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)





      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile and run the test program, Memory.java.

      $ javac Memory.java
      $ java -Xmx15g Memory

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Compile and run the test program, Memory.java. Program runs without errors with Java 6u45.

      $ javac Memory.java
      $ java -Xmx15g Memory
      Allocating 2147483642 elements.
      Allocating 2147483643 elements.
      Allocating 2147483644 elements.
      Allocating 2147483645 elements.
      Allocating 2147483646 elements.
      Allocating 2147483647 elements.
      Done allocating.

      ACTUAL -
      Program fails at Integer.MAX_VALUE-1 elements. Fails with Java 7 and Java 8. Works with Java 6.

      $ javac Memory.java
      $ java -Xmx15g Memory
      Allocating 2147483642 elements.
      Allocating 2147483643 elements.
      Allocating 2147483644 elements.
      Allocating 2147483645 elements.
      Allocating 2147483646 elements.
      Exception in thread "main" java.lang.OutOfMemoryError: Requested array size exceeds VM limit
      at Memory.main(Memory.java:8)


      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread "main" java.lang.OutOfMemoryError: Requested array size exceeds VM limit
      at Memory.main(Memory.java:8)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      // Test program source file: Memory.java
      public class Memory {
        public static void main(String[] args) throws Exception {
          for (int i = Integer.MAX_VALUE-5; i>0; ++i) {
            System.out.println("Allocating "+i+" elements.");
            // Note that the type of allocation is not important. It fails at
            // Integer.MAX_VALUE-1 elements whether byte, float, double, etc.
            Object array = new byte[i];
          }

          System.out.println("Done allocating.");
        }
      }

      ---------- END SOURCE ----------

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: