8254864: vmTestbase/nsk/jvmti/ResourceExhausted/resexhausted001/TestDescription.java timed out

Reviewed-by: sspitsyn, cjplummer
This commit is contained in:
Alex Menkov 2020-11-06 21:57:43 +00:00
parent 0b7fba75c1
commit a9dff9420a
6 changed files with 46 additions and 21 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -22,17 +22,28 @@
*/
package nsk.jvmti.ResourceExhausted;
import jtreg.SkippedException;
public class Helper {
static native boolean gotExhaustedEvent();
static native int getExhaustedEventFlags();
static native void resetExhaustedEvent();
static boolean checkResult(String eventName) {
if ( ! gotExhaustedEvent() ) {
static final int JVMTI_RESOURCE_EXHAUSTED_OOM_ERROR = 1;
static final int JVMTI_RESOURCE_EXHAUSTED_JAVA_HEAP = 2;
static final int JVMTI_RESOURCE_EXHAUSTED_THREADS = 4;
static boolean checkResult(int expectedFlag, String eventName) {
int got = getExhaustedEventFlags();
if (got == 0) {
System.err.println("Failure: Expected ResourceExhausted event after " + eventName + " did not occur");
return false;
}
if ((got & expectedFlag) == 0) {
System.err.println("Warning: did not get expected flag bit (expected: "+ expectedFlag + ", got: " + got + ")");
throw new SkippedException("Test did not get expected flag value");
}
System.out.println("Got expected ResourceExhausted event");
return true;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -33,7 +33,7 @@
extern "C" {
static jvmtiEnv* gJvmti = NULL;
static volatile jboolean gGotEvent = JNI_FALSE;
static volatile jint gEventFlags = 0;
void JNICALL
resourceExhausted(jvmtiEnv *jvmti_env,
@ -46,19 +46,19 @@ resourceExhausted(jvmtiEnv *jvmti_env,
if (flags & JVMTI_RESOURCE_EXHAUSTED_OOM_ERROR) NSK_DISPLAY0("Agent: JVMTI_RESOURCE_EXHAUSTED_OOM_ERROR\n");
if (flags & JVMTI_RESOURCE_EXHAUSTED_JAVA_HEAP) NSK_DISPLAY0("Agent: JVMTI_RESOURCE_EXHAUSTED_JAVA_HEAP\n");
if (flags & JVMTI_RESOURCE_EXHAUSTED_THREADS) NSK_DISPLAY0("Agent: JVMTI_RESOURCE_EXHAUSTED_THREADS\n");
gGotEvent = JNI_TRUE;
gEventFlags = flags;
}
JNIEXPORT jboolean JNICALL
Java_nsk_jvmti_ResourceExhausted_Helper_gotExhaustedEvent(JNIEnv* env, jclass cls)
JNIEXPORT jint JNICALL
Java_nsk_jvmti_ResourceExhausted_Helper_getExhaustedEventFlags(JNIEnv* env, jclass cls)
{
return gGotEvent;
return gEventFlags;
}
JNIEXPORT void JNICALL
Java_nsk_jvmti_ResourceExhausted_Helper_resetExhaustedEvent(JNIEnv* env, jclass cls)
{
gGotEvent = JNI_FALSE;
gEventFlags = 0;
}
#ifdef STATIC_BUILD

View File

@ -25,6 +25,7 @@ package nsk.jvmti.ResourceExhausted;
import java.io.PrintStream;
import java.util.concurrent.atomic.AtomicInteger;
import jdk.test.lib.Platform;
import nsk.share.Consts;
import nsk.share.test.Stresser;
import jtreg.SkippedException;
@ -42,6 +43,11 @@ public class resexhausted001 {
public static int run(String args[], PrintStream out) {
// Check platform here (instead of @requires) as this test is also called from resexhausted004
if (Platform.isWindows()) {
throw new SkippedException("Cannot get JVMTI_RESOURCE_EXHAUSTED_THREADS on Windows");
}
Stresser stress = new Stresser(args);
int count = 0;
@ -56,14 +62,15 @@ public class resexhausted001 {
makeThread();
}
System.out.println("Can't reproduce OOME due to a limit on iterations/execution time. Test was useless.");
System.out.println("Can't reproduce OOME due to a limit on iterations/execution time. Test was useless."
+ " threadCount=" + threadCount.get());
throw new SkippedException("Test did not get an OutOfMemory error");
} catch (OutOfMemoryError e) {
count = threadCount.get();
} finally {
threadsDone = true;
synchronized (hanger) {
threadsDone = true;
hanger.notifyAll();
}
stress.finish();
@ -74,7 +81,8 @@ public class resexhausted001 {
}
System.gc();
if (!Helper.checkResult("creating " + count + " threads")) {
System.out.println("got OOME with threadCount=" + count);
if (!Helper.checkResult(Helper.JVMTI_RESOURCE_EXHAUSTED_THREADS, "creating " + count + " threads")) {
return Consts.TEST_FAILED;
}
@ -85,16 +93,17 @@ public class resexhausted001 {
final Thread thr = new Thread(new Runnable() {
public void run() {
threadCount.getAndIncrement();
while (!threadsDone) {
try {
synchronized (hanger) {
synchronized (hanger) {
while (!threadsDone) {
try {
hanger.wait();
}
} catch (InterruptedException ignored) {}
} catch (InterruptedException ignored) {}
}
}
threadCount.getAndDecrement();
}
}, "fleece");
thr.setDaemon(true);
thr.start();
return thr;
}

View File

@ -40,6 +40,8 @@
* @run main/othervm/native/timeout=240
* -agentlib:resexhausted=-waittime=5
* -XX:-UseGCOverheadLimit
* -Xms16m
* -Xmx16m
* nsk.jvmti.ResourceExhausted.resexhausted001
* -stressTime 220
*/

View File

@ -64,8 +64,9 @@ public class resexhausted002 {
}
System.gc();
if ( ! Helper.checkResult("creating " + count + " objects") )
if (!Helper.checkResult(Helper.JVMTI_RESOURCE_EXHAUSTED_JAVA_HEAP, "creating " + count + " objects")) {
return Consts.TEST_FAILED;
}
return Consts.TEST_PASSED;
}

View File

@ -125,8 +125,10 @@ public class resexhausted003 {
}
System.gc();
if ( ! Helper.checkResult("loading " + count + " classes of " + bloatBytes.length + " bytes") )
if (!Helper.checkResult(Helper.JVMTI_RESOURCE_EXHAUSTED_OOM_ERROR,
"loading " + count + " classes of " + bloatBytes.length + " bytes")) {
return Consts.TEST_FAILED;
}
return Consts.TEST_PASSED;
}