aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElliot Barlas <elliotbarlas@gmail.com>2024-01-31 13:12:35 -0800
committerGitHub <noreply@github.com>2024-01-31 22:12:35 +0100
commita11e5a12470c8c5edad09622f3d23b660853798b (patch)
tree038387150b8638eacc5beb50dd26b4a2bd150a98
parente639e2a045371ab0be51404767a42f22f689cf2c (diff)
Use GraalVM native image for ebarlas submission. (#698)
-rwxr-xr-xcalculate_average_ebarlas.sh9
-rwxr-xr-xprepare_ebarlas.sh7
2 files changed, 13 insertions, 3 deletions
diff --git a/calculate_average_ebarlas.sh b/calculate_average_ebarlas.sh
index 2bd59d4..c73cb1a 100755
--- a/calculate_average_ebarlas.sh
+++ b/calculate_average_ebarlas.sh
@@ -15,5 +15,10 @@
# limitations under the License.
#
-JAVA_OPTS="--enable-preview"
-java $JAVA_OPTS --class-path target/average-1.0.0-SNAPSHOT.jar dev.morling.onebrc.CalculateAverage_ebarlas
+if [ -f target/CalculateAverage_ebarlas_image ]; then
+ echo "Picking up existing native image 'target/CalculateAverage_ebarlas_image', delete the file to select JVM mode." 1>&2
+ target/CalculateAverage_ebarlas_image
+else
+ echo "Choosing to run the app in JVM mode as no native image was found, use prepare_ebarlas.sh to generate." 1>&2
+ java --enable-preview --class-path target/average-1.0.0-SNAPSHOT.jar dev.morling.onebrc.CalculateAverage_ebarlas
+fi
diff --git a/prepare_ebarlas.sh b/prepare_ebarlas.sh
index f83a3ff..64b2bea 100755
--- a/prepare_ebarlas.sh
+++ b/prepare_ebarlas.sh
@@ -16,4 +16,9 @@
#
source "$HOME/.sdkman/bin/sdkman-init.sh"
-sdk use java 21.0.1-graal 1>&2
+sdk use java 21.0.2-graal 1>&2
+
+if [ ! -f target/CalculateAverage_ebarlas_image ]; then
+ NATIVE_IMAGE_OPTS="-H:+UnlockExperimentalVMOptions --initialize-at-build-time=dev.morling.onebrc.CalculateAverage_ebarlas --gc=epsilon -O3 -march=native -R:MaxHeapSize=128m -H:-GenLoopSafepoints --enable-preview"
+ native-image $NATIVE_IMAGE_OPTS -cp target/average-1.0.0-SNAPSHOT.jar -o target/CalculateAverage_ebarlas_image dev.morling.onebrc.CalculateAverage_ebarlas
+fi