Subject: [BUG] Crash in FFM when calling native function with std::make_unique<RtcManager>

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Mon Mar 31 10:52:51 UTC 2025


Hi,
At the moment, FFM works with C libraries. While some C++ functions can 
be called, FFM doesn't know the C++ calling conventions, so I wonder if 
something in the function you are calling might require "more setup" 
(where such setup would typically be performed by a C++ compiler).

Do you have a link to the library header? That would allow us to 
investigate more.

Cheers
Maurizio

On 31/03/2025 10:26, bai li wrote:
> Hi Panama team,
>
> I’m using the Java FFM API in JDK 21 to call a C++ dynamic library 
> function, `void createRtcContext(const char* localId, int logLevel, 
> IceConfig* iceConfig, DataChannelConfig* dataChannelConfig)`. The 
> function can be invoked, but it crashes when executing 
> `std::make_unique<RtcManager>()` inside the function. The same C++ 
> code runs without any issues when executed independently. The 
> `RtcManager` class is roughly defined as follows:
>
> ```cpp
> class RtcManager {
> private:
>     std::string localId;
>     rtc::Configuration config;
>     std::unordered_map<std::string, 
> std::shared_ptr<rtc::PeerConnection>> peerConnectionMap;
>     std::unordered_map<std::string, std::shared_ptr<rtc::DataChannel>> 
> dataChannelMap;
>     std::shared_ptr<rtc::WebSocket> ws = 
> std::make_shared<rtc::WebSocket>();
>     std::shared_ptr<DataChannelListener> dataChannelListener = nullptr;
> public:
>     explicit RtcManager(const std::string& id) : localId(id) {}
> };
> The C++ code is compiled with MSVC 2022. Here’s the crash log from the 
> console:
> # A fatal error has been detected by the Java Runtime Environment:
> #
> #  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00007ffb0ca62f58, 
> pid=22096, tid=26348
> #
> # JRE version: Java(TM) SE Runtime Environment (21.0.6+8) (build 
> 21.0.6+8-LTS-188)
> # Java VM: Java HotSpot(TM) 64-Bit Server VM (21.0.6+8-LTS-188, mixed 
> mode, sharing, tiered, compressed oops, compressed class ptrs, g1 gc, 
> windows-amd64)
> # Problematic frame:
> # C  [msvcp140.dll+0x12f58]
> #
> # No core dump will be written. Minidumps are not enabled by default 
> on client versions of Windows
> #
> # An error report file with more information is saved as:
> # E:\projects\backend-projects\test\hs_err_pid22096.log
> [0.236s][warning][os] Loading hsdis library failed
> #
> # If you would like to submit a bug report, please visit:
> # https://bugreport.java.com/bugreport/crash.jsp
> # The crash happened outside the Java Virtual Machine in native code.
> # See problematic frame for where to report the bug.
> #
> Thanks


More information about the panama-dev mailing list