Getting started with GraalVM
Posted May 29, 2020 • 5 min read
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
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
Reuse libraries in Java, R or Python
Large heap operation
Defining data structures in C/C ++
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.
Running in an Oracle database
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.
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.
This article is automatically published by one article multi-posting platform ArtiPub
================================================== ================================================== ====================