Skip to content

Commit 07ebda5

Browse files
txominpeluDavid Holmes
authored andcommitted
8334215: serviceability/dcmd/thread/PrintMountedVirtualThread.java failing with JTREG_TEST_THREAD_FACTORY=Virtual
Reviewed-by: dholmes
1 parent 2165a05 commit 07ebda5

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

src/hotspot/share/runtime/threads.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,8 +1332,11 @@ void Threads::print_on(outputStream* st, bool print_stacks,
13321332
if (p->is_vthread_mounted()) {
13331333
const oop vt = p->vthread();
13341334
assert(vt != nullptr, "vthread should not be null when vthread is mounted");
1335-
st->print_cr(" Mounted virtual thread \"%s\" #" INT64_FORMAT, JavaThread::name_for(vt), (int64_t)java_lang_Thread::thread_id(vt));
1336-
p->print_vthread_stack_on(st);
1335+
// JavaThread._vthread can refer to the carrier thread. Print only if _vthread refers to a virtual thread.
1336+
if (vt != thread_oop) {
1337+
st->print_cr(" Mounted virtual thread #" INT64_FORMAT, (int64_t)java_lang_Thread::thread_id(vt));
1338+
p->print_vthread_stack_on(st);
1339+
}
13371340
}
13381341
}
13391342
}

test/hotspot/jtreg/serviceability/dcmd/thread/PrintMountedVirtualThread.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import jdk.test.lib.process.OutputAnalyzer;
2727
import org.junit.Test;
2828

29-
import java.util.concurrent.CountDownLatch;
3029
import java.util.concurrent.atomic.AtomicBoolean;
3130
import java.util.regex.Pattern;
3231

@@ -41,16 +40,18 @@ public class PrintMountedVirtualThread {
4140

4241
public void run(CommandExecutor executor) throws InterruptedException {
4342
var shouldFinish = new AtomicBoolean(false);
44-
var started = new CountDownLatch(1);
43+
var started = new AtomicBoolean();
4544
final Runnable runnable = new DummyRunnable(shouldFinish, started);
4645
try {
4746
Thread vthread = Thread.ofVirtual().name("Dummy Vthread").start(runnable);
48-
started.await();
47+
while (!started.get()) {
48+
Thread.sleep(10);
49+
}
4950
/* Execute */
5051
OutputAnalyzer output = executor.execute("Thread.print");
5152
output.shouldMatch(".*at " + Pattern.quote(DummyRunnable.class.getName()) + "\\.run.*");
5253
output.shouldMatch(".*at " + Pattern.quote(DummyRunnable.class.getName()) + "\\.compute.*");
53-
output.shouldMatch("Mounted virtual thread " + "\"Dummy Vthread\"" + " #" + vthread.threadId());
54+
output.shouldMatch("Mounted virtual thread " + "#" + vthread.threadId());
5455

5556
} finally {
5657
shouldFinish.set(true);
@@ -63,11 +64,10 @@ public void jmx() throws InterruptedException {
6364
}
6465

6566
static class DummyRunnable implements Runnable {
66-
6767
private final AtomicBoolean shouldFinish;
68-
private final CountDownLatch started;
68+
private final AtomicBoolean started;
6969

70-
public DummyRunnable(AtomicBoolean shouldFinish, CountDownLatch started) {
70+
public DummyRunnable(AtomicBoolean shouldFinish, AtomicBoolean started) {
7171
this.shouldFinish = shouldFinish;
7272
this.started = started;
7373
}
@@ -77,12 +77,11 @@ public void run() {
7777
}
7878

7979
void compute() {
80-
started.countDown();
80+
started.set(true);
8181
while (!shouldFinish.get()) {
8282
Thread.onSpinWait();
8383
}
8484
}
8585
}
8686

87-
8887
}

0 commit comments

Comments
 (0)