我使用JNI在C中做一些事情,但每当我执行生成的库时,JVM都会以SIGSEGV (0xb)
退出
如果我正确理解了日志,那么您将找到错误日志(部分内容)和JVM退出的代码。
首先说代码:
#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));
}
};
现在错误日志:
# 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
代码是否有问题,或者我只是称错了?
如果您需要更多信息,我很乐意尽我所能,谢谢。