/*
- * Copyright (C) 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2008, 2009, 2013, 2014 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
- * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
#include "config.h"
#include "Structure.h"
-#include "Identifier.h"
+#include "CodeBlock.h"
+#include "DumpContext.h"
+#include "JSCInlines.h"
#include "JSObject.h"
+#include "JSPropertyNameEnumerator.h"
+#include "Lookup.h"
+#include "PropertyMapHashTable.h"
#include "PropertyNameArray.h"
#include "StructureChain.h"
-#include "Lookup.h"
+#include "StructureRareDataInlines.h"
+#include "WeakGCMapInlines.h"
+#include <wtf/CommaPrinter.h>
+#include <wtf/ProcessID.h>
#include <wtf/RefCountedLeakCounter.h>
#include <wtf/RefPtr.h>
-
-#if ENABLE(JSC_MULTIPLE_THREADS)
#include <wtf/Threading.h>
-#endif
#define DUMP_STRUCTURE_ID_STATISTICS 0
namespace JSC {
-// Choose a number for the following so that most property maps are smaller,
-// but it's not going to blow out the stack to allocate this number of pointers.
-static const int smallMapThreshold = 1024;
+#if DUMP_STRUCTURE_ID_STATISTICS
+static HashSet<Structure*>& liveStructureSet = *(new HashSet<Structure*>);
+#endif
-// The point at which the function call overhead of the qsort implementation
-// becomes small compared to the inefficiency of insertion sort.
-static const unsigned tinyMapThreshold = 20;
+bool StructureTransitionTable::contains(UniquedStringImpl* rep, unsigned attributes) const
+{
+ if (isUsingSingleSlot()) {
+ Structure* transition = singleTransition();
+ return transition && transition->m_nameInPrevious == rep && transition->attributesInPrevious() == attributes;
+ }
+ return map()->get(std::make_pair(rep, attributes));
+}
-static const unsigned newTableSize = 16;
+Structure* StructureTransitionTable::get(UniquedStringImpl* rep, unsigned attributes) const
+{
+ if (isUsingSingleSlot()) {
+ Structure* transition = singleTransition();
+ return (transition && transition->m_nameInPrevious == rep && transition->attributesInPrevious() == attributes) ? transition : 0;
+ }
+ return map()->get(std::make_pair(rep, attributes));
+}
-#ifndef NDEBUG
-static WTF::RefCountedLeakCounter structureCounter("Structure");
+void StructureTransitionTable::add(VM& vm, Structure* structure)
+{
+ if (isUsingSingleSlot()) {
+ Structure* existingTransition = singleTransition();
-#if ENABLE(JSC_MULTIPLE_THREADS)
-static Mutex ignoreSetMutex;
-#endif
+ // This handles the first transition being added.
+ if (!existingTransition) {
+ setSingleTransition(vm, structure);
+ return;
+ }
-static bool shouldIgnoreLeaks;
-static HashSet<Structure*> ignoreSet;
-#endif
+ // This handles the second transition being added
+ // (or the first transition being despecified!)
+ setMap(new TransitionMap(vm));
+ add(vm, existingTransition);
+ }
-#if DUMP_STRUCTURE_ID_STATISTICS
-static HashSet<Structure*> liveStructureSet;
-#endif
+ // Add the structure to the map.
+
+ // Newer versions of the STL have an std::make_pair function that takes rvalue references.
+ // When either of the parameters are bitfields, the C++ compiler will try to bind them as lvalues, which is invalid. To work around this, use unary "+" to make the parameter an rvalue.
+ // See https://bugs.webkit.org/show_bug.cgi?id=59261 for more details
+ map()->set(std::make_pair(structure->m_nameInPrevious.get(), +structure->attributesInPrevious()), structure);
+}
void Structure::dumpStatistics()
{
HashSet<Structure*>::const_iterator end = liveStructureSet.end();
for (HashSet<Structure*>::const_iterator it = liveStructureSet.begin(); it != end; ++it) {
Structure* structure = *it;
- if (structure->m_usingSingleTransitionSlot) {
- if (!structure->m_transitions.singleTransition)
+
+ switch (structure->m_transitionTable.size()) {
+ case 0:
++numberLeaf;
- else
- ++numberUsingSingleSlot;
+ if (!structure->previousID())
+ ++numberSingletons;
+ break;
- if (!structure->m_previous && !structure->m_transitions.singleTransition)
- ++numberSingletons;
+ case 1:
+ ++numberUsingSingleSlot;
+ break;
}
- if (structure->m_propertyTable) {
+ if (structure->propertyTable()) {
++numberWithPropertyMaps;
- totalPropertyMapsSize += PropertyMapHashTable::allocationSize(structure->m_propertyTable->size);
- if (structure->m_propertyTable->deletedOffsets)
- totalPropertyMapsSize += (structure->m_propertyTable->deletedOffsets->capacity() * sizeof(unsigned));
+ totalPropertyMapsSize += structure->propertyTable()->sizeInMemory();
}
}
- printf("Number of live Structures: %d\n", liveStructureSet.size());
- printf("Number of Structures using the single item optimization for transition map: %d\n", numberUsingSingleSlot);
- printf("Number of Structures that are leaf nodes: %d\n", numberLeaf);
- printf("Number of Structures that singletons: %d\n", numberSingletons);
- printf("Number of Structures with PropertyMaps: %d\n", numberWithPropertyMaps);
+ dataLogF("Number of live Structures: %d\n", liveStructureSet.size());
+ dataLogF("Number of Structures using the single item optimization for transition map: %d\n", numberUsingSingleSlot);
+ dataLogF("Number of Structures that are leaf nodes: %d\n", numberLeaf);
+ dataLogF("Number of Structures that singletons: %d\n", numberSingletons);
+ dataLogF("Number of Structures with PropertyMaps: %d\n", numberWithPropertyMaps);
- printf("Size of a single Structures: %d\n", static_cast<unsigned>(sizeof(Structure)));
- printf("Size of sum of all property maps: %d\n", totalPropertyMapsSize);
- printf("Size of average of all property maps: %f\n", static_cast<double>(totalPropertyMapsSize) / static_cast<double>(liveStructureSet.size()));
+ dataLogF("Size of a single Structures: %d\n", static_cast<unsigned>(sizeof(Structure)));
+ dataLogF("Size of sum of all property maps: %d\n", totalPropertyMapsSize);
+ dataLogF("Size of average of all property maps: %f\n", static_cast<double>(totalPropertyMapsSize) / static_cast<double>(liveStructureSet.size()));
#else
- printf("Dumping Structure statistics is not enabled.\n");
+ dataLogF("Dumping Structure statistics is not enabled.\n");
#endif
}
-Structure::Structure(JSValuePtr prototype, const TypeInfo& typeInfo)
- : m_typeInfo(typeInfo)
- , m_prototype(prototype)
- , m_propertyTable(0)
- , m_propertyStorageCapacity(JSObject::inlineStorageCapacity)
- , m_offset(noOffset)
- , m_isDictionary(false)
- , m_isPinnedPropertyTable(false)
- , m_hasGetterSetterProperties(false)
- , m_usingSingleTransitionSlot(true)
- , m_attributesInPrevious(0)
+Structure::Structure(VM& vm, JSGlobalObject* globalObject, JSValue prototype, const TypeInfo& typeInfo, const ClassInfo* classInfo, IndexingType indexingType, unsigned inlineCapacity)
+ : JSCell(vm, vm.structureStructure.get())
+ , m_blob(vm.heap.structureIDTable().allocateID(this), indexingType, typeInfo)
+ , m_outOfLineTypeFlags(typeInfo.outOfLineTypeFlags())
+ , m_globalObject(vm, this, globalObject, WriteBarrier<JSGlobalObject>::MayBeNull)
+ , m_prototype(vm, this, prototype)
+ , m_classInfo(classInfo)
+ , m_transitionWatchpointSet(IsWatched)
+ , m_offset(invalidOffset)
+ , m_inlineCapacity(inlineCapacity)
+ , m_bitField(0)
{
- ASSERT(m_prototype);
- ASSERT(m_prototype.isObject() || m_prototype.isNull());
-
- m_transitions.singleTransition = 0;
-
-#ifndef NDEBUG
-#if ENABLE(JSC_MULTIPLE_THREADS)
- MutexLocker protect(ignoreSetMutex);
-#endif
- if (shouldIgnoreLeaks)
- ignoreSet.add(this);
- else
- structureCounter.increment();
-#endif
-
-#if DUMP_STRUCTURE_ID_STATISTICS
- liveStructureSet.add(this);
-#endif
+ setDictionaryKind(NoneDictionaryKind);
+ setIsPinnedPropertyTable(false);
+ setHasGetterSetterProperties(classInfo->hasStaticSetterOrReadonlyProperties());
+ setHasCustomGetterSetterProperties(false);
+ setHasReadOnlyOrGetterSetterPropertiesExcludingProto(classInfo->hasStaticSetterOrReadonlyProperties());
+ setHasNonEnumerableProperties(false);
+ setAttributesInPrevious(0);
+ setPreventExtensions(false);
+ setDidTransition(false);
+ setStaticFunctionsReified(false);
+ setHasRareData(false);
+
+ ASSERT(inlineCapacity <= JSFinalObject::maxInlineCapacity());
+ ASSERT(static_cast<PropertyOffset>(inlineCapacity) < firstOutOfLineOffset);
+ ASSERT(!hasRareData());
+ ASSERT(hasReadOnlyOrGetterSetterPropertiesExcludingProto() || !m_classInfo->hasStaticSetterOrReadonlyProperties());
+ ASSERT(hasGetterSetterProperties() || !m_classInfo->hasStaticSetterOrReadonlyProperties());
}
-Structure::~Structure()
-{
- if (m_previous) {
- if (m_previous->m_usingSingleTransitionSlot) {
- m_previous->m_transitions.singleTransition = 0;
- } else {
- ASSERT(m_previous->m_transitions.table->contains(make_pair(m_nameInPrevious.get(), m_attributesInPrevious)));
- m_previous->m_transitions.table->remove(make_pair(m_nameInPrevious.get(), m_attributesInPrevious));
- }
- }
-
- if (m_cachedPropertyNameArrayData)
- m_cachedPropertyNameArrayData->setCachedStructure(0);
-
- if (!m_usingSingleTransitionSlot)
- delete m_transitions.table;
-
- if (m_propertyTable) {
- unsigned entryCount = m_propertyTable->keyCount + m_propertyTable->deletedSentinelCount;
- for (unsigned i = 1; i <= entryCount; i++) {
- if (UString::Rep* key = m_propertyTable->entries()[i].key)
- key->deref();
- }
-
- delete m_propertyTable->deletedOffsets;
- fastFree(m_propertyTable);
- }
-
-#ifndef NDEBUG
-#if ENABLE(JSC_MULTIPLE_THREADS)
- MutexLocker protect(ignoreSetMutex);
-#endif
- HashSet<Structure*>::iterator it = ignoreSet.find(this);
- if (it != ignoreSet.end())
- ignoreSet.remove(it);
- else
- structureCounter.decrement();
-#endif
-
-#if DUMP_STRUCTURE_ID_STATISTICS
- liveStructureSet.remove(this);
-#endif
-}
+const ClassInfo Structure::s_info = { "Structure", 0, 0, CREATE_METHOD_TABLE(Structure) };
-void Structure::startIgnoringLeaks()
+Structure::Structure(VM& vm)
+ : JSCell(CreatingEarlyCell)
+ , m_prototype(vm, this, jsNull())
+ , m_classInfo(info())
+ , m_transitionWatchpointSet(IsWatched)
+ , m_offset(invalidOffset)
+ , m_inlineCapacity(0)
+ , m_bitField(0)
{
-#ifndef NDEBUG
- shouldIgnoreLeaks = true;
-#endif
+ setDictionaryKind(NoneDictionaryKind);
+ setIsPinnedPropertyTable(false);
+ setHasGetterSetterProperties(m_classInfo->hasStaticSetterOrReadonlyProperties());
+ setHasCustomGetterSetterProperties(false);
+ setHasReadOnlyOrGetterSetterPropertiesExcludingProto(m_classInfo->hasStaticSetterOrReadonlyProperties());
+ setHasNonEnumerableProperties(false);
+ setAttributesInPrevious(0);
+ setPreventExtensions(false);
+ setDidTransition(false);
+ setStaticFunctionsReified(false);
+ setHasRareData(false);
+
+ TypeInfo typeInfo = TypeInfo(CellType, StructureFlags);
+ m_blob = StructureIDBlob(vm.heap.structureIDTable().allocateID(this), 0, typeInfo);
+ m_outOfLineTypeFlags = typeInfo.outOfLineTypeFlags();
+
+ ASSERT(hasReadOnlyOrGetterSetterPropertiesExcludingProto() || !m_classInfo->hasStaticSetterOrReadonlyProperties());
+ ASSERT(hasGetterSetterProperties() || !m_classInfo->hasStaticSetterOrReadonlyProperties());
}
-void Structure::stopIgnoringLeaks()
+Structure::Structure(VM& vm, Structure* previous)
+ : JSCell(vm, vm.structureStructure.get())
+ , m_prototype(vm, this, previous->storedPrototype())
+ , m_classInfo(previous->m_classInfo)
+ , m_transitionWatchpointSet(IsWatched)
+ , m_offset(invalidOffset)
+ , m_inlineCapacity(previous->m_inlineCapacity)
+ , m_bitField(0)
{
-#ifndef NDEBUG
- shouldIgnoreLeaks = false;
-#endif
+ setDictionaryKind(previous->dictionaryKind());
+ setIsPinnedPropertyTable(previous->hasBeenFlattenedBefore());
+ setHasGetterSetterProperties(previous->hasGetterSetterProperties());
+ setHasCustomGetterSetterProperties(previous->hasCustomGetterSetterProperties());
+ setHasReadOnlyOrGetterSetterPropertiesExcludingProto(previous->hasReadOnlyOrGetterSetterPropertiesExcludingProto());
+ setHasNonEnumerableProperties(previous->hasNonEnumerableProperties());
+ setAttributesInPrevious(0);
+ setPreventExtensions(previous->preventExtensions());
+ setDidTransition(true);
+ setStaticFunctionsReified(previous->staticFunctionsReified());
+ setHasRareData(false);
+
+ TypeInfo typeInfo = previous->typeInfo();
+ m_blob = StructureIDBlob(vm.heap.structureIDTable().allocateID(this), previous->indexingTypeIncludingHistory(), typeInfo);
+ m_outOfLineTypeFlags = typeInfo.outOfLineTypeFlags();
+
+ ASSERT(!previous->typeInfo().structureIsImmortal());
+ setPreviousID(vm, previous);
+
+ previous->didTransitionFromThisStructure();
+ if (previous->m_globalObject)
+ m_globalObject.set(vm, this, previous->m_globalObject.get());
+ ASSERT(hasReadOnlyOrGetterSetterPropertiesExcludingProto() || !m_classInfo->hasStaticSetterOrReadonlyProperties());
+ ASSERT(hasGetterSetterProperties() || !m_classInfo->hasStaticSetterOrReadonlyProperties());
}
-static bool isPowerOf2(unsigned v)
+Structure::~Structure()
{
- // Taken from http://www.cs.utk.edu/~vose/c-stuff/bithacks.html
-
- return !(v & (v - 1)) && v;
+ if (typeInfo().structureIsImmortal())
+ return;
+ Heap::heap(this)->structureIDTable().deallocateID(this, m_blob.structureID());
}
-static unsigned nextPowerOf2(unsigned v)
+void Structure::destroy(JSCell* cell)
{
- // Taken from http://www.cs.utk.edu/~vose/c-stuff/bithacks.html
- // Devised by Sean Anderson, Sepember 14, 2001
-
- v--;
- v |= v >> 1;
- v |= v >> 2;
- v |= v >> 4;
- v |= v >> 8;
- v |= v >> 16;
- v++;
-
- return v;
+ static_cast<Structure*>(cell)->Structure::~Structure();
}
-static unsigned sizeForKeyCount(size_t keyCount)
+void Structure::findStructuresAndMapForMaterialization(Vector<Structure*, 8>& structures, Structure*& structure, PropertyTable*& table)
{
- if (keyCount == notFound)
- return newTableSize;
-
- if (keyCount < 8)
- return newTableSize;
-
- if (isPowerOf2(keyCount))
- return keyCount * 4;
-
- return nextPowerOf2(keyCount) * 2;
+ ASSERT(structures.isEmpty());
+ table = 0;
+
+ for (structure = this; structure; structure = structure->previousID()) {
+ structure->m_lock.lock();
+
+ table = structure->propertyTable().get();
+ if (table) {
+ // Leave the structure locked, so that the caller can do things to it atomically
+ // before it loses its property table.
+ return;
+ }
+
+ structures.append(structure);
+ structure->m_lock.unlock();
+ }
+
+ ASSERT(!structure);
+ ASSERT(!table);
}
-void Structure::materializePropertyMap()
+void Structure::materializePropertyMap(VM& vm)
{
- ASSERT(!m_propertyTable);
+ ASSERT(structure()->classInfo() == info());
+ ASSERT(!propertyTable());
Vector<Structure*, 8> structures;
- structures.append(this);
-
- Structure* structure = this;
-
- // Search for the last Structure with a property table.
- while ((structure = structure->previousID())) {
- if (structure->m_isPinnedPropertyTable) {
- ASSERT(structure->m_propertyTable);
- ASSERT(!structure->m_previous);
-
- m_propertyTable = structure->copyPropertyTable();
- break;
- }
-
- structures.append(structure);
- }
-
- if (!m_propertyTable)
- createPropertyMapHashTable(sizeForKeyCount(m_offset + 1));
- else {
- if (sizeForKeyCount(m_offset + 1) > m_propertyTable->size)
- rehashPropertyMapHashTable(sizeForKeyCount(m_offset + 1)); // This could be made more efficient by combining with the copy above.
+ Structure* structure;
+ PropertyTable* table;
+
+ findStructuresAndMapForMaterialization(structures, structure, table);
+
+ if (table) {
+ table = table->copy(vm, numberOfSlotsForLastOffset(m_offset, m_inlineCapacity));
+ structure->m_lock.unlock();
}
+
+ // Must hold the lock on this structure, since we will be modifying this structure's
+ // property map. We don't want getConcurrently() to see the property map in a half-baked
+ // state.
+ GCSafeConcurrentJITLocker locker(m_lock, vm.heap);
+ if (!table)
+ createPropertyMap(locker, vm, numberOfSlotsForLastOffset(m_offset, m_inlineCapacity));
+ else
+ propertyTable().set(vm, this, table);
- for (ptrdiff_t i = structures.size() - 2; i >= 0; --i) {
+ for (size_t i = structures.size(); i--;) {
structure = structures[i];
- structure->m_nameInPrevious->ref();
- PropertyMapEntry entry(structure->m_nameInPrevious.get(), structure->m_offset, structure->m_attributesInPrevious, ++m_propertyTable->lastIndexUsed);
- insertIntoPropertyMapHashTable(entry);
+ if (!structure->m_nameInPrevious)
+ continue;
+ PropertyMapEntry entry(structure->m_nameInPrevious.get(), structure->m_offset, structure->attributesInPrevious());
+ propertyTable()->add(entry, m_offset, PropertyTable::PropertyOffsetMustNotChange);
}
+
+ checkOffsetConsistency();
}
-void Structure::getEnumerablePropertyNames(ExecState* exec, PropertyNameArray& propertyNames, JSObject* baseObject)
+Structure* Structure::addPropertyTransitionToExistingStructureImpl(Structure* structure, UniquedStringImpl* uid, unsigned attributes, PropertyOffset& offset)
{
- bool shouldCache = propertyNames.shouldCache() && !(propertyNames.size() || m_isDictionary);
-
- if (shouldCache && m_cachedPropertyNameArrayData) {
- if (m_cachedPropertyNameArrayData->cachedPrototypeChain() == prototypeChain(exec)) {
- propertyNames.setData(m_cachedPropertyNameArrayData);
- return;
- }
- clearEnumerationCache();
- }
-
- getEnumerableNamesFromPropertyTable(propertyNames);
- getEnumerableNamesFromClassInfoTable(exec, baseObject->classInfo(), propertyNames);
+ ASSERT(!structure->isDictionary());
+ ASSERT(structure->isObject());
- if (m_prototype.isObject()) {
- propertyNames.setShouldCache(false); // No need for our prototypes to waste memory on caching, since they're not being enumerated directly.
- asObject(m_prototype)->getPropertyNames(exec, propertyNames);
+ if (Structure* existingTransition = structure->m_transitionTable.get(uid, attributes)) {
+ validateOffset(existingTransition->m_offset, existingTransition->inlineCapacity());
+ offset = existingTransition->m_offset;
+ return existingTransition;
}
- if (shouldCache) {
- m_cachedPropertyNameArrayData = propertyNames.data();
- m_cachedPropertyNameArrayData->setCachedPrototypeChain(prototypeChain(exec));
- m_cachedPropertyNameArrayData->setCachedStructure(this);
- }
+ return 0;
}
-void Structure::clearEnumerationCache()
+Structure* Structure::addPropertyTransitionToExistingStructure(Structure* structure, PropertyName propertyName, unsigned attributes, PropertyOffset& offset)
{
- if (m_cachedPropertyNameArrayData)
- m_cachedPropertyNameArrayData->setCachedStructure(0);
- m_cachedPropertyNameArrayData.clear();
+ ASSERT(!isCompilationThread());
+ return addPropertyTransitionToExistingStructureImpl(structure, propertyName.uid(), attributes, offset);
}
-void Structure::growPropertyStorageCapacity()
+Structure* Structure::addPropertyTransitionToExistingStructureConcurrently(Structure* structure, UniquedStringImpl* uid, unsigned attributes, PropertyOffset& offset)
{
- if (m_propertyStorageCapacity == JSObject::inlineStorageCapacity)
- m_propertyStorageCapacity = JSObject::nonInlineBaseStorageCapacity;
- else
- m_propertyStorageCapacity *= 2;
+ ConcurrentJITLocker locker(structure->m_lock);
+ return addPropertyTransitionToExistingStructureImpl(structure, uid, attributes, offset);
}
-PassRefPtr<Structure> Structure::addPropertyTransitionToExistingStructure(Structure* structure, const Identifier& propertyName, unsigned attributes, size_t& offset)
+bool Structure::anyObjectInChainMayInterceptIndexedAccesses() const
{
- ASSERT(!structure->m_isDictionary);
- ASSERT(structure->typeInfo().type() == ObjectType);
+ for (const Structure* current = this; ;) {
+ if (current->mayInterceptIndexedAccesses())
+ return true;
+
+ JSValue prototype = current->storedPrototype();
+ if (prototype.isNull())
+ return false;
+
+ current = asObject(prototype)->structure();
+ }
+}
- if (structure->m_usingSingleTransitionSlot) {
- Structure* existingTransition = structure->m_transitions.singleTransition;
- if (existingTransition && existingTransition->m_nameInPrevious.get() == propertyName.ustring().rep() && existingTransition->m_attributesInPrevious == attributes) {
- ASSERT(structure->m_transitions.singleTransition->m_offset != noOffset);
- offset = structure->m_transitions.singleTransition->m_offset;
- return existingTransition;
- }
- } else {
- if (Structure* existingTransition = structure->m_transitions.table->get(make_pair(propertyName.ustring().rep(), attributes))) {
- ASSERT(existingTransition->m_offset != noOffset);
- offset = existingTransition->m_offset;
- return existingTransition;
- }
+bool Structure::holesMustForwardToPrototype(VM& vm) const
+{
+ if (this->mayInterceptIndexedAccesses())
+ return true;
+
+ JSValue prototype = this->storedPrototype();
+ if (!prototype.isObject())
+ return false;
+ JSObject* object = asObject(prototype);
+
+ while (true) {
+ Structure& structure = *object->structure(vm);
+ if (hasIndexedProperties(object->indexingType()) || structure.mayInterceptIndexedAccesses())
+ return true;
+ prototype = structure.storedPrototype();
+ if (!prototype.isObject())
+ return false;
+ object = asObject(prototype);
}
- return 0;
+ RELEASE_ASSERT_NOT_REACHED();
+ return false;
}
-PassRefPtr<Structure> Structure::addPropertyTransition(Structure* structure, const Identifier& propertyName, unsigned attributes, size_t& offset)
+bool Structure::needsSlowPutIndexing() const
{
- ASSERT(!structure->m_isDictionary);
- ASSERT(structure->typeInfo().type() == ObjectType);
- ASSERT(!Structure::addPropertyTransitionToExistingStructure(structure, propertyName, attributes, offset));
+ return anyObjectInChainMayInterceptIndexedAccesses()
+ || globalObject()->isHavingABadTime();
+}
- if (structure->transitionCount() > s_maxTransitionLength) {
- RefPtr<Structure> transition = toDictionaryTransition(structure);
- offset = transition->put(propertyName, attributes);
- if (transition->propertyStorageSize() > transition->propertyStorageCapacity())
- transition->growPropertyStorageCapacity();
- return transition.release();
- }
+NonPropertyTransition Structure::suggestedArrayStorageTransition() const
+{
+ if (needsSlowPutIndexing())
+ return AllocateSlowPutArrayStorage;
+
+ return AllocateArrayStorage;
+}
- RefPtr<Structure> transition = create(structure->m_prototype, structure->typeInfo());
- transition->m_cachedPrototypeChain = structure->m_cachedPrototypeChain;
- transition->m_previous = structure;
- transition->m_nameInPrevious = propertyName.ustring().rep();
- transition->m_attributesInPrevious = attributes;
- transition->m_propertyStorageCapacity = structure->m_propertyStorageCapacity;
- transition->m_hasGetterSetterProperties = structure->m_hasGetterSetterProperties;
-
- if (structure->m_propertyTable) {
- if (structure->m_isPinnedPropertyTable)
- transition->m_propertyTable = structure->copyPropertyTable();
- else {
- transition->m_propertyTable = structure->m_propertyTable;
- structure->m_propertyTable = 0;
- }
- } else {
- if (structure->m_previous)
- transition->materializePropertyMap();
- else
- transition->createPropertyMapHashTable();
+Structure* Structure::addPropertyTransition(VM& vm, Structure* structure, PropertyName propertyName, unsigned attributes, PropertyOffset& offset, PutPropertySlot::Context context)
+{
+ ASSERT(!structure->isDictionary());
+ ASSERT(structure->isObject());
+ ASSERT(!Structure::addPropertyTransitionToExistingStructure(structure, propertyName, attributes, offset));
+
+ int maxTransitionLength;
+ if (context == PutPropertySlot::PutById)
+ maxTransitionLength = s_maxTransitionLengthForNonEvalPutById;
+ else
+ maxTransitionLength = s_maxTransitionLength;
+ if (structure->transitionCount() > maxTransitionLength) {
+ Structure* transition = toCacheableDictionaryTransition(vm, structure);
+ ASSERT(structure != transition);
+ offset = transition->add(vm, propertyName, attributes);
+ return transition;
}
+
+ Structure* transition = create(vm, structure);
- offset = transition->put(propertyName, attributes);
- if (transition->propertyStorageSize() > transition->propertyStorageCapacity())
- transition->growPropertyStorageCapacity();
-
- transition->m_offset = offset;
+ transition->m_cachedPrototypeChain.setMayBeNull(vm, transition, structure->m_cachedPrototypeChain.get());
+ transition->m_nameInPrevious = propertyName.uid();
+ transition->setAttributesInPrevious(attributes);
+ transition->propertyTable().set(vm, transition, structure->takePropertyTableOrCloneIfPinned(vm));
+ transition->m_offset = structure->m_offset;
- if (structure->m_usingSingleTransitionSlot) {
- if (!structure->m_transitions.singleTransition) {
- structure->m_transitions.singleTransition = transition.get();
- return transition.release();
- }
+ offset = transition->add(vm, propertyName, attributes);
- Structure* existingTransition = structure->m_transitions.singleTransition;
- structure->m_usingSingleTransitionSlot = false;
- StructureTransitionTable* transitionTable = new StructureTransitionTable;
- structure->m_transitions.table = transitionTable;
- transitionTable->add(make_pair(existingTransition->m_nameInPrevious.get(), existingTransition->m_attributesInPrevious), existingTransition);
+ checkOffset(transition->m_offset, transition->inlineCapacity());
+ {
+ ConcurrentJITLocker locker(structure->m_lock);
+ structure->m_transitionTable.add(vm, transition);
}
- structure->m_transitions.table->add(make_pair(propertyName.ustring().rep(), attributes), transition.get());
- return transition.release();
+ transition->checkOffsetConsistency();
+ structure->checkOffsetConsistency();
+ return transition;
}
-PassRefPtr<Structure> Structure::removePropertyTransition(Structure* structure, const Identifier& propertyName, size_t& offset)
+Structure* Structure::removePropertyTransition(VM& vm, Structure* structure, PropertyName propertyName, PropertyOffset& offset)
{
- ASSERT(!structure->m_isDictionary);
+ ASSERT(!structure->isUncacheableDictionary());
- RefPtr<Structure> transition = toDictionaryTransition(structure);
+ Structure* transition = toUncacheableDictionaryTransition(vm, structure);
offset = transition->remove(propertyName);
- return transition.release();
+ transition->checkOffsetConsistency();
+ return transition;
}
-PassRefPtr<Structure> Structure::changePrototypeTransition(Structure* structure, JSValuePtr prototype)
+Structure* Structure::changePrototypeTransition(VM& vm, Structure* structure, JSValue prototype)
{
- RefPtr<Structure> transition = create(prototype, structure->typeInfo());
-
- transition->m_propertyStorageCapacity = structure->m_propertyStorageCapacity;
- transition->m_hasGetterSetterProperties = structure->m_hasGetterSetterProperties;
+ Structure* transition = create(vm, structure);
- // Don't set m_offset, as one can not transition to this.
+ transition->m_prototype.set(vm, transition, prototype);
- structure->materializePropertyMapIfNecessary();
- transition->m_propertyTable = structure->copyPropertyTable();
- transition->m_isPinnedPropertyTable = true;
+ DeferGC deferGC(vm.heap);
+ structure->materializePropertyMapIfNecessary(vm, deferGC);
+ transition->propertyTable().set(vm, transition, structure->copyPropertyTableForPinning(vm));
+ transition->m_offset = structure->m_offset;
+ transition->pin();
- return transition.release();
+ transition->checkOffsetConsistency();
+ return transition;
}
-PassRefPtr<Structure> Structure::getterSetterTransition(Structure* structure)
+Structure* Structure::attributeChangeTransition(VM& vm, Structure* structure, PropertyName propertyName, unsigned attributes)
{
- RefPtr<Structure> transition = create(structure->storedPrototype(), structure->typeInfo());
- transition->m_propertyStorageCapacity = structure->m_propertyStorageCapacity;
- transition->m_hasGetterSetterProperties = transition->m_hasGetterSetterProperties;
-
- // Don't set m_offset, as one can not transition to this.
+ DeferGC deferGC(vm.heap);
+ if (!structure->isUncacheableDictionary()) {
+ Structure* transition = create(vm, structure);
+
+ structure->materializePropertyMapIfNecessary(vm, deferGC);
+ transition->propertyTable().set(vm, transition, structure->copyPropertyTableForPinning(vm));
+ transition->m_offset = structure->m_offset;
+ transition->pin();
+
+ structure = transition;
+ }
- structure->materializePropertyMapIfNecessary();
- transition->m_propertyTable = structure->copyPropertyTable();
- transition->m_isPinnedPropertyTable = true;
+ ASSERT(structure->propertyTable());
+ PropertyMapEntry* entry = structure->propertyTable()->get(propertyName.uid());
+ ASSERT(entry);
+ entry->attributes = attributes;
- return transition.release();
+ structure->checkOffsetConsistency();
+ return structure;
}
-PassRefPtr<Structure> Structure::toDictionaryTransition(Structure* structure)
+Structure* Structure::toDictionaryTransition(VM& vm, Structure* structure, DictionaryKind kind)
{
- ASSERT(!structure->m_isDictionary);
-
- RefPtr<Structure> transition = create(structure->m_prototype, structure->typeInfo());
- transition->m_isDictionary = true;
- transition->m_propertyStorageCapacity = structure->m_propertyStorageCapacity;
- transition->m_hasGetterSetterProperties = structure->m_hasGetterSetterProperties;
+ ASSERT(!structure->isUncacheableDictionary());
+
+ Structure* transition = create(vm, structure);
- structure->materializePropertyMapIfNecessary();
- transition->m_propertyTable = structure->copyPropertyTable();
- transition->m_isPinnedPropertyTable = true;
+ DeferGC deferGC(vm.heap);
+ structure->materializePropertyMapIfNecessary(vm, deferGC);
+ transition->propertyTable().set(vm, transition, structure->copyPropertyTableForPinning(vm));
+ transition->m_offset = structure->m_offset;
+ transition->setDictionaryKind(kind);
+ transition->pin();
- return transition.release();
+ transition->checkOffsetConsistency();
+ return transition;
}
-PassRefPtr<Structure> Structure::fromDictionaryTransition(Structure* structure)
+Structure* Structure::toCacheableDictionaryTransition(VM& vm, Structure* structure)
{
- ASSERT(structure->m_isDictionary);
-
- // Since dictionary Structures are not shared, and no opcodes specialize
- // for them, we don't need to allocate a new Structure when transitioning
- // to non-dictionary status.
-
- // FIMXE: We can make this more efficient by canonicalizing the Structure (draining the
- // deleted offsets vector) before transitioning from dictionary.
- if (!structure->m_propertyTable || !structure->m_propertyTable->deletedOffsets || structure->m_propertyTable->deletedOffsets->isEmpty())
- structure->m_isDictionary = false;
+ return toDictionaryTransition(vm, structure, CachedDictionaryKind);
+}
- return structure;
+Structure* Structure::toUncacheableDictionaryTransition(VM& vm, Structure* structure)
+{
+ return toDictionaryTransition(vm, structure, UncachedDictionaryKind);
}
-size_t Structure::addPropertyWithoutTransition(const Identifier& propertyName, unsigned attributes)
+// In future we may want to cache this transition.
+Structure* Structure::sealTransition(VM& vm, Structure* structure)
{
- ASSERT(!m_transitions.singleTransition);
+ Structure* transition = preventExtensionsTransition(vm, structure);
- materializePropertyMapIfNecessary();
+ if (transition->propertyTable()) {
+ PropertyTable::iterator end = transition->propertyTable()->end();
+ for (PropertyTable::iterator iter = transition->propertyTable()->begin(); iter != end; ++iter)
+ iter->attributes |= DontDelete;
+ }
- m_isPinnedPropertyTable = true;
- size_t offset = put(propertyName, attributes);
- if (propertyStorageSize() > propertyStorageCapacity())
- growPropertyStorageCapacity();
- clearEnumerationCache();
- return offset;
+ transition->checkOffsetConsistency();
+ return transition;
}
-size_t Structure::removePropertyWithoutTransition(const Identifier& propertyName)
+// In future we may want to cache this transition.
+Structure* Structure::freezeTransition(VM& vm, Structure* structure)
{
- ASSERT(!m_transitions.singleTransition);
- ASSERT(m_isDictionary);
-
- materializePropertyMapIfNecessary();
+ Structure* transition = preventExtensionsTransition(vm, structure);
+
+ if (transition->propertyTable()) {
+ PropertyTable::iterator iter = transition->propertyTable()->begin();
+ PropertyTable::iterator end = transition->propertyTable()->end();
+ if (iter != end)
+ transition->setHasReadOnlyOrGetterSetterPropertiesExcludingProto(true);
+ for (; iter != end; ++iter)
+ iter->attributes |= iter->attributes & Accessor ? DontDelete : (DontDelete | ReadOnly);
+ }
- m_isPinnedPropertyTable = true;
- size_t offset = remove(propertyName);
- clearEnumerationCache();
- return offset;
+ ASSERT(transition->hasReadOnlyOrGetterSetterPropertiesExcludingProto() || !transition->classInfo()->hasStaticSetterOrReadonlyProperties());
+ ASSERT(transition->hasGetterSetterProperties() || !transition->classInfo()->hasStaticSetterOrReadonlyProperties());
+ transition->checkOffsetConsistency();
+ return transition;
}
-#if DUMP_PROPERTYMAP_STATS
+// In future we may want to cache this transition.
+Structure* Structure::preventExtensionsTransition(VM& vm, Structure* structure)
+{
+ Structure* transition = create(vm, structure);
-static int numProbes;
-static int numCollisions;
-static int numRehashes;
-static int numRemoves;
+ // Don't set m_offset, as one can not transition to this.
-struct PropertyMapStatisticsExitLogger {
- ~PropertyMapStatisticsExitLogger();
-};
+ DeferGC deferGC(vm.heap);
+ structure->materializePropertyMapIfNecessary(vm, deferGC);
+ transition->propertyTable().set(vm, transition, structure->copyPropertyTableForPinning(vm));
+ transition->m_offset = structure->m_offset;
+ transition->setPreventExtensions(true);
+ transition->pin();
-static PropertyMapStatisticsExitLogger logger;
+ transition->checkOffsetConsistency();
+ return transition;
+}
-PropertyMapStatisticsExitLogger::~PropertyMapStatisticsExitLogger()
+PropertyTable* Structure::takePropertyTableOrCloneIfPinned(VM& vm)
{
- printf("\nJSC::PropertyMap statistics\n\n");
- printf("%d probes\n", numProbes);
- printf("%d collisions (%.1f%%)\n", numCollisions, 100.0 * numCollisions / numProbes);
- printf("%d rehashes\n", numRehashes);
- printf("%d removes\n", numRemoves);
+ DeferGC deferGC(vm.heap);
+ materializePropertyMapIfNecessaryForPinning(vm, deferGC);
+
+ if (isPinnedPropertyTable())
+ return propertyTable()->copy(vm, propertyTable()->size() + 1);
+
+ // Hold the lock while stealing the table - so that getConcurrently() on another thread
+ // will either have to bypass this structure, or will get to use the property table
+ // before it is stolen.
+ ConcurrentJITLocker locker(m_lock);
+ PropertyTable* takenPropertyTable = propertyTable().get();
+ propertyTable().clear();
+ return takenPropertyTable;
}
-#endif
-
-static const unsigned deletedSentinelIndex = 1;
-
-#if !DO_PROPERTYMAP_CONSTENCY_CHECK
-
-inline void Structure::checkConsistency()
+Structure* Structure::nonPropertyTransition(VM& vm, Structure* structure, NonPropertyTransition transitionKind)
{
+ unsigned attributes = toAttributes(transitionKind);
+ IndexingType indexingType = newIndexingType(structure->indexingTypeIncludingHistory(), transitionKind);
+
+ if (JSGlobalObject* globalObject = structure->m_globalObject.get()) {
+ if (globalObject->isOriginalArrayStructure(structure)) {
+ Structure* result = globalObject->originalArrayStructureForIndexingType(indexingType);
+ if (result->indexingTypeIncludingHistory() == indexingType) {
+ structure->didTransitionFromThisStructure();
+ return result;
+ }
+ }
+ }
+
+ Structure* existingTransition;
+ if (!structure->isDictionary() && (existingTransition = structure->m_transitionTable.get(0, attributes))) {
+ ASSERT(existingTransition->attributesInPrevious() == attributes);
+ ASSERT(existingTransition->indexingTypeIncludingHistory() == indexingType);
+ return existingTransition;
+ }
+
+ Structure* transition = create(vm, structure);
+ transition->setAttributesInPrevious(attributes);
+ transition->m_blob.setIndexingType(indexingType);
+ transition->propertyTable().set(vm, transition, structure->takePropertyTableOrCloneIfPinned(vm));
+ transition->m_offset = structure->m_offset;
+ checkOffset(transition->m_offset, transition->inlineCapacity());
+
+ if (structure->isDictionary())
+ transition->pin();
+ else {
+ ConcurrentJITLocker locker(structure->m_lock);
+ structure->m_transitionTable.add(vm, transition);
+ }
+ transition->checkOffsetConsistency();
+ return transition;
}
-#endif
-
-PropertyMapHashTable* Structure::copyPropertyTable()
+// In future we may want to cache this property.
+bool Structure::isSealed(VM& vm)
{
- if (!m_propertyTable)
- return 0;
-
- size_t tableSize = PropertyMapHashTable::allocationSize(m_propertyTable->size);
- PropertyMapHashTable* newTable = static_cast<PropertyMapHashTable*>(fastMalloc(tableSize));
- memcpy(newTable, m_propertyTable, tableSize);
-
- unsigned entryCount = m_propertyTable->keyCount + m_propertyTable->deletedSentinelCount;
- for (unsigned i = 1; i <= entryCount; ++i) {
- if (UString::Rep* key = newTable->entries()[i].key)
- key->ref();
+ if (isExtensible())
+ return false;
+
+ DeferGC deferGC(vm.heap);
+ materializePropertyMapIfNecessary(vm, deferGC);
+ if (!propertyTable())
+ return true;
+
+ PropertyTable::iterator end = propertyTable()->end();
+ for (PropertyTable::iterator iter = propertyTable()->begin(); iter != end; ++iter) {
+ if ((iter->attributes & DontDelete) != DontDelete)
+ return false;
}
+ return true;
+}
- // Copy the deletedOffsets vector.
- if (m_propertyTable->deletedOffsets)
- newTable->deletedOffsets = new Vector<unsigned>(*m_propertyTable->deletedOffsets);
-
- return newTable;
+// In future we may want to cache this property.
+bool Structure::isFrozen(VM& vm)
+{
+ if (isExtensible())
+ return false;
+
+ DeferGC deferGC(vm.heap);
+ materializePropertyMapIfNecessary(vm, deferGC);
+ if (!propertyTable())
+ return true;
+
+ PropertyTable::iterator end = propertyTable()->end();
+ for (PropertyTable::iterator iter = propertyTable()->begin(); iter != end; ++iter) {
+ if (!(iter->attributes & DontDelete))
+ return false;
+ if (!(iter->attributes & (ReadOnly | Accessor)))
+ return false;
+ }
+ return true;
}
-size_t Structure::get(const Identifier& propertyName, unsigned& attributes)
+Structure* Structure::flattenDictionaryStructure(VM& vm, JSObject* object)
{
- ASSERT(!propertyName.isNull());
+ checkOffsetConsistency();
+ ASSERT(isDictionary());
- materializePropertyMapIfNecessary();
- if (!m_propertyTable)
- return notFound;
+ size_t beforeOutOfLineCapacity = this->outOfLineCapacity();
+ if (isUncacheableDictionary()) {
+ ASSERT(propertyTable());
- UString::Rep* rep = propertyName._ustring.rep();
+ size_t propertyCount = propertyTable()->size();
- unsigned i = rep->computedHash();
+ // Holds our values compacted by insertion order.
+ Vector<JSValue> values(propertyCount);
-#if DUMP_PROPERTYMAP_STATS
- ++numProbes;
-#endif
+ // Copies out our values from their hashed locations, compacting property table offsets as we go.
+ unsigned i = 0;
+ PropertyTable::iterator end = propertyTable()->end();
+ m_offset = invalidOffset;
+ for (PropertyTable::iterator iter = propertyTable()->begin(); iter != end; ++iter, ++i) {
+ values[i] = object->getDirect(iter->offset);
+ m_offset = iter->offset = offsetForPropertyNumber(i, m_inlineCapacity);
+ }
+
+ // Copies in our values to their compacted locations.
+ for (unsigned i = 0; i < propertyCount; i++)
+ object->putDirect(vm, offsetForPropertyNumber(i, m_inlineCapacity), values[i]);
- unsigned entryIndex = m_propertyTable->entryIndices[i & m_propertyTable->sizeMask];
- if (entryIndex == emptyEntryIndex)
- return notFound;
+ propertyTable()->clearDeletedOffsets();
+ checkOffsetConsistency();
+ }
- if (rep == m_propertyTable->entries()[entryIndex - 1].key) {
- attributes = m_propertyTable->entries()[entryIndex - 1].attributes;
- return m_propertyTable->entries()[entryIndex - 1].offset;
+ setDictionaryKind(NoneDictionaryKind);
+ setHasBeenFlattenedBefore(true);
+
+ size_t afterOutOfLineCapacity = this->outOfLineCapacity();
+
+ if (beforeOutOfLineCapacity != afterOutOfLineCapacity) {
+ ASSERT(beforeOutOfLineCapacity > afterOutOfLineCapacity);
+ // If the object had a Butterfly but after flattening/compacting we no longer have need of it,
+ // we need to zero it out because the collector depends on the Structure to know the size for copying.
+ if (object->butterfly() && !afterOutOfLineCapacity && !this->hasIndexingHeader(object))
+ object->setStructureAndButterfly(vm, this, 0);
+ // If the object was down-sized to the point where the base of the Butterfly is no longer within the
+ // first CopiedBlock::blockSize bytes, we'll get the wrong answer if we try to mask the base back to
+ // the CopiedBlock header. To prevent this case we need to memmove the Butterfly down.
+ else if (object->butterfly())
+ object->shiftButterflyAfterFlattening(vm, beforeOutOfLineCapacity, afterOutOfLineCapacity);
}
-#if DUMP_PROPERTYMAP_STATS
- ++numCollisions;
-#endif
+ return this;
+}
- unsigned k = 1 | doubleHash(rep->computedHash());
+PropertyOffset Structure::addPropertyWithoutTransition(VM& vm, PropertyName propertyName, unsigned attributes)
+{
+ DeferGC deferGC(vm.heap);
+ materializePropertyMapIfNecessaryForPinning(vm, deferGC);
+
+ pin();
- while (1) {
- i += k;
+ return add(vm, propertyName, attributes);
+}
-#if DUMP_PROPERTYMAP_STATS
- ++numRehashes;
-#endif
+PropertyOffset Structure::removePropertyWithoutTransition(VM& vm, PropertyName propertyName)
+{
+ ASSERT(isUncacheableDictionary());
- entryIndex = m_propertyTable->entryIndices[i & m_propertyTable->sizeMask];
- if (entryIndex == emptyEntryIndex)
- return notFound;
+ DeferGC deferGC(vm.heap);
+ materializePropertyMapIfNecessaryForPinning(vm, deferGC);
- if (rep == m_propertyTable->entries()[entryIndex - 1].key) {
- attributes = m_propertyTable->entries()[entryIndex - 1].attributes;
- return m_propertyTable->entries()[entryIndex - 1].offset;
- }
- }
+ pin();
+ return remove(propertyName);
}
-size_t Structure::put(const Identifier& propertyName, unsigned attributes)
+void Structure::pin()
{
- ASSERT(!propertyName.isNull());
- ASSERT(get(propertyName) == notFound);
+ ASSERT(propertyTable());
+ setIsPinnedPropertyTable(true);
+ clearPreviousID();
+ m_nameInPrevious = nullptr;
+}
- checkConsistency();
+void Structure::allocateRareData(VM& vm)
+{
+ ASSERT(!hasRareData());
+ StructureRareData* rareData = StructureRareData::create(vm, previous());
+ WTF::storeStoreFence();
+ m_previousOrRareData.set(vm, this, rareData);
+ WTF::storeStoreFence();
+ setHasRareData(true);
+ ASSERT(hasRareData());
+}
- UString::Rep* rep = propertyName._ustring.rep();
+WatchpointSet* Structure::ensurePropertyReplacementWatchpointSet(VM& vm, PropertyOffset offset)
+{
+ ASSERT(!isUncacheableDictionary());
+
+ if (!hasRareData())
+ allocateRareData(vm);
+ ConcurrentJITLocker locker(m_lock);
+ StructureRareData* rareData = this->rareData();
+ if (!rareData->m_replacementWatchpointSets) {
+ rareData->m_replacementWatchpointSets =
+ std::make_unique<StructureRareData::PropertyWatchpointMap>();
+ WTF::storeStoreFence();
+ }
+ auto result = rareData->m_replacementWatchpointSets->add(offset, nullptr);
+ if (result.isNewEntry)
+ result.iterator->value = adoptRef(new WatchpointSet(IsWatched));
+ return result.iterator->value.get();
+}
- if (!m_propertyTable)
- createPropertyMapHashTable();
+void Structure::startWatchingPropertyForReplacements(VM& vm, PropertyName propertyName)
+{
+ ASSERT(!isUncacheableDictionary());
+
+ PropertyOffset offset = get(vm, propertyName);
+ if (!JSC::isValidOffset(offset))
+ return;
+
+ startWatchingPropertyForReplacements(vm, offset);
+}
- // FIXME: Consider a fast case for tables with no deleted sentinels.
+void Structure::didCachePropertyReplacement(VM& vm, PropertyOffset offset)
+{
+ ensurePropertyReplacementWatchpointSet(vm, offset)->fireAll("Did cache property replacement");
+}
- unsigned i = rep->computedHash();
- unsigned k = 0;
- bool foundDeletedElement = false;
- unsigned deletedElementIndex = 0; // initialize to make the compiler happy
+void Structure::startWatchingInternalProperties(VM& vm)
+{
+ if (!isUncacheableDictionary()) {
+ startWatchingPropertyForReplacements(vm, vm.propertyNames->toString);
+ startWatchingPropertyForReplacements(vm, vm.propertyNames->valueOf);
+ }
+ setDidWatchInternalProperties(true);
+}
#if DUMP_PROPERTYMAP_STATS
- ++numProbes;
-#endif
-
- while (1) {
- unsigned entryIndex = m_propertyTable->entryIndices[i & m_propertyTable->sizeMask];
- if (entryIndex == emptyEntryIndex)
- break;
- if (entryIndex == deletedSentinelIndex) {
- // If we find a deleted-element sentinel, remember it for use later.
- if (!foundDeletedElement) {
- foundDeletedElement = true;
- deletedElementIndex = i;
- }
- }
+PropertyMapHashTableStats* propertyMapHashTableStats = 0;
- if (k == 0) {
- k = 1 | doubleHash(rep->computedHash());
-#if DUMP_PROPERTYMAP_STATS
- ++numCollisions;
-#endif
- }
+struct PropertyMapStatisticsExitLogger {
+ PropertyMapStatisticsExitLogger();
+ ~PropertyMapStatisticsExitLogger();
+};
- i += k;
+DEFINE_GLOBAL_FOR_LOGGING(PropertyMapStatisticsExitLogger, logger, );
-#if DUMP_PROPERTYMAP_STATS
- ++numRehashes;
-#endif
- }
+PropertyMapStatisticsExitLogger::PropertyMapStatisticsExitLogger()
+{
+ propertyMapHashTableStats = adoptPtr(new PropertyMapHashTableStats()).leakPtr();
+}
- // Figure out which entry to use.
- unsigned entryIndex = m_propertyTable->keyCount + m_propertyTable->deletedSentinelCount + 2;
- if (foundDeletedElement) {
- i = deletedElementIndex;
- --m_propertyTable->deletedSentinelCount;
-
- // Since we're not making the table bigger, we can't use the entry one past
- // the end that we were planning on using, so search backwards for the empty
- // slot that we can use. We know it will be there because we did at least one
- // deletion in the past that left an entry empty.
- while (m_propertyTable->entries()[--entryIndex - 1].key) { }
- }
+PropertyMapStatisticsExitLogger::~PropertyMapStatisticsExitLogger()
+{
+ unsigned finds = propertyMapHashTableStats->numFinds;
+ unsigned collisions = propertyMapHashTableStats->numCollisions;
+ dataLogF("\nJSC::PropertyMap statistics for process %d\n\n", getCurrentProcessID());
+ dataLogF("%d finds\n", finds);
+ dataLogF("%d collisions (%.1f%%)\n", collisions, 100.0 * collisions / finds);
+ dataLogF("%d lookups\n", propertyMapHashTableStats->numLookups.load());
+ dataLogF("%d lookup probings\n", propertyMapHashTableStats->numLookupProbing.load());
+ dataLogF("%d adds\n", propertyMapHashTableStats->numAdds.load());
+ dataLogF("%d removes\n", propertyMapHashTableStats->numRemoves.load());
+ dataLogF("%d rehashes\n", propertyMapHashTableStats->numRehashes.load());
+ dataLogF("%d reinserts\n", propertyMapHashTableStats->numReinserts.load());
+}
- // Create a new hash table entry.
- m_propertyTable->entryIndices[i & m_propertyTable->sizeMask] = entryIndex;
+#endif
- // Create a new hash table entry.
- rep->ref();
- m_propertyTable->entries()[entryIndex - 1].key = rep;
- m_propertyTable->entries()[entryIndex - 1].attributes = attributes;
- m_propertyTable->entries()[entryIndex - 1].index = ++m_propertyTable->lastIndexUsed;
+PropertyTable* Structure::copyPropertyTable(VM& vm)
+{
+ if (!propertyTable())
+ return 0;
+ return PropertyTable::clone(vm, *propertyTable().get());
+}
- unsigned newOffset;
- if (m_propertyTable->deletedOffsets && !m_propertyTable->deletedOffsets->isEmpty()) {
- newOffset = m_propertyTable->deletedOffsets->last();
- m_propertyTable->deletedOffsets->removeLast();
- } else
- newOffset = m_propertyTable->keyCount;
- m_propertyTable->entries()[entryIndex - 1].offset = newOffset;
+PropertyTable* Structure::copyPropertyTableForPinning(VM& vm)
+{
+ if (propertyTable())
+ return PropertyTable::clone(vm, *propertyTable().get());
+ return PropertyTable::create(vm, numberOfSlotsForLastOffset(m_offset, m_inlineCapacity));
+}
- ++m_propertyTable->keyCount;
+PropertyOffset Structure::getConcurrently(UniquedStringImpl* uid, unsigned& attributes)
+{
+ PropertyOffset result = invalidOffset;
+
+ forEachPropertyConcurrently(
+ [&] (const PropertyMapEntry& candidate) -> bool {
+ if (candidate.key != uid)
+ return true;
+
+ result = candidate.offset;
+ attributes = candidate.attributes;
+ return false;
+ });
+
+ return result;
+}
- if ((m_propertyTable->keyCount + m_propertyTable->deletedSentinelCount) * 2 >= m_propertyTable->size)
- expandPropertyMapHashTable();
+Vector<PropertyMapEntry> Structure::getPropertiesConcurrently()
+{
+ Vector<PropertyMapEntry> result;
- checkConsistency();
- return newOffset;
+ forEachPropertyConcurrently(
+ [&] (const PropertyMapEntry& entry) -> bool {
+ result.append(entry);
+ return true;
+ });
+
+ return result;
}
-size_t Structure::remove(const Identifier& propertyName)
+PropertyOffset Structure::add(VM& vm, PropertyName propertyName, unsigned attributes)
{
- ASSERT(!propertyName.isNull());
+ GCSafeConcurrentJITLocker locker(m_lock, vm.heap);
+
+ ASSERT(!JSC::isValidOffset(get(vm, propertyName)));
checkConsistency();
+ if (attributes & DontEnum)
+ setHasNonEnumerableProperties(true);
- UString::Rep* rep = propertyName._ustring.rep();
+ auto rep = propertyName.uid();
- if (!m_propertyTable)
- return notFound;
+ if (!propertyTable())
+ createPropertyMap(locker, vm);
-#if DUMP_PROPERTYMAP_STATS
- ++numProbes;
- ++numRemoves;
-#endif
+ PropertyOffset newOffset = propertyTable()->nextOffset(m_inlineCapacity);
- // Find the thing to remove.
- unsigned i = rep->computedHash();
- unsigned k = 0;
- unsigned entryIndex;
- UString::Rep* key = 0;
- while (1) {
- entryIndex = m_propertyTable->entryIndices[i & m_propertyTable->sizeMask];
- if (entryIndex == emptyEntryIndex)
- return notFound;
-
- key = m_propertyTable->entries()[entryIndex - 1].key;
- if (rep == key)
- break;
-
- if (k == 0) {
- k = 1 | doubleHash(rep->computedHash());
-#if DUMP_PROPERTYMAP_STATS
- ++numCollisions;
-#endif
- }
-
- i += k;
-
-#if DUMP_PROPERTYMAP_STATS
- ++numRehashes;
-#endif
- }
+ propertyTable()->add(PropertyMapEntry(rep, newOffset, attributes), m_offset, PropertyTable::PropertyOffsetMayChange);
+
+ checkConsistency();
+ return newOffset;
+}
- // Replace this one element with the deleted sentinel. Also clear out
- // the entry so we can iterate all the entries as needed.
- m_propertyTable->entryIndices[i & m_propertyTable->sizeMask] = deletedSentinelIndex;
+PropertyOffset Structure::remove(PropertyName propertyName)
+{
+ ConcurrentJITLocker locker(m_lock);
+
+ checkConsistency();
- size_t offset = m_propertyTable->entries()[entryIndex - 1].offset;
+ auto rep = propertyName.uid();
- key->deref();
- m_propertyTable->entries()[entryIndex - 1].key = 0;
- m_propertyTable->entries()[entryIndex - 1].attributes = 0;
- m_propertyTable->entries()[entryIndex - 1].offset = 0;
+ if (!propertyTable())
+ return invalidOffset;
- if (!m_propertyTable->deletedOffsets)
- m_propertyTable->deletedOffsets = new Vector<unsigned>;
- m_propertyTable->deletedOffsets->append(offset);
+ PropertyTable::find_iterator position = propertyTable()->find(rep);
+ if (!position.first)
+ return invalidOffset;
- ASSERT(m_propertyTable->keyCount >= 1);
- --m_propertyTable->keyCount;
- ++m_propertyTable->deletedSentinelCount;
+ PropertyOffset offset = position.first->offset;
- if (m_propertyTable->deletedSentinelCount * 4 >= m_propertyTable->size)
- rehashPropertyMapHashTable();
+ propertyTable()->remove(position);
+ propertyTable()->addDeletedOffset(offset);
checkConsistency();
return offset;
}
-void Structure::insertIntoPropertyMapHashTable(const PropertyMapEntry& entry)
+void Structure::createPropertyMap(const GCSafeConcurrentJITLocker&, VM& vm, unsigned capacity)
{
- ASSERT(m_propertyTable);
+ ASSERT(!propertyTable());
- unsigned i = entry.key->computedHash();
- unsigned k = 0;
+ checkConsistency();
+ propertyTable().set(vm, this, PropertyTable::create(vm, capacity));
+}
-#if DUMP_PROPERTYMAP_STATS
- ++numProbes;
-#endif
+void Structure::getPropertyNamesFromStructure(VM& vm, PropertyNameArray& propertyNames, EnumerationMode mode)
+{
+ DeferGC deferGC(vm.heap);
+ materializePropertyMapIfNecessary(vm, deferGC);
+ if (!propertyTable())
+ return;
- while (1) {
- unsigned entryIndex = m_propertyTable->entryIndices[i & m_propertyTable->sizeMask];
- if (entryIndex == emptyEntryIndex)
- break;
+ bool knownUnique = propertyNames.canAddKnownUniqueForStructure();
- if (k == 0) {
- k = 1 | doubleHash(entry.key->computedHash());
-#if DUMP_PROPERTYMAP_STATS
- ++numCollisions;
-#endif
+ PropertyTable::iterator end = propertyTable()->end();
+ for (PropertyTable::iterator iter = propertyTable()->begin(); iter != end; ++iter) {
+ ASSERT(hasNonEnumerableProperties() || !(iter->attributes & DontEnum));
+ if (!(iter->attributes & DontEnum) || mode.includeDontEnumProperties()) {
+ if (iter->key->isSymbol() && !mode.includeSymbolProperties())
+ continue;
+ if (knownUnique)
+ propertyNames.addKnownUnique(iter->key);
+ else
+ propertyNames.add(iter->key);
}
+ }
+}
- i += k;
+namespace {
-#if DUMP_PROPERTYMAP_STATS
- ++numRehashes;
-#endif
+class StructureFireDetail : public FireDetail {
+public:
+ StructureFireDetail(const Structure* structure)
+ : m_structure(structure)
+ {
+ }
+
+ virtual void dump(PrintStream& out) const override
+ {
+ out.print("Structure transition from ", *m_structure);
}
- unsigned entryIndex = m_propertyTable->keyCount + 2;
- m_propertyTable->entryIndices[i & m_propertyTable->sizeMask] = entryIndex;
- m_propertyTable->entries()[entryIndex - 1] = entry;
+private:
+ const Structure* m_structure;
+};
- ++m_propertyTable->keyCount;
-}
+} // anonymous namespace
-void Structure::createPropertyMapHashTable()
+void Structure::didTransitionFromThisStructure() const
{
- ASSERT(sizeForKeyCount(7) == newTableSize);
- createPropertyMapHashTable(newTableSize);
+ m_transitionWatchpointSet.fireAll(StructureFireDetail(this));
}
-void Structure::createPropertyMapHashTable(unsigned newTableSize)
+JSValue Structure::prototypeForLookup(CodeBlock* codeBlock) const
{
- ASSERT(!m_propertyTable);
- ASSERT(isPowerOf2(newTableSize));
-
- checkConsistency();
-
- m_propertyTable = static_cast<PropertyMapHashTable*>(fastZeroedMalloc(PropertyMapHashTable::allocationSize(newTableSize)));
- m_propertyTable->size = newTableSize;
- m_propertyTable->sizeMask = newTableSize - 1;
-
- checkConsistency();
+ return prototypeForLookup(codeBlock->globalObject());
}
-void Structure::expandPropertyMapHashTable()
+void Structure::visitChildren(JSCell* cell, SlotVisitor& visitor)
{
- ASSERT(m_propertyTable);
- rehashPropertyMapHashTable(m_propertyTable->size * 2);
+ Structure* thisObject = jsCast<Structure*>(cell);
+ ASSERT_GC_OBJECT_INHERITS(thisObject, info());
+
+ JSCell::visitChildren(thisObject, visitor);
+ visitor.append(&thisObject->m_globalObject);
+ if (!thisObject->isObject())
+ thisObject->m_cachedPrototypeChain.clear();
+ else {
+ visitor.append(&thisObject->m_prototype);
+ visitor.append(&thisObject->m_cachedPrototypeChain);
+ }
+ visitor.append(&thisObject->m_previousOrRareData);
+
+ if (thisObject->isPinnedPropertyTable()) {
+ ASSERT(thisObject->m_propertyTableUnsafe);
+ visitor.append(&thisObject->m_propertyTableUnsafe);
+ } else if (thisObject->m_propertyTableUnsafe)
+ thisObject->m_propertyTableUnsafe.clear();
}
-void Structure::rehashPropertyMapHashTable()
+bool Structure::prototypeChainMayInterceptStoreTo(VM& vm, PropertyName propertyName)
{
- ASSERT(m_propertyTable);
- ASSERT(m_propertyTable->size);
- rehashPropertyMapHashTable(m_propertyTable->size);
+ if (parseIndex(propertyName))
+ return anyObjectInChainMayInterceptIndexedAccesses();
+
+ for (Structure* current = this; ;) {
+ JSValue prototype = current->storedPrototype();
+ if (prototype.isNull())
+ return false;
+
+ current = prototype.asCell()->structure(vm);
+
+ unsigned attributes;
+ PropertyOffset offset = current->get(vm, propertyName, attributes);
+ if (!JSC::isValidOffset(offset))
+ continue;
+
+ if (attributes & (ReadOnly | Accessor))
+ return true;
+
+ return false;
+ }
}
-void Structure::rehashPropertyMapHashTable(unsigned newTableSize)
+PassRefPtr<StructureShape> Structure::toStructureShape(JSValue value)
{
- ASSERT(m_propertyTable);
- ASSERT(isPowerOf2(newTableSize));
+ RefPtr<StructureShape> baseShape = StructureShape::create();
+ RefPtr<StructureShape> curShape = baseShape;
+ Structure* curStructure = this;
+ JSValue curValue = value;
+ while (curStructure) {
+ Vector<Structure*, 8> structures;
+ Structure* structure;
+ PropertyTable* table;
+
+ curStructure->findStructuresAndMapForMaterialization(structures, structure, table);
+ if (table) {
+ PropertyTable::iterator iter = table->begin();
+ PropertyTable::iterator end = table->end();
+ for (; iter != end; ++iter)
+ curShape->addProperty(*iter->key);
+
+ structure->m_lock.unlock();
+ }
+ for (unsigned i = structures.size(); i--;) {
+ Structure* structure = structures[i];
+ if (structure->m_nameInPrevious)
+ curShape->addProperty(*structure->m_nameInPrevious);
+ }
- checkConsistency();
+ if (JSObject* curObject = curValue.getObject())
+ curShape->setConstructorName(JSObject::calculatedClassName(curObject));
+ else
+ curShape->setConstructorName(curStructure->classInfo()->className);
- PropertyMapHashTable* oldTable = m_propertyTable;
+ if (curStructure->isDictionary())
+ curShape->enterDictionaryMode();
- m_propertyTable = static_cast<PropertyMapHashTable*>(fastZeroedMalloc(PropertyMapHashTable::allocationSize(newTableSize)));
- m_propertyTable->size = newTableSize;
- m_propertyTable->sizeMask = newTableSize - 1;
+ curShape->markAsFinal();
- unsigned lastIndexUsed = 0;
- unsigned entryCount = oldTable->keyCount + oldTable->deletedSentinelCount;
- for (unsigned i = 1; i <= entryCount; ++i) {
- if (oldTable->entries()[i].key) {
- lastIndexUsed = max(oldTable->entries()[i].index, lastIndexUsed);
- insertIntoPropertyMapHashTable(oldTable->entries()[i]);
+ if (curStructure->storedPrototypeStructure()) {
+ RefPtr<StructureShape> newShape = StructureShape::create();
+ curShape->setProto(newShape);
+ curShape = newShape.release();
+ curValue = curStructure->storedPrototype();
}
- }
- m_propertyTable->lastIndexUsed = lastIndexUsed;
- m_propertyTable->deletedOffsets = oldTable->deletedOffsets;
-
- fastFree(oldTable);
- checkConsistency();
+ curStructure = curStructure->storedPrototypeStructure();
+ }
+
+ return baseShape.release();
}
-static int comparePropertyMapEntryIndices(const void* a, const void* b)
+bool Structure::canUseForAllocationsOf(Structure* other)
{
- unsigned ia = static_cast<PropertyMapEntry* const*>(a)[0]->index;
- unsigned ib = static_cast<PropertyMapEntry* const*>(b)[0]->index;
- if (ia < ib)
- return -1;
- if (ia > ib)
- return +1;
- return 0;
+ return inlineCapacity() == other->inlineCapacity()
+ && storedPrototype() == other->storedPrototype()
+ && objectInitializationBlob() == other->objectInitializationBlob();
}
-void Structure::getEnumerableNamesFromPropertyTable(PropertyNameArray& propertyNames)
+void Structure::dump(PrintStream& out) const
{
- materializePropertyMapIfNecessary();
- if (!m_propertyTable)
- return;
-
- if (m_propertyTable->keyCount < tinyMapThreshold) {
- PropertyMapEntry* a[tinyMapThreshold];
- int i = 0;
- unsigned entryCount = m_propertyTable->keyCount + m_propertyTable->deletedSentinelCount;
- for (unsigned k = 1; k <= entryCount; k++) {
- if (m_propertyTable->entries()[k].key && !(m_propertyTable->entries()[k].attributes & DontEnum)) {
- PropertyMapEntry* value = &m_propertyTable->entries()[k];
- int j;
- for (j = i - 1; j >= 0 && a[j]->index > value->index; --j)
- a[j + 1] = a[j];
- a[j + 1] = value;
- ++i;
- }
- }
- if (!propertyNames.size()) {
- for (int k = 0; k < i; ++k)
- propertyNames.addKnownUnique(a[k]->key);
- } else {
- for (int k = 0; k < i; ++k)
- propertyNames.add(a[k]->key);
- }
-
- return;
- }
-
- // Allocate a buffer to use to sort the keys.
- Vector<PropertyMapEntry*, smallMapThreshold> sortedEnumerables(m_propertyTable->keyCount);
+ out.print(RawPointer(this), ":[", classInfo()->className, ", {");
+
+ CommaPrinter comma;
+
+ const_cast<Structure*>(this)->forEachPropertyConcurrently(
+ [&] (const PropertyMapEntry& entry) -> bool {
+ out.print(comma, entry.key, ":", static_cast<int>(entry.offset));
+ return true;
+ });
+
+ out.print("}, ", IndexingTypeDump(indexingType()));
+
+ if (m_prototype.get().isCell())
+ out.print(", Proto:", RawPointer(m_prototype.get().asCell()));
+
+ out.print("]");
+}
- // Get pointers to the enumerable entries in the buffer.
- PropertyMapEntry** p = sortedEnumerables.data();
- unsigned entryCount = m_propertyTable->keyCount + m_propertyTable->deletedSentinelCount;
- for (unsigned i = 1; i <= entryCount; i++) {
- if (m_propertyTable->entries()[i].key && !(m_propertyTable->entries()[i].attributes & DontEnum))
- *p++ = &m_propertyTable->entries()[i];
- }
+void Structure::dumpInContext(PrintStream& out, DumpContext* context) const
+{
+ if (context)
+ context->structures.dumpBrief(this, out);
+ else
+ dump(out);
+}
- size_t enumerableCount = p - sortedEnumerables.data();
- // Sort the entries by index.
- qsort(sortedEnumerables.data(), enumerableCount, sizeof(PropertyMapEntry*), comparePropertyMapEntryIndices);
- sortedEnumerables.resize(enumerableCount);
-
- // Put the keys of the sorted entries into the list.
- if (!propertyNames.size()) {
- for (size_t i = 0; i < sortedEnumerables.size(); ++i)
- propertyNames.addKnownUnique(sortedEnumerables[i]->key);
- } else {
- for (size_t i = 0; i < sortedEnumerables.size(); ++i)
- propertyNames.add(sortedEnumerables[i]->key);
- }
+void Structure::dumpBrief(PrintStream& out, const CString& string) const
+{
+ out.print("%", string, ":", classInfo()->className);
}
-void Structure::getEnumerableNamesFromClassInfoTable(ExecState* exec, const ClassInfo* classInfo, PropertyNameArray& propertyNames)
+void Structure::dumpContextHeader(PrintStream& out)
{
- // Add properties from the static hashtables of properties
- for (; classInfo; classInfo = classInfo->parentClass) {
- const HashTable* table = classInfo->propHashTable(exec);
- if (!table)
- continue;
- table->initializeIfNeeded(exec);
- ASSERT(table->table);
-#if ENABLE(PERFECT_HASH_SIZE)
- int hashSizeMask = table->hashSizeMask;
-#else
- int hashSizeMask = table->compactSize - 1;
-#endif
- const HashEntry* entry = table->table;
- for (int i = 0; i <= hashSizeMask; ++i, ++entry) {
- if (entry->key() && !(entry->attributes() & DontEnum))
- propertyNames.add(entry->key());
- }
- }
+ out.print("Structures:");
}
#if DO_PROPERTYMAP_CONSTENCY_CHECK
-void Structure::checkConsistency()
+void PropertyTable::checkConsistency()
{
- if (!m_propertyTable)
- return;
-
- ASSERT(m_propertyTable->size >= newTableSize);
- ASSERT(m_propertyTable->sizeMask);
- ASSERT(m_propertyTable->size == m_propertyTable->sizeMask + 1);
- ASSERT(!(m_propertyTable->size & m_propertyTable->sizeMask));
-
- ASSERT(m_propertyTable->keyCount <= m_propertyTable->size / 2);
- ASSERT(m_propertyTable->deletedSentinelCount <= m_propertyTable->size / 4);
+ ASSERT(m_indexSize >= PropertyTable::MinimumTableSize);
+ ASSERT(m_indexMask);
+ ASSERT(m_indexSize == m_indexMask + 1);
+ ASSERT(!(m_indexSize & m_indexMask));
- ASSERT(m_propertyTable->keyCount + m_propertyTable->deletedSentinelCount <= m_propertyTable->size / 2);
+ ASSERT(m_keyCount <= m_indexSize / 2);
+ ASSERT(m_keyCount + m_deletedCount <= m_indexSize / 2);
+ ASSERT(m_deletedCount <= m_indexSize / 4);
unsigned indexCount = 0;
unsigned deletedIndexCount = 0;
- for (unsigned a = 0; a != m_propertyTable->size; ++a) {
- unsigned entryIndex = m_propertyTable->entryIndices[a];
- if (entryIndex == emptyEntryIndex)
+ for (unsigned a = 0; a != m_indexSize; ++a) {
+ unsigned entryIndex = m_index[a];
+ if (entryIndex == PropertyTable::EmptyEntryIndex)
continue;
- if (entryIndex == deletedSentinelIndex) {
+ if (entryIndex == deletedEntryIndex()) {
++deletedIndexCount;
continue;
}
- ASSERT(entryIndex > deletedSentinelIndex);
- ASSERT(entryIndex - 1 <= m_propertyTable->keyCount + m_propertyTable->deletedSentinelCount);
+ ASSERT(entryIndex < deletedEntryIndex());
+ ASSERT(entryIndex - 1 <= usedCount());
++indexCount;
- for (unsigned b = a + 1; b != m_propertyTable->size; ++b)
- ASSERT(m_propertyTable->entryIndices[b] != entryIndex);
+ for (unsigned b = a + 1; b != m_indexSize; ++b)
+ ASSERT(m_index[b] != entryIndex);
}
- ASSERT(indexCount == m_propertyTable->keyCount);
- ASSERT(deletedIndexCount == m_propertyTable->deletedSentinelCount);
+ ASSERT(indexCount == m_keyCount);
+ ASSERT(deletedIndexCount == m_deletedCount);
- ASSERT(m_propertyTable->entries()[0].key == 0);
+ ASSERT(!table()[deletedEntryIndex() - 1].key);
unsigned nonEmptyEntryCount = 0;
- for (unsigned c = 1; c <= m_propertyTable->keyCount + m_propertyTable->deletedSentinelCount; ++c) {
- UString::Rep* rep = m_propertyTable->entries()[c].key;
- if (!rep)
+ for (unsigned c = 0; c < usedCount(); ++c) {
+ StringImpl* rep = table()[c].key;
+ if (rep == PROPERTY_MAP_DELETED_ENTRY_KEY)
continue;
++nonEmptyEntryCount;
- unsigned i = rep->computedHash();
+ unsigned i = IdentifierRepHash::hash(rep);
unsigned k = 0;
unsigned entryIndex;
while (1) {
- entryIndex = m_propertyTable->entryIndices[i & m_propertyTable->sizeMask];
- ASSERT(entryIndex != emptyEntryIndex);
- if (rep == m_propertyTable->entries()[entryIndex - 1].key)
+ entryIndex = m_index[i & m_indexMask];
+ ASSERT(entryIndex != PropertyTable::EmptyEntryIndex);
+ if (rep == table()[entryIndex - 1].key)
break;
if (k == 0)
- k = 1 | doubleHash(rep->computedHash());
+ k = 1 | doubleHash(IdentifierRepHash::hash(rep));
i += k;
}
ASSERT(entryIndex == c + 1);
}
- ASSERT(nonEmptyEntryCount == m_propertyTable->keyCount);
+ ASSERT(nonEmptyEntryCount == m_keyCount);
+}
+
+void Structure::checkConsistency()
+{
+ checkOffsetConsistency();
+
+ if (!propertyTable())
+ return;
+
+ if (!hasNonEnumerableProperties()) {
+ PropertyTable::iterator end = propertyTable()->end();
+ for (PropertyTable::iterator iter = propertyTable()->begin(); iter != end; ++iter) {
+ ASSERT(!(iter->attributes & DontEnum));
+ }
+ }
+
+ propertyTable()->checkConsistency();
+}
+
+#else
+
+inline void Structure::checkConsistency()
+{
+ checkOffsetConsistency();
}
#endif // DO_PROPERTYMAP_CONSTENCY_CHECK
+bool ClassInfo::hasStaticSetterOrReadonlyProperties() const
+{
+ for (const ClassInfo* ci = this; ci; ci = ci->parentClass) {
+ if (const HashTable* table = ci->staticPropHashTable) {
+ if (table->hasSetterOrReadonlyProperties)
+ return true;
+ }
+ }
+ return false;
+}
+
+void Structure::setCachedPropertyNameEnumerator(VM& vm, JSPropertyNameEnumerator* enumerator)
+{
+ ASSERT(!isDictionary());
+ if (!hasRareData())
+ allocateRareData(vm);
+ rareData()->setCachedPropertyNameEnumerator(vm, enumerator);
+}
+
+JSPropertyNameEnumerator* Structure::cachedPropertyNameEnumerator() const
+{
+ if (!hasRareData())
+ return nullptr;
+ return rareData()->cachedPropertyNameEnumerator();
+}
+
+bool Structure::canCachePropertyNameEnumerator() const
+{
+ if (isDictionary())
+ return false;
+
+ if (hasIndexedProperties(indexingType()))
+ return false;
+
+ if (typeInfo().overridesGetPropertyNames())
+ return false;
+
+ StructureChain* structureChain = m_cachedPrototypeChain.get();
+ ASSERT(structureChain);
+ WriteBarrier<Structure>* structure = structureChain->head();
+ while (true) {
+ if (!structure->get())
+ break;
+ if (structure->get()->typeInfo().overridesGetPropertyNames())
+ return false;
+ structure++;
+ }
+
+ return true;
+}
+
+bool Structure::canAccessPropertiesQuickly() const
+{
+ if (hasNonEnumerableProperties())
+ return false;
+ if (hasGetterSetterProperties())
+ return false;
+ if (isUncacheableDictionary())
+ return false;
+ return true;
+}
+
} // namespace JSC