Getting started with GraalVM

Posted May 29, 20205 min read

GraalVM provides a comprehensive ecosystem that supports multiple languages (Java and other JVM-based languages, JavaScript, Ruby, Python, R, WebAssembly, C/C ++ and other LLVM-based languages) and is deployed in different Run them in the program(OpenJDK, Node.js, Oracle database or standalone). This page outlines the different solutions GraalVM can bring to your application. Some general GraalVM features that may be missing on this page are fully summarized and disclosed in GraalVM Top 10 Things to Do Blog Article .

For Java programs

For existing Java applications, GraalVM can provide benefits by running them faster, providing extensibility through a scripting language, or creating pre-compiled native images.

Run Java faster

GraalVM can run in the context of OpenJDK, which makes Java applications run faster with new just-in-time compilation technology. GraalVM is responsible for compiling Java bytecode into machine code. Especially for other JVM-based languages (such as Scala), this configuration can achieve benefits, such as the experience of running GraalVM in a production environment.

GraalVM's compiler provides performance advantages for highly abstract programs due to its ability to delete expensive object allocations in many cases. You can find detailed information and try examples in this research paper. Better inlining and more aggressive speculation optimization can bring more benefits to complex and long-running applications, see Stream API example.

Whether GraalVM differs in performance depends on the specific workload. We are interested in obtaining any benchmark results that can help us achieve GraalVM faster.

Make your application extensible

GraalVM supports running JavaScript, R, Python, Ruby, LLVM IR and Web assemblies in the context of Java applications. It provides the ability to expose Java data structures to those languages using fine-grained host access filters. Integration is language-independent, that is, JavaScript integration can also be used later to execute any other GraalVM-based language. The proxy mechanism allows dynamic objects to be simulated from Java data structures and exposed to embedded scripts. Check out the instructions on how to make your JVM-based application extend with GraalVM.

Create a native image

Running applications in the Java VM will cause problems with startup and occupancy costs. GraalVM has the function of creating native images for existing JVM-based applications. The image generation process uses static analysis to find any code accessible by the main Java method, and then performs a full ahead of time(AOT) compilation. The generated native binary file contains the entire program in the form of machine code for immediate execution. It can be linked with other native programs, and optionally includes the GraalVM compiler to provide complementary just-in-time(JIT) compilation support to run any GraalVM-based language with high performance. For higher performance, you can use the optimization of the configuration file collected in the previous run of the application to build a native image. See here an example of how to build a local image.

For Node.js programs

By replacing V8 with GraalVM to execute JavaScript, GraalVM can run in the context of Node.js. The main benefit of this is that you can enable multilingual applications(for example, using Java, R or Python libraries), run Node.js in a large heap configuration and Java's garbage collector, or use GraalVM interoperability in C/C Define data structures in ++ and Java. Use them from JavaScript.

Reuse libraries in Java, R or Python

GraalVM supports the use of existing Java libraries or Java frameworks(such as Spark or Flink) directly from Node.js. In addition, for example, R or Python can be used for data science or drawing directly from JavaScript applications. Find examples of multilingual applications here.

Large heap operation

The V8 JavaScript engine included in the standard Node.js distribution has been adjusted for browser configuration in order to work effectively in small heap scenarios. We support running Node.js through the JVM's heap management, which opens up the ability for large heap configurations and appropriate garbage collection settings. When using compressed 32-bit pointers, the maximum configurable heap size is 32 Gb, and TB heaps are supported in 64-bit pointer configurations.

Defining data structures in C/C ++

GraalVM allows an effective combination of native code(for example, written in C/C ++) and JavaScript. You can directly access native data structures, and the compiler can cross any boundary inline. This may be beneficial in cases where other application parts are written in Node.js using C to manage and distribute effective data structures. Find examples of this in the reference manual.

For Ruby, R, Python or WebAssembly

Ruby, R, Python, and WebAssembly are in the experimental stage in the GraalVM ecosystem and are not currently recommended for production, but we are actively working on the stability and support of all modules of these languages. Currently, we can run simple applications in Ruby, R and Python, but we do not provide the exact same compatibility for Java and Node.js applications. WebAssembly currently implements the WebAssembly MVP(Minimum Viable Product) specification and is the youngest language in the GraalVM environment.

In addition to standard GraalVM advantages(such as language interoperability(for example, using Java or JavaScript from those applications)), GraalVM can increase the speed of these languages by 10 times or more. We are happy to assist in using existing Ruby and R applications with GraalVM, but we cannot yet guarantee the ready compatibility of these languages.

Running in an Oracle database

GraalVM is designed for embeddability and can be executed in the database. A prototype of our Oracle Database Multilingual Engine(MLE) is provided here. It allows Oracle database users to run JavaScript, use browserify to execute Node.js modules, and use Python to write extensions.

For microservices framework

The native GraalVM image currently provided as an early adopter technology can be used with many different Java microservice frameworks. Several projects have accepted the technology as a platform for their applications:Quarkus, Micronaut and Helidon. For these frameworks, the GraalVM native image significantly reduces runtime memory requirements compared to running on HotSpot. We believe that GraalVM native imaging technology can be the best way to deploy cloud native applications.

Microservices diagram

Microservices diagram

For your platform

We encourage the development of our own integrated GraalVM embedding in Oracle database, OpenJDK or Node.js. We have explored the idea of embedding Spark or Flink with our research partners. Find a description of how to embed GraalVM in an existing JVM-based application or a local application here.

Languages and tools for you

GraalVM is an open ecosystem. We invite third-party systems to participate by connecting their own programming languages, tools or platforms.

Implement your own language

The Truffle Language Implementation Framework allows programming languages to be run efficiently on GraalVM. It simplifies language implementation by automatically deriving high-performance code from the interpreter. You can find detailed information about this method in this research paper.

Using GraalVM to implement your own language will not only bring you high performance. More importantly, it enables your language to connect with the rich tools provided by the GraalVM ecosystem. Moreover, it enables your language to run in any context in which GraalVM is embedded.

We have developed a demo language called "SimpleLanguage" to demonstrate the use of GraalVM language implementation framework. Learn how to start implementing a language.

Creating agnostic language tools

GraalVM provides a framework that can be used to create language-independent tools, such as debuggers, analyzers, or other tools. GraalVM provides a standardized method for expressing and running program code, which enables cross-language research and development tools. Once developed, these tools can be applied to any language.

Original address
This article is automatically published by one article multi-posting platform ArtiPub
================================================== ================================================== ====================