<!DOCTYPE html><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<p>Hello,</p>
<p>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).</p>
<p>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.</p>
<p>Jorn<br>
</p>
<p>[1]:
<a class="moz-txt-link-freetext" href="https://docs.oracle.com/en/java/javase/23/docs/specs/jvmti.html#IterateThroughHeap">https://docs.oracle.com/en/java/javase/23/docs/specs/jvmti.html#IterateThroughHeap</a><br>
</p>
<div class="moz-cite-prefix">On 26-11-2024 11:59, ght ggg wrote:<br>
</div>
<blockquote type="cite" cite="mid:CAPUvbOccdFeMGM5MAtqYomTstG5ijgBasxANS7yTwpOccmum8w@mail.gmail.com">
<div dir="ltr">
<div>Hello:</div>
<div><br>
I'm trying to use JVMTI's IterateOverInstancesOfClass function
to get all instances of a specified class. The code can be
found here: <a href="https://github.com/GGGGGHT/ffitest/blob/main/IterateInstance.java" moz-do-not-send="true" class="moz-txt-link-freetext">https://github.com/GGGGGHT/ffitest/blob/main/IterateInstance.java</a><br>
<br>
</div>
<div>When I call the IterateOverInstancesOfClass method, the JVM
crashes. The crash log is available here: <a href="https://github.com/GGGGGHT/ffitest/blob/main/hs_err_pid20038.log" moz-do-not-send="true" class="moz-txt-link-freetext">https://github.com/GGGGGHT/ffitest/blob/main/hs_err_pid20038.log</a></div>
<div><br>
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?</div>
<div><br>
I look forward to your response.</div>
<div>
<pre class="gmail-notranslate" style="color:rgb(0,0,0)">
</pre>
<pre class="gmail-notranslate" style="color:rgb(0,0,0)">Thanks!</pre>
<pre class="gmail-notranslate" style="color:rgb(0,0,0)">GGGGGHT</pre>
</div>
</div>
</blockquote>
</body>
</html>