source: webkit/trunk/JavaScriptCore/runtime/Structure.h@ 47620

Last change on this file since 47620 was 47605, checked in by [email protected], 16 years ago

EGRESSION: significant slowdown on Celtic Kane "AJAX declaration" subtest
https://bugs.webkit.org/show_bug.cgi?id=28332

Reviewed by Geoff Garen

Follow up style fixes that were missed in review.

File size: 9.9 KB
Line 
1/*
2 * Copyright (C) 2008, 2009 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#ifndef Structure_h
27#define Structure_h
28
29#include "Identifier.h"
30#include "JSType.h"
31#include "JSValue.h"
32#include "MarkStack.h"
33#include "PropertyMapHashTable.h"
34#include "StructureChain.h"
35#include "StructureTransitionTable.h"
36#include "TypeInfo.h"
37#include "UString.h"
38#include <wtf/PassRefPtr.h>
39#include <wtf/RefCounted.h>
40
41#ifndef NDEBUG
42#define DUMP_PROPERTYMAP_STATS 0
43#else
44#define DUMP_PROPERTYMAP_STATS 0
45#endif
46
47namespace JSC {
48
49 class PropertyNameArray;
50 class PropertyNameArrayData;
51
52 class Structure : public RefCounted<Structure> {
53 public:
54 friend class JIT;
55 static PassRefPtr<Structure> create(JSValue prototype, const TypeInfo& typeInfo)
56 {
57 return adoptRef(new Structure(prototype, typeInfo));
58 }
59
60 static void startIgnoringLeaks();
61 static void stopIgnoringLeaks();
62
63 static void dumpStatistics();
64
65 static PassRefPtr<Structure> addPropertyTransition(Structure*, const Identifier& propertyName, unsigned attributes, JSCell* specificValue, size_t& offset);
66 static PassRefPtr<Structure> addPropertyTransitionToExistingStructure(Structure*, const Identifier& propertyName, unsigned attributes, JSCell* specificValue, size_t& offset);
67 static PassRefPtr<Structure> removePropertyTransition(Structure*, const Identifier& propertyName, size_t& offset);
68 static PassRefPtr<Structure> changePrototypeTransition(Structure*, JSValue prototype);
69 static PassRefPtr<Structure> despecifyFunctionTransition(Structure*, const Identifier&);
70 static PassRefPtr<Structure> getterSetterTransition(Structure*);
71 static PassRefPtr<Structure> toDictionaryTransition(Structure*);
72 static PassRefPtr<Structure> fromDictionaryTransition(Structure*);
73
74 ~Structure();
75
76 void markAggregate(MarkStack& markStack)
77 {
78 markStack.append(m_prototype);
79 }
80
81 // These should be used with caution.
82 size_t addPropertyWithoutTransition(const Identifier& propertyName, unsigned attributes, JSCell* specificValue);
83 size_t removePropertyWithoutTransition(const Identifier& propertyName);
84 void setPrototypeWithoutTransition(JSValue prototype) { m_prototype = prototype; }
85
86 bool isDictionary() const { return m_isDictionary; }
87
88 const TypeInfo& typeInfo() const { return m_typeInfo; }
89
90 JSValue storedPrototype() const { return m_prototype; }
91 JSValue prototypeForLookup(ExecState*) const;
92 StructureChain* prototypeChain(ExecState*) const;
93
94 Structure* previousID() const { return m_previous.get(); }
95
96 void growPropertyStorageCapacity();
97 size_t propertyStorageCapacity() const { return m_propertyStorageCapacity; }
98 size_t propertyStorageSize() const { return m_propertyTable ? m_propertyTable->keyCount + (m_propertyTable->deletedOffsets ? m_propertyTable->deletedOffsets->size() : 0) : m_offset + 1; }
99 bool isUsingInlineStorage() const;
100
101 size_t get(const Identifier& propertyName);
102 size_t get(const UString::Rep* rep, unsigned& attributes, JSCell*& specificValue);
103 size_t get(const Identifier& propertyName, unsigned& attributes, JSCell*& specificValue)
104 {
105 ASSERT(!propertyName.isNull());
106 return get(propertyName.ustring().rep(), attributes, specificValue);
107 }
108 bool transitionedFor(const JSCell* specificValue)
109 {
110 return m_specificValueInPrevious == specificValue;
111 }
112 bool hasTransition(UString::Rep*, unsigned attributes);
113 bool hasTransition(const Identifier& propertyName, unsigned attributes)
114 {
115 return hasTransition(propertyName._ustring.rep(), attributes);
116 }
117
118 void getEnumerablePropertyNames(ExecState*, PropertyNameArray&, JSObject*);
119
120 bool hasGetterSetterProperties() const { return m_hasGetterSetterProperties; }
121 void setHasGetterSetterProperties(bool hasGetterSetterProperties) { m_hasGetterSetterProperties = hasGetterSetterProperties; }
122
123 bool isEmpty() const { return m_propertyTable ? !m_propertyTable->keyCount : m_offset == noOffset; }
124
125 JSCell* specificValue() { return m_specificValueInPrevious; }
126 void despecifyDictionaryFunction(const Identifier& propertyName);
127
128 private:
129 Structure(JSValue prototype, const TypeInfo&);
130
131 size_t put(const Identifier& propertyName, unsigned attributes, JSCell* specificValue);
132 size_t remove(const Identifier& propertyName);
133 void getEnumerableNamesFromPropertyTable(PropertyNameArray&);
134 void getEnumerableNamesFromClassInfoTable(ExecState*, const ClassInfo*, PropertyNameArray&);
135
136 void expandPropertyMapHashTable();
137 void rehashPropertyMapHashTable();
138 void rehashPropertyMapHashTable(unsigned newTableSize);
139 void createPropertyMapHashTable();
140 void createPropertyMapHashTable(unsigned newTableSize);
141 void insertIntoPropertyMapHashTable(const PropertyMapEntry&);
142 void checkConsistency();
143
144 bool despecifyFunction(const Identifier&);
145
146 PropertyMapHashTable* copyPropertyTable();
147 void materializePropertyMap();
148 void materializePropertyMapIfNecessary()
149 {
150 if (m_propertyTable || !m_previous)
151 return;
152 materializePropertyMap();
153 }
154
155 void clearEnumerationCache();
156
157 signed char transitionCount() const
158 {
159 // Since the number of transitions is always the same as m_offset, we keep the size of Structure down by not storing both.
160 return m_offset == noOffset ? 0 : m_offset + 1;
161 }
162
163 bool isValid(ExecState*, StructureChain* cachedPrototypeChain) const;
164
165 static const unsigned emptyEntryIndex = 0;
166
167 static const signed char s_maxTransitionLength = 64;
168
169 static const signed char noOffset = -1;
170
171 TypeInfo m_typeInfo;
172
173 JSValue m_prototype;
174 mutable RefPtr<StructureChain> m_cachedPrototypeChain;
175
176 RefPtr<Structure> m_previous;
177 RefPtr<UString::Rep> m_nameInPrevious;
178 JSCell* m_specificValueInPrevious;
179
180 union {
181 Structure* singleTransition;
182 StructureTransitionTable* table;
183 } m_transitions;
184
185 RefPtr<PropertyNameArrayData> m_cachedPropertyNameArrayData;
186
187 PropertyMapHashTable* m_propertyTable;
188
189 size_t m_propertyStorageCapacity;
190 signed char m_offset;
191
192 bool m_isDictionary : 1;
193 bool m_isPinnedPropertyTable : 1;
194 bool m_hasGetterSetterProperties : 1;
195 bool m_usingSingleTransitionSlot : 1;
196 unsigned m_attributesInPrevious : 7;
197 };
198
199 inline size_t Structure::get(const Identifier& propertyName)
200 {
201 ASSERT(!propertyName.isNull());
202
203 materializePropertyMapIfNecessary();
204 if (!m_propertyTable)
205 return WTF::notFound;
206
207 UString::Rep* rep = propertyName._ustring.rep();
208
209 unsigned i = rep->computedHash();
210
211#if DUMP_PROPERTYMAP_STATS
212 ++numProbes;
213#endif
214
215 unsigned entryIndex = m_propertyTable->entryIndices[i & m_propertyTable->sizeMask];
216 if (entryIndex == emptyEntryIndex)
217 return WTF::notFound;
218
219 if (rep == m_propertyTable->entries()[entryIndex - 1].key)
220 return m_propertyTable->entries()[entryIndex - 1].offset;
221
222#if DUMP_PROPERTYMAP_STATS
223 ++numCollisions;
224#endif
225
226 unsigned k = 1 | WTF::doubleHash(rep->computedHash());
227
228 while (1) {
229 i += k;
230
231#if DUMP_PROPERTYMAP_STATS
232 ++numRehashes;
233#endif
234
235 entryIndex = m_propertyTable->entryIndices[i & m_propertyTable->sizeMask];
236 if (entryIndex == emptyEntryIndex)
237 return WTF::notFound;
238
239 if (rep == m_propertyTable->entries()[entryIndex - 1].key)
240 return m_propertyTable->entries()[entryIndex - 1].offset;
241 }
242 }
243
244 bool StructureTransitionTable::contains(const StructureTransitionTableHash::Key& key, JSCell* specificValue)
245 {
246 TransitionTable::iterator find = m_table.find(key);
247 if (find == m_table.end())
248 return false;
249
250 return find->second.first || find->second.second->transitionedFor(specificValue);
251 }
252
253 Structure* StructureTransitionTable::get(const StructureTransitionTableHash::Key& key, JSCell* specificValue) const
254 {
255 Transition transition = m_table.get(key);
256 if (transition.second && transition.second->transitionedFor(specificValue))
257 return transition.second;
258 return transition.first;
259 }
260} // namespace JSC
261
262#endif // Structure_h
Note: See TracBrowser for help on using the repository browser.