diff --git a/test/sun/tools/jstatd/JstatdTest.java b/test/sun/tools/jstatd/JstatdTest.java index f07ce6b1742e2270900b97f3c34d1488d31d1bd4..0c003cfcb5eeaa88f1db70a25db497abfd3e82ff 100644 --- a/test/sun/tools/jstatd/JstatdTest.java +++ b/test/sun/tools/jstatd/JstatdTest.java @@ -27,6 +27,7 @@ import java.rmi.RemoteException; import java.rmi.registry.LocateRegistry; import java.rmi.registry.Registry; import java.util.Arrays; +import java.util.regex.Pattern; import static jdk.testlibrary.Asserts.*; import jdk.testlibrary.JDKToolLauncher; @@ -34,6 +35,7 @@ import jdk.testlibrary.OutputAnalyzer; import jdk.testlibrary.ProcessThread; import jdk.testlibrary.TestThread; import jdk.testlibrary.Utils; +import jdk.testlibrary.ProcessTools; /** * The base class for tests of jstatd. @@ -93,8 +95,11 @@ public final class JstatdTest { if (tool == "rmiregistry") { processName = "registryimpl"; } + + Pattern toolInJpsPattern = + Pattern.compile("^\\d+\\s{1}" + processName + "\\s{1}.*-dparent\\.pid\\." + ProcessTools.getProcessId() + ".*"); for (String line : lines) { - if (line.toLowerCase().matches("^\\d+\\s{1}" + processName + "$")) { + if (toolInJpsPattern.matcher(line.toLowerCase()).matches()) { pid = line.split(" ")[0]; count++; } @@ -167,6 +172,8 @@ public final class JstatdTest { private OutputAnalyzer runJps() throws Exception { JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jps"); launcher.addVMArg("-XX:+UsePerfData"); + // Run jps with -v flag to obtain -Dparent.pid. + launcher.addToolArg("-v"); launcher.addToolArg(getDestination()); String[] cmd = launcher.getCommand(); @@ -286,7 +293,7 @@ public final class JstatdTest { * jstatd -J-XX:+UsePerfData -J-Djava.security.policy=all.policy -n serverName * jstatd -J-XX:+UsePerfData -J-Djava.security.policy=all.policy -p port -n serverName */ - private String[] getJstatdCmd() throws UnknownHostException { + private String[] getJstatdCmd() throws Exception { JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jstatd"); launcher.addVMArg("-XX:+UsePerfData"); String testSrc = System.getProperty("test.src"); @@ -294,6 +301,8 @@ public final class JstatdTest { assertTrue(policy.exists() && policy.isFile(), "Security policy " + policy.getAbsolutePath() + " does not exist or not a file"); launcher.addVMArg("-Djava.security.policy=" + policy.getAbsolutePath()); + // -Dparent.pid. will help to identify jstad process started by this test + launcher.addVMArg("-Dparent.pid." + ProcessTools.getProcessId()); if (port != null) { launcher.addToolArg("-p"); launcher.addToolArg(port);