Backed out changeset fc66e3f4afc9
authorGraydon Hoare <graydon@mozilla.com>
Thu, 30 Jul 2009 14:27:10 -0700
changeset 31070 feacec8b4be911ce007e21a55d8d9e86521ac45a
parent 31069 2af280eb0faa3b0cd0dec1ae44b5304575fa98ee
child 31071 2bb711bd54dff2a9bb895f2288eee61257afec0c
push id8354
push userrsayre@mozilla.com
push dateMon, 03 Aug 2009 17:31:38 +0000
treeherdermozilla-central@d300a4725056 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
milestone1.9.2a1pre
backs outfc66e3f4afc94267d8907ba4f2d4b0593ffccbba
Backed out changeset fc66e3f4afc9
js/src/nanojit/LIR.cpp
js/src/nanojit/LIR.h
js/src/nanojit/avmplus.h
--- a/js/src/nanojit/LIR.cpp
+++ b/js/src/nanojit/LIR.cpp
@@ -1601,50 +1601,75 @@ namespace nanojit
 
             if (e->i->isGuard() || e->i->isBranch() || e->i->isRet()) {
                 logc->printf("\n");
                 newblock = true;
             }
         }
     }
 
-    void LirNameMap::addName(LInsp i, const char* name) {
+    LabelMap::Entry::~Entry()
+    {
+    }
+
+    LirNameMap::Entry::~Entry()
+    {
+    }
+
+    LirNameMap::~LirNameMap()
+    {
+        Entry *e;
+
+        while ((e = names.removeLast()) != NULL) {
+            labels->core->freeString(e->name);
+            NJ_DELETE(e);
+        }
+    }
+
+    bool LirNameMap::addName(LInsp i, Stringp name) {
         if (!names.containsKey(i)) {
-            char *copy = new (allocator) char[VMPI_strlen(name)+1];
-            VMPI_strcpy(copy, name);
-            Entry *e = new (allocator) Entry(copy);
+            Entry *e = NJ_NEW(labels->core->gc, Entry)(name);
             names.put(i, e);
+            return true;
+        }
+        return false;
+    }
+    void LirNameMap::addName(LInsp i, const char *name) {
+        Stringp new_name = labels->core->newString(name);
+        if (!addName(i, new_name)) {
+            labels->core->freeString(new_name);
         }
     }
 
     void LirNameMap::copyName(LInsp i, const char *s, int suffix) {
         char s2[200];
         if (isdigit(s[strlen(s)-1])) {
             // if s ends with a digit, add '_' to clarify the suffix
-            VMPI_sprintf(s2,"%s_%d", s, suffix);
+            sprintf(s2,"%s_%d", s, suffix);
         } else {
-            VMPI_sprintf(s2,"%s%d", s, suffix);
+            sprintf(s2,"%s%d", s, suffix);
         }
-        addName(i, s2);
+        addName(i, labels->core->newString(s2));
     }
 
     void LirNameMap::formatImm(int32_t c, char *buf) {
         if (c >= 10000 || c <= -10000)
             sprintf(buf,"#%s",labels->format((void*)c));
         else
             sprintf(buf,"%d", c);
     }
 
     const char* LirNameMap::formatRef(LIns *ref)
     {
         char buffer[200], *buf=buffer;
         buf[0]=0;
+        GC *gc = labels->core->gc;
         if (names.containsKey(ref)) {
-            const char* name = names.get(ref)->name;
-            VMPI_strcat(buf, name);
+            StringNullTerminatedUTF8 cname(gc, names.get(ref)->name);
+            strcat(buf, cname.c_str());
         }
         else if (ref->isconstq()) {
 #if defined NANOJIT_64BIT
             sprintf(buf, "#0x%lx", (nj_printf_ld)ref->imm64());
 #else
             formatImm(ref->imm64_1(), buf);
             buf += strlen(buf);
             *buf++ = ':';
@@ -1665,18 +1690,18 @@ namespace nanojit
                     copyName(ref, ref->callInfo()->_name, funccounts.add(ref->callInfo()));
 #if !defined NANOJIT_64BIT
                 }
 #endif
             } else {
                 NanoAssert(size_t(ref->opcode()) < sizeof(lirNames) / sizeof(lirNames[0]));
                 copyName(ref, lirNames[ref->opcode()], lircounts.add(ref->opcode()));
             }
-            const char* name = names.get(ref)->name;
-            VMPI_strcat(buf, name);
+            StringNullTerminatedUTF8 cname(gc, names.get(ref)->name);
+            strcat(buf, cname.c_str());
         }
         return labels->dup(buffer);
     }
 
     const char* LirNameMap::formatIns(LIns* i)
     {
         char sbuf[200];
         char *s = sbuf;
@@ -2198,83 +2223,92 @@ namespace nanojit
             exprs.clear();
         return out->ins0(op);
     }
 
     #endif /* FEATURE_NANOJIT */
 
 #if defined(NJ_VERBOSE)
     LabelMap::LabelMap(AvmCore *core, nanojit::Allocator& a)
-        : allocator(a), names(core->gc), addrs(core->config.verbose_addrs), end(buf)
+        : allocator(a), names(core->gc), addrs(core->config.verbose_addrs), end(buf), core(core)
     {}
 
     LabelMap::~LabelMap()
     {
         clear();
     }
 
     void LabelMap::clear()
     {
-        // don't free entries since they're owned by Allocator
-        names.clear();
+        Entry *e;
+        while ((e = names.removeLast()) != NULL) {
+            core->freeString(e->name);
+            NJ_DELETE(e);
+        }
     }
 
     void LabelMap::add(const void *p, size_t size, size_t align, const char *name)
     {
         if (!this || names.containsKey(p))
             return;
-        char* copy = new (allocator) char[VMPI_strlen(name)+1];
-        VMPI_strcpy(copy, name);
-        Entry *e = new (allocator) Entry(copy, size << align, align);
+        add(p, size, align, core->newString(name));
+    }
+
+    void LabelMap::add(const void *p, size_t size, size_t align, Stringp name)
+    {
+        if (!this || names.containsKey(p))
+            return;
+        Entry *e = NJ_NEW(core->gc, Entry)(name, size<<align, align);
         names.put(p, e);
     }
 
     const char *LabelMap::format(const void *p)
     {
         char b[200];
         int i = names.findNear(p);
         if (i >= 0) {
             const void *start = names.keyAt(i);
             Entry *e = names.at(i);
             const void *end = (const char*)start + e->size;
-            const char *name = e->name;
+            avmplus::StringNullTerminatedUTF8 cname(core->gc, e->name);
+            const char *name = cname.c_str();
             if (p == start) {
                 if (addrs)
-                    VMPI_sprintf(b,"%p %s",p,name);
+                    sprintf(b,"%p %s",p,name);
                 else
-                    VMPI_strcpy(b, name);
+                    strcpy(b, name);
                 return dup(b);
             }
             else if (p > start && p < end) {
                 int32_t d = int32_t(intptr_t(p)-intptr_t(start)) >> e->align;
                 if (addrs)
-                    VMPI_sprintf(b, "%p %s+%d", p, name, d);
+                    sprintf(b, "%p %s+%d", p, name, d);
                 else
-                    VMPI_sprintf(b,"%s+%d", name, d);
+                    sprintf(b,"%s+%d", name, d);
                 return dup(b);
             }
             else {
-                VMPI_sprintf(b, "%p", p);
+                sprintf(b, "%p", p);
                 return dup(b);
             }
         }
-        VMPI_sprintf(b, "%p", p);
+        sprintf(b, "%p", p);
         return dup(b);
     }
 
     const char *LabelMap::dup(const char *b)
     {
-        size_t need = VMPI_strlen(b)+1;
+        size_t need = strlen(b)+1;
         char *s = end;
         end += need;
         if (end > buf+sizeof(buf)) {
             s = buf;
             end = s+need;
         }
-        VMPI_strcpy(s, b);
+        strcpy(s, b);
         return s;
     }
 
     // ---------------------------------------------------------------
     // START debug-logging definitions
     // ---------------------------------------------------------------
 
     void LogControl::printf( const char* format, ... )
--- a/js/src/nanojit/LIR.h
+++ b/js/src/nanojit/LIR.h
@@ -848,31 +848,35 @@ namespace nanojit
     extern const char* lirNames[];
 
     /**
      * map address ranges to meaningful names.
      */
     class LabelMap MMGC_SUBCLASS_DECL
     {
         Allocator& allocator;
-        class Entry
+        class Entry MMGC_SUBCLASS_DECL
         {
         public:
-            Entry(char *n, size_t s, size_t a) : name(n),size(s),align(a) {}
-            char* name;
+            Entry(int) : name(0), size(0), align(0) {}
+            Entry(avmplus::String *n, size_t s, size_t a) : name(n),size(s),align(a) {}
+            ~Entry();
+            DRCWB(avmplus::String*) name;
             size_t size:29, align:3;
         };
-        avmplus::SortedMap<const void*, Entry*, avmplus::LIST_NonGCObjects> names;
+        avmplus::SortedMap<const void*, Entry*, avmplus::LIST_GCObjects> names;
         bool addrs, pad[3];
         char buf[1000], *end;
         void formatAddr(const void *p, char *buf);
     public:
-        LabelMap(AvmCore* core, Allocator& allocator);
+        avmplus::AvmCore *core;
+        LabelMap(avmplus::AvmCore *, Allocator& allocator);
         ~LabelMap();
         void add(const void *p, size_t size, size_t align, const char *name);
+        void add(const void *p, size_t size, size_t align, avmplus::String*);
         const char *dup(const char *);
         const char *format(const void *p);
         void clear();
     };
 
     class LirNameMap MMGC_SUBCLASS_DECL
     {
         Allocator& allocator;
@@ -888,36 +892,40 @@ namespace nanojit
                 }
                 put(k,c);
                 return c;
             }
         };
         CountMap<int> lircounts;
         CountMap<const CallInfo *> funccounts;
 
-        class Entry
+        class Entry MMGC_SUBCLASS_DECL
         {
         public:
-            Entry(char* n) : name(n) {}
-            char* name;
+            Entry(int) : name(0) {}
+            Entry(avmplus::String *n) : name(n) {}
+            ~Entry();
+            DRCWB(avmplus::String*) name;
         };
-        avmplus::SortedMap<LInsp, Entry*, avmplus::LIST_NonGCObjects> names;
+        avmplus::SortedMap<LInsp, Entry*, avmplus::LIST_GCObjects> names;
         LabelMap *labels;
         void formatImm(int32_t c, char *buf);
     public:
 
         LirNameMap(GC *gc, Allocator& allocator, LabelMap *r)
             : allocator(allocator),
             lircounts(gc),
             funccounts(gc),
             names(gc),
             labels(r)
         {}
+        ~LirNameMap();
 
         void addName(LInsp i, const char *s);
+        bool addName(LInsp i, avmplus::String *s);
         void copyName(LInsp i, const char *s, int suffix);
         const char *formatRef(LIns *ref);
         const char *formatIns(LInsp i);
         void formatGuard(LInsp i, char *buf);
     };
 
 
     class VerboseWriter : public LirWriter
--- a/js/src/nanojit/avmplus.h
+++ b/js/src/nanojit/avmplus.h
@@ -283,21 +283,16 @@ namespace MMgc {
 
 #define DWB(x) x
 #define DRCWB(x) x
 #define WB(gc, container, addr, value) do { *(addr) = (value); } while(0)
 #define WBRC(gc, container, addr, value) do { *(addr) = (value); } while(0)
 
 #define MMGC_MEM_TYPE(x)
 
-#define VMPI_strlen strlen
-#define VMPI_strcat strcat
-#define VMPI_strcpy strcpy
-#define VMPI_sprintf sprintf
-
 extern void VMPI_setPageProtection(void *address,
                                    size_t size,
                                    bool executableFlag,
                                    bool writeableFlag);
 
 namespace avmplus {
 
     using namespace MMgc;