diff options
Diffstat (limited to 'Source/JavaScriptCore/runtime/ConservativeSet.h')
-rw-r--r-- | Source/JavaScriptCore/runtime/ConservativeSet.h | 57 |
1 files changed, 39 insertions, 18 deletions
diff --git a/Source/JavaScriptCore/runtime/ConservativeSet.h b/Source/JavaScriptCore/runtime/ConservativeSet.h index e7c2c4a..d078606 100644 --- a/Source/JavaScriptCore/runtime/ConservativeSet.h +++ b/Source/JavaScriptCore/runtime/ConservativeSet.h @@ -23,24 +23,30 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef ConservativeSet_h -#define ConservativeSet_h +#ifndef ConservativeRoots_h +#define ConservativeRoots_h #include "Heap.h" -#include "MarkStack.h" +#include <wtf/OSAllocator.h> #include <wtf/Vector.h> namespace JSC { class JSCell; +class Heap; -class ConservativeSet { +// May contain duplicates. + +class ConservativeRoots { public: - ConservativeSet(Heap*); - ~ConservativeSet(); + ConservativeRoots(Heap*); + ~ConservativeRoots(); + void add(void*); void add(void* begin, void* end); - void mark(MarkStack&); + + size_t size(); + JSCell** roots(); private: static const size_t inlineCapacity = 128; @@ -49,32 +55,47 @@ private: void grow(); Heap* m_heap; - DeprecatedPtr<JSCell>* m_set; + JSCell** m_roots; size_t m_size; size_t m_capacity; - DeprecatedPtr<JSCell> m_inlineSet[inlineCapacity]; + JSCell* m_inlineRoots[inlineCapacity]; }; -inline ConservativeSet::ConservativeSet(Heap* heap) +inline ConservativeRoots::ConservativeRoots(Heap* heap) : m_heap(heap) - , m_set(m_inlineSet) + , m_roots(m_inlineRoots) , m_size(0) , m_capacity(inlineCapacity) { } -inline ConservativeSet::~ConservativeSet() +inline ConservativeRoots::~ConservativeRoots() +{ + if (m_roots != m_inlineRoots) + OSAllocator::decommitAndRelease(m_roots, m_capacity * sizeof(JSCell*)); +} + +inline void ConservativeRoots::add(void* p) +{ + if (!m_heap->contains(p)) + return; + + if (m_size == m_capacity) + grow(); + + m_roots[m_size++] = reinterpret_cast<JSCell*>(p); +} + +inline size_t ConservativeRoots::size() { - if (m_set != m_inlineSet) - OSAllocator::decommitAndRelease(m_set, m_capacity * sizeof(DeprecatedPtr<JSCell>*)); + return m_size; } -inline void ConservativeSet::mark(MarkStack& markStack) +inline JSCell** ConservativeRoots::roots() { - for (size_t i = 0; i < m_size; ++i) - markStack.append(&m_set[i]); + return m_roots; } } // namespace JSC -#endif // ConservativeSet_h +#endif // ConservativeRoots_h |