1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 : * vim: set ts=8 sw=4 et tw=99:
3 : *
4 : * ***** BEGIN LICENSE BLOCK *****
5 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 : *
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/
11 : *
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
15 : * License.
16 : *
17 : * The Original Code is Mozilla Communicator client code, released
18 : * March 31, 1998.
19 : *
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.
24 : *
25 : * Contributor(s):
26 : * Igor Bukanov <igor@mir2.org>
27 : *
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.
39 : *
40 : * ***** END LICENSE BLOCK ***** */
41 :
42 : #ifndef jspropertycacheinlines_h___
43 : #define jspropertycacheinlines_h___
44 :
45 : #include "jslock.h"
46 : #include "jspropertycache.h"
47 : #include "jsscope.h"
48 :
49 : /*
50 : * This method is designed to inline the fast path in js_Interpret, so it makes
51 : * "just-so" restrictions on parameters, e.g. pobj and obj should not be the
52 : * same variable, since for JOF_PROP-mode opcodes, obj must not be changed
53 : * because of a cache miss.
54 : *
55 : * On return, if name is null then obj points to the scope chain element in
56 : * which the property was found, pobj is locked, and entry is valid. If name is
57 : * non-null then no object is locked but entry is still set correctly for use,
58 : * e.g., by PropertyCache::fill and name should be used as the id to find.
59 : *
60 : * We must lock pobj on a hit in order to close races with threads that might
61 : * be deleting a property from its scope, or otherwise invalidating property
62 : * caches (on all threads) by re-generating JSObject::shape().
63 : */
64 : JS_ALWAYS_INLINE void
65 120564095 : js::PropertyCache::test(JSContext *cx, jsbytecode *pc, JSObject *&obj,
66 : JSObject *&pobj, PropertyCacheEntry *&entry, PropertyName *&name)
67 : {
68 120564095 : JS_ASSERT(this == &JS_PROPERTY_CACHE(cx));
69 :
70 120564095 : const Shape *kshape = obj->lastProperty();
71 120564095 : entry = &table[hash(pc, kshape)];
72 : PCMETER(pctestentry = entry);
73 : PCMETER(tests++);
74 120564095 : JS_ASSERT(&obj != &pobj);
75 120564095 : if (entry->kpc == pc && entry->kshape == kshape) {
76 : JSObject *tmp;
77 99544290 : pobj = obj;
78 108240230 : if (entry->isPrototypePropertyHit() &&
79 8695940 : (tmp = pobj->getProto()) != NULL) {
80 8695940 : pobj = tmp;
81 : }
82 :
83 99544290 : if (pobj->lastProperty() == entry->pshape) {
84 : PCMETER(pchits++);
85 : PCMETER(entry->isOwnPropertyHit() || protopchits++);
86 99379969 : name = NULL;
87 99379969 : return;
88 : }
89 : }
90 21184126 : name = fullTest(cx, pc, &obj, &pobj, entry);
91 21184126 : if (name)
92 : PCMETER(misses++);
93 : }
94 :
95 : JS_ALWAYS_INLINE bool
96 17694228 : js::PropertyCache::testForSet(JSContext *cx, jsbytecode *pc, JSObject *obj,
97 : PropertyCacheEntry **entryp, JSObject **obj2p, PropertyName **namep)
98 : {
99 17694228 : JS_ASSERT(this == &JS_PROPERTY_CACHE(cx));
100 :
101 17694228 : const Shape *kshape = obj->lastProperty();
102 17694228 : PropertyCacheEntry *entry = &table[hash(pc, kshape)];
103 17694228 : *entryp = entry;
104 : PCMETER(pctestentry = entry);
105 : PCMETER(tests++);
106 : PCMETER(settests++);
107 17694228 : if (entry->kpc == pc && entry->kshape == kshape)
108 15016855 : return true;
109 :
110 2677373 : PropertyName *name = fullTest(cx, pc, &obj, obj2p, entry);
111 2677373 : JS_ASSERT(name);
112 :
113 : PCMETER(misses++);
114 : PCMETER(setmisses++);
115 :
116 2677373 : *namep = name;
117 2677373 : return false;
118 : }
119 :
120 : #endif /* jspropertycacheinlines_h___ */
|