Accessing JVM functions from a GraalVM Shared JNI library.

Stack Overflow
Access Java functions (JNI/JNA) from a GraalVM Native Image shared ...
I'm here to show you my concern about the difficulty to access java functions from a GraalVM Shared library. Let's say, My java code is loading a GraalVM Shared library, public class Main { sta...
36 Replies
JavaBot
JavaBot3y ago
This post has been reserved for your question.
Hey @daysling! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here. 💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one.
daysling
dayslingOP3y ago
Not solved yet...
dan1st
dan1st3y ago
Did you really ask a question there? It seems like "I'm having some problem" but I don't really see what exactly the problem is
daysling
dayslingOP3y ago
So, I'm currently loading a shared library built with GraalVM Native-Image, to a JVM with System.loadLibrary(); I'm completely able to achieve my goal of executing native-code functions aka the functions from the GraalVM native image from the JVM completely. However, I am stuck at executing/invoking methods/functions inside the Java runtime from The GraalVM Native compiled code. I'm trying to use JNI/JNA from the native code to execute code at the java runtime If that makes sense.
dan1st
dan1st3y ago
yeah but I didn't see what the actual problem is. Do you receive an error? What happens? How is that different from what you expect to happen? Not just explain what you want to do, also explain what the problem is (in your SO question) also editing helps with getting people to find your question
JavaBot
JavaBot3y ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one.
daysling
dayslingOP3y ago
Like my problem is i'm unable to think of a solution
dan1st
dan1st3y ago
a solution of what?
daysling
dayslingOP3y ago
To access the Runtime JVM functions from the Native-Image DLL I'm more confused now :/
dan1st
dan1st3y ago
What do you mean with runtime JVM functions? And is your question really related to native-image? and what exactly happens with your current code? are you talking about upcalls (calling Java code from native code) or about some native code provided by the Java installation?
dan1st
dan1st3y ago
Stack Overflow
Calling a Java Method from the native code using jni
I am new at using JNI. I successfully write a few programs that call native methods written in c. Now I need my java code to be called by the native code side after it is initialized. Is it possib...
daysling
dayslingOP3y ago
Let's say this,
class Main {
private static native void onEnable();
public static void main(){
// load hello.dll
onEnable();
}
public static void printFromGraal() {
System.out.println("hello");
}
}
class Main {
private static native void onEnable();
public static void main(){
// load hello.dll
onEnable();
}
public static void printFromGraal() {
System.out.println("hello");
}
}
class HelloLib {
// Boilerplate annotations to create onEnable(),
private static void onEnable(...args /*jenv, pointer and stuff*/) {
// I want to Main.printFromGraal() dynamically, HelloLib won't be included in the compiled dll.
}
}
class HelloLib {
// Boilerplate annotations to create onEnable(),
private static void onEnable(...args /*jenv, pointer and stuff*/) {
// I want to Main.printFromGraal() dynamically, HelloLib won't be included in the compiled dll.
}
}
dan1st
dan1st3y ago
Is HelloLib Java code which is compiled to a native library with native-image?
daysling
dayslingOP3y ago
Yes
dan1st
dan1st3y ago
what is the reflection helper for? because I don't really see how that's related
daysling
dayslingOP3y ago
I'm trying to create a GraalVM wrapper for that class.
dan1st
dan1st3y ago
What does the ReflectionHelper do? And why do you need the wrapper?
daysling
dayslingOP3y ago
It's a reflection utility class in the runtime JVM I need to access it with the GraalVM created dll
dan1st
dan1st3y ago
So this isn't code written by you?
daysling
dayslingOP3y ago
No it is
dan1st
dan1st3y ago
So why do you need it?
daysling
dayslingOP3y ago
Like I need it for reflections? Like I want to use reflections from the GraalVM Native code to access the JVM runtime
dan1st
dan1st3y ago
Didn't you say you just wanted to call printedFromGraal? Why do you need reflection for that?
daysling
dayslingOP3y ago
Yes that's just an example that I provided..
dan1st
dan1st3y ago
and what happens when using your current code?
daysling
dayslingOP3y ago
If I could invoke printedFromGraal(), I can do the rest
dan1st
dan1st3y ago
do it like that?
daysling
dayslingOP3y ago
I get that but I don't want to use C or C++ I want to implement it with Native Image and it's libraries
dan1st
dan1st3y ago
What happens when using reflection?
daysling
dayslingOP3y ago
It doesn't resolve the class
dan1st
dan1st3y ago
Include that in your question ideally the complete error message
dan1st
dan1st3y ago
GitHub
Native Image Shared Library Java Function with String Parameters co...
Describe the issue When a java function is used to define a CE Graal Native Image shared library (--shared), whose parameters and return value are java String type, and the calling program is likew...
dan1st
dan1st3y ago
that one seems like it is exactly what you need
daysling
dayslingOP3y ago
Let me check
JavaBot
JavaBot3y ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one.

Did you find this page helpful?