gpt4 book ai didi

java - Tomcat 上的 JNI 发生 fatal error

转载 作者:行者123 更新时间:2023-11-30 17:20:31 25 4
gpt4 key购买 nike

我正在做一个矩阵计算器,我必须通过 JNI 计算 2 个矩阵的总和。我通过用户输入获取矩阵编号,并将其存储到不同的二维数组中。然后我将两个 2d 数组转换为单独的 1D 数组以传递到 JNI。但是我在完成所有这些之后,服务器崩溃了,我得到了这个日志文件:

# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x00007f2bf0c012b1, pid=7021, tid=139824982963968
#
# JRE version: OpenJDK Runtime Environment (7.0_75-b13) (build 1.7.0_75-b13)
# Java VM: OpenJDK 64-Bit Server VM (24.75-b04 mixed mode linux-amd64 compressed oops)
# Derivative: IcedTea 2.5.4
# Distribution: Ubuntu 14.04 LTS, package 7u75-2.5.4-1~trusty1
# Problematic frame:
# V [libjvm.so+0x5f62b1] jni_GetDoubleArrayElements+0x51
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# If you would like to submit a bug report, please include
# instructions on how to reproduce the bug and visit:
# http://icedtea.classpath.org/bugzilla

#

这是我的.c:

    #include <jni.h>
#include <stdio.h>
#include "MatrixCalculator.h"

JNIEXPORT jdoubleArray JNICALL Java_matrixcalculator_MatrixCalculator_summationOfMatricesViaC
(JNIEnv * env, jobject thisObj, jint jnirow1, jint jnicolumn1, jdoubleArray jniMatrix1, jdoubleArray jniMatrix2)
{

jdouble *doubleCMatrix1 = (*env)->GetDoubleArrayElements(env, jniMatrix1, NULL);
jdouble *doubleCMatrix2 = (*env)->GetDoubleArrayElements(env, jniMatrix2, NULL);

jsize length = (*env)->GetArrayLength(env, jniMatrix1);

jdoubleArray finalSum = (*env)->NewDoubleArray(env, length);

jdouble *preparingSum = (*env)->GetDoubleArrayElements(env, finalSum, NULL);

int i;
for(i = 0; i < length; i++) {
preparingSum[i] = doubleCMatrix1[i] + doubleCMatrix2[i];
}
(*env)->ReleaseDoubleArrayElements(env, jniMatrix1, doubleCMatrix1, 0);
(*env)->ReleaseDoubleArrayElements(env, jniMatrix2, doubleCMatrix2, 0);
(*env)->ReleaseDoubleArrayElements(env, finalSum, preparingSum, 0);

return finalSum;

}

我的两次转换都在这里:

 public void convert2To1D(double [][] aMatrix) {

List<Double> list = new ArrayList<Double>();

for(int i = 0; i < row2; i++)
for(int j = 0; j < column2; j++) {
list.add(aMatrix[i][j]);

}
conversion2 = new double[list.size()];
for(int i = 0; i < conversion2.length; i++)
conversion2[i] = list.get(i);

}

public void convertTo1D(double [][] aMatrix) {

List<Double> list = new ArrayList<Double>();

for(int i = 0; i < row1; i++)
for(int j = 0; j < column1; j++) {
list.add(aMatrix[i][j]);

}
conversion1 = new double[list.size()];
for(int i = 0; i < conversion1.length; i++)
conversion1[i] = list.get(i);


}

还有我的原生声明:

 public native double[] summationOfMatricesViaC(int rows, int columns, double[] aMatrix1, double[] aMatrix2);

我相信转换可能是错误的,并且它没有获取所有元素,但我可能是错的。尝试更改不同的时间,但仍然出现同样的崩溃。有什么帮助吗?

已编辑:转换没问题!正在传递 NULL 参数,这就是它在如此严重的问题中崩溃的原因。

最佳答案

解决方案:愚蠢的我,我传递了 NULL 参数,这导致了错误。请记住始终确保您的参数包含数据!

关于java - Tomcat 上的 JNI 发生 fatal error ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28567974/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com