Using FFI to call JVMTI functions
Jorn Vernee
jorn.vernee at oracle.com
Tue Nov 26 12:48:55 UTC 2024
Hello,
It's correct that FFM upcalls only support callers coming from the
'native' thread state. Looking at the code of
IterateOverInstancesOfClass, it holds the heap lock for the duration of
the iteration process, so I don't see how we could execute arbitrary
Java code during this (through an FFM upcall).
So, to answer your question: no, you can not use an FFM upcall stub as a
callback function for IterateOverInstancesOfClass, or the more modern
IterateThroughHeap [1]. In both of these cases, the callback function
can not execute Java code.
Jorn
[1]:
https://docs.oracle.com/en/java/javase/23/docs/specs/jvmti.html#IterateThroughHeap
On 26-11-2024 11:59, ght ggg wrote:
> Hello:
>
> I'm trying to use JVMTI's IterateOverInstancesOfClass function to get
> all instances of a specified class. The code can be found here:
> https://github.com/GGGGGHT/ffitest/blob/main/IterateInstance.java
>
> When I call the IterateOverInstancesOfClass method, the JVM crashes.
> The crash log is available here:
> https://github.com/GGGGGHT/ffitest/blob/main/hs_err_pid20038.log
>
> After examining the code in the UpcallLinker::on_entry method, I found
> that this method needs to run on a JavaThread, but the current thread
> is a VMThread, which leads to the JVM crash. I'm not entirely sure if
> my analysis is correct. If it is correct, does this mean that using
> FFI to call functions requiring UPCALL is not feasible? Or are there
> alternative approaches to achieve my desired functionality?
>
> I look forward to your response.
> Thanks!
> GGGGGHT
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/panama-dev/attachments/20241126/9a90882d/attachment.htm>
More information about the panama-dev
mailing list