8267075: jcmd VM.cds should print directory of the output files
Reviewed-by: ccheung
This commit is contained in:
parent
e515873f88
commit
7c31903dd3
@ -256,6 +256,7 @@ public class CDS {
|
|||||||
* @param fileName user input archive name, can be null.
|
* @param fileName user input archive name, can be null.
|
||||||
*/
|
*/
|
||||||
private static void dumpSharedArchive(boolean isStatic, String fileName) throws Exception {
|
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 currentPid = String.valueOf(ProcessHandle.current().pid());
|
||||||
String archiveFileName = fileName != null ? fileName :
|
String archiveFileName = fileName != null ? fileName :
|
||||||
"java_pid" + currentPid + (isStatic ? "_static.jsa" : "_dynamic.jsa");
|
"java_pid" + currentPid + (isStatic ? "_static.jsa" : "_dynamic.jsa");
|
||||||
@ -299,8 +300,8 @@ public class CDS {
|
|||||||
Process proc = Runtime.getRuntime().exec(cmds.toArray(new String[0]));
|
Process proc = Runtime.getRuntime().exec(cmds.toArray(new String[0]));
|
||||||
|
|
||||||
// Drain stdout/stderr to files in new threads.
|
// Drain stdout/stderr to files in new threads.
|
||||||
String stdOutFile = drainOutput(proc.getInputStream(), proc.pid(), "stdout", cmds);
|
String stdOutFileName = drainOutput(proc.getInputStream(), proc.pid(), "stdout", cmds);
|
||||||
String stdErrFile = drainOutput(proc.getErrorStream(), proc.pid(), "stderr", cmds);
|
String stdErrFileName = drainOutput(proc.getErrorStream(), proc.pid(), "stderr", cmds);
|
||||||
|
|
||||||
proc.waitFor();
|
proc.waitFor();
|
||||||
// done, delete classlist file.
|
// done, delete classlist file.
|
||||||
@ -311,14 +312,15 @@ public class CDS {
|
|||||||
if (!tempArchiveFile.exists()) {
|
if (!tempArchiveFile.exists()) {
|
||||||
throw new RuntimeException("Archive file " + tempArchiveFileName +
|
throw new RuntimeException("Archive file " + tempArchiveFileName +
|
||||||
" is not created, please check stdout file " +
|
" is not created, please check stdout file " +
|
||||||
stdOutFile + " or stderr file " +
|
cwd + File.separator + stdOutFileName + " or stderr file " +
|
||||||
stdErrFile + " for more detail");
|
cwd + File.separator + stdErrFileName + " for more detail");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
dumpDynamicArchive(tempArchiveFileName);
|
dumpDynamicArchive(tempArchiveFileName);
|
||||||
if (!tempArchiveFile.exists()) {
|
if (!tempArchiveFile.exists()) {
|
||||||
throw new RuntimeException("Archive file " + tempArchiveFileName +
|
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");
|
currentPid + " output for more detail");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -331,6 +333,6 @@ public class CDS {
|
|||||||
throw new RuntimeException("Cannot rename temp file " + tempArchiveFileName + " to archive file" + archiveFileName);
|
throw new RuntimeException("Cannot rename temp file " + tempArchiveFileName + " to archive file" + archiveFileName);
|
||||||
}
|
}
|
||||||
// Everyting goes well, print out the file name.
|
// 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -172,7 +172,7 @@ public abstract class JCmdTestDumpBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static void test(String fileName, long pid,
|
protected static OutputAnalyzer test(String fileName, long pid,
|
||||||
boolean useBoot, boolean expectOK, String... messages) throws Exception {
|
boolean useBoot, boolean expectOK, String... messages) throws Exception {
|
||||||
System.out.println("Expected: " + (expectOK ? "SUCCESS" : "FAIL"));
|
System.out.println("Expected: " + (expectOK ? "SUCCESS" : "FAIL"));
|
||||||
String archiveFileName = fileName != null ? fileName :
|
String archiveFileName = fileName != null ? fileName :
|
||||||
@ -200,6 +200,7 @@ public abstract class JCmdTestDumpBase {
|
|||||||
checkFileExistence(archiveFileName, false);
|
checkFileExistence(archiveFileName, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static void print2ln(String arg) {
|
protected static void print2ln(String arg) {
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
* @bug 8265465
|
* @bug 8265465 8267075
|
||||||
* @summary Test jcmd to dump static shared archive.
|
* @summary Test jcmd to dump static shared archive.
|
||||||
* @requires vm.cds
|
* @requires vm.cds
|
||||||
* @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds
|
* @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds
|
||||||
@ -41,8 +41,25 @@ import java.io.IOException;
|
|||||||
import jdk.test.lib.cds.CDSTestUtils;
|
import jdk.test.lib.cds.CDSTestUtils;
|
||||||
import jdk.test.lib.apps.LingeredApp;
|
import jdk.test.lib.apps.LingeredApp;
|
||||||
import jdk.test.lib.Platform;
|
import jdk.test.lib.Platform;
|
||||||
|
import jdk.test.lib.process.OutputAnalyzer;
|
||||||
|
|
||||||
public class JCmdTestFileSafety extends JCmdTestDumpBase {
|
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 {
|
static void test() throws Exception {
|
||||||
buildJars();
|
buildJars();
|
||||||
@ -67,10 +84,16 @@ public class JCmdTestFileSafety extends JCmdTestDumpBase {
|
|||||||
test(localFileName, pid, noBoot, EXPECT_PASS);
|
test(localFileName, pid, noBoot, EXPECT_PASS);
|
||||||
outputDirFile.setWritable(false);
|
outputDirFile.setWritable(false);
|
||||||
test(localFileName, pid, noBoot, EXPECT_FAIL);
|
test(localFileName, pid, noBoot, EXPECT_FAIL);
|
||||||
app.stopApp();
|
|
||||||
outputDirFile.setWritable(true);
|
outputDirFile.setWritable(true);
|
||||||
checkFileExistence(localFileName, true/*exist*/);
|
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*/);
|
setIsStatic(false/*dynamic*/);
|
||||||
// Set target dir not writable, do dynamic dump
|
// Set target dir not writable, do dynamic dump
|
||||||
print2ln(test_count++ + " Set target dir not writable, do dynamic dump");
|
print2ln(test_count++ + " Set target dir not writable, do dynamic dump");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user