Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Native image fails to compile some lambda with JDK21 #7759

Open
geofjamg opened this issue Nov 8, 2023 · 3 comments
Open

Native image fails to compile some lambda with JDK21 #7759

geofjamg opened this issue Nov 8, 2023 · 3 comments
Assignees

Comments

@geofjamg
Copy link

geofjamg commented Nov 8, 2023

Hi,

This issue could be reproduced with graalvm-jdk-21.0.1+12.1 on MacOS M1 system (Darwin mbp-de-xxx.home 23.1.0 Darwin Kernel Version 23.1.0: Mon Oct 9 21:27:24 PDT 2023; root:xnu-10002.41.9~6/RELEASE_ARM64_T6000 arm64).

It seems to be a regression because using a JDK 17, code compiles fine (and all other GraalVM distributions at least since 19.x)

Creating a shared library, it looks like we cannot anymore capture a CCharPointer inside a lambda.

private static void printMessage(Runnable runnable) {
    runnable.run();
}

@CEntryPoint(name = "hello")
public static void hello(IsolateThread thread, CCharPointer messagePtr) {
    printMessage(() -> {
        String message = CTypeConversion.utf8ToJavaString(messagePtr);
        System.out.println("Say " + message);
    });
}

When compiling we get the error from native image:

========================================================================================================================
GraalVM Native Image: Generating 'graalvm-lambda-issue' (shared library)...
========================================================================================================================
[1/8] Initializing...                                                                                    (7,8s @ 0,11GB)
 Java version: 21.0.1+12, vendor version: Oracle GraalVM 21.0.1+12.1
 Graal compiler: optimization level: 2, target machine: armv8-a, PGO: off
 C compiler: cc (apple, arm64, 15.0.0)
 Garbage collector: Serial GC (max heap size: 80% of RAM)
 1 user-specific feature(s):
 - com.oracle.svm.thirdparty.gson.GsonFeature
------------------------------------------------------------------------------------------------------------------------
Build resources:
 - 12,09GB of memory (75,6% of 16,00GB system memory, determined at start)
 - 8 thread(s) (100,0% of 8 available processor(s), determined at start)
[2/8] Performing analysis...  []                                                                         (0,8s @ 0,18GB)
      834 reachable types   (45,1% of    1 850 total)
      393 reachable fields  (23,8% of    1 653 total)
    2 080 reachable methods (32,4% of    6 420 total)
      259 types,     0 fields, and   110 methods registered for reflection

Error: Expected Object but got Word for call argument in org.example.MyLib.hello(MyLib.java:19). One possible cause for this error is when word values are passed into lambdas as parameters or from variables in an enclosing scope, which is not supported, but can be solved by instead using explicit classes (including anonymous classes).
------------------------------------------------------------------------------------------------------------------------
                        0,2s (2,1% of total time) in 13 GCs | Peak RSS: 0,53GB | CPU load: 1,46
========================================================================================================================

A simple test case could be found in this repository: https://github.com/geofjamg/graalvm-lambda-issue
To get the error just run:

git clone https://github.com/geofjamg/graalvm-lambda-issue
cd graalvm-lambda-issue
mvn package
export JAVA_HOME=<DIR>/graalvm-jdk-21.0.1+12.1/Contents/Home
<DIR>/graalvm-jdk-21.0.1+12.1/Contents/Home/bin/native-image --class-path target/graalvm-lambda-issue-1.0-SNAPSHOT.jar --shared -o graalvm-lambda-issue
@geofjamg
Copy link
Author

@marwan-hallaoui any chance to have this fixed in a coming release ?

@Terrency
Copy link

Terrency commented Mar 15, 2024

hahhh,
I got the following error:

Error: Expected Object but got Word for call argument in LibPrimary.mul(LibPrimary.kt). One possible cause for this error is when word values are passed into lambdas as parameters or from variables in an enclosing scope, which is not supported, but can be solved by instead using explicit classes (including anonymous classes).

but my EntryPoint write by kotlin, and i failed to package my simple project to native-image library, i have try GraalVM JDK 19, without lambadas desc, then i change to the JDK21, got the same error.

@JvmStatic
    @JvmName("mul")
    @CEntryPoint(name = "mul")
    fun mul(thread: IsolateThread?, simulateModelName: CCharPointer): String {
        val simModelName = CTypeConversion.toJavaString(simulateModelName)
        return simModelName
    }

@Terrency
Copy link

doesn't support kotlin well, i change to java, it worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants