|
From: <Tam...@er...> - 2006-03-14 17:20:04
|
Hi,
I'm trying to debug my Java native methods using Valgrind. =
Unfortunately, it doesn't seem to work.
When I start my test application Valgrind starts OK as well. But then it =
stops producing printouts. After that my program finishes without =
problems (but Valgrind printouts are missing).
I use Sun JVM 1.4.2.06 and Valgrind 3.1 on a SuSE Linux with 2.6.5 =
kernel.
Here is the printout I get when running my test application:
mwlx124> /export/localhome/ltameil/Documents/valgrind/bin/valgrind =
--leak-check=3Dfull =
/export/localhome/ltameil/Documents/j2sdk1.4.2_05/jre/bin/java jnitest
=3D=3D4953=3D=3D Memcheck, a memory error detector.
=3D=3D4953=3D=3D Copyright (C) 2002-2005, and GNU GPL'd, by Julian =
Seward et al.
=3D=3D4953=3D=3D Using LibVEX rev 1471, a library for dynamic binary =
translation.
=3D=3D4953=3D=3D Copyright (C) 2004-2005, and GNU GPL'd, by OpenWorks =
LLP.
=3D=3D4953=3D=3D Using valgrind-3.1.0, a dynamic binary instrumentation =
framework.
=3D=3D4953=3D=3D Copyright (C) 2000-2005, and GNU GPL'd, by Julian =
Seward et al.
=3D=3D4953=3D=3D For more details, rerun with: -v
=3D=3D4953=3D=3D
=3D=3D4953=3D=3D Conditional jump or move depends on uninitialised =
value(s)
=3D=3D4953=3D=3D at 0x4001532: elf_dynamic_do_rel.4 (in =
/lib/ld-2.2.5.so)
=3D=3D4953=3D=3D by 0x40017C9: _dl_start (in /lib/ld-2.2.5.so)
=3D=3D4953=3D=3D by 0x4001305: (within /lib/ld-2.2.5.so)
=3D=3D4953=3D=3D
=3D=3D4953=3D=3D Conditional jump or move depends on uninitialised =
value(s)
=3D=3D4953=3D=3D at 0x400156D: elf_dynamic_do_rel.4 (in =
/lib/ld-2.2.5.so)
=3D=3D4953=3D=3D by 0x40017C9: _dl_start (in /lib/ld-2.2.5.so)
=3D=3D4953=3D=3D by 0x4001305: (within /lib/ld-2.2.5.so)
=3D=3D4953=3D=3D
=3D=3D4953=3D=3D Conditional jump or move depends on uninitialised =
value(s)
=3D=3D4953=3D=3D at 0x400E303: strlen (in /lib/ld-2.2.5.so)
=3D=3D4953=3D=3D by 0x400476C: _dl_init_paths (in /lib/ld-2.2.5.so)
=3D=3D4953=3D=3D by 0x40029B8: dl_main (in /lib/ld-2.2.5.so)
=3D=3D4953=3D=3D by 0x400CC49: _dl_sysdep_start (in /lib/ld-2.2.5.so)
=3D=3D4953=3D=3D by 0x400190E: _dl_start_final (in /lib/ld-2.2.5.so)
=3D=3D4953=3D=3D by 0x40017F5: _dl_start (in /lib/ld-2.2.5.so)
=3D=3D4953=3D=3D by 0x4001305: (within /lib/ld-2.2.5.so)
=3D=3D4953=3D=3D
=3D=3D4953=3D=3D Conditional jump or move depends on uninitialised =
value(s)
=3D=3D4953=3D=3D at 0x4008F21: elf_dynamic_do_rel.4 (in =
/lib/ld-2.2.5.so)
=3D=3D4953=3D=3D by 0x40091FA: _dl_relocate_object (in =
/lib/ld-2.2.5.so)
=3D=3D4953=3D=3D by 0x4001FF1: dl_main (in /lib/ld-2.2.5.so)
=3D=3D4953=3D=3D by 0x400CC49: _dl_sysdep_start (in /lib/ld-2.2.5.so)
=3D=3D4953=3D=3D by 0x400190E: _dl_start_final (in /lib/ld-2.2.5.so)
=3D=3D4953=3D=3D by 0x40017F5: _dl_start (in /lib/ld-2.2.5.so)
=3D=3D4953=3D=3D by 0x4001305: (within /lib/ld-2.2.5.so)
=3D=3D4953=3D=3D
=3D=3D4953=3D=3D Conditional jump or move depends on uninitialised =
value(s)
=3D=3D4953=3D=3D at 0x4008F25: elf_dynamic_do_rel.4 (in =
/lib/ld-2.2.5.so)
=3D=3D4953=3D=3D by 0x40091FA: _dl_relocate_object (in =
/lib/ld-2.2.5.so)
=3D=3D4953=3D=3D by 0x4001FF1: dl_main (in /lib/ld-2.2.5.so)
=3D=3D4953=3D=3D by 0x400CC49: _dl_sysdep_start (in /lib/ld-2.2.5.so)
=3D=3D4953=3D=3D by 0x400190E: _dl_start_final (in /lib/ld-2.2.5.so)
=3D=3D4953=3D=3D by 0x40017F5: _dl_start (in /lib/ld-2.2.5.so)
=3D=3D4953=3D=3D by 0x4001305: (within /lib/ld-2.2.5.so)
This is Java_jnitest_printHello
exit...
mwlx124>
Here is the code of the native method I try to debug:
JNIEXPORT void JNICALL=20
Java_jnitest_printHello (JNIEnv *env, jobject obj) {
void* p;
int i;
printf("This is Java_jnitest_printHello\n");
for (i=3D0; i<10; i++){
p =3D malloc(1000);
}
printf("exit...\n");
}
If I do the same in a pure C program Valgrind says that there is 10000 =
bytes are definitely lost and syas that "searching for pointers to 10 =
not-freed blocks".
Here is the code:
#include <stdlib.h>
#include <stdio.h>
int main(int argc,const char* argv[]) {
int i;
void* p;
=20
printf("Start...\n");
for (i=3D0; i<10; i++) {
p =3D malloc(1000);
}
printf("Stop.\n");
}
And the printouts:
mwlx124> /export/localhome/ltameil/Documents/valgrind/bin/valgrind =
--leak-check=3Dfull ./ctest
=3D=3D5065=3D=3D Memcheck, a memory error detector.
=3D=3D5065=3D=3D Copyright (C) 2002-2005, and GNU GPL'd, by Julian =
Seward et al.
=3D=3D5065=3D=3D Using LibVEX rev 1471, a library for dynamic binary =
translation.
=3D=3D5065=3D=3D Copyright (C) 2004-2005, and GNU GPL'd, by OpenWorks =
LLP.
=3D=3D5065=3D=3D Using valgrind-3.1.0, a dynamic binary instrumentation =
framework.
=3D=3D5065=3D=3D Copyright (C) 2000-2005, and GNU GPL'd, by Julian =
Seward et al.
=3D=3D5065=3D=3D For more details, rerun with: -v
=3D=3D5065=3D=3D
=3D=3D5065=3D=3D Conditional jump or move depends on uninitialised =
value(s)
=3D=3D5065=3D=3D at 0x4001532: elf_dynamic_do_rel.4 (in =
/lib/ld-2.2.5.so)
=3D=3D5065=3D=3D by 0x40017C9: _dl_start (in /lib/ld-2.2.5.so)
=3D=3D5065=3D=3D by 0x4001305: (within /lib/ld-2.2.5.so)
=3D=3D5065=3D=3D
=3D=3D5065=3D=3D Conditional jump or move depends on uninitialised =
value(s)
=3D=3D5065=3D=3D at 0x400156D: elf_dynamic_do_rel.4 (in =
/lib/ld-2.2.5.so)
=3D=3D5065=3D=3D by 0x40017C9: _dl_start (in /lib/ld-2.2.5.so)
=3D=3D5065=3D=3D by 0x4001305: (within /lib/ld-2.2.5.so)
=3D=3D5065=3D=3D
=3D=3D5065=3D=3D Conditional jump or move depends on uninitialised =
value(s)
=3D=3D5065=3D=3D at 0x400E303: strlen (in /lib/ld-2.2.5.so)
=3D=3D5065=3D=3D by 0x400476C: _dl_init_paths (in /lib/ld-2.2.5.so)
=3D=3D5065=3D=3D by 0x40029B8: dl_main (in /lib/ld-2.2.5.so)
=3D=3D5065=3D=3D by 0x400CC49: _dl_sysdep_start (in /lib/ld-2.2.5.so)
=3D=3D5065=3D=3D by 0x400190E: _dl_start_final (in /lib/ld-2.2.5.so)
=3D=3D5065=3D=3D by 0x40017F5: _dl_start (in /lib/ld-2.2.5.so)
=3D=3D5065=3D=3D by 0x4001305: (within /lib/ld-2.2.5.so)
=3D=3D5065=3D=3D
=3D=3D5065=3D=3D Conditional jump or move depends on uninitialised =
value(s)
=3D=3D5065=3D=3D at 0x4008F21: elf_dynamic_do_rel.4 (in =
/lib/ld-2.2.5.so)
=3D=3D5065=3D=3D by 0x40091FA: _dl_relocate_object (in =
/lib/ld-2.2.5.so)
=3D=3D5065=3D=3D by 0x4001FF1: dl_main (in /lib/ld-2.2.5.so)
=3D=3D5065=3D=3D by 0x400CC49: _dl_sysdep_start (in /lib/ld-2.2.5.so)
=3D=3D5065=3D=3D by 0x400190E: _dl_start_final (in /lib/ld-2.2.5.so)
=3D=3D5065=3D=3D by 0x40017F5: _dl_start (in /lib/ld-2.2.5.so)
=3D=3D5065=3D=3D by 0x4001305: (within /lib/ld-2.2.5.so)
=3D=3D5065=3D=3D
=3D=3D5065=3D=3D Conditional jump or move depends on uninitialised =
value(s)
=3D=3D5065=3D=3D at 0x4008F25: elf_dynamic_do_rel.4 (in =
/lib/ld-2.2.5.so)
=3D=3D5065=3D=3D by 0x40091FA: _dl_relocate_object (in =
/lib/ld-2.2.5.so)
=3D=3D5065=3D=3D by 0x4001FF1: dl_main (in /lib/ld-2.2.5.so)
=3D=3D5065=3D=3D by 0x400CC49: _dl_sysdep_start (in /lib/ld-2.2.5.so)
=3D=3D5065=3D=3D by 0x400190E: _dl_start_final (in /lib/ld-2.2.5.so)
=3D=3D5065=3D=3D by 0x40017F5: _dl_start (in /lib/ld-2.2.5.so)
=3D=3D5065=3D=3D by 0x4001305: (within /lib/ld-2.2.5.so)
Start...
Stop.
=3D=3D5065=3D=3D
=3D=3D5065=3D=3D ERROR SUMMARY: 5 errors from 5 contexts (suppressed: 0 =
from 0)
=3D=3D5065=3D=3D malloc/free: in use at exit: 10,000 bytes in 10 blocks.
=3D=3D5065=3D=3D malloc/free: 10 allocs, 0 frees, 10,000 bytes =
allocated.
=3D=3D5065=3D=3D For counts of detected errors, rerun with: -v
=3D=3D5065=3D=3D searching for pointers to 10 not-freed blocks.
=3D=3D5065=3D=3D checked 69,120 bytes.
=3D=3D5065=3D=3D
=3D=3D5065=3D=3D
=3D=3D5065=3D=3D 10,000 bytes in 10 blocks are definitely lost in loss =
record 1 of 1
=3D=3D5065=3D=3D at 0x401862A: malloc =
(m_replacemalloc/vg_replace_malloc.c:149)
=3D=3D5065=3D=3D by 0x80483A7: main (in =
/export/localhome/ltameil/Documents/test/jni/ctest)
=3D=3D5065=3D=3D
=3D=3D5065=3D=3D LEAK SUMMARY:
=3D=3D5065=3D=3D definitely lost: 10,000 bytes in 10 blocks.
=3D=3D5065=3D=3D possibly lost: 0 bytes in 0 blocks.
=3D=3D5065=3D=3D still reachable: 0 bytes in 0 blocks.
=3D=3D5065=3D=3D suppressed: 0 bytes in 0 blocks.
=3D=3D5065=3D=3D Reachable blocks (those to which a pointer was found) =
are not shown.
=3D=3D5065=3D=3D To see them, rerun with: --show-reachable=3Dyes
mwlx124>
As far as I know (and as I have experienced so far) the JVM has its own =
memory management mechanism. Is it possible that this mechanism confuses =
Valgrind and that's why it cannot reveal anything?? I know that Valgrind =
should still work in this case too (this is stated on its website) but =
still! Is it possible that Valgrind can't debug Java native methods? (at =
least with this JVM)
Or am I doing something wrong? Do I need special settings??
It would also be useful if someone said: No, Valgrind is not able to =
debug Java native methods... (if this is really the case).
Thanks in advance!
/Tam=E1s
|