What’s new in Graal Languages 24.2

7 min read Original article ↗

Alina Yurenko

Press enter or click to view image in full size

Today, along with GraalVM for JDK 24, we are releasing version 24.2 of Graal Languages. This version is designed for use with GraalVM for JDK 24, but it is also compatible with the latest CPU releases of GraalVM for JDK 21, Oracle JDK 21, and OpenJDK 21. This release includes many exciting updates, including a Gradle plugin for GraalPy, scaling native Python across Java threads, a Continuation API in Espresso (Java on Truffle), the new Truffle Bytecode DSL, and more. Let’s take a look!

Alternatively, watch our release stream for the updates in this release and demos:

Graal Languages in Java ☕️

Starting from this release, users of GraalPy, GraalJS, and other Graal Languages must enable native access privileges to avoid warnings printed by the JVM. When using the module-path, pass the --enable-native-access=org.graalvm.truffle option to the java launcher, and when using the class-path, pass the --enable-native-access=ALL-UNNAMED option to resolve the new warning. Note that Truffle, the framework all Graal Languages are implemented in, automatically forwards the native access capability to all loaded languages and tools. Therefore, no further configuration is required. Denying native access with --illegal-native-access=deny will disable the optimizing runtime and the slower fallback runtime is used instead.

Context and Engine are now automatically closed when no longer strongly referenced. It is still recommended to close them explicitly whenever possible.

Moreover, the Value API has been extended: we added the ability to use Value#as(byte[].class) to copy the contents of a guest language byte buffer (Value#hasBufferElements()) to a new byte array. We also added support for the creation of strings from raw byte arrays and native memory using Value.fromByteBasedString(…) and Value.fromNativeString(…).

When embedding a Graal Language in a native image, language and instrument resources are now automatically included. By default, a separate resources folder is no longer created next to the image. See more in the Embedding Languages guide.

GraalPy 🐍

After adding a Maven plugin for GraalPy in the previous release, we now also ship a Gradle plugin that makes it easy to embed GraalPy in your Gradle projects! 🎉

You can simply add it to your Java projects as follows:

plugins {
application
id("org.graalvm.python") version "24.2.0"
}

graalPy {
packages = setOf("pygal==3.0.5")
}

One of the great benefits of using GraalPy plugins is that they provide a way to easily configure the Python packages you want to use.

The new release of GraalPy also includes two new experimental features that can significantly boost the performance of Python in Java. GraalPy can now load native Python extensions multiple times in different contexts, which makes it possible to scale native Python across Java threads. For this, enable the python.IsolateNativeModules option and use the multi-context mode of GraalPy (we recommend starting with one GraalPy context per thread).

Press enter or click to view image in full size

Performance of native Python extensions in GraalPy across multiple contexts.

The second experimental feature is a new integration of Apache Arrow, a language-independent data representation, in GraalPy. With this, it is possible to directly share large amounts of data between Java and Python without having to copy between Java and Python object layouts. This can significantly reduce the time to process shared data, for example when using popular Python packages such as Pandas from Java:

Press enter or click to view image in full size

Reduced memory and CPU usage with direct sharing

See the native extensions documentation for more details. We will also add a guide on this to our demo repository soon.

Besides, we’ve also made several improvements to how foreign types are now treated in Python. Foreign objects are now given a Python class corresponding to their interop traits. This means, for example, that Java Map or List objects now appear as subclasses of Python's dict or list respectively, and they have all the expected methods on the Python side and behave as much as possible as if they were Python objects. We also added polyglot.register_interop_type and @polyglot.interop_type to add Python methods to given foreign classes when they are called from Python code. This makes it easier to adapt foreign interfaces to be more idiomatic in Python. Finally, when calling a method on a foreign object in Python code, Python methods are now prioritized over foreign members.

Check out the GraalPy changelog for all updates in this release.

To make it easier for you to get started with GraalPy, we’ve added several new demos and guides — check them out:

See more on GitHub:

GraalJS and GraalWasm 🌍

We implemented several ECMAScript proposals, such as Error.isError, Math.sumPrecise, Atomics.pause, Promise.try, Uint8Array to/from base64 and hex, RegExp.escape, Iterator Sequencing, Source Phase Imports, and Regular Expression Pattern Modifiers.

GraalJS now also supports WebAssembly/ES module integration, so Wasm modules can be loaded via import statements. This, for example, makes it even easier to embed Rust, Go, or C++ code compiled to Wasm in a Java application. Here’s an example of this being used in a generated JavaScript binding for a Rust library that now just works on GraalJS:

import * as wasm from "./photon_bg.wasm";
export * from "./photon_bg.js";
import { __wbg_set_wasm } from "./photon_bg.js";
__wbg_set_wasm(wasm);
wasm.__wbindgen_start();

We also updated the version of our Node.js runtime to 22.13.1.

For more details, take a look at the changelogs for GraalJS and GraalWasm.

Espresso ☕️

In Espresso, our Java runtime built on Truffle, we added an exciting new experimental feature: theContinuation API. This API lets you pause a running program, save its state, and then resume it later. The heap objects can be serialized to resume execution in a different JVM instance running the same code (for example, after a restart).

There are several use cases where continuations could be particularly interesting:

  • Speculative Execution: speed up computations where CPU-intensive work is blocked by long waiting periods;
  • Implementing Coroutines/Yield;
  • Web Request Handling: Maintaining state across HTTP requests without global variables or session storage.
  • Undo/Redo Functionality: Capturing application state at various points to enable undoing or redoing actions.
  • Distributed Computing: Serializing continuation state, allowing distributed systems to migrate units of work;
  • Live Programming/Hot Code Swapping.

To get started with the Continuation API, add org.graalvm.espresso:continuations:24.2.0 to your pom.xml/build.gradle with provided scope. See also our serialization example.

You can find more Espresso updates in the changelog.

TruffleRuby 💎

In this release, we updated TruffleRuby to Ruby 3.3.5 and switched to the Panama NFI backend for improved C extension performance. With this new backend, C extensions such as sqlite3, trilogy , and json, are now around 2x to 3x faster thanks to the more efficient Panama upcalls in JVM mode.

See more updates, in particular compatibility improvements and bug fixes, in the changelog.

Truffle Language Implementation Framework

Press enter or click to view image in full size

Truffle Bytecode DSL: From source to AST to bytecode.

We added the Bytecode DSL, a new framework to simplify implementing bytecode interpreters on top of Truffle. The goal is to generate the tricky and tedious details of a bytecode interpreter from an AST-like specification. The generated interpreter supports a variety of features, including tiered interpretation, bytecode quickening, boxing elimination, instrumentation, continuations, and serialization. Additionally, the generated code implements several optimizations for interpreter speed and memory footprint. The next step for us is to put the new DSL to use in GraalPy and other Graal Languages. If you’d like to use it, please see our extensive user guides and tutorials to get started.

Community and Ecosystem

  • With GraalPy you can easily create interactive SVG charts with Pygal in your Java applications — see how for Micronaut and Spring Boot.
  • GraalPy and GraalWasm featured are featured as Innovators in InfoQ‘s Java 2024 Trends Report! 🚀
  • See our Jfokus talk for the best practices and tips for extending your Java applications with GraalPy.
  • Christian Humer, Truffle project lead, talked to Adam Bien on his airhacks.fm podcast about GraalVM, Truffle, Futamura projections, and more.

Conclusion

We’d like to take this opportunity to thank our amazing contributors and community for all the feedback, suggestions, and contributions that went into this release.

If you have feedback for this release or suggestions for features you would like to see in future releases, please share them with us on Slack, GitHub, or BlueSky.

— the GraalVM team