Changeset 83011 in webkit


Ignore:
Timestamp:
Apr 5, 2011 8:44:48 PM (13 years ago)
Author:
ggaren@apple.com
Message:

2011-04-05 Geoffrey Garen <ggaren@apple.com>

Reviewed by Oliver Hunt.

Introduced the concept of opaque roots, in preparation for marking the DOM with them
https://bugs.webkit.org/show_bug.cgi?id=57903

  • collector/handles/HandleHeap.cpp: (JSC::isValidWeakHandle): Factored out a helper function for ASSERTs.

(JSC::WeakHandleOwner::~WeakHandleOwner): Moved from header to avoid
weak linkage problems.

(JSC::WeakHandleOwner::isReachableFromOpaqueRoots): New callback.
Currently unused.

(JSC::WeakHandleOwner::finalize): Switched from pure virtual to a
default empty implementation, since not all clients necessarily want
or need non-trivial finalizers.

(JSC::HandleHeap::markWeakHandles): Split updateWeakHandles into two
passes. The first pass marks all reachable weak handles. The second pass
finalizes all unreachable weak handles. This must be two passes because
we don't know the set of finalizable weak handles until we're done
marking all weak handles.

(JSC::HandleHeap::finalizeWeakHandles): Use new helper function.

  • collector/handles/HandleHeap.h: Ditto.
  • runtime/Heap.cpp: (JSC::Heap::destroy): (JSC::Heap::markRoots): (JSC::Heap::reset): Split out handle marking from handle finalization.
  • runtime/MarkStack.cpp: (JSC::MarkStack::reset):
  • runtime/MarkStack.h: (JSC::MarkStack::addOpaqueRoot): (JSC::MarkStack::containsOpaqueRoot): (JSC::MarkStack::opaqueRootCount): (JSC::HeapRootMarker::markStack): New helper functions for managing the set of opaque roots.
  • runtime/WeakGCMap.h: (JSC::WeakGCMap::finalize): Renamed to match parent class declaration.
Location:
trunk/Source/JavaScriptCore
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r82988 r83011  
     12011-04-05  Geoffrey Garen  <ggaren@apple.com>
     2
     3        Reviewed by Oliver Hunt.
     4
     5        Introduced the concept of opaque roots, in preparation for marking the DOM with them
     6        https://bugs.webkit.org/show_bug.cgi?id=57903
     7
     8        * JavaScriptCore.exp: Who likes export files? I do!
     9
     10        * collector/handles/HandleHeap.cpp:
     11        (JSC::isValidWeakHandle): Factored out a helper function for ASSERTs.
     12
     13        (JSC::WeakHandleOwner::~WeakHandleOwner): Moved from header to avoid
     14        weak linkage problems.
     15
     16        (JSC::WeakHandleOwner::isReachableFromOpaqueRoots): New callback.
     17        Currently unused.
     18
     19        (JSC::WeakHandleOwner::finalize): Switched from pure virtual to a
     20        default empty implementation, since not all clients necessarily want
     21        or need non-trivial finalizers.
     22
     23        (JSC::HandleHeap::markWeakHandles): Split updateWeakHandles into two
     24        passes. The first pass marks all reachable weak handles. The second pass
     25        finalizes all unreachable weak handles. This must be two passes because
     26        we don't know the set of finalizable weak handles until we're done
     27        marking all weak handles.
     28
     29        (JSC::HandleHeap::finalizeWeakHandles): Use new helper function.
     30
     31        * collector/handles/HandleHeap.h: Ditto.
     32
     33        * runtime/Heap.cpp:
     34        (JSC::Heap::destroy):
     35        (JSC::Heap::markRoots):
     36        (JSC::Heap::reset): Split out handle marking from handle finalization.
     37
     38        * runtime/MarkStack.cpp:
     39        (JSC::MarkStack::reset):
     40        * runtime/MarkStack.h:
     41        (JSC::MarkStack::addOpaqueRoot):
     42        (JSC::MarkStack::containsOpaqueRoot):
     43        (JSC::MarkStack::opaqueRootCount):
     44        (JSC::HeapRootMarker::markStack): New helper functions for managing the
     45        set of opaque roots.
     46
     47        * runtime/WeakGCMap.h:
     48        (JSC::WeakGCMap::finalize): Renamed to match parent class declaration.
     49
    1502011-04-05  Balazs Kelemen  <kbalazs@webkit.org>
    251
  • trunk/Source/JavaScriptCore/JavaScriptCore.exp

    r82905 r83011  
    170170__ZN3JSC14throwTypeErrorEPNS_9ExecStateE
    171171__ZN3JSC15JSWrapperObject12markChildrenERNS_9MarkStackE
     172__ZN3JSC15WeakHandleOwner26isReachableFromOpaqueRootsENS_6HandleINS_7UnknownEEEPvRNS_9MarkStackE
     173__ZN3JSC15WeakHandleOwnerD2Ev
    172174__ZN3JSC15createTypeErrorEPNS_9ExecStateERKNS_7UStringE
    173175__ZN3JSC16InternalFunction12vtableAnchorEv
     
    385387__ZN3WTF12isMainThreadEv
    386388__ZN3WTF12randomNumberEv
    387 __ZN3WTF13StringBuilder15reserveCapacityEj
    388389__ZN3WTF13StringBuilder11reifyStringEv
    389390__ZN3WTF13StringBuilder11shrinkToFitEv
     391__ZN3WTF13StringBuilder15reserveCapacityEj
    390392__ZN3WTF13StringBuilder6appendEPKcj
    391393__ZN3WTF13StringBuilder6appendEPKtj
     
    597599__ZTVN3JSC14ScopeChainNodeE
    598600__ZTVN3JSC15JSWrapperObjectE
     601__ZTVN3JSC15WeakHandleOwnerE
    599602__ZTVN3JSC16InternalFunctionE
    600603__ZTVN3JSC16JSVariableObjectE
  • trunk/Source/JavaScriptCore/collector/handles/HandleHeap.cpp

    r82875 r83011  
    2525
    2626#include "config.h"
    27 
    2827#include "HandleHeap.h"
    2928
     
    3130
    3231namespace JSC {
     32
     33#if !ASSERT_DISABLED
     34static inline bool isValidWeakHandle(HandleSlot handle)
     35{
     36    JSValue value = *handle;
     37    if (!value || !value.isCell())
     38        return false;
     39
     40    JSCell* cell = value.asCell();
     41    if (!cell || !cell->structure())
     42        return false;
     43
     44#if ENABLE(JSC_ZOMBIES)
     45    if (cell->isZombie())
     46        return false;
     47#endif
     48
     49    return true;
     50}
     51#endif
     52
     53WeakHandleOwner::~WeakHandleOwner()
     54{
     55}
     56
     57bool WeakHandleOwner::isReachableFromOpaqueRoots(Handle<Unknown>, void*, MarkStack&)
     58{
     59    return false;
     60}
     61
     62void WeakHandleOwner::finalize(Handle<Unknown>, void*)
     63{
     64}
    3365
    3466HandleHeap::HandleHeap(JSGlobalData* globalData)
     
    5688}
    5789
    58 void HandleHeap::updateWeakHandles()
     90void HandleHeap::markWeakHandles(HeapRootMarker& heapRootMarker)
     91{
     92    MarkStack& markStack = heapRootMarker.markStack();
     93
     94    int oldCount;
     95    do {
     96        oldCount = markStack.opaqueRootCount();
     97
     98        Node* end = m_weakList.end();
     99        for (Node* node = m_weakList.begin(); node != end; node = node->next()) {
     100            ASSERT(isValidWeakHandle(node->slot()));
     101            JSCell* cell = node->slot()->asCell();
     102            if (Heap::isMarked(cell))
     103                continue;
     104
     105            WeakHandleOwner* weakOwner = node->weakOwner();
     106            if (!weakOwner)
     107                continue;
     108
     109            if (!weakOwner->isReachableFromOpaqueRoots(Handle<Unknown>::wrapSlot(node->slot()), node->weakOwnerContext(), markStack))
     110                continue;
     111
     112            heapRootMarker.mark(node->slot());
     113        }
     114    } while (oldCount != markStack.opaqueRootCount()); // If the set of opaque roots has grown, more handles may have become reachable.
     115}
     116
     117void HandleHeap::finalizeWeakHandles()
    59118{
    60119    Node* end = m_weakList.end();
     
    62121        m_nextToFinalize = node->next();
    63122
    64         JSValue value = *node->slot();
    65         ASSERT(value);
    66 
    67         JSCell* cell = value.asCell();
    68         ASSERT(cell && cell->structure());
    69 #if ENABLE(JSC_ZOMBIES)
    70         ASSERT(!cell->isZombie());
    71 #endif
    72 
     123        ASSERT(isValidWeakHandle(node->slot()));
     124        JSCell* cell = node->slot()->asCell();
    73125        if (Heap::isMarked(cell))
    74126            continue;
  • trunk/Source/JavaScriptCore/collector/handles/HandleHeap.h

    r82875 r83011  
    3535
    3636class HandleHeap;
     37class HeapRootMarker;
    3738class JSGlobalData;
    3839class JSValue;
    39 class HeapRootMarker;
     40class MarkStack;
    4041
    4142class WeakHandleOwner {
    4243public:
    43     virtual void finalize(Handle<Unknown>, void*) = 0;
    44     virtual ~WeakHandleOwner() {}
     44    virtual ~WeakHandleOwner();
     45    virtual bool isReachableFromOpaqueRoots(Handle<Unknown>, void* context, MarkStack&);
     46    virtual void finalize(Handle<Unknown>, void* context);
    4547};
    4648
     
    5759
    5860    void markStrongHandles(HeapRootMarker&);
    59     void updateWeakHandles();
     61    void markWeakHandles(HeapRootMarker&);
     62    void finalizeWeakHandles();
    6063
    6164    void writeBarrier(HandleSlot, const JSValue&);
  • trunk/Source/JavaScriptCore/runtime/Heap.cpp

    r82971 r83011  
    8383    m_markListSet = 0;
    8484    m_markedSpace.clearMarks();
    85     m_handleHeap.updateWeakHandles();
     85    m_handleHeap.finalizeWeakHandles();
    8686    m_markedSpace.destroy();
    8787
     
    243243    m_handleStack.mark(heapRootMarker);
    244244
     245    m_handleHeap.markWeakHandles(heapRootMarker);
     246    markStack.drain();
     247
    245248    // Mark the small strings cache last, since it will clear itself if nothing
    246249    // else has marked it.
    247250    m_globalData->smallStrings.markChildren(heapRootMarker);
    248 
    249     markStack.drain();
    250     markStack.compact();
    251    
    252     m_handleHeap.updateWeakHandles();
     251    markStack.drain();
     252   
     253    markStack.reset();
    253254
    254255    m_operationInProgress = NoOperation;
     
    370371
    371372    markRoots();
     373    m_handleHeap.finalizeWeakHandles();
    372374
    373375    JAVASCRIPTCORE_GC_MARKED();
  • trunk/Source/JavaScriptCore/runtime/MarkStack.cpp

    r81262 r83011  
    3939size_t MarkStack::s_pageSize = 0;
    4040
    41 void MarkStack::compact()
     41void MarkStack::reset()
    4242{
    4343    ASSERT(s_pageSize);
    4444    m_values.shrinkAllocation(s_pageSize);
    4545    m_markSets.shrinkAllocation(s_pageSize);
     46    m_opaqueRoots.clear();
    4647}
    4748
  • trunk/Source/JavaScriptCore/runtime/MarkStack.h

    r82849 r83011  
    3030#include "Register.h"
    3131#include "WriteBarrier.h"
     32#include <wtf/HashSet.h>
    3233#include <wtf/Vector.h>
    3334#include <wtf/Noncopyable.h>
     
    8283        void append(ConservativeRoots&);
    8384
     85        bool addOpaqueRoot(void* root) { return m_opaqueRoots.add(root).second; }
     86        bool containsOpaqueRoot(void* root) { return m_opaqueRoots.contains(root); }
     87        int opaqueRootCount() { return m_opaqueRoots.size(); }
     88
    8489        void drain();
    85         void compact();
     90        void reset();
    8691
    8792    private:
     
    199204        MarkStackArray<JSCell*> m_values;
    200205        static size_t s_pageSize;
     206        HashSet<void*> m_opaqueRoots; // Handle-owning data structures not visible to the garbage collector.
    201207
    202208#if !ASSERT_DISABLED
     
    275281        void mark(JSString**);
    276282        void mark(JSCell**);
     283       
     284        MarkStack& markStack();
    277285
    278286    private:
     
    305313    }
    306314
     315    inline MarkStack& HeapRootMarker::markStack()
     316    {
     317        return m_markStack;
     318    }
     319
    307320} // namespace JSC
    308321
  • trunk/Source/JavaScriptCore/runtime/WeakGCMap.h

    r82866 r83011  
    123123   
    124124private:
    125     virtual void finalize(Handle<Unknown>, void* key)
     125    virtual void finalize(Handle<Unknown>, void* context)
    126126    {
    127         HandleSlot slot = m_map.take(static_cast<KeyType>(key));
     127        HandleSlot slot = m_map.take(static_cast<KeyType>(context));
    128128        ASSERT(slot);
    129129        HandleHeap::heapFor(slot)->deallocate(slot);
Note: See TracChangeset for help on using the changeset viewer.