Using Valgrind with Julia

    By default, Valgrind assumes that there is no self modifying code in the programs it runs. This assumption works fine in most instances but fails miserably for a just-in-time compiler like . For this reason it is crucial to pass —smc-check=all-non-file to valgrind, else code may crash or behave unexpectedly (often in subtle ways).

    In some cases, to better detect memory errors using Valgrind it can help to compile julia with memory pools disabled. The compile-time flag MEMDEBUG disables memory pools in Julia, and MEMDEBUG2 disables memory pools in FemtoLisp. To build with both flags, add the following line to Make.user:

    Valgrind will typically display spurious warnings as it runs. To reduce the number of such warnings, it helps to provide a to Valgrind. A sample suppressions file is included in the Julia source distribution at contrib/valgrind-julia.supp.

    The suppressions file can be used from the julia/ source directory as follows:

    It is possible to run the entire Julia test suite under Valgrind, but it does take quite some time (typically several hours). To do so, run the following command from the directory:

    If you would like to see a report of "definite" memory leaks, pass the flags —leak-check=full —show-leak-kinds=definite to valgrind as well.

    In general, if after setting —smc-check=all-non-file you find that your program behaves differently when run under Valgrind, it may help to pass —tool=none to valgrind as you investigate further. This will enable the minimal Valgrind machinery but will also run much faster than when the full memory checker is enabled.