Help with VM Crash using the foreign linker

Jorn Vernee jorn.vernee at
Sat May 15 13:36:34 UTC 2021


Looking at the crash log, as well as the test, you seem to be passing a 
single struct to a native function, but the stack trace in the error log 
shows that the call is not being intrinsified, which should not be the 
case if you're only passing a single struct on Windows. Either it fits 
in a register, or it's passed by reference, both of which cases are 

The most likely explanation for that seems to be that you are not using 
the right FunctionDescriptor when linking, and a crash occurs when the 
native code is trying to access what it thinks is a pointer to a struct. 
This is undefined behavior territory, which could explain why the crash 
only occurs in certain scenarios.

My advice would be to check the FunctionDescriptor you're using for the 
linkage request, and make sure it matches the native function 
declaration. Looking at [1], the FunctionDescriptor you need is 
FunctionDescriptor.of(C_DOUBLE, C_POINTER).


[1] :

On 15/05/2021 02:21, Duncan McLean wrote:
> Hi Maurizio,
> Thank you for the quick reply. I've made an issue on git hub. I've attached
> one of the VM crash logs to it.
> I pulled down the Panama early access build - that's what I used to make
> the log that is attached to the issue.
> Please let me know what else I can do to help.
> Thanks!
> Duncan
> On Fri, May 14, 2021 at 4:44 PM Maurizio Cimadamore <
> maurizio.cimadamore at> wrote:
>> Hi Duncan,
>> I haven't looked in any details at your email (but I will) - sounds like
>> a cool project. I wanted to share few early considerations:
>> * attachments are dropped by the openjdk mailer - so you need to post
>> them somewhere else (maybe make a Gist on Github?)
>> * For now, Java 16 and Java 17 have exactly the same code (since we have
>> not yet integrated Panama changes into 17). So you might want to try
>> again with e.g. the panama early access [1].
>> It would be helpful if we could see at least the logs of the crash. On
>> top of my head I can't think of any interaction between the Java
>> compiler API and the Foreign Linker API that would be causing this. And,
>> while there are many things that could go wrong when working with custom
>> class loaders, typically when things go wrong you end up with an
>> exception, not a VM crash.
>> But let's start from obtaining the logs, and maybe try to reproduce it,
>> and then let's figure out what's wrong.
>> Thanks for the report!
>> Maurizio
>> On 14/05/2021 21:20, Duncan McLean wrote:
>>> Hello,
>>> I'm sorry if this isn't the right place to be asking for help with the
>>> Foreign Linker, please let me know where I should direct this question if
>>> I'm in the wrong place.
>>> I'm using the Foreign Linker API in a project and experiencing an odd
>>> result. The project is available here:
>>> The way my code works is:
>>> Give JPassport an interface class that you would like to use with the
>>> Foreign Linker. JPassport writes the java code required to call the
>> foreign
>>> library, compiles the code, and hands back an object that implements the
>>> interface and calls the foreign library. (I'm trying to mimic JNA like
>>> behaviour in terms of just providing an interface)
>>> The problem I'm seeing is in my test cases for passing data to functions
>>> requiring C structures
>>> test_jpassport/src/jpassport/test/structs/TestUsingStructs
>>> For some reason, any call to the foreign library causes the VM to crash.
>>> However, this only happens if I invoke the compiler. The 3 scenarios I've
>>> tested are:
>>> 1. Normal operation: write out a .java file, use JavaCompiler to compile,
>>> use URLClassloader to load the compiled class, call a foreign method ->
>>> crash.
>>> 2. Skip compiling: write out a .java file, do not compile, use URL
>>> Classloader to load the class compiled in the previous test, call a
>> foreigh
>>> method -> no crash, the call works perfectly.
>>> 3. Compile manually: Take the java code written out in step 1, add it to
>> my
>>> project, compile, run the program, call a foreign method -> no crash
>>> I've tested this with the most recent JDK 16, and the most recent JDK 17
>>> early access builds. My other test cases for passing primitives and
>> arrays
>>> all work properly with the "normal operation".
>>> I'm testing using 64 bit VM's on Windows 10. I've attached one of the
>> crash
>>> logs for further details on my set-up.
>>> Is there something I'm doing wrong? Please let me know if there are any
>>> other details I can provide or if there is any other way I can help
>>> diagnose what's going on.
>>> Thank you for your help,
>>> Duncan

More information about the panama-dev mailing list