tamarin-valgrind-annotations
author Benjamin Smedberg <benjamin@smedbergs.us>
Sat, 26 Jul 2008 22:49:39 -0400
changeset 167 a4da40849f5436e629c5732f4368c6c48189637f
parent 149 13eaa3adde4be1d470346a98e7cc7ab6b2ada1c8
permissions -rw-r--r--
State as of now

diff -r 79f2cd0cee5f js/tamarin/MMgc/FixedMalloc.cpp
--- a/js/tamarin/MMgc/FixedMalloc.cpp	Wed Jul 02 13:36:19 2008 -0700
+++ b/js/tamarin/MMgc/FixedMalloc.cpp	Wed Jul 02 13:38:48 2008 -0700
@@ -127,6 +127,8 @@ namespace MMgc
 
 	FixedMalloc::FixedMalloc(GCHeap* heap)
 	{
+		VALGRIND_CREATE_MEMPOOL(this, 0, 1);
+
 		m_heap = heap;
 		// Create all the allocators up front (not lazy)
 		// so that we don't have to check the pointers for
@@ -165,6 +167,7 @@ namespace MMgc
 			FixedAllocSafe *a = m_allocs[i];
 			delete a;
 		}		
+		VALGRIND_DESTROY_MEMPOOL(this);
 	}
 
 	size_t FixedMalloc::Allocated()
diff -r 79f2cd0cee5f js/tamarin/MMgc/FixedMalloc.h
--- a/js/tamarin/MMgc/FixedMalloc.h	Wed Jul 02 13:36:19 2008 -0700
+++ b/js/tamarin/MMgc/FixedMalloc.h	Wed Jul 02 13:38:48 2008 -0700
@@ -39,6 +39,8 @@
 #ifndef __Malloc__
 #define __Malloc__
 
+#include <valgrind/memcheck.h>
+#include <stdio.h>
 
 namespace MMgc
 {
@@ -74,6 +76,9 @@ namespace MMgc
 			} else {
 				item = LargeAlloc(size);
 			}
+                        VALGRIND_MEMPOOL_ALLOC(this, item, size);
+			VALGRIND_CHECK_MEM_IS_DEFINED(item, size);
+			fprintf(stderr, "FixedMalloc::Alloc = %p\n", item);
 			return item;
 		}
 
@@ -81,6 +86,8 @@ namespace MMgc
 		{
 			if(item == 0)
 				return;
+
+			VALGRIND_MEMPOOL_FREE(this, item);
 
 			// small things are never allocated on the 4K boundary b/c the block
 			// header structure is stored there, large things always are		
diff -r 79f2cd0cee5f js/tamarin/MMgc/GC.cpp
--- a/js/tamarin/MMgc/GC.cpp	Wed Jul 02 13:36:19 2008 -0700
+++ b/js/tamarin/MMgc/GC.cpp	Wed Jul 02 13:38:48 2008 -0700
@@ -106,6 +106,8 @@
 #include <sys/stack.h>
 extern "C" greg_t _getsp(void);
 #endif
+
+#include <valgrind/memcheck.h>
 
 namespace MMgc
 {
@@ -287,7 +289,9 @@ namespace MMgc
 		GCAssert (sizeof(sintptr) == 4);
 		GCAssert (sizeof(uintptr) == 4);	
 		#endif		
-	
+
+		VALGRIND_CREATE_MEMPOOL(this, 0, 0);
+
 #ifdef MMGC_DRC
 		zct.gc = this;
 #endif
@@ -403,6 +407,8 @@ namespace MMgc
 		while(m_callbacks) {
 			m_callbacks->Destroy();			
 		}
+
+		VALGRIND_DESTROY_MEMPOOL(this);
 	}
 
 	void GC::Collect()
@@ -724,6 +730,12 @@ namespace MMgc
 			memset(item, 0, Size(item));
 		}
 #endif
+
+		VALGRIND_MEMPOOL_ALLOC(this, item, size);
+		if (flags & kZero) {
+			int h = VALGRIND_MAKE_MEM_DEFINED(item, size);
+			VALGRIND_DISCARD(h);
+		}
 
 		return item;
 	}
@@ -1492,6 +1504,8 @@ bail:
 		{
 			const void *val = GC::Pointer(*p++);	
 			
+			int valhandle = VALGRIND_MAKE_MEM_DEFINED(&val, sizeof(val));
+
 			if(val < _memStart || val >= _memEnd)
 				continue;
 
@@ -1507,6 +1521,8 @@ bail:
 				RCObject *obj = (RCObject*)val;
 				obj->Pin();
 			}
+
+			VALGRIND_DISCARD(valhandle);
 		}
 	}
 			
@@ -2436,6 +2452,8 @@ bail:
 		while(p < end) 
 		{
 			uintptr val = *p++;  
+			
+			int valhandle = VALGRIND_MAKE_MEM_DEFINED(&val, sizeof(val));
 
 			if(val < _memStart || val >= _memEnd)
 				continue;
@@ -2447,6 +2465,8 @@ bail:
 			{
 				const void *item;
 				GCAlloc::GCBlock *block = (GCAlloc::GCBlock*) (val & ~0xFFF);
+
+				VALGRIND_CHECK_MEM_IS_DEFINED(&block, sizeof(GCAlloc::GCBlock*));
 
 #ifdef MMGC_INTERIOR_PTRS
 				item = (void*) val;
@@ -2590,6 +2610,8 @@ bail:
 					#endif
 				}
 			}
+
+			VALGRIND_DISCARD(valhandle);
 		}
 	}
 
diff -r 79f2cd0cee5f js/tamarin/MMgc/GCAlloc.cpp
--- a/js/tamarin/MMgc/GCAlloc.cpp	Wed Jul 02 13:36:19 2008 -0700
+++ b/js/tamarin/MMgc/GCAlloc.cpp	Wed Jul 02 13:38:48 2008 -0700
@@ -712,5 +712,7 @@ start:
 #endif
 		// Add this item to the free list
 		*((void**)item) = oldFree;	
+
+                VALGRIND_MEMPOOL_FREE(GC::GetGC(item), GetUserPointer(item));
 	}
 }
diff -r 79f2cd0cee5f js/tamarin/MMgc/GCHeap.cpp
--- a/js/tamarin/MMgc/GCHeap.cpp	Wed Jul 02 13:36:19 2008 -0700
+++ b/js/tamarin/MMgc/GCHeap.cpp	Wed Jul 02 13:38:48 2008 -0700
@@ -40,6 +40,8 @@
 #include <string.h>
 
 #include "MMgc.h"
+
+#include <valgrind/memcheck.h>
 
 #if defined(DARWIN) || defined(MMGC_ARM) || defined (MMGC_SPARC)
 #include <stdlib.h>
@@ -191,6 +193,9 @@ namespace MMgc
 			if (!block) {
 				return NULL;
 			}
+
+                        VALGRIND_MAKE_MEM_NOACCESS(block->baseAddr,
+                                                   block->size * kBlockSize);
 
 			GCAssert(block->size == size);
 			
diff -r 79f2cd0cee5f js/tamarin/MMgc/GCLargeAlloc.cpp
--- a/js/tamarin/MMgc/GCLargeAlloc.cpp	Wed Jul 02 13:36:19 2008 -0700
+++ b/js/tamarin/MMgc/GCLargeAlloc.cpp	Wed Jul 02 13:38:48 2008 -0700
@@ -101,6 +101,8 @@ namespace MMgc
 
 		if(b->flags & kHasWeakRef)
 			b->gc->ClearWeakRef(GetUserPointer(item));
+
+                VALGRIND_MEMPOOL_FREE(b->gc, GetUserPointer(item));
 
 		LargeBlock **prev = &m_blocks;
 		while(*prev)