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

Bug in Runtime.getFreeMemory() or garbage collection with HotSpot alpha2

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: P4 P4
    • None
    • 1.2.0
    • hotspot
    • gc
    • generic
    • generic

      This test case triggers a hotspot error message:

      # HotSpot Virtual Machine Error, Should Not Reach Here Error
      #
      # ShouldNotReachHere()
      #
      /usr/re/hotspot/src/solaris_only/hotspot_beta1_hp/build/solaris/../../src/share/vm/runtime/deoptimization.cpp, 207#
      #
      # Error happend during: deoptimize frame
      #

      When running the following testcase:

      java -mx4m -ms4m -verbosegc Gctest7 200000

      the output at the end of the run is:

       3967K->3967K(4032K+0K), 0.4400000 secs]
      , 0.6100000 secs]
      [Full GC[phase 1, 0.1200000 secs]
      [phase 2, 0.1200000 secs]
      [phase 3, 0.1700000 secs]
      [phase 4, 0.0000000 secs]
      Restoring 338 marks
       3967K->3967K(4032K+0K), 0.4300000 secs]
      [Full GC[phase 1, 0.1300000 secs]
      [phase 2, 0.1200000 secs]
      [phase 3, 0.1800000 secs]
      [phase 4, 0.0000000 secs]
      Restoring 338 marks
       3967K->3967K(4032K+0K), 0.4300000 secs]
      Symbol: 'vm exception holder'#
      # HotSpot Virtual Machine Error, Should Not Reach Here Error
      #
      # ShouldNotReachHere()
      #
      /usr/re/hotspot/src/solaris_only/hotspot_beta1_hp/build/solaris/../../src/share/vm/runtime/deoptimization.cpp, 207#
      #
      # Error happend during: deoptimize frame
      #


      Name: js5519 Date: 02/05/99


      Either the value returned by Runtime.getFreeMemory() is
      extremely inaccurate, or the runtime does not manage
      memory correctly when a large number of small objects
      are allocated.

      The following class accepts one argument, the number of
      objects to allocate. When executed it will print out
      the amount of memory available after each allocation.

      The application is started with a fixed heap size

      java -mx4m -ms4m -verbosegc Gctest7 200000

      The application throws a java.lang.OutOfMemory error when
      the percentage of free memory is significantly larger than
      0 (more than 20% of the memory is available, depending on
      the JDK).

      This problem occurs with the following JDKs

      NT 1.1.6 (with or without the updated JIT)
      NT 1.2
          NT 4.0
          java -fullversion -> JDK-1.2-V
          the runtime reports 46% of the memory is free

      Solaris 1.1.6
          Solaris 2.6
          Solaris_JDK_1.1.6_04
          the runtime reports that 38% of the memory is free

      The problem does not occur with Solaris_JDK_1.2_01_dev06_fcsV.
      When that version is used the runtime reports that 0% of the
      memory is available before the OutOfMemoryError is thrown.

      public class Gctest7 {
          static long totalMem;
          static long freeMem;
          static int pFree;
          static double pctFree;
          static int count;
          static Object[] objArray;
          static Integer max;

          public static void main(String[] args) {
              max = Integer.valueOf(args[0]);
      try {
      test();
      } catch(Throwable thr) {
      System.err.println("Caught " + thr.getClass().getName());
      System.err.println(thr.getMessage());
      thr.printStackTrace();
      System.err.println("FAILED: " + pFree + "% free " +
      " total = " + totalMem +
      " free = " + freeMem +
      " count = " + count);
      }
          }

          static void test() {
              objArray = new Object[max.intValue()];
      count = 0;

              for (int i = 0; i < max.intValue(); i++) {
      freeMem = Runtime.getRuntime().freeMemory();
      totalMem = Runtime.getRuntime().totalMemory();
      pctFree = (double) freeMem / (double) totalMem;
      pFree = (int) (100.0 * pctFree);
      System.err.println("DATA: " + pFree + "% free " +
      " total = " + totalMem +
      " free = " + freeMem +
      " count = " + count);
      objArray[i] = new byte[2];
      count++;
      }
          }

      }
      (Review ID: 48819)
      ======================================================================


            mgharahgsunw Mohammad Gharahgouzloo (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: