Changeset 88221 in webkit


Ignore:
Timestamp:
Jun 6, 2011 11:19:10 PM (13 years ago)
Author:
commit-queue@webkit.org
Message:

2011-06-06 Dmitry Lomov <dslomov@google.com>

Reviewed by Adam Barth.

https://bugs.webkit.org/show_bug.cgi?id=62164
Remove "multi-threaded" logic in V8 DOMData, DOMDataStore and friends
This functionality is untested and unused:
This is an old code from Lockers-based implementation of WebWorkers in
V8 bindings, to make sure that DOM objects are released on the right thread
even though GC could have happened on any thread. It is currently unused (since
current model is one worker per process) and is being removed because new implementation
of WebWorkers will be using V8 isolates.

  • WebCore.gypi:
  • bindings/v8/ChildThreadDOMData.cpp: Removed.
  • bindings/v8/ChildThreadDOMData.h: Removed.
  • bindings/v8/DOMData.cpp: (WebCore::DOMData::DOMData): (WebCore::DOMData::getCurrent): (WebCore::DOMData::getMainThreadStore):
  • bindings/v8/DOMData.h: (WebCore::DOMData::getStore): (WebCore::DOMData::getCurrentMainThreadStore): (WebCore::DOMData::handleWeakObject):
  • bindings/v8/DOMDataStore.cpp: (WebCore::DOMDataStore::DOMDataStore): (WebCore::DOMDataStore::~DOMDataStore): (WebCore::DOMDataStore::weakNodeCallback):
  • bindings/v8/DOMDataStore.h:
  • bindings/v8/MainThreadDOMData.cpp: Removed.
  • bindings/v8/MainThreadDOMData.h: Removed.
  • bindings/v8/V8DOMMap.cpp: (WebCore::getDOMDataStore): (WebCore::visitDOMNodes): (WebCore::visitDOMObjects): (WebCore::visitActiveDOMObjects): (WebCore::visitDOMSVGElementInstances):
  • bindings/v8/V8DOMMap.h:
  • bindings/v8/V8GCController.cpp: (WebCore::V8GCController::gcPrologue): (WebCore::V8GCController::gcEpilogue):
  • bindings/v8/WorkerScriptController.cpp: (WebCore::WorkerScriptController::~WorkerScriptController):
Location:
trunk/Source/WebCore
Files:
4 deleted
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r88220 r88221  
     12011-06-06  Dmitry Lomov  <dslomov@google.com>
     2
     3        Reviewed by Adam Barth.
     4
     5        https://bugs.webkit.org/show_bug.cgi?id=62164
     6        Remove "multi-threaded" logic in V8 DOMData, DOMDataStore and friends
     7        This functionality is untested and unused:
     8        This is an old code from Lockers-based implementation of WebWorkers in
     9        V8 bindings, to make sure that DOM objects are released on the right thread
     10        even though GC could have happened on any thread. It is currently unused (since
     11        current model is one worker per process) and is being removed because new implementation
     12        of WebWorkers will be using V8 isolates.
     13
     14        * WebCore.gypi:
     15        * bindings/v8/ChildThreadDOMData.cpp: Removed.
     16        * bindings/v8/ChildThreadDOMData.h: Removed.
     17        * bindings/v8/DOMData.cpp:
     18        (WebCore::DOMData::DOMData):
     19        (WebCore::DOMData::getCurrent):
     20        (WebCore::DOMData::getMainThreadStore):
     21        * bindings/v8/DOMData.h:
     22        (WebCore::DOMData::getStore):
     23        (WebCore::DOMData::getCurrentMainThreadStore):
     24        (WebCore::DOMData::handleWeakObject):
     25        * bindings/v8/DOMDataStore.cpp:
     26        (WebCore::DOMDataStore::DOMDataStore):
     27        (WebCore::DOMDataStore::~DOMDataStore):
     28        (WebCore::DOMDataStore::weakNodeCallback):
     29        * bindings/v8/DOMDataStore.h:
     30        * bindings/v8/MainThreadDOMData.cpp: Removed.
     31        * bindings/v8/MainThreadDOMData.h: Removed.
     32        * bindings/v8/V8DOMMap.cpp:
     33        (WebCore::getDOMDataStore):
     34        (WebCore::visitDOMNodes):
     35        (WebCore::visitDOMObjects):
     36        (WebCore::visitActiveDOMObjects):
     37        (WebCore::visitDOMSVGElementInstances):
     38        * bindings/v8/V8DOMMap.h:
     39        * bindings/v8/V8GCController.cpp:
     40        (WebCore::V8GCController::gcPrologue):
     41        (WebCore::V8GCController::gcEpilogue):
     42        * bindings/v8/WorkerScriptController.cpp:
     43        (WebCore::WorkerScriptController::~WorkerScriptController):
     44
    1452011-06-06  Nico Weber  <thakis@chromium.org>
    246
  • trunk/Source/WebCore/WebCore.gypi

    r88192 r88221  
    19521952            'bindings/objc/PublicDOMInterfaces.h',
    19531953            'bindings/objc/WebScriptObject.mm',
    1954             'bindings/v8/ChildThreadDOMData.cpp',
    1955             'bindings/v8/ChildThreadDOMData.h',
    19561954            'bindings/v8/DOMData.cpp',
    19571955            'bindings/v8/DOMData.h',
     
    19691967            'bindings/v8/JavaScriptCallFrame.cpp',
    19701968            'bindings/v8/JavaScriptCallFrame.h',
    1971             'bindings/v8/MainThreadDOMData.cpp',
    1972             'bindings/v8/MainThreadDOMData.h',
    19731969            'bindings/v8/NPV8Object.cpp',
    19741970            'bindings/v8/NPV8Object.h',
  • trunk/Source/WebCore/bindings/v8/DOMData.cpp

    r55882 r88221  
    3131#include "config.h"
    3232#include "DOMData.h"
    33 
    34 #include "ChildThreadDOMData.h"
    35 #include "MainThreadDOMData.h"
     33#include "V8IsolatedContext.h"
    3634#include "WebGLContextAttributes.h"
    3735#include "WebGLUniformLocation.h"
     
    4038
    4139DOMData::DOMData()
    42     : m_owningThread(WTF::currentThread())
     40    : m_defaultStore(this)
    4341{
     42    ASSERT(WTF::isMainThread());
    4443}
    4544
     
    5049DOMData* DOMData::getCurrent()
    5150{
    52     if (WTF::isMainThread())
    53         return MainThreadDOMData::getCurrent();
     51    ASSERT(WTF::isMainThread());
     52    DEFINE_STATIC_LOCAL(DOMData, mainThreadDOMData, ());
     53    return &mainThreadDOMData;
     54}
    5455
    55     DEFINE_STATIC_LOCAL(WTF::ThreadSpecific<ChildThreadDOMData>, childThreadDOMData, ());
    56     return childThreadDOMData;
     56DOMDataStore& DOMData::getMainThreadStore()
     57{
     58    // This is broken out as a separate non-virtual method from getStore()
     59    // so that it can be inlined by getCurrentMainThreadStore, which is
     60    // a hot spot in Dromaeo DOM tests.
     61    ASSERT(WTF::isMainThread());
     62    V8IsolatedContext* context = V8IsolatedContext::getEntered();
     63    if (UNLIKELY(context != 0))
     64        return *context->world()->domDataStore();
     65    return m_defaultStore;
    5766}
    5867
     
    6271}
    6372
     73
     74
    6475} // namespace WebCore
  • trunk/Source/WebCore/bindings/v8/DOMData.h

    r76248 r88221  
    3333
    3434#include "DOMDataStore.h"
     35#include "StaticDOMDataStore.h"
    3536#include "V8DOMWrapper.h"
    3637
     
    5152
    5253        static DOMData* getCurrent();
    53         virtual DOMDataStore& getStore() = 0;
     54        DOMDataStore& getStore() { return getMainThreadStore(); }
    5455
    5556        template<typename T>
     
    5960        static void removeObjectsFromWrapperMap(DOMDataStore* store, AbstractWeakReferenceMap<T, v8::Object>& domMap);
    6061
    61         ThreadIdentifier owningThread() const { return m_owningThread; }
     62        static DOMDataStore& getCurrentMainThreadStore() { return getCurrent()->getMainThreadStore(); }
    6263
    6364    private:
     
    7576        };
    7677
    77         ThreadIdentifier m_owningThread;
     78        DOMDataStore& getMainThreadStore();
     79        StaticDOMDataStore m_defaultStore;
    7880    };
    7981
     
    8183    void DOMData::handleWeakObject(DOMDataStore::DOMWrapperMapType mapType, v8::Persistent<v8::Object> v8Object, T* domObject)
    8284    {
     85        ASSERT(WTF::isMainThread());
    8386        WrapperTypeInfo* type = V8DOMWrapper::domWrapperType(v8Object);
    8487        DOMDataList& list = DOMDataStore::allStores();
     
    8689        for (size_t i = 0; i < list.size(); ++i) {
    8790            DOMDataStore* store = list[i];
    88             ASSERT(store->domData()->owningThread() == WTF::currentThread());
    8991
    9092            DOMWrapperMap<T>* domMap = static_cast<DOMWrapperMap<T>*>(store->getDOMWrapperMap(mapType));
  • trunk/Source/WebCore/bindings/v8/DOMDataStore.cpp

    r76541 r88221  
    6262// collector will remove these groups after each GC.
    6363//
    64 // DOM objects should be deref-ed from the owning thread, not the GC thread
    65 // that does not own them. In V8, GC can kick in from any thread. To ensure
    66 // that DOM objects are always deref-ed from the owning thread when running
    67 // V8 in multi-threading environment, we do following:
    68 // 1. Maintain a thread specific DOM wrapper map for each object map.
    69 //    (We're using TLS support from WTF instead of base since V8Bindings
    70 //     does not depend on base. We further assume that all child threads
    71 //     running V8 instances are created by WTF and thus a destructor will
    72 //     be called to clean up all thread specific data.)
    73 // 2. When GC happens:
    74 //    2.1. If the dead object is in GC thread's map, remove the JS reference
    75 //         and deref the DOM object.
    76 //    2.2. Otherwise, go through all thread maps to find the owning thread.
    77 //         Remove the JS reference from the owning thread's map and move the
    78 //         DOM object to a delayed queue. Post a task to the owning thread
    79 //         to have it deref-ed from the owning thread at later time.
    80 // 3. When a thread is tearing down, invoke a cleanup routine to go through
    81 //    all objects in the delayed queue and the thread map and deref all of
    82 //    them.
    83 
     64// DOM objects are accessed and deref-ed from the main thread. All V8 accesses
     65// to DOM objects happen on the main thread.
     66// When GC happens, we remove the JS reference and deref the DOM object.
    8467
    8568DOMDataStore::DOMDataStore(DOMData* domData)
     
    9275    , m_domData(domData)
    9376{
    94     WTF::MutexLocker locker(DOMDataStore::allStoresMutex());
     77    ASSERT(WTF::isMainThread());
    9578    DOMDataStore::allStores().append(this);
    9679}
     
    9881DOMDataStore::~DOMDataStore()
    9982{
    100     WTF::MutexLocker locker(DOMDataStore::allStoresMutex());
     83    ASSERT(WTF::isMainThread());
    10184    DOMDataStore::allStores().remove(DOMDataStore::allStores().find(this));
    10285}
     
    10689  DEFINE_STATIC_LOCAL(DOMDataList, staticDOMDataList, ());
    10790  return staticDOMDataList;
    108 }
    109 
    110 WTF::Mutex& DOMDataStore::allStoresMutex()
    111 {
    112     DEFINE_STATIC_LOCAL(WTF::Mutex, staticDOMDataListMutex, ());
    113     return staticDOMDataListMutex;
    11491}
    11592
     
    157134    v8::Persistent<v8::Object> v8Object = v8::Persistent<v8::Object>::Cast(value);
    158135
    159     WTF::MutexLocker locker(DOMDataStore::allStoresMutex());
    160136    DOMDataList& list = DOMDataStore::allStores();
    161137    for (size_t i = 0; i < list.size(); ++i) {
    162138        DOMDataStore* store = list[i];
    163139        if (store->domNodeMap().removeIfPresent(node, v8Object)) {
    164             ASSERT(store->domData()->owningThread() == WTF::currentThread());
    165140            node->deref(); // Nobody overrides Node::deref so it's safe
    166141            return; // There might be at most one wrapper for the node in world's maps
  • trunk/Source/WebCore/bindings/v8/DOMDataStore.h

    r76541 r88221  
    7878        // A list of all DOMDataStore objects in the current V8 instance (thread). Normally, each World has a DOMDataStore.
    7979        static DOMDataList& allStores();
    80         // Mutex to protect against concurrent access of DOMDataList.
    81         static WTF::Mutex& allStoresMutex();
    8280
    8381        DOMData* domData() const { return m_domData; }
  • trunk/Source/WebCore/bindings/v8/V8DOMMap.cpp

    r84890 r88221  
    3434#include "DOMData.h"
    3535#include "DOMDataStore.h"
    36 #include "MainThreadDOMData.h"
    3736#include "ScopedDOMDataStore.h"
    3837
     
    5251static inline DOMDataStore& getDOMDataStore()
    5352{
    54     if (LIKELY(fasterDOMStoreAccess)) {
    55         ASSERT(WTF::isMainThread());
    56         return MainThreadDOMData::getCurrentMainThreadStore();
    57     }
    58 
    59     return DOMData::getCurrent()->getStore();
     53    ASSERT(WTF::isMainThread());
     54    return DOMData::getCurrentMainThreadStore();
    6055}
    6156
     
    113108}
    114109
    115 void visitDOMNodesInCurrentThread(DOMWrapperMap<Node>::Visitor* visitor)
     110void visitDOMNodes(DOMWrapperMap<Node>::Visitor* visitor)
    116111{
    117112    v8::HandleScope scope;
    118113
    119     WTF::MutexLocker locker(DOMDataStore::allStoresMutex());
     114    ASSERT(WTF::isMainThread());
    120115    DOMDataList& list = DOMDataStore::allStores();
    121116    for (size_t i = 0; i < list.size(); ++i) {
    122117        DOMDataStore* store = list[i];
    123         if (!store->domData()->owningThread() == WTF::currentThread())
    124             continue;
    125118
    126119        store->domNodeMap().visit(store, visitor);
     
    128121}
    129122
    130 void visitDOMObjectsInCurrentThread(DOMWrapperMap<void>::Visitor* visitor)
     123void visitDOMObjects(DOMWrapperMap<void>::Visitor* visitor)
    131124{
    132125    v8::HandleScope scope;
    133126
    134     WTF::MutexLocker locker(DOMDataStore::allStoresMutex());
     127    ASSERT(WTF::isMainThread());
    135128    DOMDataList& list = DOMDataStore::allStores();
    136129    for (size_t i = 0; i < list.size(); ++i) {
    137130        DOMDataStore* store = list[i];
    138         if (!store->domData()->owningThread() == WTF::currentThread())
    139             continue;
    140131
    141132        store->domObjectMap().visit(store, visitor);
     
    143134}
    144135
    145 void visitActiveDOMObjectsInCurrentThread(DOMWrapperMap<void>::Visitor* visitor)
     136void visitActiveDOMObjects(DOMWrapperMap<void>::Visitor* visitor)
    146137{
    147138    v8::HandleScope scope;
    148139
    149     WTF::MutexLocker locker(DOMDataStore::allStoresMutex());
     140    ASSERT(WTF::isMainThread());
    150141    DOMDataList& list = DOMDataStore::allStores();
    151142    for (size_t i = 0; i < list.size(); ++i) {
    152143        DOMDataStore* store = list[i];
    153         if (!store->domData()->owningThread() == WTF::currentThread())
    154             continue;
    155144
    156145        store->activeDomObjectMap().visit(store, visitor);
     
    160149#if ENABLE(SVG)
    161150
    162 void visitDOMSVGElementInstancesInCurrentThread(DOMWrapperMap<SVGElementInstance>::Visitor* visitor)
     151void visitDOMSVGElementInstances(DOMWrapperMap<SVGElementInstance>::Visitor* visitor)
    163152{
    164153    v8::HandleScope scope;
    165154
    166     WTF::MutexLocker locker(DOMDataStore::allStoresMutex());
     155    ASSERT(WTF::isMainThread());
    167156    DOMDataList& list = DOMDataStore::allStores();
    168157    for (size_t i = 0; i < list.size(); ++i) {
    169158        DOMDataStore* store = list[i];
    170         if (!store->domData()->owningThread() == WTF::currentThread())
    171             continue;
    172159
    173160        store->domSvgElementInstanceMap().visit(store, visitor);
  • trunk/Source/WebCore/bindings/v8/V8DOMMap.h

    r76104 r88221  
    159159    // A map from DOM node to its JS wrapper.
    160160    DOMNodeMapping& getDOMNodeMap();
    161     void visitDOMNodesInCurrentThread(DOMWrapperMap<Node>::Visitor*);
     161    void visitDOMNodes(DOMWrapperMap<Node>::Visitor*);
    162162
    163163    // A map from a DOM object (non-node) to its JS wrapper. This map does not contain the DOM objects which can have pending activity (active dom objects).
    164164    DOMWrapperMap<void>& getDOMObjectMap();
    165     void visitDOMObjectsInCurrentThread(DOMWrapperMap<void>::Visitor*);
     165    void visitDOMObjects(DOMWrapperMap<void>::Visitor*);
    166166
    167167    // A map from a DOM object to its JS wrapper for DOM objects which can have pending activity.
    168168    DOMWrapperMap<void>& getActiveDOMObjectMap();
    169     void visitActiveDOMObjectsInCurrentThread(DOMWrapperMap<void>::Visitor*);
     169    void visitActiveDOMObjects(DOMWrapperMap<void>::Visitor*);
    170170
    171171    // This should be called to remove all DOM objects associated with the current thread when it is tearing down.
    172     void removeAllDOMObjectsInCurrentThread();
     172    void removeAllDOMObjects();
    173173
    174174#if ENABLE(SVG)
    175175    // A map for SVGElementInstances to its JS wrapper.
    176176    DOMWrapperMap<SVGElementInstance>& getDOMSVGElementInstanceMap();
    177     void visitSVGElementInstancesInCurrentThread(DOMWrapperMap<SVGElementInstance>::Visitor*);
     177    void visitSVGElementInstances(DOMWrapperMap<SVGElementInstance>::Visitor*);
    178178#endif
    179179
  • trunk/Source/WebCore/bindings/v8/V8GCController.cpp

    r85673 r88221  
    459459    // wrappers non weak if there is pending activity.
    460460    GCPrologueVisitor prologueVisitor;
    461     visitActiveDOMObjectsInCurrentThread(&prologueVisitor);
     461    visitActiveDOMObjects(&prologueVisitor);
    462462
    463463    // Create object groups.
    464464    GrouperVisitor grouperVisitor;
    465     visitDOMNodesInCurrentThread(&grouperVisitor);
    466     visitDOMObjectsInCurrentThread(&grouperVisitor);
     465    visitDOMNodes(&grouperVisitor);
     466    visitDOMObjects(&grouperVisitor);
    467467    grouperVisitor.applyGrouping();
    468468
     
    530530    // again.
    531531    GCEpilogueVisitor epilogueVisitor;
    532     visitActiveDOMObjectsInCurrentThread(&epilogueVisitor);
     532    visitActiveDOMObjects(&epilogueVisitor);
    533533
    534534    workingSetEstimateMB = getActualMemoryUsageInMB();
     
    540540
    541541    EnsureWeakDOMNodeVisitor weakDOMNodeVisitor;
    542     visitDOMNodesInCurrentThread(&weakDOMNodeVisitor);
     542    visitDOMNodes(&weakDOMNodeVisitor);
    543543
    544544    enumerateGlobalHandles();
  • trunk/Source/WebCore/bindings/v8/WorkerScriptController.cpp

    r84890 r88221  
    5959WorkerScriptController::~WorkerScriptController()
    6060{
    61     removeAllDOMObjectsInCurrentThread();
     61    removeAllDOMObjects();
    6262}
    6363
Note: See TracChangeset for help on using the changeset viewer.