Skip to content

Commit 239760a

Browse files
author
Eric Caspole
committed
8355233: Add a DMB related benchmark
Reviewed-by: kvn
1 parent d61765f commit 239760a

File tree

1 file changed

+107
-0
lines changed

1 file changed

+107
-0
lines changed
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
package org.openjdk.bench.vm.compiler;
25+
26+
import java.util.concurrent.TimeUnit;
27+
import org.openjdk.jmh.annotations.Benchmark;
28+
import org.openjdk.jmh.annotations.BenchmarkMode;
29+
import org.openjdk.jmh.annotations.CompilerControl;
30+
import org.openjdk.jmh.annotations.Fork;
31+
import org.openjdk.jmh.annotations.Group;
32+
import org.openjdk.jmh.annotations.GroupThreads;
33+
import org.openjdk.jmh.annotations.Measurement;
34+
import org.openjdk.jmh.annotations.Mode;
35+
import org.openjdk.jmh.annotations.OperationsPerInvocation;
36+
import org.openjdk.jmh.annotations.OutputTimeUnit;
37+
import org.openjdk.jmh.annotations.Param;
38+
import org.openjdk.jmh.annotations.Scope;
39+
import org.openjdk.jmh.annotations.Setup;
40+
import org.openjdk.jmh.annotations.State;
41+
import org.openjdk.jmh.annotations.Warmup;
42+
import org.openjdk.jmh.infra.Blackhole;
43+
44+
@BenchmarkMode(Mode.Throughput)
45+
@State(Scope.Benchmark)
46+
@OutputTimeUnit(TimeUnit.MICROSECONDS)
47+
@Warmup(iterations = 8, time = 4)
48+
@Measurement(iterations = 6, time = 3)
49+
public class DMBCheck {
50+
51+
// The allocations of DoubleDMB$A and DoubleDMB$C
52+
// will cause aarch64 dmb barrier instructions.
53+
// The different latency of the dmb ish/ishst/ishld modes
54+
// may make a noticeable difference in the benchmark results.
55+
// These modes may be set by cpu defaults or XX options.
56+
57+
class A {
58+
59+
final String b = new String("Hi there");
60+
}
61+
62+
class C {
63+
64+
private A a;
65+
66+
public A getA() {
67+
if (a == null) {
68+
a = new A();
69+
}
70+
return a;
71+
}
72+
}
73+
74+
static C c = null;
75+
76+
@Setup
77+
public void setup() {
78+
c = new C();
79+
}
80+
81+
@CompilerControl(CompilerControl.Mode.DONT_INLINE)
82+
void action(Blackhole b) throws Exception {
83+
c = new C();
84+
85+
if (c.getA().b == null) {
86+
throw new Exception("a should not be null");
87+
}
88+
b.consume(c);
89+
}
90+
91+
@Benchmark
92+
@Fork(value = 1, jvmArgs = {
93+
"-XX:+UnlockDiagnosticVMOptions", "-XX:+AlwaysMergeDMB", "-XX:+IgnoreUnrecognizedVMOptions"})
94+
public void plusAlwaysMergeDMB(Blackhole b) throws Exception {
95+
96+
action(b);
97+
}
98+
99+
@Benchmark
100+
@Fork(value = 1, jvmArgs = {
101+
"-XX:+UnlockDiagnosticVMOptions", "-XX:-AlwaysMergeDMB", "-XX:+IgnoreUnrecognizedVMOptions"})
102+
public void minusAlwaysMergeDMB(Blackhole b) throws Exception {
103+
104+
action(b);
105+
}
106+
107+
}

0 commit comments

Comments
 (0)