0

I'm interfacing with a native library using JNA 4.2.1 on a Apache Spark Cluster (nodes running with Linux (Oracle 6.7)). Very rarely, my JVM crashes because of a SIGSEGV Signal sent by the native library, which makes my entire spark-application fail.

So I want to protect my JVM to Crash because of this, so I looked into the protected mode of JNA which should translate native signals into JVM exception:

So I use

System.setProperty("jna.protected","true")
Native.setProtected(true)

before I load the library with

Native.loadLibrary(...

After doing this, I get even more SIGSEGVs, here some examples:

#  SIGSEGV (0xb) at pc=0x00007f203b4b7c13, pid=92730, tid=139775595345664
#
# 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:
# V  [libjvm.so+0x440c13]  ciBytecodeStream::get_method(bool&, ciSignature**)+0x513
#

#  SIGSEGV (0xb) at pc=0x00007f29ef518f5c, pid=73559, tid=139817217382144
#
# 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:
# V  [libjvm.so+0x6e0f5c]  jni_GetArrayLength+0x6c

#  SIGSEGV (0xb) at pc=0x00007f27b5c01a8c, pid=73454, tid=139807714744064
#
# 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:
# V  [libjvm.so+0x413a8c]  ciEnv::get_field_by_index(ciInstanceKlass*, int)+0x22c

#  SIGSEGV (0xb) at pc=0x00007f46f913aba5, pid=133097, tid=139942002874112
#
# 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:
# V  [libjvm.so+0x432ba5]  ciObjArrayKlass::make(ciKlass*)+0x85

Note that I don't specify libjsig.so as I can't set the corresponding enviromental variable (I have no access to the System as it is a cluster node).

What I'm doing wrong?

Raphael Roth
  • 26,751
  • 15
  • 88
  • 145

1 Answers1

0

Protected mode on linux doesn't work without libjsig.so. It's not something you should rely on in production anyway, since it's not reliable in a threaded environment.

technomage
  • 9,861
  • 2
  • 26
  • 40
  • Is there a way to set `LD_PRELOAD` somehow programmatically from within my code which calls the library, or does it need to be set before the JVM launches? – Raphael Roth Dec 07 '16 at 06:59
  • Ok I've figured it out... for those who are also using Spark: you can set the executors enviroment variable using the spark option `spark.executorEnv.LD_PRELOAD` – Raphael Roth Dec 07 '16 at 08:18