在valgrind下編譯並運行下面的代碼時,我始終得到「無效的4號大小寫」錯誤。有沒有一種乾淨的方式調用JNI_CreateJavaVM(),以便valgrind不會拋出一個合適的?如何在沒有Valgrind錯誤的情況下調用JNI_CreateJavaVM?
#include <jni.h>
#include <stdlib.h>
#include <string.h>
int main()
{
JavaVMInitArgs * vm_args = calloc(1, sizeof(JavaVMInitArgs));
JavaVM * jvm = NULL;
JNIEnv * env = NULL;
vm_args->version = JNI_VERSION_1_6;
vm_args->nOptions = 0;
vm_args->options = NULL;
JNI_CreateJavaVM(&jvm, (void **)&env, vm_args);
return 0;
}
這裏是我運行的valgrind命令:
valgrind --tool=memcheck --leak-check=yes --num-callers=20 --smc-check=all ./test
從我loooonng的valgrind日誌中的一個條目:
==9004== Invalid write of size 4
==9004== at 0x4D5A3C8: ???
==9004== by 0x4D512CB: ???
==9004== by 0x423374F: JavaCalls::call_helper(JavaValue*, methodHandle*, JavaCallArguments*, Thread*) (in /usr/java/jdk1.6.0_21/jre/lib/i386/client/libjvm.so)
==9004== by 0x4361B67: os::os_exception_wrapper(void (*)(JavaValue*, methodHandle*, JavaCallArguments*, Thread*), JavaValue*, methodHandle*, JavaCallArguments*, Thread*) (in /usr/java/jdk1.6.0_21/jre/lib/i386/client/libjvm.so)
==9004== by 0x42335AE: JavaCalls::call(JavaValue*, methodHandle, JavaCallArguments*, Thread*) (in /usr/java/jdk1.6.0_21/jre/lib/i386/client/libjvm.so)
==9004== by 0x420F8C5: instanceKlass::call_class_initializer_impl(instanceKlassHandle, Thread*) (in /usr/java/jdk1.6.0_21/jre/lib/i386/client/libjvm.so)
==9004== by 0x420E650: instanceKlass::initialize_impl(instanceKlassHandle, Thread*) (in /usr/java/jdk1.6.0_21/jre/lib/i386/client/libjvm.so)
==9004== by 0x420DB97: instanceKlass::initialize(Thread*) (in /usr/java/jdk1.6.0_21/jre/lib/i386/client/libjvm.so)
==9004== by 0x420E8AB: instanceKlass::initialize_impl(instanceKlassHandle, Thread*) (in /usr/java/jdk1.6.0_21/jre/lib/i386/client/libjvm.so)
==9004== by 0x420DB97: instanceKlass::initialize(Thread*) (in /usr/java/jdk1.6.0_21/jre/lib/i386/client/libjvm.so)
==9004== by 0x440D660: Threads::create_vm(JavaVMInitArgs*, bool*) (in /usr/java/jdk1.6.0_21/jre/lib/i386/client/libjvm.so)
==9004== by 0x4265395: JNI_CreateJavaVM (in /usr/java/jdk1.6.0_21/jre/lib/i386/client/libjvm.so)
==9004== by 0x804845F: main (jvm.c:15)
==9004== Address 0xbeb54078 is not stack'd, malloc'd or (recently) free'd
感謝, Chenz
如果你設法做到這一點,你可以提供你的抑制文件嗎? – Etherealone 2017-05-31 11:13:29