Title: [99588] trunk/Source/WebCore
Revision
99588
Author
tha...@chromium.org
Date
2011-11-08 10:20:18 -0800 (Tue, 08 Nov 2011)

Log Message

[chromium] Remove 6 exit time destructors and 6 static initializers
https://bugs.webkit.org/show_bug.cgi?id=71760

Reviewed by Nate Chapin.

Do this by moving global statics into function-local statics, and using
DEFINE_LOCAL_STATIC to leak them. Since this code is accessed on a single
thread, this is a safe change to make.

No behavior change, so no new tests.

* bindings/v8/ScriptGCEvent.cpp:
(WebCore::sEventListeners):
(WebCore::ScriptGCEvent::addEventListener):
(WebCore::ScriptGCEvent::removeEventListener):
(WebCore::ScriptGCEvent::gcEpilogueCallback):
* bindings/v8/ScriptGCEvent.h:
* bindings/v8/V8NPObject.cpp:
(WebCore::staticTemplateMap):
(WebCore::weakTemplateCallback):
(WebCore::npObjectGetProperty):
(WebCore::staticNPObjectMap):
(WebCore::weakNPObjectCallback):
(WebCore::createV8ObjectForNPObject):
(WebCore::forgetV8ObjectForNPObject):
* bindings/v8/V8Proxy.cpp:
(WebCore::staticExtensionsList):
(WebCore::V8Proxy::registeredExtensionWithV8):
(WebCore::V8Proxy::registerExtension):
(WebCore::V8Proxy::extensions):
* bindings/v8/V8Proxy.h:
* bindings/v8/npruntime.cpp:
* plugins/chromium/PluginDataChromium.cpp:
(WebCore::pluginCache):
(WebCore::PluginData::initPlugins):
(WebCore::PluginData::refresh):
(WebCore::getPluginMimeTypeFromExtension):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (99587 => 99588)


--- trunk/Source/WebCore/ChangeLog	2011-11-08 18:17:47 UTC (rev 99587)
+++ trunk/Source/WebCore/ChangeLog	2011-11-08 18:20:18 UTC (rev 99588)
@@ -1,3 +1,43 @@
+2011-11-08  Nico Weber  <tha...@chromium.org>
+
+        [chromium] Remove 6 exit time destructors and 6 static initializers
+        https://bugs.webkit.org/show_bug.cgi?id=71760
+
+        Reviewed by Nate Chapin.
+
+        Do this by moving global statics into function-local statics, and using
+        DEFINE_LOCAL_STATIC to leak them. Since this code is accessed on a single
+        thread, this is a safe change to make.
+
+        No behavior change, so no new tests.
+
+        * bindings/v8/ScriptGCEvent.cpp:
+        (WebCore::sEventListeners):
+        (WebCore::ScriptGCEvent::addEventListener):
+        (WebCore::ScriptGCEvent::removeEventListener):
+        (WebCore::ScriptGCEvent::gcEpilogueCallback):
+        * bindings/v8/ScriptGCEvent.h:
+        * bindings/v8/V8NPObject.cpp:
+        (WebCore::staticTemplateMap):
+        (WebCore::weakTemplateCallback):
+        (WebCore::npObjectGetProperty):
+        (WebCore::staticNPObjectMap):
+        (WebCore::weakNPObjectCallback):
+        (WebCore::createV8ObjectForNPObject):
+        (WebCore::forgetV8ObjectForNPObject):
+        * bindings/v8/V8Proxy.cpp:
+        (WebCore::staticExtensionsList):
+        (WebCore::V8Proxy::registeredExtensionWithV8):
+        (WebCore::V8Proxy::registerExtension):
+        (WebCore::V8Proxy::extensions):
+        * bindings/v8/V8Proxy.h:
+        * bindings/v8/npruntime.cpp:
+        * plugins/chromium/PluginDataChromium.cpp:
+        (WebCore::pluginCache):
+        (WebCore::PluginData::initPlugins):
+        (WebCore::PluginData::refresh):
+        (WebCore::getPluginMimeTypeFromExtension):
+
 2011-11-08  Hans Wennborg  <h...@chromium.org>
 
         IndexedDB: Start using the onSuccessWithContinuation() callback

Modified: trunk/Source/WebCore/bindings/v8/ScriptGCEvent.cpp (99587 => 99588)


--- trunk/Source/WebCore/bindings/v8/ScriptGCEvent.cpp	2011-11-08 18:17:47 UTC (rev 99587)
+++ trunk/Source/WebCore/bindings/v8/ScriptGCEvent.cpp	2011-11-08 18:20:18 UTC (rev 99588)
@@ -39,28 +39,34 @@
 
 namespace WebCore {
 
-ScriptGCEvent::GCEventListeners ScriptGCEvent::s_eventListeners;
+typedef Vector<ScriptGCEventListener*> GCEventListeners;
+static GCEventListeners& eventListeners()
+{
+    DEFINE_STATIC_LOCAL(GCEventListeners, listeners, ());
+    return listeners;
+}
+
 double ScriptGCEvent::s_startTime = 0.0;
 size_t ScriptGCEvent::s_usedHeapSize = 0;
 
 void ScriptGCEvent::addEventListener(ScriptGCEventListener* eventListener)
 {
     ASSERT(eventListener);
-    if (s_eventListeners.isEmpty()) {
+    if (eventListeners().isEmpty()) {
         v8::V8::AddGCPrologueCallback(ScriptGCEvent::gcPrologueCallback);
         v8::V8::AddGCEpilogueCallback(ScriptGCEvent::gcEpilogueCallback);
     }
-    s_eventListeners.append(eventListener);
+    eventListeners().append(eventListener);
 }
 
 void ScriptGCEvent::removeEventListener(ScriptGCEventListener* eventListener)
 {
     ASSERT(eventListener);
-    ASSERT(!s_eventListeners.isEmpty());
-    size_t i = s_eventListeners.find(eventListener);
+    ASSERT(!eventListeners().isEmpty());
+    size_t i = eventListeners().find(eventListener);
     ASSERT(i != notFound);
-    s_eventListeners.remove(i);
-    if (s_eventListeners.isEmpty()) {
+    eventListeners().remove(i);
+    if (eventListeners().isEmpty()) {
         v8::V8::RemoveGCPrologueCallback(ScriptGCEvent::gcPrologueCallback);
         v8::V8::RemoveGCEpilogueCallback(ScriptGCEvent::gcEpilogueCallback);
     }
@@ -92,7 +98,7 @@
 {
     double endTime = WTF::currentTimeMS();
     size_t collectedBytes = s_usedHeapSize - getUsedHeapSize();
-    GCEventListeners listeners(s_eventListeners);
+    GCEventListeners listeners(eventListeners());
     for (GCEventListeners::iterator i = listeners.begin(); i != listeners.end(); ++i)
         (*i)->didGC(s_startTime, endTime, collectedBytes);
 }

Modified: trunk/Source/WebCore/bindings/v8/ScriptGCEvent.h (99587 => 99588)


--- trunk/Source/WebCore/bindings/v8/ScriptGCEvent.h	2011-11-08 18:17:47 UTC (rev 99587)
+++ trunk/Source/WebCore/bindings/v8/ScriptGCEvent.h	2011-11-08 18:20:18 UTC (rev 99588)
@@ -47,8 +47,6 @@
     static void removeEventListener(ScriptGCEventListener*);
     static void getHeapSize(size_t&, size_t&, size_t&);
 private:
-    typedef Vector<ScriptGCEventListener*> GCEventListeners;
-    static GCEventListeners s_eventListeners;
     static double s_startTime;
     static size_t s_usedHeapSize;
  

Modified: trunk/Source/WebCore/bindings/v8/V8NPObject.cpp (99587 => 99588)


--- trunk/Source/WebCore/bindings/v8/V8NPObject.cpp	2011-11-08 18:17:47 UTC (rev 99587)
+++ trunk/Source/WebCore/bindings/v8/V8NPObject.cpp	2011-11-08 18:20:18 UTC (rev 99588)
@@ -163,15 +163,20 @@
 static void weakTemplateCallback(v8::Persistent<v8::Value>, void* parameter);
 
 // NPIdentifier is PrivateIdentifier*.
-static WeakReferenceMap<PrivateIdentifier, v8::FunctionTemplate> staticTemplateMap(&weakTemplateCallback);
+static WeakReferenceMap<PrivateIdentifier, v8::FunctionTemplate>& staticTemplateMap()
+{
+    typedef WeakReferenceMap<PrivateIdentifier, v8::FunctionTemplate> MapType;
+    DEFINE_STATIC_LOCAL(MapType, templateMap, (&weakTemplateCallback));
+    return templateMap;
+}
 
 static void weakTemplateCallback(v8::Persistent<v8::Value> object, void* parameter)
 {
     PrivateIdentifier* identifier = static_cast<PrivateIdentifier*>(parameter);
     ASSERT(identifier);
-    ASSERT(staticTemplateMap.contains(identifier));
+    ASSERT(staticTemplateMap().contains(identifier));
 
-    staticTemplateMap.forget(identifier);
+    staticTemplateMap().forget(identifier);
 }
 
 
@@ -201,14 +206,14 @@
 
     if (key->IsString() && npObject->_class->hasMethod && npObject->_class->hasMethod(npObject, identifier)) {
         PrivateIdentifier* id = static_cast<PrivateIdentifier*>(identifier);
-        v8::Persistent<v8::FunctionTemplate> functionTemplate = staticTemplateMap.get(id);
+        v8::Persistent<v8::FunctionTemplate> functionTemplate = staticTemplateMap().get(id);
         // Cache templates using identifier as the key.
         if (functionTemplate.IsEmpty()) {
             // Create a new template.
             v8::Local<v8::FunctionTemplate> temp = v8::FunctionTemplate::New();
             temp->SetCallHandler(npObjectMethodHandler, key);
             functionTemplate = v8::Persistent<v8::FunctionTemplate>::New(temp);
-            staticTemplateMap.set(id, functionTemplate);
+            staticTemplateMap().set(id, functionTemplate);
         }
 
         // FunctionTemplate caches function for each context.
@@ -341,17 +346,21 @@
 
 static void weakNPObjectCallback(v8::Persistent<v8::Value>, void* parameter);
 
-static DOMWrapperMap<NPObject> staticNPObjectMap(&weakNPObjectCallback);
+static DOMWrapperMap<NPObject>& staticNPObjectMap()
+{
+    DEFINE_STATIC_LOCAL(DOMWrapperMap<NPObject>, npObjectMap, (&weakNPObjectCallback));
+    return npObjectMap;
+}
 
 static void weakNPObjectCallback(v8::Persistent<v8::Value> object, void* parameter)
 {
     NPObject* npObject = static_cast<NPObject*>(parameter);
-    ASSERT(staticNPObjectMap.contains(npObject));
+    ASSERT(staticNPObjectMap().contains(npObject));
     ASSERT(npObject);
 
     // Must remove from our map before calling _NPN_ReleaseObject(). _NPN_ReleaseObject can call ForgetV8ObjectForNPObject, which
     // uses the table as well.
-    staticNPObjectMap.forget(npObject);
+    staticNPObjectMap().forget(npObject);
 
     if (_NPN_IsAlive(npObject))
         _NPN_ReleaseObject(npObject);
@@ -371,8 +380,8 @@
     }
 
     // If we've already wrapped this object, just return it.
-    if (staticNPObjectMap.contains(object))
-        return v8::Local<v8::Object>::New(staticNPObjectMap.get(object));
+    if (staticNPObjectMap().contains(object))
+        return v8::Local<v8::Object>::New(staticNPObjectMap().get(object));
 
     // FIXME: we should create a Wrapper type as a subclass of JSObject. It has two internal fields, field 0 is the wrapped
     // pointer, and field 1 is the type. There should be an api function that returns unused type id. The same Wrapper type
@@ -401,18 +410,18 @@
 
     // Maintain a weak pointer for v8 so we can cleanup the object.
     v8::Persistent<v8::Object> weakRef = v8::Persistent<v8::Object>::New(value);
-    staticNPObjectMap.set(object, weakRef);
+    staticNPObjectMap().set(object, weakRef);
 
     return value;
 }
 
 void forgetV8ObjectForNPObject(NPObject* object)
 {
-    if (staticNPObjectMap.contains(object)) {
+    if (staticNPObjectMap().contains(object)) {
         v8::HandleScope scope;
-        v8::Persistent<v8::Object> handle(staticNPObjectMap.get(object));
+        v8::Persistent<v8::Object> handle(staticNPObjectMap().get(object));
         V8DOMWrapper::setDOMWrapper(handle, npObjectTypeInfo(), 0);
-        staticNPObjectMap.forget(object);
+        staticNPObjectMap().forget(object);
         _NPN_ReleaseObject(object);
     }
 }

Modified: trunk/Source/WebCore/bindings/v8/V8Proxy.cpp (99587 => 99588)


--- trunk/Source/WebCore/bindings/v8/V8Proxy.cpp	2011-11-08 18:17:47 UTC (rev 99587)
+++ trunk/Source/WebCore/bindings/v8/V8Proxy.cpp	2011-11-08 18:20:18 UTC (rev 99588)
@@ -76,8 +76,11 @@
 
 namespace WebCore {
 
-// Static list of registered extensions
-V8Extensions V8Proxy::m_extensions;
+static V8Extensions& staticExtensionsList()
+{
+    DEFINE_STATIC_LOCAL(V8Extensions, extensions, ());
+    return extensions;
+}
 
 void batchConfigureAttributes(v8::Handle<v8::ObjectTemplate> instance, 
                               v8::Handle<v8::ObjectTemplate> proto, 
@@ -750,8 +753,9 @@
 
 bool V8Proxy::registeredExtensionWithV8(v8::Extension* extension)
 {
-    for (size_t i = 0; i < m_extensions.size(); ++i) {
-        if (m_extensions[i] == extension)
+    const V8Extensions& registeredExtensions = extensions();
+    for (size_t i = 0; i < registeredExtensions.size(); ++i) {
+        if (registeredExtensions[i] == extension)
             return true;
     }
 
@@ -761,9 +765,14 @@
 void V8Proxy::registerExtension(v8::Extension* extension)
 {
     registerExtensionWithV8(extension);
-    m_extensions.append(extension);
+    staticExtensionsList().append(extension);
 }
 
+const V8Extensions& V8Proxy::extensions()
+{
+    return staticExtensionsList();
+}
+
 bool V8Proxy::setContextDebugId(int debugId)
 {
     ASSERT(debugId > 0);

Modified: trunk/Source/WebCore/bindings/v8/V8Proxy.h (99587 => 99588)


--- trunk/Source/WebCore/bindings/v8/V8Proxy.h	2011-11-08 18:17:47 UTC (rev 99587)
+++ trunk/Source/WebCore/bindings/v8/V8Proxy.h	2011-11-08 18:20:18 UTC (rev 99588)
@@ -274,7 +274,7 @@
         static void registerExtensionWithV8(v8::Extension*);
         static bool registeredExtensionWithV8(v8::Extension*);
 
-        static const V8Extensions& extensions() { return m_extensions; }
+        static const V8Extensions& extensions();
 
         // Report an unsafe attempt to access the given frame on the console.
         static void reportUnsafeAccessTo(Frame* target);

Modified: trunk/Source/WebCore/bindings/v8/npruntime.cpp (99587 => 99588)


--- trunk/Source/WebCore/bindings/v8/npruntime.cpp	2011-11-08 18:17:47 UTC (rev 99587)
+++ trunk/Source/WebCore/bindings/v8/npruntime.cpp	2011-11-08 18:20:18 UTC (rev 99588)
@@ -356,67 +356,75 @@
 typedef WTF::HashMap<NPObject*, NPObjectSet*> NPRootObjectMap;
 
 // A map of live NPObjects with pointers to their Roots.
-NPObjectMap liveObjectMap;
+static NPObjectMap& liveObjectMap()
+{
+    DEFINE_STATIC_LOCAL(NPObjectMap, objectMap, ());
+    return objectMap;
+}
 
 // A map of the root objects and the list of NPObjects
 // associated with that object.
-NPRootObjectMap rootObjectMap;
+static NPRootObjectMap& rootObjectMap()
+{
+    DEFINE_STATIC_LOCAL(NPRootObjectMap, objectMap, ());
+    return objectMap;
+}
 
 void _NPN_RegisterObject(NPObject* npObject, NPObject* owner)
 {
     ASSERT(npObject);
 
     // Check if already registered.
-    if (liveObjectMap.find(npObject) != liveObjectMap.end())
+    if (liveObjectMap().find(npObject) != liveObjectMap().end())
         return;
 
     if (!owner) {
         // Registering a new owner object.
-        ASSERT(rootObjectMap.find(npObject) == rootObjectMap.end());
-        rootObjectMap.set(npObject, new NPObjectSet());
+        ASSERT(rootObjectMap().find(npObject) == rootObjectMap().end());
+        rootObjectMap().set(npObject, new NPObjectSet());
     } else {
         // Always associate this object with it's top-most parent.
         // Since we always flatten, we only have to look up one level.
-        NPObjectMap::iterator ownerEntry = liveObjectMap.find(owner);
+        NPObjectMap::iterator ownerEntry = liveObjectMap().find(owner);
         NPObject* parent = 0;
-        if (liveObjectMap.end() != ownerEntry)
+        if (liveObjectMap().end() != ownerEntry)
             parent = ownerEntry->second;
 
         if (parent)
             owner = parent;
-        ASSERT(rootObjectMap.find(npObject) == rootObjectMap.end());
-        if (rootObjectMap.find(owner) != rootObjectMap.end())
-            rootObjectMap.get(owner)->add(npObject);
+        ASSERT(rootObjectMap().find(npObject) == rootObjectMap().end());
+        if (rootObjectMap().find(owner) != rootObjectMap().end())
+            rootObjectMap().get(owner)->add(npObject);
     }
 
-    ASSERT(liveObjectMap.find(npObject) == liveObjectMap.end());
-    liveObjectMap.set(npObject, owner);
+    ASSERT(liveObjectMap().find(npObject) == liveObjectMap().end());
+    liveObjectMap().set(npObject, owner);
 }
 
 void _NPN_UnregisterObject(NPObject* npObject)
 {
     ASSERT(npObject);
-    ASSERT(liveObjectMap.find(npObject) != liveObjectMap.end());
+    ASSERT(liveObjectMap().find(npObject) != liveObjectMap().end());
 
     NPObject* owner = 0;
-    if (liveObjectMap.find(npObject) != liveObjectMap.end())
-        owner = liveObjectMap.find(npObject)->second;
+    if (liveObjectMap().find(npObject) != liveObjectMap().end())
+        owner = liveObjectMap().find(npObject)->second;
 
     if (!owner) {
         // Unregistering a owner object; also unregister it's descendants.
-        ASSERT(rootObjectMap.find(npObject) != rootObjectMap.end());
-        NPObjectSet* set = rootObjectMap.get(npObject);
+        ASSERT(rootObjectMap().find(npObject) != rootObjectMap().end());
+        NPObjectSet* set = rootObjectMap().get(npObject);
         while (set->size() > 0) {
 #ifndef NDEBUG
             int size = set->size();
 #endif
             NPObject* sub_object = *(set->begin());
             // The sub-object should not be a owner!
-            ASSERT(rootObjectMap.find(sub_object) == rootObjectMap.end());
+            ASSERT(rootObjectMap().find(sub_object) == rootObjectMap().end());
 
             // First, unregister the object.
             set->remove(sub_object);
-            liveObjectMap.remove(sub_object);
+            liveObjectMap().remove(sub_object);
 
             // Script objects hold a refernce to their DOMWindow*, which is going away if
             // we're unregistering the associated owner NPObject. Clear it out.
@@ -431,23 +439,23 @@
             ASSERT(set->size() < size);
         }
         delete set;
-        rootObjectMap.remove(npObject);
+        rootObjectMap().remove(npObject);
     } else {
-        NPRootObjectMap::iterator ownerEntry = rootObjectMap.find(owner);
-        if (ownerEntry != rootObjectMap.end()) {
+        NPRootObjectMap::iterator ownerEntry = rootObjectMap().find(owner);
+        if (ownerEntry != rootObjectMap().end()) {
             NPObjectSet* list = ownerEntry->second;
             ASSERT(list->find(npObject) != list->end());
             list->remove(npObject);
         }
     }
 
-    liveObjectMap.remove(npObject);
+    liveObjectMap().remove(npObject);
     forgetV8ObjectForNPObject(npObject);
 }
 
 bool _NPN_IsAlive(NPObject* npObject)
 {
-    return liveObjectMap.find(npObject) != liveObjectMap.end();
+    return liveObjectMap().find(npObject) != liveObjectMap().end();
 }
 
 }  // extern "C"

Modified: trunk/Source/WebCore/plugins/chromium/PluginDataChromium.cpp (99587 => 99588)


--- trunk/Source/WebCore/plugins/chromium/PluginDataChromium.cpp	2011-11-08 18:17:47 UTC (rev 99587)
+++ trunk/Source/WebCore/plugins/chromium/PluginDataChromium.cpp	2011-11-08 18:20:18 UTC (rev 99588)
@@ -63,24 +63,28 @@
     bool m_refresh;
 };
 
-static PluginCache pluginCache;
+static PluginCache& pluginCache()
+{
+    DEFINE_STATIC_LOCAL(PluginCache, cache, ());
+    return cache;
+}
 
 void PluginData::initPlugins(const Page*)
 {
-    const Vector<PluginInfo>& plugins = pluginCache.plugins();
+    const Vector<PluginInfo>& plugins = pluginCache().plugins();
     for (size_t i = 0; i < plugins.size(); ++i)
         m_plugins.append(plugins[i]);
 }
 
 void PluginData::refresh()
 {
-    pluginCache.reset(true);
-    pluginCache.plugins();  // Force the plugins to be reloaded now.
+    pluginCache().reset(true);
+    pluginCache().plugins(); // Force the plugins to be reloaded now.
 }
 
 String getPluginMimeTypeFromExtension(const String& extension)
 {
-    const Vector<PluginInfo>& plugins = pluginCache.plugins();
+    const Vector<PluginInfo>& plugins = pluginCache().plugins();
     for (size_t i = 0; i < plugins.size(); ++i) {
         for (size_t j = 0; j < plugins[i].mimes.size(); ++j) {
             const MimeClassInfo& mime = plugins[i].mimes[j];
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to