Skip to content

Commit 957b61d

Browse files
committedDec 18, 2023
More test updates
1 parent e22834b commit 957b61d

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed
 

‎test/jdk/java/lang/Thread/virtual/Monitors.java

+14-6
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
import org.junit.jupiter.api.RepeatedTest;
8181
import org.junit.jupiter.params.ParameterizedTest;
8282
import org.junit.jupiter.params.provider.Arguments;
83+
import org.junit.jupiter.params.provider.ValueSource;
8384
import org.junit.jupiter.params.provider.MethodSource;
8485
import org.junit.jupiter.api.condition.*;
8586
import static org.junit.jupiter.api.Assertions.*;
@@ -306,21 +307,28 @@ void testContendedEnterWhenPinnedHeldByVirtualThread() throws Exception {
306307
/**
307308
* Test that parking while holding a monitor releases the carrier.
308309
*/
309-
@Test
310+
@ParameterizedTest
310311
@EnabledIf("platformIsX64")
311-
void testReleaseWhenParked() throws Exception {
312+
@ValueSource(booleans = { true, false })
313+
void testReleaseWhenParked(boolean reenter) throws Exception {
312314
assumeTrue(ThreadBuilders.supportsCustomScheduler(), "No support for custom schedulers");
313315
try (ExecutorService scheduler = Executors.newFixedThreadPool(1)) {
314316
Thread.Builder builder = ThreadBuilders.virtualThreadBuilder(scheduler);
315317

316318
var lock = new Object();
317319

318-
// thread enters monitor and parks
320+
// thread enters (and maybe reenters) a monitor and parks
319321
var started = new CountDownLatch(1);
320322
var vthread1 = builder.start(() -> {
321323
started.countDown();
322324
synchronized (lock) {
323-
LockSupport.park();
325+
if (reenter) {
326+
synchronized (lock) {
327+
LockSupport.park();
328+
}
329+
} else {
330+
LockSupport.park();
331+
}
324332
}
325333
});
326334

@@ -344,7 +352,7 @@ void testReleaseWhenParked() throws Exception {
344352
}
345353

346354
/**
347-
* Test that blocked waiting to enter a monitor releases the carrier.
355+
* Test that blocking waiting to enter a monitor releases the carrier.
348356
*/
349357
@Test
350358
@EnabledIf("platformIsX64")
@@ -619,7 +627,7 @@ private void await(Thread thread, Thread.State expectedState) throws Interrupted
619627
}
620628
}
621629

622-
private boolean platformIsX64() {
630+
static boolean platformIsX64() {
623631
return Platform.isX64();
624632
}
625633
}

‎test/jdk/java/lang/Thread/virtual/ThreadAPI.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -1081,10 +1081,10 @@ void testSetDaemon2() throws Exception {
10811081
}
10821082

10831083
/**
1084-
* Test Thread.yield releases carrier.
1084+
* Test Thread.yield releases carrier thread.
10851085
*/
10861086
@Test
1087-
void testYieldReleases() throws Exception {
1087+
void testYield1() throws Exception {
10881088
assumeTrue(ThreadBuilders.supportsCustomScheduler(), "No support for custom schedulers");
10891089
var list = new CopyOnWriteArrayList<String>();
10901090
try (ExecutorService scheduler = Executors.newFixedThreadPool(1)) {
@@ -1112,7 +1112,7 @@ void testYieldReleases() throws Exception {
11121112
* Test Thread.yield releases carrier when virtual thread holds a monitor.
11131113
*/
11141114
@Test
1115-
void testYieldReleasesWhenHoldingMonitor() throws Exception {
1115+
void testYield2() throws Exception {
11161116
assumeTrue(Platform.isX64(), "x64 only at this time");
11171117
assumeTrue(ThreadBuilders.supportsCustomScheduler(), "No support for custom schedulers");
11181118
var list = new CopyOnWriteArrayList<String>();
@@ -1144,7 +1144,7 @@ void testYieldReleasesWhenHoldingMonitor() throws Exception {
11441144
* Test Thread.yield when thread is pinned by native frame.
11451145
*/
11461146
@Test
1147-
void testYieldWhenPinned() throws Exception {
1147+
void testYield3() throws Exception {
11481148
assumeTrue(ThreadBuilders.supportsCustomScheduler(), "No support for custom schedulers");
11491149
var list = new CopyOnWriteArrayList<String>();
11501150
try (ExecutorService scheduler = Executors.newFixedThreadPool(1)) {
@@ -1172,7 +1172,7 @@ void testYieldWhenPinned() throws Exception {
11721172
* Test Thread.yield does not consume the thread's parking permit.
11731173
*/
11741174
@Test
1175-
void testYieldDoesNotConsumeParkingPermit() throws Exception {
1175+
void testYield4() throws Exception {
11761176
var thread = Thread.ofVirtual().start(() -> {
11771177
LockSupport.unpark(Thread.currentThread());
11781178
Thread.yield();
@@ -1185,7 +1185,7 @@ void testYieldDoesNotConsumeParkingPermit() throws Exception {
11851185
* Test Thread.yield does not make available the thread's parking permit.
11861186
*/
11871187
@Test
1188-
void testYieldDoesNotGrantParkingPermit() throws Exception {
1188+
void testYield5() throws Exception {
11891189
var thread = Thread.ofVirtual().start(() -> {
11901190
Thread.yield();
11911191
LockSupport.park(); // should park

0 commit comments

Comments
 (0)
Please sign in to comment.