2010-03-24 19:20:44 -07:00
|
|
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
* vim: set ts=8 sw=4 et tw=98:
|
|
|
|
*
|
|
|
|
* ***** BEGIN LICENSE BLOCK *****
|
2010-03-24 14:16:01 -07:00
|
|
|
* 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 Mozilla Communicator client code, released
|
|
|
|
* March 31, 1998.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either 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 ***** */
|
|
|
|
|
|
|
|
#include "jspropertycache.h"
|
|
|
|
#include "jspropertycacheinlines.h"
|
|
|
|
#include "jscntxt.h"
|
|
|
|
|
|
|
|
using namespace js;
|
|
|
|
|
2010-03-26 07:01:01 -07:00
|
|
|
JS_STATIC_ASSERT(sizeof(PCVal) == sizeof(jsuword));
|
|
|
|
|
2010-03-24 19:20:44 -07:00
|
|
|
JS_REQUIRES_STACK PropertyCacheEntry *
|
|
|
|
PropertyCache::fill(JSContext *cx, JSObject *obj, uintN scopeIndex, uintN protoIndex,
|
|
|
|
JSObject *pobj, JSScopeProperty *sprop, JSBool adding)
|
2010-03-24 14:16:01 -07:00
|
|
|
{
|
|
|
|
jsbytecode *pc;
|
|
|
|
JSScope *scope;
|
|
|
|
jsuword kshape, vshape;
|
|
|
|
JSOp op;
|
|
|
|
const JSCodeSpec *cs;
|
2010-03-26 07:01:01 -07:00
|
|
|
PCVal vword;
|
2010-03-24 19:20:44 -07:00
|
|
|
PropertyCacheEntry *entry;
|
2010-03-24 14:16:01 -07:00
|
|
|
|
2010-03-24 19:20:44 -07:00
|
|
|
JS_ASSERT(this == &JS_PROPERTY_CACHE(cx));
|
2010-03-24 14:16:01 -07:00
|
|
|
JS_ASSERT(!cx->runtime->gcRunning);
|
|
|
|
|
|
|
|
/* FIXME bug 489098: consider enabling the property cache for eval. */
|
2010-08-22 16:00:20 -07:00
|
|
|
if (js_IsPropertyCacheDisabled(cx) || (cx->fp()->flags & JSFRAME_EVAL)) {
|
2010-03-24 19:20:44 -07:00
|
|
|
PCMETER(disfills++);
|
2010-03-24 14:16:01 -07:00
|
|
|
return JS_NO_PROP_CACHE_FILL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check for fill from js_SetPropertyHelper where the setter removed sprop
|
|
|
|
* from pobj's scope (via unwatch or delete, e.g.).
|
|
|
|
*/
|
2010-04-08 11:22:04 -07:00
|
|
|
scope = pobj->scope();
|
2010-03-24 14:16:01 -07:00
|
|
|
if (!scope->hasProperty(sprop)) {
|
2010-03-24 19:20:44 -07:00
|
|
|
PCMETER(oddfills++);
|
2010-03-24 14:16:01 -07:00
|
|
|
return JS_NO_PROP_CACHE_FILL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check for overdeep scope and prototype chain. Because resolve, getter,
|
|
|
|
* and setter hooks can change the prototype chain using JS_SetPrototype
|
|
|
|
* after js_LookupPropertyWithFlags has returned the nominal protoIndex,
|
|
|
|
* we have to validate protoIndex if it is non-zero. If it is zero, then
|
|
|
|
* we know thanks to the scope->hasProperty test above, combined with the
|
|
|
|
* fact that obj == pobj, that protoIndex is invariant.
|
|
|
|
*
|
|
|
|
* The scopeIndex can't be wrong. We require JS_SetParent calls to happen
|
|
|
|
* before any running script might consult a parent-linked scope chain. If
|
|
|
|
* this requirement is not satisfied, the fill in progress will never hit,
|
|
|
|
* but vcap vs. scope shape tests ensure nothing malfunctions.
|
|
|
|
*/
|
|
|
|
JS_ASSERT_IF(scopeIndex == 0 && protoIndex == 0, obj == pobj);
|
|
|
|
|
|
|
|
if (protoIndex != 0) {
|
|
|
|
JSObject *tmp = obj;
|
|
|
|
|
|
|
|
for (uintN i = 0; i != scopeIndex; i++)
|
|
|
|
tmp = tmp->getParent();
|
|
|
|
JS_ASSERT(tmp != pobj);
|
|
|
|
|
|
|
|
protoIndex = 1;
|
|
|
|
for (;;) {
|
2010-08-07 20:11:42 -07:00
|
|
|
tmp = tmp->getProto();
|
|
|
|
|
2010-03-24 14:16:01 -07:00
|
|
|
/*
|
|
|
|
* We cannot cache properties coming from native objects behind
|
2010-08-07 20:11:42 -07:00
|
|
|
* non-native ones on the prototype chain. The non-natives can
|
|
|
|
* mutate in arbitrary way without changing any shapes.
|
2010-03-24 14:16:01 -07:00
|
|
|
*/
|
2010-03-31 22:13:51 -07:00
|
|
|
if (!tmp || !tmp->isNative()) {
|
2010-03-24 19:20:44 -07:00
|
|
|
PCMETER(noprotos++);
|
2010-03-24 14:16:01 -07:00
|
|
|
return JS_NO_PROP_CACHE_FILL;
|
|
|
|
}
|
|
|
|
if (tmp == pobj)
|
|
|
|
break;
|
|
|
|
++protoIndex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (scopeIndex > PCVCAP_SCOPEMASK || protoIndex > PCVCAP_PROTOMASK) {
|
2010-03-24 19:20:44 -07:00
|
|
|
PCMETER(longchains++);
|
2010-03-24 14:16:01 -07:00
|
|
|
return JS_NO_PROP_CACHE_FILL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Optimize the cached vword based on our parameters and the current pc's
|
|
|
|
* opcode format flags.
|
|
|
|
*/
|
2010-03-03 18:10:13 -08:00
|
|
|
pc = cx->regs->pc;
|
2010-08-22 16:00:20 -07:00
|
|
|
op = js_GetOpcode(cx, cx->fp()->getScript(), pc);
|
2010-03-24 14:16:01 -07:00
|
|
|
cs = &js_CodeSpec[op];
|
|
|
|
kshape = 0;
|
|
|
|
|
|
|
|
do {
|
|
|
|
/*
|
|
|
|
* Check for a prototype "plain old method" callee computation. What
|
|
|
|
* is a plain old method? It's a function-valued property with stub
|
|
|
|
* getter, so get of a function is idempotent.
|
|
|
|
*/
|
|
|
|
if (cs->format & JOF_CALLOP) {
|
|
|
|
if (sprop->isMethod()) {
|
|
|
|
/*
|
|
|
|
* A compiler-created function object, AKA a method, already
|
|
|
|
* memoized in the property tree.
|
|
|
|
*/
|
|
|
|
JS_ASSERT(scope->hasMethodBarrier());
|
2010-07-14 23:19:36 -07:00
|
|
|
JSObject &funobj = sprop->methodObject();
|
|
|
|
JS_ASSERT(&funobj == &pobj->lockedGetSlot(sprop->slot).toObject());
|
|
|
|
vword.setFunObj(funobj);
|
2010-03-24 14:16:01 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!scope->generic() &&
|
|
|
|
sprop->hasDefaultGetter() &&
|
|
|
|
SPROP_HAS_VALID_SLOT(sprop, scope)) {
|
2010-07-14 23:19:36 -07:00
|
|
|
const Value &v = pobj->lockedGetSlot(sprop->slot);
|
|
|
|
JSObject *funobj;
|
|
|
|
if (IsFunctionObject(v, &funobj)) {
|
2010-03-24 14:16:01 -07:00
|
|
|
/*
|
|
|
|
* Great, we have a function-valued prototype property
|
|
|
|
* where the getter is JS_PropertyStub. The type id in
|
|
|
|
* pobj's scope does not evolve with changes to property
|
|
|
|
* values, however.
|
|
|
|
*
|
|
|
|
* So here, on first cache fill for this method, we brand
|
|
|
|
* the scope with a new shape and set the JSScope::BRANDED
|
|
|
|
* flag. Once this flag is set, any property assignment
|
|
|
|
* that changes the value from or to a different function
|
|
|
|
* object will result in shape being regenerated.
|
|
|
|
*/
|
|
|
|
if (!scope->branded()) {
|
2010-03-24 19:20:44 -07:00
|
|
|
PCMETER(brandfills++);
|
2010-03-24 14:16:01 -07:00
|
|
|
#ifdef DEBUG_notme
|
|
|
|
fprintf(stderr,
|
|
|
|
"branding %p (%s) for funobj %p (%s), shape %lu\n",
|
|
|
|
pobj, pobj->getClass()->name,
|
|
|
|
JSVAL_TO_OBJECT(v),
|
|
|
|
JS_GetFunctionName(GET_FUNCTION_PRIVATE(cx, JSVAL_TO_OBJECT(v))),
|
2010-04-08 11:22:04 -07:00
|
|
|
obj->shape());
|
2010-03-24 14:16:01 -07:00
|
|
|
#endif
|
|
|
|
if (!scope->brand(cx, sprop->slot, v))
|
|
|
|
return JS_NO_PROP_CACHE_FILL;
|
|
|
|
}
|
2010-07-14 23:19:36 -07:00
|
|
|
vword.setFunObj(*funobj);
|
2010-03-24 14:16:01 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-06 12:46:20 -07:00
|
|
|
/*
|
|
|
|
* If getting a value via a stub getter, or doing an INCDEC op
|
|
|
|
* with stub getters and setters, we can cache the slot.
|
|
|
|
*/
|
|
|
|
if (!(cs->format & (JOF_SET | JOF_FOR)) &&
|
|
|
|
(!(cs->format & JOF_INCDEC) || sprop->hasDefaultSetter()) &&
|
2010-03-24 14:16:01 -07:00
|
|
|
sprop->hasDefaultGetter() &&
|
|
|
|
SPROP_HAS_VALID_SLOT(sprop, scope)) {
|
|
|
|
/* Great, let's cache sprop's slot and use it on cache hit. */
|
2010-03-26 07:01:01 -07:00
|
|
|
vword.setSlot(sprop->slot);
|
2010-03-24 14:16:01 -07:00
|
|
|
} else {
|
|
|
|
/* Best we can do is to cache sprop (still a nice speedup). */
|
2010-03-26 07:01:01 -07:00
|
|
|
vword.setSprop(sprop);
|
2010-03-24 14:16:01 -07:00
|
|
|
if (adding &&
|
|
|
|
sprop == scope->lastProperty() &&
|
|
|
|
scope->shape == sprop->shape) {
|
|
|
|
/*
|
|
|
|
* Our caller added a new property. We also know that a setter
|
|
|
|
* that js_NativeSet could have run has not mutated the scope,
|
|
|
|
* so the added property is still the last one added, and the
|
|
|
|
* scope is not branded.
|
|
|
|
*
|
|
|
|
* We want to cache under scope's shape before the property
|
|
|
|
* addition to bias for the case when the mutator opcode
|
|
|
|
* always adds the same property. This allows us to optimize
|
|
|
|
* periodic execution of object initializers or other explicit
|
|
|
|
* initialization sequences such as
|
|
|
|
*
|
|
|
|
* obj = {}; obj.x = 1; obj.y = 2;
|
|
|
|
*
|
|
|
|
* We assume that on average the win from this optimization is
|
|
|
|
* greater than the cost of an extra mismatch per loop owing to
|
|
|
|
* the bias for the following case:
|
|
|
|
*
|
|
|
|
* obj = {}; ... for (...) { ... obj.x = ... }
|
|
|
|
*
|
|
|
|
* On the first iteration of such a for loop, JSOP_SETPROP
|
|
|
|
* fills the cache with the shape of the newly created object
|
|
|
|
* obj, not the shape of obj after obj.x has been assigned.
|
|
|
|
* That mismatches obj's shape on the second iteration. Note
|
|
|
|
* that on the third and subsequent iterations the cache will
|
|
|
|
* be hit because the shape is no longer updated.
|
|
|
|
*/
|
|
|
|
JS_ASSERT(!scope->isSharedEmpty());
|
|
|
|
if (sprop->parent) {
|
|
|
|
kshape = sprop->parent->shape;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* If obj had its own empty scope before, with a unique
|
|
|
|
* shape, that is lost. Here we only attempt to find a
|
|
|
|
* matching empty scope. In unusual cases involving
|
|
|
|
* __proto__ assignment we may not find one.
|
|
|
|
*/
|
|
|
|
JSObject *proto = obj->getProto();
|
2010-03-31 22:13:51 -07:00
|
|
|
if (!proto || !proto->isNative())
|
2010-03-24 14:16:01 -07:00
|
|
|
return JS_NO_PROP_CACHE_FILL;
|
2010-04-08 11:22:04 -07:00
|
|
|
JSScope *protoscope = proto->scope();
|
2010-03-24 14:16:01 -07:00
|
|
|
if (!protoscope->emptyScope ||
|
|
|
|
protoscope->emptyScope->clasp != obj->getClass()) {
|
|
|
|
return JS_NO_PROP_CACHE_FILL;
|
|
|
|
}
|
|
|
|
kshape = protoscope->emptyScope->shape;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* When adding we predict no prototype object will later gain a
|
|
|
|
* readonly property or setter.
|
|
|
|
*/
|
|
|
|
vshape = cx->runtime->protoHazardShape;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (0);
|
|
|
|
|
|
|
|
if (kshape == 0) {
|
2010-04-08 11:22:04 -07:00
|
|
|
kshape = obj->shape();
|
2010-03-24 14:16:01 -07:00
|
|
|
vshape = scope->shape;
|
|
|
|
}
|
|
|
|
JS_ASSERT(kshape < SHAPE_OVERFLOW_BIT);
|
|
|
|
|
|
|
|
if (obj == pobj) {
|
|
|
|
JS_ASSERT(scopeIndex == 0 && protoIndex == 0);
|
|
|
|
} else {
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (scopeIndex == 0) {
|
|
|
|
JS_ASSERT(protoIndex != 0);
|
|
|
|
JS_ASSERT((protoIndex == 1) == (obj->getProto() == pobj));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (scopeIndex != 0 || protoIndex != 1) {
|
|
|
|
/*
|
|
|
|
* Make sure that a later shadowing assignment will enter
|
|
|
|
* PurgeProtoChain and invalidate this entry, bug 479198.
|
|
|
|
*
|
|
|
|
* This is thread-safe even though obj is not locked. Only the
|
|
|
|
* DELEGATE bit of obj->classword can change at runtime, given that
|
|
|
|
* obj is native; and the bit is only set, never cleared. And on
|
|
|
|
* platforms where another CPU can fail to see this write, it's OK
|
|
|
|
* because the property cache and JIT cache are thread-local.
|
|
|
|
*/
|
|
|
|
obj->setDelegate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
JS_ASSERT(vshape < SHAPE_OVERFLOW_BIT);
|
|
|
|
|
2010-03-24 19:20:44 -07:00
|
|
|
entry = &table[hash(pc, kshape)];
|
2010-03-26 07:01:01 -07:00
|
|
|
PCMETER(entry->vword.isNull() || recycles++);
|
2010-03-24 19:20:44 -07:00
|
|
|
entry->assign(pc, kshape, vshape, scopeIndex, protoIndex, vword);
|
2010-03-24 14:16:01 -07:00
|
|
|
|
2010-03-24 19:20:44 -07:00
|
|
|
empty = false;
|
|
|
|
PCMETER(fills++);
|
2010-03-24 14:16:01 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The modfills counter is not exact. It increases if a getter or setter
|
|
|
|
* recurse into the interpreter.
|
|
|
|
*/
|
2010-03-24 19:20:44 -07:00
|
|
|
PCMETER(entry == pctestentry || modfills++);
|
|
|
|
PCMETER(pctestentry = NULL);
|
2010-03-24 14:16:01 -07:00
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline JSAtom *
|
|
|
|
GetAtomFromBytecode(JSContext *cx, jsbytecode *pc, JSOp op, const JSCodeSpec &cs)
|
|
|
|
{
|
|
|
|
if (op == JSOP_LENGTH)
|
|
|
|
return cx->runtime->atomState.lengthAtom;
|
|
|
|
|
|
|
|
ptrdiff_t pcoff = (JOF_TYPE(cs.format) == JOF_SLOTATOM) ? SLOTNO_LEN : 0;
|
|
|
|
JSAtom *atom;
|
2010-08-22 16:00:20 -07:00
|
|
|
GET_ATOM_FROM_BYTECODE(cx->fp()->getScript(), pc, pcoff, atom);
|
2010-03-24 14:16:01 -07:00
|
|
|
return atom;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_REQUIRES_STACK JSAtom *
|
2010-03-24 19:20:44 -07:00
|
|
|
PropertyCache::fullTest(JSContext *cx, jsbytecode *pc, JSObject **objp, JSObject **pobjp,
|
|
|
|
PropertyCacheEntry *entry)
|
2010-03-24 14:16:01 -07:00
|
|
|
{
|
|
|
|
JSObject *obj, *pobj, *tmp;
|
|
|
|
uint32 vcap;
|
|
|
|
|
2010-08-22 16:00:20 -07:00
|
|
|
JSStackFrame *fp = cx->fp();
|
|
|
|
|
2010-03-24 19:20:44 -07:00
|
|
|
JS_ASSERT(this == &JS_PROPERTY_CACHE(cx));
|
2010-08-22 16:00:20 -07:00
|
|
|
JS_ASSERT(uintN((fp->hasIMacroPC() ? fp->getIMacroPC() : pc) - fp->getScript()->code)
|
|
|
|
< fp->getScript()->length);
|
2010-03-24 14:16:01 -07:00
|
|
|
|
2010-08-22 16:00:20 -07:00
|
|
|
JSOp op = js_GetOpcode(cx, fp->getScript(), pc);
|
2010-03-24 14:16:01 -07:00
|
|
|
const JSCodeSpec &cs = js_CodeSpec[op];
|
|
|
|
|
|
|
|
obj = *objp;
|
|
|
|
vcap = entry->vcap;
|
|
|
|
|
|
|
|
if (entry->kpc != pc) {
|
2010-03-24 19:20:44 -07:00
|
|
|
PCMETER(kpcmisses++);
|
2010-03-24 14:16:01 -07:00
|
|
|
|
|
|
|
JSAtom *atom = GetAtomFromBytecode(cx, pc, op, cs);
|
|
|
|
#ifdef DEBUG_notme
|
2010-08-23 14:36:40 -07:00
|
|
|
JSScript *script = cx->fp()->getScript();
|
2010-03-24 14:16:01 -07:00
|
|
|
fprintf(stderr,
|
|
|
|
"id miss for %s from %s:%u"
|
|
|
|
" (pc %u, kpc %u, kshape %u, shape %u)\n",
|
|
|
|
js_AtomToPrintableString(cx, atom),
|
2010-08-23 14:36:40 -07:00
|
|
|
script->filename,
|
|
|
|
js_PCToLineNumber(cx, script, pc),
|
|
|
|
pc - script->code,
|
|
|
|
entry->kpc - script->code,
|
2010-03-24 14:16:01 -07:00
|
|
|
entry->kshape,
|
2010-04-08 11:22:04 -07:00
|
|
|
obj->shape());
|
2010-08-23 14:36:40 -07:00
|
|
|
js_Disassemble1(cx, script, pc,
|
|
|
|
pc - script->code,
|
2010-03-24 14:16:01 -07:00
|
|
|
JS_FALSE, stderr);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return atom;
|
|
|
|
}
|
|
|
|
|
2010-03-29 08:35:16 -07:00
|
|
|
if (entry->kshape != obj->map->shape) {
|
2010-03-24 19:20:44 -07:00
|
|
|
PCMETER(kshapemisses++);
|
2010-03-24 14:16:01 -07:00
|
|
|
return GetAtomFromBytecode(cx, pc, op, cs);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2010-03-24 19:20:44 -07:00
|
|
|
* PropertyCache::test handles only the direct and immediate-prototype hit
|
|
|
|
* cases. All others go here. We could embed the target object in the cache
|
2010-03-24 14:16:01 -07:00
|
|
|
* entry but then entry size would be 5 words. Instead we traverse chains.
|
|
|
|
*/
|
|
|
|
pobj = obj;
|
|
|
|
|
|
|
|
if (JOF_MODE(cs.format) == JOF_NAME) {
|
|
|
|
while (vcap & (PCVCAP_SCOPEMASK << PCVCAP_PROTOBITS)) {
|
|
|
|
tmp = pobj->getParent();
|
2010-03-31 22:13:51 -07:00
|
|
|
if (!tmp || !tmp->isNative())
|
2010-03-24 14:16:01 -07:00
|
|
|
break;
|
|
|
|
pobj = tmp;
|
|
|
|
vcap -= PCVCAP_PROTOSIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*objp = pobj;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (vcap & PCVCAP_PROTOMASK) {
|
|
|
|
tmp = pobj->getProto();
|
2010-03-31 22:13:51 -07:00
|
|
|
if (!tmp || !tmp->isNative())
|
2010-03-24 14:16:01 -07:00
|
|
|
break;
|
|
|
|
pobj = tmp;
|
|
|
|
--vcap;
|
|
|
|
}
|
|
|
|
|
2010-03-24 19:20:44 -07:00
|
|
|
if (matchShape(cx, pobj, vcap >> PCVCAP_TAGBITS)) {
|
2010-03-24 14:16:01 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
JSAtom *atom = GetAtomFromBytecode(cx, pc, op, cs);
|
|
|
|
jsid id = ATOM_TO_JSID(atom);
|
|
|
|
|
|
|
|
id = js_CheckForStringIndex(id);
|
2010-04-08 11:22:04 -07:00
|
|
|
JS_ASSERT(pobj->scope()->lookup(id));
|
|
|
|
JS_ASSERT_IF(pobj->scope()->object, pobj->scope()->object == pobj);
|
2010-03-24 14:16:01 -07:00
|
|
|
#endif
|
|
|
|
*pobjp = pobj;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-03-24 19:20:44 -07:00
|
|
|
PCMETER(vcapmisses++);
|
2010-03-24 14:16:01 -07:00
|
|
|
return GetAtomFromBytecode(cx, pc, op, cs);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2010-03-24 19:20:44 -07:00
|
|
|
void
|
|
|
|
PropertyCache::assertEmpty()
|
|
|
|
{
|
|
|
|
JS_ASSERT(empty);
|
|
|
|
for (uintN i = 0; i < SIZE; i++) {
|
|
|
|
JS_ASSERT(!table[i].kpc);
|
|
|
|
JS_ASSERT(!table[i].kshape);
|
|
|
|
JS_ASSERT(!table[i].vcap);
|
2010-03-26 07:01:01 -07:00
|
|
|
JS_ASSERT(table[i].vword.isNull());
|
2010-03-24 19:20:44 -07:00
|
|
|
}
|
|
|
|
}
|
2010-03-24 14:16:01 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
void
|
2010-03-24 19:20:44 -07:00
|
|
|
PropertyCache::purge(JSContext *cx)
|
2010-03-24 14:16:01 -07:00
|
|
|
{
|
2010-03-24 19:20:44 -07:00
|
|
|
if (empty) {
|
|
|
|
assertEmpty();
|
2010-03-24 14:16:01 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-03-24 19:20:44 -07:00
|
|
|
PodArrayZero(table);
|
2010-03-26 07:01:01 -07:00
|
|
|
JS_ASSERT(table[0].vword.isNull());
|
2010-03-24 19:20:44 -07:00
|
|
|
empty = true;
|
2010-03-24 14:16:01 -07:00
|
|
|
|
|
|
|
#ifdef JS_PROPERTY_CACHE_METERING
|
|
|
|
{ static FILE *fp;
|
|
|
|
if (!fp)
|
|
|
|
fp = fopen("/tmp/propcache.stats", "w");
|
|
|
|
if (fp) {
|
|
|
|
fputs("Property cache stats for ", fp);
|
|
|
|
#ifdef JS_THREADSAFE
|
|
|
|
fprintf(fp, "thread %lu, ", (unsigned long) cx->thread->id);
|
|
|
|
#endif
|
|
|
|
fprintf(fp, "GC %u\n", cx->runtime->gcNumber);
|
|
|
|
|
2010-03-24 19:20:44 -07:00
|
|
|
# define P(mem) fprintf(fp, "%11s %10lu\n", #mem, (unsigned long)mem)
|
2010-03-24 14:16:01 -07:00
|
|
|
P(fills);
|
|
|
|
P(nofills);
|
|
|
|
P(rofills);
|
|
|
|
P(disfills);
|
|
|
|
P(oddfills);
|
|
|
|
P(modfills);
|
|
|
|
P(brandfills);
|
|
|
|
P(noprotos);
|
|
|
|
P(longchains);
|
|
|
|
P(recycles);
|
|
|
|
P(tests);
|
|
|
|
P(pchits);
|
|
|
|
P(protopchits);
|
|
|
|
P(initests);
|
|
|
|
P(inipchits);
|
|
|
|
P(inipcmisses);
|
|
|
|
P(settests);
|
|
|
|
P(addpchits);
|
|
|
|
P(setpchits);
|
|
|
|
P(setpcmisses);
|
|
|
|
P(setmisses);
|
|
|
|
P(kpcmisses);
|
|
|
|
P(kshapemisses);
|
|
|
|
P(vcapmisses);
|
|
|
|
P(misses);
|
|
|
|
P(flushes);
|
|
|
|
P(pcpurges);
|
|
|
|
# undef P
|
|
|
|
|
|
|
|
fprintf(fp, "hit rates: pc %g%% (proto %g%%), set %g%%, ini %g%%, full %g%%\n",
|
2010-03-24 19:20:44 -07:00
|
|
|
(100. * pchits) / tests,
|
|
|
|
(100. * protopchits) / tests,
|
|
|
|
(100. * (addpchits + setpchits))
|
|
|
|
/ settests,
|
|
|
|
(100. * inipchits) / initests,
|
|
|
|
(100. * (tests - misses)) / tests);
|
2010-03-24 14:16:01 -07:00
|
|
|
fflush(fp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-03-24 19:20:44 -07:00
|
|
|
PCMETER(flushes++);
|
2010-03-24 14:16:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-03-24 19:20:44 -07:00
|
|
|
PropertyCache::purgeForScript(JSScript *script)
|
2010-03-24 14:16:01 -07:00
|
|
|
{
|
2010-03-24 19:20:44 -07:00
|
|
|
for (PropertyCacheEntry *entry = table; entry < table + SIZE; entry++) {
|
2010-03-24 14:16:01 -07:00
|
|
|
if (JS_UPTRDIFF(entry->kpc, script->code) < script->length) {
|
|
|
|
entry->kpc = NULL;
|
|
|
|
#ifdef DEBUG
|
2010-03-26 07:01:01 -07:00
|
|
|
entry->kshape = entry->vcap = 0;
|
|
|
|
entry->vword.setNull();
|
2010-03-24 14:16:01 -07:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|