DEV Community

özkan pakdil
özkan pakdil

Posted on • Originally published at ozkanpakdil.github.io on

Graalvm to run wasm from spring boot

Graalvm is AOT compilation advanced JDK, I am following the project since 2019, Project’s first target was AOT now lately I start seeing more about multi language support. It supports Python, JS, Ruby, Wasm more details here

And WASM is getting popular day by day, WASM is a new binary file for web. There are many cool examples of WASM

I was wondering how to run WASM code in simple spring boot application,

@GetMapping("/addTwo")
public String addTwo() {
    try (Context context = Context.create()) {
        URL wasmFile = WasmdemoApplication.class.getResource("/test.wasm");
        String moduleName = "main";
        context.eval(Source.newBuilder("wasm", wasmFile).name(moduleName).build());
        Value addTwo = context.getBindings("wasm").getMember(moduleName).getMember("addTwo");
        return "addTwo(40, 2) = " + addTwo.execute(40, 2);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

Enter fullscreen mode Exit fullscreen mode

It is not much but very good starting point how to run WASM from java with #GraalVM. Find full running code here

How looks in the browser

wasm returned from graalvm in browser

If we check how wasm file described in bash

file wasm in bash

References:

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (0)

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up