2011-02-11  Geoffrey Garen  <ggaren@apple.com>

        Reviewed by Oliver Hunt.

        A little more encapsulation for the heap: Removed CollectorHeapIterator
        https://bugs.webkit.org/show_bug.cgi?id=54298
        
        CollectorHeapIterator is a God object that knows the internals of each
        of the pieces of the heap. This undermines the encapsulation I'm trying
        to achieve by splitting concepts into different classes.
        
        As an alternative, I've given each class a forEach iteration function,
        which takes a functor as an argument. Now, each class just needs to
        know how to iterate the things it knows about.

        * GNUmakefile.am:
        * JavaScriptCore.exp:
        * JavaScriptCore.gypi:
        * JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj: Removed CollectorHeapIterator.

        * debugger/Debugger.cpp:
        (JSC::Recompiler::Recompiler):
        (JSC::Recompiler::~Recompiler):
        (JSC::Recompiler::operator()):
        (JSC::Debugger::recompileAllJSFunctions): Updated to use forEach interface
        instead of an iterator.

        * runtime/CollectorHeapIterator.h: Removed.

        * runtime/Heap.cpp:
        (JSC::TypeCounter::TypeCounter):
        (JSC::TypeCounter::typeName):
        (JSC::TypeCounter::operator()):
        (JSC::TypeCounter::take):
        (JSC::Heap::protectedObjectTypeCounts):
        (JSC::Heap::objectTypeCounts): Added forEach and removed iterator.

        * runtime/Heap.h:
        (JSC::Heap::forEach):
        * runtime/JSGlobalData.cpp:
        (JSC::Recompiler::operator()):
        (JSC::JSGlobalData::recompileAllJSFunctions):

        * runtime/MarkedBlock.h:
        (JSC::MarkedBlock::forEach): Added forEach. Removed friend declaration
        for CollectorHeapIterator. Now, we can make all our data private and
        change it without breaking any other classes.

        * runtime/MarkedSpace.cpp:
        * runtime/MarkedSpace.h:
        (JSC::MarkedSpace::forEach): Added forEach and removed iterator.
2011-02-11  Geoffrey Garen  <ggaren@apple.com>

        Reviewed by Oliver Hunt.

        A little more encapsulation for the heap: Removed CollectorHeapIterator
        https://bugs.webkit.org/show_bug.cgi?id=54298

        * WebCoreStatistics.cpp:
        (WebCoreStatistics::javaScriptProtectedObjectTypeCounts):
2011-02-11  Geoffrey Garen  <ggaren@apple.com>

        Reviewed by Oliver Hunt.

        A little more encapsulation for the heap: Removed CollectorHeapIterator
        https://bugs.webkit.org/show_bug.cgi?id=54298

        * Misc/WebCoreStatistics.mm:
        (+[WebCoreStatistics javaScriptProtectedObjectTypeCounts]):
        (+[WebCoreStatistics javaScriptObjectTypeCounts]): Updated for new typedef.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@78382 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/JavaScriptCore/runtime/Heap.cpp b/Source/JavaScriptCore/runtime/Heap.cpp
index 88c005a..c05233c 100644
--- a/Source/JavaScriptCore/runtime/Heap.cpp
+++ b/Source/JavaScriptCore/runtime/Heap.cpp
@@ -22,7 +22,6 @@
 #include "Heap.h"
 
 #include "CodeBlock.h"
-#include "CollectorHeapIterator.h"
 #include "ConservativeSet.h"
 #include "GCActivityCallback.h"
 #include "GCHandle.h"
@@ -321,7 +320,23 @@
     return m_protectedValues.size();
 }
 
-static const char* typeName(JSCell* cell)
+class TypeCounter {
+public:
+    TypeCounter();
+    void operator()(JSCell*);
+    PassOwnPtr<TypeCountSet> take();
+    
+private:
+    const char* typeName(JSCell*);
+    OwnPtr<TypeCountSet> m_typeCountSet;
+};
+
+inline TypeCounter::TypeCounter()
+    : m_typeCountSet(new TypeCountSet)
+{
+}
+
+inline const char* TypeCounter::typeName(JSCell* cell)
 {
     if (cell->isString())
         return "string";
@@ -337,27 +352,32 @@
     return info ? info->className : "Object";
 }
 
-HashCountedSet<const char*>* Heap::protectedObjectTypeCounts()
+inline void TypeCounter::operator()(JSCell* cell)
 {
-    HashCountedSet<const char*>* counts = new HashCountedSet<const char*>;
+    m_typeCountSet->add(typeName(cell));
+}
+
+inline PassOwnPtr<TypeCountSet> TypeCounter::take()
+{
+    return m_typeCountSet.release();
+}
+
+PassOwnPtr<TypeCountSet> Heap::protectedObjectTypeCounts()
+{
+    TypeCounter typeCounter;
 
     ProtectCountSet::iterator end = m_protectedValues.end();
     for (ProtectCountSet::iterator it = m_protectedValues.begin(); it != end; ++it)
-        counts->add(typeName(it->first));
+        typeCounter(it->first);
 
-    return counts;
+    return typeCounter.take();
 }
 
-HashCountedSet<const char*>* Heap::objectTypeCounts()
+PassOwnPtr<TypeCountSet> Heap::objectTypeCounts()
 {
-    HashCountedSet<const char*>* counts = new HashCountedSet<const char*>;
-
-    LiveObjectIterator it = primaryHeapBegin();
-    LiveObjectIterator heapEnd = primaryHeapEnd();
-    for ( ; it != heapEnd; ++it)
-        counts->add(typeName(*it));
-
-    return counts;
+    TypeCounter typeCounter;
+    forEach(typeCounter);
+    return typeCounter.take();
 }
 
 bool Heap::isBusy()
@@ -395,16 +415,6 @@
     (*m_activityCallback)();
 }
 
-LiveObjectIterator Heap::primaryHeapBegin()
-{
-    return m_markedSpace.primaryHeapBegin();
-}
-
-LiveObjectIterator Heap::primaryHeapEnd()
-{
-    return m_markedSpace.primaryHeapEnd();
-}
-
 void Heap::setActivityCallback(PassOwnPtr<GCActivityCallback> activityCallback)
 {
     m_activityCallback = activityCallback;