RFR: CODETOOLS-7903484: JMH: Use ThreadMXBean.getTotalThreadAllocatedBytes for -prof gc [v3]

Aleksey Shipilev shade at openjdk.org
Tue Jun 6 10:58:27 UTC 2023


> JDK 21 comes with a new method that gives the total allocated rate for all the threads, [JDK-8304074](https://bugs.openjdk.org/browse/JDK-8304074). JMH -prof gc can use it, when available. This allows catching the totality of the thread allocations, regardless whether the threads went in or out during the lifetime of the benchmark. Current `-prof gc` is missing those threads most of the time. 
> 
> Example benchmark:
> 
> 
> @Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
> @Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
> @Fork(value = 1, jvmArgsAppend = {"-Xmx1g", "-Xms1g", "-XX:+AlwaysPreTouch", "-XX:+UseParallelGC"})
> @BenchmarkMode(Mode.Throughput)
> @OutputTimeUnit(TimeUnit.SECONDS)
> @State(Scope.Thread)
> public class TAB {
> 
>     @Benchmark
>     public void inline(Blackhole bh) throws InterruptedException {
>         bh.consume(new byte[1_000_000]);
>     }
> 
>     @Benchmark
>     public void separate(Blackhole bh) throws InterruptedException {
>         Thread thread = new Thread(() -> { bh.consume(new byte[1_000_000]); });
>         thread.start();
>         thread.join();
>     }
> }
> 
> 
> Current JDK 20:
> 
> 
> Benchmark                          Mode  Cnt        Score      Error   Units
> 
> TAB.inline                        thrpt    5   100632,205 ± 1237,322   ops/s
> TAB.inline:·gc.alloc.rate         thrpt    5    95961,825 ± 1181,577  MB/sec
> TAB.inline:·gc.alloc.rate.norm    thrpt    5  1000016,004 ±    0,001    B/op
> TAB.inline:·gc.count              thrpt    5     1432,000             counts
> TAB.inline:·gc.time               thrpt    5      207,000                 ms
> 
> TAB.separate                      thrpt    5    18169,567 ±  374,656   ops/s
> TAB.separate:·gc.alloc.rate       thrpt    5        5,822 ±    0,120  MB/sec  ; <--- missing allocations
> TAB.separate:·gc.alloc.rate.norm  thrpt    5      336,024 ±    0,010    B/op  ; <--- missing allocations
> TAB.separate:·gc.count            thrpt    5     2023,000             counts
> TAB.separate:·gc.time             thrpt    5      229,000                 ms
> 
> 
> Self-built JDK 21-ea:
> 
> 
> Benchmark                          Mode  Cnt        Score      Error   Units
> 
> TAB.inline                        thrpt    5   103061,266 ± 2086,154   ops/s
> TAB.inline:·gc.alloc.rate         thrpt    5    98277,065 ± 1988,502  MB/sec
> TAB.inline:·gc.alloc.rate.norm    thrpt    5  1000016,056 ±    0,001    B/op
> TAB.inline:·gc.count              thrpt    5     1466,000             counts
> TAB...

Aleksey Shipilev has updated the pull request incrementally with one additional commit since the last revision:

  Check latest JDK

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

Changes:
  - all: https://git.openjdk.org/jmh/pull/106/files
  - new: https://git.openjdk.org/jmh/pull/106/files/8e1fdda0..3a44cdcb

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jmh&pr=106&range=02
 - incr: https://webrevs.openjdk.org/?repo=jmh&pr=106&range=01-02

  Stats: 1 line in 1 file changed: 1 ins; 0 del; 0 mod
  Patch: https://git.openjdk.org/jmh/pull/106.diff
  Fetch: git fetch https://git.openjdk.org/jmh.git pull/106/head:pull/106

PR: https://git.openjdk.org/jmh/pull/106


More information about the jmh-dev mailing list