24

I want to use Valgrind 3.7.0 to find memory leaks in my Java native code. I'm using jdk1.6.0._29.

To do that, I have to set the --trace-children=yes flag. Setting that flag, I no longer can run valgrind on any java application, even a command like:

valgrind --trace-children=yes --smc-check=all java -version

will get the error message:

   Error occurred during initialization of VM
   Unknown x64 processor: SSE2 not supported

I've seen this link: https://bugs.kde.org/show_bug.cgi?id=249943, but it was not useful.

Running the program without Valgrind or without the --trace-children flag is fine.

Does anyone has any idea on what I can do?

Adi
  • 5,089
  • 6
  • 33
  • 47
RezaPlusPlus
  • 545
  • 1
  • 8
  • 18

2 Answers2

22

You must disable JIT to run the JVM under valgrind, like so:

valgrind java -Djava.compiler=NONE ...

Also, if you end up using generated suppressions (and you most likely will!), there can be a problem with the depth of the call stacks in the generated suppressions, which is more likely to occur when running under the JVM.

In recent versions of valgrind, generated suppressions can contain deeper call stacks than can be processed by valgrind/memcheck itself. The symptom of this problem is that valgrind terminates unexpectedly with the message "too many callers in stack trace".

This problem is easily fixed: before building valgrind, edit the file coregrind/m_errormgr.c and change the hard-coded value in the #define to a larger value (I use 99):

 /* Max number of callers for context in a suppression. */

 #define VG_MAX_SUPP_CALLERS  99

Then build and install valgrind as per the docs.

valiano
  • 16,433
  • 7
  • 64
  • 79
BillT
  • 731
  • 1
  • 6
  • 10
14

Valgrind traps and emulates (to a degree) the processor, this is seemingly causing the JVM to get confused about your support for SSE and bailing out

I would suggest your try telling the JVM not to bother with SSE, you should be able to turn this off for hotspot with the JVM flag -XX:UseSSE=0

Good luck! valgrinding the JVM is a bit hard as they are somewhat hostile to each other

It might also be your version of valgrind and java I ran your command from above locally and had no problems, using valgrind 3.6.1 and both java 1.6.0_26 and java 1.7.0-b147

Greg Bowyer
  • 1,684
  • 13
  • 14
  • `-XX:UseSSE=0` most likely doesn't work anymore on current versions of the JVM on 64 Bit hardware and OS: `// in 64 bit the use of SSE2 is the minimum if (UseSSE < 2) UseSSE = 2;` https://blog.weghos.com/openjdk/OpenJDK/src/hotspot/cpu/x86/vm_version_x86.cpp.html#594 – Thorsten Schöning Dec 20 '21 at 16:23