Skip to content

Commit 3f80900

Browse files
committed
initial commit after refactoring from monorepo
0 parents  commit 3f80900

24 files changed

+1174
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
target

pom.xml

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
<!--
2+
Copyright (c) 2014, Oracle America, Inc.
3+
All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions are met:
7+
8+
* Redistributions of source code must retain the above copyright notice,
9+
this list of conditions and the following disclaimer.
10+
11+
* Redistributions in binary form must reproduce the above copyright
12+
notice, this list of conditions and the following disclaimer in the
13+
documentation and/or other materials provided with the distribution.
14+
15+
* Neither the name of Oracle nor the names of its contributors may be used
16+
to endorse or promote products derived from this software without
17+
specific prior written permission.
18+
19+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
29+
THE POSSIBILITY OF SUCH DAMAGE.
30+
-->
31+
32+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
33+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
34+
<modelVersion>4.0.0</modelVersion>
35+
36+
<groupId>pl.symentis.jvm.microbenchmarks</groupId>
37+
<artifactId>microbenchmarks</artifactId>
38+
<version>1.0</version>
39+
<packaging>jar</packaging>
40+
41+
<name>JMH benchmark sample: Java</name>
42+
43+
<dependencies>
44+
<dependency>
45+
<groupId>org.openjdk.jmh</groupId>
46+
<artifactId>jmh-core</artifactId>
47+
<version>${jmh.version}</version>
48+
</dependency>
49+
<dependency>
50+
<groupId>org.openjdk.jmh</groupId>
51+
<artifactId>jmh-generator-annprocess</artifactId>
52+
<version>${jmh.version}</version>
53+
<scope>provided</scope>
54+
</dependency>
55+
</dependencies>
56+
57+
<properties>
58+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
59+
<!-- JMH version to use with this project. -->
60+
<jmh.version>1.36</jmh.version>
61+
<!--Name of the benchmark Uber-JAR to generate. -->
62+
<uberjar.name>benchmarks</uberjar.name>
63+
</properties>
64+
65+
<build>
66+
<plugins>
67+
<plugin>
68+
<groupId>org.apache.maven.plugins</groupId>
69+
<artifactId>maven-compiler-plugin</artifactId>
70+
<version>3.11.0</version>
71+
<configuration>
72+
<source>17</source>
73+
<target>17</target>
74+
</configuration>
75+
</plugin>
76+
<plugin>
77+
<groupId>com.diffplug.spotless</groupId>
78+
<artifactId>spotless-maven-plugin</artifactId>
79+
<version>2.36.0</version>
80+
<configuration>
81+
<java>
82+
<palantirJavaFormat/>
83+
</java>
84+
</configuration>
85+
</plugin>
86+
<plugin>
87+
<groupId>org.apache.maven.plugins</groupId>
88+
<artifactId>maven-shade-plugin</artifactId>
89+
<version>3.2.1</version>
90+
<executions>
91+
<execution>
92+
<phase>package</phase>
93+
<goals>
94+
<goal>shade</goal>
95+
</goals>
96+
<configuration>
97+
<finalName>${uberjar.name}</finalName>
98+
<transformers>
99+
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
100+
<mainClass>org.openjdk.jmh.Main</mainClass>
101+
</transformer>
102+
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
103+
</transformers>
104+
<filters>
105+
<filter>
106+
<!--
107+
Shading signed JARs will fail without this.
108+
http://stackoverflow.com/questions/999489/invalid-signature-file-when-attempting-to-run-a-jar
109+
-->
110+
<artifact>*:*</artifact>
111+
<excludes>
112+
<exclude>META-INF/*.SF</exclude>
113+
<exclude>META-INF/*.DSA</exclude>
114+
<exclude>META-INF/*.RSA</exclude>
115+
</excludes>
116+
</filter>
117+
</filters>
118+
</configuration>
119+
</execution>
120+
</executions>
121+
</plugin>
122+
</plugins>
123+
<pluginManagement>
124+
<plugins>
125+
<plugin>
126+
<artifactId>maven-clean-plugin</artifactId>
127+
<version>2.5</version>
128+
</plugin>
129+
<plugin>
130+
<artifactId>maven-deploy-plugin</artifactId>
131+
<version>2.8.1</version>
132+
</plugin>
133+
<plugin>
134+
<artifactId>maven-install-plugin</artifactId>
135+
<version>2.5.1</version>
136+
</plugin>
137+
<plugin>
138+
<artifactId>maven-jar-plugin</artifactId>
139+
<version>2.4</version>
140+
</plugin>
141+
<plugin>
142+
<artifactId>maven-javadoc-plugin</artifactId>
143+
<version>2.9.1</version>
144+
</plugin>
145+
<plugin>
146+
<artifactId>maven-resources-plugin</artifactId>
147+
<version>2.6</version>
148+
</plugin>
149+
<plugin>
150+
<artifactId>maven-site-plugin</artifactId>
151+
<version>3.3</version>
152+
</plugin>
153+
<plugin>
154+
<artifactId>maven-source-plugin</artifactId>
155+
<version>2.2.1</version>
156+
</plugin>
157+
<plugin>
158+
<artifactId>maven-surefire-plugin</artifactId>
159+
<version>2.17</version>
160+
</plugin>
161+
</plugins>
162+
</pluginManagement>
163+
</build>
164+
165+
</project>

src/main/docker/Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM eclipse-temurin:17
2+
ADD https://github.com/async-profiler/async-profiler/releases/download/v2.10/async-profiler-2.10-linux-x64.tar.gz /opt/async-profiler.tar.gz
3+
ADD https://chriswhocodes.com/hsdis/hsdis-amd64.so /opt/java/openjdk/lib/server/
4+
RUN apt update && apt install --yes linux-tools-generic && \
5+
mkdir /opt/async-profiler && tar xzvf /opt/async-profiler.tar.gz --strip 1 -C /opt/async-profiler
6+
ENV JMH_PERF=/usr/lib/linux-tools/5.4.0-150-generic/perf LD_LIBRARY_PATH=/opt/async-profiler/lib/
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package pl.symentis.jvm.jit;
2+
3+
public class Fibonnaci {
4+
public static long fibonacci(int n) {
5+
if (n <= 1) {
6+
return n;
7+
} else {
8+
return fibonacci(n - 1) + fibonacci(n - 2);
9+
}
10+
}
11+
12+
public static void main(String[] args) {
13+
long time = System.currentTimeMillis();
14+
for (int i = 0; i < 200; i++) {
15+
fibonacci(32);
16+
}
17+
time = System.currentTimeMillis() - time;
18+
System.out.printf("time is %d\n", time);
19+
}
20+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package pl.symentis.jvm.jit;
2+
3+
public class FibonnaciIterative {
4+
public static long fibonacci(int n) {
5+
if (n <= 1) {
6+
return n;
7+
}
8+
int fib = 1;
9+
int prevFib = 1;
10+
11+
for (int i = 2; i < n; i++) {
12+
int temp = fib;
13+
fib += prevFib;
14+
prevFib = temp;
15+
}
16+
return fib;
17+
}
18+
19+
public static void main(String[] args) {
20+
long time = System.currentTimeMillis();
21+
for (int i = 0; i < 200; i++) {
22+
fibonacci(32);
23+
}
24+
time = System.currentTimeMillis() - time;
25+
System.out.printf("time is %d\n", time);
26+
}
27+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package pl.symentis.jvm.jit;
2+
3+
/**
4+
* java -XX:+UnlockDiagnosticVMOptions -XX:CompileCommand="print *.nullCheckFolding" -Xlog:jit+compilation=debug pl.symentis.jvm.jit.NullCheckFolding
5+
*/
6+
public class NullCheckFolding {
7+
8+
public static void assertNotNull(Object obj) {
9+
if (obj == null) {
10+
System.out.println(String.format("%s is null", obj));
11+
}
12+
}
13+
14+
public void nullCheckFolding() {
15+
assertNotNull(this);
16+
}
17+
18+
public static void main(String[] argv) {
19+
NullCheckFolding nullCheckFolding = new NullCheckFolding();
20+
for (int i = 0; i < 200000; i++) {
21+
nullCheckFolding.nullCheckFolding();
22+
}
23+
}
24+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package pl.symentis.jvm.jit;
2+
3+
public class UncommonTrap {
4+
5+
private static final int CHUNK_SIZE = 1000;
6+
7+
private static Object uncommonTrap(Object trap) {
8+
if (trap != null) {
9+
System.out.println("I am being trapped!");
10+
}
11+
return null;
12+
}
13+
14+
public static void main(String[] argv) {
15+
Object trap = null;
16+
for (int i = 0; i < 400; ++i) {
17+
for (int j = 0; j < CHUNK_SIZE; ++j) {
18+
uncommonTrap(trap);
19+
}
20+
if (i == 300) {
21+
trap = new Object();
22+
}
23+
}
24+
}
25+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package pl.symentis.jvm.jit;
2+
3+
public class UncommonTrapTypeProfile {
4+
5+
private static final int CHUNK_SIZE = 1000;
6+
7+
public static void main(String[] argv) {
8+
Calculate trap = new Sum();
9+
for (int i = 0; i < 400; ++i) {
10+
for (int j = 0; j < CHUNK_SIZE; ++j) {
11+
trap.calc(i, j);
12+
}
13+
if (i == 300) {
14+
trap = new Multiplay();
15+
}
16+
}
17+
}
18+
19+
interface Calculate {
20+
int calc(int i, int j);
21+
}
22+
23+
static class Sum implements Calculate {
24+
25+
@Override
26+
public int calc(int i, int j) {
27+
return i + j;
28+
}
29+
}
30+
31+
static class Multiplay implements Calculate {
32+
33+
@Override
34+
public int calc(int i, int j) {
35+
return i * j;
36+
}
37+
}
38+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package pl.symentis.jvm.microbenchmarks.autovector;
2+
3+
import java.util.Random;
4+
import org.openjdk.jmh.annotations.Benchmark;
5+
import org.openjdk.jmh.annotations.Fork;
6+
import org.openjdk.jmh.annotations.Level;
7+
import org.openjdk.jmh.annotations.Measurement;
8+
import org.openjdk.jmh.annotations.Param;
9+
import org.openjdk.jmh.annotations.Scope;
10+
import org.openjdk.jmh.annotations.Setup;
11+
import org.openjdk.jmh.annotations.State;
12+
import org.openjdk.jmh.annotations.Warmup;
13+
import org.openjdk.jmh.infra.Blackhole;
14+
15+
@Fork(value = 1)
16+
@Measurement(iterations = 1)
17+
@Warmup(iterations = 1)
18+
public class Autovectorization {
19+
@State(Scope.Benchmark)
20+
public static class Vectors {
21+
22+
@Param({"1000", "100000", "100000000"})
23+
public int streamSize = 100_000_000;
24+
25+
private double[] xs;
26+
private double[] ys;
27+
private double[] zs;
28+
29+
@Setup(Level.Iteration)
30+
public void setUp() {
31+
var random = new Random();
32+
this.xs = random.doubles(streamSize).toArray();
33+
ys = random.doubles(streamSize).toArray();
34+
zs = new double[streamSize];
35+
}
36+
}
37+
38+
@Benchmark
39+
public void autoVector(Vectors iv, Blackhole bh) {
40+
for (int i = 0; i < iv.streamSize; i++) {
41+
iv.zs[i] = ((iv.xs[i] * iv.ys[i]) + 1) * -1;
42+
}
43+
bh.consume(iv.zs);
44+
}
45+
46+
@Fork(jvmArgsAppend = {"-XX:-UseSuperWord"})
47+
@Benchmark
48+
public void noVector(Vectors iv, Blackhole bh) {
49+
for (int i = 0; i < iv.streamSize; i++) {
50+
iv.zs[i] = ((iv.xs[i] * iv.ys[i]) + 1) * -1;
51+
}
52+
bh.consume(iv.zs);
53+
}
54+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package pl.symentis.jvm.microbenchmarks.counters;
2+
3+
import java.util.concurrent.atomic.AtomicInteger;
4+
5+
public class AtomicCounter {
6+
private AtomicInteger counter = new AtomicInteger();
7+
8+
void inc() {
9+
counter.incrementAndGet();
10+
}
11+
12+
int value() {
13+
return counter.get();
14+
}
15+
}

0 commit comments

Comments
 (0)