Loading cnn.com in MiniBrowser hits Structure::dump() under DFG::AdaptiveInferredProp...
authorkeith_miller@apple.com <keith_miller@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 12 Jun 2018 01:46:29 +0000 (01:46 +0000)
committerkeith_miller@apple.com <keith_miller@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 12 Jun 2018 01:46:29 +0000 (01:46 +0000)
https://bugs.webkit.org/show_bug.cgi?id=186467

Reviewed by Simon Fraser.

This patch adds a LazyFireDetail that wraps ScopedLambda so that
we don't actually malloc any strings for firing unless those
Strings are actually going to be printed.

* bytecode/Watchpoint.h:
(JSC::LazyFireDetail::LazyFireDetail):
* dfg/DFGAdaptiveInferredPropertyValueWatchpoint.cpp:
(JSC::DFG::AdaptiveInferredPropertyValueWatchpoint::handleFire):
* dfg/DFGAdaptiveStructureWatchpoint.cpp:
(JSC::DFG::AdaptiveStructureWatchpoint::fireInternal):
* runtime/ArrayPrototype.cpp:
(JSC::ArrayPrototypeAdaptiveInferredPropertyWatchpoint::handleFire):

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

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/bytecode/Watchpoint.h
Source/JavaScriptCore/dfg/DFGAdaptiveInferredPropertyValueWatchpoint.cpp
Source/JavaScriptCore/dfg/DFGAdaptiveStructureWatchpoint.cpp
Source/JavaScriptCore/runtime/ArrayPrototype.cpp

index 5c24a05..658c87b 100644 (file)
@@ -1,3 +1,23 @@
+2018-06-11  Keith Miller  <keith_miller@apple.com>
+
+        Loading cnn.com in MiniBrowser hits Structure::dump() under DFG::AdaptiveInferredPropertyValueWatchpoint::handleFire  which churns 65KB of memory
+        https://bugs.webkit.org/show_bug.cgi?id=186467
+
+        Reviewed by Simon Fraser.
+
+        This patch adds a LazyFireDetail that wraps ScopedLambda so that
+        we don't actually malloc any strings for firing unless those
+        Strings are actually going to be printed.
+
+        * bytecode/Watchpoint.h:
+        (JSC::LazyFireDetail::LazyFireDetail):
+        * dfg/DFGAdaptiveInferredPropertyValueWatchpoint.cpp:
+        (JSC::DFG::AdaptiveInferredPropertyValueWatchpoint::handleFire):
+        * dfg/DFGAdaptiveStructureWatchpoint.cpp:
+        (JSC::DFG::AdaptiveStructureWatchpoint::fireInternal):
+        * runtime/ArrayPrototype.cpp:
+        (JSC::ArrayPrototypeAdaptiveInferredPropertyWatchpoint::handleFire):
+
 2018-06-11  Mark Lam  <mark.lam@apple.com>
 
         Add support for webkit-test-runner jscOptions in DumpRenderTree and WebKitTestRunner.
index 4476e2a..778fe16 100644 (file)
@@ -29,6 +29,7 @@
 #include <wtf/FastMalloc.h>
 #include <wtf/Noncopyable.h>
 #include <wtf/PrintStream.h>
+#include <wtf/ScopedLambda.h>
 #include <wtf/SentinelLinkedList.h>
 #include <wtf/ThreadSafeRefCounted.h>
 
@@ -62,6 +63,28 @@ private:
     const char* m_string;
 };
 
+template<typename... Types>
+class LazyFireDetail : public FireDetail {
+public:
+    LazyFireDetail(const Types&... args)
+    {
+        m_lambda = scopedLambda<void(PrintStream&)>([&] (PrintStream& out) {
+            out.print(args...);
+        });
+    }
+
+    void dump(PrintStream& out) const override { m_lambda(out); }
+
+private:
+    ScopedLambda<void(PrintStream&)> m_lambda;
+};
+
+template<typename... Types>
+LazyFireDetail<Types...> createLazyFireDetail(const Types&... types)
+{
+    return LazyFireDetail<Types...>(types...);
+}
+
 class WatchpointSet;
 
 class Watchpoint : public BasicRawSentinelNode<Watchpoint> {
index 207b2fc..f7b91c8 100644 (file)
@@ -46,12 +46,9 @@ void AdaptiveInferredPropertyValueWatchpoint::handleFire(const FireDetail& detai
         dataLog("Firing watchpoint ", RawPointer(this), " (", key(), ") on ", *m_codeBlock, "\n");
 
 
-    StringPrintStream out;
-    out.print("Adaptation of ", key(), " failed: ", detail);
+    auto lazyDetail = createLazyFireDetail("Adaptation of ", key(), " failed: ", detail);
 
-    StringFireDetail stringDetail(out.toCString().data());
-
-    m_codeBlock->jettison(Profiler::JettisonDueToUnprofiledWatchpoint, CountReoptimization, &stringDetail);
+    m_codeBlock->jettison(Profiler::JettisonDueToUnprofiledWatchpoint, CountReoptimization, &lazyDetail);
 }
 
 } } // namespace JSC::DFG
index 0854c56..d882071 100644 (file)
@@ -61,14 +61,11 @@ void AdaptiveStructureWatchpoint::fireInternal(const FireDetail& detail)
         dataLog(
             "Firing watchpoint ", RawPointer(this), " (", m_key, ") on ", *m_codeBlock, "\n");
     }
-    
-    StringPrintStream out;
-    out.print("Adaptation of ", m_key, " failed: ", detail);
-    
-    StringFireDetail stringDetail(out.toCString().data());
-    
+
+    auto lazyDetail = createLazyFireDetail("Adaptation of ", m_key, " failed: ", detail);
+
     m_codeBlock->jettison(
-        Profiler::JettisonDueToUnprofiledWatchpoint, CountReoptimization, &stringDetail);
+        Profiler::JettisonDueToUnprofiledWatchpoint, CountReoptimization, &lazyDetail);
 }
 
 } } // namespace JSC::DFG
index d85f710..241f240 100644 (file)
@@ -1514,16 +1514,13 @@ ArrayPrototypeAdaptiveInferredPropertyWatchpoint::ArrayPrototypeAdaptiveInferred
 
 void ArrayPrototypeAdaptiveInferredPropertyWatchpoint::handleFire(const FireDetail& detail)
 {
-    StringPrintStream out;
-    out.print("ArrayPrototype adaption of ", key(), " failed: ", detail);
-
-    StringFireDetail stringDetail(out.toCString().data());
+    auto lazyDetail = createLazyFireDetail("ArrayPrototype adaption of ", key(), " failed: ", detail);
 
     if (ArrayPrototypeInternal::verbose)
-        WTF::dataLog(stringDetail, "\n");
+        WTF::dataLog(lazyDetail, "\n");
 
     JSGlobalObject* globalObject = m_arrayPrototype->globalObject();
-    globalObject->arraySpeciesWatchpoint().fireAll(globalObject->vm(), stringDetail);
+    globalObject->arraySpeciesWatchpoint().fireAll(globalObject->vm(), lazyDetail);
 }
 
 } // namespace JSC