Skip to content

Commit c2ef302

Browse files
author
Serguei Spitsyn
committed
8307968: serviceability/jvmti/vthread/StopThreadTest/StopThreadTest.java timed out
Reviewed-by: cjplummer, lmesnik
1 parent d22bcc8 commit c2ef302

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

test/hotspot/jtreg/serviceability/jvmti/vthread/StopThreadTest/StopThreadTest.java

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public static void run() {
104104
} else {
105105
testTaskThread = Thread.ofPlatform().name("TestTaskThread").start(testTask);
106106
}
107-
testTask.ensureStarted();
107+
TestTask.ensureAtPointA();
108108

109109
if (is_virtual) { // this check is for virtual target thread only
110110
log("\nMain #A.1: unsuspended");
@@ -153,7 +153,7 @@ public static void run() {
153153
{
154154
// StopThread is called from the test task (own thread) and expected to succeed.
155155
// No suspension of the test task thread is required or can be done in this case.
156-
testTask.ensureFinished();
156+
TestTask.ensureFinished();
157157
}
158158

159159
try {
@@ -168,46 +168,41 @@ static class TestTask implements Runnable {
168168
static Object lock = new Object();
169169
static void log(String str) { System.out.println(str); }
170170

171-
private volatile boolean started = false;
172-
private volatile boolean finished = false;
171+
static volatile boolean atPointA = false;
172+
static volatile boolean finished = false;
173173

174-
static public void sleep(long millis) {
174+
static void sleep(long millis) {
175175
try {
176176
Thread.sleep(millis);
177177
} catch (InterruptedException e) {
178178
throw new RuntimeException("Interruption in TestTask.sleep: \n\t" + e);
179179
}
180180
}
181181

182-
// Ensure thread is ready.
183-
public void ensureStarted() {
184-
while (!started) {
182+
static void ensureAtPointA() {
183+
while (!atPointA) {
185184
sleep(1);
186185
}
187186
}
188187

189188
// Ensure thread is finished.
190-
public void ensureFinished() {
189+
static void ensureFinished() {
191190
while (!finished) {
192191
sleep(1);
193192
}
194193
}
195194

196195
public void run() {
197196
log("TestTask.run: started");
198-
started = true;
199197

200198
boolean seenExceptionFromA = false;
201199
try {
202200
A();
203201
} catch (AssertionError ex) {
204202
log("TestTask.run: caught expected AssertionError from method A()");
205203
seenExceptionFromA = true;
206-
if (!Thread.currentThread().isVirtual()) { // platform thread
207-
// clear the interrupt status
208-
Thread.interrupted();
209-
}
210204
}
205+
Thread.interrupted();
211206
if (!seenExceptionFromA) {
212207
StopThreadTest.setFailed("TestTask.run: expected AssertionError from method A()");
213208
}
@@ -219,11 +214,8 @@ public void run() {
219214
} catch (AssertionError ex) {
220215
log("TestTask.run: caught expected AssertionError from method B()");
221216
seenExceptionFromB = true;
222-
if (!Thread.currentThread().isVirtual()) { // platform thread
223-
// clear the interrupt status
224-
Thread.interrupted();
225-
}
226217
}
218+
Thread.interrupted();
227219
if (!seenExceptionFromB) {
228220
StopThreadTest.setFailed("TestTask.run: expected AssertionError from method B()");
229221
}
@@ -236,6 +228,7 @@ public void run() {
236228
log("TestTask.run: caught expected AssertionError from method C()");
237229
seenExceptionFromC = true;
238230
}
231+
Thread.interrupted();
239232
if (!seenExceptionFromC) {
240233
StopThreadTest.setFailed("TestTask.run: expected AssertionError from method C()");
241234
}
@@ -248,6 +241,7 @@ public void run() {
248241
// - when suspended: JVMTI_ERROR_NONE is expected
249242
static void A() {
250243
log("TestTask.A: started");
244+
atPointA = true;
251245
synchronized (lock) {
252246
}
253247
log("TestTask.A: finished");

0 commit comments

Comments
 (0)