Changeset 196217 in webkit


Ignore:
Timestamp:
Feb 6, 2016 9:00:30 AM (8 years ago)
Author:
akling@apple.com
Message:

[iOS] Throw away linked code when navigating to a new page.
<https://webkit.org/b/153851>

Reviewed by Gavin Barraclough.

Source/JavaScriptCore:

Add a VM API for throwing away linked code only.

  • runtime/VM.cpp:

(JSC::VM::deleteAllLinkedCode):

  • runtime/VM.h:

Source/WebCore:

When navigating to a new page, tell JSC to throw out any linked code it has lying around.
Linked code is tied to a specific global object, and as we're creating a new one for the
new page, none of it is useful to us here.

In the event that the user navigates back, the cost of relinking some code will be far
lower than the memory cost of keeping all of it around.

This landed previously but was rolled out due to a Speedometer regression. I've made one
minor but important change here: only throw away code if we're navigating away from an
existing history item. Or in other words, don't throw away code for "force peeks" or any
other navigations that are not traditional top-level main frame navigations.

  • bindings/js/GCController.cpp:

(WebCore::GCController::deleteAllLinkedCode):

  • bindings/js/GCController.h:
  • loader/FrameLoader.cpp:

(WebCore::FrameLoader::commitProvisionalLoad):

Location:
trunk/Source
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r196213 r196217  
     12016-02-06  Andreas Kling  <akling@apple.com>
     2
     3        [iOS] Throw away linked code when navigating to a new page.
     4        <https://webkit.org/b/153851>
     5
     6        Reviewed by Gavin Barraclough.
     7
     8        Add a VM API for throwing away linked code only.
     9
     10        * runtime/VM.cpp:
     11        (JSC::VM::deleteAllLinkedCode):
     12        * runtime/VM.h:
     13
    1142016-02-06  Commit Queue  <commit-queue@webkit.org>
    215
  • trunk/Source/JavaScriptCore/runtime/VM.cpp

    r196213 r196217  
    543543}
    544544
     545void VM::deleteAllLinkedCode()
     546{
     547    whenIdle([this]() {
     548        heap.deleteAllCodeBlocks();
     549        heap.reportAbandonedObjectGraph();
     550    });
     551}
     552
    545553void VM::deleteAllCode()
    546554{
  • trunk/Source/JavaScriptCore/runtime/VM.h

    r196213 r196217  
    575575
    576576    JS_EXPORT_PRIVATE void deleteAllCode();
     577    JS_EXPORT_PRIVATE void deleteAllLinkedCode();
    577578
    578579    void registerWatchpointForImpureProperty(const Identifier&, Watchpoint*);
  • trunk/Source/WebCore/ChangeLog

    r196216 r196217  
     12016-02-06  Andreas Kling  <akling@apple.com>
     2
     3        [iOS] Throw away linked code when navigating to a new page.
     4        <https://webkit.org/b/153851>
     5
     6        Reviewed by Gavin Barraclough.
     7
     8        When navigating to a new page, tell JSC to throw out any linked code it has lying around.
     9        Linked code is tied to a specific global object, and as we're creating a new one for the
     10        new page, none of it is useful to us here.
     11
     12        In the event that the user navigates back, the cost of relinking some code will be far
     13        lower than the memory cost of keeping all of it around.
     14
     15        This landed previously but was rolled out due to a Speedometer regression. I've made one
     16        minor but important change here: only throw away code if we're navigating away from an
     17        existing history item. Or in other words, don't throw away code for "force peeks" or any
     18        other navigations that are not traditional top-level main frame navigations.
     19
     20        * bindings/js/GCController.cpp:
     21        (WebCore::GCController::deleteAllLinkedCode):
     22        * bindings/js/GCController.h:
     23        * loader/FrameLoader.cpp:
     24        (WebCore::FrameLoader::commitProvisionalLoad):
     25
    1262016-02-06  Konstantin Tokarev  <annulen@yandex.ru>
    227
  • trunk/Source/WebCore/bindings/js/GCController.cpp

    r196213 r196217  
    123123}
    124124
     125void GCController::deleteAllLinkedCode()
     126{
     127    JSLockHolder lock(JSDOMWindow::commonVM());
     128    JSDOMWindow::commonVM().deleteAllLinkedCode();
     129}
     130
    125131} // namespace WebCore
  • trunk/Source/WebCore/bindings/js/GCController.h

    r196213 r196217  
    4747    WEBCORE_EXPORT void setJavaScriptGarbageCollectorTimerEnabled(bool);
    4848    WEBCORE_EXPORT void deleteAllCode();
     49    WEBCORE_EXPORT void deleteAllLinkedCode();
    4950
    5051private:
  • trunk/Source/WebCore/loader/FrameLoader.cpp

    r196213 r196217  
    6767#include "FrameTree.h"
    6868#include "FrameView.h"
     69#include "GCController.h"
    6970#include "HTMLAnchorElement.h"
    7071#include "HTMLFormElement.h"
     
    17571758    willTransitionToCommitted();
    17581759
    1759     // Check to see if we need to cache the page we are navigating away from into the back/forward cache.
    1760     // We are doing this here because we know for sure that a new page is about to be loaded.
    1761     if (!m_frame.tree().parent() && history().currentItem())
     1760    if (!m_frame.tree().parent() && history().currentItem()) {
     1761        // Check to see if we need to cache the page we are navigating away from into the back/forward cache.
     1762        // We are doing this here because we know for sure that a new page is about to be loaded.
    17621763        PageCache::singleton().addIfCacheable(*history().currentItem(), m_frame.page());
     1764
     1765#if PLATFORM(IOS)
     1766        // For top-level navigations, have JSC throw away linked code. The immediate memory savings far
     1767        // outweigh the cost of recompiling in the case of a future backwards navigation.
     1768        GCController::singleton().deleteAllLinkedCode();
     1769#endif
     1770    }
    17631771
    17641772    if (m_loadType != FrameLoadType::Replace)
Note: See TracChangeset for help on using the changeset viewer.