8226394: [TESTBUG] vmTestbase/metaspace/flags/maxMetaspaceSize/TestDescription.java fails with java.lang.NoClassDefFoundError

Don't use printStackTrace to verify OOM type.

Reviewed-by: lfoltan, dholmes
This commit is contained in:
Coleen Phillimore 2019-06-21 09:53:12 -04:00
parent 547e919979
commit 3ba752295e

View File

@ -57,10 +57,10 @@ public final class GarbageUtils {
} }
/** /**
* Returns true if the given error message matches * Returns true if the given error message matches
* one of expected strings. * one of expected strings.
*/ */
public boolean accept(String errorMessage) { public boolean accept(String errorMessage) {
if (expectedStrings == null || expectedStrings.length == 0 || errorMessage == null) { if (expectedStrings == null || expectedStrings.length == 0 || errorMessage == null) {
return true; return true;
} }
@ -81,7 +81,6 @@ public final class GarbageUtils {
public static final StringWriter preloadStringWriter = new StringWriter(1); public static final StringWriter preloadStringWriter = new StringWriter(1);
public static final PrintWriter preloadPrintWriter = new PrintWriter(preloadStringWriter); public static final PrintWriter preloadPrintWriter = new PrintWriter(preloadStringWriter);
public static final Throwable preloadThrowable = new Throwable("preload"); public static final Throwable preloadThrowable = new Throwable("preload");
public static final StackTraceElement[] preloadStackTraceElement = preloadThrowable.getStackTrace();
private GarbageUtils() { private GarbageUtils() {
} }
@ -215,8 +214,6 @@ public final class GarbageUtils {
public static int eatMemory(ExecutionController stresser, GarbageProducer gp, long initialFactor, long minMemoryChunk, long factor, OOM_TYPE type) { public static int eatMemory(ExecutionController stresser, GarbageProducer gp, long initialFactor, long minMemoryChunk, long factor, OOM_TYPE type) {
int numberOfOOMEs = 0; int numberOfOOMEs = 0;
try { try {
StringWriter sw = new StringWriter(10000);
PrintWriter pw = new PrintWriter(sw);
byte[] someMemory = new byte[200000]; //200 Kb byte[] someMemory = new byte[200000]; //200 Kb
try { try {
Runtime runtime = Runtime.getRuntime(); Runtime runtime = Runtime.getRuntime();
@ -243,13 +240,11 @@ public final class GarbageUtils {
} catch (OutOfMemoryError e) { } catch (OutOfMemoryError e) {
someMemory = null; someMemory = null;
if (type != OOM_TYPE.ANY) { if (type != OOM_TYPE.ANY) {
e.printStackTrace(pw); if (type.accept(e.toString())) {
pw.close();
if (type.accept(sw.toString())) {
numberOfOOMEs++; numberOfOOMEs++;
} else { } else {
// Trying to catch situation when Java generates OOM different type that test trying to catch // Trying to catch situation when Java generates OOM different type that test trying to catch
throw new TestBug("Test throw OOM of unexpected type." + sw.toString()); throw new TestBug("Test throw OOM of unexpected type." + e.toString());
} }
} else { } else {
numberOfOOMEs++; numberOfOOMEs++;
@ -265,13 +260,11 @@ public final class GarbageUtils {
} catch (OutOfMemoryError e) { } catch (OutOfMemoryError e) {
someMemory = null; someMemory = null;
if (type != OOM_TYPE.ANY) { if (type != OOM_TYPE.ANY) {
e.printStackTrace(pw); if (type.accept(e.toString())) {
pw.close();
if (type.accept(sw.toString())) {
numberOfOOMEs++; numberOfOOMEs++;
} else { } else {
// Trying to catch situation when Java generates OOM different type that test trying to catch // Trying to catch situation when Java generates OOM different type that test trying to catch
throw new TestBug("Test throw OOM of unexpected type." + sw.toString()); throw new TestBug("Test throw OOM of unexpected type." + e.toString());
} }
} else { } else {
numberOfOOMEs++; numberOfOOMEs++;