下面列出了org.openjdk.jmh.annotations.Group#org.openjdk.jmh.annotations.GroupThreads 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Benchmark @Group @GroupThreads(8)
public void record(RecordCounter counters) {
switch (buffer.offer(Boolean.TRUE)) {
case ReadBuffer.FAILED:
counters.recordFailed++;
break;
case ReadBuffer.SUCCESS:
counters.recordSuccess++;
break;
case ReadBuffer.FULL:
counters.recordFull++;
break;
default:
throw new IllegalStateException();
}
}
@Benchmark
@Group("tenMixedArgs")
@GroupThreads(PRODUCER_THREADS)
public boolean tenMixedArgsCaller(final Control control, final CallerCounters counters) {
this.waitStrategy.control = control;
try {
this.proxy.tenMixedArgs(this.intArg,
this.objArg,
this.longArg,
this.customType0,
this.doubleArg,
this.customType1,
this.floatArg,
this.customType2,
this.booleanArg,
this.customType3);
counters.callsFailed = this.waitStrategy.retries;
return true;
} catch (final StoppedException e) {
return false;
}
}
/**
* Javadoc comment.
*/
@Benchmark
@BenchmarkMode(Mode.SampleTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@GroupThreads(6)
public int attachDetach() {
Context old = cu.attach();
try {
return key.get();
} finally {
Context.current().detach(old);
}
}
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@GroupThreads(3)
public long racyGetAndSetAndGetGeneration() {
long oldGeneration = generator.getGeneration();
generator.setGeneration(oldGeneration + 1);
return generator.getGeneration();
}
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@GroupThreads(3)
public long racyGetAndSetAndGetGeneration() {
long oldGeneration = generator.getGeneration();
generator.setGeneration(oldGeneration + 1);
return generator.getGeneration();
}
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@GroupThreads(3)
public long racyGetAndSetAndGetGeneration() {
long oldGeneration = generator.getGeneration();
generator.setGeneration(oldGeneration + 1);
return generator.getGeneration();
}
@Benchmark
@BenchmarkMode(Mode.SampleTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@GroupThreads(6)
public boolean retainReleaseContended() {
buf.retain();
Blackhole.consumeCPU(delay);
return buf.release();
}
@Benchmark @Group("mild_contention") @GroupThreads(1)
public void mild_contention_drain(DrainCounters counters, ConsumerMarker cm) {
q.drainTo(next -> {
counters.drained++;
return true;
});
}
@Benchmark @Group("no_contention") @GroupThreads(1)
public void no_contention_offer(OfferCounters counters) {
if (q.offer(ONE, 1)) {
counters.offersMade++;
} else {
counters.offersFailed++;
}
}
@Benchmark @Group("no_contention") @GroupThreads(1)
public void no_contention_drain(DrainCounters counters, ConsumerMarker cm) {
q.drainTo((s, b) -> {
counters.drained++;
return true;
}, 1000);
}
@Benchmark @Group("high_contention") @GroupThreads(8)
public void high_contention_offer(OfferCounters counters) {
if (q.offer(ONE, 1)) {
counters.offersMade++;
} else {
counters.offersFailed++;
}
}
@Benchmark @Group("high_contention") @GroupThreads(1)
public void high_contention_drain(DrainCounters counters, ConsumerMarker cm) {
q.drainTo((s, b) -> {
counters.drained++;
return true;
}, 1000);
}
@Benchmark
@Group("single")
@GroupThreads(2)
public void producerSingle() {
for (int i = 0; i < batch.length; i++) {
this.s.sEnqueue(batch[i]);
}
}
@Benchmark
@Group("batchasym")
@GroupThreads(2)
public TLCState[] consumerBatch() {
final TLCState[] res = new TLCState[batch.length];
for (int i = 0; i < batch.length; i++) {
res[i] = this.s.sDequeue();
}
return res;
}
@Benchmark
@Group("unalignedPrimitiveArgs")
@GroupThreads(PRODUCER_THREADS)
public boolean unalignedPrimitiveArgsCaller(final Control control, final CallerCounters counters) {
this.waitStrategy.control = control;
try {
this.proxy.unalignedPrimitiveArgs(
longArg,
doubleArg,
longArg2,
doubleArg2,
longArg3,
doubleArg3,
longArg4,
doubleArg4,
longArg,
doubleArg,
longArg2,
doubleArg2,
longArg3,
doubleArg3,
longArg4,
doubleArg4,
intArg);
counters.callsFailed = this.waitStrategy.retries;
return true;
} catch (final StoppedException e) {
return false;
}
}
/**
*
*/
@Benchmark
@GroupThreads(THREAD_COUNT)
@Group("park")
public void unpark() {
LockSupport.unpark(thread);
}
/**
*
*/
@Benchmark
@Group("condition")
@GroupThreads(THREAD_COUNT)
public void notifyAll0() {
synchronized (mux) {
mux.notify();
}
}
@Benchmark @Group("no_contention") @GroupThreads(1)
public void no_contention_poll(PollCounters counters) {
if (queue.poll() == null) {
counters.pollsFailed++;
} else {
counters.pollsMade++;
}
}
@Benchmark @Group("mild_contention") @GroupThreads(2)
public void mild_contention_offer(OfferCounters counters) {
if (queue.offer(Boolean.TRUE)) {
counters.offersMade++;
} else {
counters.offersFailed++;
}
}
@Benchmark @Group("mild_contention") @GroupThreads(1)
public void mild_contention_poll(PollCounters counters) {
if (queue.poll() == null) {
counters.pollsFailed++;
} else {
counters.pollsMade++;
}
}
@Benchmark @Group("high_contention") @GroupThreads(8)
public void high_contention_offer(OfferCounters counters) {
if (queue.offer(Boolean.TRUE)) {
counters.offersMade++;
} else {
counters.offersFailed++;
}
}
@Benchmark @Group("high_contention") @GroupThreads(1)
public void high_contention_poll(PollCounters counters) {
if (queue.poll() == null) {
counters.pollsFailed++;
} else {
counters.pollsMade++;
}
}
/**
* Javadoc comment.
*/
@Benchmark
@BenchmarkMode(Mode.SampleTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@GroupThreads(6)
public int attachDetach() {
Context old = cu.attach();
try {
return key.get();
} finally {
Context.current().detach(old);
}
}
@Benchmark
@Group("oneObjectArg")
@GroupThreads(PRODUCER_THREADS)
public boolean oneObjectArgCaller(final Control control, final CallerCounters counters) {
this.waitStrategy.control = control;
try {
this.proxy.oneObjectArg(this.objArg);
counters.callsFailed = this.waitStrategy.retries;
return true;
} catch (final StoppedException e) {
return false;
}
}
@Benchmark
@Group("onePrimitiveArg")
@GroupThreads(PRODUCER_THREADS)
public boolean onePrimitiveArgCaller(final Control control, final CallerCounters counters) {
this.waitStrategy.control = control;
try {
this.proxy.onePrimitiveArg(this.intArg);
counters.callsFailed = this.waitStrategy.retries;
return true;
} catch (final StoppedException e) {
return false;
}
}
@Benchmark
@Group("alignedPrimitiveArgs")
@GroupThreads(PRODUCER_THREADS)
public boolean alignedPrimitiveArgsCaller(final Control control, final CallerCounters counters) {
this.waitStrategy.control = control;
try {
this.proxy.alignedPrimitiveArgs(intArg,
longArg,
doubleArg,
longArg2,
doubleArg2,
longArg3,
doubleArg3,
longArg4,
doubleArg4,
longArg,
doubleArg,
longArg2,
doubleArg2,
longArg3,
doubleArg3,
longArg4,
doubleArg4);
counters.callsFailed = this.waitStrategy.retries;
return true;
} catch (final StoppedException e) {
return false;
}
}
@Benchmark @Group("mild_contention") @GroupThreads(2)
public int mild_contention_httpResponse_servlet3() {
return threeResponses(servlet3);
}
@Benchmark
@Group("c1p4")
@GroupThreads(1)
public void c1p4Consumer(Test test) throws InterruptedException {
test.consumer().take();
}
@Benchmark @Group("high_contention") @GroupThreads(8)
public long high_contention_randomLong_jre6() {
return jre6.randomLong();
}
@Benchmark
@Group("g")
@GroupThreads(1)
public int get() {
return counter.get();
}