Issues with dtraceasm, and a workaround

Paul Sandoz paul.sandoz at oracle.com
Mon Feb 22 19:45:38 UTC 2021


Hi Alexey,

[Took last week off]

The latter works for me. Using the Process.pid method may be problematic since it's only available on Java 9 and above (there’s a hacky way to get the pid by reflective means on 8 and lower [1]).

AFAICT sending TERM (software termination signal) to the dtrace process causes it to exit gracefully with a zero exit code, so we can check for non-zero exit code and throw.

Paul.

[1] https://stackoverflow.com/questions/4750470/how-to-get-pid-of-process-ive-just-started-within-java-program

On Feb 22, 2021, at 8:51 AM, Aleksey Shipilev <shade at redhat.com<mailto:shade at redhat.com>> wrote:

On 2/22/21 5:42 PM, Henri Tremblay wrote:
Sadly, I do not get the same result. When running from master I do get
# Processing profiler results: DTraceAsmProfiler Exception in thread "main" java.lang.IllegalStateException: [kill: 37996: No such process
]
at org.openjdk.jmh.profile.DTraceAsmProfiler.afterTrial(DTraceAsmProfiler.java:94)
at org.openjdk.jmh.runner.Runner.runSeparate(Runner.java:682)
at org.openjdk.jmh.runner.Runner.runBenchmarks(Runner.java:565)
at org.openjdk.jmh.runner.Runner.internalRun(Runner.java:317)
at org.openjdk.jmh.runner.Runner.run(Runner.java:209)
at org.openjdk.jmh.Main.main(Main.java:71)
However, when applying the patch I still have the same error.
Running
sudo java -jar jmh-samples/target/benchmarks.jar Hello -wi 5 -i 5 -f 1 -w 1s -r 1s -prof dtraceasm
However, I do get the exact same issue with the PR. I did a clean install between each run. I'm not sure if if I'm just stupid or something is actually not working.
If someone has an idea. I'll debug slightly later.

I might have botched the "kill" line. Either TERM is wrong, or we are killing the wrong PID (forked VM). See if this works?

  Collection<String> messages = Utils.tryWith("sudo", "kill", "-15", Long.toString(dtraceProcess.pid()));

...or maybe we should not expect that kill always succeeds, for example when profiler exits itself?

So it should be this?

       // We cannot use Process.destroy, because it closes the streams right away.
       // Instead, deliver TERM by hand and wait for process to gracefully terminate.
       Utils.tryWith("sudo", "kill", "-TERM", Long.toString(dtraceProcess.pid()));

       try {
           // dtrace would exit with non-zero exit code due to TERM,
           // so we cannot test for errcode == 0 on this path.
           dtraceProcess.waitFor();
       } catch (InterruptedException e) {
           throw new IllegalStateException("Interrupted while waiting for profiler to stop");
       }


--
Thanks,
-Aleksey




More information about the jmh-dev mailing list