days
0
-11
0
hours
-1
0
minutes
-4
0
seconds
-4
-6
search
Meet the still-experimental GraalWasm

WebAssembly engine in GraalVM: Introducing Oracle’s GraalWasm

Maika Möbus
GraalVM
© Shutterstock / Vixit

Oracle has been working on implementing a Wasm engine in GraalVM, and the result is GraalWasm. The project is still in its early stages and marked as experimental. Let’s see what Oracle has done so far, what the anticipated benefits are, and what’s planned for the future.

Oracle announced that it has been working on GraalWasm, a WebAssembly engine implemented in GraalVM. Now GraalWasm has been made publicly available, though still in an experimental state.

WebAssembly is a low-level binary format for the web that other high-level languages compile to in order for them to run in the browser. While C, Rust and C++ compile natively to WebAssembly, C# is supported via Microsoft’s SPA framework Blazor WebAssembly, currently still in preview state.

SEE ALSO: GraalVM: Clearing up confusion around the term and why Twitter uses it in production

GraalVM as a universal platform?

By supporting WebAssembly, or Wasm, the set of GraalVM languages can be broadened, thus bringing it further to a “universal platform for programming language execution,” as Oracle’s Aleksandar Prokopec states in a blog post.

How to get started

GraalWasm can be used to interpret and compile Wasm programs in binary format. Just follow the standard workflow for Graal projects for building GraalWasm.

Additionally, GraalWasm can be embedded into other programs, as it can be accessed programmatically with the Polyglot API.

In this example, a WebAssembly program is run using GraalWasm from a Java application:


import org.graalvm.polyglot.*;

import org.graalvm.polyglot.io.ByteSequence;

 

byte[] binary = readBytes("example.wasm"); // You need to load the .wasm contents into a byte array.

Context.Builder contextBuilder = Context.newBuilder("wasm");

Source.Builder sourceBuilder = Source.newBuilder("wasm", ByteSequence.create(binary), "example");

Source source = sourceBuilder.build();

Context context = contextBuilder.build();

 

context.eval(source);

 

Value mainFunction = context.getBindings("wasm").getMember("_main");

mainFunction.execute();

SEE ALSO: GraalVM 19.3 brings support for JDK 11

Some future plans for GraalWasm include performance improvements and the implementation of WASI (WebAssembly System Interface), a set of APIs that enable WebAssembly programs to run outside the web.

Read more about GraalWasm on GitHub, where Oracle is open for suggestions from the community on how to further improve it.

Author
Maika Möbus
Maika Möbus has been an editor for Software & Support Media since January 2019. She studied Sociology at Goethe University Frankfurt and Johannes Gutenberg University Mainz.

Leave a Reply

1 Comment on "WebAssembly engine in GraalVM: Introducing Oracle’s GraalWasm"

Helen
Guest

Great, looking forward to work on the GraalWasm platform.