gpt4 book ai didi

java - 最近的 Ubuntu 16.04 中的 JNI_CreateJavaVM() 堆栈损坏

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:16:10 24 4
gpt4 key购买 nike

几周以来,SWI-Prolog Java 接口(interface)在 JNI_CreateJavaVM 中立即崩溃。好吧,在大多数机器上。它在我的一台机器上运行良好,它运行相同版本的 Ubuntu 和 openjdk ...我将其简化为这个小程序:

#include <jni.h>
#include <stdio.h>
#include <stdlib.h>

static JavaVM *jvm;

int
main(int argc, char **argv)
{ JavaVMInitArgs vm_args = {0};
JNIEnv *env;
JavaVMOption opt[8] = {0};
int optn = 0;
int r;

opt[optn++].optionString = "-Djava.class.path=" "jpl.jar:.";
opt[optn++].optionString = "-Xrs";

vm_args.version = JNI_VERSION_1_2;
vm_args.nOptions = optn;
vm_args.options = opt;

r = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
fprintf(stderr, "Got %d\n", r);
exit(0);
}

即编译使用

JVM=/usr/lib/jvm/java-8-oracle
#JVM=/usr/lib/jvm/java-1.8.0-openjdk-amd64

gcc -I$JVM/include \
-I$JVM/include/linux \
-L$JVM/jre/lib/amd64/server \
-L$JVM/jre/lib/amd64 \
-g -Wall -o t t.c -ljsig -ljava -lverify -ljvm

Gdb 没有提供可用的堆栈跟踪,因为它声称 JVM 某处存在堆栈损坏。我很迷茫,因为使用 Oracle 和 OpenJDK java 都崩溃了,有人认为这是我的错。另一方面,这种方法多年来一直有效,您在所有示例中也都能找到这种方法。

平台为 Ubuntu 16.04、amd64、gcc 5.4.0

valgrind 是这样说的。有趣的是,它在没有崩溃的情况下运行的机器上也是如此。

==9642== Memcheck, a memory error detector
==9642== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==9642== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==9642== Command: ./t
==9642==
==9642== Warning: set address range perms: large range [0x5cb200000, 0x7c0000000) (noaccess)
==9642== Warning: set address range perms: large range [0x5cb200000, 0x5e0100000) (defined)
==9642== Warning: set address range perms: large range [0x7c0000000, 0x800000000) (noaccess)
==9642== Invalid write of size 4
==9642== at 0x84C0BE7: ???
==9642== by 0x84AE4E6: ???
==9642== by 0x549C11A: ??? (in /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server/libjvm.so)
==9642== by 0x545ABA6: ??? (in /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server/libjvm.so)
==9642== by 0x545AFA1: ??? (in /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server/libjvm.so)
==9642== by 0x545B3FF: ??? (in /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server/libjvm.so)
==9642== by 0x545B1B1: ??? (in /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server/libjvm.so)
==9642== by 0x545B3FF: ??? (in /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server/libjvm.so)
==9642== by 0x584A9BB: ??? (in /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server/libjvm.so)
==9642== by 0x54C31E1: JNI_CreateJavaVM (in /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server/libjvm.so)
==9642== by 0x4007C7: main (t.c:22)
==9642== Address 0xffeffea00 is on thread 1's stack
==9642== 4096 bytes below stack pointer

最佳答案

我怀疑这个问题与以下内核问题有关 https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1699772

在更新到最新的软件包后,我注意到我认为 CentOS 7 中存在同样的问题:

  • java-1.8.0-openjdk-1.8.0.131-3.b12.el7_3.x86_64
  • Linux 3.10.0-514-21.2.el7.x86_64

如果我使用 Linux 3.10.0-514-21.1 重新启动,问题就会消失。

关于java - 最近的 Ubuntu 16.04 中的 JNI_CreateJavaVM() 堆栈损坏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44763387/

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