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