Skip to content

Commit 5a96a5d

Browse files
committedJul 18, 2022
8289612: Change hotspot/jtreg tests to not use Thread.stop
Reviewed-by: dholmes, dcubed
1 parent b65f7ec commit 5a96a5d

File tree

7 files changed

+140
-48
lines changed

7 files changed

+140
-48
lines changed
 

‎test/hotspot/jtreg/runtime/Thread/AsyncExceptionOnMonitorEnter.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@
2525
* @test
2626
* @bug 8283044
2727
* @summary Stress delivery of asynchronous exceptions while target is at monitorenter
28-
* @build AsyncExceptionOnMonitorEnter
28+
* @library /test/hotspot/jtreg/testlibrary
2929
* @run main/othervm AsyncExceptionOnMonitorEnter 0
3030
* @run main/othervm/native -agentlib:AsyncExceptionOnMonitorEnter AsyncExceptionOnMonitorEnter 1
3131
*/
3232

33+
import jvmti.JVMTIUtils;
34+
3335
import java.util.concurrent.Semaphore;
3436

3537
public class AsyncExceptionOnMonitorEnter extends Thread {
@@ -142,11 +144,11 @@ public static void main(String[] args) {
142144
Thread.sleep(300);
143145

144146
while (true) {
145-
worker2.stop();
147+
JVMTIUtils.stopThread(worker2);
146148
if (TEST_MODE != 1) {
147149
// Don't stop() worker1 with JVMTI raw monitors since if the monitor is
148150
// not released worker2 will deadlock on enter
149-
worker1.stop();
151+
JVMTIUtils.stopThread(worker1);
150152
}
151153

152154
if (!worker1.isAlive() && !worker2.isAlive()) {
@@ -197,4 +199,3 @@ public static void usage() {
197199
System.exit(1);
198200
}
199201
}
200-

‎test/hotspot/jtreg/runtime/Thread/AsyncExceptionTest.java

+13-9
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,16 @@
2626
* @bug 8283044
2727
* @requires vm.compiler1.enabled | vm.compiler2.enabled
2828
* @summary Stress delivery of asynchronous exceptions.
29-
* @library /test/lib /test/hotspot/jtreg
30-
* @build AsyncExceptionTest
31-
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -Xcomp
29+
* @library /test/hotspot/jtreg/testlibrary
30+
* @run main/othervm -Xcomp
3231
-XX:CompileCommand=dontinline,AsyncExceptionTest::internalRun2
3332
-XX:CompileCommand=compileonly,AsyncExceptionTest::internalRun1
3433
-XX:CompileCommand=compileonly,AsyncExceptionTest::internalRun2
3534
AsyncExceptionTest
3635
*/
3736

37+
import jvmti.JVMTIUtils;
38+
3839
import java.util.concurrent.CountDownLatch;
3940

4041
public class AsyncExceptionTest extends Thread {
@@ -53,13 +54,17 @@ public void run() {
5354
try {
5455
internalRun1();
5556
} catch (ThreadDeath td) {
56-
throw new RuntimeException("Catched ThreadDeath in run() instead of internalRun2() or internalRun1(). receivedThreadDeathinInternal1=" + receivedThreadDeathinInternal1 + "; receivedThreadDeathinInternal2=" + receivedThreadDeathinInternal2);
57+
throw new RuntimeException("Caught ThreadDeath in run() instead of internalRun2() or internalRun1().\n"
58+
+ "receivedThreadDeathinInternal1=" + receivedThreadDeathinInternal1
59+
+ "; receivedThreadDeathinInternal2=" + receivedThreadDeathinInternal2);
5760
} catch (NoClassDefFoundError ncdfe) {
58-
// ignore because we're testing Thread.stop() which can cause it
61+
// ignore because we're testing StopThread() which can cause it
5962
}
6063

6164
if (receivedThreadDeathinInternal2 == false && receivedThreadDeathinInternal1 == false) {
62-
throw new RuntimeException("Didn't catched ThreadDeath in internalRun2() nor in internalRun1(). receivedThreadDeathinInternal1=" + receivedThreadDeathinInternal1 + "; receivedThreadDeathinInternal2=" + receivedThreadDeathinInternal2);
65+
throw new RuntimeException("Didn't catch ThreadDeath in internalRun2() nor in internalRun1().\n"
66+
+ "receivedThreadDeathinInternal1=" + receivedThreadDeathinInternal1
67+
+ "; receivedThreadDeathinInternal2=" + receivedThreadDeathinInternal2);
6368
}
6469
exitSyncObj.countDown();
6570
}
@@ -120,7 +125,7 @@ public static void main(String[] args) {
120125
thread.startSyncObj.await();
121126
while (true) {
122127
// Send async exception and wait until it is thrown
123-
thread.stop();
128+
JVMTIUtils.stopThread(thread);
124129
thread.exitSyncObj.await();
125130
Thread.sleep(100);
126131

@@ -133,7 +138,7 @@ public static void main(String[] args) {
133138
} catch (InterruptedException e) {
134139
throw new Error("Unexpected: " + e);
135140
} catch (NoClassDefFoundError ncdfe) {
136-
// Ignore because we're testing Thread.stop() which can
141+
// Ignore because we're testing StopThread which can
137142
// cause it. Yes, a NoClassDefFoundError that happens
138143
// in a worker thread can subsequently be seen in the
139144
// main thread.
@@ -165,4 +170,3 @@ public static void usage() {
165170
System.exit(1);
166171
}
167172
}
168-

‎test/hotspot/jtreg/runtime/jni/terminatedThread/TestTerminatedThread.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2022, 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
@@ -75,8 +75,6 @@ public static void main(String[] args) throws Throwable {
7575
t.setName("NewName");
7676
System.out.println("Calling interrupt ...");
7777
t.interrupt();
78-
System.out.println("Calling stop ...");
79-
t.stop();
8078

8179
// Now the ThreadMXBean functions
8280

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
package jvmti;
25+
26+
public class JVMTIUtils {
27+
28+
private static native int init();
29+
30+
static {
31+
System.loadLibrary("JvmtiUtils");
32+
if (init() != 0) {
33+
throw new RuntimeException("Error during native lib utilization.");
34+
}
35+
}
36+
37+
private static native void stopThread(Thread t, Throwable ex);
38+
39+
public static void stopThread(Thread t) {
40+
stopThread(t, new ThreadDeath());
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
#include <string.h>
25+
#include "jvmti.h"
26+
#include "jvmti_common.h"
27+
28+
extern "C" {
29+
30+
static jvmtiEnv* jvmti = NULL;
31+
32+
JNIEXPORT jint JNICALL
33+
Java_jvmti_JVMTIUtils_init(JNIEnv *jni, jclass cls) {
34+
JavaVM* jvm;
35+
jni->GetJavaVM(&jvm);
36+
37+
if (jvm->GetEnv((void **) (&jvmti), JVMTI_VERSION) != JNI_OK) {
38+
return JNI_ERR;
39+
}
40+
jvmtiCapabilities caps;
41+
memset(&caps, 0, sizeof (caps));
42+
caps.can_signal_thread = 1;
43+
jvmtiError err = jvmti->AddCapabilities(&caps);
44+
if (err != JVMTI_ERROR_NONE) {
45+
LOG("error in JVMTI AddCapabilities: %d\n", err);
46+
return JNI_ERR;
47+
}
48+
return JNI_OK;
49+
}
50+
51+
JNIEXPORT void JNICALL
52+
Java_jvmti_JVMTIUtils_stopThread(JNIEnv *jni, jclass cls, jthread thread, jobject exception) {
53+
jvmtiError err = jvmti->StopThread(thread, exception);
54+
if (err == JVMTI_ERROR_THREAD_NOT_ALIVE) {
55+
LOG("JVMTI_ERROR_THREAD_NOT_ALIVE happened");
56+
return;
57+
}
58+
check_jvmti_status(jni, err, "Error during StopThread()");
59+
}
60+
61+
}

‎test/hotspot/jtreg/vmTestbase/gc/gctests/mallocWithGC2/mallocWithGC2.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2002, 2022, 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
@@ -113,8 +113,6 @@ public void run() {
113113
tArray[i].start();
114114

115115
tArray[0].join(); // wait for the javaHeapEater Thread to finish
116-
tArray[1].stop(); // Once javaHeapEater is finished, stop the
117-
// the cHeapEater thread.
118116
} catch (Exception e) {
119117
throw new TestFailure("Test Failed.", e);
120118
}

‎test/hotspot/jtreg/vmTestbase/nsk/stress/stack/stack002.java

+17-29
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2000, 2022, 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
@@ -74,26 +74,27 @@ public static int run(String args[], PrintStream out) {
7474
Timer timer = new Timer(tester);
7575
timer.start();
7676
tester.start();
77-
while (timer.isAlive())
77+
while (timer.isAlive()) {
7878
try {
7979
timer.join();
8080
} catch (InterruptedException e) {
8181
e.printStackTrace(out);
8282
return 2;
8383
}
84-
// if (tester.isAlive())
85-
// return 2;
84+
}
8685
out.println("Maximal depth: " + tester.maxdepth);
8786
return 0;
8887
}
8988

9089
private static class Tester extends Thread {
9190
int maxdepth;
9291
PrintStream out;
92+
public volatile boolean stop;
9393

9494
public Tester(PrintStream out) {
9595
this.out = out;
9696
maxdepth = 0;
97+
stop = false;
9798
}
9899

99100
public void run() {
@@ -103,24 +104,14 @@ public void run() {
103104
void recurse(int depth) {
104105
maxdepth = depth;
105106
try {
107+
if (stop) {
108+
return;
109+
}
106110
recurse(depth + 1);
107-
// } catch (StackOverflowError e) {
108-
//
109-
// OutOfMemoryError is also eligible to indicate stack overflow:
110-
//
111111
} catch (Error error) {
112112
if (!(error instanceof StackOverflowError) &&
113113
!(error instanceof OutOfMemoryError))
114114
throw error;
115-
116-
/***
117-
*** Originally, I supposed that VM crashes because of unexpected
118-
*** native stack overflow (println() invokes native method).
119-
*** However, I found that HS 1.3 and HS 2.0 crash even on
120-
*** invocation of Java (not native) method.
121-
***
122-
out.println("StackOverflowError, depth=" + depth);
123-
***/
124115
recurse(depth + 1);
125116
}
126117
}
@@ -136,18 +127,15 @@ public Timer(Tester tester) {
136127
public void run() {
137128
long started;
138129
started = System.currentTimeMillis();
139-
while (System.currentTimeMillis() - started < timeout)
140-
; /***
141-
*** The test hangs on JDK 1.2.2 Classic VM if sleep() is invoked.
142-
***
143-
try {
144-
this.sleep(1000);
145-
} catch (InterruptedException e) {
146-
e.printStackTrace(tester.out);
147-
return;
148-
};
149-
***/
150-
tester.stop();
130+
while (System.currentTimeMillis() - started < timeout) {
131+
try {
132+
this.sleep(1000);
133+
} catch (InterruptedException e) {
134+
e.printStackTrace(tester.out);
135+
return;
136+
};
137+
}
138+
tester.stop = true;
151139
}
152140
}
153141
}

0 commit comments

Comments
 (0)
Please sign in to comment.