Ignore:
Timestamp:
Sep 22, 2015, 6:35:49 PM (10 years ago)
Author:
[email protected]
Message:

GCThreadSharedData is just a bad way of saying Heap
https://bugs.webkit.org/show_bug.cgi?id=149435

Reviewed by Mark Lam.

This removes the GCThreadSharedData class and moves its members into Heap. This is a net
simplification since GCThreadSharedData had a 1-to-1 mapping to Heap and the two classes had a
vast contract with a lot of interdependencies. Heap would call a lot of GCThreadSharedData
methods; now a lot of those are inlined since they were only called from the one place in Heap.
This makes it a lot easier to see what is going on. For example, you no longer have to look at
code in two places (Heap and GCThreadSharedData) to figure out the timing and synchronization
of GC phases - all of that code is in Heap now.

This also removes weird indirections in other places. It used to be that a lot of GC helper
classes woud have a pointer to GCThreadSharedData, and then would use that to get to Heap, VM,
and the visitors. Now these helpers just point to Heap.

I think that GCThreadSharedData was only useful for defining the set of things that we need to
know to collect garbage. That's how we decided if something would go into GCThreadSharedData
instead of Heap. But I think that separating things into multiple classes usually makes the
code less hackable, so there should be a very high bar for doing this in a way that produces a
1-to-1 mapping between two classes - where one instance of one of the classes is always paired
with exactly one instance of the other class and vice-versa.

(JSC::CopyVisitor::CopyVisitor):
(JSC::CopyVisitor::copyFromShared):

  • heap/CopyVisitor.h:
  • heap/CopyVisitorInlines.h:

(JSC::CopyVisitor::allocateNewSpaceSlow):
(JSC::CopyVisitor::startCopying):
(JSC::CopyVisitor::doneCopying):
(JSC::CopyVisitor::didCopy):

  • heap/GCThread.cpp:

(JSC::GCThread::GCThread):
(JSC::GCThread::waitForNextPhase):
(JSC::GCThread::gcThreadMain):

  • heap/GCThread.h:
  • heap/GCThreadSharedData.cpp: Removed.
  • heap/GCThreadSharedData.h: Removed.
  • heap/Heap.cpp:

(JSC::Heap::Heap):
(JSC::Heap::~Heap):
(JSC::Heap::isPagedOut):
(JSC::Heap::markRoots):
(JSC::Heap::copyBackingStores):
(JSC::Heap::updateObjectCounts):
(JSC::Heap::resetVisitors):
(JSC::Heap::objectCount):
(JSC::Heap::sweepNextLogicallyEmptyWeakBlock):
(JSC::Heap::threadVisitCount):
(JSC::Heap::threadBytesVisited):
(JSC::Heap::threadBytesCopied):
(JSC::Heap::startNextPhase):
(JSC::Heap::endCurrentPhase):

  • heap/Heap.h:
  • heap/HeapInlines.h:

(JSC::Heap::unregisterWeakGCMap):
(JSC::Heap::getNextBlocksToCopy):

  • heap/ListableHandler.h:
  • heap/SlotVisitor.cpp:

(JSC::SlotVisitor::SlotVisitor):
(JSC::SlotVisitor::didStartMarking):
(JSC::SlotVisitor::reset):
(JSC::SlotVisitor::donateKnownParallel):
(JSC::SlotVisitor::drain):
(JSC::SlotVisitor::drainFromShared):
(JSC::SlotVisitor::mergeOpaqueRoots):
(JSC::SlotVisitor::harvestWeakReferences):
(JSC::SlotVisitor::finalizeUnconditionalFinalizers):

  • heap/SlotVisitor.h:

(JSC::SlotVisitor::markStack):
(JSC::SlotVisitor::isEmpty):
(JSC::SlotVisitor::sharedData): Deleted.

  • heap/SlotVisitorInlines.h:

(JSC::SlotVisitor::addWeakReferenceHarvester):
(JSC::SlotVisitor::addUnconditionalFinalizer):
(JSC::SlotVisitor::addOpaqueRoot):
(JSC::SlotVisitor::containsOpaqueRoot):
(JSC::SlotVisitor::containsOpaqueRootTriState):
(JSC::SlotVisitor::opaqueRootCount):
(JSC::SlotVisitor::mergeOpaqueRootsIfNecessary):
(JSC::SlotVisitor::copyLater):
(JSC::SlotVisitor::heap):
(JSC::SlotVisitor::vm):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/heap/Heap.h

    r190113 r190151  
    22 *  Copyright (C) 1999-2000 Harri Porten ([email protected])
    33 *  Copyright (C) 2001 Peter Kelly ([email protected])
    4  *  Copyright (C) 2003-2009, 2013-2014 Apple Inc. All rights reserved.
     4 *  Copyright (C) 2003-2009, 2013-2015 Apple Inc. All rights reserved.
    55 *
    66 *  This library is free software; you can redistribute it and/or
     
    2727#include "CopyVisitor.h"
    2828#include "GCIncomingRefCountedSet.h"
    29 #include "GCThreadSharedData.h"
     29#include "GCThread.h"
    3030#include "HandleSet.h"
    3131#include "HandleStack.h"
    3232#include "HeapOperation.h"
    3333#include "JITStubRoutineSet.h"
     34#include "ListableHandler.h"
    3435#include "MarkedAllocator.h"
    3536#include "MarkedBlock.h"
     
    3940#include "SlotVisitor.h"
    4041#include "StructureIDTable.h"
     42#include "UnconditionalFinalizer.h"
    4143#include "WeakHandleOwner.h"
     44#include "WeakReferenceHarvester.h"
    4245#include "WriteBarrierBuffer.h"
    4346#include "WriteBarrierSupport.h"
     
    8689    friend class JIT;
    8790    friend class DFG::SpeculativeJIT;
    88     friend class GCThreadSharedData;
    8991    static Heap* heap(const JSValue); // 0 for immediate values
    9092    static Heap* heap(const JSCell*);
     
    244246    friend class GCAwareJITStubRoutine;
    245247    friend class GCLogging;
     248    friend class GCThread;
    246249    friend class HandleSet;
    247250    friend class HeapVerifier;
     
    340343    void decrementDeferralDepthAndGCIfNeeded();
    341344
     345    size_t threadVisitCount();
     346    size_t threadBytesVisited();
     347    size_t threadBytesCopied();
     348    size_t threadDupStrings();
     349
     350    void getNextBlocksToCopy(size_t&, size_t&);
     351    void startNextPhase(GCPhase);
     352    void endCurrentPhase();
     353
    342354    const HeapType m_heapType;
    343355    const size_t m_ramSize;
     
    372384    MachineThreads m_machineThreads;
    373385   
    374     GCThreadSharedData m_sharedData;
    375386    SlotVisitor m_slotVisitor;
    376387    CopyVisitor m_copyVisitor;
     
    410421
    411422    HashMap<void*, std::function<void()>> m_weakGCMaps;
     423
     424    bool m_shouldHashCons { false };
     425
     426    Vector<GCThread*> m_gcThreads;
     427
     428    Lock m_markingMutex;
     429    Condition m_markingConditionVariable;
     430    MarkStackArray m_sharedMarkStack;
     431    unsigned m_numberOfActiveParallelMarkers { 0 };
     432    bool m_parallelMarkersShouldExit { false };
     433
     434    Lock m_opaqueRootsMutex;
     435    HashSet<void*> m_opaqueRoots;
     436
     437    Lock m_copyLock;
     438    Vector<CopiedBlock*> m_blocksToCopy;
     439    size_t m_copyIndex { 0 };
     440    static const size_t s_blockFragmentLength = 32;
     441
     442    Lock m_phaseMutex;
     443    Condition m_phaseConditionVariable;
     444    Condition m_activityConditionVariable;
     445    unsigned m_numberOfActiveGCThreads { 0 };
     446    bool m_gcThreadsShouldWait { false };
     447    GCPhase m_currentPhase { NoPhase };
     448
     449    ListableHandler<WeakReferenceHarvester>::List m_weakReferenceHarvesters;
     450    ListableHandler<UnconditionalFinalizer>::List m_unconditionalFinalizers;
    412451};
    413452
Note: See TracChangeset for help on using the changeset viewer.