GraalVM is a new open source project by Oracle which is trying to make Java VM an universal VM to run all the major languages. Before GraalVM, there were already few languages like Scala, Closure which targeted JVM as their runtime. This has been hugely successful for those languages. GraalVM takes this idea further and makes it easy to target JVM so that many more languages can coexist on JVM.
GraalVM is around from 2014 as a research project. It’s been used in production by Twitter from 2017. But for general public, it became production ready in latter half of 2019.
Enable Allow Access on Context
The below code shows how to do that
val context = Context.newBuilder().allowAllAccess(true).build()
Here we are using builder pattern of context to pass extra parameter. Using allowAllAccess method on context, we allow access to host environment.
Create a Scala Object
The below code creates a person object in Scala
case class Person(name:String, age:Int) val person = Person("John",20)
val result = context.eval("js","person.name() == 'John' && person.age() == 20").asBoolean()
You can access complete code on github.
Polyglot nature of GraalVM makes it very attractive to mix and match different languages on same VM. Ability to pass values between different languages makes it seamless to do different computation in different languages.