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

(gc) Test case runs out of memory if explicit gc() calls are not made.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: P4 P4
    • None
    • 1.1.3, 1.1.6, 1.2.0, 1.2.1
    • hotspot
    • generic, x86
    • generic, windows_95, windows_nt

      Here is the Borland Bug Report:

      BUG DESCRIPTION (Borland Bug #5931):
      --------------------------------------------------------------
      Test case runs out of memory if explicit gc() calls not made.
       If periodic gc() calls made, does not run out of memory.
      Appears to be running out of handles, not memory.


      STEPS/CODE TO REPRODUCE (Borland Bug #5931)
      -------------------------------------------------------------------------------
      public class MemProblem {

        public static void willWork() {
          int count = 200000;
          String[] a = new String[count];
          for (int index = 0; index < count; ++index) {
             if ((index%10000) == 0)
               System.gc();
             a[index] = new String(new char[]{0, 0, 0, 0});
          }
        }
        public static void wontWork() {
          int count = 200000;
          String[] a = new String[count];
          for (int index = 0; index < count; ++index) {
            a[index] = new String(new char[]{0, 0, 0, 0});
          }
        }

        static public void main(String[] args) {
          try {
            // Run java with -ms16m command line argument.
            //
            // wontWork() gets a java.lang.OutOfMemoryError. It
      appears that its
            // running out of handles. willWork() allocates the same
      amount of memory
            // and completes successfully.
            // The only difference between these two is that the one
      that willWork()
            // does an explicit gc() every 10000 iterations through the
      loop.
            //
            wontWork();
      // willWork();
          }
          catch(Exception ex) {
            ex.printStackTrace();
          }
        }

      }


      Name: krT82822 Date: 04/28/99


      The JDK runtime runs out of object handles before it runs out of heap space. This problem occurs on NT JDKs {1.1.6, 1.1.8, 1.2.1}. It also occurs on Solaris production JDK 1.1.7. It does not occur on Solaris production JDK 1.2.1.

      NT JDK 1.1.8 has an access error in symcjit.dll when the exception is thrown

      The test below allocates object and places them on a list. The amount of free memory is printed every 1000 iterations. The JDK runtime throws
      an out of memory exception when there is approximately 58% of the heap free for each test.

      The exception also occurs if System.gc is called every 1000 iterations.

      I ran the test with:

      Command line approximate # allocations at failure
      ------------ ------------------------------------
      java -mx4m -ms4m Limit 100,000
      java -mx8m -ms8m Limit 210,000
      java -mx16m -ms16m Limit 415,000
      java -mx32m -ms32m Limit 835,000
      java -mx64m -ms64m Limit 1,675,000



      Limit.java
      ---------------------------------------

      class Elem {
          Elem next;
      }

      public class Limit {

          public static void main(String[] args) {
              Elem tail = new Elem();
              Elem head = tail;
              int count = 1;
              long free = 0, total = 0;

              try {
                  while(true) {
                      free = Runtime.getRuntime().freeMemory();
                      total = Runtime.getRuntime().totalMemory();
                      count++;
                      Elem tmp = new Elem();
                      tail.next = tmp;
                      tail = tmp;
                      if (count % 1000 == 0)
                          System.err.println("Count = " + count +
                                             " free = " + free +
                                             " total = " + total +
                                             " %free = " +
                                             ((double) free) / ((double) total));
                  }
              } catch(Throwable thr) {
                  System.err.println("Objects = " + count);
                  System.err.println("Before: " +
                                     " Free memory = " + free +
                                     " Total memory = " + total +
                                     " %free = " +
                                     ((double) free) / ((double) total));

                  free = Runtime.getRuntime().freeMemory();
                  total = Runtime.getRuntime().totalMemory();

                  System.err.println("After: " +
                                     " Free memory = " + free +
                                     " Total memory = " + total +
                                     " %free = " +
                                     ((double) free) / ((double) total));

                  System.err.println("Caught: " + thr);
                  thr.printStackTrace();
              }
          }
      }
      (Review ID: 57617)
      ======================================================================

            never Tom Rodriguez
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: