gpt4 book ai didi

C-to-Java 调用通过但 JVM 以一种奇怪/无法解释的方式崩溃

转载 作者:搜寻专家 更新时间:2023-11-01 03:27:54 29 4
gpt4 key购买 nike

问了第一个问题,所以我会直截了当。

我有一些将与 Java 交互的 C 代码;我做了关于 JNI 和主题的作业。这是代码:

C 部分:

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

#define CLASSPATH "-Djava.class.path=/scratch/workareas/JTest/Java/" //folder which contains .class files

#define DEBUG 0

JNIEnv* create_vm(JavaVM ** jvm)
{

JNIEnv *env;
JavaVMInitArgs vm_args;
JavaVMOption options;
strcpy(options.optionString, CLASSPATH); //fix for options.optionString = CLASSPATH;
if (DEBUG) printf("optionString = %s\n", options.optionString);
vm_args.version = JNI_VERSION_1_6; //JDK version. This indicates version 1.6
vm_args.nOptions = 1;
vm_args.options = &options;
vm_args.ignoreUnrecognized = 0;

int ret = JNI_CreateJavaVM(jvm, (void**) &env, &vm_args);
if (ret < 0) printf("\n<<<<< Unable to Launch JVM >>>>>\n");
return env;
}

int main(int argc, char* argv[])
{
JNIEnv* env;
JavaVM* jvm;
printf("Creating JVM....");
env = create_vm(&jvm);
printf(" done! [env = %p\tjvm = %p]\n", env, jvm);
if (env == NULL) return 1;

jclass myClass = NULL;
jmethodID dispatchMessage = NULL;
int counter = 0;

//Obtaining Class
myClass = (*env)->FindClass(env, "EventHandler");
printf("FindClass done! [%p]\n", myClass);

//Obtaining Method ID
if (myClass != NULL)
dispatchMessage = (*env)->GetStaticMethodID(env, myClass, "dispatchEvent", "(I)V");
else
printf("Unable to find the requested class\n");

printf("Calling dispatchEvent() [%p] ...\n", dispatchMessage);
if (dispatchMessage != NULL)
{
// jstring newMessage = (*env)->NewStringUTF(env, "Test call::Called from C\n");
for(counter = 0; counter < 10; counter ++)
{
jint newMessage = counter;
(*env)->CallStaticVoidMethod(env, myClass, dispatchMessage, newMessage);
}
} printf("dispatchMessage() done!\n");

//Release resources.
printf("Releasing resources...");
(*jvm)->DestroyJavaVM(jvm);
printf(" done! Exiting.\n");
return 0;
}

Java 部分:

public class EventHandler
{
public static final int EVENT_CODE_E1 = 1;
public static final int EVENT_CODE_E2 = 2;
//...
public static final int EVENT_CODE_E10 = 10;

private static EventHandler instance = new EventHandler();


public EventHandler()
{
//TODO: create object here
}

public static EventHandler getInstance()
{
if(instance == null)
instance = new EventHandler();
return instance;
}

public static void dispatchEvent(int eventCode)
{
switch(eventCode)
{
case EVENT_CODE_E1:
System.out.println("Event 1 firing!");
getInstance().onEventE1();
break;
case EVENT_CODE_E2:
System.out.println("Event 2 just fired!");
break;
//case
default:
System.out.println("Unknown event with ID: "+eventCode+" triggered!");
break;
}
}

private void onEventE1()
{
System.out.println("heyoooo");
}
}

现在问题来了:执行调用 10 次后,这是我得到的输出:

Creating JVM.... done! [env = 0x80e6d20 jvm = 0x177e6a4]
FindClass done! [0x80e7c78]
Calling dispatchEvent() [0x90b3fe8c] ...
Unknown event with ID: 0 triggered!
Event 1 firing!
heyoooo
Event 2 just fired!
Unknown event with ID: 3 triggered!
Unknown event with ID: 4 triggered!
Unknown event with ID: 5 triggered!
Unknown event with ID: 6 triggered!
Unknown event with ID: 7 triggered!
Unknown event with ID: 8 triggered!
Unknown event with ID: 9 triggered!
dispatchMessage() done!
Releasing resources... done! Exiting.
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x632e6176, pid=14752, tid=3077634256
#
# JRE version: 6.0_26-b03
# Java VM: Java HotSpot(TM) Server VM (20.1-b02 mixed mode linux-x86 )
# Problematic frame:
# C 0x632e6176
[error occurred during error reporting (printing problematic frame), id 0xb]

# An error report file with more information is saved as:
# /scratch/workareas/JTest/hs_err_pid14752.log
#
# If you would like to submit a bug report, please visit:
# http://java.sun.com/webapps/bugreport/crash.jsp
#
Aborted

我不知道是什么原因导致了这次崩溃。我查看了日志,没有任何意义。有人愿意帮忙吗? :)

编辑:我还附上了日志,以防有人发现有趣的东西。我尝试将它与 JNITest 的 objdump 交叉引用,并尝试使用 addr2line,但它没有给我任何好处。 GDB session 在确定根本原因方面也无效。

#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x632e6176, pid=14752, tid=3077634256
#
# JRE version: 6.0_26-b03
# Java VM: Java HotSpot(TM) Server VM (20.1-b02 mixed mode linux-x86 )
# Problematic frame:
# C 0x632e6176
[error occurred during error reporting (printing problematic frame), id 0xb]

# If you would like to submit a bug report, please visit:
# http://java.sun.com/webapps/bugreport/crash.jsp
#

--------------- T H R E A D ---------------

Current thread is native thread

siginfo:si_signo=SIGSEGV: si_errno=0, si_code=1 (SEGV_MAPERR), si_addr=0x632e6176

Registers:
EAX=0x00000000, EBX=0x0063dff4, ECX=0x0063e4e0, EDX=0x0063f360
ESP=0xbfd2f380, EBP=0x616a442d, ESI=0x00000000, EDI=0x00000000
EIP=0x632e6176, EFLAGS=0x00210246, CR2=0x632e6176

Top of Stack: (sp=0xbfd2f380)
0xbfd2f380: 7373616c 7461702e 732f3d68 74617263
0xbfd2f390: 772f6863 616b726f 73616572 65544a2f
0xbfd2f3a0: 4a2f7473 2f617661 00f7c100 00f8bad0
0xbfd2f3b0: b77108d0 0063dff4 00000000 00000000
0xbfd2f3c0: bfd2f3f8 2f09115f 15974820 00000000
0xbfd2f3d0: 00000000 00000000 00000001 08048400
0xbfd2f3e0: 00000000 00f81d90 004fbc0b 00f8aff4
0xbfd2f3f0: 00000001 08048400 00000000 08048421

Instructions: (pc=0x632e6176)
0x632e6156:
[error occurred during error reporting (printing registers, top of stack, instructions near pc), id 0xb]

Register to memory mapping:

EAX=0x00000000 is an unknown value
EBX=0x0063dff4: <offset 0x158ff4> in /lib/libc.so.6 at 0x004e5000
ECX=0x0063e4e0: _IO_2_1_stdout_+0 in /lib/libc.so.6 at 0x004e5000
EDX=0x0063f360: <offset 0x15a360> in /lib/libc.so.6 at 0x004e5000
ESP=0xbfd2f380 is an unknown value
EBP=0x616a442d is an unknown value
ESI=0x00000000 is an unknown value
EDI=0x00000000 is an unknown value


Stack: [0xbfce0000,0xbfd30000], sp=0xbfd2f380, free space=316k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C 0x632e6176
[error occurred during error reporting (printing native stack), id 0xb]


--------------- P R O C E S S ---------------

VM state:at safepoint (shutting down)

VM Mutex/Monitor currently owned by a thread: ([mutex/lock_event])
[0x080e4aa0] Threads_lock - owner thread: 0x90b72000

Heap
PSYoungGen total 9408K, used 322K [0xa9e40000, 0xaa8c0000, 0xb4640000)
eden space 8064K, 4% used [0xa9e40000,0xa9e90b48,0xaa620000)
from space 1344K, 0% used [0xaa770000,0xaa770000,0xaa8c0000)
to space 1344K, 0% used [0xaa620000,0xaa620000,0xaa770000)
PSOldGen total 21504K, used 0K [0x94e40000, 0x96340000, 0xa9e40000)
object space 21504K, 0% used [0x94e40000,0x94e40000,0x96340000)
PSPermGen total 16384K, used 1751K [0x90e40000, 0x91e40000, 0x94e40000)
object space 16384K, 10% used [0x90e40000,0x90ff5f40,0x91e40000)

Code Cache [0xb470f000, 0xb494f000, 0xb770f000)
total_blobs=90 nmethods=0 adapters=58 free_code_cache=50039104 largest_free_block=0

Dynamic libraries:
00110000-00133000 r-xp 00000000 08:06 1710021 /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/i386/libjava.so
00133000-00135000 rw-p 00023000 08:06 1710021 /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/i386/libjava.so
00135000-00148000 r-xp 00000000 08:06 1845308 /lib/libnsl-2.12.1.so
00148000-00149000 r--p 00012000 08:06 1845308 /lib/libnsl-2.12.1.so
00149000-0014a000 rw-p 00013000 08:06 1845308 /lib/libnsl-2.12.1.so
0014a000-0014c000 rw-p 00000000 00:00 0
00154000-0015a000 r-xp 00000000 08:06 1845309 /lib/libnss_compat-2.12.1.so
0015a000-0015b000 r--p 00006000 08:06 1845309 /lib/libnss_compat-2.12.1.so
0015b000-0015c000 rw-p 00007000 08:06 1845309 /lib/libnss_compat-2.12.1.so
0015c000-00166000 r-xp 00000000 08:06 1845311 /lib/libnss_files-2.12.1.so
00166000-00167000 r--p 00009000 08:06 1845311 /lib/libnss_files-2.12.1.so
00167000-00168000 rw-p 0000a000 08:06 1845311 /lib/libnss_files-2.12.1.so
0019d000-001c1000 r-xp 00000000 08:06 1845306 /lib/libm-2.12.1.so
001c1000-001c2000 r--p 00023000 08:06 1845306 /lib/libm-2.12.1.so
001c2000-001c3000 rw-p 00024000 08:06 1845306 /lib/libm-2.12.1.so
001c3000-001c6000 ---p 00000000 00:00 0
001c6000-00214000 rwxp 00000000 00:00 0
00243000-00244000 ---p 00000000 00:00 0
00244000-002c4000 rwxp 00000000 00:00 0
002c4000-002c7000 ---p 00000000 00:00 0
002c7000-00315000 rwxp 00000000 00:00 0
0032d000-00342000 r-xp 00000000 08:06 1845316 /lib/libpthread-2.12.1.so
00342000-00343000 ---p 00015000 08:06 1845316 /lib/libpthread-2.12.1.so
00343000-00344000 r--p 00015000 08:06 1845316 /lib/libpthread-2.12.1.so
00344000-00345000 rw-p 00016000 08:06 1845316 /lib/libpthread-2.12.1.so
00345000-00347000 rw-p 00000000 00:00 0
00347000-0034a000 ---p 00000000 00:00 0
0034a000-00398000 rwxp 00000000 00:00 0
003ba000-003c9000 r-xp 00000000 08:06 1710024 /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/i386/libzip.so
003c9000-003cb000 rw-p 0000e000 08:06 1710024 /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/i386/libzip.so
003cb000-003ce000 ---p 00000000 00:00 0
003ce000-0044c000 rwxp 00000000 00:00 0
0044c000-0044f000 ---p 00000000 00:00 0
0044f000-004cd000 rwxp 00000000 00:00 0
004e5000-0063c000 r-xp 00000000 08:06 1845302 /lib/libc-2.12.1.so
0063c000-0063e000 r--p 00157000 08:06 1845302 /lib/libc-2.12.1.so
0063e000-0063f000 rw-p 00159000 08:06 1845302 /lib/libc-2.12.1.so
0063f000-00642000 rw-p 00000000 00:00 0
00642000-00643000 ---p 00000000 00:00 0
00643000-006c3000 rwxp 00000000 00:00 0
0077a000-0077c000 r-xp 00000000 08:06 1845305 /lib/libdl-2.12.1.so
0077c000-0077d000 r--p 00001000 08:06 1845305 /lib/libdl-2.12.1.so
0077d000-0077e000 rw-p 00002000 08:06 1845305 /lib/libdl-2.12.1.so
008ec000-008ed000 ---p 00000000 00:00 0
008ed000-0096d000 rwxp 00000000 00:00 0
0098b000-0098c000 r-xp 00000000 00:00 0 [vdso]
00991000-00992000 ---p 00000000 00:00 0
00992000-00a12000 rwxp 00000000 00:00 0
00a50000-00a57000 r-xp 00000000 08:06 1845318 /lib/librt-2.12.1.so
00a57000-00a58000 r--p 00006000 08:06 1845318 /lib/librt-2.12.1.so
00a58000-00a59000 rw-p 00007000 08:06 1845318 /lib/librt-2.12.1.so
00c40000-00c49000 r-xp 00000000 08:06 1845313 /lib/libnss_nis-2.12.1.so
00c49000-00c4a000 r--p 00008000 08:06 1845313 /lib/libnss_nis-2.12.1.so
00c4a000-00c4b000 rw-p 00009000 08:06 1845313 /lib/libnss_nis-2.12.1.so
00c76000-00c81000 r-xp 00000000 08:06 1710020 /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/i386/libverify.so
00c81000-00c82000 rw-p 0000b000 08:06 1710020 /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/i386/libverify.so
00e31000-00e34000 ---p 00000000 00:00 0
00e34000-00e82000 rwxp 00000000 00:00 0
00f6e000-00f8a000 r-xp 00000000 08:06 1845299 /lib/ld-2.12.1.so
00f8a000-00f8b000 r--p 0001b000 08:06 1845299 /lib/ld-2.12.1.so
00f8b000-00f8c000 rw-p 0001c000 08:06 1845299 /lib/ld-2.12.1.so
00f8c000-0173e000 r-xp 00000000 08:06 1710009 /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/i386/server/libjvm.so
0173e000-01792000 rw-p 007b1000 08:06 1710009 /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/i386/server/libjvm.so
01792000-01bb0000 rw-p 00000000 00:00 0
08048000-08049000 r-xp 00000000 08:11 3670021 /scratch/workareas/JTest/JNItest
08049000-0804a000 r--p 00000000 08:11 3670021 /scratch/workareas/JTest/JNItest
0804a000-0804b000 rw-p 00001000 08:11 3670021 /scratch/workareas/JTest/JNItest
080e2000-08103000 rw-p 00000000 00:00 0 [heap]
90734000-90934000 r--p 00000000 08:06 919903 /usr/lib/locale/locale-archive
90934000-90968000 rw-p 00000000 00:00 0
90968000-90b00000 r--s 03029000 08:06 1583846 /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar
90b00000-90ba1000 rw-p 00000000 00:00 0
90ba1000-90c00000 ---p 00000000 00:00 0
90c5b000-90c63000 rw-p 00000000 00:00 0
90c63000-90c7b000 rw-p 00000000 00:00 0
90c7b000-90c86000 rw-p 00000000 00:00 0
90c86000-90d23000 rw-p 00000000 00:00 0
90d23000-90d2b000 rw-p 00000000 00:00 0
90d2b000-90d43000 rw-p 00000000 00:00 0
90d43000-90d4e000 rw-p 00000000 00:00 0
90d4e000-90deb000 rw-p 00000000 00:00 0
90deb000-90df1000 rw-p 00000000 00:00 0
90df1000-90e3f000 rw-p 00000000 00:00 0
90e3f000-91e40000 rw-p 00000000 00:00 0
91e40000-94e40000 rw-p 00000000 00:00 0
94e40000-96340000 rw-p 00000000 00:00 0
96340000-a9e40000 rw-p 00000000 00:00 0
a9e40000-aa8c0000 rw-p 00000000 00:00 0
aa8c0000-b4640000 rw-p 00000000 00:00 0
b464f000-b4658000 rw-p 00000000 00:00 0
b4658000-b470f000 rw-p 00000000 00:00 0
b470f000-b494f000 rwxp 00000000 00:00 0
b494f000-b770f000 rw-p 00000000 00:00 0
b770f000-b7711000 rw-p 00000000 00:00 0
b771a000-b771b000 r--p 002a1000 08:06 919903 /usr/lib/locale/locale-archive
b771b000-b7723000 rw-s 00000000 08:06 1181409 /tmp/hsperfdata_rtrk/14752 (deleted)
b7723000-b7724000 rw-p 00000000 00:00 0
b7724000-b7725000 ---p 00000000 00:00 0
b7725000-b7728000 rw-p 00000000 00:00 0
bfce4000-bfd30000 rwxp 00000000 00:00 0 [stack]
bfd30000-bfd32000 rw-p 00000000 00:00 0

VM Arguments:
java_command: <unknown>
Launcher Type: generic

Environment Variables:
PATH=<snip, it's not the path>
USERNAME=rtrk
LD_LIBRARY_PATH=/usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/i386:/usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/i386/server:/home/rtrk/workspace/UPnP/bin-pc/usr/local/lib:
SHELL=/bin/bash
DISPLAY=:0.0

Signal Handlers:
SIGSEGV: [libjvm.so+0x725510], sa_mask[0]=0x7ffbfeff, sa_flags=0x10000004
SIGBUS: [libjvm.so+0x725510], sa_mask[0]=0x7ffbfeff, sa_flags=0x10000004
SIGFPE: [libjvm.so+0x5dff20], sa_mask[0]=0x7ffbfeff, sa_flags=0x10000004
SIGPIPE: [libjvm.so+0x5dff20], sa_mask[0]=0x7ffbfeff, sa_flags=0x10000004
SIGXFSZ: [libjvm.so+0x5dff20], sa_mask[0]=0x7ffbfeff, sa_flags=0x10000004
SIGILL: [libjvm.so+0x5dff20], sa_mask[0]=0x7ffbfeff, sa_flags=0x10000004
SIGUSR1: SIG_DFL, sa_mask[0]=0x00000000, sa_flags=0x00000000
SIGUSR2: [libjvm.so+0x5e3160], sa_mask[0]=0x00000000, sa_flags=0x10000004
SIGHUP: [libjvm.so+0x5e2d40], sa_mask[0]=0x7ffbfeff, sa_flags=0x10000004
SIGINT: [libjvm.so+0x5e2d40], sa_mask[0]=0x7ffbfeff, sa_flags=0x10000004
SIGTERM: [libjvm.so+0x5e2d40], sa_mask[0]=0x7ffbfeff, sa_flags=0x10000004
SIGQUIT: [libjvm.so+0x5e2d40], sa_mask[0]=0x7ffbfeff, sa_flags=0x10000004


--------------- S Y S T E M ---------------

OS:squeeze/sid

uname:Linux 2.6.35-22-generic #33-Ubuntu SMP Sun Sep 19 20:34:50 UTC 2010 i686
libc:glibc 2.12.1 NPTL 2.12.1
rlimit: STACK 8192k, CORE 0k, NPROC infinity, NOFILE 1024, AS infinity
load average:0.02 0.42 1.02

/proc/meminfo:
MemTotal: 2060876 kB
MemFree: 78596 kB
Buffers: 231004 kB
Cached: 1029676 kB
SwapCached: 42504 kB
Active: 711912 kB
Inactive: 1193204 kB
Active(anon): 399420 kB
Inactive(anon): 251192 kB
Active(file): 312492 kB
Inactive(file): 942012 kB
Unevictable: 0 kB
Mlocked: 0 kB
HighTotal: 1187784 kB
HighFree: 18836 kB
LowTotal: 873092 kB
LowFree: 59760 kB
SwapTotal: 1998844 kB
SwapFree: 1841240 kB
Dirty: 232 kB
Writeback: 0 kB
AnonPages: 613140 kB
Mapped: 47840 kB
Shmem: 6164 kB
Slab: 54384 kB
SReclaimable: 41476 kB
SUnreclaim: 12908 kB
KernelStack: 3072 kB
PageTables: 7384 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 3029280 kB
Committed_AS: 1775172 kB
VmallocTotal: 122880 kB
VmallocUsed: 7284 kB
VmallocChunk: 108952 kB
HardwareCorrupted: 0 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 4096 kB
DirectMap4k: 16376 kB
DirectMap4M: 892928 kB


CPU:total 2 (1 cores per cpu, 1 threads per core) family 6 model 42 stepping 7, cmov, cx8, fxsr, mmx, sse, sse2, sse3, ssse3, sse4.1, sse4.2, popcnt

/proc/cpuinfo:
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 42
model name : Intel(R) Core(TM) i5-2400 CPU @ 3.10GHz
stepping : 7
cpu MHz : 3093.040
cache size : 6144 KB
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss nx rdtscp lm constant_tsc arch_perfmon pebs bts xtopology tsc_reliable nonstop_tsc aperfmperf pni pclmulqdq ssse3 cx16 sse4_1 sse4_2 popcnt aes hypervisor lahf_lm ida arat pln pts
bogomips : 6186.08
clflush size : 64
cache_alignment : 64
address sizes : 40 bits physical, 48 bits virtual
power management:

processor : 1
vendor_id : GenuineIntel
cpu family : 6
model : 42
model name : Intel(R) Core(TM) i5-2400 CPU @ 3.10GHz
stepping : 7
cpu MHz : 3093.040
cache size : 6144 KB
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss nx rdtscp lm constant_tsc arch_perfmon pebs bts xtopology tsc_reliable nonstop_tsc aperfmperf pni pclmulqdq ssse3 cx16 sse4_1 sse4_2 popcnt aes hypervisor lahf_lm ida arat pln pts
bogomips : 6186.08
clflush size : 64
cache_alignment : 64
address sizes : 40 bits physical, 48 bits virtual
power management:



Memory: 4k page, physical 2060876k(78580k free), swap 1998844k(1841240k free)

vm_info: Java HotSpot(TM) Server VM (20.1-b02) for linux-x86 JRE (1.6.0_26-b03), built on May 4 2011 01:04:10 by "java_re" with gcc 3.2.1-7a (J2SE release)

time: Fri Dec 16 10:58:12 2011
elapsed time: 3 seconds

感谢大家的努力:)

最佳答案

问题已经解决。

再搜索一番后,我找到了这篇文章http://docs.oracle.com/javase/1.4.2/docs/guide/jni/jni-12.html#JNI_OnLoad

在它的底部附近是一个很好的例子,说明了如何传递多个选项以及如何命名它们。原来 -Xcheck:jni 作为 -DXcheck:jni 传递(jni:pedantic 也有效),在我将 strcpy 从我的代码中移出后,我最后不再得到故障转储。我怀疑罪魁祸首是 strcpy,但其中一个成功了。

这是更新后的代码位:

JNIEnv* create_vm(JavaVM ** jvm)
{

JNIEnv *env;
JavaVMInitArgs vm_args;
JavaVMOption options[2];
options[0].optionString = CLASSPATH; //"-Djava.class.path=/scratch/workareas/JTest/Java/"
options[1].optionString = "-DXcheck:jni:pedantic";
vm_args.version = JNI_VERSION_1_6; //JDK version. This indicates version 1.6
vm_args.nOptions = 2;
vm_args.options = options;
vm_args.ignoreUnrecognized = JNI_TRUE; //drop unrecognized options

int ret = JNI_CreateJavaVM(jvm, (void**) &env, &vm_args);
if (ret < 0) printf("\n<<<<< Unable to Launch JVM >>>>>\n");
return env;
}

关于C-to-Java 调用通过但 JVM 以一种奇怪/无法解释的方式崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8532642/

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