Ignore:
Timestamp:
Sep 15, 2009, 4:17:19 PM (16 years ago)
Author:
[email protected]
Message:

Allow anonymous storage inside JSObject
https://bugs.webkit.org/show_bug.cgi?id=29168

Reviewed by Geoff Garen

Add the concept of anonymous slots to Structures so that it is
possible to store references to values that need marking in the
standard JSObject storage buffer. This allows us to reduce the
malloc overhead of some objects (by allowing them to store JS
values in the inline storage of the object) and reduce the
dependence of custom mark functions (if all an objects children
are in the standard object property storage there's no need to
mark them manually).

File:
1 edited

Legend:

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

    r48265 r48403  
    3232#include <wtf/HashTraits.h>
    3333#include <wtf/PtrAndFlags.h>
     34#include <wtf/OwnPtr.h>
    3435#include <wtf/RefPtr.h>
    3536
     
    6970    class StructureTransitionTable {
    7071        typedef std::pair<Structure*, Structure*> Transition;
    71         typedef HashMap<StructureTransitionTableHash::Key, Transition, StructureTransitionTableHash, StructureTransitionTableHashTraits> TransitionTable;
     72        struct TransitionTable : public HashMap<StructureTransitionTableHash::Key, Transition, StructureTransitionTableHash, StructureTransitionTableHashTraits> {
     73            typedef HashMap<unsigned, Structure*> AnonymousSlotMap;
     74
     75            void addSlotTransition(unsigned count, Structure* structure)
     76            {
     77                ASSERT(!getSlotTransition(count));
     78                if (!m_anonymousSlotTable)
     79                    m_anonymousSlotTable.set(new AnonymousSlotMap);
     80                m_anonymousSlotTable->add(count, structure);
     81            }
     82
     83            void removeSlotTransition(unsigned count)
     84            {
     85                ASSERT(getSlotTransition(count));
     86                m_anonymousSlotTable->remove(count);
     87            }
     88
     89            Structure* getSlotTransition(unsigned count)
     90            {
     91                if (!m_anonymousSlotTable)
     92                    return 0;
     93
     94                AnonymousSlotMap::iterator find = m_anonymousSlotTable->find(count);
     95                if (find == m_anonymousSlotTable->end())
     96                    return 0;
     97                return find->second;
     98            }
     99        private:
     100            OwnPtr<AnonymousSlotMap> m_anonymousSlotTable;
     101        };
    72102    public:
    73103        StructureTransitionTable() {
     
    124154            }
    125155        }
     156
     157        Structure* getAnonymousSlotTransition(unsigned count)
     158        {
     159            if (usingSingleTransitionSlot())
     160                return 0;
     161            return table()->getSlotTransition(count);
     162        }
     163
     164        void addAnonymousSlotTransition(unsigned count, Structure* structure)
     165        {
     166            if (usingSingleTransitionSlot())
     167                reifySingleTransition();
     168            ASSERT(!table()->getSlotTransition(count));
     169            table()->addSlotTransition(count, structure);
     170        }
     171       
     172        void removeAnonymousSlotTransition(unsigned count)
     173        {
     174            ASSERT(!usingSingleTransitionSlot());
     175            table()->removeSlotTransition(count);
     176        }
    126177    private:
    127178        TransitionTable* table() const { ASSERT(!usingSingleTransitionSlot()); return m_transitions.m_table; }
Note: See TracChangeset for help on using the changeset viewer.