Ignore:
Timestamp:
Mar 9, 2017, 2:39:09 PM (8 years ago)
Author:
[email protected]
Message:

Refactoring some HeapVerifier code.
https://bugs.webkit.org/show_bug.cgi?id=169443

Reviewed by Filip Pizlo.

Renamed LiveObjectData to CellProfile.
Renamed LiveObjectList to CellList.
Moved CellProfile.*, CellList.*, and HeapVerifier.* from the heap folder to the tools folder.
Updated the HeapVerifier to handle JSCells instead of just JSObjects.

This is in preparation for subsequent patches to fix up the HeapVerifier for service again.

  • CMakeLists.txt:
  • JavaScriptCore.xcodeproj/project.pbxproj:
  • heap/Heap.cpp:

(JSC::Heap::runBeginPhase):
(JSC::Heap::runEndPhase):

  • heap/HeapVerifier.cpp: Removed.
  • heap/HeapVerifier.h: Removed.
  • heap/LiveObjectData.h: Removed.
  • heap/LiveObjectList.cpp: Removed.
  • heap/LiveObjectList.h: Removed.
  • tools/CellList.cpp: Copied from Source/JavaScriptCore/heap/LiveObjectList.cpp.

(JSC::CellList::findCell):
(JSC::LiveObjectList::findObject): Deleted.

  • tools/CellList.h: Copied from Source/JavaScriptCore/heap/LiveObjectList.h.

(JSC::CellList::CellList):
(JSC::CellList::reset):
(JSC::LiveObjectList::LiveObjectList): Deleted.
(JSC::LiveObjectList::reset): Deleted.

  • tools/CellProfile.h: Copied from Source/JavaScriptCore/heap/LiveObjectData.h.

(JSC::CellProfile::CellProfile):
(JSC::LiveObjectData::LiveObjectData): Deleted.

  • tools/HeapVerifier.cpp: Copied from Source/JavaScriptCore/heap/HeapVerifier.cpp.

(JSC::GatherCellFunctor::GatherCellFunctor):
(JSC::GatherCellFunctor::visit):
(JSC::GatherCellFunctor::operator()):
(JSC::HeapVerifier::gatherLiveCells):
(JSC::HeapVerifier::cellListForGathering):
(JSC::trimDeadCellsFromList):
(JSC::HeapVerifier::trimDeadCells):
(JSC::HeapVerifier::verifyButterflyIsInStorageSpace):
(JSC::HeapVerifier::reportCell):
(JSC::HeapVerifier::checkIfRecorded):
(JSC::GatherLiveObjFunctor::GatherLiveObjFunctor): Deleted.
(JSC::GatherLiveObjFunctor::visit): Deleted.
(JSC::GatherLiveObjFunctor::operator()): Deleted.
(JSC::HeapVerifier::gatherLiveObjects): Deleted.
(JSC::HeapVerifier::liveObjectListForGathering): Deleted.
(JSC::trimDeadObjectsFromList): Deleted.
(JSC::HeapVerifier::trimDeadObjects): Deleted.
(JSC::HeapVerifier::reportObject): Deleted.

  • tools/HeapVerifier.h: Copied from Source/JavaScriptCore/heap/HeapVerifier.h.
File:
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/tools/HeapVerifier.cpp

    r213674 r213675  
    6767}
    6868
    69 struct GatherLiveObjFunctor : MarkedBlock::CountFunctor {
    70     GatherLiveObjFunctor(LiveObjectList& list)
     69struct GatherCellFunctor : MarkedBlock::CountFunctor {
     70    GatherCellFunctor(CellList& list)
    7171        : m_list(list)
    7272    {
    73         ASSERT(!list.liveObjects.size());
     73        ASSERT(!list.liveCells.size());
    7474    }
    7575
    7676    inline void visit(JSCell* cell)
    7777    {
    78         if (!cell->isObject())
    79             return;       
    80         LiveObjectData data(asObject(cell));
    81         m_list.liveObjects.append(data);
     78        CellProfile profile(cell);
     79        m_list.liveCells.append(profile);
    8280    }
    8381
     
    8785            // FIXME: This const_cast exists because this isn't a C++ lambda.
    8886            // https://bugs.webkit.org/show_bug.cgi?id=159644
    89             const_cast<GatherLiveObjFunctor*>(this)->visit(static_cast<JSCell*>(cell));
     87            const_cast<GatherCellFunctor*>(this)->visit(static_cast<JSCell*>(cell));
    9088        }
    9189        return IterationStatus::Continue;
    9290    }
    9391
    94     LiveObjectList& m_list;
     92    CellList& m_list;
    9593};
    9694
    97 void HeapVerifier::gatherLiveObjects(HeapVerifier::Phase phase)
     95void HeapVerifier::gatherLiveCells(HeapVerifier::Phase phase)
    9896{
    9997    Heap* heap = m_heap;
    100     LiveObjectList& list = *liveObjectListForGathering(phase);
     98    CellList& list = *cellListForGathering(phase);
    10199
    102100    HeapIterationScope iterationScope(*heap);
    103101    list.reset();
    104     GatherLiveObjFunctor functor(list);
     102    GatherCellFunctor functor(list);
    105103    heap->m_objectSpace.forEachLiveCell(iterationScope, functor);
    106104}
    107105
    108 LiveObjectList* HeapVerifier::liveObjectListForGathering(HeapVerifier::Phase phase)
     106CellList* HeapVerifier::cellListForGathering(HeapVerifier::Phase phase)
    109107{
    110108    switch (phase) {
     
    115113    case Phase::BeforeGC:
    116114    case Phase::AfterGC:
    117         // We should not be gathering live objects during these phases.
     115        // We should not be gathering live cells during these phases.
    118116        break;
    119117    }
     
    122120}
    123121
    124 static void trimDeadObjectsFromList(HashSet<JSObject*>& knownLiveSet, LiveObjectList& list)
    125 {
    126     if (!list.hasLiveObjects)
     122static void trimDeadCellsFromList(HashSet<JSCell*>& knownLiveSet, CellList& list)
     123{
     124    if (!list.hasLiveCells)
    127125        return;
    128126
    129     size_t liveObjectsFound = 0;
    130     for (auto& objData : list.liveObjects) {
    131         if (objData.isConfirmedDead)
    132             continue; // Don't "resurrect" known dead objects.
    133         if (!knownLiveSet.contains(objData.obj)) {
    134             objData.isConfirmedDead = true;
     127    size_t liveCellsFound = 0;
     128    for (auto& cellProfile : list.liveCells) {
     129        if (cellProfile.isConfirmedDead)
     130            continue; // Don't "resurrect" known dead cells.
     131        if (!knownLiveSet.contains(cellProfile.cell)) {
     132            cellProfile.isConfirmedDead = true;
    135133            continue;
    136134        }
    137         liveObjectsFound++;
    138     }
    139     list.hasLiveObjects = !!liveObjectsFound;
    140 }
    141 
    142 void HeapVerifier::trimDeadObjects()
    143 {
    144     HashSet<JSObject*> knownLiveSet;
    145 
    146     LiveObjectList& after = currentCycle().after;
    147     for (auto& objData : after.liveObjects)
    148         knownLiveSet.add(objData.obj);
    149 
    150     trimDeadObjectsFromList(knownLiveSet, currentCycle().before);
     135        liveCellsFound++;
     136    }
     137    list.hasLiveCells = !!liveCellsFound;
     138}
     139
     140void HeapVerifier::trimDeadCells()
     141{
     142    HashSet<JSCell*> knownLiveSet;
     143
     144    CellList& after = currentCycle().after;
     145    for (auto& cellProfile : after.liveCells)
     146        knownLiveSet.add(cellProfile.cell);
     147
     148    trimDeadCellsFromList(knownLiveSet, currentCycle().before);
    151149
    152150    for (int i = -1; i > -m_numberOfCycles; i--) {
    153         trimDeadObjectsFromList(knownLiveSet, cycleForIndex(i).before);
    154         trimDeadObjectsFromList(knownLiveSet, cycleForIndex(i).after);
    155     }
    156 }
    157 
    158 bool HeapVerifier::verifyButterflyIsInStorageSpace(Phase, LiveObjectList&)
     151        trimDeadCellsFromList(knownLiveSet, cycleForIndex(i).before);
     152        trimDeadCellsFromList(knownLiveSet, cycleForIndex(i).after);
     153    }
     154}
     155
     156bool HeapVerifier::verifyButterflyIsInStorageSpace(Phase, CellList&)
    159157{
    160158    // FIXME: Make this work again. https://bugs.webkit.org/show_bug.cgi?id=161752
     
    169167}
    170168
    171 void HeapVerifier::reportObject(LiveObjectData& objData, int cycleIndex, HeapVerifier::GCCycle& cycle, LiveObjectList& list)
    172 {
    173     JSObject* obj = objData.obj;
    174 
    175     if (objData.isConfirmedDead) {
    176         dataLogF("FOUND dead obj %p in GC[%d] %s list '%s'\n",
    177             obj, cycleIndex, collectionScopeName(cycle.scope), list.name);
     169void HeapVerifier::reportCell(CellProfile& cellProfile, int cycleIndex, HeapVerifier::GCCycle& cycle, CellList& list)
     170{
     171    JSCell* cell = cellProfile.cell;
     172
     173    if (cellProfile.isConfirmedDead) {
     174        dataLogF("FOUND dead cell %p in GC[%d] %s list '%s'\n",
     175            cell, cycleIndex, collectionScopeName(cycle.scope), list.name);
    178176        return;
    179177    }
    180178
    181     Structure* structure = obj->structure();
    182     Butterfly* butterfly = obj->butterfly();
    183     void* butterflyBase = butterfly->base(structure);
    184 
    185     dataLogF("FOUND obj %p type '%s' butterfly %p (base %p) in GC[%d] %s list '%s'\n",
    186         obj, structure->classInfo()->className,
    187         butterfly, butterflyBase,
    188         cycleIndex, collectionScopeName(cycle.scope), list.name);
    189 }
    190 
    191 void HeapVerifier::checkIfRecorded(JSObject* obj)
     179    if (cell->isObject()) {
     180        JSObject* object = static_cast<JSObject*>(cell);
     181        Structure* structure = object->structure();
     182        Butterfly* butterfly = object->butterfly();
     183        void* butterflyBase = butterfly->base(structure);
     184
     185        dataLogF("FOUND object %p type '%s' butterfly %p (base %p) in GC[%d] %s list '%s'\n",
     186            object, structure->classInfo()->className,
     187            butterfly, butterflyBase,
     188            cycleIndex, collectionScopeName(cycle.scope), list.name);
     189    } else {
     190        Structure* structure = cell->structure();
     191        dataLogF("FOUND cell %p type '%s' in GC[%d] %s list '%s'\n",
     192            cell, structure->classInfo()->className,
     193            cycleIndex, collectionScopeName(cycle.scope), list.name);
     194    }
     195}
     196
     197void HeapVerifier::checkIfRecorded(JSCell* cell)
    192198{
    193199    bool found = false;
     
    195201    for (int cycleIndex = 0; cycleIndex > -m_numberOfCycles; cycleIndex--) {
    196202        GCCycle& cycle = cycleForIndex(cycleIndex);
    197         LiveObjectList& beforeList = cycle.before;
    198         LiveObjectList& afterList = cycle.after;
    199 
    200         LiveObjectData* objData;
    201         objData = beforeList.findObject(obj);
    202         if (objData) {
    203             reportObject(*objData, cycleIndex, cycle, beforeList);
     203        CellList& beforeList = cycle.before;
     204        CellList& afterList = cycle.after;
     205
     206        CellProfile* profile;
     207        profile = beforeList.findCell(cell);
     208        if (profile) {
     209            reportCell(*profile, cycleIndex, cycle, beforeList);
    204210            found = true;
    205211        }
    206         objData = afterList.findObject(obj);
    207         if (objData) {
    208             reportObject(*objData, cycleIndex, cycle, afterList);
     212        profile = afterList.findCell(cell);
     213        if (profile) {
     214            reportCell(*profile, cycleIndex, cycle, afterList);
    209215            found = true;
    210216        }
     
    212218
    213219    if (!found)
    214         dataLogF("obj %p NOT FOUND\n", obj);
     220        dataLogF("cell %p NOT FOUND\n", cell);
    215221}
    216222
Note: See TracChangeset for help on using the changeset viewer.