--- old/test/hotspot/jtreg/containers/docker/TestJcmdWithSideCar.java 2019-08-06 20:11:04.000000000 -0700 +++ new/test/hotspot/jtreg/containers/docker/TestJcmdWithSideCar.java 2019-08-06 20:11:04.000000000 -0700 @@ -71,11 +71,14 @@ waitForMainContainerToStart(500, 10); t.checkForErrors(); - OutputAnalyzer jcmdOut = testCase01(); - long mainProcPid = findProcess(jcmdOut, "EventGeneratorLoop"); + long mainProcPid = testCase01(); t.assertIsAlive(); - testCase02(mainProcPid); + + // Excluding the test case below until JDK-8228850 is fixed + // JDK-8228850: jhsdb jinfo fails with ClassCastException: + // s.j.h.oops.TypeArray cannot be cast to s.j.h.oops.Instance + // testCase02(mainProcPid); // JCMD does not work in sidecar configuration, except for "jcmd -l". // Including this test case to assist in reproduction of the problem. @@ -90,12 +93,31 @@ } - // Run "jcmd -l" in a sidecar container and find a process that runs EventGeneratorLoop - private static OutputAnalyzer testCase01() throws Exception { - return runSideCar(MAIN_CONTAINER_NAME, "/jdk/bin/jcmd", "-l") + // Run "jcmd -l" in a sidecar container, find a process that runs EventGeneratorLoop and + // return it's PID. Try several times. It is possible that container and JVM has started, + // but but the JVM has not loaded main class yet. In such case, JCMD reports + // "Unknown" as the name of the main class, but exits without failure. That is OK, just + // try again after a short delay. + private static long testCase01() throws Exception { + long pid = -1; + for (int i=1; i<5; i++) { + OutputAnalyzer out = runSideCar(MAIN_CONTAINER_NAME, "/jdk/bin/jcmd", "-l") .shouldHaveExitValue(0) - .shouldContain("sun.tools.jcmd.JCmd") - .shouldContain("EventGeneratorLoop"); + .shouldContain("sun.tools.jcmd.JCmd"); + pid = findProcess(out, "EventGeneratorLoop"); + if (pid != -1) { + break; + } + try { + Thread.sleep(500); + } catch (InterruptedException e) {} + } + + if (pid == -1) { + throw new RuntimeException("Could not find the target process"); + } + + return pid; } // run jhsdb jinfo (jhsdb uses PTRACE) @@ -176,13 +198,14 @@ return DockerTestUtils.execute(cmd); } + // will return -1 if matching process could not be found private static long findProcess(OutputAnalyzer out, String name) throws Exception { List l = out.asLines() .stream() .filter(s -> s.contains(name)) .collect(Collectors.toList()); if (l.isEmpty()) { - throw new RuntimeException("Could not find matching process"); + return -1; } String psInfo = l.get(0); System.out.println("findProcess(): psInfo: " + psInfo);