8314085: Fixing scope from benchmark to thread for JMH tests having shared state

Co-authored-by: Vladimir Ivanov <vaivanov@openjdk.org>
Reviewed-by: sviswanathan, ecaspole
This commit is contained in:
Swati Sharma 2023-10-03 16:01:36 +00:00 committed by Sandhya Viswanathan
parent ae796a4e10
commit b438cffdb9
38 changed files with 46 additions and 46 deletions

View File

@ -36,7 +36,7 @@ import java.util.concurrent.TimeUnit;
@Fork(value = 4, warmups = 0)
@Measurement(iterations = 5, time = 1)
@Warmup(iterations = 2, time = 2)
@State(Scope.Benchmark)
@State(Scope.Thread)
public class DataInputStreamTest {
private final int size = 1024;

View File

@ -46,7 +46,7 @@ import org.openjdk.jmh.runner.options.OptionsBuilder;
@Warmup(iterations = 2, time = 3, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 15, time = 1, timeUnit = TimeUnit.SECONDS)
@Fork(1)
@State(Scope.Benchmark)
@State(Scope.Thread)
public class ArrayClone {
@Param({"0", "10", "100", "1000"})

View File

@ -51,7 +51,7 @@ import org.openjdk.jmh.infra.Blackhole;
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@State(Scope.Benchmark)
@State(Scope.Thread)
@Measurement(iterations = 3, time = 1000, timeUnit = TimeUnit.MILLISECONDS)
@Warmup(iterations = 3, time = 1000, timeUnit = TimeUnit.MILLISECONDS)
@Fork(3)

View File

@ -30,7 +30,7 @@ import java.util.concurrent.TimeUnit;
*/
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@State(Scope.Benchmark)
@State(Scope.Thread)
@Warmup(iterations = 5, time = 1)
@Measurement(iterations = 5, time = 1)
@Fork(3)

View File

@ -32,7 +32,7 @@ import java.util.concurrent.TimeUnit;
*/
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@State(Scope.Benchmark)
@State(Scope.Thread)
@Warmup(iterations = 5, time = 1)
@Measurement(iterations = 5, time = 1)
@Fork(value = 3)

View File

@ -30,7 +30,7 @@ import java.util.concurrent.TimeUnit;
*/
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@State(Scope.Benchmark)
@State(Scope.Thread)
@Warmup(iterations = 5, time = 1)
@Measurement(iterations = 5, time = 1)
@Fork(value = 3)

View File

@ -39,7 +39,7 @@ import java.util.concurrent.TimeUnit;
*/
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@State(Scope.Benchmark)
@State(Scope.Thread)
@Warmup(iterations = 5, time = 1)
@Measurement(iterations = 5, time = 1)
@Fork(value = 3)

View File

@ -28,7 +28,7 @@ import java.util.concurrent.TimeUnit;
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@State(Scope.Benchmark)
@State(Scope.Thread)
@Warmup(iterations = 5, time = 1)
@Measurement(iterations = 5, time = 1)
@Fork(value = 3)

View File

@ -31,7 +31,7 @@ import java.util.concurrent.TimeUnit;
@Fork(value = 3)
@Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
@State(Scope.Benchmark)
@State(Scope.Thread)
public class StringSubstring {
public String s = new String("An arbitrary string that happened to be of length 52");

View File

@ -42,7 +42,7 @@ import static java.util.FormatProcessor.FMT;
*/
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@State(Scope.Benchmark)
@State(Scope.Thread)
@Warmup(iterations = 5, time = 1)
@Measurement(iterations = 5, time = 1)
@Fork(value = 3, jvmArgsAppend = "--enable-preview")

View File

@ -49,7 +49,7 @@ import java.util.concurrent.TimeUnit;
@Warmup(iterations = 3, time = 2)
@Measurement(iterations = 6, time = 1)
@Fork(1)
@State(Scope.Benchmark)
@State(Scope.Thread)
public class MethodTypeDescFactories {
private static final ClassDesc DUMMY_CD = ClassDesc.of("Dummy_invalid");

View File

@ -47,7 +47,7 @@ import static java.lang.constant.ConstantDescs.*;
@Warmup(iterations = 3, time = 2)
@Measurement(iterations = 6, time = 1)
@Fork(1)
@State(Scope.Benchmark)
@State(Scope.Thread)
public class ReferenceClassDescResolve {
private static final MethodHandles.Lookup LOOKUP = MethodHandles.lookup();
private static final ClassDesc CLASS_OR_INTERFACE = CD_String;

View File

@ -42,7 +42,7 @@ import java.util.concurrent.TimeUnit;
*/
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@State(Scope.Benchmark)
@State(Scope.Thread)
@Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
@Fork(3)

View File

@ -42,7 +42,7 @@ import java.util.concurrent.TimeUnit;
*/
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@State(Scope.Benchmark)
@State(Scope.Thread)
@Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 5, time = 2, timeUnit = TimeUnit.SECONDS)
@Fork(3)

View File

@ -42,7 +42,7 @@ import java.util.concurrent.TimeUnit;
*/
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@State(Scope.Benchmark)
@State(Scope.Thread)
@Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
@Fork(3)

View File

@ -41,7 +41,7 @@ import java.util.concurrent.TimeUnit;
*/
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@State(Scope.Benchmark)
@State(Scope.Thread)
@Warmup(iterations = 10, time = 1, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
@Fork(3)

View File

@ -41,7 +41,7 @@ import java.util.concurrent.TimeUnit;
*/
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@State(Scope.Benchmark)
@State(Scope.Thread)
@Warmup(iterations = 10, time = 1, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
@Fork(3)

View File

@ -41,7 +41,7 @@ import java.util.concurrent.TimeUnit;
*/
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@State(Scope.Benchmark)
@State(Scope.Thread)
@Warmup(iterations = 10, time = 1, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
@Fork(3)

View File

@ -41,7 +41,7 @@ import java.util.concurrent.TimeUnit;
*/
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@State(Scope.Benchmark)
@State(Scope.Thread)
@Warmup(iterations = 10, time = 1, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
@Fork(3)

View File

@ -41,7 +41,7 @@ import java.util.concurrent.TimeUnit;
*/
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@State(Scope.Benchmark)
@State(Scope.Thread)
@Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
@Fork(3)

View File

@ -41,7 +41,7 @@ import java.util.concurrent.TimeUnit;
*/
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@State(Scope.Benchmark)
@State(Scope.Thread)
@Warmup(iterations = 10, time = 1, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
@Fork(3)

View File

@ -31,7 +31,7 @@ import java.util.concurrent.TimeUnit;
@Fork(value = 3, jvmArgsAppend = {"--add-exports", "java.base/sun.security.ssl=ALL-UNNAMED", "--add-opens", "java.base/sun.security.ssl=ALL-UNNAMED"})
@State(Scope.Benchmark)
@State(Scope.Thread)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
@BenchmarkMode(Mode.Throughput)
@Warmup(iterations = 5, time = 1)

View File

@ -58,7 +58,7 @@ import org.openjdk.jmh.infra.Blackhole;
@Warmup(iterations = 5, time = 1)
@Measurement(iterations = 5, time = 1)
@Fork(3)
@State(Scope.Benchmark)
@State(Scope.Thread)
public class GetYearBench {
private TimeZone UTC = TimeZone.getTimeZone("UTC");

View File

@ -50,7 +50,7 @@ import org.openjdk.jmh.annotations.Warmup;
@Warmup(iterations = 5, time = 1)
@Measurement(iterations = 5, time = 1)
@Fork(3)
@State(Scope.Benchmark)
@State(Scope.Thread)
public class InstantBench {
private Instant[] INSTANTS;

View File

@ -36,7 +36,7 @@ import java.util.concurrent.TimeUnit;
@Warmup(iterations = 5, time = 1)
@Measurement(iterations = 5, time = 1)
@Fork(3)
@State(Scope.Benchmark)
@State(Scope.Thread)
public class DateTimeFormatterWithPaddingBench {
private static final DateTimeFormatter FORMATTER_WITH_PADDING = new DateTimeFormatterBuilder()

View File

@ -34,7 +34,7 @@ import java.util.concurrent.TimeUnit;
* initializers. Use parallel GC and set initial heap size to avoid
* GC during runs.
*/
@State(Scope.Benchmark)
@State(Scope.Thread)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@Fork(value = 3, jvmArgsAppend = { "-verbose:gc", "-XX:+UseParallelGC", "-Xms4g", "-Xmx4g", "-Xint" })
@Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)

View File

@ -40,7 +40,7 @@ import java.util.concurrent.TimeUnit;
*/
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@State(Scope.Benchmark)
@State(Scope.Thread)
@Warmup(iterations = 4, time = 2)
@Measurement(iterations = 4, time = 2)
@Fork(value = 3)

View File

@ -29,7 +29,7 @@ import org.openjdk.jmh.annotations.*;
@BenchmarkMode(Mode.Throughput)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@State(Scope.Benchmark)
@State(Scope.Thread)
public class TestAdler32 {
private Adler32 adler32;

View File

@ -29,7 +29,7 @@ import org.openjdk.jmh.annotations.*;
@BenchmarkMode(Mode.Throughput)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@State(Scope.Benchmark)
@State(Scope.Thread)
@Warmup(iterations = 4, time = 2)
@Measurement(iterations = 4, time = 2)
@Fork(value = 3)

View File

@ -29,7 +29,7 @@ import org.openjdk.jmh.annotations.*;
@BenchmarkMode(Mode.Throughput)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@State(Scope.Benchmark)
@State(Scope.Thread)
@Warmup(iterations = 4, time = 2)
@Measurement(iterations = 4, time = 2)
@Fork(value = 3)

View File

@ -47,7 +47,7 @@ import java.util.regex.Pattern;
@Fork(2)
@Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
@State(Scope.Benchmark)
@State(Scope.Thread)
public class Exponential {
/** Run length of non-matching consecutive whitespace chars. */
@Param({"16", "128", "1024"})

View File

@ -47,7 +47,7 @@ import java.util.regex.Pattern;
@Fork(1)
@Warmup(iterations = 2, time = 3, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 4, time = 3, timeUnit = TimeUnit.SECONDS)
@State(Scope.Benchmark)
@State(Scope.Thread)
public class Primality {
/** Number to be primality tested. */
@Param({"16", "17", /* "256", "257", */ "4096", "4099"})

View File

@ -78,7 +78,7 @@ import java.util.regex.Pattern;
@Fork(2)
@Warmup(iterations = 5, time = 3, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 5, time = 3, timeUnit = TimeUnit.SECONDS)
@State(Scope.Benchmark)
@State(Scope.Thread)
public class Trim {
/** Run length of non-matching consecutive whitespace chars. */
@Param({"16", "256", "4096"})

View File

@ -35,7 +35,7 @@ import java.util.concurrent.TimeUnit;
@Fork(value = 3, jvmArgsAppend = {"-Xms1g", "-Xmx1g"})
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@State(Scope.Benchmark)
@State(Scope.Thread)
public class AESReinit {
private Cipher cipher;

View File

@ -29,7 +29,7 @@ import org.openjdk.jmh.annotations.*;
@BenchmarkMode(Mode.Throughput)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@State(Scope.Benchmark)
@State(Scope.Thread)
@Warmup(iterations = 3, time = 1)
@Measurement(iterations = 5, time = 1)
@Fork(value = 1, jvmArgsPrepend = {"--add-modules=jdk.incubator.vector"})

View File

@ -41,7 +41,7 @@ import org.openjdk.jmh.infra.Blackhole;
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@State(Scope.Benchmark)
@State(Scope.Thread)
@Fork(value = 3)
@Measurement(iterations = 5, time = 1000, timeUnit = TimeUnit.MILLISECONDS)
@Warmup(iterations = 5, time = 1000, timeUnit = TimeUnit.MILLISECONDS)

View File

@ -28,7 +28,7 @@ import org.openjdk.jmh.infra.Blackhole;
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@State(Scope.Benchmark)
@State(Scope.Thread)
@Fork(value = 3, jvmArgsAppend = "-XX:-UseSuperWord")
@Warmup(time = 1, timeUnit = TimeUnit.SECONDS)
@Measurement(time = 1, timeUnit = TimeUnit.SECONDS)

View File

@ -28,16 +28,16 @@ import java.util.concurrent.TimeUnit;
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@State(Scope.Benchmark)
@State(Scope.Thread)
@Warmup(iterations = 5, time = 1)
@Measurement(iterations = 5, time = 1)
@Fork(value = 1, jvmArgsAppend = {"-XX:-UseSuperWord"})
public class ConvertF2I {
static final int LENGTH = 1000;
static final int[] INT_ARRAY = new int[LENGTH];
static final long[] LONG_ARRAY = new long[LENGTH];
static final float[] FLOAT_ARRAY = new float[LENGTH];
static final double[] DOUBLE_ARRAY = new double[LENGTH];
int[] intArray = new int[LENGTH];
long[] longArray = new long[LENGTH];
float[] floatArray = new float[LENGTH];
double[] doubleArray = new double[LENGTH];
float f;
double d;
@ -64,28 +64,28 @@ public class ConvertF2I {
@Benchmark
public void f2iArray() {
for (int i = 0; i < LENGTH; i++) {
INT_ARRAY[i] = (int)FLOAT_ARRAY[i];
intArray[i] = (int)floatArray[i];
}
}
@Benchmark
public void f2lArray() {
for (int i = 0; i < LENGTH; i++) {
LONG_ARRAY[i] = (long)FLOAT_ARRAY[i];
longArray[i] = (long)floatArray[i];
}
}
@Benchmark
public void d2iArray() {
for (int i = 0; i < LENGTH; i++) {
INT_ARRAY[i] = (int)DOUBLE_ARRAY[i];
intArray[i] = (int)doubleArray[i];
}
}
@Benchmark
public void d2lArray() {
for (int i = 0; i < LENGTH; i++) {
LONG_ARRAY[i] = (long)DOUBLE_ARRAY[i];
longArray[i] = (long)doubleArray[i];
}
}
}