diff options
Diffstat (limited to 'Source/WebCore/bindings/js/GCController.cpp')
-rw-r--r-- | Source/WebCore/bindings/js/GCController.cpp | 106 |
1 files changed, 49 insertions, 57 deletions
diff --git a/Source/WebCore/bindings/js/GCController.cpp b/Source/WebCore/bindings/js/GCController.cpp index ba70d4a06..6f9fca67f 100644 --- a/Source/WebCore/bindings/js/GCController.cpp +++ b/Source/WebCore/bindings/js/GCController.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007 Apple Inc. All rights reserved. + * Copyright (C) 2007, 2014, 2016 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -10,10 +10,10 @@ * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR @@ -26,11 +26,13 @@ #include "config.h" #include "GCController.h" -#include "JSDOMWindow.h" +#include "CommonVM.h" #include <runtime/VM.h> #include <runtime/JSLock.h> #include <heap/Heap.h> #include <wtf/StdLibExtras.h> +#include <wtf/FastMalloc.h> +#include <wtf/NeverDestroyed.h> using namespace JSC; @@ -38,57 +40,63 @@ namespace WebCore { static void collect(void*) { - JSLockHolder lock(JSDOMWindow::commonVM()); - JSDOMWindow::commonVM()->heap.collectAllGarbage(); + JSLockHolder lock(commonVM()); + commonVM().heap.collectAllGarbage(); } -GCController& gcController() +GCController& GCController::singleton() { - DEFINE_STATIC_LOCAL(GCController, staticGCController, ()); - return staticGCController; + static NeverDestroyed<GCController> controller; + return controller; } GCController::GCController() -#if !USE(CF) - : m_GCTimer(this, &GCController::gcTimerFired) -#endif + : m_GCTimer(*this, &GCController::gcTimerFired) { } void GCController::garbageCollectSoon() { - // We only use reportAbandonedObjectGraph on systems with CoreFoundation - // since it uses a runloop-based timer that is currently only available on - // systems with CoreFoundation. If and when the notion of a run loop is pushed - // down into WTF so that more platforms can take advantage of it, we will be - // able to use reportAbandonedObjectGraph on more platforms. -#if USE(CF) - JSLockHolder lock(JSDOMWindow::commonVM()); - JSDOMWindow::commonVM()->heap.reportAbandonedObjectGraph(); + // We only use reportAbandonedObjectGraph for systems for which there's an implementation + // of the garbage collector timers in JavaScriptCore. We wouldn't need this if JavaScriptCore + // used a timer implementation from WTF like RunLoop::Timer. +#if USE(CF) || USE(GLIB) + JSLockHolder lock(commonVM()); + commonVM().heap.reportAbandonedObjectGraph(); #else + garbageCollectOnNextRunLoop(); +#endif +} + +void GCController::garbageCollectOnNextRunLoop() +{ if (!m_GCTimer.isActive()) m_GCTimer.startOneShot(0); -#endif } -#if !USE(CF) -void GCController::gcTimerFired(Timer<GCController>*) +void GCController::gcTimerFired() { - collect(0); + collect(nullptr); } -#endif void GCController::garbageCollectNow() { - JSLockHolder lock(JSDOMWindow::commonVM()); -#if PLATFORM(IOS) - // If JavaScript was never run in this process, there's no need to call GC which will - // end up creating a VM unnecessarily. - if (!JSDOMWindow::commonVMExists()) - return; + JSLockHolder lock(commonVM()); + if (!commonVM().heap.isCurrentThreadBusy()) { + commonVM().heap.collectAllGarbage(); + WTF::releaseFastMallocFreeMemory(); + } +} + +void GCController::garbageCollectNowIfNotDoneRecently() +{ +#if USE(CF) || USE(GLIB) + JSLockHolder lock(commonVM()); + if (!commonVM().heap.isCurrentThreadBusy()) + commonVM().heap.collectAllGarbageIfNotDoneRecently(); +#else + garbageCollectSoon(); #endif - if (!JSDOMWindow::commonVM()->heap.isBusy()) - JSDOMWindow::commonVM()->heap.collectAllGarbage(); } void GCController::garbageCollectOnAlternateThreadForDebugging(bool waitUntilDone) @@ -103,37 +111,21 @@ void GCController::garbageCollectOnAlternateThreadForDebugging(bool waitUntilDon detachThread(threadID); } -void GCController::releaseExecutableMemory() +void GCController::setJavaScriptGarbageCollectorTimerEnabled(bool enable) { - JSLockHolder lock(JSDOMWindow::commonVM()); - -#if PLATFORM(IOS) - // If JavaScript was never run in this process, there's no need to call GC which will - // end up creating a VM unnecessarily. - if (!JSDOMWindow::commonVMExists()) - return; -#endif - - // We shouldn't have any javascript running on our stack when this function is called. The - // following line asserts that. - ASSERT(!JSDOMWindow::commonVM()->entryScope); - - // But be safe in release builds just in case... - if (JSDOMWindow::commonVM()->entryScope) - return; - - JSDOMWindow::commonVM()->releaseExecutableMemory(); + commonVM().heap.setGarbageCollectionTimerEnabled(enable); } -void GCController::setJavaScriptGarbageCollectorTimerEnabled(bool enable) +void GCController::deleteAllCode(DeleteAllCodeEffort effort) { - JSDOMWindow::commonVM()->heap.setGarbageCollectionTimerEnabled(enable); + JSLockHolder lock(commonVM()); + commonVM().deleteAllCode(effort); } -void GCController::discardAllCompiledCode() +void GCController::deleteAllLinkedCode(DeleteAllCodeEffort effort) { - JSLockHolder lock(JSDOMWindow::commonVM()); - JSDOMWindow::commonVM()->discardAllCode(); + JSLockHolder lock(commonVM()); + commonVM().deleteAllLinkedCode(effort); } } // namespace WebCore |