graal
graal copied to clipboard
Graalvm-wasm is not compatible to wasm code compiled by JWebAssembly
Describe the issue Graalvm-wasm is not compatible to wasm code compiled by JWebAssembly
Steps to reproduce the issue
- Use graalvm to load wasm file which is compiled by JWebAssembly. https://github.com/i-net-software/JWebAssembly
- Error happens with message Invalid value type: 0x02 when context.evaluate(source).
- The same wasm file can be load and executed by wasmer-java library.
- The wasm filed is attached
Describe GraalVM and your environment:
- GraalVM version 22.1
- JDK major version: 11
- OS: MacOS 12.4
- Architecture: ARM64/M1
My host code
import java.nio.file.Files;
import java.nio.file.Path;
import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.Source;
import org.graalvm.polyglot.Value;
import org.graalvm.polyglot.io.ByteSequence;
public class WASMTest {
public static void main(String[] args) throws Exception {
byte[] binary = Files.readAllBytes(Path.of("./JWebassemblyTest-1.0-SNAPSHOT.wasm"));
Context.Builder contextBuilder = Context.newBuilder("wasm");
Source.Builder sourceBuilder = Source.newBuilder("wasm", ByteSequence.create(binary), null);
Source source = sourceBuilder.build();
Context context = contextBuilder.build();
context.eval(source);
Value bindings = context.getBindings("wasm");
Value discount = bindings.getMember("main").getMember("discount");
Value result = discount.execute();
System.out.println(result);
}
}
My source code compile to WASM
import de.inetsoftware.jwebassembly.api.annotation.Export;
public class HelloWorld {
@Export
public static int discount()
{
return 10;
}
@Export
public static int discountCountry(int code)
{
if(code == 400)
{
return 5;
}
else if(code == 500)
{
return 10;
}
return 15;
}
}
Error message:
Exception in thread "main" Invalid value type: 0x02
at org.graalvm.sdk/org.graalvm.polyglot.Context.eval(Context.java:399)
at WASMTest.main(WASMTest.java:19)
Update: I made it work if I keep only one java method in my source code and compile it to wasm by JWebAssembly, it works with Graalvm-wasm. In above example, I have two methods...
Is this a limit of Graalvm-wasm?
Hi, Thank you for reporting this, we will take a look into it and get back to you
Your example requires WebAssembly Multi-Value support, which is currently not part of GraalWasm.
Hi all,
Apparently the latest version of Graal ( 22.3.0 ) supports Multi-Value: https://docs.oracle.com/en/graalvm/enterprise/22/docs/release-notes/
@i059917 Can you re-check?