8226536: Catch OOM from deopt that fails rematerializing objects

Reviewed-by: vlivanov, thartmann
This commit is contained in:
Nils Eliasson 2019-07-10 18:48:05 +02:00
parent 8c52f63fe1
commit 019b9891d7

View File

@ -26,6 +26,7 @@ package nsk.share.gc.gp;
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 @@ public final class GarbageUtils {
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 @@ public final class GarbageUtils {
* @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 {