2011-03-13 17:45:02 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2010-03-25 05:20:44 +03:00
|
|
|
* vim: set ts=8 sw=4 et tw=98:
|
|
|
|
*
|
|
|
|
* ***** BEGIN LICENSE BLOCK *****
|
2010-03-25 00:16:01 +03: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 ***** */
|
|
|
|
|
|
|
|
#ifndef jspropertycache_h___
|
|
|
|
#define jspropertycache_h___
|
|
|
|
|
|
|
|
#include "jsapi.h"
|
|
|
|
#include "jsprvtd.h"
|
|
|
|
#include "jstypes.h"
|
|
|
|
|
2011-12-27 12:27:02 +04:00
|
|
|
#include "vm/String.h"
|
|
|
|
|
2010-03-25 05:20:44 +03:00
|
|
|
namespace js {
|
2010-03-25 00:16:01 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Property cache with structurally typed capabilities for invalidation, for
|
|
|
|
* polymorphic callsite method/get/set speedups. For details, see
|
|
|
|
* <https://developer.mozilla.org/en/SpiderMonkey/Internals/Property_cache>.
|
|
|
|
*/
|
2011-12-29 15:43:57 +04:00
|
|
|
class PropertyCache;
|
2010-03-26 17:01:01 +03:00
|
|
|
|
2010-03-25 05:20:44 +03:00
|
|
|
struct PropertyCacheEntry
|
2010-03-25 00:16:45 +03:00
|
|
|
{
|
2010-03-25 00:16:01 +03:00
|
|
|
jsbytecode *kpc; /* pc of cache-testing bytecode */
|
2011-09-29 02:04:55 +04:00
|
|
|
const Shape *kshape; /* shape of direct (key) object */
|
|
|
|
const Shape *pshape; /* shape of owning object */
|
|
|
|
const Shape *prop; /* shape of accessed property */
|
2010-03-25 05:20:44 +03:00
|
|
|
|
2011-12-29 15:43:57 +04:00
|
|
|
friend class PropertyCache;
|
|
|
|
|
|
|
|
private:
|
|
|
|
/* Index into scope chain; inapplicable to property lookup entries. */
|
|
|
|
uint8_t scopeIndex;
|
|
|
|
/* Index into the prototype chain from the object for this entry. */
|
|
|
|
uint8_t protoIndex;
|
|
|
|
|
|
|
|
public:
|
|
|
|
static const size_t MaxScopeIndex = 15;
|
|
|
|
static const size_t MaxProtoIndex = 15;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* True iff the property lookup will find an own property on the object if
|
|
|
|
* the entry matches.
|
|
|
|
*
|
|
|
|
* This test is applicable only to property lookups, not to identifier
|
|
|
|
* lookups. It is meaningless to ask this question of an entry for an
|
|
|
|
* identifier lookup.
|
|
|
|
*/
|
|
|
|
bool isOwnPropertyHit() const { return scopeIndex == 0 && protoIndex == 0; }
|
|
|
|
|
|
|
|
/*
|
|
|
|
* True iff the property lookup will find the property on the prototype of
|
|
|
|
* the object if the entry matches.
|
|
|
|
*
|
|
|
|
* This test is applicable only to property lookups, not to identifier
|
|
|
|
* lookups. It is meaningless to ask this question of an entry for an
|
|
|
|
* identifier lookup.
|
|
|
|
*/
|
|
|
|
bool isPrototypePropertyHit() const { return scopeIndex == 0 && protoIndex == 1; }
|
2010-03-25 05:20:44 +03:00
|
|
|
|
2011-09-29 02:04:55 +04:00
|
|
|
void assign(jsbytecode *kpc, const Shape *kshape, const Shape *pshape,
|
2012-02-29 03:11:11 +04:00
|
|
|
const Shape *prop, unsigned scopeIndex, unsigned protoIndex) {
|
2011-12-29 15:43:57 +04:00
|
|
|
JS_ASSERT(scopeIndex <= MaxScopeIndex);
|
|
|
|
JS_ASSERT(protoIndex <= MaxProtoIndex);
|
2010-03-25 05:20:44 +03:00
|
|
|
|
|
|
|
this->kpc = kpc;
|
|
|
|
this->kshape = kshape;
|
2011-09-29 02:04:55 +04:00
|
|
|
this->pshape = pshape;
|
|
|
|
this->prop = prop;
|
2011-12-29 15:43:57 +04:00
|
|
|
this->scopeIndex = uint8_t(scopeIndex);
|
|
|
|
this->protoIndex = uint8_t(protoIndex);
|
2010-03-25 00:16:01 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
2010-03-25 05:20:44 +03:00
|
|
|
* Special value for functions returning PropertyCacheEntry * to distinguish
|
2010-03-25 00:16:01 +03:00
|
|
|
* between failure and no no-cache-fill cases.
|
|
|
|
*/
|
2010-03-25 05:20:44 +03:00
|
|
|
#define JS_NO_PROP_CACHE_FILL ((js::PropertyCacheEntry *) NULL + 1)
|
2010-03-25 00:16:01 +03:00
|
|
|
|
|
|
|
#if defined DEBUG_brendan || defined DEBUG_brendaneich
|
|
|
|
#define JS_PROPERTY_CACHE_METERING 1
|
|
|
|
#endif
|
|
|
|
|
2010-03-27 02:38:33 +03:00
|
|
|
class PropertyCache
|
2010-03-25 05:20:44 +03:00
|
|
|
{
|
2010-03-27 02:38:33 +03:00
|
|
|
private:
|
2010-03-25 05:20:44 +03:00
|
|
|
enum {
|
|
|
|
SIZE_LOG2 = 12,
|
|
|
|
SIZE = JS_BIT(SIZE_LOG2),
|
|
|
|
MASK = JS_BITMASK(SIZE_LOG2)
|
|
|
|
};
|
|
|
|
|
|
|
|
PropertyCacheEntry table[SIZE];
|
2010-03-25 00:16:01 +03:00
|
|
|
JSBool empty;
|
2011-03-13 17:45:02 +03:00
|
|
|
|
2010-03-27 02:38:33 +03:00
|
|
|
public:
|
2011-03-13 17:45:02 +03:00
|
|
|
#ifdef JS_PROPERTY_CACHE_METERING
|
2010-03-25 05:20:44 +03:00
|
|
|
PropertyCacheEntry *pctestentry; /* entry of the last PC-based test */
|
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 fills; /* number of cache entry fills */
|
|
|
|
uint32_t nofills; /* couldn't fill (e.g. default get) */
|
|
|
|
uint32_t rofills; /* set on read-only prop can't fill */
|
|
|
|
uint32_t disfills; /* fill attempts on disabled cache */
|
|
|
|
uint32_t oddfills; /* fill attempt after setter deleted */
|
|
|
|
uint32_t add2dictfills; /* fill attempt on dictionary object */
|
|
|
|
uint32_t modfills; /* fill that rehashed to a new entry */
|
|
|
|
uint32_t brandfills; /* scope brandings to type structural
|
2010-03-25 00:16:01 +03:00
|
|
|
method fills */
|
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 noprotos; /* resolve-returned non-proto pobj */
|
|
|
|
uint32_t longchains; /* overlong scope and/or proto chain */
|
|
|
|
uint32_t recycles; /* cache entries recycled by fills */
|
|
|
|
uint32_t tests; /* cache probes */
|
|
|
|
uint32_t pchits; /* fast-path polymorphic op hits */
|
|
|
|
uint32_t protopchits; /* pchits hitting immediate prototype */
|
|
|
|
uint32_t initests; /* cache probes from JSOP_INITPROP */
|
|
|
|
uint32_t inipchits; /* init'ing next property pchit case */
|
|
|
|
uint32_t inipcmisses; /* init'ing next property pc misses */
|
|
|
|
uint32_t settests; /* cache probes from JOF_SET opcodes */
|
|
|
|
uint32_t addpchits; /* adding next property pchit case */
|
|
|
|
uint32_t setpchits; /* setting existing property pchit */
|
|
|
|
uint32_t setpcmisses; /* setting/adding property pc misses */
|
|
|
|
uint32_t setmisses; /* JSOP_SET{NAME,PROP} total misses */
|
|
|
|
uint32_t kpcmisses; /* slow-path key id == atom misses */
|
|
|
|
uint32_t kshapemisses; /* slow-path key object misses */
|
|
|
|
uint32_t vcapmisses; /* value capability misses */
|
|
|
|
uint32_t misses; /* cache misses */
|
|
|
|
uint32_t flushes; /* cache flushes */
|
|
|
|
uint32_t pcpurges; /* shadowing purges on proto chain */
|
2011-03-13 17:45:02 +03:00
|
|
|
|
2010-03-25 00:16:01 +03:00
|
|
|
# define PCMETER(x) x
|
|
|
|
#else
|
|
|
|
# define PCMETER(x) ((void)0)
|
|
|
|
#endif
|
2010-03-25 05:20:44 +03:00
|
|
|
|
2011-03-13 17:45:02 +03:00
|
|
|
PropertyCache() {
|
|
|
|
PodZero(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2012-01-11 12:23:05 +04:00
|
|
|
static inline uintptr_t
|
2011-09-29 02:04:55 +04:00
|
|
|
hash(jsbytecode *pc, const Shape *kshape)
|
2010-03-25 05:20:44 +03:00
|
|
|
{
|
2012-01-11 12:23:05 +04:00
|
|
|
return (((uintptr_t(pc) >> SIZE_LOG2) ^ uintptr_t(pc) ^ ((uintptr_t)kshape >> 3)) & MASK);
|
2010-03-25 05:20:44 +03: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
|
|
|
static inline bool matchShape(JSContext *cx, JSObject *obj, uint32_t shape);
|
2010-03-25 05:20:44 +03:00
|
|
|
|
2011-12-27 12:27:02 +04:00
|
|
|
PropertyName *
|
|
|
|
fullTest(JSContext *cx, jsbytecode *pc, JSObject **objp,
|
|
|
|
JSObject **pobjp, PropertyCacheEntry *entry);
|
2010-03-27 02:38:33 +03:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
void assertEmpty();
|
|
|
|
#else
|
|
|
|
inline void assertEmpty() {}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
public:
|
2011-12-21 05:31:28 +04:00
|
|
|
JS_ALWAYS_INLINE void test(JSContext *cx, jsbytecode *pc,
|
|
|
|
JSObject *&obj, JSObject *&pobj,
|
2011-12-27 12:27:02 +04:00
|
|
|
PropertyCacheEntry *&entry, PropertyName *&name);
|
2010-03-25 05:20:44 +03:00
|
|
|
|
2010-03-27 02:38:33 +03:00
|
|
|
/*
|
|
|
|
* Test for cached information about a property set on *objp at pc.
|
|
|
|
*
|
2010-10-26 05:22:07 +04:00
|
|
|
* On a hit, set *entryp to the entry and return true.
|
2010-03-27 02:38:33 +03:00
|
|
|
*
|
2011-12-27 12:27:02 +04:00
|
|
|
* On a miss, set *namep to the name of the property being set and return false.
|
2010-03-27 02:38:33 +03:00
|
|
|
*/
|
|
|
|
JS_ALWAYS_INLINE bool testForSet(JSContext *cx, jsbytecode *pc, JSObject *obj,
|
|
|
|
PropertyCacheEntry **entryp, JSObject **obj2p,
|
2011-12-27 12:27:02 +04:00
|
|
|
PropertyName **namep);
|
2010-03-27 02:38:33 +03:00
|
|
|
|
2010-03-25 05:20:44 +03:00
|
|
|
/*
|
|
|
|
* Fill property cache entry for key cx->fp->pc, optimized value word
|
2010-08-29 22:57:08 +04:00
|
|
|
* computed from obj and shape, and entry capability forged from 24-bit
|
2010-04-08 22:22:04 +04:00
|
|
|
* obj->shape(), 4-bit scopeIndex, and 4-bit protoIndex.
|
2010-03-25 05:20:44 +03:00
|
|
|
*
|
|
|
|
* Return the filled cache entry or JS_NO_PROP_CACHE_FILL if caching was
|
|
|
|
* not possible.
|
|
|
|
*/
|
2012-02-29 03:11:11 +04:00
|
|
|
PropertyCacheEntry *fill(JSContext *cx, JSObject *obj, unsigned scopeIndex,
|
2011-12-21 05:31:28 +04:00
|
|
|
JSObject *pobj, const js::Shape *shape);
|
2010-03-25 05:20:44 +03:00
|
|
|
|
2012-02-29 16:18:16 +04:00
|
|
|
void purge(JSRuntime *rt);
|
2011-03-23 21:57:19 +03:00
|
|
|
|
|
|
|
/* Restore an entry that may have been purged during a GC. */
|
|
|
|
void restore(PropertyCacheEntry *entry);
|
2010-03-25 05:20:44 +03:00
|
|
|
};
|
2010-03-25 00:16:01 +03:00
|
|
|
|
2010-03-25 05:20:44 +03:00
|
|
|
} /* namespace js */
|
2010-03-25 00:16:01 +03:00
|
|
|
|
|
|
|
#endif /* jspropertycache_h___ */
|