Changeset 128138 in webkit


Ignore:
Timestamp:
Sep 10, 2012 6:22:17 PM (12 years ago)
Author:
commit-queue@webkit.org
Message:

[V8] We don't us the global handle map for anything useful---let's remove it
https://bugs.webkit.org/show_bug.cgi?id=96343

Patch by Adam Barth <abarth@chromium.org> on 2012-09-10
Reviewed by Kentaro Hara.

The global handle map was a dream of tracking all the persistent V8
handles in WebCore. Unfortunately, it has never been complete, and I'm
not aware of us using it for anything. This patch removes what little
is left of it.

  • bindings/v8/NPV8Object.cpp:

(WebCore::freeV8NPObject):
(WebCore::npCreateV8ScriptObject):

  • bindings/v8/V8GCController.cpp:

(WebCore):
(WebCore::V8GCController::gcEpilogue):
(WebCore::V8GCController::collectGarbage):

  • bindings/v8/V8GCController.h:

(V8GCController):

  • bindings/v8/V8PerIsolateData.h:

(WebCore):
(V8PerIsolateData):

Location:
trunk/Source/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r128137 r128138  
     12012-09-10  Adam Barth  <abarth@chromium.org>
     2
     3        [V8] We don't us the global handle map for anything useful---let's remove it
     4        https://bugs.webkit.org/show_bug.cgi?id=96343
     5
     6        Reviewed by Kentaro Hara.
     7
     8        The global handle map was a dream of tracking all the persistent V8
     9        handles in WebCore. Unfortunately, it has never been complete, and I'm
     10        not aware of us using it for anything. This patch removes what little
     11        is left of it.
     12
     13        * bindings/v8/NPV8Object.cpp:
     14        (WebCore::freeV8NPObject):
     15        (WebCore::npCreateV8ScriptObject):
     16        * bindings/v8/V8GCController.cpp:
     17        (WebCore):
     18        (WebCore::V8GCController::gcEpilogue):
     19        (WebCore::V8GCController::collectGarbage):
     20        * bindings/v8/V8GCController.h:
     21        (V8GCController):
     22        * bindings/v8/V8PerIsolateData.h:
     23        (WebCore):
     24        (V8PerIsolateData):
     25
    1262012-09-10  John Bates  <jbates@google.com>
    227
  • trunk/Source/WebCore/bindings/v8/NPV8Object.cpp

    r127757 r128138  
    103103    }
    104104
    105 #ifndef NDEBUG
    106     V8GCController::unregisterGlobalHandle(v8NpObject, v8NpObject->v8Object);
    107 #endif
    108105    v8NpObject->v8Object.Dispose();
    109106    free(v8NpObject);
     
    177174    V8NPObject* v8npObject = reinterpret_cast<V8NPObject*>(_NPN_CreateObject(npp, &V8NPObjectClass));
    178175    v8npObject->v8Object = v8::Persistent<v8::Object>::New(object);
    179 #ifndef NDEBUG
    180     V8GCController::registerGlobalHandle(NPOBJECT, v8npObject, v8npObject->v8Object);
    181 #endif
    182176    v8npObject->rootObject = root;
    183177
  • trunk/Source/WebCore/bindings/v8/V8GCController.cpp

    r126926 r128138  
    6868namespace WebCore {
    6969
    70 #ifndef NDEBUG
    71 // Keeps track of global handles created (not JS wrappers
    72 // of DOM objects). Often these global handles are source
    73 // of leaks.
    74 //
    75 // If you want to let a C++ object hold a persistent handle
    76 // to a JS object, you should register the handle here to
    77 // keep track of leaks.
    78 //
    79 // When creating a persistent handle, call:
    80 //
    81 // #ifndef NDEBUG
    82 //    V8GCController::registerGlobalHandle(type, host, handle);
    83 // #endif
    84 //
    85 // When releasing the handle, call:
    86 //
    87 // #ifndef NDEBUG
    88 //    V8GCController::unregisterGlobalHandle(type, host, handle);
    89 // #endif
    90 //
    91 
    92 static GlobalHandleMap& currentGlobalHandleMap()
    93 {
    94     return V8PerIsolateData::current()->globalHandleMap();
    95 }
    96 
    97 // The function is the place to set the break point to inspect
    98 // live global handles. Leaks are often come from leaked global handles.
    99 static void enumerateGlobalHandles()
    100 {
    101     GlobalHandleMap& globalHandleMap = currentGlobalHandleMap();
    102     for (GlobalHandleMap::iterator it = globalHandleMap.begin(), end = globalHandleMap.end(); it != end; ++it) {
    103         GlobalHandleInfo* info = it->second;
    104         UNUSED_PARAM(info);
    105         v8::Value* handle = it->first;
    106         UNUSED_PARAM(handle);
    107     }
    108 }
    109 
    110 void V8GCController::registerGlobalHandle(GlobalHandleType type, void* host, v8::Persistent<v8::Value> handle)
    111 {
    112     GlobalHandleMap& globalHandleMap = currentGlobalHandleMap();
    113     ASSERT(!globalHandleMap.contains(*handle));
    114     globalHandleMap.set(*handle, new GlobalHandleInfo(host, type));
    115 }
    116 
    117 void V8GCController::unregisterGlobalHandle(void* host, v8::Persistent<v8::Value> handle)
    118 {
    119     GlobalHandleMap& globalHandleMap = currentGlobalHandleMap();
    120     ASSERT(globalHandleMap.contains(*handle));
    121     GlobalHandleInfo* info = globalHandleMap.take(*handle);
    122     ASSERT(info->m_host == host);
    123     delete info;
    124 }
    125 #endif // ifndef NDEBUG
    126 
    12770typedef HashMap<Node*, v8::Object*> DOMNodeMap;
    12871typedef HashMap<void*, v8::Object*> DOMObjectMap;
     
    476419int V8GCController::workingSetEstimateMB = 0;
    477420
    478 namespace {
    479 
    480 
    481 }  // anonymous namespace
    482 
    483421void V8GCController::gcEpilogue()
    484422{
     
    501439    EnsureWeakDOMNodeVisitor weakDOMNodeVisitor;
    502440    visitDOMNodes(&weakDOMNodeVisitor);
    503 
    504     enumerateGlobalHandles();
    505441#endif
    506442
     
    537473    v8::HandleScope handleScope;
    538474
    539     v8::Persistent<v8::Context> context = v8::Context::New();
    540     if (context.IsEmpty())
     475    ScopedPersistent<v8::Context> context;
     476
     477    context.adopt(v8::Context::New());
     478    if (context.isEmpty())
    541479        return;
    542     {
    543         v8::Context::Scope scope(context);
     480
     481    {
     482        v8::Context::Scope scope(context.get());
    544483        v8::Local<v8::String> source = v8::String::New("if (gc) gc();");
    545484        v8::Local<v8::String> name = v8::String::New("gc");
     
    550489        }
    551490    }
    552     context.Dispose();
     491
     492    context.clear();
    553493}
    554494
  • trunk/Source/WebCore/bindings/v8/V8GCController.h

    r126123 r128138  
    3636namespace WebCore {
    3737
    38 #ifndef NDEBUG
     38class V8GCController {
     39public:
     40    static void gcPrologue();
     41    static void gcEpilogue();
    3942
    40 #define GlobalHandleTypeList(V)   \
    41     V(PROXY)                      \
    42     V(NPOBJECT)                   \
    43     V(SCHEDULED_ACTION)           \
    44     V(EVENT_LISTENER)             \
    45     V(NODE_FILTER)                \
    46     V(SCRIPTINSTANCE)             \
    47     V(SCRIPTVALUE)                \
    48     V(DATASOURCE)
     43    static void checkMemoryUsage();
     44    static void hintForCollectGarbage();
     45    static void collectGarbage();
    4946
    50 
    51     // Host information of persistent handles.
    52     enum GlobalHandleType {
    53 #define ENUM(name) name,
    54         GlobalHandleTypeList(ENUM)
    55 #undef ENUM
    56     };
    57 
    58     class GlobalHandleInfo {
    59     public:
    60         GlobalHandleInfo(void* host, GlobalHandleType type) : m_host(host), m_type(type) { }
    61         void* m_host;
    62         GlobalHandleType m_type;
    63     };
    64 
    65 #endif // NDEBUG
    66 
    67     class V8GCController {
    68     public:
    69 #ifndef NDEBUG
    70         // For debugging and leak detection purpose.
    71         static void registerGlobalHandle(GlobalHandleType, void*, v8::Persistent<v8::Value>);
    72         static void unregisterGlobalHandle(void*, v8::Persistent<v8::Value>);
    73 #endif
    74 
    75         static void gcPrologue();
    76         static void gcEpilogue();
    77 
    78         static void checkMemoryUsage();
    79         static void hintForCollectGarbage();
    80         static void collectGarbage();
    81 
    82     private:
    83         // Estimate of current working set.
    84         static int workingSetEstimateMB;
    85     };
     47private:
     48    static int workingSetEstimateMB;
     49};
    8650
    8751}
  • trunk/Source/WebCore/bindings/v8/V8PerIsolateData.h

    r128127 r128138  
    4848
    4949typedef WTF::Vector<DOMDataStore*> DOMDataList;
    50 
    51 #ifndef NDEBUG
    52 class GlobalHandleInfo;
    53 typedef HashMap<v8::Value*, GlobalHandleInfo*> GlobalHandleMap;
    54 #endif
    5550
    5651class V8PerIsolateData {
     
    112107
    113108#ifndef NDEBUG
    114     GlobalHandleMap& globalHandleMap() { return m_globalHandleMap; }
    115 
    116109    int internalScriptRecursionLevel() const { return m_internalScriptRecursionLevel; }
    117110    int incrementInternalScriptRecursionLevel() { return ++m_internalScriptRecursionLevel; }
     
    156149
    157150#ifndef NDEBUG
    158     GlobalHandleMap m_globalHandleMap;
    159151    int m_internalScriptRecursionLevel;
    160152#endif
Note: See TracChangeset for help on using the changeset viewer.