Skip to content

Commit 2c5445a

Browse files
author
duke
committed
Automatic merge of jdk:master into master
2 parents e8bc2de + a9dff94 commit 2c5445a

File tree

6 files changed

+46
-21
lines changed

6 files changed

+46
-21
lines changed

test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResourceExhausted/Helper.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2008, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -22,17 +22,28 @@
2222
*/
2323
package nsk.jvmti.ResourceExhausted;
2424

25+
import jtreg.SkippedException;
26+
2527
public class Helper {
2628

27-
static native boolean gotExhaustedEvent();
29+
static native int getExhaustedEventFlags();
2830
static native void resetExhaustedEvent();
2931

30-
static boolean checkResult(String eventName) {
31-
if ( ! gotExhaustedEvent() ) {
32+
static final int JVMTI_RESOURCE_EXHAUSTED_OOM_ERROR = 1;
33+
static final int JVMTI_RESOURCE_EXHAUSTED_JAVA_HEAP = 2;
34+
static final int JVMTI_RESOURCE_EXHAUSTED_THREADS = 4;
35+
36+
static boolean checkResult(int expectedFlag, String eventName) {
37+
int got = getExhaustedEventFlags();
38+
if (got == 0) {
3239
System.err.println("Failure: Expected ResourceExhausted event after " + eventName + " did not occur");
3340
return false;
3441
}
3542

43+
if ((got & expectedFlag) == 0) {
44+
System.err.println("Warning: did not get expected flag bit (expected: "+ expectedFlag + ", got: " + got + ")");
45+
throw new SkippedException("Test did not get expected flag value");
46+
}
3647
System.out.println("Got expected ResourceExhausted event");
3748
return true;
3849
}

test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResourceExhausted/resexhausted.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2008, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -33,7 +33,7 @@
3333
extern "C" {
3434

3535
static jvmtiEnv* gJvmti = NULL;
36-
static volatile jboolean gGotEvent = JNI_FALSE;
36+
static volatile jint gEventFlags = 0;
3737

3838
void JNICALL
3939
resourceExhausted(jvmtiEnv *jvmti_env,
@@ -46,19 +46,19 @@ resourceExhausted(jvmtiEnv *jvmti_env,
4646
if (flags & JVMTI_RESOURCE_EXHAUSTED_OOM_ERROR) NSK_DISPLAY0("Agent: JVMTI_RESOURCE_EXHAUSTED_OOM_ERROR\n");
4747
if (flags & JVMTI_RESOURCE_EXHAUSTED_JAVA_HEAP) NSK_DISPLAY0("Agent: JVMTI_RESOURCE_EXHAUSTED_JAVA_HEAP\n");
4848
if (flags & JVMTI_RESOURCE_EXHAUSTED_THREADS) NSK_DISPLAY0("Agent: JVMTI_RESOURCE_EXHAUSTED_THREADS\n");
49-
gGotEvent = JNI_TRUE;
49+
gEventFlags = flags;
5050
}
5151

52-
JNIEXPORT jboolean JNICALL
53-
Java_nsk_jvmti_ResourceExhausted_Helper_gotExhaustedEvent(JNIEnv* env, jclass cls)
52+
JNIEXPORT jint JNICALL
53+
Java_nsk_jvmti_ResourceExhausted_Helper_getExhaustedEventFlags(JNIEnv* env, jclass cls)
5454
{
55-
return gGotEvent;
55+
return gEventFlags;
5656
}
5757

5858
JNIEXPORT void JNICALL
5959
Java_nsk_jvmti_ResourceExhausted_Helper_resetExhaustedEvent(JNIEnv* env, jclass cls)
6060
{
61-
gGotEvent = JNI_FALSE;
61+
gEventFlags = 0;
6262
}
6363

6464
#ifdef STATIC_BUILD

test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResourceExhausted/resexhausted001.java

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.io.PrintStream;
2626
import java.util.concurrent.atomic.AtomicInteger;
2727

28+
import jdk.test.lib.Platform;
2829
import nsk.share.Consts;
2930
import nsk.share.test.Stresser;
3031
import jtreg.SkippedException;
@@ -42,6 +43,11 @@ public class resexhausted001 {
4243

4344
public static int run(String args[], PrintStream out) {
4445

46+
// Check platform here (instead of @requires) as this test is also called from resexhausted004
47+
if (Platform.isWindows()) {
48+
throw new SkippedException("Cannot get JVMTI_RESOURCE_EXHAUSTED_THREADS on Windows");
49+
}
50+
4551
Stresser stress = new Stresser(args);
4652

4753
int count = 0;
@@ -56,14 +62,15 @@ public static int run(String args[], PrintStream out) {
5662
makeThread();
5763
}
5864

59-
System.out.println("Can't reproduce OOME due to a limit on iterations/execution time. Test was useless.");
65+
System.out.println("Can't reproduce OOME due to a limit on iterations/execution time. Test was useless."
66+
+ " threadCount=" + threadCount.get());
6067
throw new SkippedException("Test did not get an OutOfMemory error");
6168

6269
} catch (OutOfMemoryError e) {
6370
count = threadCount.get();
6471
} finally {
65-
threadsDone = true;
6672
synchronized (hanger) {
73+
threadsDone = true;
6774
hanger.notifyAll();
6875
}
6976
stress.finish();
@@ -74,7 +81,8 @@ public static int run(String args[], PrintStream out) {
7481
}
7582

7683
System.gc();
77-
if (!Helper.checkResult("creating " + count + " threads")) {
84+
System.out.println("got OOME with threadCount=" + count);
85+
if (!Helper.checkResult(Helper.JVMTI_RESOURCE_EXHAUSTED_THREADS, "creating " + count + " threads")) {
7886
return Consts.TEST_FAILED;
7987
}
8088

@@ -85,16 +93,17 @@ static Thread makeThread() {
8593
final Thread thr = new Thread(new Runnable() {
8694
public void run() {
8795
threadCount.getAndIncrement();
88-
while (!threadsDone) {
89-
try {
90-
synchronized (hanger) {
96+
synchronized (hanger) {
97+
while (!threadsDone) {
98+
try {
9199
hanger.wait();
92-
}
93-
} catch (InterruptedException ignored) {}
100+
} catch (InterruptedException ignored) {}
101+
}
94102
}
95103
threadCount.getAndDecrement();
96104
}
97105
}, "fleece");
106+
thr.setDaemon(true);
98107
thr.start();
99108
return thr;
100109
}

test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResourceExhausted/resexhausted001/TestDescription.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
* @run main/othervm/native/timeout=240
4141
* -agentlib:resexhausted=-waittime=5
4242
* -XX:-UseGCOverheadLimit
43+
* -Xms16m
44+
* -Xmx16m
4345
* nsk.jvmti.ResourceExhausted.resexhausted001
4446
* -stressTime 220
4547
*/

test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResourceExhausted/resexhausted002.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ public static int run(String args[], PrintStream out) {
6464
}
6565

6666
System.gc();
67-
if ( ! Helper.checkResult("creating " + count + " objects") )
67+
if (!Helper.checkResult(Helper.JVMTI_RESOURCE_EXHAUSTED_JAVA_HEAP, "creating " + count + " objects")) {
6868
return Consts.TEST_FAILED;
69+
}
6970

7071
return Consts.TEST_PASSED;
7172
}

test/hotspot/jtreg/vmTestbase/nsk/jvmti/ResourceExhausted/resexhausted003.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,10 @@ public static int run(String args[], PrintStream out) {
125125
}
126126

127127
System.gc();
128-
if ( ! Helper.checkResult("loading " + count + " classes of " + bloatBytes.length + " bytes") )
128+
if (!Helper.checkResult(Helper.JVMTI_RESOURCE_EXHAUSTED_OOM_ERROR,
129+
"loading " + count + " classes of " + bloatBytes.length + " bytes")) {
129130
return Consts.TEST_FAILED;
131+
}
130132

131133
return Consts.TEST_PASSED;
132134
}

0 commit comments

Comments
 (0)