Skip to content

Commit

Permalink
ini
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergej Isbrecht committed Apr 19, 2023
0 parents commit 53921b4
Show file tree
Hide file tree
Showing 20 changed files with 1,925 additions and 0 deletions.
156 changes: 156 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
### Maven template
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
# https://github.com/takari/maven-wrapper#usage-without-binary-jar
.mvn/wrapper/maven-wrapper.jar

# Eclipse m2e generated files
# Eclipse Core
.project
# JDT-specific (Eclipse Java Development Tools)
.classpath

### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# AWS User-specific
.idea/**/aws.xml

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# SonarLint plugin
.idea/sonarlint/

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

### Gradle template
.gradle
**/build/
!src/**/build/

# Ignore Gradle GUI config
gradle-app.setting

# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
!gradle-wrapper.jar

# Avoid ignore Gradle wrappper properties
!gradle-wrapper.properties

# Cache of project
.gradletasknamecache

# Eclipse Gradle plugin generated files
# Eclipse Core
.project
# JDT-specific (Eclipse Java Development Tools)
.classpath

### Android template
# Gradle files
.gradle/
build/

# Local configuration file (sdk path, etc)
local.properties

# Log/OS Files
*.log

# Android Studio generated files and folders
captures/
.externalNativeBuild/
.cxx/
*.apk
output.json

# IntelliJ
*.iml
.idea/
misc.xml
deploymentTargetDropDown.xml
render.experimental.xml

# Keystore files
*.jks
*.keystore

# Google Services (e.g. APIs or Firebase)
google-services.json

# Android Profiling
*.hprof

93 changes: 93 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# StackTrace

## Setup

Set the GraalVM JDK17 path in `gradle.properties`

```
org.gradle.java.installations.paths=/home/user/graalvm-community-java17-linux-amd64-dev/graalvm-community-openjdk-17.0.7+4.1
```

When using a different JDK version, you might need to change the `build.gradle.kts` file

```
languageVersion.set(JavaLanguageVersion.of(17))
```

to a version of your liking.

If nothing is set, an error will be shown

```
* What went wrong:
Execution failed for task ':compileJava'.
> Error while evaluating property 'javaCompiler' of task ':compileJava'.
> Failed to calculate the value of task ':compileJava' property 'javaCompiler'.
> No matching toolchains found for requested specification: {languageVersion=17, vendor=any, implementation=vendor-specific}.
> No locally installed toolchains match (see https://docs.gradle.org/8.0/userguide/toolchains.html#sec:auto_detection) and toolchain auto-provisioning is not enabled (see https://docs.gradle.org/8.0/userguide/toolchains.html#sec:auto_detection).
```

## Run

### OpenJDK

```
./gradlew run --no-daemon --rerun-tasks
```

### native-image

```
./gradlew nativeCompile --no-daemon --rerun-tasks --info
```

and

```
./build/native/nativeCompile/bench_amd64
```

## Result

Run on amd64 (5.4.0-146-generic)

```
GraalVM CE 23.1.0-dev-20230414_0206
https://github.com/graalvm/graalvm-ce-dev-builds/releases/tag/23.1.0-dev-20230414_0206
graalvm-community-java17-linux-amd64-dev.tar.gz
```

### OpenJDK 17 hotspot C2

```
Benchmark Mode Cnt Score Error Units
FromStringBench.valueOf avgt 5 4.729 ± 0.234 ns/op
FromStringBench.valueOf:·gc.alloc.rate avgt 5 ≈ 10⁻⁴ MB/sec
FromStringBench.valueOf:·gc.alloc.rate.norm avgt 5 ≈ 10⁻⁷ B/op
FromStringBench.valueOf:·gc.count avgt 5 ≈ 0 counts
FromStringBench.valueOfException avgt 5 1195.178 ± 65.872 ns/op
FromStringBench.valueOfException:·gc.alloc.rate avgt 5 766.129 ± 41.666 MB/sec
FromStringBench.valueOfException:·gc.alloc.rate.norm avgt 5 960.000 ± 0.001 B/op
FromStringBench.valueOfException:·gc.count avgt 5 129.000 counts
FromStringBench.valueOfException:·gc.time avgt 5 84.000 ms
```

### native-image JDK17

```
# JMH version: 1.36
# VM version: JDK 17.0.7, Substrate VM, 17.0.7+4
```

```
Benchmark Mode Cnt Score Error Units
FromStringBench.valueOf avgt 5 7.475 ± 0.187 ns/op
FromStringBench.valueOf:·gc.alloc.rate avgt 5 ≈ 0 MB/sec
FromStringBench.valueOf:·gc.count avgt 5 ≈ 0 counts
FromStringBench.valueOfException avgt 5 2988.646 ± 23.550 ns/op
FromStringBench.valueOfException:·gc.alloc.rate avgt 5 ≈ 0 MB/sec
FromStringBench.valueOfException:·gc.count avgt 5 437.000 counts
FromStringBench.valueOfException:·gc.time avgt 5 898.000 ms
```

![flamegraph](./doc/flamegraph_valueOfException.png)
85 changes: 85 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
plugins {
java
application
id("com.github.johnrengelman.shadow") version "8.1.1"
id("org.graalvm.buildtools.native") version "0.9.21"
}

group = "io.sergejisbrecht"
version = "1.0-SNAPSHOT"

application {
mainClass.set("io.sergejisbrecht.HelloWorldOpenJdk")
}

repositories {
mavenCentral()
}

java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17

toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
// vendor.set(JvmVendorSpec.matching("GraalVM Community"))
}
}

dependencies {
implementation("org.openjdk.jmh:jmh-core:1.36")
annotationProcessor("org.openjdk.jmh:jmh-generator-annprocess:1.36")
}

tasks.withType<Zip> {
duplicatesStrategy = DuplicatesStrategy.INCLUDE
}

tasks.withType<Tar> {
duplicatesStrategy = DuplicatesStrategy.INCLUDE
}

graalvmNative {
binaries {
agent {
defaultMode.set("standard") // Default agent mode if one isn't specified using `-Pagent=mode_name`
enabled.set(false) // Enables the agent
}

this["main"].run {
this.useFatJar.set(true)

println("BUILD main")

imageName.set("bench_amd64")
verbose.set(true)

javaLauncher.set(javaToolchains.launcherFor {
languageVersion.set(JavaLanguageVersion.of(17))
// vendor.set(JvmVendorSpec.matching("GraalVM Community"))
})

mainClass.set("io.sergejisbrecht.HelloWorldNativeImage")

buildArgs.add("--verbose")
buildArgs.add("--no-fallback")
// buildArgs.add("-g")
// buildArgs.add("-H:-DeleteLocalSymbols")
buildArgs.add("-H:IncludeResources=.*/BenchmarkList")
buildArgs.add("-H:Log=registerResource:verbose")
buildArgs.add("--initialize-at-build-time=org.openjdk.jmh.infra,org.openjdk.jmh.util.Utils,org.openjdk.jmh.runner.InfraControl,org.openjdk.jmh.runner.InfraControlL0,org.openjdk.jmh.runner.InfraControlL1,org.openjdk.jmh.runner.InfraControlL2,org.openjdk.jmh.runner.InfraControlL3,org.openjdk.jmh.runner.InfraControlL4")
buildArgs.add("-H:-SpawnIsolates")
buildArgs.add("-H:+UseSerialGC")
buildArgs.add("-H:InitialCollectionPolicy=BySpaceAndTime")
// buildArgs.add("-H:+SourceLevelDebug")
// buildArgs.add("-H:AlignedHeapChunkSize=2097152")
// buildArgs.add("--native-compiler-path=/usr/bin/gcc-10")
buildArgs.add("-H:AlignedHeapChunkSize=524288")
buildArgs.add("-H:+ReportExceptionStackTraces")
buildArgs.add("--enable-monitoring=all")
buildArgs.add("-J-Xmx20g")
buildArgs.add("-march=native")

}
}
}
Binary file added doc/flamegraph_valueOfException.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
org.gradle.java.installations.auto-download=false
org.gradle.java.installations.auto-detect=false
org.gradle.java.installations.paths=
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
5 changes: 5 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit 53921b4

Please sign in to comment.