RFR: CODETOOLS-7902839: JMH: Replace the use of ThreadLocal with explicitly managed thread map [v2]
Aleksey Shipilev
shade at openjdk.java.net
Tue Mar 9 18:26:32 UTC 2021
> SonarCloud instance reports the potential problem in BenchmarkHandler: 'Call "remove()" on "threadData"'
>
> private final ThreadLocal<ThreadData> threadData;
>
> This actually points to the lifecycle problem with `ThreadLocal`-s in `BenchmarkHandler`. We use it to pass and cache the thread-specific instances and thread parameters with benchmark threads, so that threads can reenter on each iteration and still have the same instances to work on.
>
> Normally, this would be cleaned up when Threads die. They normally do, as default `Executor` shuts down most of the time. But this is not the case for Executors that are not shut down, for example, common pool. In this case, `ThreadLocal`-s would be held until the VM exits.
>
> This should be cleaned up not to use `ThreadLocal`.
Aleksey Shipilev has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains three additional commits since the last revision:
- Rename a bit
- Merge branch 'master' into CODETOOLS-7902839-threadlocal-be-gone
- CODETOOLS-7902839: JMH: Replace the use of ThreadLocal with explicitly managed thread map
-------------
Changes:
- all: https://git.openjdk.java.net/jmh/pull/26/files
- new: https://git.openjdk.java.net/jmh/pull/26/files/e88f9336..b95a62e8
Webrevs:
- full: https://webrevs.openjdk.java.net/?repo=jmh&pr=26&range=01
- incr: https://webrevs.openjdk.java.net/?repo=jmh&pr=26&range=00-01
Stats: 206 lines in 50 files changed: 70 ins; 20 del; 116 mod
Patch: https://git.openjdk.java.net/jmh/pull/26.diff
Fetch: git fetch https://git.openjdk.java.net/jmh pull/26/head:pull/26
PR: https://git.openjdk.java.net/jmh/pull/26
More information about the jmh-dev
mailing list