diff runtime/fixed_alloc.c @ 119:72c648bca43b

Improved memory debug output and fixed memory leak in Array
author Mike Pavone <pavone@retrodev.com>
date Mon, 18 Oct 2010 00:50:18 -0400
parents 43cc42df26cc
children
line wrap: on
line diff
--- a/runtime/fixed_alloc.c	Fri Oct 15 00:55:02 2010 -0400
+++ b/runtime/fixed_alloc.c	Mon Oct 18 00:50:18 2010 -0400
@@ -45,11 +45,42 @@
 	fflush(stdout);
 }
 
-void print_live_object_types(mem_manager * manager)
+void find_live_objects_oftype(mem_manager * manager, int32_t type_id, void ** output)
 {
 	object * obj;
 	mem_block * cur;
-	int32_t i,j,bitslots,bit,*counts = malloc(sizeof(int32_t)*max_registered_type);
+	int32_t i,j,bitslots,bit,outpos=0;
+	for (i = 0; i < (MAX_SIZE-MIN_SIZE)/STRIDE; i++)
+	{
+		cur = manager->inuse[i];
+		while(cur)
+		{
+			bitslots = max_free[i]/8;
+			if(max_free[i]&7)
+				++bitslots;
+			for(j = 0; j < bitslots; ++j)
+				if(cur->bitmap[j] != 0xFF)
+				{
+					for (bit = 0; bit < 8; ++bit)
+					{
+						if (!(cur->bitmap[j] & (1 << bit)))
+						{
+							obj = (object *)(((char *)cur)+BLOCK_SIZE-(((j*8+bit)+1)*(i*STRIDE+MIN_SIZE)));
+							if(obj->bprint->type_id == type_id)
+								output[outpos++] = obj;
+						}
+					}
+				}
+			cur = cur->next;
+		}
+	}
+}
+
+void get_live_object_counts(mem_manager * manager, int32_t * counts)
+{
+	object * obj;
+	mem_block * cur;
+	int32_t i,j,bitslots,bit;
 	memset(counts, 0, sizeof(int32_t)*max_registered_type);
 	for (i = 0; i < (MAX_SIZE-MIN_SIZE)/STRIDE; i++)
 	{
@@ -74,6 +105,12 @@
 			cur = cur->next;
 		}
 	}
+}
+
+void print_live_object_types(mem_manager * manager)
+{
+	int32_t i,*counts = malloc(sizeof(int32_t)*max_registered_type);
+	get_live_object_counts(manager, counts);
 	for (i = 0; i < max_registered_type; ++i)
 		if(counts[i])
 			printf("%d live objects of type %d\n", counts[i], i);