]>
git.saurik.com Git - apple/javascriptcore.git/blob - heap/HandleSet.h
2 * Copyright (C) 2011 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 INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
30 #include "HandleBlock.h"
31 #include <wtf/DoublyLinkedList.h>
32 #include <wtf/HashCountedSet.h>
33 #include <wtf/SentinelLinkedList.h>
34 #include <wtf/SinglyLinkedList.h>
40 class HeapRootVisitor
;
47 HandleNode(WTF::SentinelTag
);
51 HandleSet
* handleSet();
53 void setPrev(HandleNode
*);
56 void setNext(HandleNode
*);
66 friend class HandleBlock
;
68 static HandleSet
* heapFor(HandleSlot
);
75 HandleSlot
allocate();
76 void deallocate(HandleSlot
);
78 void visitStrongHandles(HeapRootVisitor
&);
80 JS_EXPORT_PRIVATE
void writeBarrier(HandleSlot
, const JSValue
&);
82 unsigned protectedGlobalObjectCount();
84 template<typename Functor
> void forEachStrongHandle(Functor
&, const HashCountedSet
<JSCell
*>& skipSet
);
87 typedef HandleNode Node
;
88 static HandleSlot
toHandle(Node
*);
89 static Node
* toNode(HandleSlot
);
91 JS_EXPORT_PRIVATE
void grow();
93 #if ENABLE(GC_VALIDATION) || !ASSERT_DISABLED
94 bool isLiveNode(Node
*);
98 DoublyLinkedList
<HandleBlock
> m_blockList
;
100 SentinelLinkedList
<Node
> m_strongList
;
101 SentinelLinkedList
<Node
> m_immediateList
;
102 SinglyLinkedList
<Node
> m_freeList
;
105 inline HandleSet
* HandleSet::heapFor(HandleSlot handle
)
107 return toNode(handle
)->handleSet();
110 inline VM
* HandleSet::vm()
115 inline HandleSlot
HandleSet::toHandle(HandleSet::Node
* node
)
117 return reinterpret_cast<HandleSlot
>(node
);
120 inline HandleSet::Node
* HandleSet::toNode(HandleSlot handle
)
122 return reinterpret_cast<HandleSet::Node
*>(handle
);
125 inline HandleSlot
HandleSet::allocate()
127 if (m_freeList
.isEmpty())
130 HandleSet::Node
* node
= m_freeList
.pop();
131 new (NotNull
, node
) HandleSet::Node();
132 m_immediateList
.push(node
);
133 return toHandle(node
);
136 inline void HandleSet::deallocate(HandleSlot handle
)
138 HandleSet::Node
* node
= toNode(handle
);
139 SentinelLinkedList
<HandleSet::Node
>::remove(node
);
140 m_freeList
.push(node
);
143 inline HandleNode::HandleNode()
149 inline HandleNode::HandleNode(WTF::SentinelTag
)
155 inline HandleSlot
HandleNode::slot()
160 inline HandleSet
* HandleNode::handleSet()
162 return HandleBlock::blockFor(this)->handleSet();
165 inline void HandleNode::setPrev(HandleNode
* prev
)
170 inline HandleNode
* HandleNode::prev()
175 inline void HandleNode::setNext(HandleNode
* next
)
180 inline HandleNode
* HandleNode::next()
185 template<typename Functor
> void HandleSet::forEachStrongHandle(Functor
& functor
, const HashCountedSet
<JSCell
*>& skipSet
)
187 HandleSet::Node
* end
= m_strongList
.end();
188 for (HandleSet::Node
* node
= m_strongList
.begin(); node
!= end
; node
= node
->next()) {
189 JSValue value
= *node
->slot();
190 if (!value
|| !value
.isCell())
192 if (skipSet
.contains(value
.asCell()))
194 functor(value
.asCell());