valgrind-annotations
author Benjamin Smedberg <benjamin@smedbergs.us>
Sun, 20 Apr 2008 21:43:09 -0400
changeset 42 53c5098cb79e0223016b6901194a89d913f235fb
parent 41 84ba4253dc28a9bce6153579cee311af1278267c
permissions -rw-r--r--
Updates and imports

Add valgrind annotations for MMgc allocations. Note that there are some extraneous changes to set the current work queue correctly... I need to split those hunks out :-(
* * *

diff --git a/MMgc/FixedMalloc.cpp b/MMgc/FixedMalloc.cpp
--- a/MMgc/FixedMalloc.cpp
+++ b/MMgc/FixedMalloc.cpp
@@ -126,6 +126,8 @@
 
 	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
@@ -164,6 +166,7 @@
 			FixedAllocSafe *a = m_allocs[i];
 			delete a;
 		}		
+		VALGRIND_DESTROY_MEMPOOL(this);
 	}
 
 	size_t FixedMalloc::Allocated()
diff --git a/MMgc/FixedMalloc.h b/MMgc/FixedMalloc.h
--- a/MMgc/FixedMalloc.h
+++ b/MMgc/FixedMalloc.h
@@ -38,6 +38,8 @@
 #ifndef __Malloc__
 #define __Malloc__
 
+#include <valgrind/memcheck.h>
+#include <stdio.h>
 
 namespace MMgc
 {
@@ -73,6 +75,9 @@
 			} 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;
 		}
 
@@ -80,6 +85,8 @@
 		{
 			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 --git a/MMgc/GC.cpp b/MMgc/GC.cpp
--- a/MMgc/GC.cpp
+++ b/MMgc/GC.cpp
@@ -106,6 +106,8 @@
 #include <sys/stack.h>
 extern "C" greg_t _getsp(void);
 #endif
+
+#include <valgrind/memcheck.h>
 
 namespace MMgc
 {
@@ -289,7 +291,9 @@
 		GCAssert (sizeof(sintptr) == 4);
 		GCAssert (sizeof(uintptr) == 4);	
 		#endif		
-	
+
+		VALGRIND_CREATE_MEMPOOL(this, 0, 0);
+
 #ifdef MMGC_DRC
 		zct.gc = this;
 #endif
@@ -405,6 +409,8 @@
 		while(m_callbacks) {
 			m_callbacks->Destroy();			
 		}
+
+		VALGRIND_DESTROY_MEMPOOL(this);
 	}
 
 	void GC::Collect()
@@ -744,6 +750,12 @@
 			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;
 	}
@@ -1529,6 +1541,8 @@
 		{
 			const void *val = GC::Pointer(*p++);	
 			
+			int valhandle = VALGRIND_MAKE_MEM_DEFINED(&val, sizeof(val));
+
 			if(val < _memStart || val >= _memEnd)
 				continue;
 
@@ -1544,6 +1558,8 @@
 				RCObject *obj = (RCObject*)val;
 				obj->Pin();
 			}
+
+			VALGRIND_DISCARD(valhandle);
 		}
 	}
 			
@@ -2495,6 +2511,8 @@
 		while(p < end) 
 		{
 			uintptr val = *p++;  
+			
+			int valhandle = VALGRIND_MAKE_MEM_DEFINED(&val, sizeof(val));
 
 			if(val < _memStart || val >= _memEnd)
 				continue;
@@ -2506,6 +2524,8 @@
 			{
 				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;
@@ -2649,6 +2669,8 @@
 					#endif
 				}
 			}
+
+			VALGRIND_DISCARD(valhandle);
 		}
 	}
 
diff --git a/MMgc/GCAlloc.cpp b/MMgc/GCAlloc.cpp
--- a/MMgc/GCAlloc.cpp
+++ b/MMgc/GCAlloc.cpp
@@ -711,5 +711,7 @@
 #endif
 		// Add this item to the free list
 		*((void**)item) = oldFree;	
+
+                VALGRIND_MEMPOOL_FREE(GC::GetGC(item), GetUserPointer(item));
 	}
 }
diff --git a/MMgc/GCHeap.cpp b/MMgc/GCHeap.cpp
--- a/MMgc/GCHeap.cpp
+++ b/MMgc/GCHeap.cpp
@@ -39,6 +39,8 @@
 #include <string.h>
 
 #include "MMgc.h"
+
+#include <valgrind/memcheck.h>
 
 #if defined(DARWIN) || defined(MMGC_ARM) || defined (MMGC_SPARC)
 #include <stdlib.h>
@@ -190,6 +192,9 @@
 			if (!block) {
 				return NULL;
 			}
+
+                        VALGRIND_MAKE_MEM_NOACCESS(block->baseAddr,
+                                                   block->size * kBlockSize);
 
 			GCAssert(block->size == size);
 			
diff --git a/MMgc/GCLargeAlloc.cpp b/MMgc/GCLargeAlloc.cpp
--- a/MMgc/GCLargeAlloc.cpp
+++ b/MMgc/GCLargeAlloc.cpp
@@ -100,6 +100,8 @@
 
 		if(b->flags & kHasWeakRef)
 			b->gc->ClearWeakRef(GetUserPointer(item));
+
+                VALGRIND_MEMPOOL_FREE(b->gc, GetUserPointer(item));
 
 		LargeBlock **prev = &m_blocks;
 		while(*prev)