2 * Copyright (C) 2013 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
26 #ifndef StructureInlines_h
27 #define StructureInlines_h
29 #include "PropertyMapHashTable.h"
30 #include "Structure.h"
34 inline Structure
* Structure::create(VM
& vm
, JSGlobalObject
* globalObject
, JSValue prototype
, const TypeInfo
& typeInfo
, const ClassInfo
* classInfo
, IndexingType indexingType
, unsigned inlineCapacity
)
36 ASSERT(vm
.structureStructure
);
38 Structure
* structure
= new (NotNull
, allocateCell
<Structure
>(vm
.heap
)) Structure(vm
, globalObject
, prototype
, typeInfo
, classInfo
, indexingType
, inlineCapacity
);
39 structure
->finishCreation(vm
);
43 inline Structure
* Structure::createStructure(VM
& vm
)
45 ASSERT(!vm
.structureStructure
);
46 Structure
* structure
= new (NotNull
, allocateCell
<Structure
>(vm
.heap
)) Structure(vm
);
47 structure
->finishCreation(vm
, CreatingEarlyCell
);
51 inline Structure
* Structure::create(VM
& vm
, const Structure
* structure
)
53 ASSERT(vm
.structureStructure
);
54 Structure
* newStructure
= new (NotNull
, allocateCell
<Structure
>(vm
.heap
)) Structure(vm
, structure
);
55 newStructure
->finishCreation(vm
);
59 inline PropertyOffset
Structure::get(VM
& vm
, PropertyName propertyName
)
61 ASSERT(structure()->classInfo() == &s_info
);
62 materializePropertyMapIfNecessary(vm
);
66 PropertyMapEntry
* entry
= propertyTable()->find(propertyName
.uid()).first
;
67 return entry
? entry
->offset
: invalidOffset
;
70 inline PropertyOffset
Structure::get(VM
& vm
, const WTF::String
& name
)
72 ASSERT(structure()->classInfo() == &s_info
);
73 materializePropertyMapIfNecessary(vm
);
77 PropertyMapEntry
* entry
= propertyTable()->findWithString(name
.impl()).first
;
78 return entry
? entry
->offset
: invalidOffset
;
81 inline bool Structure::masqueradesAsUndefined(JSGlobalObject
* lexicalGlobalObject
)
83 return typeInfo().masqueradesAsUndefined() && globalObject() == lexicalGlobalObject
;
86 ALWAYS_INLINE
void SlotVisitor::internalAppend(JSCell
* cell
)
88 ASSERT(!m_isCheckingForDefaultMarkViolation
);
91 #if ENABLE(GC_VALIDATION)
94 if (Heap::testAndSetMarked(cell
) || !cell
->structure())
99 MARK_LOG_CHILD(*this, cell
);
101 // Should never attempt to mark something that is zapped.
102 ASSERT(!cell
->isZapped());
104 m_stack
.append(cell
);
107 inline bool Structure::transitivelyTransitionedFrom(Structure
* structureToFind
)
109 for (Structure
* current
= this; current
; current
= current
->previousID()) {
110 if (current
== structureToFind
)
116 inline void Structure::setEnumerationCache(VM
& vm
, JSPropertyNameIterator
* enumerationCache
)
118 ASSERT(!isDictionary());
119 if (!typeInfo().structureHasRareData())
120 allocateRareData(vm
);
121 rareData()->setEnumerationCache(vm
, this, enumerationCache
);
124 inline JSPropertyNameIterator
* Structure::enumerationCache()
126 if (!typeInfo().structureHasRareData())
128 return rareData()->enumerationCache();
131 inline JSValue
Structure::prototypeForLookup(JSGlobalObject
* globalObject
) const
134 return m_prototype
.get();
136 ASSERT(typeInfo().type() == StringType
);
137 return globalObject
->stringPrototype();
140 inline JSValue
Structure::prototypeForLookup(ExecState
* exec
) const
142 return prototypeForLookup(exec
->lexicalGlobalObject());
145 inline StructureChain
* Structure::prototypeChain(VM
& vm
, JSGlobalObject
* globalObject
) const
147 // We cache our prototype chain so our clients can share it.
148 if (!isValid(globalObject
, m_cachedPrototypeChain
.get())) {
149 JSValue prototype
= prototypeForLookup(globalObject
);
150 m_cachedPrototypeChain
.set(vm
, this, StructureChain::create(vm
, prototype
.isNull() ? 0 : asObject(prototype
)->structure()));
152 return m_cachedPrototypeChain
.get();
155 inline StructureChain
* Structure::prototypeChain(ExecState
* exec
) const
157 return prototypeChain(exec
->vm(), exec
->lexicalGlobalObject());
160 inline bool Structure::isValid(JSGlobalObject
* globalObject
, StructureChain
* cachedPrototypeChain
) const
162 if (!cachedPrototypeChain
)
165 JSValue prototype
= prototypeForLookup(globalObject
);
166 WriteBarrier
<Structure
>* cachedStructure
= cachedPrototypeChain
->head();
167 while (*cachedStructure
&& !prototype
.isNull()) {
168 if (asObject(prototype
)->structure() != cachedStructure
->get())
171 prototype
= asObject(prototype
)->prototype();
173 return prototype
.isNull() && !*cachedStructure
;
176 inline bool Structure::isValid(ExecState
* exec
, StructureChain
* cachedPrototypeChain
) const
178 return isValid(exec
->lexicalGlobalObject(), cachedPrototypeChain
);
181 inline bool Structure::putWillGrowOutOfLineStorage()
183 checkOffsetConsistency();
185 ASSERT(outOfLineCapacity() >= outOfLineSize());
187 if (!propertyTable()) {
188 unsigned currentSize
= numberOfOutOfLineSlotsForLastOffset(m_offset
);
189 ASSERT(outOfLineCapacity() >= currentSize
);
190 return currentSize
== outOfLineCapacity();
193 ASSERT(totalStorageCapacity() >= propertyTable()->propertyStorageSize());
194 if (propertyTable()->hasDeletedOffset())
197 ASSERT(totalStorageCapacity() >= propertyTable()->size());
198 return propertyTable()->size() == totalStorageCapacity();
201 ALWAYS_INLINE WriteBarrier
<PropertyTable
>& Structure::propertyTable()
203 ASSERT(!globalObject() || !globalObject()->vm().heap
.isBusy());
204 return m_propertyTableUnsafe
;
207 ALWAYS_INLINE
bool Structure::checkOffsetConsistency() const
209 PropertyTable
* propertyTable
= m_propertyTableUnsafe
.get();
211 if (!propertyTable
) {
212 ASSERT(!m_isPinnedPropertyTable
);
216 RELEASE_ASSERT(numberOfSlotsForLastOffset(m_offset
, m_inlineCapacity
) == propertyTable
->propertyStorageSize());
217 unsigned totalSize
= propertyTable
->propertyStorageSize();
218 RELEASE_ASSERT((totalSize
< inlineCapacity() ? 0 : totalSize
- inlineCapacity()) == numberOfOutOfLineSlotsForLastOffset(m_offset
));
225 #endif // StructureInlines_h