2011-03-01 115 views
5

在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

+0

如果你設法做到這一點,你可以提供你的抑制文件嗎? – Etherealone 2017-05-31 11:13:29

回答

1

由於這是在JVM中你可以選擇壓制它。 Valgrind可以配置爲抑制特定的錯誤。你可以找到更多的細節here

+0

上一個答案是正確的 - JVM執行valgrind不贊同的許多事情。您需要抑制這些錯誤,同時不要抑制您想要valgrind檢查的代碼中的錯誤。不幸的是,這是一個單調乏味的試錯過程。 使用由valgrind生成的壓抑可以使這更容易,但它絕不是無痛苦的。 如果最終發現「valgrind中堆棧跟蹤中的調用者太多」,請參閱此帖:http://stackoverflow.com/a/11040043/203044 – BillT 2012-06-14 19:33:15

相關問題