GraalVM

{{Short description|Virtual machine software}}

{{Multiple issues|

{{Advert|date=January 2024}}

{{Primary sources|date=January 2024}}

}}

{{Infobox software

| name = GraalVM

| logo = GraalVM Logo RGB.svg

| screenshot =

| caption =

| developer = Oracle Corporation

| latest release version = GraalVM for JDK 23

| latest release date = {{Start date and age|2024|09|17|df=yes}}

| operating system = Linux, Windows and macOS{{Cite web | url=https://www.graalvm.org/downloads/ |title = Downloads}}

| platform = Java Virtual Machine

| programming language = Java

| genre = Java dynamic compiler and runtime

| license = Community Edition: GPLv2;{{cite web|url=http://www.graalvm.org/docs/faq/#what-is-the-license-of-graalvm|title=GraalVM FAQ|accessdate=2018-04-25|archive-date=2020-04-13|archive-url=https://web.archive.org/web/20200413065925/https://www.graalvm.org/docs/faq/#what-is-the-license-of-graalvm|url-status=dead}}{{cite web|url=https://github.com/oracle/graal/blob/master/README.md#license|title=graal/README.md|website=GitHub|accessdate=2018-04-25}}

Oracle GraalVM: {{cite web|url=https://www.oracle.com/downloads/licenses/graal-free-license.html |title = GFTC}}

| website = {{URL|https://www.graalvm.org/}}

}}

GraalVM is a Java Development Kit (JDK) written in Java. The open-source distribution of GraalVM is based on OpenJDK, and the enterprise distribution is based on Oracle JDK. As well as just-in-time (JIT) compilation, GraalVM can compile a Java application ahead of time. This allows for faster initialization, greater runtime performance, and decreased resource consumption, but the resulting executable can only run on the platform it was compiled for.

It provides additional programming languages and execution modes. The first production-ready release, GraalVM 19.0, was distributed in May 2019.{{cite web |title=For Building Programs That Run Faster Anywhere: Oracle GraalVM Enterprise Edition |url=https://blogs.oracle.com/graalvm/announcement |accessdate=2022-01-21 |publisher=Oracle Corporation}} The most recent release is GraalVM for JDK 23, made available in September 2024.{{cite web |title=GraalVM for JDK 23 Release Notes |url=https://www.graalvm.org/release-notes/JDK_23/ |access-date=2024-12-29 |website=GraalVM for JDK 23 |publisher=Oracle Corporation}}

Major differentiators of GraalVM compared to the base JDK include:

  • Graal Compiler, a just-in-time (JIT) compiler.
  • GraalVM Native Image is a technology to compile Java applications ahead of time.
  • Truffle Language Implementation Framework and GraalVM SDK, a Java-based framework and a collection of APIs for developing high-performance language runtimes.
  • GraalVM Polyglot API, an API to embed guest language code in a Java-based host application.
  • JavaScript Runtime, an ECMAScript 2023-compliant JavaScript runtime, as well as Node.js.
  • LLVM Runtime is a runtime to execute languages that can be transformed into LLVM bitcode.

Goals

  • To improve the performance of Java virtual machine (JVM)-based languages to match native languages.{{cite web |title=Why GraalVM |url=https://www.graalvm.org/docs/why-graal/ |accessdate=2018-04-25}}{{cite web |date=2012-02-13 |title=Graal : Un compilateur dynamique pour Java |url=http://www.lemondeinformatique.fr/actualites/lire-graal-un-compilateur-dynamique-pour-java-47761.html |accessdate=2013-08-23 |publisher=lemondeinformatique.fr}}
  • To reduce the startup time of JVM-based applications by compiling them ahead of time.
  • To enable GraalVM integration into the Oracle Database, OpenJDK, Android/iOS, and similar custom embeddings.
  • To enable embedding guest language code in a JVM-based host application.
  • To enable mixing of code from any programming language in a single application, billed as a "polyglot application."{{cite web |title=Reference Manual for Polyglot Applications |url=https://www.graalvm.org/docs/reference-manual/polyglot/ |url-status=dead |archive-url=https://web.archive.org/web/20201023062253/https://www.graalvm.org/docs/reference-manual/polyglot/ |archive-date=2020-10-23 |accessdate=2018-04-25}}

History

GraalVM has its roots in the Maxine Virtual Machine project at Sun Microsystems Laboratories (now Oracle Labs). The project's goal was to write a Java virtual machine in Java itself to avoid the problems of developing in C++, particularly manual memory management, and benefit from meta-circular optimizations. The project changed its focus to the compiler and to hook it into the HotSpot runtime as much as possible. The GraalVM compiler, Graal, was started by manually converting the code of the HotSpot client compiler (named "C1") into Java, replacing the previous Maxine compiler.{{Cite web |title="Meta-Circularity is Near", GraalVM, Truffle--airhacks.fm podcast : Adam Bien's Weblog |url=https://adambien.blog/roller/abien/entry/meta_circularity_is_near_graalvm |archive-url=https://web.archive.org/web/20200529203136/https://adambien.blog/roller/abien/entry/meta_circularity_is_near_graalvm |archive-date=2020-05-29}}

Graal was included in HotSpot-based JDK releases such as OpenJDK from Java SE 9 through 15, to provide experimental ahead-of-time compilation. The {{tt|UseJVMCICompiler}} option also enabled the use of Graal as a replacement for the server compiler (named "C2").{{cite web |title=OpenJDK: Graal |url=https://openjdk.org/projects/graal/}} The option was removed in Java SE 16 to eliminate the duplicate effort of maintaining a version in the JDK and a standalone GraalVM release. A similar function to create a native executable from a Java application is provided by the native-image tool of standalone GraalVM releases. The tool processes a Java application's classes and other metadata to create a binary for a specific operating system and architecture. It can be used to build a native executable or a native shared library.

Releases

GraalVM is available as Oracle GraalVM under the GraalVM Free Terms and Conditions (GFTC) license, as Oracle GraalVM Enterprise Edition accessible by accepting the "OTN License Agreement Oracle GraalVM Enterprise Edition Including License for Early Adopter Versions",https://www.oracle.com/technetwork/licenses/graalvm-otn-license-5486575.html {{Bare URL inline|date=September 2022}} or as a Community Edition with an open-source license. Oracle Corporation announced the release of Oracle GraalVM Enterprise Edition on May 8, 2019, and Oracle GraalVM on June 13, 2023, introducing a new GraalVM Free Terms and Conditions (GFTC) license. GraalVM can substitute for a default JDK on Linux and macOS platforms on x64 and AArch64 CPUs, and on a Windows x64 platform. The release schedule is at the Oracle Help Center and the GraalVM website.

class="wikitable mw-collapsible"

|+

!Release

!Date

!Java Version

!Features

GraalVM 19.0.0

|2019-05-09

|OpenJDK 1.8.0_212

|The first production release for Linux and macOS x64 platforms. Windows availability was under development and released as early adopter functionality.

GraalVM 19.1.0

|2019-07-02

|OpenJDK 1.8.0_212

|Introduced libgraal, a shared library produced by GraalVM Native Image, which contained a pre-compiled binary of the Graal compiler that dramatically improved compilation speed. The release also improved profile-guided optimization (PGO) implementation for Native Image.

GraalVM 19.2.0

|2019-08-20

|OpenJDK 1.8.0_222

|This release added preliminary functionality to compile native applications using the LLVM toolchain, shipped with GraalVM. GraalVM Native Image improved throughput performance and simplified the process of collecting data for profile-guided optimizations (PGO). Custom polyglot access was implemented in the polyglot runtime to control access for polyglot bindings and data sharing between languages. A preview of Java Flight Recorder (JFR) functionality was released as a plugin for VisualVM.

GraalVM 19.3.0

|2019-11-19

|Oracle JDK 1.8.0_231, 11.0.5

OpenJDK 1.8.0_232,11.0.5

|This release announced the first GraalVM Java SE 11-based builds; added new platforms — Linux AArch64 and experimental Windows x64. This release also added module encapsulation to isolate Graal compiler and Truffle API code from the application code. GraalVM Native Image switched to using the JDK native code instead of manual substitutions. The [https://graalvm.github.io/native-build-tools/latest/maven-plugin.html Native Image Maven Plugin] was first introduced. GraalVM Enterprise 19.3.0 was the first planned long-term support (LTS) release.

GraalVM 20.0.0

|2020-02-18

|Oracle JDK 1.8.0_241, 11.0.6

OpenJDK 1.8.0_242, 11.0.6

|Improved Windows compatibility; included enhanced Native Image technology, and improved tooling, as well as many changes in the compiler and hosted languages.

GraalVM 20.1.0

|2020-05-19

|Oracle JDK 1.8.0_251, 11.0.7

OpenJDK 1.8.0_252, 11.0.7

|Included several improvements for many of the components. In addition to performance improvements, usability fixes for Native Image were published. The JavaScript engine implemented all ECMAScript 2020 mode features by default. The regular expression engine (TRegex) used by JavaScript and Python implemented all expressions. Ruby (TruffleRuby) was improved in compatibility with native gems.

GraalVM 20.2.0

|2020-08-18

|Oracle JDK 8u261, 11.0.8

OpenJDK 1.8.0_262, 11.0.8

|This release introduced a new Partial Loop Unrolling optimization for JIT compilation. Improved the G1GC-like garbage collection for workloads where Native Image requires smaller GC pauses. Native Image was extended to generate “mostly static” executables which statically link everything except libc.

GraalVM 20.3.0

|2020-11-17

|Oracle JDK 1.8.0_271, 11.0.9

OpenJDK 1.8.0_272, 11.0.9

|The first LTS Enterprise version of Oracle GraalVM Enterprise Edition and the final release for 2020. This release provided code sharing in the GraalVM LLVM runtime, enabling sharing of abstract syntax tree (AST) and compiled code of common bitcode libraries between multiple contexts within a single engine. An experimental "sandbox resource limits" feature was added to Oracle GraalVM Enterprise Edition.

GraalVM 21.0.0

|2021-01-19

|Oracle JDK 1.8.0_281,11.0.10

OpenJDK 1.8.0_282,11.0.10

|This release introduced Java on Truffle — a Java virtual machine implementation based on a Truffle interpreter. GraalVM Native Image added serialization functionality, AWT and Swing implementations for the Linux platform. The GraalVM Updater was improved to enable updating/upgrading a local GraalVM installation.

GraalVM 21.1.0

|2021-04-20

|Oracle JDK 1.8.0_291, 11.0.11, 16.0.1

OpenJDK 1.8.0_292, 11.0.11, 16.0.1

|This release added Java 16 (experimental) functionality and improved Linux AArch64 compatibility. GraalVM Native Image enabled reporting on the build to produce multiple artifacts, and improved compatibility with Windows. Multi-tier compilation was enabled by default for the polyglot runtime (first introduced in GraalVM 20.3); a new sandbox option --sandbox.MaxHeapMemory= to specify the maximum heap memory was introduced.

GraalVM 21.2.0

|2021-07-20

|Oracle JDK 1.8.0_301, 11.0.12, 16.0.2

OpenJDK 1.8.0_302, 11.0.12, 16.0.2

|In this release, the GraalVM team added a novel SIMD (Single Instruction Multiple Data) vectorization optimization for sequential code, and a Strip Mining optimization for non-counted loops for the Graal compiler. It also included new official Gradle and Maven plugins for GraalVM Native Image with initial [https://medium.com/graalvm/gradle-and-maven-plugins-for-native-image-with-initial-junit-testing-support-dde00a8caf0b JUnit 5 testing functionality] and added basic Java Flight Recorder (JFR) functionality on Java SE 11 in GraalVM Native Image, and the “epsilon” GC to build an executable without a garbage collector. Java on Truffle introduced a HotSwap Plugin API to reload code without restarting a running application.

GraalVM 21.3.0

|2021-10-19

|Oracle JDK 1.8.0_311, 11.0.13, 17.0.1

OpenJDK 1.8.0_312, 11.0.13, 17.0.1

|The GraalVM distributions for Java SE 17 became available for download. The release added a new Infeasible Path Correlation optimization to eliminate infeasible paths, provided an implementation for Constant Blinding to defend against JIT spraying attacks. GraalVM Native Image improved gathering the reflection metadata distinguishing between queried and invoked reflection methods, added the initial compatibility for the Java Platform Module System, and several new optimizations to reduce the size of the executable and its build time.

GraalVM 22.0.0

|2022-01-18

|Oracle JDK 11.0.14, 17.0.2

OpenJDK 11.0.14, 17.0.2

|As of this release, GraalVM dropped support for Java SE 8, and removed support for Java SE 12, 13, 14, 15, and 16. This release brought new user-friendly build output for GraalVM Native Image with progress bars and more summary information; improved compatibility with the Java Platform Module System (the options --add-reads and --add-modulesappeared); and a new loop rotation optimization for the Graal compiler that converts more non-counted loops to counted loops.

GraalVM 22.1.0

|2022-04-19

|Oracle JDK 11.0.15, 17.0.3

OpenJDK 11.0.15, 17.0.3

|This release introduced a preview build for Apple Silicon, darwin-aarch64. GraalVM Native Image added a new mode to create conditional configuration using the Tracing agent, and a new “quick build” mode, -Ob, to reduce the time to produce development builds. The Truffle framework introduced TruffleStrings— an implementation of a String type shared between Truffle languages.

GraalVM 22.2.0

|2022-07-19

|Oracle JDK 11.0.16, 17.0.4

OpenJDK 11.0.16, 17.0.4

|This release featured a smaller JDK size, improved memory usage, and better library compatibility. The Oracle GraalVM team together with the Spring, Micronaut, and Quarkus teams introduced the [https://github.com/oracle/graalvm-reachability-metadata GraalVM Reachability Metadata Repository], a centralized place providing configuration for libraries which did not support GraalVM Native Image. GraalVM Native Image also implemented a Software Bill of Materials (SBOM), and started to run on the module path by default. JavaScript, LLVM runtimes, and VisualVM were decoupled from the main package and provided as installable components.

GraalVM 22.3.0

|2022-10-18

|Oracle JDK 11.0.17, 17.0.5, 19.0.1

OpenJDK 11.0.17, 17.0.5, 19.0.1

|This was the last release to support Java SE 11, and the last Feature release of the year. GraalVM Enterprise 22.3.0 would be supported for the next 18 months, and GraalVM Community for 12 months. This version provided Java SE 19 builds, enabling users to take advantage of the latest Java SE 18 and Java SE 19 features. GraalVM Native Image implemented [https://openjdk.org/jeps/425 OpenJDK Project Loom Virtual Threads (JEP 425)]; a jlink implementation; and provided multiple new monitoring features. The GraalPython project was renamed to GraalPy, and its launcher from graalpython to graalpy.

GraalVM for JDK 17

|2023-06-13

|Oracle JDK 17.0.7

OpenJDK 17.0.7

| rowspan="2" |This release introduced a new distribution: Oracle GraalVM, under the new [https://blogs.oracle.com/java/post/graalvm-free-license GraalVM Free Terms and Conditions license]. Along with performance improvements, an implementation for the ZGC garbage collector. GraalVM Native Image introduced the [https://www.graalvm.org/jdk20/reference-manual/native-image/overview/Bundles/ Native Image Bundles feature] and added Machine Learning (ML) based profile inference — a pre-trained machine learning model to predict the control flow of graph branches. Also, as of this release, GraalVM Native Image set build environments on Windows automatically (it was no longer a requirement to run the x64 Native Tools Command Prompt).

GraalVM for JDK 20

|2023-06-13

|Oracle JDK 20.0.1

OpenJDK 20.0.1

GraalVM for JDK 21

|2023-09-19

|Oracle JDK 21 OpenJDK 21

|This release brought all Java SE 21 features to GraalVM such as virtual threads from Project Loom. Performance improvements in this release made ahead-of-time compiled Java applications run at peak performance as on HotSpot. This release enabled the [https://docs.oracle.com/javase/9/gctuning/garbage-first-garbage-collector.htm Garbage First Garbage Collector] (G1 GC) on Linux AArch64 (in addition to Linux x64) in GraalVM Native Image. The GraalVM SDK was refactored and split into four modules. [https://medium.com/graalvm/truffle-unchained-13887b77b62c Languages runtimes were "unchained" from the GraalVM JDK] and became available as Java libraries at Maven Central. Oracle GraalVM for JDK 21 became the current long-term support (LTS) release.

GraalVM for JDK 22

|2023-03-19

|Oracle JDK 22 OpenJDK 22

|

GraalVM for JDK 23

|2024-09-17

|Oracle JDK 23 OpenJDK 23

|

Components

The GraalVM compiler, Graal, is shipped with the components of a normal Java virtual machine (OpenJDK). Additional components are included in GraalVM to enable new execution modes (GraalVM Native Image) or programming languages (LLVM runtime, GraalVM JavaScript as a potential replacement to the deprecated Nashorn engine, TRegex as a regular expression engine).

= Compiler =

The GraalVM compiler, Graal, is a modern Java (JIT) compiler. It complements or replaces the existing compilers (C1/C2 in HotSpot). In contrast to those existing compilers, Graal is written in a modular, maintainable and extendable fashion in Java itself. It is released under GPL version 2 with the classpath exception.

= Native Image =

GraalVM Native Image is an ahead-of-time compilation technology that produces executable binaries of class files.{{cite web |url=https://www.graalvm.org/docs/reference-manual/aot-compilation/ |title=Native Images |website=www.graalvm.org |url-status=dead |archive-url=https://web.archive.org/web/20180420043824/http://www.graalvm.org/docs/reference-manual/aot-compilation/ |archive-date=2018-04-20}} It is released as an early adopter technology, which means it is production-ready but may include backport incompatible updates in future releases.

This functionality supports JVM-,based languages, but can optionally run dynamic languages, developed on top of GraalVM with the Truffle framework. The executable file does not run on a JVM and uses necessary runtime components such as thread scheduling or GC from a minimal bespoke virtual machine called Substrate VM. Since the resulting native binary includes application classes, JDK dependencies and libraries already, the startup and execution time are reduced significantly.

GraalVM Native Image is officially supported by the Fn, Gluon, Helidon, Micronaut, Picocli, Quarkus, Vert.x and Spring Boot Java frameworks.{{cite web

| url=https://www.graalvm.org/community/opensource/#ecosystem

| publisher=Oracle Corporation

| title=GraalVM Open Source Ecosystem

| accessdate=2019-09-11

}}{{cite web

| url=https://docs.spring.io/spring-native/docs/current/reference/htmlsingle/

| publisher=Spring Framework

| title=Spring Native Image documentation

| accessdate=2021-10-26

}}

In September 2016, Oracle detailed plans to add ahead-of-time compilation to the OpenJDK using the GraalVM compiler for Java SE 9.{{cite web

| url=https://www.infoq.com/news/2016/10/AOT-HotSpot-OpenJDK-9

| publisher=InfoQ.com

| title=Ahead-of-Time (AOT) Compilation May Come to OpenJDK HotSpot in Java 9

| quote=AOT brings about a new tool called ‘jaotc' which uses Graal as the backend (to generate code)

| date=2016-10-01

| accessdate=2016-10-06

}}{{cite web

| url=https://bugs.openjdk.java.net/browse/JDK-8166089

| publisher=Oracle Corporation

| title=JDK-8166089: Ahead-of-Time Compilation

| quote=Compile an application's Java classes to native code prior to launching the virtual machine.

| date=2016-09-14

| author=Vladimir Kozlov

| accessdate=2016-10-06

}} This proposal, tracked by [https://openjdk.org/jeps/295 JEP 295: Ahead-of-Time Compilation], was included in Java SE 9.{{cite web

| url=http://openjdk.java.net/jeps/295

| publisher=Oracle Corporation

| title=JEP 295: Ahead-of-Time Compilation

| quote=Compile Java classes to native code prior to launching the virtual machine.

| date=2016-10-13

| author=Vladimir Kozlov

| accessdate=2016-10-13

}} The experimental use of GraalVM as a just-in-time compiler was added for the Linux x64 platform for Java SE 10.{{cite web

| url=http://openjdk.java.net/jeps/317

| publisher=Oracle Corporation

| title=JEP 317: Experimental Java-Based JIT Compiler

| quote=JEP 317: Experimental Java-Based JIT Compiler

| date=2017-10-20

| author=Vladimir Kozlov

| accessdate=2018-01-21

}}

In Java SE versions 9 to 15, the {{code|jaotc}} command creates an executable.{{cite web |title=OpenJDK: Graal |url=https://openjdk.java.net/projects/graal/ |website=openjdk.java.net}} The experimental {{code|-XX:+EnableJVMCIProduct}} flag enables the use of Graal JIT compiler.{{cite web |title=[JDK-8232118] Add JVM option to enable JVMCI compilers in product mode |url=https://bugs.openjdk.java.net/browse/JDK-8232118 |website=bugs.openjdk.java.net}} The functionality is since available in the Native Image component of standalone GraalVM releases.{{cite web |title=GraalVM: Reference Manual: Native Image |url=https://www.graalvm.org/22.1/reference-manual/native-image/ |website=graalvm.org}}

= Truffle Language Implementation Framework =

In association with GraalVM, Oracle Labs developed an abstract syntax tree (AST) interpreter called "Truffle" that enables it to implement languages on top of GraalVM.{{cite web|url=http://wiki.jvmlangsummit.com/images/b/b7/2012-07-31_TruffleJVMSummit2012_Presentation.pdf|title=Truffle: A Self-Optimizing Runtime System|publisher=Oracle Corporation|accessdate=2013-08-23}}{{cite web|url=https://zeroturnaround.com/rebellabs/graal-and-truffle-for-polyglot-languages-on-jvm/|title=Truffle served in a Holy Graal: Graal and Truffle for polyglot language interpretation on the JVM|date=2017-12-05|accessdate=2018-04-25}} Many languages have been implemented in Truffle, including a C interpreter claiming to be about as fast as GCC and Clang.{{cite web |title=Truffle: Languages and Material |url=https://gist.github.com/smarr/d1f8f2101b5cc8e14e12 |website=Gist |language=en}}

The Truffle framework and its dependent part, GraalVM SDK, are released under the Universal Permissive License, version 1.0, to encourage the use of the framework for projects that do not want to be bound by the copyright or other parent rights.

= Instrumentation-Based Tool Support =

A major advantage of the GraalVM ecosystem is language-agnostic, fully dynamic instrumentation support directly built into the VM runtime. Execution events can be captured by API clients with overhead that is extremely low in fully optimized code.{{cite journal

|last1=Van De Vanter |first1=Michael

|last2=Seaton |first2=Chris

|last3=Haupt |first3=Michael

|last4=Humer |first4= Christian

|last5=Würthinger |first5=Thomas

|date=March 9, 2018

|title=Fast, Flexible, Polyglot Instrumentation Support for Debuggers and other Tools

|journal=The Art, Science, and Engineering of Programming

|volume=2

|issue=3, Article 14

|pages=30

|doi=10.22152/programming-journal.org/2018/2/14

|arxiv=1803.10201

|bibcode=

|s2cid=4382172

}}{{cite web

|url=https://www.graalvm.org/docs/graalvm-as-a-platform/implement-instrument/

|title=Getting started with Instruments in GraalVM

|author=

|website=www.graalvm.org

|access-date=2019-04-08

|quote=Truffle instruments can track very fine-grained VM-level runtime events to profile, inspect, and analyze the runtime behavior of applications running on GraalVM.}}

The core GraalVM installation provides a language-agnostic debugger, profiler, heap viewer, and others based on instrumentation and other VM support.{{cite web |author= |title=GraalVM Debugging and Monitoring Tools |url=https://www.graalvm.org/docs/reference-manual/tools/ |url-status=dead |archive-url=https://web.archive.org/web/20190425142543/https://www.graalvm.org/docs/reference-manual/tools/ |archive-date=2019-04-25 |access-date=2019-04-08 |website=www.graalvm.org |quote=GraalVM provides a set of tools for developers, integrators, and IT administrators to debug and monitor GraalVM and deployed applications.}} GraalVM also includes a backend implementation of the Chrome Inspector remote debugging protocol.{{cite web

|url=https://developers.google.com/web/tools/chrome-devtools/

|title=Chrome DevTools

|author=

|website=developers.google.com

|access-date=2019-04-08

|quote=Chrome DevTools is a set of web developer tools built directly into the Google Chrome browser. DevTools can help you edit pages on-the-fly and diagnose problems quickly, which ultimately helps you build better websites, faster.}} Although designed originally for JavaScript debugging, it can be used to debug all GraalVM languages from a browser.

Embedding languages

Another advantage of GraalVM is the possibility to embed code from a guest language in Java and write "polyglot" applications. A developer can integrate JavaScript, Python, or other supported languages inside Java source code, granting them the characteristic advantages of those languages. A host Java application and a guest language pass data back and forth in the same memory space. It is possible thanks to the Truffle Language Implementation Framework{{cite web |title=Truffle: A Self-Optimizing Runtime System |url=http://wiki.jvmlangsummit.com/images/b/b7/2012-07-31_TruffleJVMSummit2012_Presentation.pdf |accessdate=2013-08-23 |publisher=Oracle Corporation}} and the GraalVM Polyglot API. Below is the example how to call a function defined in Python from Java:

try (Context context = Context.create()) {

Value function = context.eval("python", "lambda x: x + 1");

assert function.canExecute();

int x = function.execute(41).asInt();

assert x == 42;

}

The Python function increments its input value by one and returns the result to the host language. From Java, for security purposes, we ask first if the variable function can be executed via the canExecute() call, and then we invoke the function with the execute() call. Find more examples in the [https://www.graalvm.org/latest/reference-manual/embed-languages/ Embedding Languages reference documentation].

Language and runtime support

GraalVM is written in and for the Java ecosystem. It can run applications written in all languages that compile to the Java bytecode format, for example, Java, Scala, Kotlin, and more.

Based on the Truffle Language Implementation Framework, the following additional languages are designed for use with GraalVM:

  • GraalJS:[http://www.github.com/graalvm/graaljs GraalVM JavaScript github repository] An ECMAScript 2023 compliant JavaScript runtime, with support for Node.js
  • GraalPy:[https://github.com/graalvm/graalpython GraalPython github repository] A Python 3 language implementation
  • GraalVM LLVM Runtime (Sulong):[https://github.com/oracle/graal/tree/master/sulong GraalVM LLVM Runtime github repository] An LLVM bitcode interpreter implementation
  • GraalWasm:{{Cite web |title=GraalWasm github repository |url=https://github.com/oracle/graal/tree/master/wasm |website=GitHub}}{{Cite web |last=Prokopec |first=Aleksandar |date=2019-12-02 |title=Announcing GraalWasm — a WebAssembly engine in GraalVM |url=https://medium.com/graalvm/announcing-graalwasm-a-webassembly-engine-in-graalvm-25cd0400a7f2 |access-date=2020-01-15 |website=Medium |language=en}} A WebAssembly implementation
  • TruffleRuby:[https://github.com/oracle/truffleruby TruffleRuby github repository] A Ruby language implementation with preliminary support for Ruby on Rails
  • FastR:[https://github.com/oracle/fastr GraalVM FastR github repository] An R language implementation

Support for additional languages can be implemented by users of GraalVM. Some notable third-party language implementations are grCuda,[https://github.com/NVIDIA/grcuda grCuda GitHub repository] SOMns,[https://github.com/smarr/SOMns SOMns GitHub repository] TruffleSqueak,[https://github.com/hpi-swa/trufflesqueak TruffleSqueak GitHub repository]{{cite book|chapter-url=https://doi.org/10.1145/3357390.3361024 |first1=Fabio |last1=Niephaus |first2=Tim |last2=Felgentreff |first3=Robert |last3=Hirschfeld |title=Proceedings of the 16th ACM SIGPLAN International Conference on Managed Programming Languages and Runtimes - MPLR 2019 |chapter=GraalSqueak: Toward a Smalltalk-based Tooling Platform for Polyglot Programming |publisher=ACM Digital Library |year=2019 |pages=14–26 |doi=10.1145/3357390.3361024 |isbn=9781450369770 |s2cid=204728643 |accessdate=2020-11-08}} and Yona.[https://yona-lang.org Yona Language]

References

{{Reflist|30em}}