From e78f7043a83fd70de675667fa89e609baf9f6fdc Mon Sep 17 00:00:00 2001 From: Yumin Qi Date: Wed, 23 Jun 2021 10:07:37 -0700 Subject: [PATCH 1/2] 8267075: jcmd VM.cds should print directory of the output files --- .../share/classes/jdk/internal/misc/CDS.java | 14 ++++++----- .../cds/appcds/jcmd/JCmdTestDumpBase.java | 3 ++- .../cds/appcds/jcmd/JCmdTestFileSafety.java | 25 ++++++++++++++++++- 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/java.base/share/classes/jdk/internal/misc/CDS.java b/src/java.base/share/classes/jdk/internal/misc/CDS.java index 4bed16ad87bdc..d3f6e4f3dd312 100644 --- a/src/java.base/share/classes/jdk/internal/misc/CDS.java +++ b/src/java.base/share/classes/jdk/internal/misc/CDS.java @@ -256,6 +256,7 @@ private static boolean containsExcludedFlags(String testStr) { * @param fileName user input archive name, can be null. */ private static void dumpSharedArchive(boolean isStatic, String fileName) throws Exception { + String cwd = new File("").getAbsolutePath(); // current dir used for printing message. String currentPid = String.valueOf(ProcessHandle.current().pid()); String archiveFileName = fileName != null ? fileName : "java_pid" + currentPid + (isStatic ? "_static.jsa" : "_dynamic.jsa"); @@ -299,8 +300,8 @@ private static void dumpSharedArchive(boolean isStatic, String fileName) throws Process proc = Runtime.getRuntime().exec(cmds.toArray(new String[0])); // Drain stdout/stderr to files in new threads. - String stdOutFile = drainOutput(proc.getInputStream(), proc.pid(), "stdout", cmds); - String stdErrFile = drainOutput(proc.getErrorStream(), proc.pid(), "stderr", cmds); + String stdOutFileName = drainOutput(proc.getInputStream(), proc.pid(), "stdout", cmds); + String stdErrFileName = drainOutput(proc.getErrorStream(), proc.pid(), "stderr", cmds); proc.waitFor(); // done, delete classlist file. @@ -311,14 +312,15 @@ private static void dumpSharedArchive(boolean isStatic, String fileName) throws if (!tempArchiveFile.exists()) { throw new RuntimeException("Archive file " + tempArchiveFileName + " is not created, please check stdout file " + - stdOutFile + " or stderr file " + - stdErrFile + " for more detail"); + cwd + File.separator + stdOutFileName + " or stderr file " + + cwd + File.separator + stdErrFileName + " for more detail"); } } else { dumpDynamicArchive(tempArchiveFileName); if (!tempArchiveFile.exists()) { throw new RuntimeException("Archive file " + tempArchiveFileName + - " is not created, please check process " + + " is not created, please check current working directory " + + cwd + " for process " + currentPid + " output for more detail"); } } @@ -331,6 +333,6 @@ private static void dumpSharedArchive(boolean isStatic, String fileName) throws throw new RuntimeException("Cannot rename temp file " + tempArchiveFileName + " to archive file" + archiveFileName); } // Everyting goes well, print out the file name. - System.out.println((isStatic ? "Static" : " Dynamic") + " dump to file " + archiveFileName); + System.out.println((isStatic ? "Static" : " Dynamic") + " dump to file " + cwd + File.separator + archiveFileName); } } diff --git a/test/hotspot/jtreg/runtime/cds/appcds/jcmd/JCmdTestDumpBase.java b/test/hotspot/jtreg/runtime/cds/appcds/jcmd/JCmdTestDumpBase.java index 563e0698479fc..75103a50ed491 100644 --- a/test/hotspot/jtreg/runtime/cds/appcds/jcmd/JCmdTestDumpBase.java +++ b/test/hotspot/jtreg/runtime/cds/appcds/jcmd/JCmdTestDumpBase.java @@ -172,7 +172,7 @@ private static void runWithArchiveFile(String archiveName, boolean useBoot, Str } } - protected static void test(String fileName, long pid, + protected static OutputAnalyzer test(String fileName, long pid, boolean useBoot, boolean expectOK, String... messages) throws Exception { System.out.println("Expected: " + (expectOK ? "SUCCESS" : "FAIL")); String archiveFileName = fileName != null ? fileName : @@ -200,6 +200,7 @@ protected static void test(String fileName, long pid, checkFileExistence(archiveFileName, false); } } + return output; } protected static void print2ln(String arg) { diff --git a/test/hotspot/jtreg/runtime/cds/appcds/jcmd/JCmdTestFileSafety.java b/test/hotspot/jtreg/runtime/cds/appcds/jcmd/JCmdTestFileSafety.java index 19669bc004478..ceb24fd7002d6 100644 --- a/test/hotspot/jtreg/runtime/cds/appcds/jcmd/JCmdTestFileSafety.java +++ b/test/hotspot/jtreg/runtime/cds/appcds/jcmd/JCmdTestFileSafety.java @@ -41,8 +41,25 @@ import jdk.test.lib.cds.CDSTestUtils; import jdk.test.lib.apps.LingeredApp; import jdk.test.lib.Platform; +import jdk.test.lib.process.OutputAnalyzer; public class JCmdTestFileSafety extends JCmdTestDumpBase { + static final String promtStdout = "please check stdout file"; + static final String promtStderr = "or stderr file"; + + static void checkContainAbsoluteLogPath(OutputAnalyzer output) throws Exception { + String stdText = output.getOutput(); + if (stdText.contains(promtStdout) && + stdText.contains(promtStderr)) { + int a = stdText.indexOf(promtStdout); + int b = stdText.indexOf(promtStderr); + String stdOutFileName = stdText.substring(a + promtStdout.length() + 1, b - 1).trim(); + File stdOutFile = new File(stdOutFileName); + if (!stdOutFile.isAbsolute()) { + throw new RuntimeException("Failed to set file name in absolute for prompting message"); + } + } + } static void test() throws Exception { buildJars(); @@ -67,10 +84,16 @@ static void test() throws Exception { test(localFileName, pid, noBoot, EXPECT_PASS); outputDirFile.setWritable(false); test(localFileName, pid, noBoot, EXPECT_FAIL); - app.stopApp(); outputDirFile.setWritable(true); checkFileExistence(localFileName, true/*exist*/); + // Illegal character in file name + localFileName = "mystatic:.jsa"; + OutputAnalyzer output = test(localFileName, pid, noBoot, EXPECT_FAIL); + checkFileExistence(localFileName, false/*exist*/); + checkContainAbsoluteLogPath(output); + app.stopApp(); + setIsStatic(false/*dynamic*/); // Set target dir not writable, do dynamic dump print2ln(test_count++ + " Set target dir not writable, do dynamic dump"); From 2ef28e061858766eb4df4f1cf18fbc84860b0040 Mon Sep 17 00:00:00 2001 From: Yumin Qi Date: Wed, 23 Jun 2021 15:04:05 -0700 Subject: [PATCH 2/2] Fix string name for prompt --- .../cds/appcds/jcmd/JCmdTestFileSafety.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/hotspot/jtreg/runtime/cds/appcds/jcmd/JCmdTestFileSafety.java b/test/hotspot/jtreg/runtime/cds/appcds/jcmd/JCmdTestFileSafety.java index ceb24fd7002d6..e6312521d157d 100644 --- a/test/hotspot/jtreg/runtime/cds/appcds/jcmd/JCmdTestFileSafety.java +++ b/test/hotspot/jtreg/runtime/cds/appcds/jcmd/JCmdTestFileSafety.java @@ -24,7 +24,7 @@ /* * @test - * @bug 8265465 + * @bug 8265465 8267075 * @summary Test jcmd to dump static shared archive. * @requires vm.cds * @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds @@ -44,16 +44,16 @@ import jdk.test.lib.process.OutputAnalyzer; public class JCmdTestFileSafety extends JCmdTestDumpBase { - static final String promtStdout = "please check stdout file"; - static final String promtStderr = "or stderr file"; + static final String promptStdout = "please check stdout file"; + static final String promptStderr = "or stderr file"; static void checkContainAbsoluteLogPath(OutputAnalyzer output) throws Exception { String stdText = output.getOutput(); - if (stdText.contains(promtStdout) && - stdText.contains(promtStderr)) { - int a = stdText.indexOf(promtStdout); - int b = stdText.indexOf(promtStderr); - String stdOutFileName = stdText.substring(a + promtStdout.length() + 1, b - 1).trim(); + if (stdText.contains(promptStdout) && + stdText.contains(promptStderr)) { + int a = stdText.indexOf(promptStdout); + int b = stdText.indexOf(promptStderr); + String stdOutFileName = stdText.substring(a + promptStdout.length() + 1, b - 1).trim(); File stdOutFile = new File(stdOutFileName); if (!stdOutFile.isAbsolute()) { throw new RuntimeException("Failed to set file name in absolute for prompting message");