-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 + espresso, espressoHome not defined & internal GraalVM error #4555
Comments
This is rather a usability issue on our side, let me explain. Currently, Espresso (bundled in a native image) is not fully standalone, the native executable only includes the interpreter/JIT+GC; but it also needs the .jars/modules and Java core native libraries like libjava.so, libnio.so ... to boot a guest JVM. You can also customize the guest Java home as you please e.g. a jlinked version with only But a "guest" Java home is not enough, Espresso itself requires a few extra libraries and .jars to run and provide additional functionality, briefly commented: $ ls $GRAALVM_HOME/languages/java/lib
hotswap.jar # Advanced redefinition capabilities API (optional)
libeden.so # A library with workarounds for glibc dlmopen bugs. (optional)
libjavavm.so # Espresso's core (optional)
libjvm.so # JVM (native) API
libnespresso.so # JNI (native) API
polyglot.jar # Guest Java API for interop (optional) These files are located in the "Espresso Home" e.g. In JVM mode, Espresso (by default) reuses the same .jars/modules and native libraries bundled with GraalVM (which also includes the Espresso home). Do you need a full-blown GraalVM to run Espresso inside a native image? I just opened a PR for the espresso-jshell demo to make this clear. We could bundle all jars/modules within the native executable and unpack the native libraries to /tmp or have an extra folder with the native libraries since dlopen from memory is not possible. BTW, awesome bug report! |
Just tried this, and it seems to solve my immediate problem!
This is ultimately what we are trying to achieve. We're aware of some of the issues involved and have a few of ideas for working around them (some hackier than others). The first thing we'll probably try is, as you suggest here, writing temporary files somewhere and passing them to the context.
A full graalvm installation probably isn't going to be viable in our case. You've given me plenty of information though so I should be able to work out how to slim things down a bit. That being said, is there another system property that can be used to manually set espresso home? Or is it always inferred from graalvm home? If so, the error message should probably reflect this!
That's interesting. When I was experimenting with the jshell demo, I don't recall ever having to explicitly set org.graalvm.home to get it to run.
Thanks! Your comment has actually been super helpful and answered a few (semi) related questions I had about espresso. I have a much clearer understanding of what's going on now and should be able to make some progress. Thanks for the help! |
That's my fault, the GraalVM home used at build time for
At some point there was an option to specify the Espresso home, I'm investigating how to bring it back, for now, replicating the folder structure does the job e.g. Espresso home must be located in As an experiment, I built a minimal guest+host Java home for |
There is
Also maybe useful:
This one you can specify at native-image build time, that way you can hardcode a relative path in your main executable file. That way, you can provide a "package" containing your image and the needed language homes, and the whole thing is relocatable as long as the relative paths don't change. |
Thank you both for your help! Your answers have been very informative. I was eventually able to create a sample which worked in a regular linux environment, however because we aren't able to load dynamic libraries in the environment where we eventually need this to work, espresso may not be suitable. I've been reading up a little on how the JNI works, and it looks as though from jdk8 onwards, the jdk contains a linker and can load static libraries at runtime. I have made some attempts to build the espresso native components statically, but I'm not very familiar with mx so I haven't been able to make much progress. Do you think this is possible? |
native-image already statically links Java libraries, but these libraries cannot be used by multiple contexts e.g. host Java and guest Java are also considered different contexts. |
|
Environment:
java -Xinternalversion
: OpenJDK 64-Bit Server VM (17.0.2+8-jvmci-22.0-b05) for linux-amd64 JRE (17.0.2+8-jvmci-22.0-b05), built on Jan 20 2022 22:54:40 by "buildslave" with gcc 10.3.0The error:
Have I verified this issue still happens when using the latest snapshot?
I have not.
Code
The code consists of two parts, the host and the client.
The "host" code uses espresso and the polyglot API to load and execute a method from a jar file:
The "client" code (for the purposes of reproducing this error) is just a trivial hello world program:
When the host code is built as a native image and executed, the aforementioned error occurs at line 42 (
Value mainClass = polyglot.getBindings("java").getMember(mainClassName);
) when attempting to get the main class.Steps to reproduce the issue
LD_DEBUG=unused $GRAALVM_HOME/bin/java -jar espressoHost.jar hello.jar hello.Main
and observe that espresso successfully runs the hello world program.native-image -jar espressoHost.jar --no-fallback --language:java
, and execute it with the same arguments. this should result in the aforementioned error.Expected behaviour
Expected the program to execute as it does before compilation as a native image.
Additional context
As part of a project I'm working on, I'm attempting to create a native image which can dynamically load and execute methods from an arbitrary jar file, specified at runtime. I'm unsure as to whether or not the error I'm getting is because of an internal graalvm bug, or a direct result of something I've done improperly.
I haven't been able to find anything regarding "espressoHome" on the graalvm docsite or in the graalvm demo code (Most of my experimentation with espresso has so far been accomplished by reverse engineering the espresso jshell demo). I'm currently reading the espresso source to try and better understand where this error comes from.
The text was updated successfully, but these errors were encountered: