2009-06-11 05:29:44 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2013-04-17 00:47:10 +04:00
|
|
|
* vim: set ts=8 sts=4 et sw=4 tw=99:
|
2012-05-21 15:12:37 +04:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
1998-09-03 02:37:14 +04:00
|
|
|
|
|
|
|
/*
|
1998-10-14 14:22:38 +04:00
|
|
|
* PR hash table package.
|
1998-09-03 02:37:14 +04:00
|
|
|
*/
|
2013-07-04 02:46:51 +04:00
|
|
|
|
|
|
|
#include "jshash.h"
|
|
|
|
|
|
|
|
#include "mozilla/MathAlgorithms.h"
|
|
|
|
|
1998-09-03 02:37:14 +04:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2013-07-26 11:57:03 +04:00
|
|
|
|
1998-10-14 14:22:38 +04:00
|
|
|
#include "jstypes.h"
|
2013-07-26 11:57:03 +04:00
|
|
|
|
|
|
|
#include "js/Utility.h"
|
1998-09-03 02:37:14 +04:00
|
|
|
|
Bug 634155: Account for NewCompartment's memory, and change allocation APIs (r=nnethercote)
This changes the allocation API, in the following way:
js_malloc -> {cx->,rt->,OffTheBooks::}malloc
js_calloc -> {cx->,rt->,OffTheBooks::}calloc
js_realloc -> {cx->,rt->,OffTheBooks::}realloc
js_free -> {cx->,rt->,Foreground::,UnwantedForeground::}free
js_new -> {cx->,rt->,OffTheBooks::}new_
js_new_array -> {cx->,rt->,OffTheBooks::}new_array
js_delete -> {cx->,rt->,Foreground::,UnwantedForeground::}delete_
This is to move as many allocations as possible through a JSContext (so that they may be aken into account by gcMallocBytes) and to move as many deallocations to the background as possible (except on error paths).
2011-03-31 12:13:49 +04:00
|
|
|
using namespace js;
|
|
|
|
|
2013-07-04 02:46:51 +04:00
|
|
|
using mozilla::CeilingLog2Size;
|
2014-01-20 11:58:26 +04:00
|
|
|
using mozilla::RotateLeft;
|
2013-07-04 02:46:51 +04:00
|
|
|
|
1998-09-03 02:37:14 +04:00
|
|
|
/* Compute the number of buckets in ht */
|
1998-10-14 14:22:38 +04:00
|
|
|
#define NBUCKETS(ht) JS_BIT(JS_HASH_BITS - (ht)->shift)
|
1998-09-03 02:37:14 +04:00
|
|
|
|
|
|
|
/* The smallest table has 16 buckets */
|
|
|
|
#define MINBUCKETSLOG2 4
|
1998-10-14 14:22:38 +04:00
|
|
|
#define MINBUCKETS JS_BIT(MINBUCKETSLOG2)
|
1998-09-03 02:37:14 +04:00
|
|
|
|
|
|
|
/* Compute the maximum entries given n buckets that we will tolerate, ~90% */
|
|
|
|
#define OVERLOADED(n) ((n) - ((n) >> 3))
|
|
|
|
|
|
|
|
/* Compute the number of entries below which we shrink the table by half */
|
|
|
|
#define UNDERLOADED(n) (((n) > MINBUCKETS) ? ((n) >> 2) : 0)
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Stubs for default hash allocator ops.
|
|
|
|
*/
|
1998-10-14 14:22:38 +04:00
|
|
|
static void *
|
|
|
|
DefaultAllocTable(void *pool, size_t size)
|
1998-09-03 02:37:14 +04:00
|
|
|
{
|
2012-09-01 02:01:33 +04:00
|
|
|
return js_malloc(size);
|
1998-09-03 02:37:14 +04:00
|
|
|
}
|
|
|
|
|
1998-10-14 14:22:38 +04:00
|
|
|
static void
|
2009-04-06 08:17:22 +04:00
|
|
|
DefaultFreeTable(void *pool, void *item, size_t size)
|
1998-09-03 02:37:14 +04:00
|
|
|
{
|
2012-09-01 02:01:33 +04:00
|
|
|
js_free(item);
|
1998-09-03 02:37:14 +04:00
|
|
|
}
|
|
|
|
|
1998-10-14 14:22:38 +04:00
|
|
|
static JSHashEntry *
|
1998-09-03 02:37:14 +04:00
|
|
|
DefaultAllocEntry(void *pool, const void *key)
|
|
|
|
{
|
2012-09-01 02:01:33 +04:00
|
|
|
return (JSHashEntry*) js_malloc(sizeof(JSHashEntry));
|
1998-09-03 02:37:14 +04:00
|
|
|
}
|
|
|
|
|
1998-10-14 14:22:38 +04:00
|
|
|
static void
|
2012-02-29 03:11:11 +04:00
|
|
|
DefaultFreeEntry(void *pool, JSHashEntry *he, unsigned flag)
|
1998-09-03 02:37:14 +04:00
|
|
|
{
|
|
|
|
if (flag == HT_FREE_ENTRY)
|
2012-09-01 02:01:33 +04:00
|
|
|
js_free(he);
|
1998-09-03 02:37:14 +04:00
|
|
|
}
|
|
|
|
|
2013-09-24 19:21:22 +04:00
|
|
|
static const JSHashAllocOps defaultHashAllocOps = {
|
1998-09-03 02:37:14 +04:00
|
|
|
DefaultAllocTable, DefaultFreeTable,
|
|
|
|
DefaultAllocEntry, DefaultFreeEntry
|
|
|
|
};
|
|
|
|
|
2012-07-19 04:38:10 +04:00
|
|
|
JSHashTable *
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 07:54:10 +04:00
|
|
|
JS_NewHashTable(uint32_t n, JSHashFunction keyHash,
|
1998-10-14 14:22:38 +04:00
|
|
|
JSHashComparator keyCompare, JSHashComparator valueCompare,
|
2013-09-24 19:21:22 +04:00
|
|
|
const JSHashAllocOps *allocOps, void *allocPriv)
|
1998-09-03 02:37:14 +04:00
|
|
|
{
|
1998-10-14 14:22:38 +04:00
|
|
|
JSHashTable *ht;
|
|
|
|
size_t nb;
|
1998-09-03 02:37:14 +04:00
|
|
|
|
|
|
|
if (n <= MINBUCKETS) {
|
|
|
|
n = MINBUCKETSLOG2;
|
|
|
|
} else {
|
2013-07-04 02:46:51 +04:00
|
|
|
n = CeilingLog2Size(n);
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 07:54:10 +04:00
|
|
|
if (int32_t(n) < 0)
|
2013-09-19 23:26:36 +04:00
|
|
|
return nullptr;
|
1998-09-03 02:37:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!allocOps) allocOps = &defaultHashAllocOps;
|
|
|
|
|
2004-04-13 05:25:17 +04:00
|
|
|
ht = (JSHashTable*) allocOps->allocTable(allocPriv, sizeof *ht);
|
1998-09-03 02:37:14 +04:00
|
|
|
if (!ht)
|
2013-09-19 23:26:36 +04:00
|
|
|
return nullptr;
|
1998-09-03 02:37:14 +04:00
|
|
|
memset(ht, 0, sizeof *ht);
|
1998-10-14 14:22:38 +04:00
|
|
|
ht->shift = JS_HASH_BITS - n;
|
|
|
|
n = JS_BIT(n);
|
|
|
|
nb = n * sizeof(JSHashEntry *);
|
2004-04-13 05:25:17 +04:00
|
|
|
ht->buckets = (JSHashEntry**) allocOps->allocTable(allocPriv, nb);
|
1998-09-03 02:37:14 +04:00
|
|
|
if (!ht->buckets) {
|
2009-04-06 08:17:22 +04:00
|
|
|
allocOps->freeTable(allocPriv, ht, nb);
|
2013-09-19 23:26:36 +04:00
|
|
|
return nullptr;
|
1998-09-03 02:37:14 +04:00
|
|
|
}
|
|
|
|
memset(ht->buckets, 0, nb);
|
|
|
|
|
|
|
|
ht->keyHash = keyHash;
|
|
|
|
ht->keyCompare = keyCompare;
|
|
|
|
ht->valueCompare = valueCompare;
|
|
|
|
ht->allocOps = allocOps;
|
|
|
|
ht->allocPriv = allocPriv;
|
|
|
|
return ht;
|
|
|
|
}
|
|
|
|
|
2012-07-19 04:38:10 +04:00
|
|
|
void
|
1998-10-14 14:22:38 +04:00
|
|
|
JS_HashTableDestroy(JSHashTable *ht)
|
1998-09-03 02:37:14 +04:00
|
|
|
{
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 07:54:10 +04:00
|
|
|
uint32_t i, n;
|
2001-05-17 05:43:58 +04:00
|
|
|
JSHashEntry *he, **hep;
|
2013-09-24 19:21:22 +04:00
|
|
|
const JSHashAllocOps *allocOps = ht->allocOps;
|
1998-09-03 02:37:14 +04:00
|
|
|
void *allocPriv = ht->allocPriv;
|
|
|
|
|
|
|
|
n = NBUCKETS(ht);
|
|
|
|
for (i = 0; i < n; i++) {
|
2001-05-17 05:43:58 +04:00
|
|
|
hep = &ht->buckets[i];
|
2013-09-19 23:26:36 +04:00
|
|
|
while ((he = *hep) != nullptr) {
|
2001-05-17 05:43:58 +04:00
|
|
|
*hep = he->next;
|
2004-04-13 05:25:17 +04:00
|
|
|
allocOps->freeEntry(allocPriv, he, HT_FREE_ENTRY);
|
1998-09-03 02:37:14 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#ifdef DEBUG
|
|
|
|
memset(ht->buckets, 0xDB, n * sizeof ht->buckets[0]);
|
|
|
|
#endif
|
2009-04-06 08:17:22 +04:00
|
|
|
allocOps->freeTable(allocPriv, ht->buckets, n * sizeof ht->buckets[0]);
|
1998-09-03 02:37:14 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
memset(ht, 0xDB, sizeof *ht);
|
|
|
|
#endif
|
2009-04-06 08:17:22 +04:00
|
|
|
allocOps->freeTable(allocPriv, ht, sizeof *ht);
|
1998-09-03 02:37:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2006-02-24 01:20:27 +03:00
|
|
|
* Multiplicative hash, from Knuth 6.4.
|
|
|
|
*/
|
|
|
|
#define BUCKET_HEAD(ht, keyHash) \
|
|
|
|
(&(ht)->buckets[((keyHash) * JS_GOLDEN_RATIO) >> (ht)->shift])
|
|
|
|
|
2012-07-19 04:38:10 +04:00
|
|
|
JSHashEntry **
|
1998-10-14 14:22:38 +04:00
|
|
|
JS_HashTableRawLookup(JSHashTable *ht, JSHashNumber keyHash, const void *key)
|
1998-09-03 02:37:14 +04:00
|
|
|
{
|
1998-10-14 14:22:38 +04:00
|
|
|
JSHashEntry *he, **hep, **hep0;
|
1998-09-03 02:37:14 +04:00
|
|
|
|
* Menu of -D flags for enabling instrumentation, as a commented-out CFLAGS += setting for convenient testing. * js_FindProperty and js_LookupPropertyWithFlags return indexes into the scope and prototype chains, respectively, to support internal instrumentation, and to pave the way for the return of the property cache (bug 365851).. * jsutil.[ch] JSBasicStats struct and functions for computing mean/sigma/max and auto-scaling histogram. * JS_SCOPE_DEPTH_METER instrumentation for compile- and run-time scope chain length instrumentation: + At compile time, rt->hostenvScopeDepthStats and rt->lexicalScopeDepthStats meter scope chains passed into the compile and evaluate APIs. + At runtime, rt->protoLookupDepthStats and rt->scopeSearchDepthStats track steps along the prototype and scope chains until the sought-after property is found. * JS_ARENAMETER uses JSBasicStats now. * Added rt->liveScopePropsPreSweep to fix the property tree stats code that rotted when property tree sweeping moved to after the finalization phase. * Un-bitrotted some DEBUG_brendan code, turned some off for myself via XXX. * Mac OS X toolchain requires initialized data shared across dynamic library member files, outlaws common data, so initialize extern metering vars. * Old HASHMETER code in jshash.[ch] is now JS_HASHMETER-controlled and based on JSBasicStats. * DEBUG_scopemeters macro renamed JS_DUMP_SCOPE_METERS; uses JSBasicStats now. * Disentangle DEBUG and DUMP_SCOPE_STATS (now JS_DUMP_PROPTREE_STATS) and fix inconsistent thread safety for liveScopeProps (sometimes atomic-incremented, sometimes runtime-locked). * Compiler-modeled maxScopeDepth will propagate via JSScript to runtime for capability-based, interpreter-inlined cache hit qualifier bits, to bypass scope and prototype chain lookup by optimizing for common monomorphic get, set, and call site referencing a prototype property in a well-named object (no shadowing or mutation in 99.9% of the cases).
2008-01-13 03:31:31 +03:00
|
|
|
#ifdef JS_HASHMETER
|
1998-09-03 02:37:14 +04:00
|
|
|
ht->nlookups++;
|
|
|
|
#endif
|
2006-02-24 01:20:27 +03:00
|
|
|
hep = hep0 = BUCKET_HEAD(ht, keyHash);
|
2013-09-19 23:26:36 +04:00
|
|
|
while ((he = *hep) != nullptr) {
|
2004-04-13 05:25:17 +04:00
|
|
|
if (he->keyHash == keyHash && ht->keyCompare(key, he->key)) {
|
1998-09-03 02:37:14 +04:00
|
|
|
/* Move to front of chain if not already there */
|
|
|
|
if (hep != hep0) {
|
|
|
|
*hep = he->next;
|
|
|
|
he->next = *hep0;
|
|
|
|
*hep0 = he;
|
|
|
|
}
|
|
|
|
return hep0;
|
|
|
|
}
|
|
|
|
hep = &he->next;
|
* Menu of -D flags for enabling instrumentation, as a commented-out CFLAGS += setting for convenient testing. * js_FindProperty and js_LookupPropertyWithFlags return indexes into the scope and prototype chains, respectively, to support internal instrumentation, and to pave the way for the return of the property cache (bug 365851).. * jsutil.[ch] JSBasicStats struct and functions for computing mean/sigma/max and auto-scaling histogram. * JS_SCOPE_DEPTH_METER instrumentation for compile- and run-time scope chain length instrumentation: + At compile time, rt->hostenvScopeDepthStats and rt->lexicalScopeDepthStats meter scope chains passed into the compile and evaluate APIs. + At runtime, rt->protoLookupDepthStats and rt->scopeSearchDepthStats track steps along the prototype and scope chains until the sought-after property is found. * JS_ARENAMETER uses JSBasicStats now. * Added rt->liveScopePropsPreSweep to fix the property tree stats code that rotted when property tree sweeping moved to after the finalization phase. * Un-bitrotted some DEBUG_brendan code, turned some off for myself via XXX. * Mac OS X toolchain requires initialized data shared across dynamic library member files, outlaws common data, so initialize extern metering vars. * Old HASHMETER code in jshash.[ch] is now JS_HASHMETER-controlled and based on JSBasicStats. * DEBUG_scopemeters macro renamed JS_DUMP_SCOPE_METERS; uses JSBasicStats now. * Disentangle DEBUG and DUMP_SCOPE_STATS (now JS_DUMP_PROPTREE_STATS) and fix inconsistent thread safety for liveScopeProps (sometimes atomic-incremented, sometimes runtime-locked). * Compiler-modeled maxScopeDepth will propagate via JSScript to runtime for capability-based, interpreter-inlined cache hit qualifier bits, to bypass scope and prototype chain lookup by optimizing for common monomorphic get, set, and call site referencing a prototype property in a well-named object (no shadowing or mutation in 99.9% of the cases).
2008-01-13 03:31:31 +03:00
|
|
|
#ifdef JS_HASHMETER
|
1998-09-03 02:37:14 +04:00
|
|
|
ht->nsteps++;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
return hep;
|
|
|
|
}
|
|
|
|
|
2013-08-09 02:53:04 +04:00
|
|
|
static bool
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 07:54:10 +04:00
|
|
|
Resize(JSHashTable *ht, uint32_t newshift)
|
2006-02-24 01:20:27 +03:00
|
|
|
{
|
|
|
|
size_t nb, nentries, i;
|
|
|
|
JSHashEntry **oldbuckets, *he, *next, **hep;
|
|
|
|
size_t nold = NBUCKETS(ht);
|
|
|
|
|
2014-02-18 10:24:15 +04:00
|
|
|
MOZ_ASSERT(newshift < JS_HASH_BITS);
|
2006-02-24 01:20:27 +03:00
|
|
|
|
|
|
|
nb = (size_t)1 << (JS_HASH_BITS - newshift);
|
|
|
|
|
|
|
|
/* Integer overflow protection. */
|
|
|
|
if (nb > (size_t)-1 / sizeof(JSHashEntry*))
|
2013-08-07 10:59:54 +04:00
|
|
|
return false;
|
2006-02-24 01:20:27 +03:00
|
|
|
nb *= sizeof(JSHashEntry*);
|
|
|
|
|
|
|
|
oldbuckets = ht->buckets;
|
|
|
|
ht->buckets = (JSHashEntry**)ht->allocOps->allocTable(ht->allocPriv, nb);
|
|
|
|
if (!ht->buckets) {
|
|
|
|
ht->buckets = oldbuckets;
|
2013-08-07 10:59:54 +04:00
|
|
|
return false;
|
2006-02-24 01:20:27 +03:00
|
|
|
}
|
|
|
|
memset(ht->buckets, 0, nb);
|
|
|
|
|
|
|
|
ht->shift = newshift;
|
|
|
|
nentries = ht->nentries;
|
|
|
|
|
|
|
|
for (i = 0; nentries != 0; i++) {
|
|
|
|
for (he = oldbuckets[i]; he; he = next) {
|
2014-02-18 10:24:15 +04:00
|
|
|
MOZ_ASSERT(nentries != 0);
|
2006-02-24 01:20:27 +03:00
|
|
|
--nentries;
|
|
|
|
next = he->next;
|
|
|
|
hep = BUCKET_HEAD(ht, he->keyHash);
|
|
|
|
|
|
|
|
/*
|
2009-04-06 08:17:22 +04:00
|
|
|
* We do not require unique entries, instead appending he to the
|
|
|
|
* chain starting at hep.
|
2006-02-24 01:20:27 +03:00
|
|
|
*/
|
2009-04-06 08:17:22 +04:00
|
|
|
while (*hep)
|
|
|
|
hep = &(*hep)->next;
|
2013-09-19 23:26:36 +04:00
|
|
|
he->next = nullptr;
|
2006-02-24 01:20:27 +03:00
|
|
|
*hep = he;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#ifdef DEBUG
|
|
|
|
memset(oldbuckets, 0xDB, nold * sizeof oldbuckets[0]);
|
|
|
|
#endif
|
2009-04-06 08:17:22 +04:00
|
|
|
ht->allocOps->freeTable(ht->allocPriv, oldbuckets,
|
|
|
|
nold * sizeof oldbuckets[0]);
|
2013-08-07 10:59:54 +04:00
|
|
|
return true;
|
2006-02-24 01:20:27 +03:00
|
|
|
}
|
|
|
|
|
2012-07-19 04:38:10 +04:00
|
|
|
JSHashEntry *
|
2009-07-17 00:16:27 +04:00
|
|
|
JS_HashTableRawAdd(JSHashTable *ht, JSHashEntry **&hep,
|
1998-10-14 14:22:38 +04:00
|
|
|
JSHashNumber keyHash, const void *key, void *value)
|
1998-09-03 02:37:14 +04:00
|
|
|
{
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 07:54:10 +04:00
|
|
|
uint32_t n;
|
2006-02-24 01:20:27 +03:00
|
|
|
JSHashEntry *he;
|
1998-09-03 02:37:14 +04:00
|
|
|
|
|
|
|
/* Grow the table if it is overloaded */
|
|
|
|
n = NBUCKETS(ht);
|
|
|
|
if (ht->nentries >= OVERLOADED(n)) {
|
2006-02-24 01:20:27 +03:00
|
|
|
if (!Resize(ht, ht->shift - 1))
|
2013-09-19 23:26:36 +04:00
|
|
|
return nullptr;
|
* Menu of -D flags for enabling instrumentation, as a commented-out CFLAGS += setting for convenient testing. * js_FindProperty and js_LookupPropertyWithFlags return indexes into the scope and prototype chains, respectively, to support internal instrumentation, and to pave the way for the return of the property cache (bug 365851).. * jsutil.[ch] JSBasicStats struct and functions for computing mean/sigma/max and auto-scaling histogram. * JS_SCOPE_DEPTH_METER instrumentation for compile- and run-time scope chain length instrumentation: + At compile time, rt->hostenvScopeDepthStats and rt->lexicalScopeDepthStats meter scope chains passed into the compile and evaluate APIs. + At runtime, rt->protoLookupDepthStats and rt->scopeSearchDepthStats track steps along the prototype and scope chains until the sought-after property is found. * JS_ARENAMETER uses JSBasicStats now. * Added rt->liveScopePropsPreSweep to fix the property tree stats code that rotted when property tree sweeping moved to after the finalization phase. * Un-bitrotted some DEBUG_brendan code, turned some off for myself via XXX. * Mac OS X toolchain requires initialized data shared across dynamic library member files, outlaws common data, so initialize extern metering vars. * Old HASHMETER code in jshash.[ch] is now JS_HASHMETER-controlled and based on JSBasicStats. * DEBUG_scopemeters macro renamed JS_DUMP_SCOPE_METERS; uses JSBasicStats now. * Disentangle DEBUG and DUMP_SCOPE_STATS (now JS_DUMP_PROPTREE_STATS) and fix inconsistent thread safety for liveScopeProps (sometimes atomic-incremented, sometimes runtime-locked). * Compiler-modeled maxScopeDepth will propagate via JSScript to runtime for capability-based, interpreter-inlined cache hit qualifier bits, to bypass scope and prototype chain lookup by optimizing for common monomorphic get, set, and call site referencing a prototype property in a well-named object (no shadowing or mutation in 99.9% of the cases).
2008-01-13 03:31:31 +03:00
|
|
|
#ifdef JS_HASHMETER
|
2001-08-07 06:48:10 +04:00
|
|
|
ht->ngrows++;
|
|
|
|
#endif
|
1998-10-14 14:22:38 +04:00
|
|
|
hep = JS_HashTableRawLookup(ht, keyHash, key);
|
1998-09-03 02:37:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Make a new key value entry */
|
2004-04-13 05:25:17 +04:00
|
|
|
he = ht->allocOps->allocEntry(ht->allocPriv, key);
|
1998-09-03 02:37:14 +04:00
|
|
|
if (!he)
|
2013-09-19 23:26:36 +04:00
|
|
|
return nullptr;
|
1998-09-03 02:37:14 +04:00
|
|
|
he->keyHash = keyHash;
|
|
|
|
he->key = key;
|
|
|
|
he->value = value;
|
|
|
|
he->next = *hep;
|
|
|
|
*hep = he;
|
|
|
|
ht->nentries++;
|
|
|
|
return he;
|
|
|
|
}
|
|
|
|
|
2012-07-19 04:38:10 +04:00
|
|
|
JSHashEntry *
|
1998-10-14 14:22:38 +04:00
|
|
|
JS_HashTableAdd(JSHashTable *ht, const void *key, void *value)
|
1998-09-03 02:37:14 +04:00
|
|
|
{
|
1998-10-14 14:22:38 +04:00
|
|
|
JSHashNumber keyHash;
|
|
|
|
JSHashEntry *he, **hep;
|
1998-09-03 02:37:14 +04:00
|
|
|
|
2004-04-13 05:25:17 +04:00
|
|
|
keyHash = ht->keyHash(key);
|
1998-10-14 14:22:38 +04:00
|
|
|
hep = JS_HashTableRawLookup(ht, keyHash, key);
|
2013-09-19 23:26:36 +04:00
|
|
|
if ((he = *hep) != nullptr) {
|
1998-09-03 02:37:14 +04:00
|
|
|
/* Hit; see if values match */
|
2004-04-13 05:25:17 +04:00
|
|
|
if (ht->valueCompare(he->value, value)) {
|
1998-09-03 02:37:14 +04:00
|
|
|
/* key,value pair is already present in table */
|
|
|
|
return he;
|
|
|
|
}
|
|
|
|
if (he->value)
|
2004-04-13 05:25:17 +04:00
|
|
|
ht->allocOps->freeEntry(ht->allocPriv, he, HT_FREE_VALUE);
|
1998-09-03 02:37:14 +04:00
|
|
|
he->value = value;
|
|
|
|
return he;
|
|
|
|
}
|
1998-10-14 14:22:38 +04:00
|
|
|
return JS_HashTableRawAdd(ht, hep, keyHash, key, value);
|
1998-09-03 02:37:14 +04:00
|
|
|
}
|
|
|
|
|
2012-07-19 04:38:10 +04:00
|
|
|
void
|
1998-10-14 14:22:38 +04:00
|
|
|
JS_HashTableRawRemove(JSHashTable *ht, JSHashEntry **hep, JSHashEntry *he)
|
1998-09-03 02:37:14 +04:00
|
|
|
{
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 07:54:10 +04:00
|
|
|
uint32_t n;
|
1998-09-03 02:37:14 +04:00
|
|
|
|
|
|
|
*hep = he->next;
|
2004-04-13 05:25:17 +04:00
|
|
|
ht->allocOps->freeEntry(ht->allocPriv, he, HT_FREE_ENTRY);
|
1998-09-03 02:37:14 +04:00
|
|
|
|
|
|
|
/* Shrink table if it's underloaded */
|
|
|
|
n = NBUCKETS(ht);
|
|
|
|
if (--ht->nentries < UNDERLOADED(n)) {
|
2006-02-24 01:20:27 +03:00
|
|
|
Resize(ht, ht->shift + 1);
|
* Menu of -D flags for enabling instrumentation, as a commented-out CFLAGS += setting for convenient testing. * js_FindProperty and js_LookupPropertyWithFlags return indexes into the scope and prototype chains, respectively, to support internal instrumentation, and to pave the way for the return of the property cache (bug 365851).. * jsutil.[ch] JSBasicStats struct and functions for computing mean/sigma/max and auto-scaling histogram. * JS_SCOPE_DEPTH_METER instrumentation for compile- and run-time scope chain length instrumentation: + At compile time, rt->hostenvScopeDepthStats and rt->lexicalScopeDepthStats meter scope chains passed into the compile and evaluate APIs. + At runtime, rt->protoLookupDepthStats and rt->scopeSearchDepthStats track steps along the prototype and scope chains until the sought-after property is found. * JS_ARENAMETER uses JSBasicStats now. * Added rt->liveScopePropsPreSweep to fix the property tree stats code that rotted when property tree sweeping moved to after the finalization phase. * Un-bitrotted some DEBUG_brendan code, turned some off for myself via XXX. * Mac OS X toolchain requires initialized data shared across dynamic library member files, outlaws common data, so initialize extern metering vars. * Old HASHMETER code in jshash.[ch] is now JS_HASHMETER-controlled and based on JSBasicStats. * DEBUG_scopemeters macro renamed JS_DUMP_SCOPE_METERS; uses JSBasicStats now. * Disentangle DEBUG and DUMP_SCOPE_STATS (now JS_DUMP_PROPTREE_STATS) and fix inconsistent thread safety for liveScopeProps (sometimes atomic-incremented, sometimes runtime-locked). * Compiler-modeled maxScopeDepth will propagate via JSScript to runtime for capability-based, interpreter-inlined cache hit qualifier bits, to bypass scope and prototype chain lookup by optimizing for common monomorphic get, set, and call site referencing a prototype property in a well-named object (no shadowing or mutation in 99.9% of the cases).
2008-01-13 03:31:31 +03:00
|
|
|
#ifdef JS_HASHMETER
|
2001-08-07 06:48:10 +04:00
|
|
|
ht->nshrinks++;
|
|
|
|
#endif
|
1998-09-03 02:37:14 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-09 02:53:04 +04:00
|
|
|
bool
|
1998-10-14 14:22:38 +04:00
|
|
|
JS_HashTableRemove(JSHashTable *ht, const void *key)
|
1998-09-03 02:37:14 +04:00
|
|
|
{
|
1998-10-14 14:22:38 +04:00
|
|
|
JSHashNumber keyHash;
|
|
|
|
JSHashEntry *he, **hep;
|
1998-09-03 02:37:14 +04:00
|
|
|
|
2004-04-13 05:25:17 +04:00
|
|
|
keyHash = ht->keyHash(key);
|
1998-10-14 14:22:38 +04:00
|
|
|
hep = JS_HashTableRawLookup(ht, keyHash, key);
|
2013-09-19 23:26:36 +04:00
|
|
|
if ((he = *hep) == nullptr)
|
2013-08-07 10:59:54 +04:00
|
|
|
return false;
|
1998-09-03 02:37:14 +04:00
|
|
|
|
|
|
|
/* Hit; remove element */
|
1998-10-14 14:22:38 +04:00
|
|
|
JS_HashTableRawRemove(ht, hep, he);
|
2013-08-07 10:59:54 +04:00
|
|
|
return true;
|
1998-09-03 02:37:14 +04:00
|
|
|
}
|
|
|
|
|
2012-07-19 04:38:10 +04:00
|
|
|
void *
|
1998-10-14 14:22:38 +04:00
|
|
|
JS_HashTableLookup(JSHashTable *ht, const void *key)
|
1998-09-03 02:37:14 +04:00
|
|
|
{
|
1998-10-14 14:22:38 +04:00
|
|
|
JSHashNumber keyHash;
|
|
|
|
JSHashEntry *he, **hep;
|
1998-09-03 02:37:14 +04:00
|
|
|
|
2004-04-13 05:25:17 +04:00
|
|
|
keyHash = ht->keyHash(key);
|
1998-10-14 14:22:38 +04:00
|
|
|
hep = JS_HashTableRawLookup(ht, keyHash, key);
|
2013-09-19 23:26:36 +04:00
|
|
|
if ((he = *hep) != nullptr) {
|
1998-09-03 02:37:14 +04:00
|
|
|
return he->value;
|
|
|
|
}
|
2013-09-19 23:26:36 +04:00
|
|
|
return nullptr;
|
1998-09-03 02:37:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Iterate over the entries in the hash table calling func for each
|
1998-10-14 14:22:38 +04:00
|
|
|
** entry found. Stop if "f" says to (return value & JS_ENUMERATE_STOP).
|
1998-09-03 02:37:14 +04:00
|
|
|
** Return a count of the number of elements scanned.
|
|
|
|
*/
|
2012-07-19 04:38:10 +04:00
|
|
|
int
|
1998-10-14 14:22:38 +04:00
|
|
|
JS_HashTableEnumerateEntries(JSHashTable *ht, JSHashEnumerator f, void *arg)
|
1998-09-03 02:37:14 +04:00
|
|
|
{
|
2006-02-24 01:20:27 +03:00
|
|
|
JSHashEntry *he, **hep, **bucket;
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 07:54:10 +04:00
|
|
|
uint32_t nlimit, n, nbuckets, newlog2;
|
2006-02-24 01:20:27 +03:00
|
|
|
int rv;
|
|
|
|
|
|
|
|
nlimit = ht->nentries;
|
|
|
|
n = 0;
|
|
|
|
for (bucket = ht->buckets; n != nlimit; ++bucket) {
|
|
|
|
hep = bucket;
|
2013-09-19 23:26:36 +04:00
|
|
|
while ((he = *hep) != nullptr) {
|
2014-02-18 10:24:15 +04:00
|
|
|
MOZ_ASSERT(n < nlimit);
|
2004-04-13 05:25:17 +04:00
|
|
|
rv = f(he, n, arg);
|
1998-09-03 02:37:14 +04:00
|
|
|
n++;
|
2006-02-23 13:11:17 +03:00
|
|
|
if (rv & HT_ENUMERATE_REMOVE) {
|
1998-09-03 02:37:14 +04:00
|
|
|
*hep = he->next;
|
2006-02-24 01:20:27 +03:00
|
|
|
ht->allocOps->freeEntry(ht->allocPriv, he, HT_FREE_ENTRY);
|
|
|
|
--ht->nentries;
|
1998-09-03 02:37:14 +04:00
|
|
|
} else {
|
|
|
|
hep = &he->next;
|
|
|
|
}
|
|
|
|
if (rv & HT_ENUMERATE_STOP) {
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
2006-02-24 01:20:27 +03:00
|
|
|
/* Shrink table if removal of entries made it underloaded */
|
|
|
|
if (ht->nentries != nlimit) {
|
2014-02-18 10:24:15 +04:00
|
|
|
MOZ_ASSERT(ht->nentries < nlimit);
|
2006-02-24 01:20:27 +03:00
|
|
|
nbuckets = NBUCKETS(ht);
|
|
|
|
if (MINBUCKETS < nbuckets && ht->nentries < UNDERLOADED(nbuckets)) {
|
2013-07-04 02:46:51 +04:00
|
|
|
newlog2 = CeilingLog2Size(ht->nentries);
|
2006-02-24 01:20:27 +03:00
|
|
|
if (newlog2 < MINBUCKETSLOG2)
|
|
|
|
newlog2 = MINBUCKETSLOG2;
|
|
|
|
|
|
|
|
/* Check that we really shrink the table. */
|
2014-02-18 10:24:15 +04:00
|
|
|
MOZ_ASSERT(JS_HASH_BITS - ht->shift > newlog2);
|
2006-02-24 01:20:27 +03:00
|
|
|
Resize(ht, JS_HASH_BITS - newlog2);
|
|
|
|
}
|
1998-09-03 02:37:14 +04:00
|
|
|
}
|
2006-02-24 01:20:27 +03:00
|
|
|
return (int)n;
|
1998-09-03 02:37:14 +04:00
|
|
|
}
|
|
|
|
|
* Menu of -D flags for enabling instrumentation, as a commented-out CFLAGS += setting for convenient testing. * js_FindProperty and js_LookupPropertyWithFlags return indexes into the scope and prototype chains, respectively, to support internal instrumentation, and to pave the way for the return of the property cache (bug 365851).. * jsutil.[ch] JSBasicStats struct and functions for computing mean/sigma/max and auto-scaling histogram. * JS_SCOPE_DEPTH_METER instrumentation for compile- and run-time scope chain length instrumentation: + At compile time, rt->hostenvScopeDepthStats and rt->lexicalScopeDepthStats meter scope chains passed into the compile and evaluate APIs. + At runtime, rt->protoLookupDepthStats and rt->scopeSearchDepthStats track steps along the prototype and scope chains until the sought-after property is found. * JS_ARENAMETER uses JSBasicStats now. * Added rt->liveScopePropsPreSweep to fix the property tree stats code that rotted when property tree sweeping moved to after the finalization phase. * Un-bitrotted some DEBUG_brendan code, turned some off for myself via XXX. * Mac OS X toolchain requires initialized data shared across dynamic library member files, outlaws common data, so initialize extern metering vars. * Old HASHMETER code in jshash.[ch] is now JS_HASHMETER-controlled and based on JSBasicStats. * DEBUG_scopemeters macro renamed JS_DUMP_SCOPE_METERS; uses JSBasicStats now. * Disentangle DEBUG and DUMP_SCOPE_STATS (now JS_DUMP_PROPTREE_STATS) and fix inconsistent thread safety for liveScopeProps (sometimes atomic-incremented, sometimes runtime-locked). * Compiler-modeled maxScopeDepth will propagate via JSScript to runtime for capability-based, interpreter-inlined cache hit qualifier bits, to bypass scope and prototype chain lookup by optimizing for common monomorphic get, set, and call site referencing a prototype property in a well-named object (no shadowing or mutation in 99.9% of the cases).
2008-01-13 03:31:31 +03:00
|
|
|
#ifdef JS_HASHMETER
|
1998-09-03 02:37:14 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2012-07-19 04:38:10 +04:00
|
|
|
void
|
1998-10-14 14:22:38 +04:00
|
|
|
JS_HashTableDumpMeter(JSHashTable *ht, JSHashEnumerator dump, FILE *fp)
|
1998-09-03 02:37:14 +04:00
|
|
|
{
|
* Menu of -D flags for enabling instrumentation, as a commented-out CFLAGS += setting for convenient testing. * js_FindProperty and js_LookupPropertyWithFlags return indexes into the scope and prototype chains, respectively, to support internal instrumentation, and to pave the way for the return of the property cache (bug 365851).. * jsutil.[ch] JSBasicStats struct and functions for computing mean/sigma/max and auto-scaling histogram. * JS_SCOPE_DEPTH_METER instrumentation for compile- and run-time scope chain length instrumentation: + At compile time, rt->hostenvScopeDepthStats and rt->lexicalScopeDepthStats meter scope chains passed into the compile and evaluate APIs. + At runtime, rt->protoLookupDepthStats and rt->scopeSearchDepthStats track steps along the prototype and scope chains until the sought-after property is found. * JS_ARENAMETER uses JSBasicStats now. * Added rt->liveScopePropsPreSweep to fix the property tree stats code that rotted when property tree sweeping moved to after the finalization phase. * Un-bitrotted some DEBUG_brendan code, turned some off for myself via XXX. * Mac OS X toolchain requires initialized data shared across dynamic library member files, outlaws common data, so initialize extern metering vars. * Old HASHMETER code in jshash.[ch] is now JS_HASHMETER-controlled and based on JSBasicStats. * DEBUG_scopemeters macro renamed JS_DUMP_SCOPE_METERS; uses JSBasicStats now. * Disentangle DEBUG and DUMP_SCOPE_STATS (now JS_DUMP_PROPTREE_STATS) and fix inconsistent thread safety for liveScopeProps (sometimes atomic-incremented, sometimes runtime-locked). * Compiler-modeled maxScopeDepth will propagate via JSScript to runtime for capability-based, interpreter-inlined cache hit qualifier bits, to bypass scope and prototype chain lookup by optimizing for common monomorphic get, set, and call site referencing a prototype property in a well-named object (no shadowing or mutation in 99.9% of the cases).
2008-01-13 03:31:31 +03:00
|
|
|
double sqsum, mean, sigma;
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 07:54:10 +04:00
|
|
|
uint32_t nchains, nbuckets;
|
|
|
|
uint32_t i, n, maxChain, maxChainLen;
|
1998-10-14 14:22:38 +04:00
|
|
|
JSHashEntry *he;
|
1998-09-03 02:37:14 +04:00
|
|
|
|
2000-05-20 22:41:13 +04:00
|
|
|
sqsum = 0;
|
1998-09-03 02:37:14 +04:00
|
|
|
nchains = 0;
|
* Menu of -D flags for enabling instrumentation, as a commented-out CFLAGS += setting for convenient testing. * js_FindProperty and js_LookupPropertyWithFlags return indexes into the scope and prototype chains, respectively, to support internal instrumentation, and to pave the way for the return of the property cache (bug 365851).. * jsutil.[ch] JSBasicStats struct and functions for computing mean/sigma/max and auto-scaling histogram. * JS_SCOPE_DEPTH_METER instrumentation for compile- and run-time scope chain length instrumentation: + At compile time, rt->hostenvScopeDepthStats and rt->lexicalScopeDepthStats meter scope chains passed into the compile and evaluate APIs. + At runtime, rt->protoLookupDepthStats and rt->scopeSearchDepthStats track steps along the prototype and scope chains until the sought-after property is found. * JS_ARENAMETER uses JSBasicStats now. * Added rt->liveScopePropsPreSweep to fix the property tree stats code that rotted when property tree sweeping moved to after the finalization phase. * Un-bitrotted some DEBUG_brendan code, turned some off for myself via XXX. * Mac OS X toolchain requires initialized data shared across dynamic library member files, outlaws common data, so initialize extern metering vars. * Old HASHMETER code in jshash.[ch] is now JS_HASHMETER-controlled and based on JSBasicStats. * DEBUG_scopemeters macro renamed JS_DUMP_SCOPE_METERS; uses JSBasicStats now. * Disentangle DEBUG and DUMP_SCOPE_STATS (now JS_DUMP_PROPTREE_STATS) and fix inconsistent thread safety for liveScopeProps (sometimes atomic-incremented, sometimes runtime-locked). * Compiler-modeled maxScopeDepth will propagate via JSScript to runtime for capability-based, interpreter-inlined cache hit qualifier bits, to bypass scope and prototype chain lookup by optimizing for common monomorphic get, set, and call site referencing a prototype property in a well-named object (no shadowing or mutation in 99.9% of the cases).
2008-01-13 03:31:31 +03:00
|
|
|
maxChain = maxChainLen = 0;
|
1998-09-03 02:37:14 +04:00
|
|
|
nbuckets = NBUCKETS(ht);
|
|
|
|
for (i = 0; i < nbuckets; i++) {
|
|
|
|
he = ht->buckets[i];
|
|
|
|
if (!he)
|
|
|
|
continue;
|
|
|
|
nchains++;
|
|
|
|
for (n = 0; he; he = he->next)
|
|
|
|
n++;
|
2000-05-20 22:41:13 +04:00
|
|
|
sqsum += n * n;
|
1998-09-03 02:37:14 +04:00
|
|
|
if (n > maxChainLen) {
|
|
|
|
maxChainLen = n;
|
|
|
|
maxChain = i;
|
|
|
|
}
|
|
|
|
}
|
* Menu of -D flags for enabling instrumentation, as a commented-out CFLAGS += setting for convenient testing. * js_FindProperty and js_LookupPropertyWithFlags return indexes into the scope and prototype chains, respectively, to support internal instrumentation, and to pave the way for the return of the property cache (bug 365851).. * jsutil.[ch] JSBasicStats struct and functions for computing mean/sigma/max and auto-scaling histogram. * JS_SCOPE_DEPTH_METER instrumentation for compile- and run-time scope chain length instrumentation: + At compile time, rt->hostenvScopeDepthStats and rt->lexicalScopeDepthStats meter scope chains passed into the compile and evaluate APIs. + At runtime, rt->protoLookupDepthStats and rt->scopeSearchDepthStats track steps along the prototype and scope chains until the sought-after property is found. * JS_ARENAMETER uses JSBasicStats now. * Added rt->liveScopePropsPreSweep to fix the property tree stats code that rotted when property tree sweeping moved to after the finalization phase. * Un-bitrotted some DEBUG_brendan code, turned some off for myself via XXX. * Mac OS X toolchain requires initialized data shared across dynamic library member files, outlaws common data, so initialize extern metering vars. * Old HASHMETER code in jshash.[ch] is now JS_HASHMETER-controlled and based on JSBasicStats. * DEBUG_scopemeters macro renamed JS_DUMP_SCOPE_METERS; uses JSBasicStats now. * Disentangle DEBUG and DUMP_SCOPE_STATS (now JS_DUMP_PROPTREE_STATS) and fix inconsistent thread safety for liveScopeProps (sometimes atomic-incremented, sometimes runtime-locked). * Compiler-modeled maxScopeDepth will propagate via JSScript to runtime for capability-based, interpreter-inlined cache hit qualifier bits, to bypass scope and prototype chain lookup by optimizing for common monomorphic get, set, and call site referencing a prototype property in a well-named object (no shadowing or mutation in 99.9% of the cases).
2008-01-13 03:31:31 +03:00
|
|
|
|
|
|
|
mean = JS_MeanAndStdDev(nchains, ht->nentries, sqsum, &sigma);
|
1998-09-03 02:37:14 +04:00
|
|
|
|
|
|
|
fprintf(fp, "\nHash table statistics:\n");
|
|
|
|
fprintf(fp, " number of lookups: %u\n", ht->nlookups);
|
|
|
|
fprintf(fp, " number of entries: %u\n", ht->nentries);
|
|
|
|
fprintf(fp, " number of grows: %u\n", ht->ngrows);
|
|
|
|
fprintf(fp, " number of shrinks: %u\n", ht->nshrinks);
|
|
|
|
fprintf(fp, " mean steps per hash: %g\n", (double)ht->nsteps
|
|
|
|
/ ht->nlookups);
|
|
|
|
fprintf(fp, "mean hash chain length: %g\n", mean);
|
2000-05-20 22:41:13 +04:00
|
|
|
fprintf(fp, " standard deviation: %g\n", sigma);
|
1998-09-03 02:37:14 +04:00
|
|
|
fprintf(fp, " max hash chain length: %u\n", maxChainLen);
|
|
|
|
fprintf(fp, " max hash chain: [%u]\n", maxChain);
|
|
|
|
|
|
|
|
for (he = ht->buckets[maxChain], i = 0; he; he = he->next, i++)
|
2004-04-13 05:25:17 +04:00
|
|
|
if (dump(he, i, fp) != HT_ENUMERATE_NEXT)
|
1998-09-03 02:37:14 +04:00
|
|
|
break;
|
|
|
|
}
|
* Menu of -D flags for enabling instrumentation, as a commented-out CFLAGS += setting for convenient testing. * js_FindProperty and js_LookupPropertyWithFlags return indexes into the scope and prototype chains, respectively, to support internal instrumentation, and to pave the way for the return of the property cache (bug 365851).. * jsutil.[ch] JSBasicStats struct and functions for computing mean/sigma/max and auto-scaling histogram. * JS_SCOPE_DEPTH_METER instrumentation for compile- and run-time scope chain length instrumentation: + At compile time, rt->hostenvScopeDepthStats and rt->lexicalScopeDepthStats meter scope chains passed into the compile and evaluate APIs. + At runtime, rt->protoLookupDepthStats and rt->scopeSearchDepthStats track steps along the prototype and scope chains until the sought-after property is found. * JS_ARENAMETER uses JSBasicStats now. * Added rt->liveScopePropsPreSweep to fix the property tree stats code that rotted when property tree sweeping moved to after the finalization phase. * Un-bitrotted some DEBUG_brendan code, turned some off for myself via XXX. * Mac OS X toolchain requires initialized data shared across dynamic library member files, outlaws common data, so initialize extern metering vars. * Old HASHMETER code in jshash.[ch] is now JS_HASHMETER-controlled and based on JSBasicStats. * DEBUG_scopemeters macro renamed JS_DUMP_SCOPE_METERS; uses JSBasicStats now. * Disentangle DEBUG and DUMP_SCOPE_STATS (now JS_DUMP_PROPTREE_STATS) and fix inconsistent thread safety for liveScopeProps (sometimes atomic-incremented, sometimes runtime-locked). * Compiler-modeled maxScopeDepth will propagate via JSScript to runtime for capability-based, interpreter-inlined cache hit qualifier bits, to bypass scope and prototype chain lookup by optimizing for common monomorphic get, set, and call site referencing a prototype property in a well-named object (no shadowing or mutation in 99.9% of the cases).
2008-01-13 03:31:31 +03:00
|
|
|
#endif /* JS_HASHMETER */
|
1998-09-03 02:37:14 +04:00
|
|
|
|
2012-07-19 04:38:10 +04:00
|
|
|
int
|
1998-10-14 14:22:38 +04:00
|
|
|
JS_HashTableDump(JSHashTable *ht, JSHashEnumerator dump, FILE *fp)
|
1998-09-03 02:37:14 +04:00
|
|
|
{
|
|
|
|
int count;
|
|
|
|
|
1998-10-14 14:22:38 +04:00
|
|
|
count = JS_HashTableEnumerateEntries(ht, dump, fp);
|
* Menu of -D flags for enabling instrumentation, as a commented-out CFLAGS += setting for convenient testing. * js_FindProperty and js_LookupPropertyWithFlags return indexes into the scope and prototype chains, respectively, to support internal instrumentation, and to pave the way for the return of the property cache (bug 365851).. * jsutil.[ch] JSBasicStats struct and functions for computing mean/sigma/max and auto-scaling histogram. * JS_SCOPE_DEPTH_METER instrumentation for compile- and run-time scope chain length instrumentation: + At compile time, rt->hostenvScopeDepthStats and rt->lexicalScopeDepthStats meter scope chains passed into the compile and evaluate APIs. + At runtime, rt->protoLookupDepthStats and rt->scopeSearchDepthStats track steps along the prototype and scope chains until the sought-after property is found. * JS_ARENAMETER uses JSBasicStats now. * Added rt->liveScopePropsPreSweep to fix the property tree stats code that rotted when property tree sweeping moved to after the finalization phase. * Un-bitrotted some DEBUG_brendan code, turned some off for myself via XXX. * Mac OS X toolchain requires initialized data shared across dynamic library member files, outlaws common data, so initialize extern metering vars. * Old HASHMETER code in jshash.[ch] is now JS_HASHMETER-controlled and based on JSBasicStats. * DEBUG_scopemeters macro renamed JS_DUMP_SCOPE_METERS; uses JSBasicStats now. * Disentangle DEBUG and DUMP_SCOPE_STATS (now JS_DUMP_PROPTREE_STATS) and fix inconsistent thread safety for liveScopeProps (sometimes atomic-incremented, sometimes runtime-locked). * Compiler-modeled maxScopeDepth will propagate via JSScript to runtime for capability-based, interpreter-inlined cache hit qualifier bits, to bypass scope and prototype chain lookup by optimizing for common monomorphic get, set, and call site referencing a prototype property in a well-named object (no shadowing or mutation in 99.9% of the cases).
2008-01-13 03:31:31 +03:00
|
|
|
#ifdef JS_HASHMETER
|
1998-10-14 14:22:38 +04:00
|
|
|
JS_HashTableDumpMeter(ht, dump, fp);
|
1998-09-03 02:37:14 +04:00
|
|
|
#endif
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2012-07-19 04:38:10 +04:00
|
|
|
JSHashNumber
|
1998-10-14 14:22:38 +04:00
|
|
|
JS_HashString(const void *key)
|
1998-09-03 02:37:14 +04:00
|
|
|
{
|
1998-10-14 14:22:38 +04:00
|
|
|
JSHashNumber h;
|
|
|
|
const unsigned char *s;
|
1998-09-03 02:37:14 +04:00
|
|
|
|
|
|
|
h = 0;
|
2000-02-02 04:10:31 +03:00
|
|
|
for (s = (const unsigned char *)key; *s; s++)
|
2014-01-20 11:58:26 +04:00
|
|
|
h = RotateLeft(h, 4) ^ *s;
|
1998-09-03 02:37:14 +04:00
|
|
|
return h;
|
|
|
|
}
|
|
|
|
|
2012-07-19 04:38:10 +04:00
|
|
|
int
|
1998-10-14 14:22:38 +04:00
|
|
|
JS_CompareValues(const void *v1, const void *v2)
|
1998-09-03 02:37:14 +04:00
|
|
|
{
|
|
|
|
return v1 == v2;
|
|
|
|
}
|