Skip to content
Permalink
Browse files
Automatic merge of jdk:master into master
  • Loading branch information
duke committed Jun 24, 2021
2 parents d433033 + 7c31903 commit c1c2122ab10f46530274a219ed106b61c8d5f0f5
Showing 3 changed files with 35 additions and 9 deletions.
@@ -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);
}
}
@@ -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) {
@@ -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
@@ -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();
@@ -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");

0 comments on commit c1c2122

Please sign in to comment.