Search code examples
javacvalgrindexecvpmemcheck

Prevent valgrind from tracing any java child processes created with execvp


I have a C program in which I make an execvp call out to java like so:

execvp(path_to_java, args);

Where path_to_java="/usr/java/latest/jre/bin/java" and args contains a link to the jar I'm running. I know it is working - I just want to profile the C portion.

I'm trying to run memcheck on it with this command in an attempt to avoid profiling the java child process, while profiling all of the other child processes:

valgrind --leak-check=yes --trace-children=yes --trace-children-skip=*java* myprog >>& LOGFILE

However, among other problems, I see the following in the LOGFILE:

valgrind: No match.

I tried --trace-children-skip=java as well, which didn't cause the "No match" error, but it failed entirely to prevent valgrind from stepping into the java subprocesses.

The reason why I am doing this is that I don't care to profile the java subprocesses, especially because valgrind and the JVM don't play nice. For instance:

==4873== 32,744 bytes in 1 blocks are possibly lost in loss record 946 of 986
==4873==    at 0x4A069EE: malloc (vg_replace_malloc.c:270)
==4873==    by 0x5A455E8: os::malloc(unsigned long, unsigned short, unsigned cha
r*) (in /usr/java/jdk1.7.0_45/jre/lib/amd64/server/libjvm.so)
==4873==    by 0x54D7D32: ChunkPool::allocate(unsigned long, AllocFailStrategy::
AllocFailEnum) (in /usr/java/jdk1.7.0_45/jre/lib/amd64/server/libjvm.so)
==4873==    by 0x54D7950: Arena::grow(unsigned long, AllocFailStrategy::AllocFai
lEnum) (in /usr/java/jdk1.7.0_45/jre/lib/amd64/server/libjvm.so)
==4873==    by 0x56BDCFE: constMethodKlass::allocate(int, int, int, int, int, bo
ol, Thread*) (in /usr/java/jdk1.7.0_45/jre/lib/amd64/server/libjvm.so)
==4873==    by 0x5A3EDF9: oopFactory::new_method(int, AccessFlags, int, int, int
, int, bool, Thread*) (in /usr/java/jdk1.7.0_45/jre/lib/amd64/server/libjvm.so)
==4873==    by 0x563BD38: ClassFileParser::parse_method(constantPoolHandle, bool
, AccessFlags*, typeArrayHandle*, typeArrayHandle*, typeArrayHandle*, Thread*) (
in /usr/java/jdk1.7.0_45/jre/lib/amd64/server/libjvm.so)
==4873==    by 0x563C81B: ClassFileParser::parse_methods(constantPoolHandle, bool, AccessFlags*, bool*, objArrayOopDesc**, objArrayOopDesc**, objArrayOopDesc**, Thread*) (in /usr/java/jdk1.7.0_45/jre/lib/amd64/server/libjvm.so)
==4873==    by 0x563F8B0: ClassFileParser::parseClassFile(Symbol*, Handle, Handle, KlassHandle, GrowableArray<Handle>*, TempNewSymbol&, bool, Thread*) (in /usr/java/jdk1.7.0_45/jre/lib/amd64/server/libjvm.so)
==4873==    by 0x5643BF2: ClassLoader::load_classfile(Symbol*, Thread*) (in /usr/java/jdk1.7.0_45/jre/lib/amd64/server/libjvm.so)
==4873==    by 0x5B4FC86: SystemDictionary::load_instance_class(Symbol*, Handle, Thread*) (in /usr/java/jdk1.7.0_45/jre/lib/amd64/server/libjvm.so)
==4873==    by 0x5B50490: SystemDictionary::resolve_instance_class_or_null(Symbol*, Handle, Handle, Thread*) (in /usr/java/jdk1.7.0_45/jre/lib/amd64/server/libjvm.so)

Owch. What am I doing wrong?


Solution

  • Did you put the *java* pattern into quotes in your command line? Eg. like this:

    valgrind --leak-check=yes --trace-children=yes --trace-children-skip="*java*" myprog >>& LOGFILE

    Otherwise the asterisks will be interpreted by the shell, which will cause the valgrind: No match. message.