1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * vim: set ts=8 sw=4 et tw=99:
4 * ***** BEGIN LICENSE BLOCK *****
5 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
7 * The contents of this file are subject to the Mozilla Public License Version
8 * 1.1 (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
10 * http://www.mozilla.org/MPL/
12 * Software distributed under the License is distributed on an "AS IS" basis,
13 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14 * for the specific language governing rights and limitations under the
17 * The Original Code is Mozilla Communicator client code, released
20 * The Initial Developer of the Original Code is
21 * Mozilla Corporation.
22 * Portions created by the Initial Developer are Copyright (C) 2010
23 * the Initial Developer. All Rights Reserved.
26 * Igor Bukanov <igor@mir2.org>
28 * Alternatively, the contents of this file may be used under the terms of
29 * either of the GNU General Public License Version 2 or later (the "GPL"),
30 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
31 * in which case the provisions of the GPL or the LGPL are applicable instead
32 * of those above. If you wish to allow use of your version of this file only
33 * under the terms of either the GPL or the LGPL, and not to allow others to
34 * use your version of this file under the terms of the MPL, indicate your
35 * decision by deleting the provisions above and replace them with the notice
36 * and other provisions required by the GPL or the LGPL. If you do not delete
37 * the provisions above, a recipient may use your version of this file under
38 * the terms of any one of the MPL, the GPL or the LGPL.
40 * ***** END LICENSE BLOCK ***** */
42 #ifndef jspropertycacheinlines_h___
43 #define jspropertycacheinlines_h___
46 #include "jspropertycache.h"
51 /* static */ inline bool
52 PropertyCache::matchShape(JSContext
*cx
, JSObject
*obj
, uint32 shape
)
54 return obj
->shape() == shape
;
58 * This method is designed to inline the fast path in js_Interpret, so it makes
59 * "just-so" restrictions on parameters, e.g. pobj and obj should not be the
60 * same variable, since for JOF_PROP-mode opcodes, obj must not be changed
61 * because of a cache miss.
63 * On return, if atom is null then obj points to the scope chain element in
64 * which the property was found, pobj is locked, and entry is valid. If atom is
65 * non-null then no object is locked but entry is still set correctly for use,
66 * e.g., by PropertyCache::fill and atom should be used as the id to find.
68 * We must lock pobj on a hit in order to close races with threads that might
69 * be deleting a property from its scope, or otherwise invalidating property
70 * caches (on all threads) by re-generating JSObject::shape().
73 PropertyCache::test(JSContext
*cx
, jsbytecode
*pc
, JSObject
*&obj
,
74 JSObject
*&pobj
, PropertyCacheEntry
*&entry
, JSAtom
*&atom
)
76 JS_ASSERT(this == &JS_PROPERTY_CACHE(cx
));
78 uint32 kshape
= obj
->shape();
79 entry
= &table
[hash(pc
, kshape
)];
80 PCMETER(pctestentry
= entry
);
82 JS_ASSERT(&obj
!= &pobj
);
83 JS_ASSERT(entry
->kshape
< SHAPE_OVERFLOW_BIT
);
84 if (entry
->kpc
== pc
&& entry
->kshape
== kshape
) {
87 if (entry
->vcapTag() == 1 &&
88 (tmp
= pobj
->getProto()) != NULL
) {
92 if (matchShape(cx
, pobj
, entry
->vshape())) {
94 PCMETER(!entry
->vcapTag() || protopchits
++);
99 atom
= fullTest(cx
, pc
, &obj
, &pobj
, entry
);
104 JS_ALWAYS_INLINE
bool
105 PropertyCache::testForSet(JSContext
*cx
, jsbytecode
*pc
, JSObject
*obj
,
106 PropertyCacheEntry
**entryp
, JSObject
**obj2p
, JSAtom
**atomp
)
108 uint32 shape
= obj
->shape();
109 PropertyCacheEntry
*entry
= &table
[hash(pc
, shape
)];
111 PCMETER(pctestentry
= entry
);
114 JS_ASSERT(entry
->kshape
< SHAPE_OVERFLOW_BIT
);
115 if (entry
->kpc
== pc
&& entry
->kshape
== shape
)
118 JSAtom
*atom
= fullTest(cx
, pc
, &obj
, obj2p
, entry
);
122 PCMETER(setmisses
++);
128 JS_ALWAYS_INLINE
bool
129 PropertyCache::testForInit(JSRuntime
*rt
, jsbytecode
*pc
, JSObject
*obj
,
130 const js::Shape
**shapep
, PropertyCacheEntry
**entryp
)
132 JS_ASSERT(obj
->slotSpan() >= JSSLOT_FREE(obj
->getClass()));
133 JS_ASSERT(obj
->isExtensible());
134 uint32 kshape
= obj
->shape();
135 PropertyCacheEntry
*entry
= &table
[hash(pc
, kshape
)];
137 PCMETER(pctestentry
= entry
);
140 JS_ASSERT(entry
->kshape
< SHAPE_OVERFLOW_BIT
);
142 if (entry
->kpc
== pc
&&
143 entry
->kshape
== kshape
&&
144 entry
->vshape() == rt
->protoHazardShape
) {
146 PCMETER(inipchits
++);
147 JS_ASSERT(entry
->vcapTag() == 0);
148 *shapep
= entry
->vword
.toShape();
149 JS_ASSERT((*shapep
)->writable());
155 #endif /* jspropertycacheinlines_h___ */