bug 572678 - valgrind integration with conservative GC. r=nnethercote
authorIgor Bukanov <igor@mir2.org>
Mon, 21 Jun 2010 14:22:32 +0200
changeset 47512 650a162fbb0045cdf623e5d8fa7f9200fb11ac9e
parent 47511 08a8426164c40c44ecd14d810ff18a99553dc324
child 47513 332e161f38db131ce04c87fd1bf3b80b9735fd0d
push id1
push usershaver@mozilla.com
push dateTue, 04 Jan 2011 17:58:04 +0000
reviewersnnethercote
bugs572678
milestone1.9.3a6pre
bug 572678 - valgrind integration with conservative GC. r=nnethercote
js/src/jsgc.cpp
--- a/js/src/jsgc.cpp
+++ b/js/src/jsgc.cpp
@@ -85,16 +85,23 @@
 #include "jsxml.h"
 #endif
 
 #include "jsdtracef.h"
 #include "jscntxtinlines.h"
 #include "jsobjinlines.h"
 #include "jshashtable.h"
 
+#ifdef MOZ_VALGRIND
+# define JS_VALGRIND
+#endif
+#ifdef JS_VALGRIND
+# include <valgrind/memcheck.h>
+#endif
+
 using namespace js;
 
 /*
  * Check that JSTRACE_XML follows JSTRACE_OBJECT, JSTRACE_DOUBLE and
  * JSTRACE_STRING.
  */
 JS_STATIC_ASSERT(JSTRACE_OBJECT == 0);
 JS_STATIC_ASSERT(JSTRACE_DOUBLE == 1);
@@ -1101,16 +1108,26 @@ ConservativeGCStackMarker::dumpConservat
     if (fp != stdout && fp != stderr)
         fclose(fp);
 }
 #endif /* JS_DUMP_CONSERVATIVE_GC_ROOTS */
 
 void
 ConservativeGCStackMarker::markWord(jsuword w)
 {
+    /*
+     * The conservative scanner may access words that valgrind considers as
+     * undefined. To avoid false positives and not to alter valgrind view of
+     * the memory we make as memcheck-defined the argument, a copy of the
+     * original word. See bug 572678.
+     */
+#ifdef JS_VALGRIND
+    VALGRIND_MAKE_MEM_DEFINED(&w, sizeof(w));
+#endif
+
 #define RETURN(x) do { CONSERVATIVE_METER(stats.x++); return; } while (0)
     /*
      * We assume that the compiler never uses sub-word alignment to store
      * pointers and does not tag pointers on its own. Thus we exclude words
      * with JSVAL_INT (any odd words) or JSVAL_SPECIAL tags as they never
      * point to GC things. We also exclude words with a double tag that point
      * into a non-double. But, for example, on 32-bit platforms we cannot
      * exclude a pointer into an object arena tagged with JSVAL_STRING. The