Segmentation fault in Java (SIGSEGV)

Segmentation fault in Java (SIGSEGV)

We had some major issues when we had to use a native library by a third party.

We were seeing segmentation faults mainly the dreaded SIGSEGV. This would lead to OS signalling to kill the thread / process.

There can be multiple reasons for segmentation fault. In case of native calls it can be null pointers in native code or some incorrect memory access leading to killing of the thread. The bad part is this can be handled anywhere as the entire process killed. It would be interesting if there can be a way that the Java thread remains alive while native thread is killed. Just hypothetically thinking.

We solved it by switching the jdk to the Sun’s version instead of OpenJdk. The problem is solved but I am trying to understand what could have gone wrong. So if you are seeing segmentation fault please check the natives libraries or switch to Sun Jdk. There are loads of other reasons but these two seem to be main culprits always. I am continuing my research on this anyways to understand why Open Jdk crashed while Sun’s still works. Irony is I know the exact line of code where it happens. There is a malloc but why it works with Sun and crashes with Open Jdk needs to be found out.

Leave a comment