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

OutOfMemory protection

    XMLWordPrintable

Details

    • Enhancement
    • Resolution: Duplicate
    • P4
    • None
    • 1.2.2
    • core-libs
    • generic
    • generic

    Description



      Name: skT45625 Date: 02/25/2000


      java version "1.1.8"

      Hi!

      In case I have a multi-threaded server application and have configured it with
      e.g. 32MB max heap memory, the following scenarion could occur:

      * A request arrives, executes and needs 10M
      * A second request arrives, executes and needs 10M
      * A third request arrives, executes and needs 10M
      * A fourth request arrives, executes and needs 10M and causes an
      OutOfMemoryException - oops

      It would be nice to have a mechanism, that prevents a VM of throwing unnecessary
      OOMs, which are hard to handle by applications, because they can occur in 3rd
      party classes. The registered handler could wait until the requested amount of
      heap memory is available (for a specified amount of time) and continue where the
      OOM occured.

      One advantage is, that people tolerate applications, that are slow but do, what
      they are wanted to do. But people do not tolerate applications, that crash e.g.
      in case of an OOM.

      Another advantage is, that denial of service attacks have a lower chance to
      crash an application.

      A disadvantage is, that time critical applications could fail, if the handler
      waits too long. But this can be minimized, if an exception/error handler can be
      registered for a thread or thread group.

      The mechanism could be implemented like signal handlers in C/C++ with the
      extension, that each thread group can have its own handlers for specified
      exceptions/errors. For example: If I register a handler for VM-errors, the
      handler would be called for any thrown error, that is an instance of
      java.lang.VirtualMachineError.

      For example a VM with mx=32m:

      class OOMHandler implements java.lang.ThrowableHandler {
          public int handleThrowable (
              java.lang.Thread thrd, // the Thread, where the Throwable error occured
              java.lang.Method mth, // the method, where the error occured
              java.lang.Throwable t, // the Throwable object, that would be thrown
              int occurenceCounter) // indicates, how often a retry of the statement
      was done
          {
              if (t instanceof java.lang.OutOfMemoryError) {
                  return 1; // retry at the point, where the error was thrown
              }
              return 0; // do "really" throw the error
          }
      }

      public static void main(String args[]) {
          java.lang.Thread.getCurrent().getThreadGroup().addThrowableHandler(
              new OOMHandler(),
              new java.lang.OutOfMemoryError().getClass());
          byte a[]=new byte[10*1024*1024];
          byte b[]=new byte[10*1024*1024];
          byte c[]=new byte[10*1024*1024];
          // say, an OutOfMemory is thrown at the next statement
          // the registered java.lang.ThrowableHandler would be called
          byte d[]=new byte[10*1024*1024];
      }
      (Review ID: 101749)
      ======================================================================

      Attachments

        Issue Links

          Activity

            People

              mr Mark Reinhold
              skondamasunw Suresh Kondamareddy (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: