Skip to content

Commit f0f78a9

Browse files
author
Eric Caspole
committed
8290894: Reduce runtime of vm.lang microbenchmarks
Reviewed-by: rriggs
1 parent 1451642 commit f0f78a9

File tree

5 files changed

+36
-9
lines changed

5 files changed

+36
-9
lines changed

test/micro/org/openjdk/bench/vm/lang/InstanceOf.java

+6
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,15 @@
2424

2525
import org.openjdk.jmh.annotations.Benchmark;
2626
import org.openjdk.jmh.annotations.BenchmarkMode;
27+
import org.openjdk.jmh.annotations.Fork;
28+
import org.openjdk.jmh.annotations.Measurement;
2729
import org.openjdk.jmh.annotations.Mode;
2830
import org.openjdk.jmh.annotations.OperationsPerInvocation;
2931
import org.openjdk.jmh.annotations.OutputTimeUnit;
3032
import org.openjdk.jmh.annotations.Scope;
3133
import org.openjdk.jmh.annotations.Setup;
3234
import org.openjdk.jmh.annotations.State;
35+
import org.openjdk.jmh.annotations.Warmup;
3336

3437
import java.io.Serializable;
3538
import java.util.Date;
@@ -41,6 +44,9 @@
4144
@BenchmarkMode(Mode.AverageTime)
4245
@OutputTimeUnit(TimeUnit.NANOSECONDS)
4346
@State(Scope.Thread)
47+
@Warmup(iterations = 4, time = 2)
48+
@Measurement(iterations = 4, time = 2)
49+
@Fork(value = 3)
4450
public class InstanceOf {
4551

4652
private static final int NOOFOBJECTS = 100;

test/micro/org/openjdk/bench/vm/lang/LockUnlock.java

+6
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,16 @@
2424

2525
import org.openjdk.jmh.annotations.Benchmark;
2626
import org.openjdk.jmh.annotations.BenchmarkMode;
27+
import org.openjdk.jmh.annotations.Fork;
28+
import org.openjdk.jmh.annotations.Measurement;
2729
import org.openjdk.jmh.annotations.Mode;
2830
import org.openjdk.jmh.annotations.OutputTimeUnit;
2931
import org.openjdk.jmh.annotations.Param;
3032
import org.openjdk.jmh.annotations.Scope;
3133
import org.openjdk.jmh.annotations.Setup;
3234
import org.openjdk.jmh.annotations.State;
3335
import org.openjdk.jmh.annotations.Threads;
36+
import org.openjdk.jmh.annotations.Warmup;
3437

3538
import java.util.concurrent.TimeUnit;
3639

@@ -41,6 +44,9 @@
4144
@BenchmarkMode(Mode.AverageTime)
4245
@OutputTimeUnit(TimeUnit.NANOSECONDS)
4346
@State(Scope.Benchmark)
47+
@Warmup(iterations = 4, time = 2)
48+
@Measurement(iterations = 4, time = 2)
49+
@Fork(value = 3)
4450
public class LockUnlock {
4551

4652
@Param("100")

test/micro/org/openjdk/bench/vm/lang/MonitorBench.java

+12-9
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,27 @@
2727

2828
import org.openjdk.jmh.annotations.Benchmark;
2929
import org.openjdk.jmh.annotations.BenchmarkMode;
30+
import org.openjdk.jmh.annotations.Fork;
31+
import org.openjdk.jmh.annotations.Measurement;
3032
import org.openjdk.jmh.annotations.Mode;
3133
import org.openjdk.jmh.annotations.OutputTimeUnit;
3234
import org.openjdk.jmh.annotations.Param;
3335
import org.openjdk.jmh.annotations.Scope;
3436
import org.openjdk.jmh.annotations.Setup;
3537
import org.openjdk.jmh.annotations.State;
3638
import org.openjdk.jmh.annotations.Threads;
39+
import org.openjdk.jmh.annotations.Warmup;
3740
import org.openjdk.jmh.infra.Blackhole;
3841

3942
@State(Scope.Benchmark)
4043
@Threads(Threads.MAX)
44+
@Warmup(iterations = 4, time = 2)
45+
@Measurement(iterations = 4, time = 2)
46+
@Fork(value = 3)
4147
public class MonitorBench {
4248

43-
@Param({"100", "250"})
44-
int consumeUnlocked;
45-
46-
@Param({"100", "250"})
47-
int consumeLocked;
49+
@Param({"50" /* , "250" */})
50+
int consumeTime;
4851

4952
@Param({"0", "1"})
5053
int throwThreshold;
@@ -67,19 +70,19 @@ public void setup() {
6770

6871
int update2(int sharedIndex) throws Exception {
6972
synchronized (sharedLocks[sharedIndex]) {
70-
Blackhole.consumeCPU(consumeLocked);
73+
Blackhole.consumeCPU(consumeTime);
7174
if (ThreadLocalRandom.current().nextInt(range) < throwThreshold) {
7275
throw new Exception("Update failed");
7376
} else {
74-
Blackhole.consumeCPU(consumeLocked);
77+
Blackhole.consumeCPU(consumeTime);
7578
return 0;
7679
}
7780
}
7881
}
7982

8083
int update1(int sharedIndex) throws Exception {
8184
synchronized (sharedLocks[sharedIndex]) {
82-
Blackhole.consumeCPU(consumeLocked);
85+
Blackhole.consumeCPU(consumeTime);
8386
return update2(sharedIndex);
8487
}
8588
}
@@ -88,7 +91,7 @@ int update1(int sharedIndex) throws Exception {
8891
@BenchmarkMode(Mode.Throughput)
8992
@OutputTimeUnit(TimeUnit.MILLISECONDS)
9093
public int action() throws InterruptedException {
91-
Blackhole.consumeCPU(consumeUnlocked);
94+
Blackhole.consumeCPU(consumeTime);
9295
int sharedLockIndex = ThreadLocalRandom.current().nextInt(locksSize);
9396
Object sharedLock = sharedLocks[sharedLockIndex];
9497
synchronized (sharedLock) {

test/micro/org/openjdk/bench/vm/lang/Throw.java

+6
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,13 @@
2424

2525
import org.openjdk.jmh.annotations.Benchmark;
2626
import org.openjdk.jmh.annotations.BenchmarkMode;
27+
import org.openjdk.jmh.annotations.Fork;
28+
import org.openjdk.jmh.annotations.Measurement;
2729
import org.openjdk.jmh.annotations.Mode;
2830
import org.openjdk.jmh.annotations.OutputTimeUnit;
2931
import org.openjdk.jmh.annotations.Scope;
3032
import org.openjdk.jmh.annotations.State;
33+
import org.openjdk.jmh.annotations.Warmup;
3134
import org.openjdk.jmh.infra.Blackhole;
3235

3336
import java.util.concurrent.TimeUnit;
@@ -38,6 +41,9 @@
3841
@BenchmarkMode(Mode.AverageTime)
3942
@OutputTimeUnit(TimeUnit.NANOSECONDS)
4043
@State(Scope.Thread)
44+
@Warmup(iterations = 4, time = 2)
45+
@Measurement(iterations = 4, time = 2)
46+
@Fork(value = 3)
4147
public class Throw {
4248

4349
public static boolean alwaysTrue = true;

test/micro/org/openjdk/bench/vm/lang/ThrowableRuntimeMicros.java

+6
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,22 @@
2525
import java.util.concurrent.TimeUnit;
2626
import org.openjdk.jmh.annotations.Benchmark;
2727
import org.openjdk.jmh.annotations.BenchmarkMode;
28+
import org.openjdk.jmh.annotations.Fork;
29+
import org.openjdk.jmh.annotations.Measurement;
2830
import org.openjdk.jmh.annotations.Mode;
2931
import org.openjdk.jmh.annotations.OutputTimeUnit;
3032
import org.openjdk.jmh.annotations.Param;
3133
import org.openjdk.jmh.annotations.Scope;
3234
import org.openjdk.jmh.annotations.State;
35+
import org.openjdk.jmh.annotations.Warmup;
3336
import org.openjdk.jmh.infra.Blackhole;
3437

3538
@State(value = Scope.Benchmark)
3639
@BenchmarkMode(Mode.AverageTime)
3740
@OutputTimeUnit(TimeUnit.NANOSECONDS)
41+
@Warmup(iterations = 4, time = 2)
42+
@Measurement(iterations = 4, time = 2)
43+
@Fork(value = 3)
3844
public class ThrowableRuntimeMicros {
3945

4046
// TestStack will add this number of calls to the call stack

0 commit comments

Comments
 (0)