The official introduction

Oracle has recently opened source an experimental product, GraalVM, officially known as Universal GraalVM. It Bridges the gap between languages and allows us to do hybrid multilingual programming. On top of GraalVM, we can write Java, Python, Ruby, R, Scala, Kotlin, and even C and C++.

You may be wary of performance issues arising from interoperation between different languages. GraalVM says no, you can jump from one language to another and performance is not an issue. It is completely different from JRuby and Jython libraries in the JVM.

Seeing this, you have to understand that GraalVM may be more than just a toy, it can actually run large applications.

The example in the figure uses NodeJS, Java, and R to run a simple Web server using the Node platform express framework.

GraalVM supports image acceleration, similar to Ahead-time compilation for Android, which compiles programs into native binaries and speeds up the program launch process.

We see at least an order of magnitude faster performance. The issue of slow Spring startup is likely to be addressed first by GraalVM.

GraalVM can be built into different runtime environments. It is already built into Node, Java, Oracle, and MySQL products.

Download and install

Let’s experience the magic of GraalVM for ourselves.

First up on the download page, OMG offers both the community edition and the enterprise edition, so GraalVM is more than just a toy.

Oops, the community edition currently doesn’t support MAC, so you have to download it on github.

Enterprise version support MAC, good, can try, but download to register Oracle account, foreign website access is really slow. Patience! Patience! Patience!

After filling out a lengthy registration form, I was finally able to download it.

Switch to thunder, thunder fast, also fast a little, quickly reduced from 500K /s to 50K /s, back to 100K /s. Let’s have a cup of coffee.

Finally finished, took about an hour.

The purple commands in the figure are the more specialized commands provided by GraalVM

  1. Js javascript command line running on top of GraalVM
  2. Node is just like a regular node except that it runs on GraalVM
  3. Java is just like regular Java, except that it runs on GraalVM
  4. Lli runs the LLVM bytecode executor on top of GraalVM, where C and C++ code is compiled into LLVM bytecode and then run through it
  5. Native – Image precompiled program files generate fast binaries that are used to speed up startup programs
  6. Support for other languages like Python, Ruby, and R is installed through GU

Since the small editor cannot climb the wall at this point, we have to abandon the Ruby and Python installation.

Version information

You can see that all of these commands have Graal words in their version information except node.

run

After precompilation with native image, a binary file will be generated, and the execution performance before and after precompilation is significantly improved by comparing the running time before and after precompilation. Native image takes a long time because it requires a lot of code static analysis, which takes about 1 minute.

C needs to compile the LLVM bytecode program hello. BC before lLI commands can be executed.

Javascript interpreter, global object Console, Math, Date.

Surprisingly, NPM can install third-party packages directly, and GraalVM provides nodes that work just fine. NPM is also built into GraalVM.

What pain points have been addressed

GraalVM’s hybrid multilingual programming solves the following common problems for developers

  1. I don’t have the language in that library. I have to masturbate myself
  2. That language is perfect for my problem, but IT doesn’t work in my environment
  3. This problem has been solved by my language, but my language is too slow

By using the Polyglot API, GraalVM gives developers true language-level freedom.

How Polyglot works

GraalVM provides a way to transfer values seamlessly between languages without the need for serialization and deserialization of other virtual machines. This ensures continued high performance across languages.

GraalVM has developed the “Cross-language Interoperability Protocol”, a special interface protocol that is implemented by every language running on GraalVM to ensure interoperability across languages. Languages can transfer values efficiently without having to know each other. The protocol is still evolving and will support more features in the future.

Weakened main language

GraalVM developed an experimental launcher called “Polyglot”. There is no concept of a main language in Polyglot. Each language is equal and you can use Polyglot to run programs written in any language without requiring a separate launcher for each of the previous languages. Polyglot automatically classifies languages by file extensions.

Shell

GraalVM also developed a dynamic language Shell that uses JS by default and can use commands to switch to any other language for interpretation.

The last

Unfortunately, GraalVM is an Oracle product and would have been a perfect product if it had been more conscientious like Google.

Let’s take a closer look at GraalVM by following the public account “Code Hole”.