ARM: Improve memory instruction disassembly.
[gem5.git] / src / base / fast_alloc.cc
index 3e43ad94cebf3b3e977adfd75fbfe3bd4c6f4bbb..0238f03cbc7eef9a0f4cdbb4a4a13432699dec94 100644 (file)
@@ -34,7 +34,8 @@
  * by permission.
  */
 
-#include <assert.h>
+#include <cassert>
+
 #include "base/fast_alloc.hh"
 
 #if !NO_FAST_ALLOC
@@ -51,7 +52,8 @@ unsigned FastAlloc::deleteCount[Num_Buckets];
 unsigned FastAlloc::allocCount[Num_Buckets];
 #endif
 
-void *FastAlloc::moreStructs(int bucket)
+void *
+FastAlloc::moreStructs(int bucket)
 {
     assert(bucket > 0 && bucket < Num_Buckets);
 
@@ -71,14 +73,14 @@ void *FastAlloc::moreStructs(int bucket)
     return (p + sz);
 }
 
-
 #if FAST_ALLOC_DEBUG
 
-#include <typeinfo>
-#include <iostream>
-#include <iomanip>
 #include <map>
 #include <string>
+#include <typeinfo>
+
+#include "base/cprintf.hh"
+#include "sim/core.hh"   // for curTick
 
 using namespace std;
 
@@ -97,12 +99,12 @@ FastAlloc::FastAlloc(FastAlloc *prev, FastAlloc *next)
     inUseNext = next;
 }
 
-
 // constructor: marks as in use, add to in-use list
 FastAlloc::FastAlloc()
 {
     // mark this object in use
     inUse = true;
+    whenAllocated = curTick;
 
     // update count
     ++numInUse;
@@ -132,6 +134,12 @@ FastAlloc::~FastAlloc()
 }
 
 
+// Note that in all the display functions below we suppress anything
+// with a zero allocation timestamp... there are a bunch of static or
+// quasi-static structures that get allocated during initialization
+// and we generally don't care about them so this gets them out of the
+// way.
+
 // summarize in-use list
 void
 FastAlloc::dump_summary()
@@ -140,17 +148,16 @@ FastAlloc::dump_summary()
 
     for (FastAlloc *p = inUseHead.inUseNext; p != &inUseHead; p = p->inUseNext)
     {
-        ++typemap[typeid(*p).name()];
+        if (p->whenAllocated != 0)
+            ++typemap[typeid(*p).name()];
     }
 
     map<string, int>::const_iterator mapiter;
 
-    cout << " count  type\n"
-         << " -----  ----\n";
+    cprintf(" count  type\n"
+            " -----  ----\n");
     for (mapiter = typemap.begin(); mapiter != typemap.end(); ++mapiter)
-    {
-        cout << setw(6) << mapiter->second << "  " << mapiter->first << endl;
-    }
+        cprintf("%6d  %s\n",mapiter->second, mapiter->first);
 }
 
 
@@ -160,18 +167,42 @@ FastAlloc::dump_oldest(int n)
 {
     // sanity check: don't want to crash the debugger if you forget to
     // pass in a parameter
-    if (n < 0 || n > numInUse)
-    {
-        cout << "FastAlloc::dump_oldest: bad arg " << n
-             << " (" << numInUse << " objects in use" << endl;
+    if (n < 0 || n > numInUse) {
+        cprintf("FastAlloc::dump_oldest: bad arg %d (%d objects in use)\n",
+                n, numInUse);
         return;
     }
 
     for (FastAlloc *p = inUseHead.inUseNext;
          p != &inUseHead && n > 0;
-         p = p->inUseNext, --n)
-    {
-        cout << p << " " << typeid(*p).name() << endl;
+         p = p->inUseNext, --n) {
+        if (p->whenAllocated != 0)
+            cprintf("%x %15d %s\n", p, p->whenAllocated, typeid(*p).name());
+    }
+}
+
+
+// show oldest n items on in-use list for specified type
+void
+FastAlloc::dump_oldest_of_type(int n, const char *type_name)
+{
+    // sanity check: don't want to crash the debugger if you forget to
+    // pass in a parameter
+    if (n < 0 || n > numInUse) {
+        cprintf("FastAlloc::dump_oldest_of_type: bad arg %d "
+                "(%d objects in use)\n",
+                n, numInUse);
+        return;
+    }
+
+    for (FastAlloc *p = inUseHead.inUseNext;
+         p != &inUseHead && n > 0;
+         p = p->inUseNext) {
+        if (p->whenAllocated != 0 &&
+            strcmp(typeid(*p).name(), type_name) == 0) {
+            cprintf("%x %15d\n", p, p->whenAllocated);
+            --n;
+        }
     }
 }
 
@@ -192,6 +223,6 @@ fast_alloc_oldest(int n)
     FastAlloc::dump_oldest(n);
 }
 
-#endif
+#endif // FAST_ALLOC_DEBUG
 
 #endif // NO_FAST_ALLOC