0

I'm using JNI to do some stuff in C, but whenever I execute the generated library, the JVM exits with SIGSEGV (0xb)

following you'll find the error log(parts of it) and the code that the JVM exits at, if I understand the log correctly.

First said code:

#include <jni.h>
#include "Function.h"

/**
 * A C++ Function suitable for JNI calls.
 */
class JavaFunction: public Function {

private:
    JNIEnv   *env;       // JVM environment
    jobject   instance;  // the Java function instance
    jmethodID fct;       // the Java method
    jstring   jname;     // the Java function name
    jdoubleArray array;  // the Java array as argument

public:
    /**
     * Constructor to wrap a Java Function implementation.
     */
    JavaFunction(JNIEnv *env,jobject instance){
        this->env = env;
        this->instance = instance;
        jclass clazz = env->GetObjectClass(instance);
        fct = env->GetMethodID(clazz, "eval", "([D)D"); 
    }
    virtual ~JavaFunction(){}

    /**
     * overloaded operator to execute  double y = f(x) 
     * for java functions implementations.
     */
    virtual double operator()(double x) const {
        // our C++ functions are one dimensional the java function not...
        env->SetDoubleArrayRegion(array,0,1,&x);

        return (env->CallDoubleMethod(instance,fct,array));
    }
};

Now the error log:

# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00007f290907c7df, pid=15104, tid=0x00007f290a5a5700
#
# JRE version: Java(TM) SE Runtime Environment (8.0_151-b12) (build 1.8.0_151-b12)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.151-b12 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# V  [libjvm.so+0x6d47df]  jni_SetDoubleArrayRegion+0x1af

Stack: [0x00007f290a4a5000,0x00007f290a5a6000],  sp=0x00007f290a5a2f50,  free space=1015k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
V  [libjvm.so+0x6d47df]  jni_SetDoubleArrayRegion+0x1af
C  [libNumeric.so+0x1d6e]  JNIEnv_::SetDoubleArrayRegion(_jdoubleArray*, int, int, double const*)+0x3c
C  [libNumeric.so+0x1fba]  JavaFunction::operator()(double) const+0x3a
C  [libNumeric.so+0x195b]  viability(JavaFunction, double)+0x31
C  [libNumeric.so+0x1a64]  Java_de_lab4inf_wrb_Differentiator_differentiate+0x9a
j  de.lab4inf.wrb.Differentiator.differentiate(Lde/lab4inf/wrb/Function;DD)D+0
j  de.lab4inf.wrb.Differentiator.differentiate(Lde/lab4inf/wrb/Function;D)D+7
j  de.lab4inf.wrb.Prak4Tester.checkNatives()V+121

Is there something wrong with the code or am I simply calling it wrong?

If you need more information, I'm happy to provide whatever I can, thank you.

Meik Vtune
  • 450
  • 8
  • 25
  • 3
    Are you creating the array (env->NewDoubleArray()) before trying to assign the elements? – user158037 Dec 18 '17 at 13:26
  • @user158037 No, I am not, I guess. I totally missed that. I've just googled a bit and to create a `jdoublearray`, I'll have to use the JENVObject, right? – Meik Vtune Dec 18 '17 at 13:36

0 Answers0