Bug 510545 - Convert LInsHashSet to use Allocator instead of GC, r=gal.
authorEdwin Smith <edwsmith@adobe.com>
Thu, 06 Aug 2009 09:41:07 -0400
changeset 31826 ae4a9225ddcf6bc3a94519751f19982f7592c99d
parent 31825 d8e4676dc10e0b8809151d635298a3a124ecb243
child 31827 a2ab5097c5e504ad4cebf2f0826d0d925adcabdb
child 31831 553ce86e72dbd430e979e5387c76ae32967cb79f
push id8746
push userrsayre@mozilla.com
push dateTue, 25 Aug 2009 16:53:43 +0000
treeherdermozilla-central@189759c41621 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgal
bugs510545
milestone1.9.2a2pre
Bug 510545 - Convert LInsHashSet to use Allocator instead of GC, r=gal.
js/src/jstracer.cpp
js/src/nanojit/LIR.cpp
js/src/nanojit/LIR.h
--- a/js/src/jstracer.cpp
+++ b/js/src/jstracer.cpp
@@ -1741,17 +1741,17 @@ TraceRecorder::TraceRecorder(JSContext* 
                = new (&gc) VerboseWriter(*traceMonitor->allocator, lir,
                                          lirbuf->names, &js_LogController);
         }
     )
     if (nanojit::AvmCore::config.soft_float)
         lir = float_filter = new (&gc) SoftFloatFilter(lir);
     else
         float_filter = 0;
-    lir = cse_filter = new (&gc) CseFilter(lir, &gc);
+    lir = cse_filter = new (&gc) CseFilter(lir, *traceMonitor->allocator);
     lir = expr_filter = new (&gc) ExprFilter(lir);
     lir = func_filter = new (&gc) FuncFilter(lir);
     lir->ins0(LIR_start);
 
     if (!nanojit::AvmCore::config.tree_opt || fragment->root == fragment)
         lirbuf->state = addName(lir->insParam(0, 0), "state");
 
     lirbuf->sp = addName(lir->insLoad(LIR_ldp, lirbuf->state, (int)offsetof(InterpState, sp)), "sp");
--- a/js/src/nanojit/LIR.cpp
+++ b/js/src/nanojit/LIR.cpp
@@ -104,18 +104,17 @@ namespace nanojit
 
 #ifdef NJ_PROFILE
     // @todo fixup move to nanojit.h
     #undef counter_value
     #define counter_value(x)        x
 #endif /* NJ_PROFILE */
 
     // LCompressedBuffer
-    LirBuffer::LirBuffer(Allocator& alloc)
-        :
+    LirBuffer::LirBuffer(Allocator& alloc) :
 #ifdef NJ_VERBOSE
           names(NULL),
 #endif
           abi(ABI_FASTCALL), state(NULL), param1(NULL), sp(NULL), rp(NULL),
           _allocator(alloc), _bytesAllocated(0)
     {
         clear();
     }
@@ -1105,29 +1104,21 @@ namespace nanojit
         hash += hash >> 5;
         hash ^= hash << 4;
         hash += hash >> 17;
         hash ^= hash << 25;
         hash += hash >> 6;
         return hash;
     }
 
-    LInsHashSet::LInsHashSet(GC* gc) :
-            m_used(0), m_cap(kInitialCap), m_gc(gc)
+    LInsHashSet::LInsHashSet(Allocator& alloc) :
+            m_cap(kInitialCap), alloc(alloc)
     {
-#ifdef MEMORY_INFO
-//        m_list.set_meminfo_name("LInsHashSet.list");
-#endif
-        LInsp *list = (LInsp*) gc->Alloc(sizeof(LInsp)*m_cap, GC::kZero);
-        WB(gc, this, &m_list, list);
-    }
-
-    LInsHashSet::~LInsHashSet()
-    {
-        m_gc->Free(m_list);
+        m_list = new (alloc) LInsp[m_cap];
+        clear();
     }
 
     void LInsHashSet::clear() {
         VMPI_memset(m_list, 0, sizeof(LInsp)*m_cap);
         m_used = 0;
     }
 
     /*static*/ uint32_t FASTCALL LInsHashSet::hashcode(LInsp i)
@@ -1225,30 +1216,27 @@ namespace nanojit
                 return true;
             }
         }
     }
 
     void FASTCALL LInsHashSet::grow()
     {
         const uint32_t newcap = m_cap << 1;
-        LInsp *newlist = (LInsp*) m_gc->Alloc(newcap * sizeof(LInsp), GC::kZero);
+        LInsp *newlist = new (alloc) LInsp[newcap];
+        VMPI_memset(newlist, 0, newcap * sizeof(LInsp));
         LInsp *list = m_list;
-#ifdef MEMORY_INFO
-//        newlist.set_meminfo_name("LInsHashSet.list");
-#endif
         for (uint32_t i=0, n=m_cap; i < n; i++) {
             LInsp name = list[i];
             if (!name) continue;
             uint32_t j = find(name, hashcode(name), newlist, newcap);
             newlist[j] = name;
         }
         m_cap = newcap;
-        m_gc->Free(list);
-        WB(m_gc, this, &m_list, newlist);
+        m_list = newlist;
     }
 
     uint32_t FASTCALL LInsHashSet::find(LInsp name, uint32_t hash, const LInsp *list, uint32_t cap)
     {
         const uint32_t bitmask = (cap - 1) & ~0x1;
 
         uint32_t n = 7 << 1;
         hash &= bitmask;
@@ -1858,18 +1846,18 @@ namespace nanojit
                 VMPI_sprintf(s, "?");
                 break;
         }
         return labels->dup(sbuf);
     }
 
 
 #endif
-    CseFilter::CseFilter(LirWriter *out, GC *gc)
-        : LirWriter(out), exprs(gc) {}
+    CseFilter::CseFilter(LirWriter *out, Allocator& alloc)
+        : LirWriter(out), exprs(alloc) {}
 
     LIns* CseFilter::insImm(int32_t imm)
     {
         uint32_t k;
         LInsp found = exprs.find32(imm, k);
         if (found)
             return found;
         return exprs.add(out->insImm(imm), k);
@@ -2128,17 +2116,17 @@ namespace nanojit
         if (op == LIR_label)
             exprs.clear();
         return out->ins0(op);
     }
 
     #endif /* FEATURE_NANOJIT */
 
 #if defined(NJ_VERBOSE)
-    LabelMap::LabelMap(nanojit::Allocator& a, LogControl *logc)
+    LabelMap::LabelMap(Allocator& a, LogControl *logc)
         : allocator(a), names(a), logc(logc), end(buf)
     {}
 
     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];
--- a/js/src/nanojit/LIR.h
+++ b/js/src/nanojit/LIR.h
@@ -1031,26 +1031,26 @@ namespace nanojit
     {
         // must be a power of 2.
         // don't start too small, or we'll waste time growing and rehashing.
         // don't start too large, will waste memory.
         static const uint32_t kInitialCap = 64;
 
         LInsp *m_list;
         uint32_t m_used, m_cap;
-        GC* m_gc;
+        Allocator& alloc;
 
         static uint32_t FASTCALL hashcode(LInsp i);
         uint32_t FASTCALL find(LInsp name, uint32_t hash, const LInsp *list, uint32_t cap);
         static bool FASTCALL equals(LInsp a, LInsp b);
         void FASTCALL grow();
 
     public:
-        LInsHashSet(GC* gc);
-        ~LInsHashSet();
+
+        LInsHashSet(Allocator&);
         LInsp find32(int32_t a, uint32_t &i);
         LInsp find64(uint64_t a, uint32_t &i);
         LInsp find1(LOpcode v, LInsp a, uint32_t &i);
         LInsp find2(LOpcode v, LInsp a, LInsp b, uint32_t &i);
         LInsp find3(LOpcode v, LInsp a, LInsp b, LInsp c, uint32_t &i);
         LInsp findLoad(LOpcode v, LInsp a, int32_t b, uint32_t &i);
         LInsp findcall(const CallInfo *call, uint32_t argc, LInsp args[], uint32_t &i);
         LInsp add(LInsp i, uint32_t k);
@@ -1064,32 +1064,32 @@ namespace nanojit
         static uint32_t FASTCALL hashLoad(LOpcode v, LInsp, int32_t);
         static uint32_t FASTCALL hashcall(const CallInfo *call, uint32_t argc, LInsp args[]);
     };
 
     class CseFilter: public LirWriter
     {
     public:
         LInsHashSet exprs;
-        CseFilter(LirWriter *out, GC *gc);
+        CseFilter(LirWriter *out, Allocator&);
         LIns* insImm(int32_t imm);
         LIns* insImmq(uint64_t q);
         LIns* ins0(LOpcode v);
         LIns* ins1(LOpcode v, LInsp);
         LIns* ins2(LOpcode v, LInsp, LInsp);
         LIns* ins3(LOpcode v, LInsp, LInsp, LInsp);
         LIns* insLoad(LOpcode op, LInsp cond, int32_t d);
         LIns* insCall(const CallInfo *call, LInsp args[]);
         LIns* insGuard(LOpcode op, LInsp cond, LIns *x);
     };
 
     class LirBuffer
     {
         public:
-            LirBuffer(Allocator&);
+            LirBuffer(Allocator& alloc);
             void        clear();
             uintptr_t   makeRoom(size_t szB);   // make room for an instruction
 
             debug_only (void validate() const;)
             verbose_only(LirNameMap* names;)
 
             int32_t insCount();
             size_t  byteCount();
@@ -1139,17 +1139,17 @@ namespace nanojit
         LirBuffer*    _buf;        // underlying buffer housing the instructions
 
         public:
             LirBufWriter(LirBuffer* buf)
                 : LirWriter(0), _buf(buf) {
             }
 
             // LirWriter interface
-            LInsp   insLoad(LOpcode op, LInsp base, int32_t disp);
+            LInsp    insLoad(LOpcode op, LInsp base, int32_t disp);
             LInsp    insStorei(LInsp o1, LInsp o2, int32_t disp);
             LInsp    ins0(LOpcode op);
             LInsp    ins1(LOpcode op, LInsp o1);
             LInsp    ins2(LOpcode op, LInsp o1, LInsp o2);
             LInsp    ins3(LOpcode op, LInsp o1, LInsp o2, LInsp o3);
             LInsp    insParam(int32_t i, int32_t kind);
             LInsp    insImm(int32_t imm);
             LInsp    insImmq(uint64_t imm);
@@ -1176,17 +1176,19 @@ namespace nanojit
     };
 
     // concrete
     class LirReader : public LirFilter
     {
         LInsp _i; // current instruction that this decoder is operating on.
 
     public:
-        LirReader(LInsp i) : LirFilter(0), _i(i) { }
+        LirReader(LInsp i) : LirFilter(0), _i(i) {
+            NanoAssert(_i);
+        }
         virtual ~LirReader() {}
 
         // LirReader i/f
         LInsp read(); // advance to the prior instruction
         LInsp pos() {
             return _i;
         }
         void setpos(LIns *i) {
@@ -1215,18 +1217,19 @@ namespace nanojit
     class LoadFilter: public LirWriter
     {
     public:
         LInsp sp, rp;
         LInsHashSet exprs;
 
         void clear(LInsp p);
     public:
-        LoadFilter(LirWriter *out, GC *gc)
-            : LirWriter(out), exprs(gc) { }
+        LoadFilter(LirWriter *out, Allocator& alloc)
+            : LirWriter(out), sp(NULL), rp(NULL), exprs(alloc)
+        { }
 
         LInsp ins0(LOpcode);
         LInsp insLoad(LOpcode, LInsp base, int32_t disp);
         LInsp insStorei(LInsp v, LInsp b, int32_t d);
         LInsp insCall(const CallInfo *call, LInsp args[]);
     };
 }
 #endif // __nanojit_LIR__