8226536: Catch OOM from deopt that fails rematerializing objects
authorneliasso
Wed, 10 Jul 2019 18:48:05 +0200
changeset 55660 fe5dcb38a26a
parent 55659 60bdaee6010a
child 55661 b32b6ffb221b
8226536: Catch OOM from deopt that fails rematerializing objects Reviewed-by: vlivanov, thartmann
test/hotspot/jtreg/vmTestbase/nsk/share/gc/gp/GarbageUtils.java
--- a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/gp/GarbageUtils.java	Wed Jul 10 08:24:31 2019 -0700
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/gp/GarbageUtils.java	Wed Jul 10 18:48:05 2019 +0200
@@ -26,6 +26,7 @@
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.io.StringWriter;
+import java.lang.invoke.*;
 import java.util.*;
 import nsk.share.gc.gp.array.*;
 import nsk.share.gc.gp.string.*;
@@ -194,6 +195,36 @@
             return eatMemory(stresser, gp, initialFactor, minMemoryChunk, factor, OOM_TYPE.ANY);
         }
 
+         static int numberOfOOMEs = 0;
+
+         /**
+          * Minimal wrapper of the main implementation. Catches any OOM
+          * that might be thrown when rematerializing Objects when deoptimizing.
+          *
+          * It is Important that the impl is not inlined.
+          */
+
+         public static int eatMemory(ExecutionController stresser, GarbageProducer gp, long initialFactor, long minMemoryChunk, long factor, OOM_TYPE type) {
+            try {
+               // Using a methodhandle invoke of eatMemoryImpl to prevent inlining of it
+               MethodHandles.Lookup lookup = MethodHandles.lookup();
+               MethodType mt = MethodType.methodType(
+                     int.class,
+                     ExecutionController.class,
+                     GarbageProducer.class,
+                     long.class,
+                     long.class,
+                     long.class,
+                     OOM_TYPE.class);
+               MethodHandle eat = lookup.findStatic(GarbageUtils.class, "eatMemoryImpl", mt);
+               return (int) eat.invoke(stresser, gp, initialFactor, minMemoryChunk, factor, type);
+            } catch (OutOfMemoryError e) {
+               return numberOfOOMEs++;
+            } catch (Throwable t) {
+               throw new RuntimeException(t);
+            }
+         }
+
         /**
          * Eat memory using given garbage producer.
          *
@@ -211,8 +242,9 @@
          * @param type of OutOfMemory Exception: Java heap space or Metadata space
          * @return number of OOME occured
          */
-        public static int eatMemory(ExecutionController stresser, GarbageProducer gp, long initialFactor, long minMemoryChunk, long factor, OOM_TYPE type) {
-                int numberOfOOMEs = 0;
+
+         public static int eatMemoryImpl(ExecutionController stresser, GarbageProducer gp, long initialFactor, long minMemoryChunk, long factor, OOM_TYPE type) {
+                numberOfOOMEs = 0;
                 try {
                         byte[] someMemory = new byte[200000]; //200 Kb
                         try {