support to print out size of garbage
authorbdemsky <bdemsky>
Tue, 2 Jun 2009 01:55:20 +0000 (01:55 +0000)
committerbdemsky <bdemsky>
Tue, 2 Jun 2009 01:55:20 +0000 (01:55 +0000)
Robust/src/Runtime/garbage.c

index 168921715addc9dd9c114857bca4943e7aac25c4..88bbdd3dc6726a6475292a584fb41835cb8b4891 100644 (file)
@@ -39,6 +39,11 @@ extern struct ctable *reverse;
 extern struct RuntimeHash *fdtoobject;
 #endif
 
+#ifdef GARBAGESTATS
+#define MAXSTATS 500
+long garbagearray[MAXSTATS];
+#endif
+
 #if defined(THREADS) || defined(DSTM) || defined(STM)
 int needtocollect=0;
 struct listitem * list=NULL;
@@ -287,6 +292,14 @@ void collect(struct garbagelist * stackptr) {
   }
 #endif
 
+#ifdef GARBAGESTATS
+  {
+    int i;
+    for(i=0;i<MAXSTATS;i++)
+      garbagearray[i]=0;
+  }
+#endif
+
   if (head==NULL) {
     headindex=0;
     tailindex=0;
@@ -748,6 +761,13 @@ void * mygcmalloc(struct garbagelist * stackptr, int size) {
     printf("Garbage collected: Old bytes: %u\n", curr_heapptr-curr_heapbase);
     printf("New space: %u\n", to_heapptr-to_heapbase);
     printf("Total space: %u\n", to_heaptop-to_heapbase);
+    {
+      int i;
+      for(i=0;i<MAXSTATS;i++) {
+       if (garbagearray[i]!=0)
+         printf("Type=%d Size=%u\n", i, garbagearray[i]);
+      }
+    }
 #endif
     /* Flip to/curr heaps */
     {
@@ -808,6 +828,9 @@ int gc_createcopy(void * orig, void ** copy_ptr) {
       int size=classsize[type];
       void *newobj=tomalloc(size);
       memcpy(newobj, orig, size);
+#endif
+#ifdef GARBAGESTATS
+      garbagearray[type]+=size;
 #endif
       ((int *)orig)[0]=-1;
       ((void **)orig)[1]=newobj;
@@ -828,7 +851,9 @@ int gc_createcopy(void * orig, void ** copy_ptr) {
       void *newobj=tomalloc(size);
       memcpy(newobj, orig, size);
 #endif
-
+#ifdef GARBAGESTATS
+      garbagearray[type]+=size;
+#endif
       ((int *)orig)[0]=-1;
       ((void **)orig)[1]=newobj;
       *copy_ptr=newobj;