Modified: trunk/Source/_javascript_Core/ChangeLog (87179 => 87180)
--- trunk/Source/_javascript_Core/ChangeLog 2011-05-24 18:51:49 UTC (rev 87179)
+++ trunk/Source/_javascript_Core/ChangeLog 2011-05-24 18:55:10 UTC (rev 87180)
@@ -1,3 +1,30 @@
+2011-05-24 Geoffrey Garen <[email protected]>
+
+ Rubber-stamped by Oliver Hunt.
+
+ Split out function definitions and class definitions from class
+ declarations in MarkStack.h, for readability.
+
+ * heap/MarkStack.h:
+ (JSC::MarkStack::MarkStack):
+ (JSC::MarkStack::~MarkStack):
+ (JSC::MarkStack::addOpaqueRoot):
+ (JSC::MarkStack::containsOpaqueRoot):
+ (JSC::MarkStack::opaqueRootCount):
+ (JSC::MarkSet::MarkSet):
+ (JSC::MarkStack::allocateStack):
+ (JSC::MarkStack::releaseStack):
+ (JSC::MarkStack::pageSize):
+ (JSC::::MarkStackArray):
+ (JSC::::~MarkStackArray):
+ (JSC::::expand):
+ (JSC::::append):
+ (JSC::::removeLast):
+ (JSC::::last):
+ (JSC::::isEmpty):
+ (JSC::::size):
+ (JSC::::shrinkAllocation):
+
2011-05-24 Oliver Hunt <[email protected]>
Reviewed by Geoffrey Garen.
Modified: trunk/Source/_javascript_Core/heap/MarkStack.h (87179 => 87180)
--- trunk/Source/_javascript_Core/heap/MarkStack.h 2011-05-24 18:51:49 UTC (rev 87179)
+++ trunk/Source/_javascript_Core/heap/MarkStack.h 2011-05-24 18:55:10 UTC (rev 87180)
@@ -38,49 +38,78 @@
class ConservativeRoots;
class JSGlobalData;
+ class MarkStack;
class Register;
template<typename T> class WriteBarrierBase;
+ typedef MarkStack SlotVisitor;
+
enum MarkSetProperties { MayContainNullValues, NoNullValues };
+ struct MarkSet {
+ MarkSet(JSValue* values, JSValue* end, MarkSetProperties);
+
+ JSValue* m_values;
+ JSValue* m_end;
+ MarkSetProperties m_properties;
+ };
+
+ template<typename T> class MarkStackArray {
+ public:
+ MarkStackArray();
+ ~MarkStackArray();
+
+ void expand();
+ void append(const T&);
+
+ T removeLast();
+ T& last();
+
+ bool isEmpty();
+ size_t size();
+
+ void shrinkAllocation(size_t);
+
+ private:
+ size_t m_top;
+ size_t m_allocated;
+ size_t m_capacity;
+ T* m_data;
+ };
+
class MarkStack {
WTF_MAKE_NONCOPYABLE(MarkStack);
+ friend class HeapRootVisitor; // Allowed to mark a JSValue* or JSCell** directly.
+
public:
- MarkStack(void* jsArrayVPtr)
- : m_jsArrayVPtr(jsArrayVPtr)
-#if !ASSERT_DISABLED
- , m_isCheckingForDefaultMarkViolation(false)
- , m_isDraining(false)
-#endif
- {
- }
+ static size_t pageSize();
- ~MarkStack()
- {
- ASSERT(m_markSets.isEmpty());
- ASSERT(m_values.isEmpty());
- }
+ static void* allocateStack(size_t);
+ static void releaseStack(void*, size_t);
+ MarkStack(void* jsArrayVPtr);
+ ~MarkStack();
+
+ void append(ConservativeRoots&);
+
template<typename T> inline void append(WriteBarrierBase<T>*);
inline void appendValues(WriteBarrierBase<Unknown>*, size_t count, MarkSetProperties = NoNullValues);
- void append(ConservativeRoots&);
+ bool addOpaqueRoot(void*);
+ bool containsOpaqueRoot(void*);
+ int opaqueRootCount();
- bool addOpaqueRoot(void* root) { return m_opaqueRoots.add(root).second; }
- bool containsOpaqueRoot(void* root) { return m_opaqueRoots.contains(root); }
- int opaqueRootCount() { return m_opaqueRoots.size(); }
-
void drain();
void reset();
private:
- friend class HeapRootVisitor; // Allowed to mark a JSValue* or JSCell** directly.
-
#if ENABLE(GC_VALIDATION)
static void validateSet(JSValue*, size_t);
static void validateValue(JSValue);
#endif
+ static void initializePagesize();
+
void append(JSValue*);
void append(JSValue*, size_t count);
void append(JSCell**);
@@ -89,121 +118,146 @@
void internalAppend(JSValue);
void visitChildren(JSCell*);
- struct MarkSet {
- MarkSet(JSValue* values, JSValue* end, MarkSetProperties properties)
- : m_values(values)
- , m_end(end)
- , m_properties(properties)
- {
- ASSERT(values);
- }
- JSValue* m_values;
- JSValue* m_end;
- MarkSetProperties m_properties;
- };
+ static size_t s_pageSize;
- static void* allocateStack(size_t size) { return OSAllocator::reserveAndCommit(size); }
- static void releaseStack(void* addr, size_t size) { OSAllocator::decommitAndRelease(addr, size); }
+ void* m_jsArrayVPtr;
+ MarkStackArray<MarkSet> m_markSets;
+ MarkStackArray<JSCell*> m_values;
+ HashSet<void*> m_opaqueRoots; // Handle-owning data structures not visible to the garbage collector.
- static void initializePagesize();
- static size_t pageSize()
+#if !ASSERT_DISABLED
+ public:
+ bool m_isCheckingForDefaultMarkViolation;
+ bool m_isDraining;
+#endif
+ };
+
+ inline MarkStack::MarkStack(void* jsArrayVPtr)
+ : m_jsArrayVPtr(jsArrayVPtr)
+#if !ASSERT_DISABLED
+ , m_isCheckingForDefaultMarkViolation(false)
+ , m_isDraining(false)
+#endif
+ {
+ }
+
+ inline MarkStack::~MarkStack()
+ {
+ ASSERT(m_markSets.isEmpty());
+ ASSERT(m_values.isEmpty());
+ }
+
+ inline bool MarkStack::addOpaqueRoot(void* root)
+ {
+ return m_opaqueRoots.add(root).second;
+ }
+
+ inline bool MarkStack::containsOpaqueRoot(void* root)
+ {
+ return m_opaqueRoots.contains(root);
+ }
+
+ inline int MarkStack::opaqueRootCount()
+ {
+ return m_opaqueRoots.size();
+ }
+
+ inline MarkSet::MarkSet(JSValue* values, JSValue* end, MarkSetProperties properties)
+ : m_values(values)
+ , m_end(end)
+ , m_properties(properties)
{
- if (!s_pageSize)
- initializePagesize();
- return s_pageSize;
+ ASSERT(values);
}
- template<typename T> struct MarkStackArray {
- MarkStackArray()
- : m_top(0)
- , m_allocated(MarkStack::pageSize())
- , m_capacity(m_allocated / sizeof(T))
- {
- m_data = reinterpret_cast<T*>(allocateStack(m_allocated));
- }
+ inline void* MarkStack::allocateStack(size_t size)
+ {
+ return OSAllocator::reserveAndCommit(size);
+ }
- ~MarkStackArray()
- {
- releaseStack(m_data, m_allocated);
- }
+ inline void MarkStack::releaseStack(void* addr, size_t size)
+ {
+ OSAllocator::decommitAndRelease(addr, size);
+ }
- void expand()
- {
- size_t oldAllocation = m_allocated;
- m_allocated *= 2;
- m_capacity = m_allocated / sizeof(T);
- void* newData = allocateStack(m_allocated);
- memcpy(newData, m_data, oldAllocation);
- releaseStack(m_data, oldAllocation);
- m_data = reinterpret_cast<T*>(newData);
- }
+ inline size_t MarkStack::pageSize()
+ {
+ if (!s_pageSize)
+ initializePagesize();
+ return s_pageSize;
+ }
- inline void append(const T& v)
- {
- if (m_top == m_capacity)
- expand();
- m_data[m_top++] = v;
- }
+ template <typename T> inline MarkStackArray<T>::MarkStackArray()
+ : m_top(0)
+ , m_allocated(MarkStack::pageSize())
+ , m_capacity(m_allocated / sizeof(T))
+ {
+ m_data = reinterpret_cast<T*>(MarkStack::allocateStack(m_allocated));
+ }
- inline T removeLast()
- {
- ASSERT(m_top);
- return m_data[--m_top];
- }
-
- inline T& last()
- {
- ASSERT(m_top);
- return m_data[m_top - 1];
- }
+ template <typename T> inline MarkStackArray<T>::~MarkStackArray()
+ {
+ MarkStack::releaseStack(m_data, m_allocated);
+ }
- inline bool isEmpty()
- {
- return m_top == 0;
- }
+ template <typename T> inline void MarkStackArray<T>::expand()
+ {
+ size_t oldAllocation = m_allocated;
+ m_allocated *= 2;
+ m_capacity = m_allocated / sizeof(T);
+ void* newData = MarkStack::allocateStack(m_allocated);
+ memcpy(newData, m_data, oldAllocation);
+ MarkStack::releaseStack(m_data, oldAllocation);
+ m_data = reinterpret_cast<T*>(newData);
+ }
- inline size_t size() { return m_top; }
+ template <typename T> inline void MarkStackArray<T>::append(const T& v)
+ {
+ if (m_top == m_capacity)
+ expand();
+ m_data[m_top++] = v;
+ }
- inline void shrinkAllocation(size_t size)
- {
- ASSERT(size <= m_allocated);
- ASSERT(0 == (size % MarkStack::pageSize()));
- if (size == m_allocated)
- return;
-#if OS(WINDOWS) || OS(SYMBIAN) || PLATFORM(BREWMP)
- // We cannot release a part of a region with VirtualFree. To get around this,
- // we'll release the entire region and reallocate the size that we want.
- releaseStack(m_data, m_allocated);
- m_data = reinterpret_cast<T*>(allocateStack(size));
-#else
- releaseStack(reinterpret_cast<char*>(m_data) + size, m_allocated - size);
-#endif
- m_allocated = size;
- m_capacity = m_allocated / sizeof(T);
- }
+ template <typename T> inline T MarkStackArray<T>::removeLast()
+ {
+ ASSERT(m_top);
+ return m_data[--m_top];
+ }
+
+ template <typename T> inline T& MarkStackArray<T>::last()
+ {
+ ASSERT(m_top);
+ return m_data[m_top - 1];
+ }
- private:
- size_t m_top;
- size_t m_allocated;
- size_t m_capacity;
- T* m_data;
- };
+ template <typename T> inline bool MarkStackArray<T>::isEmpty()
+ {
+ return m_top == 0;
+ }
- void* m_jsArrayVPtr;
- MarkStackArray<MarkSet> m_markSets;
- MarkStackArray<JSCell*> m_values;
- static size_t s_pageSize;
- HashSet<void*> m_opaqueRoots; // Handle-owning data structures not visible to the garbage collector.
+ template <typename T> inline size_t MarkStackArray<T>::size()
+ {
+ return m_top;
+ }
-#if !ASSERT_DISABLED
- public:
- bool m_isCheckingForDefaultMarkViolation;
- bool m_isDraining;
+ template <typename T> inline void MarkStackArray<T>::shrinkAllocation(size_t size)
+ {
+ ASSERT(size <= m_allocated);
+ ASSERT(0 == (size % MarkStack::pageSize()));
+ if (size == m_allocated)
+ return;
+#if OS(WINDOWS) || OS(SYMBIAN) || PLATFORM(BREWMP)
+ // We cannot release a part of a region with VirtualFree. To get around this,
+ // we'll release the entire region and reallocate the size that we want.
+ releaseStack(m_data, m_allocated);
+ m_data = reinterpret_cast<T*>(allocateStack(size));
+#else
+ MarkStack::releaseStack(reinterpret_cast<char*>(m_data) + size, m_allocated - size);
#endif
- };
+ m_allocated = size;
+ m_capacity = m_allocated / sizeof(T);
+ }
- typedef MarkStack SlotVisitor;
-
inline void MarkStack::append(JSValue* slot, size_t count)
{
if (!count)
@@ -244,7 +298,7 @@
private:
friend class Heap;
HeapRootVisitor(SlotVisitor&);
-
+
public:
void mark(JSValue*);
void mark(JSValue*, size_t);