weinig@apple.com | 3412bb4 | 2008-09-01 21:22:54 +0000 | [diff] [blame] | 1 | /* |
fpizlo@apple.com | 31be38f | 2013-02-16 05:31:00 +0000 | [diff] [blame] | 2 | * Copyright (C) 2008, 2009, 2012, 2013 Apple Inc. All rights reserved. |
weinig@apple.com | 3412bb4 | 2008-09-01 21:22:54 +0000 | [diff] [blame] | 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 | |
darin@apple.com | a9778f9 | 2008-11-16 04:40:06 +0000 | [diff] [blame] | 26 | #ifndef Structure_h |
| 27 | #define Structure_h |
weinig@apple.com | 3412bb4 | 2008-09-01 21:22:54 +0000 | [diff] [blame] | 28 | |
barraclough@apple.com | dfe18a5 | 2011-10-15 01:25:53 +0000 | [diff] [blame] | 29 | #include "ClassInfo.h" |
fpizlo@apple.com | d8dd053 | 2012-09-13 04:18:52 +0000 | [diff] [blame] | 30 | #include "IndexingType.h" |
mhahnenberg@apple.com | c1bc9d3 | 2013-01-24 21:39:55 +0000 | [diff] [blame] | 31 | #include "JSCJSValue.h" |
oliver@apple.com | ed66e77 | 2011-04-05 01:33:58 +0000 | [diff] [blame] | 32 | #include "JSCell.h" |
mjs@apple.com | 4fab811 | 2008-09-10 08:42:43 +0000 | [diff] [blame] | 33 | #include "JSType.h" |
barraclough@apple.com | 38d3c75 | 2012-05-12 00:39:43 +0000 | [diff] [blame] | 34 | #include "PropertyName.h" |
ggaren@apple.com | a850b06 | 2009-10-09 18:14:08 +0000 | [diff] [blame] | 35 | #include "PropertyNameArray.h" |
akling@apple.com | 85b2682 | 2013-03-06 12:52:16 +0000 | [diff] [blame] | 36 | #include "PropertyOffset.h" |
ggaren@apple.com | 5236be2 | 2009-10-17 05:52:20 +0000 | [diff] [blame] | 37 | #include "Protect.h" |
mhahnenberg@apple.com | dc3d148 | 2013-02-01 23:10:49 +0000 | [diff] [blame] | 38 | #include "StructureRareData.h" |
darin@apple.com | a9778f9 | 2008-11-16 04:40:06 +0000 | [diff] [blame] | 39 | #include "StructureTransitionTable.h" |
hausmann@webkit.org | f580f32 | 2009-09-09 14:56:12 +0000 | [diff] [blame] | 40 | #include "JSTypeInfo.h" |
fpizlo@apple.com | 04e4115 | 2012-06-15 22:14:53 +0000 | [diff] [blame] | 41 | #include "Watchpoint.h" |
ggaren@apple.com | f03cbce | 2011-04-10 02:32:07 +0000 | [diff] [blame] | 42 | #include "Weak.h" |
weinig@apple.com | 3412bb4 | 2008-09-01 21:22:54 +0000 | [diff] [blame] | 43 | #include <wtf/PassRefPtr.h> |
| 44 | #include <wtf/RefCounted.h> |
benjamin@webkit.org | cff06e4 | 2012-08-30 21:23:51 +0000 | [diff] [blame] | 45 | #include <wtf/text/StringImpl.h> |
weinig@apple.com | 3412bb4 | 2008-09-01 21:22:54 +0000 | [diff] [blame] | 46 | |
weinig@apple.com | c13fb9f | 2008-10-31 00:12:50 +0000 | [diff] [blame] | 47 | |
cwzwarich@webkit.org | 3f782f6 | 2008-09-08 01:28:33 +0000 | [diff] [blame] | 48 | namespace JSC { |
weinig@apple.com | 3412bb4 | 2008-09-01 21:22:54 +0000 | [diff] [blame] | 49 | |
fpizlo@apple.com | 34cee20 | 2013-02-16 20:07:05 +0000 | [diff] [blame] | 50 | class LLIntOffsetsExtractor; |
| 51 | class PropertyNameArray; |
| 52 | class PropertyNameArrayData; |
akling@apple.com | 85b2682 | 2013-03-06 12:52:16 +0000 | [diff] [blame] | 53 | class PropertyTable; |
fpizlo@apple.com | 34cee20 | 2013-02-16 20:07:05 +0000 | [diff] [blame] | 54 | class StructureChain; |
| 55 | class SlotVisitor; |
| 56 | class JSString; |
weinig@apple.com | 3412bb4 | 2008-09-01 21:22:54 +0000 | [diff] [blame] | 57 | |
fpizlo@apple.com | 34cee20 | 2013-02-16 20:07:05 +0000 | [diff] [blame] | 58 | // The out-of-line property storage capacity to use when first allocating out-of-line |
| 59 | // storage. Note that all objects start out without having any out-of-line storage; |
| 60 | // this comes into play only on the first property store that exhausts inline storage. |
| 61 | static const unsigned initialOutOfLineCapacity = 4; |
fpizlo@apple.com | 1ffdcff | 2012-07-19 00:30:34 +0000 | [diff] [blame] | 62 | |
fpizlo@apple.com | 34cee20 | 2013-02-16 20:07:05 +0000 | [diff] [blame] | 63 | // The factor by which to grow out-of-line storage when it is exhausted, after the |
| 64 | // initial allocation. |
| 65 | static const unsigned outOfLineGrowthFactor = 2; |
fpizlo@apple.com | 1ffdcff | 2012-07-19 00:30:34 +0000 | [diff] [blame] | 66 | |
fpizlo@apple.com | 34cee20 | 2013-02-16 20:07:05 +0000 | [diff] [blame] | 67 | class Structure : public JSCell { |
| 68 | public: |
| 69 | friend class StructureTransitionTable; |
commit-queue@webkit.org | 6c25c52 | 2011-08-09 20:46:17 +0000 | [diff] [blame] | 70 | |
fpizlo@apple.com | 34cee20 | 2013-02-16 20:07:05 +0000 | [diff] [blame] | 71 | typedef JSCell Base; |
commit-queue@webkit.org | 6c25c52 | 2011-08-09 20:46:17 +0000 | [diff] [blame] | 72 | |
fpizlo@apple.com | 34cee20 | 2013-02-16 20:07:05 +0000 | [diff] [blame] | 73 | static Structure* create(JSGlobalData&, JSGlobalObject*, JSValue prototype, const TypeInfo&, const ClassInfo*, IndexingType = NonArray, unsigned inlineCapacity = 0); |
weinig@apple.com | 2229430 | 2008-09-09 06:55:39 +0000 | [diff] [blame] | 74 | |
fpizlo@apple.com | 34cee20 | 2013-02-16 20:07:05 +0000 | [diff] [blame] | 75 | protected: |
| 76 | void finishCreation(JSGlobalData& globalData) |
mhahnenberg@apple.com | b44a7f0 | 2012-07-26 23:27:53 +0000 | [diff] [blame] | 77 | { |
fpizlo@apple.com | 34cee20 | 2013-02-16 20:07:05 +0000 | [diff] [blame] | 78 | Base::finishCreation(globalData); |
| 79 | ASSERT(m_prototype); |
| 80 | ASSERT(m_prototype.isObject() || m_prototype.isNull()); |
mhahnenberg@apple.com | b44a7f0 | 2012-07-26 23:27:53 +0000 | [diff] [blame] | 81 | } |
fpizlo@apple.com | 34cee20 | 2013-02-16 20:07:05 +0000 | [diff] [blame] | 82 | |
| 83 | void finishCreation(JSGlobalData& globalData, CreatingEarlyCellTag) |
mhahnenberg@apple.com | b44a7f0 | 2012-07-26 23:27:53 +0000 | [diff] [blame] | 84 | { |
fpizlo@apple.com | 34cee20 | 2013-02-16 20:07:05 +0000 | [diff] [blame] | 85 | Base::finishCreation(globalData, this, CreatingEarlyCell); |
| 86 | ASSERT(m_prototype); |
| 87 | ASSERT(m_prototype.isNull()); |
mhahnenberg@apple.com | b44a7f0 | 2012-07-26 23:27:53 +0000 | [diff] [blame] | 88 | ASSERT(!globalData.structureStructure); |
mhahnenberg@apple.com | b44a7f0 | 2012-07-26 23:27:53 +0000 | [diff] [blame] | 89 | } |
| 90 | |
fpizlo@apple.com | 34cee20 | 2013-02-16 20:07:05 +0000 | [diff] [blame] | 91 | public: |
| 92 | static void dumpStatistics(); |
| 93 | |
| 94 | JS_EXPORT_PRIVATE static Structure* addPropertyTransition(JSGlobalData&, Structure*, PropertyName, unsigned attributes, JSCell* specificValue, PropertyOffset&); |
| 95 | JS_EXPORT_PRIVATE static Structure* addPropertyTransitionToExistingStructure(Structure*, PropertyName, unsigned attributes, JSCell* specificValue, PropertyOffset&); |
| 96 | static Structure* removePropertyTransition(JSGlobalData&, Structure*, PropertyName, PropertyOffset&); |
| 97 | JS_EXPORT_PRIVATE static Structure* changePrototypeTransition(JSGlobalData&, Structure*, JSValue prototype); |
| 98 | JS_EXPORT_PRIVATE static Structure* despecifyFunctionTransition(JSGlobalData&, Structure*, PropertyName); |
| 99 | static Structure* attributeChangeTransition(JSGlobalData&, Structure*, PropertyName, unsigned attributes); |
| 100 | static Structure* toCacheableDictionaryTransition(JSGlobalData&, Structure*); |
| 101 | static Structure* toUncacheableDictionaryTransition(JSGlobalData&, Structure*); |
| 102 | static Structure* sealTransition(JSGlobalData&, Structure*); |
| 103 | static Structure* freezeTransition(JSGlobalData&, Structure*); |
| 104 | static Structure* preventExtensionsTransition(JSGlobalData&, Structure*); |
| 105 | static Structure* nonPropertyTransition(JSGlobalData&, Structure*, NonPropertyTransition); |
| 106 | |
| 107 | bool isSealed(JSGlobalData&); |
| 108 | bool isFrozen(JSGlobalData&); |
| 109 | bool isExtensible() const { return !m_preventExtensions; } |
| 110 | bool didTransition() const { return m_didTransition; } |
akling@apple.com | 85b2682 | 2013-03-06 12:52:16 +0000 | [diff] [blame] | 111 | bool putWillGrowOutOfLineStorage(); |
fpizlo@apple.com | 34cee20 | 2013-02-16 20:07:05 +0000 | [diff] [blame] | 112 | JS_EXPORT_PRIVATE size_t suggestedNewOutOfLineStorageCapacity(); |
fpizlo@apple.com | 74d43ae | 2011-09-17 23:33:01 +0000 | [diff] [blame] | 113 | |
fpizlo@apple.com | 34cee20 | 2013-02-16 20:07:05 +0000 | [diff] [blame] | 114 | Structure* flattenDictionaryStructure(JSGlobalData&, JSObject*); |
| 115 | |
| 116 | static const bool needsDestruction = true; |
| 117 | static const bool hasImmortalStructure = true; |
| 118 | static void destroy(JSCell*); |
| 119 | |
| 120 | // These should be used with caution. |
| 121 | JS_EXPORT_PRIVATE PropertyOffset addPropertyWithoutTransition(JSGlobalData&, PropertyName, unsigned attributes, JSCell* specificValue); |
| 122 | PropertyOffset removePropertyWithoutTransition(JSGlobalData&, PropertyName); |
| 123 | void setPrototypeWithoutTransition(JSGlobalData& globalData, JSValue prototype) { m_prototype.set(globalData, this, prototype); } |
| 124 | |
| 125 | bool isDictionary() const { return m_dictionaryKind != NoneDictionaryKind; } |
| 126 | bool isUncacheableDictionary() const { return m_dictionaryKind == UncachedDictionaryKind; } |
| 127 | |
| 128 | bool propertyAccessesAreCacheable() { return m_dictionaryKind != UncachedDictionaryKind && !typeInfo().prohibitsPropertyCaching(); } |
| 129 | |
| 130 | // Type accessors. |
| 131 | const TypeInfo& typeInfo() const { ASSERT(structure()->classInfo() == &s_info); return m_typeInfo; } |
| 132 | bool isObject() const { return typeInfo().isObject(); } |
| 133 | |
| 134 | IndexingType indexingType() const { return m_indexingType & AllArrayTypes; } |
| 135 | IndexingType indexingTypeIncludingHistory() const { return m_indexingType; } |
| 136 | |
| 137 | bool mayInterceptIndexedAccesses() const |
mhahnenberg@apple.com | 9f04ed4 | 2013-02-02 03:57:42 +0000 | [diff] [blame] | 138 | { |
fpizlo@apple.com | 34cee20 | 2013-02-16 20:07:05 +0000 | [diff] [blame] | 139 | return !!(indexingTypeIncludingHistory() & MayHaveIndexedAccessors); |
| 140 | } |
| 141 | |
| 142 | bool anyObjectInChainMayInterceptIndexedAccesses() const; |
| 143 | |
| 144 | bool needsSlowPutIndexing() const; |
| 145 | NonPropertyTransition suggestedArrayStorageTransition() const; |
| 146 | |
| 147 | JSGlobalObject* globalObject() const { return m_globalObject.get(); } |
| 148 | void setGlobalObject(JSGlobalData& globalData, JSGlobalObject* globalObject) { m_globalObject.set(globalData, this, globalObject); } |
| 149 | |
| 150 | JSValue storedPrototype() const { return m_prototype.get(); } |
| 151 | JSValue prototypeForLookup(ExecState*) const; |
| 152 | JSValue prototypeForLookup(JSGlobalObject*) const; |
| 153 | JSValue prototypeForLookup(CodeBlock*) const; |
| 154 | StructureChain* prototypeChain(JSGlobalData&, JSGlobalObject*) const; |
| 155 | StructureChain* prototypeChain(ExecState*) const; |
| 156 | static void visitChildren(JSCell*, SlotVisitor&); |
| 157 | |
| 158 | // Will just the prototype chain intercept this property access? |
| 159 | bool prototypeChainMayInterceptStoreTo(JSGlobalData&, PropertyName); |
| 160 | |
| 161 | bool transitionDidInvolveSpecificValue() const { return !!m_specificValueInPrevious; } |
| 162 | |
| 163 | Structure* previousID() const |
| 164 | { |
| 165 | ASSERT(structure()->classInfo() == &s_info); |
| 166 | if (typeInfo().structureHasRareData()) |
| 167 | return rareData()->previousID(); |
| 168 | return previous(); |
| 169 | } |
| 170 | bool transitivelyTransitionedFrom(Structure* structureToFind); |
| 171 | |
| 172 | unsigned outOfLineCapacity() const |
| 173 | { |
| 174 | ASSERT(checkOffsetConsistency()); |
| 175 | |
| 176 | unsigned outOfLineSize = this->outOfLineSize(); |
| 177 | |
| 178 | if (!outOfLineSize) |
| 179 | return 0; |
| 180 | |
| 181 | if (outOfLineSize <= initialOutOfLineCapacity) |
| 182 | return initialOutOfLineCapacity; |
| 183 | |
| 184 | ASSERT(outOfLineSize > initialOutOfLineCapacity); |
| 185 | COMPILE_ASSERT(outOfLineGrowthFactor == 2, outOfLineGrowthFactor_is_two); |
| 186 | return WTF::roundUpToPowerOfTwo(outOfLineSize); |
| 187 | } |
| 188 | unsigned outOfLineSize() const |
| 189 | { |
| 190 | ASSERT(checkOffsetConsistency()); |
| 191 | ASSERT(structure()->classInfo() == &s_info); |
| 192 | |
| 193 | return numberOfOutOfLineSlotsForLastOffset(m_offset); |
| 194 | } |
| 195 | bool hasInlineStorage() const |
| 196 | { |
| 197 | return !!m_inlineCapacity; |
| 198 | } |
| 199 | unsigned inlineCapacity() const |
| 200 | { |
| 201 | return m_inlineCapacity; |
| 202 | } |
| 203 | unsigned inlineSize() const |
| 204 | { |
| 205 | return std::min<unsigned>(m_offset + 1, m_inlineCapacity); |
| 206 | } |
| 207 | unsigned totalStorageSize() const |
| 208 | { |
| 209 | return numberOfSlotsForLastOffset(m_offset, m_inlineCapacity); |
| 210 | } |
| 211 | unsigned totalStorageCapacity() const |
| 212 | { |
| 213 | ASSERT(structure()->classInfo() == &s_info); |
| 214 | return outOfLineCapacity() + inlineCapacity(); |
mhahnenberg@apple.com | 9f04ed4 | 2013-02-02 03:57:42 +0000 | [diff] [blame] | 215 | } |
| 216 | |
fpizlo@apple.com | 34cee20 | 2013-02-16 20:07:05 +0000 | [diff] [blame] | 217 | PropertyOffset firstValidOffset() const |
| 218 | { |
| 219 | if (hasInlineStorage()) |
| 220 | return 0; |
| 221 | return firstOutOfLineOffset; |
| 222 | } |
| 223 | PropertyOffset lastValidOffset() const |
| 224 | { |
| 225 | return m_offset; |
| 226 | } |
| 227 | bool isValidOffset(PropertyOffset offset) const |
| 228 | { |
| 229 | return offset >= firstValidOffset() |
| 230 | && offset <= lastValidOffset(); |
| 231 | } |
| 232 | |
| 233 | bool masqueradesAsUndefined(JSGlobalObject* lexicalGlobalObject); |
| 234 | |
| 235 | PropertyOffset get(JSGlobalData&, PropertyName); |
| 236 | PropertyOffset get(JSGlobalData&, const WTF::String& name); |
| 237 | JS_EXPORT_PRIVATE PropertyOffset get(JSGlobalData&, PropertyName, unsigned& attributes, JSCell*& specificValue); |
| 238 | |
| 239 | bool hasGetterSetterProperties() const { return m_hasGetterSetterProperties; } |
| 240 | bool hasReadOnlyOrGetterSetterPropertiesExcludingProto() const { return m_hasReadOnlyOrGetterSetterPropertiesExcludingProto; } |
| 241 | void setHasGetterSetterProperties(bool is__proto__) |
| 242 | { |
| 243 | m_hasGetterSetterProperties = true; |
| 244 | if (!is__proto__) |
| 245 | m_hasReadOnlyOrGetterSetterPropertiesExcludingProto = true; |
| 246 | } |
| 247 | void setContainsReadOnlyProperties() |
| 248 | { |
| 249 | m_hasReadOnlyOrGetterSetterPropertiesExcludingProto = true; |
| 250 | } |
| 251 | |
| 252 | bool hasNonEnumerableProperties() const { return m_hasNonEnumerableProperties; } |
| 253 | |
| 254 | bool isEmpty() const |
| 255 | { |
| 256 | ASSERT(checkOffsetConsistency()); |
| 257 | return !JSC::isValidOffset(m_offset); |
| 258 | } |
| 259 | |
| 260 | JS_EXPORT_PRIVATE void despecifyDictionaryFunction(JSGlobalData&, PropertyName); |
| 261 | void disableSpecificFunctionTracking() { m_specificFunctionThrashCount = maxSpecificFunctionThrashCount; } |
| 262 | |
| 263 | void setEnumerationCache(JSGlobalData&, JSPropertyNameIterator* enumerationCache); // Defined in JSPropertyNameIterator.h. |
| 264 | JSPropertyNameIterator* enumerationCache(); // Defined in JSPropertyNameIterator.h. |
| 265 | void getPropertyNamesFromStructure(JSGlobalData&, PropertyNameArray&, EnumerationMode); |
| 266 | |
| 267 | JSString* objectToStringValue() |
mhahnenberg@apple.com | 9f04ed4 | 2013-02-02 03:57:42 +0000 | [diff] [blame] | 268 | { |
| 269 | if (!typeInfo().structureHasRareData()) |
| 270 | return 0; |
fpizlo@apple.com | 34cee20 | 2013-02-16 20:07:05 +0000 | [diff] [blame] | 271 | return rareData()->objectToStringValue(); |
mhahnenberg@apple.com | 9f04ed4 | 2013-02-02 03:57:42 +0000 | [diff] [blame] | 272 | } |
| 273 | |
fpizlo@apple.com | 34cee20 | 2013-02-16 20:07:05 +0000 | [diff] [blame] | 274 | void setObjectToStringValue(JSGlobalData& globalData, const JSCell* owner, JSString* value) |
| 275 | { |
| 276 | if (!typeInfo().structureHasRareData()) |
| 277 | allocateRareData(globalData); |
| 278 | rareData()->setObjectToStringValue(globalData, owner, value); |
| 279 | } |
| 280 | |
| 281 | bool staticFunctionsReified() |
| 282 | { |
| 283 | return m_staticFunctionReified; |
| 284 | } |
| 285 | |
| 286 | void setStaticFunctionsReified() |
| 287 | { |
| 288 | m_staticFunctionReified = true; |
| 289 | } |
| 290 | |
| 291 | const ClassInfo* classInfo() const { return m_classInfo; } |
| 292 | |
| 293 | static ptrdiff_t prototypeOffset() |
| 294 | { |
| 295 | return OBJECT_OFFSETOF(Structure, m_prototype); |
| 296 | } |
| 297 | |
| 298 | static ptrdiff_t globalObjectOffset() |
| 299 | { |
| 300 | return OBJECT_OFFSETOF(Structure, m_globalObject); |
| 301 | } |
| 302 | |
| 303 | static ptrdiff_t typeInfoFlagsOffset() |
| 304 | { |
| 305 | return OBJECT_OFFSETOF(Structure, m_typeInfo) + TypeInfo::flagsOffset(); |
| 306 | } |
| 307 | |
| 308 | static ptrdiff_t typeInfoTypeOffset() |
| 309 | { |
| 310 | return OBJECT_OFFSETOF(Structure, m_typeInfo) + TypeInfo::typeOffset(); |
| 311 | } |
| 312 | |
| 313 | static ptrdiff_t classInfoOffset() |
| 314 | { |
| 315 | return OBJECT_OFFSETOF(Structure, m_classInfo); |
| 316 | } |
| 317 | |
| 318 | static ptrdiff_t indexingTypeOffset() |
| 319 | { |
| 320 | return OBJECT_OFFSETOF(Structure, m_indexingType); |
| 321 | } |
| 322 | |
| 323 | static Structure* createStructure(JSGlobalData&); |
| 324 | |
| 325 | bool transitionWatchpointSetHasBeenInvalidated() const |
| 326 | { |
| 327 | return m_transitionWatchpointSet.hasBeenInvalidated(); |
| 328 | } |
| 329 | |
| 330 | bool transitionWatchpointSetIsStillValid() const |
| 331 | { |
| 332 | return m_transitionWatchpointSet.isStillValid(); |
| 333 | } |
| 334 | |
| 335 | void addTransitionWatchpoint(Watchpoint* watchpoint) const |
| 336 | { |
| 337 | ASSERT(transitionWatchpointSetIsStillValid()); |
| 338 | m_transitionWatchpointSet.add(watchpoint); |
| 339 | } |
| 340 | |
| 341 | void notifyTransitionFromThisStructure() const |
| 342 | { |
| 343 | m_transitionWatchpointSet.notifyWrite(); |
| 344 | } |
| 345 | |
| 346 | static JS_EXPORTDATA const ClassInfo s_info; |
| 347 | |
| 348 | private: |
| 349 | friend class LLIntOffsetsExtractor; |
| 350 | |
| 351 | JS_EXPORT_PRIVATE Structure(JSGlobalData&, JSGlobalObject*, JSValue prototype, const TypeInfo&, const ClassInfo*, IndexingType, unsigned inlineCapacity); |
| 352 | Structure(JSGlobalData&); |
| 353 | Structure(JSGlobalData&, const Structure*); |
| 354 | |
| 355 | static Structure* create(JSGlobalData&, const Structure*); |
| 356 | |
| 357 | typedef enum { |
| 358 | NoneDictionaryKind = 0, |
| 359 | CachedDictionaryKind = 1, |
| 360 | UncachedDictionaryKind = 2 |
| 361 | } DictionaryKind; |
| 362 | static Structure* toDictionaryTransition(JSGlobalData&, Structure*, DictionaryKind); |
| 363 | |
| 364 | PropertyOffset putSpecificValue(JSGlobalData&, PropertyName, unsigned attributes, JSCell* specificValue); |
| 365 | PropertyOffset remove(PropertyName); |
| 366 | |
akling@apple.com | 85b2682 | 2013-03-06 12:52:16 +0000 | [diff] [blame] | 367 | void createPropertyMap(JSGlobalData&, unsigned keyCount = 0); |
fpizlo@apple.com | 34cee20 | 2013-02-16 20:07:05 +0000 | [diff] [blame] | 368 | void checkConsistency(); |
| 369 | |
| 370 | bool despecifyFunction(JSGlobalData&, PropertyName); |
| 371 | void despecifyAllFunctions(JSGlobalData&); |
| 372 | |
akling@apple.com | 85b2682 | 2013-03-06 12:52:16 +0000 | [diff] [blame] | 373 | WriteBarrier<PropertyTable>& propertyTable(); |
| 374 | PropertyTable* takePropertyTableOrCloneIfPinned(JSGlobalData&, Structure* owner); |
| 375 | PropertyTable* copyPropertyTable(JSGlobalData&, Structure* owner); |
| 376 | PropertyTable* copyPropertyTableForPinning(JSGlobalData&, Structure* owner); |
fpizlo@apple.com | 34cee20 | 2013-02-16 20:07:05 +0000 | [diff] [blame] | 377 | JS_EXPORT_PRIVATE void materializePropertyMap(JSGlobalData&); |
| 378 | void materializePropertyMapIfNecessary(JSGlobalData& globalData) |
| 379 | { |
| 380 | ASSERT(structure()->classInfo() == &s_info); |
| 381 | ASSERT(checkOffsetConsistency()); |
akling@apple.com | 85b2682 | 2013-03-06 12:52:16 +0000 | [diff] [blame] | 382 | if (!propertyTable() && previousID()) |
fpizlo@apple.com | 34cee20 | 2013-02-16 20:07:05 +0000 | [diff] [blame] | 383 | materializePropertyMap(globalData); |
| 384 | } |
| 385 | void materializePropertyMapIfNecessaryForPinning(JSGlobalData& globalData) |
| 386 | { |
| 387 | ASSERT(structure()->classInfo() == &s_info); |
| 388 | checkOffsetConsistency(); |
akling@apple.com | 85b2682 | 2013-03-06 12:52:16 +0000 | [diff] [blame] | 389 | if (!propertyTable()) |
fpizlo@apple.com | 34cee20 | 2013-02-16 20:07:05 +0000 | [diff] [blame] | 390 | materializePropertyMap(globalData); |
| 391 | } |
| 392 | |
| 393 | void setPreviousID(JSGlobalData& globalData, Structure* transition, Structure* structure) |
| 394 | { |
| 395 | if (typeInfo().structureHasRareData()) |
| 396 | rareData()->setPreviousID(globalData, transition, structure); |
| 397 | else |
| 398 | m_previousOrRareData.set(globalData, transition, structure); |
| 399 | } |
| 400 | |
| 401 | void clearPreviousID() |
| 402 | { |
| 403 | if (typeInfo().structureHasRareData()) |
| 404 | rareData()->clearPreviousID(); |
| 405 | else |
| 406 | m_previousOrRareData.clear(); |
| 407 | } |
| 408 | |
| 409 | int transitionCount() const |
| 410 | { |
| 411 | // Since the number of transitions is always the same as m_offset, we keep the size of Structure down by not storing both. |
| 412 | return numberOfSlotsForLastOffset(m_offset, m_inlineCapacity); |
| 413 | } |
| 414 | |
| 415 | bool isValid(JSGlobalObject*, StructureChain* cachedPrototypeChain) const; |
| 416 | bool isValid(ExecState*, StructureChain* cachedPrototypeChain) const; |
| 417 | |
| 418 | void pin(); |
| 419 | |
| 420 | Structure* previous() const |
| 421 | { |
| 422 | ASSERT(!typeInfo().structureHasRareData()); |
| 423 | return static_cast<Structure*>(m_previousOrRareData.get()); |
| 424 | } |
| 425 | |
| 426 | StructureRareData* rareData() const |
| 427 | { |
| 428 | ASSERT(typeInfo().structureHasRareData()); |
| 429 | return static_cast<StructureRareData*>(m_previousOrRareData.get()); |
| 430 | } |
| 431 | |
akling@apple.com | 85b2682 | 2013-03-06 12:52:16 +0000 | [diff] [blame] | 432 | bool checkOffsetConsistency() const; |
fpizlo@apple.com | 34cee20 | 2013-02-16 20:07:05 +0000 | [diff] [blame] | 433 | |
| 434 | void allocateRareData(JSGlobalData&); |
| 435 | void cloneRareDataFrom(JSGlobalData&, const Structure*); |
| 436 | |
| 437 | static const int s_maxTransitionLength = 64; |
| 438 | |
| 439 | static const unsigned maxSpecificFunctionThrashCount = 3; |
fpizlo@apple.com | 34cee20 | 2013-02-16 20:07:05 +0000 | [diff] [blame] | 440 | |
| 441 | WriteBarrier<JSGlobalObject> m_globalObject; |
| 442 | WriteBarrier<Unknown> m_prototype; |
| 443 | mutable WriteBarrier<StructureChain> m_cachedPrototypeChain; |
| 444 | |
| 445 | WriteBarrier<JSCell> m_previousOrRareData; |
| 446 | |
| 447 | RefPtr<StringImpl> m_nameInPrevious; |
| 448 | WriteBarrier<JSCell> m_specificValueInPrevious; |
| 449 | |
| 450 | const ClassInfo* m_classInfo; |
| 451 | |
| 452 | StructureTransitionTable m_transitionTable; |
| 453 | |
akling@apple.com | 85b2682 | 2013-03-06 12:52:16 +0000 | [diff] [blame] | 454 | // Should be accessed through propertyTable(). During GC, it may be set to 0 by another thread. |
| 455 | WriteBarrier<PropertyTable> m_propertyTableUnsafe; |
fpizlo@apple.com | 34cee20 | 2013-02-16 20:07:05 +0000 | [diff] [blame] | 456 | |
| 457 | mutable InlineWatchpointSet m_transitionWatchpointSet; |
| 458 | |
fpizlo@apple.com | 34cee20 | 2013-02-16 20:07:05 +0000 | [diff] [blame] | 459 | COMPILE_ASSERT(firstOutOfLineOffset < 256, firstOutOfLineOffset_fits); |
| 460 | |
| 461 | // m_offset does not account for anonymous slots |
| 462 | PropertyOffset m_offset; |
| 463 | |
akling@apple.com | b76b00b | 2013-03-06 19:43:24 +0000 | [diff] [blame^] | 464 | TypeInfo m_typeInfo; |
| 465 | IndexingType m_indexingType; |
| 466 | |
| 467 | uint8_t m_inlineCapacity; |
fpizlo@apple.com | 34cee20 | 2013-02-16 20:07:05 +0000 | [diff] [blame] | 468 | unsigned m_dictionaryKind : 2; |
| 469 | bool m_isPinnedPropertyTable : 1; |
| 470 | bool m_hasGetterSetterProperties : 1; |
| 471 | bool m_hasReadOnlyOrGetterSetterPropertiesExcludingProto : 1; |
| 472 | bool m_hasNonEnumerableProperties : 1; |
akling@apple.com | b76b00b | 2013-03-06 19:43:24 +0000 | [diff] [blame^] | 473 | unsigned m_attributesInPrevious : 14; |
fpizlo@apple.com | 34cee20 | 2013-02-16 20:07:05 +0000 | [diff] [blame] | 474 | unsigned m_specificFunctionThrashCount : 2; |
| 475 | unsigned m_preventExtensions : 1; |
| 476 | unsigned m_didTransition : 1; |
| 477 | unsigned m_staticFunctionReified; |
| 478 | }; |
| 479 | |
cwzwarich@webkit.org | 3f782f6 | 2008-09-08 01:28:33 +0000 | [diff] [blame] | 480 | } // namespace JSC |
weinig@apple.com | 3412bb4 | 2008-09-01 21:22:54 +0000 | [diff] [blame] | 481 | |
darin@apple.com | a9778f9 | 2008-11-16 04:40:06 +0000 | [diff] [blame] | 482 | #endif // Structure_h |