Fork me on GitHub
#graalvm
<
2024-04-23
>
volrath21:04:53

Hello everyone, I'm starting to play with GraalVM. I wanted to create a shared library, sort of adapting https://www.graalvm.org/latest/reference-manual/native-image/guides/build-native-shared-library/ to Clojure, but I'm hitting this wall: > Error: Expected Object but got Word for call argument in my.lib.graal_shared_lib.filterEnv(Unknown Source). 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). Full output:

native-image -jar target/graal-shared-lib.jar -O1 --no-server --no-fallback --features=clj_easy.graal_build_time.InitClojureClasses
Warning: Ignoring server-mode native-image argument --no-server.
========================================================================================================================
GraalVM Native Image: Generating 'graal-shared-lib' (executable)...
========================================================================================================================
[clj-easy/graal-build-time] Registering packages for build time initialization: clojure, clj_easy.graal_build_time, my.lib
[1/8] Initializing...                                                                                    (3.0s @ 0.12GB)
 Java version: 22.0.1+8, vendor version: Oracle GraalVM 22.0.1+8.1
 Graal compiler: optimization level: 1, target machine: x86-64-v3, PGO: off
 C compiler: gcc (pc, x86_64, 13.2.1)
 Garbage collector: Serial GC (max heap size: 80% of RAM)
 2 user-specific feature(s):
 - clj_easy.graal_build_time.InitClojureClasses
 - com.oracle.svm.thirdparty.gson.GsonFeature
------------------------------------------------------------------------------------------------------------------------
Build resources:
 - 17.53GB of memory (75.6% of 23.20GB system memory, determined at start)
 - 8 thread(s) (100.0% of 8 available processor(s), determined at start)
[2/8] Performing analysis...  []                                                                         (3.6s @ 0.20GB)
    1,838 reachable types   (55.9% of    3,288 total)
    1,678 reachable fields  (36.6% of    4,582 total)
    7,240 reachable methods (32.4% of   22,349 total)
      674 types,    36 fields, and   272 methods registered for reflection

Error: Expected Object but got Word for call argument in my.lib.graal_shared_lib.filterEnv(Unknown Source). 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.5s (6.5% of total time) in 31 GCs | Peak RSS: 0.62GB | CPU load: 5.31
========================================================================================================================
Failed generating 'graal-shared-lib' after 6.8s.
Does it ring any bell?

mauricio.szabo16:04:47

You're on Windows, right?

volrath16:04:12

Nope, Linux. I was trying to create the class where the CEntryPoints are defined using Clojure, but it worked once i changed it to Java and referenced my clj code from there. I guess the problem is related to some indirection that the byte compiled clj code does..

volrath16:04:12

I still want to figure out if this Java wrapper can be avoided somehow. Maybe looking at how dtype-next works for graalvm

volrath16:04:10

I'm not currently at my desk, but I'll upload a bit more info later, might be useful for someone in the future

mauricio.szabo17:04:18

Ok, I found this problem when I tried to compile my code (that works on Linux) on a Windows VM at the CI. I found out that GraalVM stable version on Windows is a little behind. I also could not find a way to avoid the Java code, unfortunately. If you find something related to this, please let me know, I'm doing Ruby -> C -> Java -> Clojure and this amount of indirection gets weird really fast...