From 2c0bc63017ff82003b1672076e6344d451ac1e35 Mon Sep 17 00:00:00 2001 From: Terrence Cole Date: Thu, 29 Mar 2012 17:52:45 -0700 Subject: [PATCH] Backout 00f2e1e9adc2 after mq malfunction. --- js/src/builtin/TestingFunctions.cpp | 30 +++++++++-------- js/src/frontend/Parser.cpp | 4 +++ js/src/jsapi.cpp | 52 +++++++++++++++++------------ js/src/jscntxt.h | 1 + js/src/jsdbgapi.cpp | 2 +- js/src/jsgc.h | 1 + js/src/jsobj.cpp | 1 + js/src/jsscope.cpp | 13 ++++---- js/src/jsscope.h | 12 +++---- js/src/jsscopeinlines.h | 4 +-- 10 files changed, 71 insertions(+), 49 deletions(-) diff --git a/js/src/builtin/TestingFunctions.cpp b/js/src/builtin/TestingFunctions.cpp index bc7b15d4ebd7..6de7947092c8 100644 --- a/js/src/builtin/TestingFunctions.cpp +++ b/js/src/builtin/TestingFunctions.cpp @@ -245,11 +245,9 @@ struct JSCountHeapNode { JSCountHeapNode *next; }; -typedef HashSet, SystemAllocPolicy> VisitedSet; - typedef struct JSCountHeapTracer { JSTracer base; - VisitedSet visited; + JSDHashTable visited; bool ok; JSCountHeapNode *traceList; JSCountHeapNode *recycleList; @@ -258,24 +256,27 @@ typedef struct JSCountHeapTracer { static void CountHeapNotify(JSTracer *trc, void **thingp, JSGCTraceKind kind) { - JS_ASSERT(trc->callback == CountHeapNotify); - - JSCountHeapTracer *countTracer = (JSCountHeapTracer *)trc; + JSCountHeapTracer *countTracer; + JSDHashEntryStub *entry; + JSCountHeapNode *node; void *thing = *thingp; + JS_ASSERT(trc->callback == CountHeapNotify); + countTracer = (JSCountHeapTracer *)trc; if (!countTracer->ok) return; - VisitedSet::AddPtr p = countTracer->visited.lookupForAdd(thing); - if (p) - return; - - if (!countTracer->visited.add(p, thing)) { + entry = (JSDHashEntryStub *) + JS_DHashTableOperate(&countTracer->visited, thing, JS_DHASH_ADD); + if (!entry) { countTracer->ok = false; return; } + if (entry->key) + return; + entry->key = thing; - JSCountHeapNode *node = countTracer->recycleList; + node = countTracer->recycleList; if (node) { countTracer->recycleList = node->next; } else { @@ -353,7 +354,9 @@ CountHeap(JSContext *cx, unsigned argc, jsval *vp) } JS_TracerInit(&countTracer.base, JS_GetRuntime(cx), CountHeapNotify); - if (!countTracer.visited.init()) { + if (!JS_DHashTableInit(&countTracer.visited, JS_DHashGetStubOps(), + NULL, sizeof(JSDHashEntryStub), + JS_DHASH_DEFAULT_CAPACITY(100))) { JS_ReportOutOfMemory(cx); return JS_FALSE; } @@ -381,6 +384,7 @@ CountHeap(JSContext *cx, unsigned argc, jsval *vp) countTracer.recycleList = node->next; js_free(node); } + JS_DHashTableFinish(&countTracer.visited); if (!countTracer.ok) { JS_ReportOutOfMemory(cx); return false; diff --git a/js/src/frontend/Parser.cpp b/js/src/frontend/Parser.cpp index 0adf4dd3b2d4..6b3673320e27 100644 --- a/js/src/frontend/Parser.cpp +++ b/js/src/frontend/Parser.cpp @@ -86,6 +86,10 @@ #include "jsxml.h" #endif +#if JS_HAS_DESTRUCTURING +#include "jsdhash.h" +#endif + #include "jsatominlines.h" #include "jsscriptinlines.h" diff --git a/js/src/jsapi.cpp b/js/src/jsapi.cpp index 51e9a4470eca..28d7c91e88c2 100644 --- a/js/src/jsapi.cpp +++ b/js/src/jsapi.cpp @@ -49,6 +49,7 @@ #include "jstypes.h" #include "jsutil.h" #include "jsclist.h" +#include "jsdhash.h" #include "jsprf.h" #include "jsapi.h" #include "jsarray.h" @@ -2607,11 +2608,9 @@ struct JSHeapDumpNode { into thing */ }; -typedef HashSet, SystemAllocPolicy> VisitedSet; - typedef struct JSDumpingTracer { JSTracer base; - VisitedSet visited; + JSDHashTable visited; bool ok; void *startThing; void *thingToFind; @@ -2624,10 +2623,12 @@ typedef struct JSDumpingTracer { static void DumpNotify(JSTracer *trc, void **thingp, JSGCTraceKind kind) { - JS_ASSERT(trc->callback == DumpNotify); - - JSDumpingTracer *dtrc = (JSDumpingTracer *)trc; void *thing = *thingp; + JSDumpingTracer *dtrc; + JSDHashEntryStub *entry; + + JS_ASSERT(trc->callback == DumpNotify); + dtrc = (JSDumpingTracer *)trc; if (!dtrc->ok || thing == dtrc->thingToIgnore) return; @@ -2649,13 +2650,15 @@ DumpNotify(JSTracer *trc, void **thingp, JSGCTraceKind kind) */ if (thing == dtrc->startThing) return; - VisitedSet::AddPtr p = dtrc->visited.lookupForAdd(thing); - if (p) - return; - if (!dtrc->visited.add(p, thing)) { + entry = (JSDHashEntryStub *) + JS_DHashTableOperate(&dtrc->visited, thing, JS_DHASH_ADD); + if (!entry) { dtrc->ok = false; return; } + if (entry->key) + return; + entry->key = thing; } const char *edgeName = JS_GetTraceEdgeName(&dtrc->base, dtrc->buffer, sizeof(dtrc->buffer)); @@ -2747,20 +2750,26 @@ JS_PUBLIC_API(JSBool) JS_DumpHeap(JSRuntime *rt, FILE *fp, void* startThing, JSGCTraceKind startKind, void *thingToFind, size_t maxDepth, void *thingToIgnore) { - if (maxDepth == 0) - return true; - JSDumpingTracer dtrc; - if (!dtrc.visited.init()) { + JSHeapDumpNode *node, *children, *next, *parent; + size_t depth; + JSBool thingToFindWasTraced; + + if (maxDepth == 0) + return JS_TRUE; + + JS_TracerInit(&dtrc.base, rt, DumpNotify); + if (!JS_DHashTableInit(&dtrc.visited, JS_DHashGetStubOps(), + NULL, sizeof(JSDHashEntryStub), + JS_DHASH_DEFAULT_CAPACITY(100))) { return false; } - JS_TracerInit(&dtrc.base, rt, DumpNotify); dtrc.ok = JS_TRUE; dtrc.startThing = startThing; dtrc.thingToFind = thingToFind; dtrc.thingToIgnore = thingToIgnore; dtrc.parentNode = NULL; - JSHeapDumpNode *node = NULL; + node = NULL; dtrc.lastNodep = &node; if (!startThing) { JS_ASSERT(startKind == JSTRACE_OBJECT); @@ -2769,12 +2778,11 @@ JS_DumpHeap(JSRuntime *rt, FILE *fp, void* startThing, JSGCTraceKind startKind, JS_TraceChildren(&dtrc.base, startThing, startKind); } - size_t depth = 1; + depth = 1; if (!node) - return dtrc.ok; + goto dump_out; - JSHeapDumpNode *children, *next, *parent; - bool thingToFindWasTraced = thingToFind && thingToFind == startThing; + thingToFindWasTraced = thingToFind && thingToFind == startThing; for (;;) { /* * Loop must continue even when !dtrc.ok to free all nodes allocated @@ -2811,14 +2819,16 @@ JS_DumpHeap(JSRuntime *rt, FILE *fp, void* startThing, JSGCTraceKind startKind, if (node) break; if (!parent) - return dtrc.ok; + goto dump_out; JS_ASSERT(depth > 1); --depth; node = parent; } } + dump_out: JS_ASSERT(depth == 1); + JS_DHashTableFinish(&dtrc.visited); return dtrc.ok; } diff --git a/js/src/jscntxt.h b/js/src/jscntxt.h index 40f8687cfde9..c39036c7bf29 100644 --- a/js/src/jscntxt.h +++ b/js/src/jscntxt.h @@ -52,6 +52,7 @@ #include "jsprvtd.h" #include "jsatom.h" #include "jsclist.h" +#include "jsdhash.h" #include "jsgc.h" #include "jspropertycache.h" #include "jspropertytree.h" diff --git a/js/src/jsdbgapi.cpp b/js/src/jsdbgapi.cpp index 7baff1789559..37a7c3a61c8f 100644 --- a/js/src/jsdbgapi.cpp +++ b/js/src/jsdbgapi.cpp @@ -968,7 +968,7 @@ GetAtomTotalSize(JSContext *cx, JSAtom *atom) { size_t nbytes; - nbytes = sizeof(AtomStateEntry) + sizeof(HashNumber); + nbytes = sizeof(JSAtom *) + sizeof(JSDHashEntryStub); nbytes += sizeof(JSString); nbytes += (atom->length() + 1) * sizeof(jschar); return nbytes; diff --git a/js/src/jsgc.h b/js/src/jsgc.h index 159a37647ebc..246c4e1a3ca1 100644 --- a/js/src/jsgc.h +++ b/js/src/jsgc.h @@ -51,6 +51,7 @@ #include "jstypes.h" #include "jsprvtd.h" #include "jspubtd.h" +#include "jsdhash.h" #include "jslock.h" #include "jsutil.h" #include "jsversion.h" diff --git a/js/src/jsobj.cpp b/js/src/jsobj.cpp index 15ea133d1d63..c3d8f243bd89 100644 --- a/js/src/jsobj.cpp +++ b/js/src/jsobj.cpp @@ -49,6 +49,7 @@ #include "jstypes.h" #include "jsutil.h" #include "jshash.h" +#include "jsdhash.h" #include "jsprf.h" #include "jsapi.h" #include "jsarray.h" diff --git a/js/src/jsscope.cpp b/js/src/jsscope.cpp index 4063277dcb4f..1db72f3e39f3 100644 --- a/js/src/jsscope.cpp +++ b/js/src/jsscope.cpp @@ -46,6 +46,7 @@ #include #include "jstypes.h" #include "jsclist.h" +#include "jsdhash.h" #include "jsutil.h" #include "jsapi.h" #include "jsatom.h" @@ -88,7 +89,7 @@ PropertyTable::init(JSRuntime *rt, Shape *lastProp) if (!entries) return false; - hashShift = HASH_BITS - sizeLog2; + hashShift = JS_DHASH_BITS - sizeLog2; for (Shape::Range r = lastProp->all(); !r.empty(); r.popFront()) { const Shape &shape = r.front(); Shape **spp = search(shape.propid(), true); @@ -201,7 +202,7 @@ PropertyTable::search(jsid id, bool adding) return spp; /* Collision: double hash. */ - sizeLog2 = HASH_BITS - hashShift; + sizeLog2 = JS_DHASH_BITS - hashShift; hash2 = HASH2(hash0, sizeLog2, hashShift); sizeMask = JS_BITMASK(sizeLog2); @@ -260,7 +261,7 @@ PropertyTable::change(int log2Delta, JSContext *cx) /* * Grow, shrink, or compress by changing this->entries. */ - int oldlog2 = HASH_BITS - hashShift; + int oldlog2 = JS_DHASH_BITS - hashShift; int newlog2 = oldlog2 + log2Delta; uint32_t oldsize = JS_BIT(oldlog2); uint32_t newsize = JS_BIT(newlog2); @@ -269,7 +270,7 @@ PropertyTable::change(int log2Delta, JSContext *cx) return false; /* Now that we have newTable allocated, update members. */ - hashShift = HASH_BITS - newlog2; + hashShift = JS_DHASH_BITS - newlog2; removedCount = 0; Shape **oldTable = entries; entries = newTable; @@ -1150,7 +1151,7 @@ Shape::setObjectFlag(JSContext *cx, BaseShape::Flag flag, JSObject *proto, Shape /* static */ inline HashNumber StackBaseShape::hash(const StackBaseShape *base) { - HashNumber hash = base->flags; + JSDHashNumber hash = base->flags; hash = JS_ROTATE_LEFT32(hash, 4) ^ (uintptr_t(base->clasp) >> 3); hash = JS_ROTATE_LEFT32(hash, 4) ^ (uintptr_t(base->parent) >> 3); hash = JS_ROTATE_LEFT32(hash, 4) ^ uintptr_t(base->rawGetter); @@ -1287,7 +1288,7 @@ Bindings::setParent(JSContext *cx, JSObject *obj) /* static */ inline HashNumber InitialShapeEntry::hash(const Lookup &lookup) { - HashNumber hash = uintptr_t(lookup.clasp) >> 3; + JSDHashNumber hash = uintptr_t(lookup.clasp) >> 3; hash = JS_ROTATE_LEFT32(hash, 4) ^ (uintptr_t(lookup.proto) >> 3); hash = JS_ROTATE_LEFT32(hash, 4) ^ (uintptr_t(lookup.parent) >> 3); return hash + lookup.nfixed; diff --git a/js/src/jsscope.h b/js/src/jsscope.h index 4f1a86160f94..4cedeea2cb51 100644 --- a/js/src/jsscope.h +++ b/js/src/jsscope.h @@ -48,6 +48,7 @@ #include #endif +#include "jsdhash.h" #include "jsobj.h" #include "jspropertytree.h" #include "jstypes.h" @@ -135,11 +136,10 @@ static const uint32_t SHAPE_INVALID_SLOT = JS_BIT(24) - 1; static const uint32_t SHAPE_MAXIMUM_SLOT = JS_BIT(24) - 2; /* - * Shapes use multiplicative hashing, but specialized to + * Shapes use multiplicative hashing, _a la_ jsdhash.[ch], but specialized to * minimize footprint. */ struct PropertyTable { - static const uint32_t HASH_BITS = tl::BitSize::result; static const uint32_t MIN_ENTRIES = 7; static const uint32_t MIN_SIZE_LOG2 = 4; static const uint32_t MIN_SIZE = JS_BIT(MIN_SIZE_LOG2); @@ -154,7 +154,7 @@ struct PropertyTable { js::Shape **entries; /* table of ptrs to shared tree nodes */ PropertyTable(uint32_t nentries) - : hashShift(HASH_BITS - MIN_SIZE_LOG2), + : hashShift(JS_DHASH_BITS - MIN_SIZE_LOG2), entryCount(nentries), removedCount(0), freelist(SHAPE_INVALID_SLOT) @@ -166,8 +166,8 @@ struct PropertyTable { js::UnwantedForeground::free_(entries); } - /* By definition, hashShift = HASH_BITS - log2(capacity). */ - uint32_t capacity() const { return JS_BIT(HASH_BITS - hashShift); } + /* By definition, hashShift = JS_DHASH_BITS - log2(capacity). */ + uint32_t capacity() const { return JS_BIT(JS_DHASH_BITS - hashShift); } /* Computes the size of the entries array for a given capacity. */ static size_t sizeOfEntries(size_t cap) { return cap * sizeof(Shape *); } @@ -999,7 +999,7 @@ struct StackShape slot_ = slot; } - inline HashNumber hash() const; + inline JSDHashNumber hash() const; }; /* Rooter for stack allocated shapes. */ diff --git a/js/src/jsscopeinlines.h b/js/src/jsscopeinlines.h index 55a8cc11723a..3210568d8ed4 100644 --- a/js/src/jsscopeinlines.h +++ b/js/src/jsscopeinlines.h @@ -236,10 +236,10 @@ Shape::Shape(UnownedBaseShape *base, uint32_t nfixed) kids.setNull(); } -inline HashNumber +inline JSDHashNumber StackShape::hash() const { - HashNumber hash = uintptr_t(base); + JSDHashNumber hash = uintptr_t(base); /* Accumulate from least to most random so the low bits are most random. */ hash = JS_ROTATE_LEFT32(hash, 4) ^ (flags & Shape::PUBLIC_FLAGS);