package micro.benchmarks;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.infra.Blackhole;
public class GroupAllocationBenchmark extends BenchmarkBase {
static class Node {
Object x;
Object y;
Object z1;
Object z2;
Object z3;
Node(Object x, Object y) {
this.x = x;
this.y = y;
}
}
@State(Scope.Benchmark)
public static class BenchState {
public byte[] bytes = new byte[16];
Object c;
Object a;
Object b;
Pair pair = new Pair();
}
static class Pair {
Object left;
Object right;
}
@Benchmark
public void groupAllocate3(Blackhole bh) {
bh.consume(new Node(new Node(bh, bh), new Node(bh, bh)));
}
@Benchmark
public void groupAllocate2(Blackhole bh) {
bh.consume(new Node(new Node(bh, bh), null));
}
@Benchmark
public void groupAllocate1(Blackhole bh) {
bh.consume(new Node(null, null));
}
class BufByteArray {
int begin;
int end;
byte[] bytes;
BufByteArray(byte[] bytes) {
this.bytes = bytes;
this.begin = 116;
this.end = 324;
}
}
@Benchmark
public void bufDecode(Blackhole bh, BenchState state) {
Object a = new BufByteArray(state.bytes);
Object b = new BufByteArray(state.bytes);
Pair pair = state.pair;
pair.left = a;
pair.right = b;
bh.consume(pair);
}
class TxnLevelImpl {
int prevReadCount;
long minRetryTimeoutNanos = 9223372036854775807L;
long consumedRetryDelta;
int prevBargeCount;
int prevWriteThreshold;
int logSize;
int[] indices;
Object[] prevValues;
int beforeCommitSize;
int whileValidatingSize;
int whilePreparingSize;
int whileCommittingSize;
int afterCommitSize;
int afterRollbackSize;
boolean phantom;
boolean waiters;
Object txn;
Object executor;
TxnLevelImpl parUndo;
Object parLevel;
Object root;
Object blockedBy;
Object state;
TxnLevelImpl(Object a, Object b, Object c) {
txn = a;
executor = b;
root = c;
}
}
@Benchmark
public void rangeTxnLevelImpl(Blackhole bh, BenchState state) {
TxnLevelImpl o = new TxnLevelImpl(state.a, state.b, state.c);
bh.consume(o);
}
}