Changeset 54672 in webkit for trunk/JavaScriptCore


Ignore:
Timestamp:
Feb 11, 2010, 1:28:52 PM (15 years ago)
Author:
[email protected]
Message:

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

Reviewed by Oliver Hunt.

  • 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.

Location:
trunk/JavaScriptCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r54655 r54672  
     12010-02-10  Geoffrey Garen  <[email protected]>
     2
     3        Reviewed by Oliver Hunt.
     4
     5        Added an SPI for asking about all the different live objects on the heap.
     6        Useful for memory debugging.
     7
     8        * JavaScriptCore.exp: Export the new SPI.
     9
     10        * runtime/Collector.cpp:
     11        (JSC::typeName): Use a little capitalization. Don't crash in the case of
     12        a non-object cell, since it might just be an uninitialized cell.
     13
     14        (JSC::Heap::objectTypeCounts): The new SPI.
     15
     16        * runtime/Collector.h:
     17        * runtime/CollectorHeapIterator.h:
     18        (JSC::CollectorHeapIterator::advance):
     19        (JSC::LiveObjectIterator::operator++):
     20        (JSC::DeadObjectIterator::operator++):
     21        (JSC::ObjectIterator::operator++): Made 2 tweaks to these iterators:
     22        (1) Skip the last cell in the block, since it's a dummy sentinel, and
     23        we don't want it to confuse the object count; (2) Fixed a logic error
     24        in LiveObjectIterator that could cause it to iterate dead objects if
     25        m_block were equal to m_heap.nextBlock and m_cell were less than
     26        m_heap.nextCell. No test for this since I can't think of a way that this
     27        could make WebKit behave badly.
     28
    1292010-02-11  Steve Block  <[email protected]>
    230
  • trunk/JavaScriptCore/JavaScriptCore.exp

    r54531 r54672  
    191191__ZN3JSC4Heap14primaryHeapEndEv
    192192__ZN3JSC4Heap15recordExtraCostEm
     193__ZN3JSC4Heap16objectTypeCountsEv
    193194__ZN3JSC4Heap16primaryHeapBeginEv
    194195__ZN3JSC4Heap17collectAllGarbageEv
     
    300301__ZN3WTF10fastCallocEmm
    301302__ZN3WTF10fastMallocEm
     303__ZN3WTF10fastStrDupEPKc
    302304__ZN3WTF11currentTimeEv
    303305__ZN3WTF11fastReallocEPvm
     
    348350__ZN3WTF8CollatorD1Ev
    349351__ZN3WTF8fastFreeEPv
    350 __ZN3WTF10fastStrDupEPKc
    351352__ZN3WTF8msToYearEd
     353__ZN3WTF9ByteArray6createEm
    352354__ZN3WTF9dayInYearEdi
    353 __ZN3WTF9ByteArray6createEm
    354355__ZNK3JSC10JSFunction23isHostFunctionNonInlineEv
    355356__ZNK3JSC11Interpreter14retrieveCallerEPNS_9ExecStateEPNS_16InternalFunctionE
  • trunk/JavaScriptCore/runtime/Collector.cpp

    r53572 r54672  
    11981198#endif
    11991199    if (cell->isGetterSetter())
    1200         return "gettersetter";
     1200        return "Getter-Setter";
    12011201    if (cell->isAPIValueWrapper())
    1202         return "value wrapper";
     1202        return "API wrapper";
    12031203    if (cell->isPropertyNameIterator())
    1204         return "for-in iterator";
    1205     ASSERT(cell->isObject());
     1204        return "For-in iterator";
     1205    if (!cell->isObject())
     1206        return "[empty cell]";
    12061207    const ClassInfo* info = cell->classInfo();
    12071208    return info ? info->className : "Object";
     
    12151216    for (ProtectCountSet::iterator it = m_protectedValues.begin(); it != end; ++it)
    12161217        counts->add(typeName(it->first));
     1218
     1219    return counts;
     1220}
     1221
     1222HashCountedSet<const char*>* Heap::objectTypeCounts()
     1223{
     1224    HashCountedSet<const char*>* counts = new HashCountedSet<const char*>;
     1225
     1226    LiveObjectIterator it = primaryHeapBegin();
     1227    LiveObjectIterator heapEnd = primaryHeapEnd();
     1228    for ( ; it != heapEnd; ++it)
     1229        counts->add(typeName(*it));
    12171230
    12181231    return counts;
  • trunk/JavaScriptCore/runtime/Collector.h

    r52791 r54672  
    101101        size_t protectedGlobalObjectCount();
    102102        HashCountedSet<const char*>* protectedObjectTypeCounts();
     103        HashCountedSet<const char*>* objectTypeCounts();
    103104
    104105        void registerThread(); // Only needs to be called by clients that can use the same heap from multiple threads.
  • trunk/JavaScriptCore/runtime/CollectorHeapIterator.h

    r52176 r54672  
    3939    protected:
    4040        CollectorHeapIterator(CollectorHeap&, size_t startBlock, size_t startCell);
    41         void advance(size_t cellsPerBlock);
     41        void advance(size_t max);
    4242
    4343        CollectorHeap& m_heap;
     
    8181    }
    8282   
    83     inline void CollectorHeapIterator::advance(size_t cellsPerBlock)
     83    // Iterators advance up to the next-to-last -- and not the last -- cell in a
     84    // block, since the last cell is a dummy sentinel.
     85    inline void CollectorHeapIterator::advance(size_t max)
    8486    {
    8587        ++m_cell;
    86         if (m_cell == cellsPerBlock) {
     88        if (m_cell == max) {
    8789            m_cell = 0;
    8890            ++m_block;
     
    98100    inline LiveObjectIterator& LiveObjectIterator::operator++()
    99101    {
    100         if (m_block < m_heap.nextBlock || m_cell < m_heap.nextCell) {
    101             advance(HeapConstants::cellsPerBlock);
     102        advance(HeapConstants::cellsPerBlock - 1);
     103        if (m_block < m_heap.nextBlock || (m_block == m_heap.nextBlock && m_cell < m_heap.nextCell))
    102104            return *this;
    103         }
    104105
    105         do {
    106             advance(HeapConstants::cellsPerBlock);
    107         } while (m_block < m_heap.usedBlocks && !m_heap.blocks[m_block]->marked.get(m_cell));
     106        while (m_block < m_heap.usedBlocks && !m_heap.blocks[m_block]->marked.get(m_cell))
     107            advance(HeapConstants::cellsPerBlock - 1);
    108108        return *this;
    109109    }
     
    118118    {
    119119        do {
    120             advance(HeapConstants::cellsPerBlock);
     120            advance(HeapConstants::cellsPerBlock - 1);
    121121            ASSERT(m_block > m_heap.nextBlock || (m_block == m_heap.nextBlock && m_cell >= m_heap.nextCell));
    122122        } while (m_block < m_heap.usedBlocks && m_heap.blocks[m_block]->marked.get(m_cell));
     
    132132    inline ObjectIterator& ObjectIterator::operator++()
    133133    {
    134         advance(HeapConstants::cellsPerBlock);
     134        advance(HeapConstants::cellsPerBlock - 1);
    135135        return *this;
    136136    }
Note: See TracChangeset for help on using the changeset viewer.