When compiling and running the following code under valgrind, I consistently get "Invalid write of size 4" errors. Is there a clean way of calling JNI_CreateJavaVM() so that valgrind doesn't throw a fit?
#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;
}
Here is the valgrind command I am running:
valgrind --tool=memcheck --leak-check=yes --num-callers=20 --smc-check=all ./test
A single entry from my loooonng valgrind log:
==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
Thanks, Chenz
Since this is an error within the JVM you can just choose to supress it. Valgrind can be configured to supress specific errors. You can find more details here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With