[V8] Increment the amount of externally allocated memory for the receiving V8 isolate...
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 16 Nov 2012 13:19:56 +0000 (13:19 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 16 Nov 2012 13:19:56 +0000 (13:19 +0000)
https://bugs.webkit.org/show_bug.cgi?id=94463

Patch by Ulan Degenbaev <ulan@chromium.org> on 2012-11-16
Reviewed by Kentaro Hara.

Call AdjustAmountOfExternalAllocatedMemory when V8ArrayBuffer is deserialized and transferred.

.:

* ManualTests/typed-array-memory.html:

Source/WebCore:

Test: ManualTests/typed-array-memory.html

* bindings/v8/SerializedScriptValue.cpp:

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

ChangeLog
ManualTests/typed-array-memory.html
Source/WebCore/ChangeLog
Source/WebCore/bindings/v8/SerializedScriptValue.cpp

index e051524..d2c28fe 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2012-11-16  Ulan Degenbaev  <ulan@chromium.org>
+
+        [V8] Increment the amount of externally allocated memory for the receiving V8 isolate when transferring ArrayBuffer
+        https://bugs.webkit.org/show_bug.cgi?id=94463
+
+        Reviewed by Kentaro Hara.
+
+        Call AdjustAmountOfExternalAllocatedMemory when V8ArrayBuffer is deserialized and transferred.
+
+        * ManualTests/typed-array-memory.html:
+
 2012-11-16  Sheriff Bot  <webkit.review.bot@gmail.com>
 
         Unreviewed, rolling out r134908.
index 1d62429..bc8d89e 100644 (file)
@@ -136,16 +136,18 @@ function transfersThatDecreaseExternalMemory() {
 "function externalMemory() {\n" +
 "    return getV8Statistics().amount_of_external_allocated_memory;\n" +
 "}\n" +
-"function collectGarbage() {\n" +
-"    for (var i = 0; i < 10; i++) gc();\n" +
-"}\n" +
-"var before = externalMemory();\n" +
+"var KB = 1024;\n" +
+"var MB = KB * KB;\n" +
+"var noise = KB;\n" +
 "self.onmessage = function(e) {\n" +
-"    var now = externalMemory();\n" +
-"    e.data = null;\n" +
-"    collectGarbage();\n" +
+"    var before = externalMemory();\n" +
+"    e.data;\n" +
 "    var after = externalMemory();\n" +
-"    self.postMessage(before + ' ' + now + ' ' + after);\n" +
+"    if (after > before + MB - noise) {\n" +
+"      self.postMessage('PASS: Amount of external memory increased.');\n" +
+"    } else {\n" +
+"      self.postMessage('FAIL: Amount of external memory did not increase.');\n" +
+"    }\n" +
 "}\n";
 
     var blob = new Blob([workerSource]);
@@ -158,7 +160,7 @@ function transfersThatDecreaseExternalMemory() {
         var buffer = eval(expression);
         try {
             var before = externalMemory();
-            worker.webkitPostMessage(buffer, [buffer]);
+            worker.postMessage(buffer, [buffer]);
             var now = externalMemory();
             if (now > before - MB + noise) {
                 fail("Transfer of " + expression + " did not decrease the amount of external memory (" +
index 74d2170..8672e5b 100644 (file)
@@ -1,3 +1,16 @@
+2012-11-16  Ulan Degenbaev  <ulan@chromium.org>
+
+        [V8] Increment the amount of externally allocated memory for the receiving V8 isolate when transferring ArrayBuffer
+        https://bugs.webkit.org/show_bug.cgi?id=94463
+
+        Reviewed by Kentaro Hara.
+
+        Call AdjustAmountOfExternalAllocatedMemory when V8ArrayBuffer is deserialized and transferred.
+
+        Test: ManualTests/typed-array-memory.html
+
+        * bindings/v8/SerializedScriptValue.cpp:
+
 2012-11-16  Sheriff Bot  <webkit.review.bot@gmail.com>
 
         Unreviewed, rolling out r134694.
index 4c310d8..b619105 100644 (file)
@@ -41,6 +41,7 @@
 #include "MessagePort.h"
 #include "SharedBuffer.h"
 #include "V8ArrayBuffer.h"
+#include "V8ArrayBufferCustom.h"
 #include "V8ArrayBufferView.h"
 #include "V8Binding.h"
 #include "V8Blob.h"
@@ -1647,6 +1648,8 @@ private:
             return 0;
         const void* bufferStart = m_buffer + m_position;
         RefPtr<ArrayBuffer> arrayBuffer = ArrayBuffer::create(bufferStart, byteLength);
+        arrayBuffer->setDeallocationObserver(V8ArrayBufferDeallocationObserver::instance());
+        v8::V8::AdjustAmountOfExternalAllocatedMemory(arrayBuffer->byteLength());
         m_position += byteLength;
         return arrayBuffer.release();
     }
@@ -2034,7 +2037,10 @@ public:
             return false;
         v8::Handle<v8::Object> result = m_arrayBuffers.at(index);
         if (result.IsEmpty()) {
-            result = toV8Object(ArrayBuffer::create(m_arrayBufferContents->at(index)).get(), v8::Handle<v8::Object>(), m_reader.getIsolate());
+            RefPtr<ArrayBuffer> buffer = ArrayBuffer::create(m_arrayBufferContents->at(index));
+            buffer->setDeallocationObserver(V8ArrayBufferDeallocationObserver::instance());
+            v8::V8::AdjustAmountOfExternalAllocatedMemory(buffer->byteLength());
+            result = toV8Object(buffer.get(), v8::Handle<v8::Object>(), m_reader.getIsolate());
             m_arrayBuffers[index] = result;
         }
         *object = result;