Access GCController instance via GCController::singleton() instead of a free function
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 9 Jun 2015 00:28:19 +0000 (00:28 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 9 Jun 2015 00:28:19 +0000 (00:28 +0000)
https://bugs.webkit.org/show_bug.cgi?id=145776

Reviewed by Darin Adler.

Access GCController instance via GCController::singleton() instead of a
free function as per coding style and for consistency with other
singleton classes in the codebase.

Source/WebCore:

* bindings/js/GCController.cpp:
(WebCore::GCController::singleton):
(WebCore::gcController): Deleted.
* bindings/js/GCController.h:
* bindings/js/JSDOMWindowShell.cpp:
(WebCore::JSDOMWindowShell::setWindow):
* bindings/js/ScriptCachedFrameData.cpp:
(WebCore::ScriptCachedFrameData::clear):
* bindings/js/ScriptController.cpp:
(WebCore::collectGarbageAfterWindowShellDestruction):
* platform/MemoryPressureHandler.cpp:
(WebCore::MemoryPressureHandler::releaseCriticalMemory):

Source/WebKit/mac:

* Misc/WebCoreStatistics.mm:
(+[WebCoreStatistics garbageCollectJavaScriptObjects]):
(+[WebCoreStatistics garbageCollectJavaScriptObjectsOnAlternateThreadForDebugging:]):
(+[WebCoreStatistics setJavaScriptGarbageCollectorTimerEnabled:]):
* WebView/WebView.mm:
(+[WebView garbageCollectNow]):
(+[WebView discardAllCompiledCode]):
(-[WebView _close]):

Source/WebKit/win:

* WebCoreStatistics.cpp:
(WebCoreStatistics::garbageCollectJavaScriptObjects):
(WebCoreStatistics::garbageCollectJavaScriptObjectsOnAlternateThreadForDebugging):
(WebCoreStatistics::setJavaScriptGarbageCollectorTimerEnabled):
* WebJavaScriptCollector.cpp:
(WebJavaScriptCollector::collect):
(WebJavaScriptCollector::collectOnAlternateThread):

Source/WebKit2:

* WebProcess/InjectedBundle/InjectedBundle.cpp:
(WebKit::InjectedBundle::garbageCollectJavaScriptObjects):
(WebKit::InjectedBundle::garbageCollectJavaScriptObjectsOnAlternateThreadForDebugging):
* WebProcess/WebProcess.cpp:
(WebKit::WebProcess::terminate):
(WebKit::WebProcess::didClose):
(WebKit::WebProcess::garbageCollectJavaScriptObjects):
(WebKit::WebProcess::setJavaScriptGarbageCollectorTimerEnabled):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@185342 268f45cc-cd09-0410-ab3c-d52691b4dbfc

16 files changed:
Source/WebCore/ChangeLog
Source/WebCore/bindings/js/GCController.cpp
Source/WebCore/bindings/js/GCController.h
Source/WebCore/bindings/js/JSDOMWindowShell.cpp
Source/WebCore/bindings/js/ScriptCachedFrameData.cpp
Source/WebCore/bindings/js/ScriptController.cpp
Source/WebCore/platform/MemoryPressureHandler.cpp
Source/WebKit/mac/ChangeLog
Source/WebKit/mac/Misc/WebCoreStatistics.mm
Source/WebKit/mac/WebView/WebView.mm
Source/WebKit/win/ChangeLog
Source/WebKit/win/WebCoreStatistics.cpp
Source/WebKit/win/WebJavaScriptCollector.cpp
Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/InjectedBundle/InjectedBundle.cpp
Source/WebKit2/WebProcess/WebProcess.cpp

index 83fcc20..86455bc 100644 (file)
@@ -1,3 +1,27 @@
+2015-06-08  Chris Dumez  <cdumez@apple.com>
+
+        Access GCController instance via GCController::singleton() instead of a free function
+        https://bugs.webkit.org/show_bug.cgi?id=145776
+
+        Reviewed by Darin Adler.
+
+        Access GCController instance via GCController::singleton() instead of a
+        free function as per coding style and for consistency with other
+        singleton classes in the codebase.
+
+        * bindings/js/GCController.cpp:
+        (WebCore::GCController::singleton):
+        (WebCore::gcController): Deleted.
+        * bindings/js/GCController.h:
+        * bindings/js/JSDOMWindowShell.cpp:
+        (WebCore::JSDOMWindowShell::setWindow):
+        * bindings/js/ScriptCachedFrameData.cpp:
+        (WebCore::ScriptCachedFrameData::clear):
+        * bindings/js/ScriptController.cpp:
+        (WebCore::collectGarbageAfterWindowShellDestruction):
+        * platform/MemoryPressureHandler.cpp:
+        (WebCore::MemoryPressureHandler::releaseCriticalMemory):
+
 2015-06-08  Daniel Bates  <dabates@apple.com>
 
         Mouse release on AutoFill button activates it; should only activate on click
index 955294f..c0a2bc4 100644 (file)
@@ -32,6 +32,7 @@
 #include <heap/Heap.h>
 #include <wtf/StdLibExtras.h>
 #include <wtf/FastMalloc.h>
+#include <wtf/NeverDestroyed.h>
 
 using namespace JSC;
 
@@ -43,10 +44,10 @@ static void collect(void*)
     JSDOMWindow::commonVM().heap.collectAllGarbage();
 }
 
-GCController& gcController()
+GCController& GCController::singleton()
 {
-    DEPRECATED_DEFINE_STATIC_LOCAL(GCController, staticGCController, ());
-    return staticGCController;
+    static NeverDestroyed<GCController> controller;
+    return controller;
 }
 
 GCController::GCController()
index 41567c2..fa31cda 100644 (file)
 #ifndef GCController_h
 #define GCController_h
 
-#include <wtf/FastMalloc.h>
+#include <wtf/Forward.h>
 #include <wtf/Noncopyable.h>
 #include "Timer.h"
 
 namespace WebCore {
 
-    class GCController {
-        WTF_MAKE_NONCOPYABLE(GCController); WTF_MAKE_FAST_ALLOCATED;
-        WEBCORE_EXPORT friend GCController& gcController();
+class GCController {
+    WTF_MAKE_NONCOPYABLE(GCController);
+    friend class WTF::NeverDestroyed<GCController>;
+public:
+    WEBCORE_EXPORT static GCController& singleton();
 
-    public:
-        WEBCORE_EXPORT void garbageCollectSoon();
-        WEBCORE_EXPORT void garbageCollectNow(); // It's better to call garbageCollectSoon, unless you have a specific reason not to.
-        void garbageCollectOnNextRunLoop();
+    WEBCORE_EXPORT void garbageCollectSoon();
+    WEBCORE_EXPORT void garbageCollectNow(); // It's better to call garbageCollectSoon, unless you have a specific reason not to.
+    void garbageCollectOnNextRunLoop();
 
-        WEBCORE_EXPORT void garbageCollectOnAlternateThreadForDebugging(bool waitUntilDone); // Used for stress testing.
-        WEBCORE_EXPORT void releaseExecutableMemory();
-        WEBCORE_EXPORT void setJavaScriptGarbageCollectorTimerEnabled(bool);
-        WEBCORE_EXPORT void discardAllCompiledCode();
+    WEBCORE_EXPORT void garbageCollectOnAlternateThreadForDebugging(bool waitUntilDone); // Used for stress testing.
+    WEBCORE_EXPORT void releaseExecutableMemory();
+    WEBCORE_EXPORT void setJavaScriptGarbageCollectorTimerEnabled(bool);
+    WEBCORE_EXPORT void discardAllCompiledCode();
 
-    private:
-        GCController(); // Use gcController() instead
+private:
+    GCController(); // Use singleton() instead.
 
-        void gcTimerFired();
-        Timer m_GCTimer;
-    };
-
-    // Function to obtain the global GC controller.
-    WEBCORE_EXPORT GCController& gcController() PURE_FUNCTION;
+    void gcTimerFired();
+    Timer m_GCTimer;
+};
 
 } // namespace WebCore
 
index 429aa8a..54cb5e5 100644 (file)
@@ -66,7 +66,7 @@ void JSDOMWindowShell::setWindow(VM& vm, JSDOMWindow* window)
     ASSERT_ARG(window, window);
     setTarget(vm, window);
     structure()->setGlobalObject(vm, window);
-    gcController().garbageCollectSoon();
+    GCController::singleton().garbageCollectSoon();
 }
 
 void JSDOMWindowShell::setWindow(PassRefPtr<DOMWindow> domWindow)
index 3b1e89e..0430ba7 100644 (file)
@@ -109,7 +109,7 @@ void ScriptCachedFrameData::clear()
 
     JSLockHolder lock(JSDOMWindowBase::commonVM());
     m_windows.clear();
-    gcController().garbageCollectSoon();
+    GCController::singleton().garbageCollectSoon();
 }
 
 } // namespace WebCore
index cf299cc..161e5f0 100644 (file)
@@ -69,9 +69,9 @@ static void collectGarbageAfterWindowShellDestruction()
     if (MemoryPressureHandler::singleton().isUnderMemoryPressure()) {
         // NOTE: We do the collection on next runloop to ensure that there's no pointer
         //       to the window object on the stack.
-        gcController().garbageCollectOnNextRunLoop();
+        GCController::singleton().garbageCollectOnNextRunLoop();
     } else
-        gcController().garbageCollectSoon();
+        GCController::singleton().garbageCollectSoon();
 }
 
 void ScriptController::initializeThreading()
index 647cd03..9bafd74 100644 (file)
@@ -128,7 +128,7 @@ void MemoryPressureHandler::releaseCriticalMemory(Synchronous synchronous)
 
     {
         ReliefLogger log("Discard all JIT-compiled code");
-        gcController().discardAllCompiledCode();
+        GCController::singleton().discardAllCompiledCode();
     }
 
     {
@@ -138,11 +138,11 @@ void MemoryPressureHandler::releaseCriticalMemory(Synchronous synchronous)
 
     if (synchronous == Synchronous::Yes) {
         ReliefLogger log("Collecting JavaScript garbage");
-        gcController().garbageCollectNow();
+        GCController::singleton().garbageCollectNow();
     } else {
         // FIXME: We should do a garbage sweep and prune dead resources from the MemoryCache
         // after the garbage collection has completed to free up more memory.
-        gcController().garbageCollectSoon();
+        GCController::singleton().garbageCollectSoon();
 
         // Do a full sweep of collected objects. garbageCollectNow() already does this so we only
         // need to do this if it isn't called.
index 75e389d..9d41ec8 100644 (file)
@@ -1,3 +1,23 @@
+2015-06-08  Chris Dumez  <cdumez@apple.com>
+
+        Access GCController instance via GCController::singleton() instead of a free function
+        https://bugs.webkit.org/show_bug.cgi?id=145776
+
+        Reviewed by Darin Adler.
+
+        Access GCController instance via GCController::singleton() instead of a
+        free function as per coding style and for consistency with other
+        singleton classes in the codebase.
+
+        * Misc/WebCoreStatistics.mm:
+        (+[WebCoreStatistics garbageCollectJavaScriptObjects]):
+        (+[WebCoreStatistics garbageCollectJavaScriptObjectsOnAlternateThreadForDebugging:]):
+        (+[WebCoreStatistics setJavaScriptGarbageCollectorTimerEnabled:]):
+        * WebView/WebView.mm:
+        (+[WebView garbageCollectNow]):
+        (+[WebView discardAllCompiledCode]):
+        (-[WebView _close]):
+
 2015-06-08  Anders Carlsson  <andersca@apple.com>
 
         Remove more unused Objective-C methods
index 6644cc4..78210ac 100644 (file)
@@ -112,17 +112,17 @@ using namespace WebCore;
 
 + (void)garbageCollectJavaScriptObjects
 {
-    gcController().garbageCollectNow();
+    GCController::singleton().garbageCollectNow();
 }
 
 + (void)garbageCollectJavaScriptObjectsOnAlternateThreadForDebugging:(BOOL)waitUntilDone
 {
-    gcController().garbageCollectOnAlternateThreadForDebugging(waitUntilDone);
+    GCController::singleton().garbageCollectOnAlternateThreadForDebugging(waitUntilDone);
 }
 
 + (void)setJavaScriptGarbageCollectorTimerEnabled:(BOOL)enable
 {
-    gcController().setJavaScriptGarbageCollectorTimerEnabled(enable);
+    GCController::singleton().setJavaScriptGarbageCollectorTimerEnabled(enable);
 }
 
 + (size_t)iconPageURLMappingCount
index 4bab193..ff26ab1 100644 (file)
@@ -1350,7 +1350,7 @@ static void WebKitInitializeGamepadProviderIfNecessary()
 {
     ASSERT(WebThreadIsCurrent());
     WebKit::MemoryMeasure measurer("Memory warning: Calling JavaScript GC.");
-    gcController().garbageCollectNow();
+    GCController::singleton().garbageCollectNow();
 }
 
 + (void)purgeInactiveFontData
@@ -1371,7 +1371,7 @@ static void WebKitInitializeGamepadProviderIfNecessary()
 {
     ASSERT(WebThreadIsCurrent());
     WebKit::MemoryMeasure measurer("Memory warning: Discarding JIT'ed code.");
-    gcController().discardAllCompiledCode();
+    GCController::singleton().discardAllCompiledCode();
 }
 
 + (BOOL)isCharacterSmartReplaceExempt:(unichar)character isPreviousCharacter:(BOOL)b
@@ -1802,7 +1802,7 @@ static bool fastDocumentTeardownEnabled()
 #ifndef NDEBUG
     // Need this to make leak messages accurate.
     if (applicationIsTerminating) {
-        gcController().garbageCollectNow();
+        GCController::singleton().garbageCollectNow();
         [WebCache setDisabled:YES];
     }
 #endif
index 0ed9346..3f3033d 100644 (file)
@@ -1,3 +1,22 @@
+2015-06-08  Chris Dumez  <cdumez@apple.com>
+
+        Access GCController instance via GCController::singleton() instead of a free function
+        https://bugs.webkit.org/show_bug.cgi?id=145776
+
+        Reviewed by Darin Adler.
+
+        Access GCController instance via GCController::singleton() instead of a
+        free function as per coding style and for consistency with other
+        singleton classes in the codebase.
+
+        * WebCoreStatistics.cpp:
+        (WebCoreStatistics::garbageCollectJavaScriptObjects):
+        (WebCoreStatistics::garbageCollectJavaScriptObjectsOnAlternateThreadForDebugging):
+        (WebCoreStatistics::setJavaScriptGarbageCollectorTimerEnabled):
+        * WebJavaScriptCollector.cpp:
+        (WebJavaScriptCollector::collect):
+        (WebJavaScriptCollector::collectOnAlternateThread):
+
 2015-06-05  Mark Lam  <mark.lam@apple.com>
 
         finally blocks should not set the exception stack trace when re-throwing the exception.
index 5b8de7a..574b6d3 100644 (file)
@@ -246,19 +246,19 @@ HRESULT STDMETHODCALLTYPE WebCoreStatistics::glyphPageCount(
 
 HRESULT WebCoreStatistics::garbageCollectJavaScriptObjects()
 {
-    gcController().garbageCollectNow();
+    GCController::singleton().garbageCollectNow();
     return S_OK;
 }
 
 HRESULT WebCoreStatistics::garbageCollectJavaScriptObjectsOnAlternateThreadForDebugging(BOOL waitUntilDone)
 {
-    gcController().garbageCollectOnAlternateThreadForDebugging(waitUntilDone);
+    GCController::singleton().garbageCollectOnAlternateThreadForDebugging(waitUntilDone);
     return S_OK;
 }
 
 HRESULT WebCoreStatistics::setJavaScriptGarbageCollectorTimerEnabled(BOOL enable)
 {
-    gcController().setJavaScriptGarbageCollectorTimerEnabled(enable);
+    GCController::singleton().setJavaScriptGarbageCollectorTimerEnabled(enable);
     return S_OK;
 }
 
index badd084..72d678a 100644 (file)
@@ -91,14 +91,14 @@ ULONG STDMETHODCALLTYPE WebJavaScriptCollector::Release(void)
 
 HRESULT STDMETHODCALLTYPE WebJavaScriptCollector::collect()
 {
-    gcController().garbageCollectNow();
+    GCController::singleton().garbageCollectNow();
     return S_OK;
 }
 
 HRESULT STDMETHODCALLTYPE WebJavaScriptCollector::collectOnAlternateThread( 
     /* [in] */ BOOL waitUntilDone)
 {
-    gcController().garbageCollectOnAlternateThreadForDebugging(!!waitUntilDone);
+    GCController::singleton().garbageCollectOnAlternateThreadForDebugging(!!waitUntilDone);
     return S_OK;
 }
 
index 81ab64e..6a9dff6 100644 (file)
@@ -1,3 +1,23 @@
+2015-06-08  Chris Dumez  <cdumez@apple.com>
+
+        Access GCController instance via GCController::singleton() instead of a free function
+        https://bugs.webkit.org/show_bug.cgi?id=145776
+
+        Reviewed by Darin Adler.
+
+        Access GCController instance via GCController::singleton() instead of a
+        free function as per coding style and for consistency with other
+        singleton classes in the codebase.
+
+        * WebProcess/InjectedBundle/InjectedBundle.cpp:
+        (WebKit::InjectedBundle::garbageCollectJavaScriptObjects):
+        (WebKit::InjectedBundle::garbageCollectJavaScriptObjectsOnAlternateThreadForDebugging):
+        * WebProcess/WebProcess.cpp:
+        (WebKit::WebProcess::terminate):
+        (WebKit::WebProcess::didClose):
+        (WebKit::WebProcess::garbageCollectJavaScriptObjects):
+        (WebKit::WebProcess::setJavaScriptGarbageCollectorTimerEnabled):
+
 2015-06-08  Anders Carlsson  <andersca@apple.com>
 
         Include IndexedDB databases in -[WKWebsiteDataStore allWebsiteDataTypes]
index 9c9d3ee..0dd6ad7 100644 (file)
@@ -497,12 +497,12 @@ void InjectedBundle::removeAllUserContent(WebPageGroupProxy* pageGroup)
 
 void InjectedBundle::garbageCollectJavaScriptObjects()
 {
-    gcController().garbageCollectNow();
+    GCController::singleton().garbageCollectNow();
 }
 
 void InjectedBundle::garbageCollectJavaScriptObjectsOnAlternateThreadForDebugging(bool waitUntilDone)
 {
-    gcController().garbageCollectOnAlternateThreadForDebugging(waitUntilDone);
+    GCController::singleton().garbageCollectOnAlternateThreadForDebugging(waitUntilDone);
 }
 
 size_t InjectedBundle::javaScriptObjectsCount()
index 3c315f4..2126f74 100644 (file)
@@ -591,7 +591,7 @@ bool WebProcess::shouldTerminate()
 void WebProcess::terminate()
 {
 #ifndef NDEBUG
-    gcController().garbageCollectNow();
+    GCController::singleton().garbageCollectNow();
     FontCache::singleton().invalidate();
     MemoryCache::singleton().setDisabled(true);
 #endif
@@ -655,7 +655,7 @@ void WebProcess::didClose(IPC::Connection&)
         page->close();
     pages.clear();
 
-    gcController().garbageCollectSoon();
+    GCController::singleton().garbageCollectSoon();
     FontCache::singleton().invalidate();
     MemoryCache::singleton().setDisabled(true);
 #endif    
@@ -980,12 +980,12 @@ void WebProcess::getWebCoreStatistics(uint64_t callbackID)
 
 void WebProcess::garbageCollectJavaScriptObjects()
 {
-    gcController().garbageCollectNow();
+    GCController::singleton().garbageCollectNow();
 }
 
 void WebProcess::setJavaScriptGarbageCollectorTimerEnabled(bool flag)
 {
-    gcController().setJavaScriptGarbageCollectorTimerEnabled(flag);
+    GCController::singleton().setJavaScriptGarbageCollectorTimerEnabled(flag);
 }
 
 void WebProcess::handleInjectedBundleMessage(const String& messageName, const UserData& messageBody)