8290894: Reduce runtime of vm.lang microbenchmarks
Reviewed-by: rriggs
This commit is contained in:
parent
1451642317
commit
f0f78a9125
@ -24,12 +24,15 @@ package org.openjdk.bench.vm.lang;
|
||||
|
||||
import org.openjdk.jmh.annotations.Benchmark;
|
||||
import org.openjdk.jmh.annotations.BenchmarkMode;
|
||||
import org.openjdk.jmh.annotations.Fork;
|
||||
import org.openjdk.jmh.annotations.Measurement;
|
||||
import org.openjdk.jmh.annotations.Mode;
|
||||
import org.openjdk.jmh.annotations.OperationsPerInvocation;
|
||||
import org.openjdk.jmh.annotations.OutputTimeUnit;
|
||||
import org.openjdk.jmh.annotations.Scope;
|
||||
import org.openjdk.jmh.annotations.Setup;
|
||||
import org.openjdk.jmh.annotations.State;
|
||||
import org.openjdk.jmh.annotations.Warmup;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
@ -41,6 +44,9 @@ import java.util.concurrent.TimeUnit;
|
||||
@BenchmarkMode(Mode.AverageTime)
|
||||
@OutputTimeUnit(TimeUnit.NANOSECONDS)
|
||||
@State(Scope.Thread)
|
||||
@Warmup(iterations = 4, time = 2)
|
||||
@Measurement(iterations = 4, time = 2)
|
||||
@Fork(value = 3)
|
||||
public class InstanceOf {
|
||||
|
||||
private static final int NOOFOBJECTS = 100;
|
||||
|
@ -24,6 +24,8 @@ package org.openjdk.bench.vm.lang;
|
||||
|
||||
import org.openjdk.jmh.annotations.Benchmark;
|
||||
import org.openjdk.jmh.annotations.BenchmarkMode;
|
||||
import org.openjdk.jmh.annotations.Fork;
|
||||
import org.openjdk.jmh.annotations.Measurement;
|
||||
import org.openjdk.jmh.annotations.Mode;
|
||||
import org.openjdk.jmh.annotations.OutputTimeUnit;
|
||||
import org.openjdk.jmh.annotations.Param;
|
||||
@ -31,6 +33,7 @@ import org.openjdk.jmh.annotations.Scope;
|
||||
import org.openjdk.jmh.annotations.Setup;
|
||||
import org.openjdk.jmh.annotations.State;
|
||||
import org.openjdk.jmh.annotations.Threads;
|
||||
import org.openjdk.jmh.annotations.Warmup;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@ -41,6 +44,9 @@ import java.util.concurrent.TimeUnit;
|
||||
@BenchmarkMode(Mode.AverageTime)
|
||||
@OutputTimeUnit(TimeUnit.NANOSECONDS)
|
||||
@State(Scope.Benchmark)
|
||||
@Warmup(iterations = 4, time = 2)
|
||||
@Measurement(iterations = 4, time = 2)
|
||||
@Fork(value = 3)
|
||||
public class LockUnlock {
|
||||
|
||||
@Param("100")
|
||||
|
@ -27,6 +27,8 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.openjdk.jmh.annotations.Benchmark;
|
||||
import org.openjdk.jmh.annotations.BenchmarkMode;
|
||||
import org.openjdk.jmh.annotations.Fork;
|
||||
import org.openjdk.jmh.annotations.Measurement;
|
||||
import org.openjdk.jmh.annotations.Mode;
|
||||
import org.openjdk.jmh.annotations.OutputTimeUnit;
|
||||
import org.openjdk.jmh.annotations.Param;
|
||||
@ -34,17 +36,18 @@ import org.openjdk.jmh.annotations.Scope;
|
||||
import org.openjdk.jmh.annotations.Setup;
|
||||
import org.openjdk.jmh.annotations.State;
|
||||
import org.openjdk.jmh.annotations.Threads;
|
||||
import org.openjdk.jmh.annotations.Warmup;
|
||||
import org.openjdk.jmh.infra.Blackhole;
|
||||
|
||||
@State(Scope.Benchmark)
|
||||
@Threads(Threads.MAX)
|
||||
@Warmup(iterations = 4, time = 2)
|
||||
@Measurement(iterations = 4, time = 2)
|
||||
@Fork(value = 3)
|
||||
public class MonitorBench {
|
||||
|
||||
@Param({"100", "250"})
|
||||
int consumeUnlocked;
|
||||
|
||||
@Param({"100", "250"})
|
||||
int consumeLocked;
|
||||
@Param({"50" /* , "250" */})
|
||||
int consumeTime;
|
||||
|
||||
@Param({"0", "1"})
|
||||
int throwThreshold;
|
||||
@ -67,11 +70,11 @@ public class MonitorBench {
|
||||
|
||||
int update2(int sharedIndex) throws Exception {
|
||||
synchronized (sharedLocks[sharedIndex]) {
|
||||
Blackhole.consumeCPU(consumeLocked);
|
||||
Blackhole.consumeCPU(consumeTime);
|
||||
if (ThreadLocalRandom.current().nextInt(range) < throwThreshold) {
|
||||
throw new Exception("Update failed");
|
||||
} else {
|
||||
Blackhole.consumeCPU(consumeLocked);
|
||||
Blackhole.consumeCPU(consumeTime);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@ -79,7 +82,7 @@ public class MonitorBench {
|
||||
|
||||
int update1(int sharedIndex) throws Exception {
|
||||
synchronized (sharedLocks[sharedIndex]) {
|
||||
Blackhole.consumeCPU(consumeLocked);
|
||||
Blackhole.consumeCPU(consumeTime);
|
||||
return update2(sharedIndex);
|
||||
}
|
||||
}
|
||||
@ -88,7 +91,7 @@ public class MonitorBench {
|
||||
@BenchmarkMode(Mode.Throughput)
|
||||
@OutputTimeUnit(TimeUnit.MILLISECONDS)
|
||||
public int action() throws InterruptedException {
|
||||
Blackhole.consumeCPU(consumeUnlocked);
|
||||
Blackhole.consumeCPU(consumeTime);
|
||||
int sharedLockIndex = ThreadLocalRandom.current().nextInt(locksSize);
|
||||
Object sharedLock = sharedLocks[sharedLockIndex];
|
||||
synchronized (sharedLock) {
|
||||
|
@ -24,10 +24,13 @@ package org.openjdk.bench.vm.lang;
|
||||
|
||||
import org.openjdk.jmh.annotations.Benchmark;
|
||||
import org.openjdk.jmh.annotations.BenchmarkMode;
|
||||
import org.openjdk.jmh.annotations.Fork;
|
||||
import org.openjdk.jmh.annotations.Measurement;
|
||||
import org.openjdk.jmh.annotations.Mode;
|
||||
import org.openjdk.jmh.annotations.OutputTimeUnit;
|
||||
import org.openjdk.jmh.annotations.Scope;
|
||||
import org.openjdk.jmh.annotations.State;
|
||||
import org.openjdk.jmh.annotations.Warmup;
|
||||
import org.openjdk.jmh.infra.Blackhole;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@ -38,6 +41,9 @@ import java.util.concurrent.TimeUnit;
|
||||
@BenchmarkMode(Mode.AverageTime)
|
||||
@OutputTimeUnit(TimeUnit.NANOSECONDS)
|
||||
@State(Scope.Thread)
|
||||
@Warmup(iterations = 4, time = 2)
|
||||
@Measurement(iterations = 4, time = 2)
|
||||
@Fork(value = 3)
|
||||
public class Throw {
|
||||
|
||||
public static boolean alwaysTrue = true;
|
||||
|
@ -25,16 +25,22 @@ package org.openjdk.bench.vm.lang;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.openjdk.jmh.annotations.Benchmark;
|
||||
import org.openjdk.jmh.annotations.BenchmarkMode;
|
||||
import org.openjdk.jmh.annotations.Fork;
|
||||
import org.openjdk.jmh.annotations.Measurement;
|
||||
import org.openjdk.jmh.annotations.Mode;
|
||||
import org.openjdk.jmh.annotations.OutputTimeUnit;
|
||||
import org.openjdk.jmh.annotations.Param;
|
||||
import org.openjdk.jmh.annotations.Scope;
|
||||
import org.openjdk.jmh.annotations.State;
|
||||
import org.openjdk.jmh.annotations.Warmup;
|
||||
import org.openjdk.jmh.infra.Blackhole;
|
||||
|
||||
@State(value = Scope.Benchmark)
|
||||
@BenchmarkMode(Mode.AverageTime)
|
||||
@OutputTimeUnit(TimeUnit.NANOSECONDS)
|
||||
@Warmup(iterations = 4, time = 2)
|
||||
@Measurement(iterations = 4, time = 2)
|
||||
@Fork(value = 3)
|
||||
public class ThrowableRuntimeMicros {
|
||||
|
||||
// TestStack will add this number of calls to the call stack
|
||||
|
Loading…
Reference in New Issue
Block a user