2011-03-16  Geoffrey Garen  <ggaren@apple.com>

        Reviewed by Oliver Hunt.

        Some conservative root gathering cleanup
        https://bugs.webkit.org/show_bug.cgi?id=56447
        
        SunSpider says 0.5% - 1.8% faster.

        * interpreter/RegisterFile.cpp:
        (JSC::RegisterFile::gatherConservativeRoots):
        * interpreter/RegisterFile.h: New helper function for doing the
        conservative gathering of the register file. It's still conservative,
        since the register file may contain uninitialized values, but it's
        moving-safe, because it only visits values tagged as pointers, so there's
        no risk of mistaking an integer for a pointer and accidentally changing it.

        * runtime/ConservativeSet.cpp:
        (JSC::ConservativeRoots::add):
        * runtime/ConservativeSet.h: Added a single-value add function, used above.

        * runtime/Heap.cpp:
        (JSC::Heap::markRoots): Separated machine stack conservative roots from
        register file conservative roots because machine stack roots must be
        pinned, but register file roots need not be pinned.
        
        Adopted new interface for passing the current stack extent to the machine
        stack root gathering routine. This allows us to exclude marking-related
        data structures on the stack, and thus avoid double-marking the set of
        machine roots.

        * runtime/MachineStackMarker.cpp:
        (JSC::MachineThreads::gatherFromCurrentThread):
        (JSC::MachineThreads::gatherConservativeRoots):
        * runtime/MachineStackMarker.h: Added new interface, described above.

        * runtime/MarkedBlock.h:
        (JSC::MarkedBlock::firstAtom):
        * wtf/StdLibExtras.h:
        (WTF::roundUpToMultipleOf): Moved roundUpToMultipleOf so it could be used
        by MachineStacks.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@81262 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/JavaScriptCore/runtime/Heap.cpp b/Source/JavaScriptCore/runtime/Heap.cpp
index c780c89..79533e0 100644
--- a/Source/JavaScriptCore/runtime/Heap.cpp
+++ b/Source/JavaScriptCore/runtime/Heap.cpp
@@ -199,25 +199,32 @@
     }
 #endif
 
+    void* dummy;
+
     ASSERT(m_operationInProgress == NoOperation);
     if (m_operationInProgress != NoOperation)
         CRASH();
 
     m_operationInProgress = Collection;
 
-    // We gather the conservative set before clearing mark bits, because
+    MarkStack& markStack = m_markStack;
+    HeapRootMarker heapRootMarker(markStack);
+    
+    // We gather conservative roots before clearing mark bits because
     // conservative gathering uses the mark bits from our last mark pass to
     // determine whether a reference is valid.
-    ConservativeRoots conservativeRoots(this);
-    m_machineThreads.gatherConservativeRoots(conservativeRoots);
-    conservativeRoots.add(registerFile().start(), registerFile().end());
+    ConservativeRoots machineThreadRoots(this);
+    m_machineThreads.gatherConservativeRoots(machineThreadRoots, &dummy);
+
+    ConservativeRoots registerFileRoots(this);
+    registerFile().gatherConservativeRoots(registerFileRoots);
 
     m_markedSpace.clearMarks();
 
-    MarkStack& markStack = m_markStack;
-    HeapRootMarker heapRootMarker(markStack);
+    markStack.append(machineThreadRoots);
+    markStack.drain();
 
-    markStack.append(conservativeRoots);
+    markStack.append(registerFileRoots);
     markStack.drain();
 
     markProtectedObjects(heapRootMarker);