AddressSanitizer: SEGV when running C++ code containing call to JNI_CreateJavaVM

0

Our product is written in C++ and, depending on the program flow, makes calls into the Java Native Interface (JNI) to load and run Java classes, mostly to make JBDC calls to access database tables. When this process runs on Linux, with a specific customer configuration, it fails around 20% of the time with a segmentation fault, generating a core dump. The backtrace in the core dump indicates the program is failing somewhere in the JVM (libjvm.so). I've tried running with -Xcheck:jni but the information it has provided doesn't appear to help isolate this issue. I've tried several versions/builds of Java 7 and 8.

To try to get more information about that crash, I've recompiled the code with gcc 4.8.5 using the additional options -fsanitize=address -fstack-protector -fno-omit-frame-pointer. When I compile and use the -fsanitize=address option, then run the program, it quickly crashes with with the following error:

ASAN:SIGSEGV
=================================================================
==15864== ERROR: AddressSanitizer: SEGV on unknown address 0x00000000 (pc 0xe2a00202 sp 0xfff4a8cc bp 0xf35e2b40 T0)
AddressSanitizer can not provide additional info.
    #0 0xe2a00201 (+0x201)
==15864== ABORTING

That crash appears to be occurring when the JNI_CreateJavaVM() function is called from the C++ code to set up to call Java. I took our code out of the picture and tried to just recompile and run the sample Invocation API code that is provided here. When I compile this code, and use the -fsanitize=address option, then run it, it crashes with same kind of error as above. The compile command and options I used are pasted below:

/usr/bin/g++ -m32 -fsanitize=address -I/scratch/jwcarter/jdk1.8.0_291_x86/include -I/scratch/jwcarter/jdk1.8.0_291_x86/include/linux -L/scratch/jwcarter/jdk1.8.0_291_x86/jre/lib/i386/client /scratch/jwcarter/rel125as/rps100/jnitest/c/jnitest.cpp -o jnitest -ljvm

Are there additional compile or link flags that I need to specify in order to use the -fsanitize=address compile option to build code that includes a call to JNI_CreateJavaVM()? Thanks.

java
c++
gcc
asked on Stack Overflow Apr 30, 2021 by John Carter

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0