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

G1GC throws OutOfMemoryError incorrectly

XMLWordPrintable

    • gc

      In Java EPP and Java 17 a different exception for OOM is thrown when using parallel GC and G1GC, which could affect the behavior of related products when catching that particular exception. For example, WLS executes some internal tasks if an OOM is detected.

      While UseParallelGC generates a Throwable, G1GC produces Exception: java.lang.OutOfMemoryError thrown from the
      UncaughtExceptionHandler in thread "main"

      Previously in JDK 8, this is the behavior of both UseG1GC and UseParallelGC -- the
      exception is thrown to the calling thread, which can catch and process the
      exception.

      Test case:
      public class Mem {
          static java.util.ArrayList al = new java.util.ArrayList();
          public static void main(String[] args) throws Exception {
              try {
          while(true) al.add(new byte[1024*1024]);
      } catch (Throwable t) {
          System.out.println("Caught exception; terminating");
      }
          }
      }

            poonam Poonam Bajaj Parhar
            shadowbug Shadow Bug
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: