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

OutOfMemoryError when compiling class with 65535 methods

    Details

    • Subcomponent:
    • CPU:
      x86
    • OS:
      windows_xp

      Description

      FULL PRODUCT VERSION :
      java version "1.6.0_01"
      Java(TM) SE Runtime Environment (build 1.6.0_01-b06)
      Java HotSpot(TM) Client VM (build 1.6.0_01-b06, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      I tried to compile a class with 65535 methods. I got the error message java.lang.OutIOfMemoryError: Java Heap Space.



      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create a class with 65535 methods. Try to compile the class with the javac compiler.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Expected error message like 'too many methods in class file'.
      ACTUAL -
      C:\temp>C:\Programme\Java\jdk1.6.0_01\bin\javac.exe TestMethod.java
      Exception in thread "main" java.lang.OutOfMemoryError: Java heap space

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread "main" java.lang.OutOfMemoryError: Java heap space

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      /*
       * TestMethodCount.java
       *
       * A java class to generate a .java file with many methods.
       * After running this file, you have to compile c:\temp\TestMethod.java
       */

      package javatest;

      import java.io.BufferedWriter;
      import java.io.FileWriter;
      import java.io.IOException;
      import testst.Main;

      /**
       *
       * @author udo
       */
      public class TestMethodCount {
          
          /** Creates a new instance of TestMethodCount */
          public TestMethodCount(String name, int count) throws IOException {
              BufferedWriter bw = new BufferedWriter(new FileWriter("C:\\Temp\\" + name + ".java"));
              try {
                  bw.write("public class " + name + " {\n");
                  for (int i = 0; i < count; i++) {
                      bw.write("public void method" + Integer.toString(i) + "() {}\n");
                  }
                  bw.write("}\n");
              } finally {
                  bw.close();
              }
          }
          
          public static void main(String[] args) {
              try {
                  new TestMethodCount("TestMethod", 65535);
              } catch (IOException ex) {
                  ex.printStackTrace();
              }
          }
      }

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

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              ndcosta Nelson Dcosta (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Imported:
                Indexed: