aboutsummaryrefslogtreecommitdiff
path: root/java9/src/jmh/java/io/perfmark/java9/VarHandleMarkHolderBenchmarkTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'java9/src/jmh/java/io/perfmark/java9/VarHandleMarkHolderBenchmarkTest.java')
-rw-r--r--java9/src/jmh/java/io/perfmark/java9/VarHandleMarkHolderBenchmarkTest.java85
1 files changed, 85 insertions, 0 deletions
diff --git a/java9/src/jmh/java/io/perfmark/java9/VarHandleMarkHolderBenchmarkTest.java b/java9/src/jmh/java/io/perfmark/java9/VarHandleMarkHolderBenchmarkTest.java
new file mode 100644
index 0000000..b6162fe
--- /dev/null
+++ b/java9/src/jmh/java/io/perfmark/java9/VarHandleMarkHolderBenchmarkTest.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2021 Carl Mastrangelo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.perfmark.java9;
+
+import static java.util.List.of;
+
+import io.perfmark.impl.MarkHolder;
+import io.perfmark.testing.GarbageCollector;
+import io.perfmark.testing.MarkHolderBenchmark;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+import org.junit.runners.Parameterized;
+import org.openjdk.jmh.annotations.Scope;
+import org.openjdk.jmh.annotations.State;
+import org.openjdk.jmh.runner.Runner;
+import org.openjdk.jmh.runner.options.Options;
+import org.openjdk.jmh.runner.options.OptionsBuilder;
+import org.openjdk.jmh.runner.options.TimeValue;
+
+@RunWith(Parameterized.class)
+public class VarHandleMarkHolderBenchmarkTest {
+
+ @Parameterized.Parameter(0)
+ public GarbageCollector gc;
+
+ @Parameterized.Parameters
+ public static Collection<Object[]> args() {
+ List<Object[]> cases = new ArrayList<>();
+ for (GarbageCollector gc : GarbageCollector.values()) {
+ if (gc != GarbageCollector.CMS) {
+ continue;
+ }
+ cases.add(List.of(gc).toArray(new Object[0]));
+ }
+
+ return List.copyOf(cases);
+ }
+
+ @Test
+ public void markHolderBenchmark() throws Exception {
+ List<String> jvmArgs = new ArrayList<>();
+ jvmArgs.add("-da");
+ jvmArgs.addAll(gc.jvmArgs());
+ Options options = new OptionsBuilder()
+ .include(VarHandleMarkHolderBenchmark.class.getCanonicalName())
+ .measurementIterations(10)
+ .warmupIterations(10)
+ .forks(1)
+ .warmupTime(TimeValue.seconds(1))
+ .measurementTime(TimeValue.seconds(1))
+ .param("GC", gc.name())
+ .shouldFailOnError(true)
+ // This is necessary to run in the IDE, otherwise it would inherit the VM args.
+ .jvmArgs(jvmArgs.toArray(new String[0]))
+ .build();
+
+ new Runner(options).run();
+ }
+
+ @State(Scope.Thread)
+ public static class VarHandleMarkHolderBenchmark extends MarkHolderBenchmark {
+ @Override
+ public MarkHolder getMarkHolder() {
+ return new VarHandleMarkHolder(16384);
+ }
+ }
+}