diff options
author | Ben Murdoch <benm@google.com> | 2011-06-02 12:07:03 +0100 |
---|---|---|
committer | Ben Murdoch <benm@google.com> | 2011-06-10 10:47:21 +0100 |
commit | 2daae5fd11344eaa88a0d92b0f6d65f8d2255c00 (patch) | |
tree | e4964fbd1cb70599f7718ff03e50ea1dab33890b /Source/JavaScriptCore/runtime/StructureTransitionTable.h | |
parent | 87bdf0060a247bfbe668342b87e0874182e0ffa9 (diff) | |
download | external_webkit-2daae5fd11344eaa88a0d92b0f6d65f8d2255c00.zip external_webkit-2daae5fd11344eaa88a0d92b0f6d65f8d2255c00.tar.gz external_webkit-2daae5fd11344eaa88a0d92b0f6d65f8d2255c00.tar.bz2 |
Merge WebKit at r84325: Initial merge by git.
Change-Id: Ic1a909300ecc0a13ddc6b4e784371d2ac6e3d59b
Diffstat (limited to 'Source/JavaScriptCore/runtime/StructureTransitionTable.h')
-rw-r--r-- | Source/JavaScriptCore/runtime/StructureTransitionTable.h | 57 |
1 files changed, 50 insertions, 7 deletions
diff --git a/Source/JavaScriptCore/runtime/StructureTransitionTable.h b/Source/JavaScriptCore/runtime/StructureTransitionTable.h index da78e1b..adebad2 100644 --- a/Source/JavaScriptCore/runtime/StructureTransitionTable.h +++ b/Source/JavaScriptCore/runtime/StructureTransitionTable.h @@ -27,8 +27,8 @@ #define StructureTransitionTable_h #include "UString.h" +#include "WeakGCMap.h" #include <wtf/HashFunctions.h> -#include <wtf/HashMap.h> #include <wtf/HashTraits.h> #include <wtf/OwnPtr.h> #include <wtf/RefPtr.h> @@ -69,7 +69,21 @@ class StructureTransitionTable { static bool isDeletedValue(const TraitType& value) { return FirstTraits::isDeletedValue(value.first); } }; - typedef HashMap<Hash::Key, Structure*, Hash, HashTraits> TransitionMap; + struct WeakGCMapFinalizerCallback { + static void* finalizerContextFor(Hash::Key) + { + return 0; + } + + static inline Hash::Key keyForFinalizer(void* context, Structure* structure) + { + return keyForWeakGCMapFinalizer(context, structure); + } + }; + + typedef WeakGCMap<Hash::Key, Structure, WeakGCMapFinalizerCallback, Hash, HashTraits> TransitionMap; + + static Hash::Key keyForWeakGCMapFinalizer(void* context, Structure*); public: StructureTransitionTable() @@ -81,9 +95,11 @@ public: { if (!isUsingSingleSlot()) delete map(); + else + clearSingleTransition(); } - inline void add(Structure*); + inline void add(JSGlobalData&, Structure*); inline void remove(Structure*); inline bool contains(StringImpl* rep, unsigned attributes) const; inline Structure* get(StringImpl* rep, unsigned attributes) const; @@ -100,9 +116,18 @@ private: return reinterpret_cast<TransitionMap*>(m_data); } + HandleSlot slot() const + { + ASSERT(isUsingSingleSlot()); + return reinterpret_cast<HandleSlot>(m_data & ~UsingSingleSlotFlag); + } + void setMap(TransitionMap* map) { ASSERT(isUsingSingleSlot()); + + if (HandleSlot slot = this->slot()) + HandleHeap::heapFor(slot)->deallocate(slot); // This implicitly clears the flag that indicates we're using a single transition m_data = reinterpret_cast<intptr_t>(map); @@ -113,13 +138,31 @@ private: Structure* singleTransition() const { ASSERT(isUsingSingleSlot()); - return reinterpret_cast<Structure*>(m_data & ~UsingSingleSlotFlag); + if (HandleSlot slot = this->slot()) { + if (*slot) + return reinterpret_cast<Structure*>(slot->asCell()); + } + return 0; } - - void setSingleTransition(Structure* structure) + + void clearSingleTransition() { ASSERT(isUsingSingleSlot()); - m_data = reinterpret_cast<intptr_t>(structure) | UsingSingleSlotFlag; + if (HandleSlot slot = this->slot()) + HandleHeap::heapFor(slot)->deallocate(slot); + } + + void setSingleTransition(JSGlobalData& globalData, Structure* structure) + { + ASSERT(isUsingSingleSlot()); + HandleSlot slot = this->slot(); + if (!slot) { + slot = globalData.allocateGlobalHandle(); + HandleHeap::heapFor(slot)->makeWeak(slot, 0, 0); + m_data = reinterpret_cast<intptr_t>(slot) | UsingSingleSlotFlag; + } + HandleHeap::heapFor(slot)->writeBarrier(slot, reinterpret_cast<JSCell*>(structure)); + *slot = reinterpret_cast<JSCell*>(structure); } intptr_t m_data; |