graal icon indicating copy to clipboard operation
graal copied to clipboard

[GR-65205] [Native Image, WASM] ZipFile is broken

Open purplesyringa opened this issue 8 months ago • 0 comments

Describe the Issue

I know this is all work in progress, but I thought I'd report this anyway. ZipFile is broken and tries to access the UNIX filesystem rather than the virtual filesystem, probably because of this mess in OpenJDK.

import java.io.IOException;
import java.nio.file.Files;
import java.util.zip.ZipFile;

public class Main {
    public static void main(String[] args) throws IOException {
        var sourcePath = Files.createTempFile("source", ".zip");
        Files.write(sourcePath, new byte[]{1, 2, 3}); // just for testing

        var file = new ZipFile(sourcePath.toFile());
        System.out.println(file.getComment());
    }
}
Exception in thread "main" java.lang.UnsupportedOperationException: UnmanagedMemorySupport.malloc not supported
	at genBacktrace (/home/purplesyringa/mc/decompiler/target/decompiler.js:1229:12)
	at genBacktrace (/home/purplesyringa/mc/decompiler/target/decompiler.js:1299:32)
	at _Unsafe_allocateMemory___J_J (wasm://wasm/027eb0e6:wasm-function[6614]:0x21e215)
	at _NativeBuffer___strictfp___I_V (wasm://wasm/027eb0e6:wasm-function[9281]:0x2cba97)
	at _UnixNativeDispatcher_copyToNativeBuffer___UnixPath_NativeBuffer (wasm://wasm/027eb0e6:wasm-function[9258]:0x2cacf6)
	at _UnixNativeDispatcher_stat___UnixPath_UnixFileAttributes_V (wasm://wasm/027eb0e6:wasm-function[9300]:0x2cc988)
	at _UnixFileAttributes_get___UnixPath_Z_UnixFileAttributes (wasm://wasm/027eb0e6:wasm-function[9324]:0x2cde4e)
	at _UnixFileAttributeViews$Basic_readAttributes___BasicFileAttributes (wasm://wasm/027eb0e6:wasm-function[8873]:0x2ae558)
	at func.bridge._BasicFileAttributeView.readAttributes___BasicFileAttributes (wasm://wasm/027eb0e6:wasm-function[2320]:0x14d1b2)

Using the latest version of GraalVM can resolve many issues.

GraalVM Version

java version "25" 2025-09-16 LTS
Java(TM) SE Runtime Environment Oracle GraalVM 25-dev+20.1 (build 25+20-LTS-jvmci-b01)
Java HotSpot(TM) 64-Bit Server VM Oracle GraalVM 25-dev+20.1 (build 25+20-LTS-jvmci-b01, mixed mode, sharing)

Operating System and Version

Linux axolotl 6.13.6-arch1-1 #1 SMP PREEMPT_DYNAMIC Fri, 07 Mar 2025 20:19:00 +0000 x86_64 GNU/Linux

Troubleshooting Confirmation

Run Command

native-image --tool:svm-wasm -g <...> && node <...>

Expected Behavior

The attributes are requested from the virtual filesystem.

Actual Behavior

OpenJDK tries to invoke the native stat syscall.

Steps to Reproduce

Create a Java project, include the code snippet as the main class, build targeting WASM, try to run.

Additional Context

No response

Run-Time Log Output and Error Messages

No response

purplesyringa avatar May 04 '25 21:05 purplesyringa