Been trying GraalVM

Daestrum

Expert
Licensed User
Longtime User
I have been playing around with GraalVM, it's a (new)VM. (has all the normal tools compiler etc) but has some advantages.
It's still at an early stage and not all things function in windows as they do on Linux & MacOs.

Interaction between the supported languages is built in, so for example you can write a function in javascript, then call it from java. Or write a function in Python and call it from c++.

The current supported languages (not all on Windows) are JavaScript, Python, Ruby, R, JVM-based languages like Java, Scala, Groovy, Kotlin, Clojure, and LLVM-based languages such as C and C++.

It also has the ability to compile to a native image for the OS it will run on.

It looks good so far, not had a problem telling B4J IDE to use the Graalvm compiler (probably as it's really the oracle version 8-221 EE with tweaks).

They are working on the java 11 version.
 
Last edited:

Daestrum

Expert
Licensed User
Longtime User
Update:

After a good few hours setting it up for use on Ubuntu under WSL so I could try all the extra goodies, I must say I am quite impressed.

A simple java app (the usual helloworld type)

B4X:
public class testjava1{
     public static void main(String... args){
              System.out.println("Hello from GraalVM");
     }
}

Compiled fine and ran with the usual java testjava1

I then tried the native-image option, this bit really impressed me.

Seeing as normally packaging an app involves adding in a jvm to run it. The output code actually had a file size of just over 2MB, and ran directly from bash.

I will keep tabs on this as to when the Windows side gets finished as this seems the way to go.
 

Daestrum

Expert
Licensed User
Longtime User
Some of the output showing jvm vs native-image run times.

The simple java code I used
B4X:
import org.graalvm.polyglot.*;
public class javapoly{
 public static void main(String[] args){
  System.out.println("Hello");
  Context js = Context.create("js");
  System.out.println(js);
  js.eval("js","print('hello from javascript inside java');"); 
  js.close();
 }
}
Note: The compile times may be affected by the fact ubuntu is running under windows, so both are competing for system memory.

This one is the result of running the native image. (Compile time was > 150 seconds)
B4X:
xxxx@DESKTOP-MUQINOJ:/home$ time ./javapoly
Hello
org.graalvm.polyglot.Context@7f9717c13d90
hello from javascript inside java
real    0m0.035s
user    0m0.000s
sys     0m0.016s

This is the same java program running in the JVM ( Compile time ~ 1 second)
B4X:
xxxx@DESKTOP-MUQINOJ:/home$ time $graalvm/java javapoly
Hello
org.graalvm.polyglot.Context@4157f54e
hello from javascript inside java
real    0m2.741s
user    0m1.469s
sys     0m0.750s
xxxx@DESKTOP-MUQINOJ:/home$
 
Top