Title: [196104] trunk/Source
Revision
196104
Author
akl...@apple.com
Date
2016-02-03 19:12:23 -0800 (Wed, 03 Feb 2016)

Log Message

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

Reviewed by Gavin Barraclough.

Source/_javascript_Core:

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.

* bindings/js/GCController.cpp:
(WebCore::GCController::deleteAllLinkedCode):
* bindings/js/GCController.h:
* loader/FrameLoader.cpp:
(WebCore::FrameLoader::commitProvisionalLoad):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (196103 => 196104)


--- trunk/Source/_javascript_Core/ChangeLog	2016-02-04 01:48:22 UTC (rev 196103)
+++ trunk/Source/_javascript_Core/ChangeLog	2016-02-04 03:12:23 UTC (rev 196104)
@@ -1,3 +1,16 @@
+2016-02-03  Andreas Kling  <akl...@apple.com>
+
+        [iOS] Throw away linked code when navigating to a new page.
+        <https://webkit.org/b/153851>
+
+        Reviewed by Gavin Barraclough.
+
+        Add a VM API for throwing away linked code only.
+
+        * runtime/VM.cpp:
+        (JSC::VM::deleteAllLinkedCode):
+        * runtime/VM.h:
+
 2016-02-03  Michael Catanzaro  <mcatanz...@igalia.com>
 
         [GTK][EFL] Switch FTL to B3

Modified: trunk/Source/_javascript_Core/runtime/VM.cpp (196103 => 196104)


--- trunk/Source/_javascript_Core/runtime/VM.cpp	2016-02-04 01:48:22 UTC (rev 196103)
+++ trunk/Source/_javascript_Core/runtime/VM.cpp	2016-02-04 03:12:23 UTC (rev 196104)
@@ -542,6 +542,14 @@
     entryScope->addDidPopListener(callback);
 }
 
+void VM::deleteAllLinkedCode()
+{
+    whenIdle([this]() {
+        heap.deleteAllCodeBlocks();
+        heap.reportAbandonedObjectGraph();
+    });
+}
+
 void VM::deleteAllCode()
 {
     whenIdle([this]() {

Modified: trunk/Source/_javascript_Core/runtime/VM.h (196103 => 196104)


--- trunk/Source/_javascript_Core/runtime/VM.h	2016-02-04 01:48:22 UTC (rev 196103)
+++ trunk/Source/_javascript_Core/runtime/VM.h	2016-02-04 03:12:23 UTC (rev 196104)
@@ -574,6 +574,7 @@
     JS_EXPORT_PRIVATE void whenIdle(std::function<void()>);
 
     JS_EXPORT_PRIVATE void deleteAllCode();
+    JS_EXPORT_PRIVATE void deleteAllLinkedCode();
 
     void registerWatchpointForImpureProperty(const Identifier&, Watchpoint*);
     

Modified: trunk/Source/WebCore/ChangeLog (196103 => 196104)


--- trunk/Source/WebCore/ChangeLog	2016-02-04 01:48:22 UTC (rev 196103)
+++ trunk/Source/WebCore/ChangeLog	2016-02-04 03:12:23 UTC (rev 196104)
@@ -1,3 +1,22 @@
+2016-02-03  Andreas Kling  <akl...@apple.com>
+
+        [iOS] Throw away linked code when navigating to a new page.
+        <https://webkit.org/b/153851>
+
+        Reviewed by Gavin Barraclough.
+
+        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.
+
+        * bindings/js/GCController.cpp:
+        (WebCore::GCController::deleteAllLinkedCode):
+        * bindings/js/GCController.h:
+        * loader/FrameLoader.cpp:
+        (WebCore::FrameLoader::commitProvisionalLoad):
+
 2016-02-03  Alex Christensen  <achristen...@webkit.org>
 
         Report wasBlocked and cannotShowURL errors when using NetworkSession

Modified: trunk/Source/WebCore/bindings/js/GCController.cpp (196103 => 196104)


--- trunk/Source/WebCore/bindings/js/GCController.cpp	2016-02-04 01:48:22 UTC (rev 196103)
+++ trunk/Source/WebCore/bindings/js/GCController.cpp	2016-02-04 03:12:23 UTC (rev 196104)
@@ -122,4 +122,10 @@
     JSDOMWindow::commonVM().deleteAllCode();
 }
 
+void GCController::deleteAllLinkedCode()
+{
+    JSLockHolder lock(JSDOMWindow::commonVM());
+    JSDOMWindow::commonVM().deleteAllLinkedCode();
+}
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/bindings/js/GCController.h (196103 => 196104)


--- trunk/Source/WebCore/bindings/js/GCController.h	2016-02-04 01:48:22 UTC (rev 196103)
+++ trunk/Source/WebCore/bindings/js/GCController.h	2016-02-04 03:12:23 UTC (rev 196104)
@@ -46,6 +46,7 @@
     WEBCORE_EXPORT void garbageCollectOnAlternateThreadForDebugging(bool waitUntilDone); // Used for stress testing.
     WEBCORE_EXPORT void setJavaScriptGarbageCollectorTimerEnabled(bool);
     WEBCORE_EXPORT void deleteAllCode();
+    WEBCORE_EXPORT void deleteAllLinkedCode();
 
 private:
     GCController(); // Use singleton() instead.

Modified: trunk/Source/WebCore/loader/FrameLoader.cpp (196103 => 196104)


--- trunk/Source/WebCore/loader/FrameLoader.cpp	2016-02-04 01:48:22 UTC (rev 196103)
+++ trunk/Source/WebCore/loader/FrameLoader.cpp	2016-02-04 03:12:23 UTC (rev 196104)
@@ -66,6 +66,7 @@
 #include "FrameNetworkingContext.h"
 #include "FrameTree.h"
 #include "FrameView.h"
+#include "GCController.h"
 #include "HTMLAnchorElement.h"
 #include "HTMLFormElement.h"
 #include "HTMLInputElement.h"
@@ -1761,6 +1762,13 @@
     if (!m_frame.tree().parent() && history().currentItem())
         PageCache::singleton().addIfCacheable(*history().currentItem(), m_frame.page());
 
+#if PLATFORM(IOS)
+    // For top-level navigations, have JSC throw away linked code. The immediate memory savings far
+    // outweigh the cost of recompiling in the case of a future backwards navigation.
+    if (!m_frame.tree().parent())
+        GCController::singleton().deleteAllLinkedCode();
+#endif
+
     if (m_loadType != FrameLoadType::Replace)
         closeOldDataSources();
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to