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

时间:2017-06-26 15:37:47

标签: java ubuntu java-native-interface

几周后,SWI-Prolog Java界面立即在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

1 个答案:

答案 0 :(得分:5)

我怀疑这个问题与以下内核问题有关 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重新启动,问题就会消失。