Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8267075: jcmd VM.cds should print directory of the output files #4576

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/java.base/share/classes/jdk/internal/misc/CDS.java
Expand Up @@ -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");
Expand Down Expand Up @@ -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.
Expand All @@ -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");
}
}
Expand All @@ -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);
}
}
Expand Up @@ -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 :
Expand Down Expand Up @@ -200,6 +200,7 @@ protected static void test(String fileName, long pid,
checkFileExistence(archiveFileName, false);
}
}
return output;
}

protected static void print2ln(String arg) {
Expand Down
27 changes: 25 additions & 2 deletions test/hotspot/jtreg/runtime/cds/appcds/jcmd/JCmdTestFileSafety.java
Expand Up @@ -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
Expand All @@ -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 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(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");
}
}
}

static void test() throws Exception {
buildJars();
Expand All @@ -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");
Expand Down