@@ -104,7 +104,7 @@ public static void run() {
104
104
} else {
105
105
testTaskThread = Thread .ofPlatform ().name ("TestTaskThread" ).start (testTask );
106
106
}
107
- testTask . ensureStarted ();
107
+ TestTask . ensureAtPointA ();
108
108
109
109
if (is_virtual ) { // this check is for virtual target thread only
110
110
log ("\n Main #A.1: unsuspended" );
@@ -153,7 +153,7 @@ public static void run() {
153
153
{
154
154
// StopThread is called from the test task (own thread) and expected to succeed.
155
155
// No suspension of the test task thread is required or can be done in this case.
156
- testTask .ensureFinished ();
156
+ TestTask .ensureFinished ();
157
157
}
158
158
159
159
try {
@@ -168,46 +168,41 @@ static class TestTask implements Runnable {
168
168
static Object lock = new Object ();
169
169
static void log (String str ) { System .out .println (str ); }
170
170
171
- private volatile boolean started = false ;
172
- private volatile boolean finished = false ;
171
+ static volatile boolean atPointA = false ;
172
+ static volatile boolean finished = false ;
173
173
174
- static public void sleep (long millis ) {
174
+ static void sleep (long millis ) {
175
175
try {
176
176
Thread .sleep (millis );
177
177
} catch (InterruptedException e ) {
178
178
throw new RuntimeException ("Interruption in TestTask.sleep: \n \t " + e );
179
179
}
180
180
}
181
181
182
- // Ensure thread is ready.
183
- public void ensureStarted () {
184
- while (!started ) {
182
+ static void ensureAtPointA () {
183
+ while (!atPointA ) {
185
184
sleep (1 );
186
185
}
187
186
}
188
187
189
188
// Ensure thread is finished.
190
- public void ensureFinished () {
189
+ static void ensureFinished () {
191
190
while (!finished ) {
192
191
sleep (1 );
193
192
}
194
193
}
195
194
196
195
public void run () {
197
196
log ("TestTask.run: started" );
198
- started = true ;
199
197
200
198
boolean seenExceptionFromA = false ;
201
199
try {
202
200
A ();
203
201
} catch (AssertionError ex ) {
204
202
log ("TestTask.run: caught expected AssertionError from method A()" );
205
203
seenExceptionFromA = true ;
206
- if (!Thread .currentThread ().isVirtual ()) { // platform thread
207
- // clear the interrupt status
208
- Thread .interrupted ();
209
- }
210
204
}
205
+ Thread .interrupted ();
211
206
if (!seenExceptionFromA ) {
212
207
StopThreadTest .setFailed ("TestTask.run: expected AssertionError from method A()" );
213
208
}
@@ -219,11 +214,8 @@ public void run() {
219
214
} catch (AssertionError ex ) {
220
215
log ("TestTask.run: caught expected AssertionError from method B()" );
221
216
seenExceptionFromB = true ;
222
- if (!Thread .currentThread ().isVirtual ()) { // platform thread
223
- // clear the interrupt status
224
- Thread .interrupted ();
225
- }
226
217
}
218
+ Thread .interrupted ();
227
219
if (!seenExceptionFromB ) {
228
220
StopThreadTest .setFailed ("TestTask.run: expected AssertionError from method B()" );
229
221
}
@@ -236,6 +228,7 @@ public void run() {
236
228
log ("TestTask.run: caught expected AssertionError from method C()" );
237
229
seenExceptionFromC = true ;
238
230
}
231
+ Thread .interrupted ();
239
232
if (!seenExceptionFromC ) {
240
233
StopThreadTest .setFailed ("TestTask.run: expected AssertionError from method C()" );
241
234
}
@@ -248,6 +241,7 @@ public void run() {
248
241
// - when suspended: JVMTI_ERROR_NONE is expected
249
242
static void A () {
250
243
log ("TestTask.A: started" );
244
+ atPointA = true ;
251
245
synchronized (lock ) {
252
246
}
253
247
log ("TestTask.A: finished" );
0 commit comments