2010-03-22 11:11:44 -07:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 4; tab-width: 40; indent-tabs-mode: nil -*- */
|
|
|
|
/* vim: set ts=40 sw=4 et tw=99: */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is the Mozilla SpiderMonkey property tree implementation
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Mozilla Foundation
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2002-2010
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Brendan Eich <brendan@mozilla.org>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
#include <new>
|
|
|
|
|
2010-03-22 11:11:44 -07:00
|
|
|
#include "jstypes.h"
|
|
|
|
#include "jsarena.h"
|
|
|
|
#include "jsprf.h"
|
|
|
|
#include "jsapi.h"
|
|
|
|
#include "jscntxt.h"
|
|
|
|
#include "jsgc.h"
|
|
|
|
#include "jspropertytree.h"
|
|
|
|
#include "jsscope.h"
|
|
|
|
|
2010-06-18 17:43:02 -07:00
|
|
|
#include "jsobjinlines.h"
|
2010-03-22 11:11:44 -07:00
|
|
|
#include "jsscopeinlines.h"
|
|
|
|
|
|
|
|
using namespace js;
|
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
inline HashNumber
|
|
|
|
ShapeHasher::hash(const Lookup l)
|
2010-03-22 11:11:44 -07:00
|
|
|
{
|
2010-08-29 11:57:08 -07:00
|
|
|
return l->hash();
|
2010-03-22 11:11:44 -07:00
|
|
|
}
|
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
inline bool
|
|
|
|
ShapeHasher::match(const Key k, const Lookup l)
|
2010-03-22 11:11:44 -07:00
|
|
|
{
|
2010-08-29 11:57:08 -07:00
|
|
|
return l->matches(k);
|
2010-03-22 11:11:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
PropertyTree::init()
|
|
|
|
{
|
2010-07-11 00:09:34 -07:00
|
|
|
JS_InitArenaPool(&arenaPool, "properties",
|
2010-08-29 11:57:08 -07:00
|
|
|
256 * sizeof(Shape), sizeof(void *), NULL);
|
2010-03-22 11:11:44 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PropertyTree::finish()
|
|
|
|
{
|
2010-07-11 00:09:34 -07:00
|
|
|
JS_FinishArenaPool(&arenaPool);
|
2010-03-22 11:11:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NB: Called with cx->runtime->gcLock held if gcLocked is true.
|
|
|
|
* On failure, return null after unlocking the GC and reporting out of memory.
|
|
|
|
*/
|
2010-08-29 11:57:08 -07:00
|
|
|
Shape *
|
|
|
|
PropertyTree::newShape(JSContext *cx, bool gcLocked)
|
2010-03-22 11:11:44 -07:00
|
|
|
{
|
2010-08-29 11:57:08 -07:00
|
|
|
Shape *shape;
|
2010-03-22 11:11:44 -07:00
|
|
|
|
|
|
|
if (!gcLocked)
|
|
|
|
JS_LOCK_GC(cx->runtime);
|
2010-08-29 11:57:08 -07:00
|
|
|
shape = freeList;
|
|
|
|
if (shape) {
|
|
|
|
shape->removeFree();
|
2010-03-22 11:11:44 -07:00
|
|
|
} else {
|
2010-08-29 11:57:08 -07:00
|
|
|
JS_ARENA_ALLOCATE_CAST(shape, Shape *, &arenaPool, sizeof(Shape));
|
|
|
|
if (!shape) {
|
2010-03-22 11:11:44 -07:00
|
|
|
JS_UNLOCK_GC(cx->runtime);
|
|
|
|
JS_ReportOutOfMemory(cx);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!gcLocked)
|
|
|
|
JS_UNLOCK_GC(cx->runtime);
|
|
|
|
|
|
|
|
JS_RUNTIME_METER(cx->runtime, livePropTreeNodes);
|
|
|
|
JS_RUNTIME_METER(cx->runtime, totalPropTreeNodes);
|
2010-08-29 11:57:08 -07:00
|
|
|
return shape;
|
2010-03-22 11:11:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NB: Called with cx->runtime->gcLock held, always.
|
|
|
|
* On failure, return null after unlocking the GC and reporting out of memory.
|
|
|
|
*/
|
2010-08-29 11:57:08 -07:00
|
|
|
KidsChunk *
|
|
|
|
KidsChunk::create(JSContext *cx)
|
2010-03-22 11:11:44 -07:00
|
|
|
{
|
2010-08-29 11:57:08 -07:00
|
|
|
KidsChunk *chunk;
|
2010-03-22 11:11:44 -07:00
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
chunk = (KidsChunk *) js_calloc(sizeof *chunk);
|
2010-03-22 11:11:44 -07:00
|
|
|
if (!chunk) {
|
|
|
|
JS_UNLOCK_GC(cx->runtime);
|
|
|
|
JS_ReportOutOfMemory(cx);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
JS_RUNTIME_METER(cx->runtime, propTreeKidsChunks);
|
|
|
|
return chunk;
|
|
|
|
}
|
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
KidsChunk *
|
|
|
|
KidsChunk::destroy(JSContext *cx, KidsChunk *chunk)
|
2010-03-22 11:11:44 -07:00
|
|
|
{
|
|
|
|
JS_RUNTIME_UNMETER(cx->runtime, propTreeKidsChunks);
|
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
KidsChunk *nextChunk = chunk->next;
|
2010-03-22 11:11:44 -07:00
|
|
|
js_free(chunk);
|
|
|
|
return nextChunk;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NB: Called with cx->runtime->gcLock held, always.
|
|
|
|
* On failure, return null after unlocking the GC and reporting out of memory.
|
|
|
|
*/
|
|
|
|
bool
|
2010-08-29 11:57:08 -07:00
|
|
|
PropertyTree::insertChild(JSContext *cx, Shape *parent, Shape *child)
|
2010-03-22 11:11:44 -07:00
|
|
|
{
|
2010-08-29 11:57:08 -07:00
|
|
|
JS_ASSERT(!parent->inDictionary());
|
2010-03-22 11:11:44 -07:00
|
|
|
JS_ASSERT(!child->parent);
|
2010-08-29 11:57:08 -07:00
|
|
|
JS_ASSERT(!child->inDictionary());
|
2010-07-14 23:19:36 -07:00
|
|
|
JS_ASSERT(!JSID_IS_VOID(parent->id));
|
|
|
|
JS_ASSERT(!JSID_IS_VOID(child->id));
|
2010-03-22 11:11:44 -07:00
|
|
|
|
2010-09-02 14:50:44 -07:00
|
|
|
child->setParent(parent);
|
2010-03-22 11:11:44 -07:00
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
KidsPointer *kidp = &parent->kids;
|
|
|
|
if (kidp->isNull()) {
|
|
|
|
kidp->setShape(child);
|
|
|
|
return true;
|
|
|
|
}
|
2010-03-22 11:11:44 -07:00
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
Shape *shape;
|
|
|
|
|
|
|
|
if (kidp->isShape()) {
|
|
|
|
shape = kidp->toShape();
|
|
|
|
JS_ASSERT(shape != child);
|
|
|
|
if (shape->matches(child)) {
|
|
|
|
/*
|
|
|
|
* Duplicate child created while racing to getChild on the same
|
|
|
|
* node label. See PropertyTree::getChild, further below.
|
|
|
|
*/
|
|
|
|
JS_RUNTIME_METER(cx->runtime, duplicatePropTreeNodes);
|
2010-03-22 11:11:44 -07:00
|
|
|
}
|
2010-08-29 11:57:08 -07:00
|
|
|
|
|
|
|
KidsChunk *chunk = KidsChunk::create(cx);
|
|
|
|
if (!chunk)
|
|
|
|
return false;
|
|
|
|
parent->kids.setChunk(chunk);
|
|
|
|
chunk->kids[0] = shape;
|
|
|
|
chunk->kids[1] = child;
|
|
|
|
return true;
|
2010-03-22 11:11:44 -07:00
|
|
|
}
|
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
if (kidp->isChunk()) {
|
|
|
|
KidsChunk **chunkp;
|
|
|
|
KidsChunk *chunk = kidp->toChunk();
|
|
|
|
|
|
|
|
do {
|
|
|
|
for (uintN i = 0; i < MAX_KIDS_PER_CHUNK; i++) {
|
|
|
|
shape = chunk->kids[i];
|
|
|
|
if (!shape) {
|
|
|
|
chunk->kids[i] = child;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ASSERT(shape != child);
|
|
|
|
if (shape->matches(child)) {
|
|
|
|
/*
|
|
|
|
* Duplicate child, see comment above. In this case, we
|
|
|
|
* must let the duplicate be inserted at this level in the
|
|
|
|
* tree, so we keep iterating, looking for an empty slot in
|
|
|
|
* which to insert.
|
|
|
|
*/
|
|
|
|
JS_ASSERT(shape != child);
|
|
|
|
JS_RUNTIME_METER(cx->runtime, duplicatePropTreeNodes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
chunkp = &chunk->next;
|
|
|
|
} while ((chunk = *chunkp) != NULL);
|
|
|
|
|
|
|
|
chunk = KidsChunk::create(cx);
|
|
|
|
if (!chunk)
|
|
|
|
return false;
|
|
|
|
*chunkp = chunk;
|
|
|
|
chunk->kids[0] = child;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
KidsHash *hash = kidp->toHash();
|
|
|
|
KidsHash::AddPtr addPtr = hash->lookupForAdd(child);
|
|
|
|
if (!addPtr) {
|
|
|
|
if (!hash->add(addPtr, child))
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
// FIXME ignore duplicate child case here, going thread-local soon!
|
|
|
|
}
|
2010-03-22 11:11:44 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* NB: Called with cx->runtime->gcLock held. */
|
|
|
|
void
|
2010-08-29 11:57:08 -07:00
|
|
|
PropertyTree::removeChild(JSContext *cx, Shape *child)
|
2010-03-22 11:11:44 -07:00
|
|
|
{
|
2010-08-29 11:57:08 -07:00
|
|
|
JS_ASSERT(!child->inDictionary());
|
2010-03-22 11:11:44 -07:00
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
Shape *parent = child->parent;
|
2010-03-22 11:11:44 -07:00
|
|
|
JS_ASSERT(parent);
|
2010-07-14 23:19:36 -07:00
|
|
|
JS_ASSERT(!JSID_IS_VOID(parent->id));
|
2010-03-22 11:11:44 -07:00
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
KidsPointer *kidp = &parent->kids;
|
|
|
|
if (kidp->isShape()) {
|
|
|
|
Shape *kid = kidp->toShape();
|
2010-03-22 11:11:44 -07:00
|
|
|
if (kid == child)
|
2010-08-29 11:57:08 -07:00
|
|
|
parent->kids.setNull();
|
2010-03-22 11:11:44 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
if (kidp->isChunk()) {
|
|
|
|
KidsChunk *list = kidp->toChunk();
|
|
|
|
KidsChunk *chunk = list;
|
|
|
|
KidsChunk **chunkp = &list;
|
2010-03-22 11:11:44 -07:00
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
do {
|
|
|
|
for (uintN i = 0; i < MAX_KIDS_PER_CHUNK; i++) {
|
|
|
|
if (chunk->kids[i] == child) {
|
|
|
|
KidsChunk *lastChunk = chunk;
|
|
|
|
|
|
|
|
uintN j;
|
|
|
|
if (!lastChunk->next) {
|
|
|
|
j = i + 1;
|
|
|
|
} else {
|
|
|
|
j = 0;
|
|
|
|
do {
|
|
|
|
chunkp = &lastChunk->next;
|
|
|
|
lastChunk = *chunkp;
|
|
|
|
} while (lastChunk->next);
|
|
|
|
}
|
|
|
|
for (; j < MAX_KIDS_PER_CHUNK; j++) {
|
|
|
|
if (!lastChunk->kids[j])
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
--j;
|
|
|
|
|
|
|
|
if (chunk != lastChunk || j > i)
|
|
|
|
chunk->kids[i] = lastChunk->kids[j];
|
|
|
|
lastChunk->kids[j] = NULL;
|
|
|
|
if (j == 0) {
|
|
|
|
*chunkp = NULL;
|
|
|
|
if (!list)
|
|
|
|
parent->kids.setNull();
|
|
|
|
KidsChunk::destroy(cx, lastChunk);
|
|
|
|
}
|
|
|
|
return;
|
2010-03-22 11:11:44 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
chunkp = &chunk->next;
|
|
|
|
} while ((chunk = *chunkp) != NULL);
|
2010-03-22 11:11:44 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
kidp->toHash()->remove(child);
|
2010-03-22 11:11:44 -07:00
|
|
|
}
|
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
static KidsHash *
|
|
|
|
HashChunks(KidsChunk *chunk, uintN n)
|
2010-03-22 11:11:44 -07:00
|
|
|
{
|
2010-08-29 11:57:08 -07:00
|
|
|
void *mem = js_malloc(sizeof(KidsHash));
|
|
|
|
if (!mem)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
KidsHash *hash = new (mem) KidsHash();
|
|
|
|
if (!hash->init(n)) {
|
|
|
|
js_free(hash);
|
2010-03-22 11:11:44 -07:00
|
|
|
return NULL;
|
2010-08-29 11:57:08 -07:00
|
|
|
}
|
|
|
|
|
2010-03-22 11:11:44 -07:00
|
|
|
do {
|
2010-08-29 11:57:08 -07:00
|
|
|
for (uintN i = 0; i < MAX_KIDS_PER_CHUNK; i++) {
|
|
|
|
Shape *shape = chunk->kids[i];
|
|
|
|
if (!shape)
|
2010-03-22 11:11:44 -07:00
|
|
|
break;
|
2010-08-29 11:57:08 -07:00
|
|
|
KidsHash::AddPtr addPtr = hash->lookupForAdd(shape);
|
|
|
|
if (!addPtr) {
|
|
|
|
/*
|
|
|
|
* Infallible, we right-sized via hash->init(n) just above.
|
|
|
|
* Assert just in case jshashtable.h ever regresses.
|
|
|
|
*/
|
|
|
|
JS_ALWAYS_TRUE(hash->add(addPtr, shape));
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Duplicate child case, we don't handle this race,
|
|
|
|
* multi-threaded shapes are going away...
|
|
|
|
*/
|
|
|
|
}
|
2010-03-22 11:11:44 -07:00
|
|
|
}
|
|
|
|
} while ((chunk = chunk->next) != NULL);
|
2010-08-29 11:57:08 -07:00
|
|
|
return hash;
|
2010-03-22 11:11:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called without cx->runtime->gcLock held. This function acquires that lock
|
|
|
|
* only when inserting a new child. Thus there may be races to find or add a
|
|
|
|
* node that result in duplicates. We expect such races to be rare!
|
|
|
|
*
|
|
|
|
* We use cx->runtime->gcLock, not ...->rtLock, to avoid nesting the former
|
|
|
|
* inside the latter in js_GenerateShape below.
|
|
|
|
*/
|
2010-08-29 11:57:08 -07:00
|
|
|
Shape *
|
|
|
|
PropertyTree::getChild(JSContext *cx, Shape *parent, const Shape &child)
|
2010-03-22 11:11:44 -07:00
|
|
|
{
|
2010-08-29 11:57:08 -07:00
|
|
|
Shape *shape;
|
2010-03-22 11:11:44 -07:00
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
JS_ASSERT(parent);
|
|
|
|
JS_ASSERT(!JSID_IS_VOID(parent->id));
|
2010-03-22 11:11:44 -07:00
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
/*
|
|
|
|
* Because chunks are appended at the end and never deleted except by
|
|
|
|
* the GC, we can search without taking the runtime's GC lock. We may
|
|
|
|
* miss a matching shape added by another thread, and make a duplicate
|
|
|
|
* one, but that is an unlikely, therefore small, cost. The property
|
|
|
|
* tree has extremely low fan-out below its root in popular embeddings
|
|
|
|
* with real-world workloads.
|
|
|
|
*
|
|
|
|
* Patterns such as defining closures that capture a constructor's
|
|
|
|
* environment as getters or setters on the new object that is passed
|
|
|
|
* in as |this| can significantly increase fan-out below the property
|
|
|
|
* tree root -- see bug 335700 for details.
|
|
|
|
*/
|
|
|
|
KidsPointer *kidp = &parent->kids;
|
|
|
|
if (!kidp->isNull()) {
|
|
|
|
if (kidp->isShape()) {
|
|
|
|
shape = kidp->toShape();
|
|
|
|
if (shape->matches(&child))
|
|
|
|
return shape;
|
|
|
|
} else if (kidp->isChunk()) {
|
|
|
|
KidsChunk *chunk = kidp->toChunk();
|
|
|
|
|
|
|
|
uintN n = 0;
|
|
|
|
do {
|
|
|
|
for (uintN i = 0; i < MAX_KIDS_PER_CHUNK; i++) {
|
|
|
|
shape = chunk->kids[i];
|
|
|
|
if (!shape) {
|
|
|
|
n += i;
|
|
|
|
if (n >= CHUNK_HASH_THRESHOLD) {
|
|
|
|
/*
|
|
|
|
* kidp->isChunk() was true, but if we're racing it
|
|
|
|
* may not be by this point. FIXME: thread "safety"
|
|
|
|
* is for the birds!
|
|
|
|
*/
|
|
|
|
if (!kidp->isHash()) {
|
|
|
|
chunk = kidp->toChunk();
|
|
|
|
|
|
|
|
KidsHash *hash = HashChunks(chunk, n);
|
|
|
|
if (!hash) {
|
|
|
|
JS_ReportOutOfMemory(cx);
|
|
|
|
return NULL;
|
|
|
|
}
|
2010-03-22 11:11:44 -07:00
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
JS_LOCK_GC(cx->runtime);
|
|
|
|
if (kidp->isHash()) {
|
|
|
|
hash->KidsHash::~KidsHash();
|
|
|
|
js_free(hash);
|
|
|
|
} else {
|
|
|
|
// FIXME unsafe race with kidp->is/toChunk() above.
|
|
|
|
// But this is all going single-threaded soon...
|
|
|
|
while (chunk)
|
|
|
|
chunk = KidsChunk::destroy(cx, chunk);
|
|
|
|
kidp->setHash(hash);
|
2010-03-22 11:11:44 -07:00
|
|
|
}
|
2010-08-29 11:57:08 -07:00
|
|
|
goto locked_not_found;
|
2010-03-22 11:11:44 -07:00
|
|
|
}
|
|
|
|
}
|
2010-08-29 11:57:08 -07:00
|
|
|
goto not_found;
|
2010-03-22 11:11:44 -07:00
|
|
|
}
|
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
if (shape->matches(&child))
|
|
|
|
return shape;
|
|
|
|
}
|
|
|
|
n += MAX_KIDS_PER_CHUNK;
|
|
|
|
} while ((chunk = chunk->next) != NULL);
|
|
|
|
} else {
|
|
|
|
JS_LOCK_GC(cx->runtime);
|
|
|
|
shape = *kidp->toHash()->lookup(&child);
|
|
|
|
if (shape)
|
|
|
|
goto out;
|
|
|
|
goto locked_not_found;
|
|
|
|
}
|
2010-03-22 11:11:44 -07:00
|
|
|
}
|
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
not_found:
|
|
|
|
JS_LOCK_GC(cx->runtime);
|
|
|
|
|
2010-03-22 11:11:44 -07:00
|
|
|
locked_not_found:
|
2010-08-29 11:57:08 -07:00
|
|
|
shape = newShape(cx, true);
|
|
|
|
if (!shape)
|
2010-03-22 11:11:44 -07:00
|
|
|
return NULL;
|
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
new (shape) Shape(child.id, child.rawGetter, child.rawSetter, child.slot, child.attrs,
|
2010-09-02 14:50:44 -07:00
|
|
|
child.flags, child.shortid, js_GenerateShape(cx, true));
|
2010-03-22 11:11:44 -07:00
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
if (!insertChild(cx, parent, shape))
|
|
|
|
return NULL;
|
2010-03-22 11:11:44 -07:00
|
|
|
|
|
|
|
out:
|
|
|
|
JS_UNLOCK_GC(cx->runtime);
|
2010-08-29 11:57:08 -07:00
|
|
|
return shape;
|
2010-03-22 11:11:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2010-09-12 09:34:56 -07:00
|
|
|
|
|
|
|
void
|
|
|
|
KidsPointer::checkConsistency(const Shape *aKid) const
|
|
|
|
{
|
|
|
|
if (isShape()) {
|
|
|
|
JS_ASSERT(toShape() == aKid);
|
|
|
|
} else if (isChunk()) {
|
|
|
|
bool found = false;
|
|
|
|
for (KidsChunk *chunk = toChunk(); chunk; chunk = chunk->next) {
|
|
|
|
for (uintN i = 0; i < MAX_KIDS_PER_CHUNK; i++) {
|
|
|
|
if (!chunk->kids[i]) {
|
|
|
|
JS_ASSERT(!chunk->next);
|
|
|
|
for (uintN j = i + 1; j < MAX_KIDS_PER_CHUNK; j++)
|
|
|
|
JS_ASSERT(!chunk->kids[j]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (chunk->kids[i] == aKid) {
|
|
|
|
JS_ASSERT(!found);
|
|
|
|
found = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
JS_ASSERT(found);
|
|
|
|
} else {
|
|
|
|
JS_ASSERT(isHash());
|
|
|
|
KidsHash *hash = toHash();
|
|
|
|
KidsHash::Ptr ptr = hash->lookup(aKid);
|
|
|
|
JS_ASSERT(*ptr == aKid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-22 11:11:44 -07:00
|
|
|
void
|
2010-08-29 11:57:08 -07:00
|
|
|
Shape::dump(JSContext *cx, FILE *fp) const
|
2010-03-22 11:11:44 -07:00
|
|
|
{
|
2010-07-14 23:19:36 -07:00
|
|
|
JS_ASSERT(!JSID_IS_VOID(id));
|
2010-03-22 11:11:44 -07:00
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
if (JSID_IS_INT(id)) {
|
|
|
|
fprintf(fp, "[%ld]", (long) JSID_TO_INT(id));
|
2010-03-22 11:11:44 -07:00
|
|
|
} else {
|
|
|
|
JSString *str;
|
2010-07-14 23:19:36 -07:00
|
|
|
if (JSID_IS_ATOM(id)) {
|
|
|
|
str = JSID_TO_STRING(id);
|
2010-03-22 11:11:44 -07:00
|
|
|
} else {
|
2010-07-14 23:19:36 -07:00
|
|
|
JS_ASSERT(JSID_IS_OBJECT(id));
|
|
|
|
str = js_ValueToString(cx, IdToValue(id));
|
2010-03-22 11:11:44 -07:00
|
|
|
fputs("object ", fp);
|
|
|
|
}
|
|
|
|
if (!str)
|
|
|
|
fputs("<error>", fp);
|
|
|
|
else
|
|
|
|
js_FileEscapedString(fp, str, '"');
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(fp, " g/s %p/%p slot %u attrs %x ",
|
|
|
|
JS_FUNC_TO_DATA_PTR(void *, rawGetter),
|
|
|
|
JS_FUNC_TO_DATA_PTR(void *, rawSetter),
|
|
|
|
slot, attrs);
|
|
|
|
if (attrs) {
|
|
|
|
int first = 1;
|
|
|
|
fputs("(", fp);
|
|
|
|
#define DUMP_ATTR(name, display) if (attrs & JSPROP_##name) fputs(" " #display + first, fp), first = 0
|
|
|
|
DUMP_ATTR(ENUMERATE, enumerate);
|
|
|
|
DUMP_ATTR(READONLY, readonly);
|
|
|
|
DUMP_ATTR(PERMANENT, permanent);
|
|
|
|
DUMP_ATTR(GETTER, getter);
|
|
|
|
DUMP_ATTR(SETTER, setter);
|
|
|
|
DUMP_ATTR(SHARED, shared);
|
|
|
|
#undef DUMP_ATTR
|
|
|
|
fputs(") ", fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(fp, "flags %x ", flags);
|
|
|
|
if (flags) {
|
|
|
|
int first = 1;
|
|
|
|
fputs("(", fp);
|
|
|
|
#define DUMP_FLAG(name, display) if (flags & name) fputs(" " #display + first, fp), first = 0
|
|
|
|
DUMP_FLAG(ALIAS, alias);
|
|
|
|
DUMP_FLAG(HAS_SHORTID, has_shortid);
|
|
|
|
DUMP_FLAG(METHOD, method);
|
|
|
|
DUMP_FLAG(MARK, mark);
|
|
|
|
DUMP_FLAG(SHAPE_REGEN, shape_regen);
|
|
|
|
DUMP_FLAG(IN_DICTIONARY, in_dictionary);
|
|
|
|
#undef DUMP_FLAG
|
|
|
|
fputs(") ", fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(fp, "shortid %d\n", shortid);
|
|
|
|
}
|
2010-08-29 11:57:08 -07:00
|
|
|
|
|
|
|
static void
|
|
|
|
MeterKidCount(JSBasicStats *bs, uintN nkids)
|
|
|
|
{
|
|
|
|
JS_BASIC_STATS_ACCUM(bs, nkids);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
js::PropertyTree::meter(JSBasicStats *bs, Shape *node)
|
|
|
|
{
|
|
|
|
uintN nkids = 0;
|
|
|
|
const KidsPointer &kids = node->kids;
|
|
|
|
if (!kids.isNull()) {
|
|
|
|
if (kids.isShape()) {
|
|
|
|
meter(bs, kids.toShape());
|
|
|
|
nkids = 1;
|
|
|
|
} else if (kids.isChunk()) {
|
|
|
|
for (KidsChunk *chunk = kids.toChunk(); chunk; chunk = chunk->next) {
|
|
|
|
for (uintN i = 0; i < MAX_KIDS_PER_CHUNK; i++) {
|
|
|
|
Shape *kid = chunk->kids[i];
|
|
|
|
if (!kid)
|
|
|
|
break;
|
|
|
|
meter(bs, kid);
|
|
|
|
nkids++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
const KidsHash &hash = *kids.toHash();
|
|
|
|
for (KidsHash::Range range = hash.all(); !range.empty(); range.popFront()) {
|
|
|
|
Shape *kid = range.front();
|
|
|
|
|
|
|
|
meter(bs, kid);
|
|
|
|
nkids++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MeterKidCount(bs, nkids);
|
|
|
|
}
|
2010-03-22 11:11:44 -07:00
|
|
|
|
|
|
|
void
|
2010-08-29 11:57:08 -07:00
|
|
|
Shape::dumpSubtree(JSContext *cx, int level, FILE *fp) const
|
2010-03-22 11:11:44 -07:00
|
|
|
{
|
2010-08-29 11:57:08 -07:00
|
|
|
if (!parent) {
|
|
|
|
JS_ASSERT(level == 0);
|
|
|
|
JS_ASSERT(JSID_IS_EMPTY(id));
|
|
|
|
fprintf(fp, "class %s emptyShape %u\n", clasp->name, shape);
|
|
|
|
} else {
|
|
|
|
fprintf(fp, "%*sid ", level, "");
|
|
|
|
dump(cx, fp);
|
|
|
|
}
|
2010-03-22 11:11:44 -07:00
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
if (!kids.isNull()) {
|
2010-03-22 11:11:44 -07:00
|
|
|
++level;
|
2010-08-29 11:57:08 -07:00
|
|
|
if (kids.isShape()) {
|
|
|
|
Shape *kid = kids.toShape();
|
|
|
|
JS_ASSERT(kid->parent == this);
|
|
|
|
kid->dumpSubtree(cx, level, fp);
|
|
|
|
} else if (kids.isChunk()) {
|
|
|
|
KidsChunk *chunk = kids.toChunk();
|
2010-03-22 11:11:44 -07:00
|
|
|
do {
|
|
|
|
for (uintN i = 0; i < MAX_KIDS_PER_CHUNK; i++) {
|
2010-08-29 11:57:08 -07:00
|
|
|
Shape *kid = chunk->kids[i];
|
2010-03-22 11:11:44 -07:00
|
|
|
if (!kid)
|
|
|
|
break;
|
|
|
|
JS_ASSERT(kid->parent == this);
|
|
|
|
kid->dumpSubtree(cx, level, fp);
|
|
|
|
}
|
|
|
|
} while ((chunk = chunk->next) != NULL);
|
|
|
|
} else {
|
2010-08-29 11:57:08 -07:00
|
|
|
const KidsHash &hash = *kids.toHash();
|
|
|
|
for (KidsHash::Range range = hash.all(); !range.empty(); range.popFront()) {
|
|
|
|
Shape *kid = range.front();
|
|
|
|
|
|
|
|
JS_ASSERT(kid->parent == this);
|
|
|
|
kid->dumpSubtree(cx, level, fp);
|
|
|
|
}
|
2010-03-22 11:11:44 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* DEBUG */
|
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
JS_ALWAYS_INLINE void
|
|
|
|
js::PropertyTree::orphanKids(JSContext *cx, Shape *shape)
|
2010-03-22 11:11:44 -07:00
|
|
|
{
|
2010-08-29 11:57:08 -07:00
|
|
|
KidsPointer *kidp = &shape->kids;
|
2010-03-22 11:11:44 -07:00
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
JS_ASSERT(!kidp->isNull());
|
2010-03-22 11:11:44 -07:00
|
|
|
|
|
|
|
/*
|
2010-08-29 11:57:08 -07:00
|
|
|
* Note that JS_PROPERTY_TREE(cx).removeChild(cx, shape) precedes the call
|
|
|
|
* to orphanKids in sweepShapes, below. Therefore the grandparent must have
|
|
|
|
* either no kids left, or else space in chunks or a hash for more than one
|
|
|
|
* kid.
|
2010-03-22 11:11:44 -07:00
|
|
|
*/
|
2010-08-29 11:57:08 -07:00
|
|
|
JS_ASSERT_IF(shape->parent, !shape->parent->kids.isShape());
|
2010-03-22 11:11:44 -07:00
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
if (kidp->isShape()) {
|
|
|
|
Shape *kid = kidp->toShape();
|
|
|
|
|
|
|
|
if (!JSID_IS_VOID(kid->id)) {
|
|
|
|
JS_ASSERT(kid->parent == shape);
|
|
|
|
kid->parent = NULL;
|
|
|
|
}
|
|
|
|
} else if (kidp->isChunk()) {
|
|
|
|
KidsChunk *chunk = kidp->toChunk();
|
2010-03-22 11:11:44 -07:00
|
|
|
|
|
|
|
do {
|
|
|
|
for (uintN i = 0; i < MAX_KIDS_PER_CHUNK; i++) {
|
2010-08-29 11:57:08 -07:00
|
|
|
Shape *kid = chunk->kids[i];
|
2010-03-22 11:11:44 -07:00
|
|
|
if (!kid)
|
|
|
|
break;
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
if (!JSID_IS_VOID(kid->id)) {
|
2010-08-29 11:57:08 -07:00
|
|
|
JS_ASSERT(kid->parent == shape);
|
2010-03-22 11:11:44 -07:00
|
|
|
kid->parent = NULL;
|
|
|
|
}
|
|
|
|
}
|
2010-08-29 11:57:08 -07:00
|
|
|
} while ((chunk = KidsChunk::destroy(cx, chunk)) != NULL);
|
2010-03-22 11:11:44 -07:00
|
|
|
} else {
|
2010-08-29 11:57:08 -07:00
|
|
|
KidsHash *hash = kidp->toHash();
|
2010-03-22 11:11:44 -07:00
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
for (KidsHash::Range range = hash->all(); !range.empty(); range.popFront()) {
|
|
|
|
Shape *kid = range.front();
|
|
|
|
if (!JSID_IS_VOID(kid->id)) {
|
|
|
|
JS_ASSERT(kid->parent == shape);
|
|
|
|
kid->parent = NULL;
|
|
|
|
}
|
2010-03-22 11:11:44 -07:00
|
|
|
}
|
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
hash->KidsHash::~KidsHash();
|
|
|
|
js_free(hash);
|
2010-03-22 11:11:44 -07:00
|
|
|
}
|
2010-08-29 11:57:08 -07:00
|
|
|
|
|
|
|
kidp->setNull();
|
2010-03-22 11:11:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-08-29 11:57:08 -07:00
|
|
|
js::PropertyTree::sweepShapes(JSContext *cx)
|
2010-03-22 11:11:44 -07:00
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
JSBasicStats bs;
|
|
|
|
uint32 livePropCapacity = 0, totalLiveCount = 0;
|
|
|
|
static FILE *logfp;
|
|
|
|
if (!logfp) {
|
2010-08-29 11:57:08 -07:00
|
|
|
if (const char *filename = cx->runtime->propTreeStatFilename)
|
2010-03-22 11:11:44 -07:00
|
|
|
logfp = fopen(filename, "w");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (logfp) {
|
|
|
|
JS_BASIC_STATS_INIT(&bs);
|
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
uint32 empties;
|
|
|
|
{
|
|
|
|
typedef JSRuntime::EmptyShapeSet HS;
|
2010-03-22 11:11:44 -07:00
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
HS &h = cx->runtime->emptyShapes;
|
|
|
|
empties = h.count();
|
|
|
|
MeterKidCount(&bs, empties);
|
|
|
|
for (HS::Range r = h.all(); !r.empty(); r.popFront())
|
|
|
|
meter(&bs, r.front());
|
|
|
|
}
|
2010-03-22 11:11:44 -07:00
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
double props = cx->runtime->liveObjectPropsPreSweep;
|
|
|
|
double nodes = cx->runtime->livePropTreeNodes;
|
|
|
|
double dicts = cx->runtime->liveDictModeNodes;
|
2010-03-22 11:11:44 -07:00
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
/* Empty scope nodes are never hashed, so subtract them from nodes. */
|
|
|
|
JS_ASSERT(nodes - dicts == bs.sum);
|
|
|
|
nodes -= empties;
|
2010-03-22 11:11:44 -07:00
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
double sigma;
|
|
|
|
double mean = JS_MeanAndStdDevBS(&bs, &sigma);
|
2010-03-22 11:11:44 -07:00
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
fprintf(logfp,
|
|
|
|
"props %g nodes %g (dicts %g) beta %g meankids %g sigma %g max %u\n",
|
|
|
|
props, nodes, dicts, nodes / props, mean, sigma, bs.max);
|
2010-03-22 11:11:44 -07:00
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
JS_DumpHistogram(&bs, logfp);
|
2010-03-22 11:11:44 -07:00
|
|
|
}
|
2010-08-29 11:57:08 -07:00
|
|
|
#endif
|
2010-03-22 11:11:44 -07:00
|
|
|
|
|
|
|
/*
|
2010-08-29 11:57:08 -07:00
|
|
|
* Sweep the heap clean of all unmarked nodes. Here we will find nodes
|
|
|
|
* already GC'ed from the root ply, but we will avoid re-orphaning their
|
|
|
|
* kids, because the kids member will already be null.
|
2010-03-22 11:11:44 -07:00
|
|
|
*/
|
2010-07-11 00:09:34 -07:00
|
|
|
JSArena **ap = &JS_PROPERTY_TREE(cx).arenaPool.first.next;
|
|
|
|
while (JSArena *a = *ap) {
|
2010-08-29 11:57:08 -07:00
|
|
|
Shape *limit = (Shape *) a->avail;
|
2010-03-22 11:11:44 -07:00
|
|
|
uintN liveCount = 0;
|
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
for (Shape *shape = (Shape *) a->base; shape < limit; shape++) {
|
|
|
|
/* If the id is null, shape is already on the freelist. */
|
|
|
|
if (JSID_IS_VOID(shape->id))
|
2010-03-22 11:11:44 -07:00
|
|
|
continue;
|
|
|
|
|
|
|
|
/*
|
2010-08-29 11:57:08 -07:00
|
|
|
* If the mark bit is set, shape is alive, so clear the mark bit
|
2010-03-22 11:11:44 -07:00
|
|
|
* and continue the while loop.
|
|
|
|
*
|
2010-08-29 11:57:08 -07:00
|
|
|
* Regenerate shape->shape if it hasn't already been refreshed
|
2010-03-22 11:11:44 -07:00
|
|
|
* during the mark phase, when live scopes' lastProp members are
|
|
|
|
* followed to update both scope->shape and lastProp->shape.
|
|
|
|
*/
|
2010-08-29 11:57:08 -07:00
|
|
|
if (shape->marked()) {
|
|
|
|
shape->clearMark();
|
2010-03-22 11:11:44 -07:00
|
|
|
if (cx->runtime->gcRegenShapes) {
|
2010-08-29 11:57:08 -07:00
|
|
|
if (shape->hasRegenFlag())
|
|
|
|
shape->clearRegenFlag();
|
2010-03-22 11:11:44 -07:00
|
|
|
else
|
2010-08-29 11:57:08 -07:00
|
|
|
shape->shape = js_RegenerateShapeForGC(cx);
|
2010-03-22 11:11:44 -07:00
|
|
|
}
|
|
|
|
liveCount++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
if ((shape->flags & Shape::SHARED_EMPTY) &&
|
|
|
|
cx->runtime->meterEmptyShapes()) {
|
|
|
|
cx->runtime->emptyShapes.remove((EmptyShape *) shape);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (shape->inDictionary()) {
|
|
|
|
JS_RUNTIME_UNMETER(cx->runtime, liveDictModeNodes);
|
|
|
|
} else {
|
2010-03-22 11:11:44 -07:00
|
|
|
/*
|
2010-08-29 11:57:08 -07:00
|
|
|
* Here, shape is garbage to collect, but its parent might not
|
|
|
|
* be, so we may have to remove it from its parent's kids hash,
|
|
|
|
* chunk list, or kid singleton pointer set.
|
2010-03-22 11:11:44 -07:00
|
|
|
*
|
|
|
|
* Without a separate mark-clearing pass, we can't tell whether
|
2010-08-29 11:57:08 -07:00
|
|
|
* shape->parent is live at this point, so we must remove shape
|
|
|
|
* if its parent member is non-null. A saving grace: if shape's
|
|
|
|
* parent is dead and swept by this point, shape->parent will
|
2010-03-22 11:11:44 -07:00
|
|
|
* be null -- in the next paragraph, we null all of a property
|
|
|
|
* tree node's kids' parent links when sweeping that node.
|
|
|
|
*/
|
2010-08-29 11:57:08 -07:00
|
|
|
if (shape->parent)
|
|
|
|
JS_PROPERTY_TREE(cx).removeChild(cx, shape);
|
2010-03-22 11:11:44 -07:00
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
if (!shape->kids.isNull())
|
|
|
|
orphanKids(cx, shape);
|
2010-03-22 11:11:44 -07:00
|
|
|
}
|
|
|
|
|
2010-03-22 16:26:28 -07:00
|
|
|
/*
|
2010-08-29 11:57:08 -07:00
|
|
|
* Note that Shape::insertFree nulls shape->id so we know that
|
|
|
|
* shape is on the freelist.
|
2010-03-22 16:26:28 -07:00
|
|
|
*/
|
2010-08-29 11:57:08 -07:00
|
|
|
shape->freeTable(cx);
|
|
|
|
shape->insertFree(&JS_PROPERTY_TREE(cx).freeList);
|
2010-03-22 11:11:44 -07:00
|
|
|
JS_RUNTIME_UNMETER(cx->runtime, livePropTreeNodes);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If a contains no live properties, return it to the malloc heap. */
|
|
|
|
if (liveCount == 0) {
|
2010-08-29 11:57:08 -07:00
|
|
|
for (Shape *shape = (Shape *) a->base; shape < limit; shape++)
|
|
|
|
shape->removeFree();
|
2010-07-11 00:09:34 -07:00
|
|
|
JS_ARENA_DESTROY(&JS_PROPERTY_TREE(cx).arenaPool, a, ap);
|
2010-03-22 11:11:44 -07:00
|
|
|
} else {
|
|
|
|
#ifdef DEBUG
|
2010-08-29 11:57:08 -07:00
|
|
|
livePropCapacity += limit - (Shape *) a->base;
|
2010-03-22 11:11:44 -07:00
|
|
|
totalLiveCount += liveCount;
|
|
|
|
#endif
|
2010-07-11 00:09:34 -07:00
|
|
|
ap = &a->next;
|
2010-03-22 11:11:44 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (logfp) {
|
|
|
|
fprintf(logfp,
|
|
|
|
"\nProperty tree stats for gcNumber %lu\n",
|
|
|
|
(unsigned long) cx->runtime->gcNumber);
|
|
|
|
|
|
|
|
fprintf(logfp, "arenautil %g%%\n",
|
|
|
|
(totalLiveCount && livePropCapacity)
|
|
|
|
? (totalLiveCount * 100.0) / livePropCapacity
|
|
|
|
: 0.0);
|
|
|
|
|
|
|
|
#define RATE(f1, f2) (((double)js_scope_stats.f1 / js_scope_stats.f2) * 100.0)
|
|
|
|
|
|
|
|
fprintf(logfp,
|
|
|
|
"Scope search stats:\n"
|
2010-08-29 11:57:08 -07:00
|
|
|
" searches: %6u\n"
|
|
|
|
" hits: %6u %5.2f%% of searches\n"
|
|
|
|
" misses: %6u %5.2f%%\n"
|
|
|
|
" hashes: %6u %5.2f%%\n"
|
|
|
|
" hashHits: %6u %5.2f%% (%5.2f%% of hashes)\n"
|
|
|
|
" hashMisses: %6u %5.2f%% (%5.2f%%)\n"
|
|
|
|
" steps: %6u %5.2f%% (%5.2f%%)\n"
|
|
|
|
" stepHits: %6u %5.2f%% (%5.2f%%)\n"
|
|
|
|
" stepMisses: %6u %5.2f%% (%5.2f%%)\n"
|
|
|
|
" initSearches: %6u\n"
|
|
|
|
" changeSearches: %6u\n"
|
|
|
|
" tableAllocFails: %6u\n"
|
|
|
|
" toDictFails: %6u\n"
|
|
|
|
" wrapWatchFails: %6u\n"
|
|
|
|
" adds: %6u\n"
|
|
|
|
" addFails: %6u\n"
|
|
|
|
" puts: %6u\n"
|
|
|
|
" redundantPuts: %6u\n"
|
|
|
|
" putFails: %6u\n"
|
|
|
|
" changes: %6u\n"
|
|
|
|
" changeFails: %6u\n"
|
|
|
|
" compresses: %6u\n"
|
|
|
|
" grows: %6u\n"
|
|
|
|
" removes: %6u\n"
|
|
|
|
" removeFrees: %6u\n"
|
|
|
|
" uselessRemoves: %6u\n"
|
|
|
|
" shrinks: %6u\n",
|
2010-03-22 11:11:44 -07:00
|
|
|
js_scope_stats.searches,
|
|
|
|
js_scope_stats.hits, RATE(hits, searches),
|
|
|
|
js_scope_stats.misses, RATE(misses, searches),
|
|
|
|
js_scope_stats.hashes, RATE(hashes, searches),
|
2010-08-29 11:57:08 -07:00
|
|
|
js_scope_stats.hashHits, RATE(hashHits, searches), RATE(hashHits, hashes),
|
|
|
|
js_scope_stats.hashMisses, RATE(hashMisses, searches), RATE(hashMisses, hashes),
|
2010-03-22 11:11:44 -07:00
|
|
|
js_scope_stats.steps, RATE(steps, searches), RATE(steps, hashes),
|
2010-08-29 11:57:08 -07:00
|
|
|
js_scope_stats.stepHits, RATE(stepHits, searches), RATE(stepHits, hashes),
|
|
|
|
js_scope_stats.stepMisses, RATE(stepMisses, searches), RATE(stepMisses, hashes),
|
|
|
|
js_scope_stats.initSearches,
|
|
|
|
js_scope_stats.changeSearches,
|
2010-03-22 11:11:44 -07:00
|
|
|
js_scope_stats.tableAllocFails,
|
|
|
|
js_scope_stats.toDictFails,
|
|
|
|
js_scope_stats.wrapWatchFails,
|
|
|
|
js_scope_stats.adds,
|
|
|
|
js_scope_stats.addFails,
|
|
|
|
js_scope_stats.puts,
|
|
|
|
js_scope_stats.redundantPuts,
|
|
|
|
js_scope_stats.putFails,
|
|
|
|
js_scope_stats.changes,
|
|
|
|
js_scope_stats.changeFails,
|
|
|
|
js_scope_stats.compresses,
|
|
|
|
js_scope_stats.grows,
|
|
|
|
js_scope_stats.removes,
|
|
|
|
js_scope_stats.removeFrees,
|
|
|
|
js_scope_stats.uselessRemoves,
|
|
|
|
js_scope_stats.shrinks);
|
|
|
|
|
|
|
|
#undef RATE
|
|
|
|
|
|
|
|
fflush(logfp);
|
|
|
|
}
|
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
if (const char *filename = cx->runtime->propTreeDumpFilename) {
|
2010-03-22 11:11:44 -07:00
|
|
|
char pathname[1024];
|
|
|
|
JS_snprintf(pathname, sizeof pathname, "%s.%lu",
|
|
|
|
filename, (unsigned long)cx->runtime->gcNumber);
|
|
|
|
FILE *dumpfp = fopen(pathname, "w");
|
|
|
|
if (dumpfp) {
|
2010-08-29 11:57:08 -07:00
|
|
|
typedef JSRuntime::EmptyShapeSet HS;
|
2010-03-22 11:11:44 -07:00
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
HS &h = cx->runtime->emptyShapes;
|
|
|
|
for (HS::Range r = h.all(); !r.empty(); r.popFront()) {
|
|
|
|
Shape *empty = r.front();
|
|
|
|
empty->dumpSubtree(cx, 0, dumpfp);
|
|
|
|
putc('\n', dumpfp);
|
2010-03-22 11:11:44 -07:00
|
|
|
}
|
2010-08-29 11:57:08 -07:00
|
|
|
|
2010-03-22 11:11:44 -07:00
|
|
|
fclose(dumpfp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* DEBUG */
|
|
|
|
}
|