Title: [236999] trunk/Source/WebCore
Revision
236999
Author
[email protected]
Date
2018-10-10 01:48:57 -0700 (Wed, 10 Oct 2018)

Log Message

XMLHttpRequest should use reportExtraMemoryAllocated/reportExtraMemoryVisited instead of deprecatedReportExtraMemory
https://bugs.webkit.org/show_bug.cgi?id=190279

Reviewed by Ryosuke Niwa.

This patch switches deprecatedReportExtraMemory to reportExtraMemoryAllocated/reportExtraMemoryVisited
in XMLHttpRequest. We report extra memory allocation when the readyState becomes DONE. And memoryCost
function returns the memory cost which is based on the readyState and m_responseBuilder.
We annotate XMLHttpRequest with ReportExtraMemoryCost to use reportExtraMemoryVisited automatically with
memoryCost() function.

* xml/XMLHttpRequest.cpp:
(WebCore::XMLHttpRequest::changeState):
(WebCore::XMLHttpRequest::abort):
(WebCore::XMLHttpRequest::internalAbort):
(WebCore::XMLHttpRequest::networkErrorTimerFired):
(WebCore::XMLHttpRequest::memoryCost const):
(WebCore::XMLHttpRequest::didFinishLoading):
(WebCore::XMLHttpRequest::didReachTimeout):
(WebCore::XMLHttpRequest::dropProtection): Deleted.
* xml/XMLHttpRequest.h:
* xml/XMLHttpRequest.idl:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (236998 => 236999)


--- trunk/Source/WebCore/ChangeLog	2018-10-10 06:55:24 UTC (rev 236998)
+++ trunk/Source/WebCore/ChangeLog	2018-10-10 08:48:57 UTC (rev 236999)
@@ -1,3 +1,28 @@
+2018-10-10  Yusuke Suzuki  <[email protected]>
+
+        XMLHttpRequest should use reportExtraMemoryAllocated/reportExtraMemoryVisited instead of deprecatedReportExtraMemory
+        https://bugs.webkit.org/show_bug.cgi?id=190279
+
+        Reviewed by Ryosuke Niwa.
+
+        This patch switches deprecatedReportExtraMemory to reportExtraMemoryAllocated/reportExtraMemoryVisited
+        in XMLHttpRequest. We report extra memory allocation when the readyState becomes DONE. And memoryCost
+        function returns the memory cost which is based on the readyState and m_responseBuilder.
+        We annotate XMLHttpRequest with ReportExtraMemoryCost to use reportExtraMemoryVisited automatically with
+        memoryCost() function.
+
+        * xml/XMLHttpRequest.cpp:
+        (WebCore::XMLHttpRequest::changeState):
+        (WebCore::XMLHttpRequest::abort):
+        (WebCore::XMLHttpRequest::internalAbort):
+        (WebCore::XMLHttpRequest::networkErrorTimerFired):
+        (WebCore::XMLHttpRequest::memoryCost const):
+        (WebCore::XMLHttpRequest::didFinishLoading):
+        (WebCore::XMLHttpRequest::didReachTimeout):
+        (WebCore::XMLHttpRequest::dropProtection): Deleted.
+        * xml/XMLHttpRequest.h:
+        * xml/XMLHttpRequest.idl:
+
 2018-10-09  Antoine Quint  <[email protected]>
 
         Remove the frames() timing function

Modified: trunk/Source/WebCore/xml/XMLHttpRequest.cpp (236998 => 236999)


--- trunk/Source/WebCore/xml/XMLHttpRequest.cpp	2018-10-10 06:55:24 UTC (rev 236998)
+++ trunk/Source/WebCore/xml/XMLHttpRequest.cpp	2018-10-10 08:48:57 UTC (rev 236999)
@@ -295,6 +295,19 @@
 {
     if (readyState() != newState) {
         m_readyState = static_cast<State>(newState);
+        if (readyState() == DONE) {
+            // The XHR object itself holds on to the responseText, and
+            // thus has extra cost even independent of any
+            // responseText or responseXML objects it has handed
+            // out. But it is protected from GC while loading, so this
+            // can't be recouped until the load is done, so only
+            // report the extra cost at that point.
+            if (auto* context = scriptExecutionContext()) {
+                JSC::VM& vm = context->vm();
+                JSC::JSLockHolder lock(vm);
+                vm.heap.reportExtraMemoryAllocated(memoryCost());
+            }
+        }
         callReadyStateChangeListener();
     }
 }
@@ -656,7 +669,7 @@
 
 void XMLHttpRequest::abort()
 {
-    // internalAbort() calls dropProtection(), which may release the last reference.
+    // internalAbort() calls unsetPendingActivity(this), which may release the last reference.
     Ref<XMLHttpRequest> protectedThis(*this);
 
     m_wasAbortedByClient = true;
@@ -702,7 +715,7 @@
     // Save this information to a local variable since we are going to drop protection.
     bool newLoadStarted = m_loader;
 
-    dropProtection();
+    unsetPendingActivity(this);
 
     return !newLoadStarted;
 }
@@ -749,7 +762,7 @@
 void XMLHttpRequest::networkErrorTimerFired()
 {
     networkError();
-    dropProtection();
+    unsetPendingActivity(this);
 }
     
 void XMLHttpRequest::abortError()
@@ -759,21 +772,11 @@
     dispatchErrorEvents(eventNames().abortEvent);
 }
 
-void XMLHttpRequest::dropProtection()
+size_t XMLHttpRequest::memoryCost() const
 {
-    // The XHR object itself holds on to the responseText, and
-    // thus has extra cost even independent of any
-    // responseText or responseXML objects it has handed
-    // out. But it is protected from GC while loading, so this
-    // can't be recouped until the load is done, so only
-    // report the extra cost at that point.
-    JSC::VM& vm = scriptExecutionContext()->vm();
-    JSC::JSLockHolder lock(vm);
-    // FIXME: Adopt reportExtraMemoryVisited, and switch to reportExtraMemoryAllocated.
-    // https://bugs.webkit.org/show_bug.cgi?id=142595
-    vm.heap.deprecatedReportExtraMemory(m_responseBuilder.length() * 2);
-
-    unsetPendingActivity(this);
+    if (readyState() == DONE)
+        return m_responseBuilder.length() * 2;
+    return 0;
 }
 
 ExceptionOr<void> XMLHttpRequest::overrideMimeType(const String& mimeType)
@@ -943,7 +946,7 @@
     m_timeoutTimer.stop();
 
     if (hadLoader)
-        dropProtection();
+        unsetPendingActivity(this);
 }
 
 void XMLHttpRequest::didSendData(unsigned long long bytesSent, unsigned long long totalBytesToBeSent)
@@ -1083,7 +1086,7 @@
 
 void XMLHttpRequest::didReachTimeout()
 {
-    // internalAbort() calls dropProtection(), which may release the last reference.
+    // internalAbort() calls unsetPendingActivity(this), which may release the last reference.
     Ref<XMLHttpRequest> protectedThis(*this);
     if (!internalAbort())
         return;

Modified: trunk/Source/WebCore/xml/XMLHttpRequest.h (236998 => 236999)


--- trunk/Source/WebCore/xml/XMLHttpRequest.h	2018-10-10 06:55:24 UTC (rev 236998)
+++ trunk/Source/WebCore/xml/XMLHttpRequest.h	2018-10-10 08:48:57 UTC (rev 236999)
@@ -125,6 +125,8 @@
     using RefCounted<XMLHttpRequest>::ref;
     using RefCounted<XMLHttpRequest>::deref;
 
+    size_t memoryCost() const;
+
 private:
     explicit XMLHttpRequest(ScriptExecutionContext&);
 
@@ -166,7 +168,6 @@
 
     void changeState(State);
     void callReadyStateChangeListener();
-    void dropProtection();
 
     // Returns false when cancelling the loader within internalAbort() triggers an event whose callback creates a new loader. 
     // In that case, the function calling internalAbort should exit.

Modified: trunk/Source/WebCore/xml/XMLHttpRequest.idl (236998 => 236999)


--- trunk/Source/WebCore/xml/XMLHttpRequest.idl	2018-10-10 06:55:24 UTC (rev 236998)
+++ trunk/Source/WebCore/xml/XMLHttpRequest.idl	2018-10-10 08:48:57 UTC (rev 236999)
@@ -47,6 +47,7 @@
     JSCustomMarkFunction,
     JSGenerateToJSObject,
     JSGenerateToNativeObject,
+    ReportExtraMemoryCost,
 ] interface XMLHttpRequest : XMLHttpRequestEventTarget {
     // event handler
     attribute EventHandler onreadystatechange;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to