Skip to content

Conversation

@shipilev
Copy link
Member

@shipilev shipilev commented Jun 1, 2023

JDK 21 comes with a new method that gives the total allocated rate for all the threads, 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.inline:·gc.time               thrpt    5      180,000                 ms

TAB.separate                      thrpt    5    18105,424 ± 1444,031   ops/s
TAB.separate:·gc.alloc.rate       thrpt    5    17270,918 ± 1378,016  MB/sec
TAB.separate:·gc.alloc.rate.norm  thrpt    5  1000360,319 ±    0,030    B/op ; <--- same alloc rate
TAB.separate:·gc.count            thrpt    5     2015,000             counts
TAB.separate:·gc.time             thrpt    5      197,000                 ms

Note: GHA testing would not be clean until 21-ea release catches up and contains JDK-8304074.


Progress

  • Change must not contain extraneous whitespace
  • Change must be properly reviewed (1 review required, with at least 1 Committer)

Issue

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jmh.git pull/106/head:pull/106
$ git checkout pull/106

Update a local copy of the PR:
$ git checkout pull/106
$ git pull https://git.openjdk.org/jmh.git pull/106/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 106

View PR using the GUI difftool:
$ git pr show -t 106

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jmh/pull/106.diff

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Jun 1, 2023

👋 Welcome back shade! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@shipilev shipilev marked this pull request as ready for review June 1, 2023 11:19
@openjdk openjdk bot added the rfr Pull request is ready for review label Jun 1, 2023
@mlbridge
Copy link

mlbridge bot commented Jun 1, 2023

Webrevs

Copy link
Member

@phohensee phohensee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a Committer, but nice result. Change looks fine.

@shipilev shipilev force-pushed the CODETOOLS-7903484-use-thread-allocated-bytes branch from 4d52144 to 8e1fdda Compare June 6, 2023 10:15
@openjdk
Copy link

openjdk bot commented Jun 6, 2023

@shipilev Please do not rebase or force-push to an active PR as it invalidates existing review comments. Note for future reference, the bots always squash all changes into a single commit automatically as part of the integration. See OpenJDK Developers’ Guide for more information.

@shipilev shipilev merged commit 9384362 into openjdk:master Jun 6, 2023
@shipilev shipilev deleted the CODETOOLS-7903484-use-thread-allocated-bytes branch June 20, 2023 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

rfr Pull request is ready for review

Development

Successfully merging this pull request may close these issues.

2 participants