8308033: The jcmd thread dump related tests should test virtual threads

Reviewed-by: cjplummer, sspitsyn
This commit is contained in:
Jaikiran Pai 2024-05-08 10:11:01 +00:00
parent 1aebab780c
commit edd47c10eb
6 changed files with 56 additions and 16 deletions

View File

@ -1,5 +1,5 @@
#
# Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
@ -27,10 +27,6 @@
serviceability/AsyncGetCallTrace/MyPackage/ASGCTBaseTest.java 8308026 generic-all
serviceability/jvmti/GetThreadListStackTraces/OneGetThreadListStackTraces.java 8308027 generic-all
serviceability/jvmti/Heap/IterateHeapWithEscapeAnalysisEnabled.java 8264699 generic-all
serviceability/dcmd/thread/PrintConcurrentLocksTest.java 8308033 generic-all
serviceability/dcmd/thread/PrintTest.java 8308033 generic-all
serviceability/dcmd/thread/ThreadDumpToFileTest.java 8308033 generic-all
serviceability/tmtools/jstack/DaemonThreadTest.java 8308033 generic-all
####
## Classes not unloaded as expected (TODO, need to check if FJ keeps a reference)

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -21,6 +21,7 @@
* questions.
*/
import org.testng.SkipException;
import org.testng.annotations.Test;
import org.testng.Assert;
@ -171,6 +172,9 @@ public class PrintTest {
@Test
public void jmx() {
if (Thread.currentThread().isVirtual()) {
throw new SkipException("skipping test since current thread is virtual thread");
}
run(new JMXExecutor());
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -38,6 +38,7 @@ public class DaemonThreadTest {
static class NormalThread extends Thread {
NormalThread() {
setDaemon(false);
}
@Override

View File

@ -33,9 +33,6 @@ com/sun/jdi/cds/CDSBreakpointTest.java 8307778 generic-all
com/sun/jdi/cds/CDSDeleteAllBkptsTest.java 8307778 generic-all
com/sun/jdi/cds/CDSFieldWatchpoints.java 8307778 generic-all
sun/tools/jcmd/JcmdOutputEncodingTest.java 8308033 generic-all
sun/tools/jstack/BasicJStackTest.java 8308033 generic-all
javax/management/remote/mandatory/connection/BrokenConnectionTest.java 8308035 windows-x64
javax/management/remote/mandatory/loading/MissingClassTest.java 8145413 windows-x64

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,6 +23,8 @@
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import jdk.test.lib.Utils;
import jdk.test.lib.process.OutputAnalyzer;
@ -31,7 +33,7 @@ import jdk.test.lib.JDKToolLauncher;
/*
* @test
* @bug 8222491 8273187
* @bug 8222491 8273187 8308033
* @summary Tests if we handle the encoding of jcmd output correctly.
* @library /test/lib
* @run main JcmdOutputEncodingTest
@ -52,12 +54,43 @@ public class JcmdOutputEncodingTest {
launcher.addVMArg("-Dfile.encoding=" + cs);
launcher.addVMArg("-Dsun.stdout.encoding=" + cs);
launcher.addToolArg(Long.toString(ProcessTools.getProcessId()));
launcher.addToolArg("Thread.print");
boolean isVirtualThread = Thread.currentThread().isVirtual();
Path threadDumpFile = null;
if (isVirtualThread) {
// "jcmd Thread.print" will not print thread dumps of virtual threads.
// So we use "Thread.dump_to_file" command instead and dump the thread
// stacktraces in a file
threadDumpFile = Files.createTempFile(Path.of("."), "jcmd", ".tdump").toAbsolutePath();
launcher.addToolArg("Thread.dump_to_file");
launcher.addToolArg("-overwrite");
launcher.addToolArg(threadDumpFile.toString());
} else {
launcher.addToolArg("Thread.print");
}
ProcessBuilder processBuilder = new ProcessBuilder();
processBuilder.command(launcher.getCommand());
OutputAnalyzer output = ProcessTools.executeProcess(processBuilder, null, cs);
output.shouldHaveExitValue(0);
output.shouldContain(marker);
if (isVirtualThread) {
// verify the file containing the thread dump has the expected text
try (var br = Files.newBufferedReader(threadDumpFile, cs)) {
String line = null;
boolean found = false;
while ((line = br.readLine()) != null) {
if (line.contains(marker)) {
found = true;
break;
}
}
if (!found) {
output.reportDiagnosticSummary();
throw new RuntimeException("'" + marker + "' missing in thread dump in file "
+ threadDumpFile);
}
}
} else {
output.shouldContain(marker);
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -30,9 +30,11 @@ import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.JDKToolLauncher;
import jtreg.SkippedException;
/*
* @test
* @bug 8273187
* @bug 8273187 8308033
* @summary Unit test for jstack utility
* @library /test/lib
* @run main BasicJStackTest
@ -42,6 +44,13 @@ public class BasicJStackTest {
private static ProcessBuilder processBuilder = new ProcessBuilder();
public static void main(String[] args) throws Exception {
if (Thread.currentThread().isVirtual()) {
// This test runs jstack against the current process and then asserts the
// presence of current thread in the stacktraces. We skip this test
// when the current thread is a virtual thread since "jstack" command doesn't
// print the stacktraces of virtual threads.
throw new SkippedException("skipping test since current thread is a virtual thread");
}
testJstackNoArgs();
testJstack_l();
testJstackUTF8Encoding();