changeset 374:7658cbdf76a4

JCStress benchmarks.
author shade
date Wed, 01 Mar 2017 19:50:31 +0100
parents 325e0f2bcdef
children 3dfd10339436
files jcstress-benchmarks/pom.xml jcstress-benchmarks/src/main/java/org/openjdk/jcstress/SampleTest.java jcstress-benchmarks/src/main/java/org/openjdk/jcstress/SampleTestBench.java pom.xml
diffstat 4 files changed, 310 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jcstress-benchmarks/pom.xml	Wed Mar 01 19:50:31 2017 +0100
@@ -0,0 +1,172 @@
+<!--
+Copyright (c) 2017, Red Hat Inc. All rights reserved.
+DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+
+This code is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License version 2 only, as
+published by the Free Software Foundation.  Oracle designates this
+particular file as subject to the "Classpath" exception as provided
+by Oracle in the LICENSE file that accompanied this code.
+
+This code is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+version 2 for more details (a copy is included in the LICENSE file that
+accompanied this code).
+
+You should have received a copy of the GNU General Public License version
+2 along with this work; if not, write to the Free Software Foundation,
+Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+
+Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+or visit www.oracle.com if you need additional information or have any
+questions.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+      <artifactId>jcstress-parent</artifactId>
+      <groupId>org.openjdk.jcstress</groupId>
+      <version>0.2-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>jcstress-benchmarks</artifactId>
+    <packaging>jar</packaging>
+
+    <name>JCStress Benchmarks</name>
+
+    <prerequisites>
+        <maven>3.0</maven>
+    </prerequisites>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.openjdk.jmh</groupId>
+            <artifactId>jmh-core</artifactId>
+            <version>${jmh.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.openjdk.jmh</groupId>
+            <artifactId>jmh-generator-annprocess</artifactId>
+            <version>${jmh.version}</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.openjdk.jcstress</groupId>
+            <artifactId>jcstress-core</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+    </dependencies>
+
+    <properties>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+
+        <!--
+            JMH version to use with this project.
+          -->
+        <jmh.version>1.17.5</jmh.version>
+
+        <!--
+            Java source/target to use for compilation.
+          -->
+        <javac.target>1.8</javac.target>
+
+        <!--
+            Name of the benchmark Uber-JAR to generate.
+          -->
+        <uberjar.name>benchmarks</uberjar.name>
+    </properties>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>3.1</version>
+                <configuration>
+                    <compilerVersion>${javac.target}</compilerVersion>
+                    <source>${javac.target}</source>
+                    <target>${javac.target}</target>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-shade-plugin</artifactId>
+                <version>2.2</version>
+                <executions>
+                    <execution>
+                        <phase>package</phase>
+                        <goals>
+                            <goal>shade</goal>
+                        </goals>
+                        <configuration>
+                            <finalName>${uberjar.name}</finalName>
+                            <transformers>
+                                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
+                                    <mainClass>org.openjdk.jmh.Main</mainClass>
+                                </transformer>
+                            </transformers>
+                            <filters>
+                                <filter>
+                                    <!--
+                                        Shading signed JARs will fail without this.
+                                        http://stackoverflow.com/questions/999489/invalid-signature-file-when-attempting-to-run-a-jar
+                                    -->
+                                    <artifact>*:*</artifact>
+                                    <excludes>
+                                        <exclude>META-INF/*.SF</exclude>
+                                        <exclude>META-INF/*.DSA</exclude>
+                                        <exclude>META-INF/*.RSA</exclude>
+                                    </excludes>
+                                </filter>
+                            </filters>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+        <pluginManagement>
+            <plugins>
+                <plugin>
+                    <artifactId>maven-clean-plugin</artifactId>
+                    <version>2.5</version>
+                </plugin>
+                <plugin>
+                    <artifactId>maven-deploy-plugin</artifactId>
+                    <version>2.8.1</version>
+                </plugin>
+                <plugin>
+                    <artifactId>maven-install-plugin</artifactId>
+                    <version>2.5.1</version>
+                </plugin>
+                <plugin>
+                    <artifactId>maven-jar-plugin</artifactId>
+                    <version>2.4</version>
+                </plugin>
+                <plugin>
+                    <artifactId>maven-javadoc-plugin</artifactId>
+                    <version>2.9.1</version>
+                </plugin>
+                <plugin>
+                    <artifactId>maven-resources-plugin</artifactId>
+                    <version>2.6</version>
+                </plugin>
+                <plugin>
+                    <artifactId>maven-site-plugin</artifactId>
+                    <version>3.3</version>
+                </plugin>
+                <plugin>
+                    <artifactId>maven-source-plugin</artifactId>
+                    <version>2.2.1</version>
+                </plugin>
+                <plugin>
+                    <artifactId>maven-surefire-plugin</artifactId>
+                    <version>2.17</version>
+                </plugin>
+            </plugins>
+        </pluginManagement>
+    </build>
+
+</project>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jcstress-benchmarks/src/main/java/org/openjdk/jcstress/SampleTest.java	Wed Mar 01 19:50:31 2017 +0100
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2017, Red Hat Inc. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package org.openjdk.jcstress;
+
+import org.openjdk.jcstress.annotations.*;
+import org.openjdk.jcstress.infra.results.IntResult4;
+
+import static org.openjdk.jcstress.annotations.Expect.ACCEPTABLE;
+
+@JCStressTest
+@Description("Sample test")
+@Outcome(id = ".*", expect = ACCEPTABLE,  desc = "All acceptable")
+@State
+public class SampleTest {
+
+    @sun.misc.Contended
+    @jdk.internal.vm.annotation.Contended
+    int a;
+
+    @sun.misc.Contended
+    @jdk.internal.vm.annotation.Contended
+    int b;
+
+    @Actor
+    public void actor1(IntResult4 r) {
+        r.r1 = b;
+    }
+
+    @Actor
+    public void actor2(IntResult4 r) {
+        r.r2 = a;
+    }
+
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jcstress-benchmarks/src/main/java/org/openjdk/jcstress/SampleTestBench.java	Wed Mar 01 19:50:31 2017 +0100
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2017, Red Hat Inc. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package org.openjdk.jcstress;
+
+import org.openjdk.jmh.annotations.State;
+import org.openjdk.jcstress.infra.TestInfo;
+import org.openjdk.jcstress.infra.collectors.TestResultCollector;
+import org.openjdk.jcstress.infra.grading.ConsoleReportPrinter;
+import org.openjdk.jcstress.infra.runners.Runner;
+import org.openjdk.jcstress.infra.runners.TestConfig;
+import org.openjdk.jmh.annotations.*;
+
+import java.io.PrintWriter;
+import java.lang.reflect.Constructor;
+import java.util.Collections;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+@State(Scope.Thread)
+public class SampleTestBench {
+
+    private Runner<?> o;
+    private ExecutorService pool;
+
+    @Setup
+    public void setup() throws Throwable {
+        Options opts = new Options(new String[]{"-v", "-iters", "1", "-time", "5000", "-deoptRatio", "1000"});
+        opts.parse();
+        PrintWriter pw = new PrintWriter(System.out, true);
+        ConsoleReportPrinter sink = new ConsoleReportPrinter(opts, pw, 1, 1);
+
+        String testName = SampleTest.class.getCanonicalName();
+        String runnerName = SampleTest_jcstress.class.getCanonicalName();
+
+        TestInfo ti = new TestInfo(testName, runnerName, "", 2, false);
+        TestConfig cfg = new TestConfig(opts, ti, TestConfig.RunMode.EMBEDDED, 1, Collections.emptyList());
+
+        pool = Executors.newCachedThreadPool();
+
+        Class<?> aClass = Class.forName(runnerName);
+        Constructor<?> cnstr = aClass.getConstructor(TestConfig.class, TestResultCollector.class, ExecutorService.class);
+        o = (Runner<?>) cnstr.newInstance(cfg, sink, pool);
+    }
+
+    @TearDown
+    public void tearDown() {
+        pool.shutdown();
+    }
+
+    @Benchmark
+    @BenchmarkMode(Mode.SingleShotTime)
+    public void testMethod() throws Throwable {
+        o.run();
+    }
+
+}
--- a/pom.xml	Wed Mar 01 12:39:57 2017 +0100
+++ b/pom.xml	Wed Mar 01 19:50:31 2017 +0100
@@ -246,6 +246,7 @@
         <module>jcstress-core</module>
         <module>jcstress-samples</module>
         <module>jcstress-java-test-archetype</module>
+        <module>jcstress-benchmarks</module>
         <module>tests-custom</module>
         <module>tests-chapter-0a</module>
         <module>tests-chapter-0b</module>
@@ -258,6 +259,6 @@
         <module>tests-chapter-1d</module>
         <module>tests-chapter-2b</module>
         <module>tests-all</module>
-    </modules>
+  </modules>
 
 </project>