nativelibs4java / BridJ

BridJ: blazing fast Java / C / C++ interop
https://code.google.com/archive/p/bridj/
Other
299 stars 77 forks source link

JVM crashed when calling C++ method with char*[] param #84

Open lucaswanlinz opened 8 years ago

lucaswanlinz commented 8 years ago

Hi, I get a trouble while I'm going to call a method of a native C++ library. The JVM crashed with following error:

# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x0000000000000000, pid=2894, tid=140656179414784
#
# JRE version: Java(TM) SE Runtime Environment (8.0_60-b27) (build 1.8.0_60-b27)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.60-b23 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C  0x0000000000000000
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /opt/bin/hs_err_pid2894.log
#
# If you would like to submit a bug report, please visit:
#   http://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.
#

The public declaration of this method:

virtual int SubscribeMarketData(char *ppTopics[], int nCount) = 0;

The proxy methods generated by JNAerator:

@Name("SubscribeData")
@Virtual(8)
public int SubscribeData(Pointer<Pointer<Byte > > ppTopics, int nCount) {
     return SubscribeData(Pointer.getPeer(ppTopics), nCount);
}
@Name("SubscribeData")
@Virtual(8)
protected native int SubscribeData(@Ptr long ppTopics, int nCount);

My code is something like:

Pointer p = Pointer.pointerToCStrings("myTopic1");
int result = m_api.SubscribeData(p, 1);   //<-- JVM crashed after this line executed.

The other methods in this library works well except this one, and according to the error report:

Current thread (0x00000000013c4800):  JavaThread "Thread-5" daemon [_thread_in_native, id=4316, stack(0x00007f491f203000,0x00007f491fa04000)]

siginfo: si_signo: 11 (SIGSEGV), si_code: 1 (SEGV_MAPERR), si_addr: 0x0000000000000000

Seems that it's a memory allocate error. Not quite sure but I guess there might be something wrong with Pointer.pointerToCStrings. I'm using BridJ 0.7.0 and JNAerator 0.12. Do you have any idea about this or is it something that I'm doing wrong?

Thank you in advance.