Skip to content

Commit 17b695d

Browse files
Satyen SubramaniamPaul Hohensee
authored andcommitted
8308033: The jcmd thread dump related tests should test virtual threads
Backport-of: edd47c10ebfdc021368820dec6a109251554e8b0
1 parent a1e5891 commit 17b695d

File tree

6 files changed

+56
-16
lines changed

6 files changed

+56
-16
lines changed

test/hotspot/jtreg/ProblemList-Virtual.txt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2022, 2024, 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
@@ -27,10 +27,6 @@
2727
serviceability/AsyncGetCallTrace/MyPackage/ASGCTBaseTest.java 8308026 generic-all
2828
serviceability/jvmti/GetThreadListStackTraces/OneGetThreadListStackTraces.java 8308027 generic-all
2929
serviceability/jvmti/Heap/IterateHeapWithEscapeAnalysisEnabled.java 8264699 generic-all
30-
serviceability/dcmd/thread/PrintConcurrentLocksTest.java 8308033 generic-all
31-
serviceability/dcmd/thread/PrintTest.java 8308033 generic-all
32-
serviceability/dcmd/thread/ThreadDumpToFileTest.java 8308033 generic-all
33-
serviceability/tmtools/jstack/DaemonThreadTest.java 8308033 generic-all
3430

3531
####
3632
## Classes not unloaded as expected (TODO, need to check if FJ keeps a reference)

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2024, 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
@@ -21,6 +21,7 @@
2121
* questions.
2222
*/
2323

24+
import org.testng.SkipException;
2425
import org.testng.annotations.Test;
2526
import org.testng.Assert;
2627

@@ -171,6 +172,9 @@ public void run(CommandExecutor executor) {
171172

172173
@Test
173174
public void jmx() {
175+
if (Thread.currentThread().isVirtual()) {
176+
throw new SkipException("skipping test since current thread is virtual thread");
177+
}
174178
run(new JMXExecutor());
175179
}
176180
}

test/hotspot/jtreg/serviceability/tmtools/jstack/DaemonThreadTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2024, 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
@@ -38,6 +38,7 @@ public class DaemonThreadTest {
3838
static class NormalThread extends Thread {
3939

4040
NormalThread() {
41+
setDaemon(false);
4142
}
4243

4344
@Override

test/jdk/ProblemList-Virtual.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ com/sun/jdi/EATests.java#id0 8264699 generic-
3030
com/sun/jdi/ExceptionEvents.java 8278470 generic-all
3131
com/sun/jdi/RedefineCrossStart.java 8278470 generic-all
3232

33-
sun/tools/jcmd/JcmdOutputEncodingTest.java 8308033 generic-all
34-
sun/tools/jstack/BasicJStackTest.java 8308033 generic-all
35-
3633
javax/management/remote/mandatory/connection/BrokenConnectionTest.java 8308035 windows-x64
3734

3835
javax/management/remote/mandatory/loading/MissingClassTest.java 8145413 windows-x64

test/jdk/sun/tools/jcmd/JcmdOutputEncodingTest.java

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2024, 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
@@ -23,6 +23,8 @@
2323

2424
import java.nio.charset.Charset;
2525
import java.nio.charset.StandardCharsets;
26+
import java.nio.file.Files;
27+
import java.nio.file.Path;
2628

2729
import jdk.test.lib.Utils;
2830
import jdk.test.lib.process.OutputAnalyzer;
@@ -31,7 +33,7 @@
3133

3234
/*
3335
* @test
34-
* @bug 8222491 8273187
36+
* @bug 8222491 8273187 8308033
3537
* @summary Tests if we handle the encoding of jcmd output correctly.
3638
* @library /test/lib
3739
* @run main JcmdOutputEncodingTest
@@ -52,12 +54,43 @@ private static void testThreadDump() throws Exception {
5254
launcher.addVMArg("-Dfile.encoding=" + cs);
5355
launcher.addVMArg("-Dsun.stdout.encoding=" + cs);
5456
launcher.addToolArg(Long.toString(ProcessTools.getProcessId()));
55-
launcher.addToolArg("Thread.print");
57+
boolean isVirtualThread = Thread.currentThread().isVirtual();
58+
Path threadDumpFile = null;
59+
if (isVirtualThread) {
60+
// "jcmd Thread.print" will not print thread dumps of virtual threads.
61+
// So we use "Thread.dump_to_file" command instead and dump the thread
62+
// stacktraces in a file
63+
threadDumpFile = Files.createTempFile(Path.of("."), "jcmd", ".tdump").toAbsolutePath();
64+
launcher.addToolArg("Thread.dump_to_file");
65+
launcher.addToolArg("-overwrite");
66+
launcher.addToolArg(threadDumpFile.toString());
67+
} else {
68+
launcher.addToolArg("Thread.print");
69+
}
5670

5771
ProcessBuilder processBuilder = new ProcessBuilder();
5872
processBuilder.command(launcher.getCommand());
5973
OutputAnalyzer output = ProcessTools.executeProcess(processBuilder, null, cs);
6074
output.shouldHaveExitValue(0);
61-
output.shouldContain(marker);
75+
if (isVirtualThread) {
76+
// verify the file containing the thread dump has the expected text
77+
try (var br = Files.newBufferedReader(threadDumpFile, cs)) {
78+
String line = null;
79+
boolean found = false;
80+
while ((line = br.readLine()) != null) {
81+
if (line.contains(marker)) {
82+
found = true;
83+
break;
84+
}
85+
}
86+
if (!found) {
87+
output.reportDiagnosticSummary();
88+
throw new RuntimeException("'" + marker + "' missing in thread dump in file "
89+
+ threadDumpFile);
90+
}
91+
}
92+
} else {
93+
output.shouldContain(marker);
94+
}
6295
}
6396
}

test/jdk/sun/tools/jstack/BasicJStackTest.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2024, 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
@@ -30,9 +30,11 @@
3030
import jdk.test.lib.process.ProcessTools;
3131
import jdk.test.lib.JDKToolLauncher;
3232

33+
import jtreg.SkippedException;
34+
3335
/*
3436
* @test
35-
* @bug 8273187
37+
* @bug 8273187 8308033
3638
* @summary Unit test for jstack utility
3739
* @library /test/lib
3840
* @run main BasicJStackTest
@@ -42,6 +44,13 @@ public class BasicJStackTest {
4244
private static ProcessBuilder processBuilder = new ProcessBuilder();
4345

4446
public static void main(String[] args) throws Exception {
47+
if (Thread.currentThread().isVirtual()) {
48+
// This test runs jstack against the current process and then asserts the
49+
// presence of current thread in the stacktraces. We skip this test
50+
// when the current thread is a virtual thread since "jstack" command doesn't
51+
// print the stacktraces of virtual threads.
52+
throw new SkippedException("skipping test since current thread is a virtual thread");
53+
}
4554
testJstackNoArgs();
4655
testJstack_l();
4756
testJstackUTF8Encoding();

0 commit comments

Comments
 (0)