RFR: Runner: if -Djmh.ignoreLock=true then skip jmh.lock creation

Aleksey Shipilev shade at openjdk.java.net
Wed Oct 21 08:29:36 UTC 2020


On Wed, 21 Oct 2020 08:12:42 GMT, Sergey Ponomarev <github.com+415502+stokito at openjdk.org> wrote:

> When -Djmh.ignoreLock=true JMH anyway will try to create the jmh.lock file and if it fails it will write a warning for
> an user. This may be not a best way for several reasons:
> 1. If user specified ignoreLock then he already knows what she or he doing.
> 2. If the Benchmark is started from IDE i.e idea-jmh-plugin and the ignoreLock was added automatically then users may
> be confused by this warning 3. It makes execution slightly longer when we anyway trying to create the jmh.lock file
> 4. This simplifies logic

I think avoiding touching the `jmh.lock` file is a good thing, but I don't think we should be silent about explicit
lock ignore.

jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java line 206:

> 204:             if (lock == null) {
> 205:                 String msg = "Unable to acquire the JMH lock (" + JMH_LOCK_FILE + "): already taken by another JMH
> instance"; 206:                 throw new RunnerException("ERROR: " + msg + ", exiting. Use -Djmh.ignoreLock=true to
> forcefully continue.");

The local `msg` here was to use it in both branches. Since both branches are gone, this could be just: `throw new
RunnerException("ERROR: Unable to acquire the JMH lock (" + JMH_LOCK_FILE + "), already taken by another JMH instance,
exiting. Use -Djmh.ignoreLock=true to forcefully continue.");`

jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java line 212:

> 210:         } catch (IOException e) {
> 211:             String msg = "Exception while trying to acquire the JMH lock (" + JMH_LOCK_FILE + "): " +
> e.getMessage(); 212:             throw new RunnerException("ERROR: " + msg  + ", exiting. Use -Djmh.ignoreLock=true to
> forcefully continue.");

Similarly, `throw new RunnerException("ERROR: Exception while trying to acquire the JMH lock (" + JMH_LOCK_FILE + "),
exiting. Use -Djmh.ignoreLock=true to forcefully continue.", e);`

jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java line 185:

> 183:     public Collection<RunResult> run() throws RunnerException {
> 184:         if (JMH_LOCK_IGNORE) {
> 185:             return internalRun();

We should still print the warning here. `-Djmh.ignoreLock=true` must not go unnoticed, because it has a potential to
break performance benchmarks. (I guess it is a separate discussion why does any plugin pass it in -- it should not
without user knowing!). So, I suggest:

 if (JMH_LOCK_IGNORE) {
    out.println("# WARNING: JMH lock is ignored by user request, make sure no other JMH instances are running");
    return internalRun();
 }

-------------

Changes requested by shade (Committer).

PR: https://git.openjdk.java.net/jmh/pull/6


More information about the jmh-dev mailing list