Getting started with GraalVM for Scala

Oleg Šelajev
Jun 11, 2019 · 3 min read

Here’s how you can start using GraalVM for your Scala projects.

GraalVM distribution you obtained is a Java 8 SE compliant Java Virtual Machine (based on OpenJDK 1.8.0_212).

It means that you can use the java command and run Scala applications as you normally would:

Or if you have a jar file that you’d like to run, you can run it:

Of course, you can also set GraalVM as the default Java on your machine, and add it to the path, for example, I have the following lines in the ~/.bashrc file (on macOS make GRAALVM_HOME point to graalvm/Contents/Home like below, on Linux there’s no Contents/Home)

After that whenever you run java you’ll get the one from the GraalVM distribution.

Using GraalVM with sbt

Now, if you use sbt for building your project, you can specify which java should be used on the command line with the-java-home argument

Let’s create a sample sbt project you can try it on:

Then in the example directory create the application file Hello.scala:

Start sbt with the -java-home pointing to the GRAALVM_HOME, execute the run command to run our sample code:

You can see that the code is running using the provided Java. So you can use GraalVM without placing it on the PATH.

GraalVM shows great performance results for Scala projects; Twitter is using the GraalVM compiler for their microservices; GraalVM can speed up Scala compilation too (because scalac is a Scala program and runs faster on GraalVM), and we know that GraalVM performs really well on the benchmarks too:

Image for post
Image for post
Sample Renaissance benchmark measurements showing performance of multiple JVM implementations

Give it a try, see what performance impact GraalVM shows on your code. If there are any issues or feedback, we’d love to hear about it. The GitHub repository is probably the best place to leave such feedback: oracle/graal; and if you happen to have a success story or any questions, please tell us too: twitter.com/graalvm.

graalvm

GraalVM team blog - https://www.graalvm.org

Oleg Šelajev

Written by

Developer advocate for GraalVM at OracleLabs. VirtualJUG organizer. Became Java Champion in 2017. Likes programming languages, compilers, performance, chess

graalvm

graalvm

GraalVM team blog - https://www.graalvm.org

Oleg Šelajev

Written by

Developer advocate for GraalVM at OracleLabs. VirtualJUG organizer. Became Java Champion in 2017. Likes programming languages, compilers, performance, chess

graalvm

graalvm

GraalVM team blog - https://www.graalvm.org

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store