JavaScriptCore: Added an SPI for asking about all the different live objects on the heap.
Useful for memory debugging.

Reviewed by Oliver Hunt.

* JavaScriptCore.exp: Export the new SPI.

* runtime/Collector.cpp:
(JSC::typeName): Use a little capitalization. Don't crash in the case of
a non-object cell, since it might just be an uninitialized cell.

(JSC::Heap::objectTypeCounts): The new SPI.

* runtime/Collector.h:
* runtime/CollectorHeapIterator.h:
(JSC::CollectorHeapIterator::advance):
(JSC::LiveObjectIterator::operator++):
(JSC::DeadObjectIterator::operator++):
(JSC::ObjectIterator::operator++): Made 2 tweaks to these iterators:
(1) Skip the last cell in the block, since it's a dummy sentinel, and
we don't want it to confuse the object count; (2) Fixed a logic error
in LiveObjectIterator that could cause it to iterate dead objects if
m_block were equal to m_heap.nextBlock and m_cell were less than
m_heap.nextCell. No test for this since I can't think of a way that this
could make WebKit behave badly.

WebKit/mac: Exported some new JavaScript heap introspection.

Reviewed by Oliver Hunt.

* Misc/WebCoreStatistics.h:
* Misc/WebCoreStatistics.mm:
(+[WebCoreStatistics javaScriptObjectTypeCounts]): Just like
javaScriptProtectedObjectTypeCounts, except this function enumerates all
live objects, not just protected objects.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@54672 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/JavaScriptCore/runtime/Collector.cpp b/JavaScriptCore/runtime/Collector.cpp
index 63139a2..a391d267 100644
--- a/JavaScriptCore/runtime/Collector.cpp
+++ b/JavaScriptCore/runtime/Collector.cpp
@@ -1197,12 +1197,13 @@
         return "number";
 #endif
     if (cell->isGetterSetter())
-        return "gettersetter";
+        return "Getter-Setter";
     if (cell->isAPIValueWrapper())
-        return "value wrapper";
+        return "API wrapper";
     if (cell->isPropertyNameIterator())
-        return "for-in iterator";
-    ASSERT(cell->isObject());
+        return "For-in iterator";
+    if (!cell->isObject())
+        return "[empty cell]";
     const ClassInfo* info = cell->classInfo();
     return info ? info->className : "Object";
 }
@@ -1218,6 +1219,18 @@
     return counts;
 }
 
+HashCountedSet<const char*>* 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;
+}
+
 bool Heap::isBusy()
 {
     return m_heap.operationInProgress != NoOperation;