Ignore:
Timestamp:
Oct 31, 2008, 12:53:20 PM (17 years ago)
Author:
[email protected]
Message:

2008-10-31 Cameron Zwarich <[email protected]>

Reviewed by Darin Adler.

Bug 22005: Move StructureIDChain into its own file
<https://bugs.webkit.org/show_bug.cgi?id=22005>

  • GNUmakefile.am:
  • JavaScriptCore.pri:
  • JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj:
  • JavaScriptCore.xcodeproj/project.pbxproj:
  • JavaScriptCoreSources.bkl:
  • runtime/StructureID.cpp:
  • runtime/StructureID.h:
  • runtime/StructureIDChain.cpp: Copied from runtime/StructureID.cpp.
  • runtime/StructureIDChain.h: Copied from runtime/StructureID.h.
File:
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/runtime/StructureIDChain.h

    r38044 r38046  
    2424 */
    2525
    26 #ifndef StructureID_h
    27 #define StructureID_h
     26#ifndef StructureIDChain_h
     27#define StructureIDChain_h
    2828
    29 #include "JSType.h"
    30 #include "JSValue.h"
    31 #include "PropertyMapHashTable.h"
    32 #include "StructureIDTransitionTable.h"
    33 #include "TypeInfo.h"
    34 #include "identifier.h"
    35 #include "ustring.h"
    36 #include <wtf/HashFunctions.h>
    37 #include <wtf/HashTraits.h>
    3829#include <wtf/OwnArrayPtr.h>
    3930#include <wtf/PassRefPtr.h>
    4031#include <wtf/RefCounted.h>
    41 
    42 #define DUMP_STRUCTURE_ID_STATISTICS 0
    43 
    44 #ifndef NDEBUG
    45 #define DUMP_PROPERTYMAP_STATS 0
    46 #else
    47 #define DUMP_PROPERTYMAP_STATS 0
    48 #endif
     32#include <wtf/RefPtr.h>
    4933
    5034namespace JSC {
    5135
    52     class PropertyNameArray;
    53     class PropertyNameArrayData;
    54     class StructureIDChain;
    55 
    56     class StructureID : public RefCounted<StructureID> {
    57     public:
    58         friend class CTI;
    59         static PassRefPtr<StructureID> create(JSValue* prototype, const TypeInfo& typeInfo)
    60         {
    61             return adoptRef(new StructureID(prototype, typeInfo));
    62         }
    63 
    64         static void startIgnoringLeaks();
    65         static void stopIgnoringLeaks();
    66 
    67 #if DUMP_STRUCTURE_ID_STATISTICS
    68         static void dumpStatistics();
    69 #endif
    70 
    71         static PassRefPtr<StructureID> changePrototypeTransition(StructureID*, JSValue* prototype);
    72         static PassRefPtr<StructureID> addPropertyTransition(StructureID*, const Identifier& propertyName, unsigned attributes, size_t& offset);
    73         static PassRefPtr<StructureID> removePropertyTransition(StructureID*, const Identifier& propertyName, size_t& offset);
    74         static PassRefPtr<StructureID> getterSetterTransition(StructureID*);
    75         static PassRefPtr<StructureID> toDictionaryTransition(StructureID*);
    76         static PassRefPtr<StructureID> fromDictionaryTransition(StructureID*);
    77 
    78         ~StructureID();
    79 
    80         void mark()
    81         {
    82             if (!m_prototype->marked())
    83                 m_prototype->mark();
    84         }
    85 
    86         // These should be used with caution. 
    87         size_t addPropertyWithoutTransition(const Identifier& propertyName, unsigned attributes);
    88         size_t removePropertyWithoutTransition(const Identifier& propertyName);
    89         void setPrototypeWithoutTransition(JSValue* prototype) { m_prototype = prototype; }
    90 
    91         bool isDictionary() const { return m_isDictionary; }
    92 
    93         const TypeInfo& typeInfo() const { return m_typeInfo; }
    94 
    95         // For use when first creating a new structure.
    96         TypeInfo& mutableTypeInfo() { return m_typeInfo; }
    97 
    98         JSValue* storedPrototype() const { return m_prototype; }
    99         JSValue* prototypeForLookup(ExecState*);
    100 
    101         StructureID* previousID() const { return m_previous.get(); }
    102 
    103         StructureIDChain* createCachedPrototypeChain();
    104         void setCachedPrototypeChain(PassRefPtr<StructureIDChain> cachedPrototypeChain) { m_cachedPrototypeChain = cachedPrototypeChain; }
    105         StructureIDChain* cachedPrototypeChain() const { return m_cachedPrototypeChain.get(); }
    106 
    107         void setCachedTransistionOffset(size_t offset) { m_cachedTransistionOffset = offset; }
    108         size_t cachedTransistionOffset() const { return m_cachedTransistionOffset; }
    109 
    110         void growPropertyStorageCapacity();
    111         size_t propertyStorageCapacity() const { return m_propertyStorageCapacity; }
    112         size_t propertyStorageSize() const { return m_propertyTable ? m_propertyTable->keyCount + m_deletedOffsets.size() : 0; }
    113 
    114         size_t get(const Identifier& propertyName) const;
    115         size_t get(const Identifier& propertyName, unsigned& attributes) const;
    116         void getEnumerablePropertyNames(ExecState*, PropertyNameArray&, JSObject*);
    117 
    118         bool hasGetterSetterProperties() const { return m_hasGetterSetterProperties; }
    119         void setHasGetterSetterProperties(bool hasGetterSetterProperties) { m_hasGetterSetterProperties = hasGetterSetterProperties; }
    120 
    121         bool isEmpty() const { return !m_propertyTable; }
    122 
    123     private:
    124         StructureID(JSValue* prototype, const TypeInfo&);
    125 
    126         size_t put(const Identifier& propertyName, unsigned attributes);
    127         size_t remove(const Identifier& propertyName);
    128         void getEnumerablePropertyNamesInternal(PropertyNameArray&) const;
    129 
    130         void expandPropertyMapHashTable();
    131         void rehashPropertyMapHashTable();
    132         void rehashPropertyMapHashTable(unsigned newTableSize);
    133         void createPropertyMapHashTable();
    134         void insertIntoPropertyMapHashTable(const PropertyMapEntry&);
    135         void checkConsistency();
    136 
    137         PropertyMapHashTable* copyPropertyTable();
    138 
    139         void clearEnumerationCache();
    140 
    141         static const unsigned emptyEntryIndex = 0;
    142    
    143         static const size_t s_maxTransitionLength = 64;
    144 
    145         TypeInfo m_typeInfo;
    146 
    147         JSValue* m_prototype;
    148         RefPtr<StructureIDChain> m_cachedPrototypeChain;
    149 
    150         RefPtr<StructureID> m_previous;
    151         UString::Rep* m_nameInPrevious;
    152 
    153         size_t m_transitionCount;
    154         union {
    155             StructureID* singleTransition;
    156             StructureIDTransitionTable* table;
    157         } m_transitions;
    158 
    159         RefPtr<PropertyNameArrayData> m_cachedPropertyNameArrayData;
    160 
    161         PropertyMapHashTable* m_propertyTable;
    162         Vector<unsigned> m_deletedOffsets;
    163 
    164         size_t m_propertyStorageCapacity;
    165 
    166         size_t m_cachedTransistionOffset;
    167 
    168         bool m_isDictionary : 1;
    169         bool m_hasGetterSetterProperties : 1;
    170         bool m_usingSingleTransitionSlot : 1;
    171         unsigned m_attributesInPrevious : 5;
    172     };
    173 
    174     inline size_t StructureID::get(const Identifier& propertyName) const
    175     {
    176         ASSERT(!propertyName.isNull());
    177 
    178         if (!m_propertyTable)
    179             return WTF::notFound;
    180 
    181         UString::Rep* rep = propertyName._ustring.rep();
    182 
    183         unsigned i = rep->computedHash();
    184 
    185 #if DUMP_PROPERTYMAP_STATS
    186         ++numProbes;
    187 #endif
    188 
    189         unsigned entryIndex = m_propertyTable->entryIndices[i & m_propertyTable->sizeMask];
    190         if (entryIndex == emptyEntryIndex)
    191             return WTF::notFound;
    192 
    193         if (rep == m_propertyTable->entries()[entryIndex - 1].key)
    194             return m_propertyTable->entries()[entryIndex - 1].offset;
    195 
    196 #if DUMP_PROPERTYMAP_STATS
    197         ++numCollisions;
    198 #endif
    199 
    200         unsigned k = 1 | WTF::doubleHash(rep->computedHash());
    201 
    202         while (1) {
    203             i += k;
    204 
    205 #if DUMP_PROPERTYMAP_STATS
    206             ++numRehashes;
    207 #endif
    208 
    209             entryIndex = m_propertyTable->entryIndices[i & m_propertyTable->sizeMask];
    210             if (entryIndex == emptyEntryIndex)
    211                 return WTF::notFound;
    212 
    213             if (rep == m_propertyTable->entries()[entryIndex - 1].key)
    214                 return m_propertyTable->entries()[entryIndex - 1].offset;
    215         }
    216     }
     36    class StructureID;
    21737
    21838    class StructureIDChain : public RefCounted<StructureIDChain> {
     
    23252} // namespace JSC
    23353
    234 #endif // StructureID_h
     54#endif // StructureIDChain_h
Note: See TracChangeset for help on using the changeset viewer.