Patch by James Robinson <jamesr@chromium.org> on 2011-07-07

Reviewed by Kenneth Russell.

Use v8::AdjustAmountOfExternalAllocatedMemory for ArrayBuffers
https://bugs.webkit.org/show_bug.cgi?id=42912

This calls v8's AdjustAmountOfExternalAllocatedMemory when ArrayBuffers are allocated/deallocated so that V8's
garbage collection heuristics can account for the memory held by these objects.  On the new test page, this
reduces the peak memory use from 5BG+ (or a crash in 32-bit systems) to <300MB.

Test: WebCore/manual-tests/array-buffer-memory.html

* html/canvas/ArrayBuffer.cpp:
(WebCore::ArrayBuffer::~ArrayBuffer):
(WebCore::ArrayBuffer::tryAllocate):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@90592 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 21fa5518
2011-07-07 James Robinson <jamesr@chromium.org>
Reviewed by Kenneth Russell.
Use v8::AdjustAmountOfExternalAllocatedMemory for ArrayBuffers
https://bugs.webkit.org/show_bug.cgi?id=42912
This calls v8's AdjustAmountOfExternalAllocatedMemory when ArrayBuffers are allocated/deallocated so that V8's
garbage collection heuristics can account for the memory held by these objects. On the new test page, this
reduces the peak memory use from 5BG+ (or a crash in 32-bit systems) to <300MB.
Test: WebCore/manual-tests/array-buffer-memory.html
* html/canvas/ArrayBuffer.cpp:
(WebCore::ArrayBuffer::~ArrayBuffer):
(WebCore::ArrayBuffer::tryAllocate):
2011-07-07 Ryosuke Niwa <rniwa@webkit.org>
Move all code related to cachedSelection to HTMLTextFormControlElement
......
......@@ -26,6 +26,10 @@
#include "config.h"
#include "ArrayBuffer.h"
#if USE(V8)
#include "V8Binding.h"
#endif
#include <wtf/RefPtr.h>
namespace WebCore {
......@@ -76,6 +80,9 @@ unsigned ArrayBuffer::byteLength() const
ArrayBuffer::~ArrayBuffer()
{
#if USE(V8)
v8::V8::AdjustAmountOfExternalAllocatedMemory(-m_sizeInBytes);
#endif
WTF::fastFree(m_data);
}
......@@ -91,8 +98,12 @@ void* ArrayBuffer::tryAllocate(unsigned numElements, unsigned elementByteSize)
if (totalSize / numElements != elementByteSize)
return 0;
}
if (WTF::tryFastCalloc(numElements, elementByteSize).getValue(result))
if (WTF::tryFastCalloc(numElements, elementByteSize).getValue(result)) {
#if USE(V8)
v8::V8::AdjustAmountOfExternalAllocatedMemory(numElements * elementByteSize);
#endif
return result;
}
return 0;
}
......
<html>
<head>
<title>ArrayBuffer memory test</title>
</head>
<body>
Test creating many ArrayBuffers. The page should fully load without crashing and without using more than ~300mb of ram.
<script>
function allocateLargeBuffer() {
var arrayBuffer = new ArrayBuffer(64*1024*1024);
}
for (var i=0; i<96; ++i)
allocateLargeBuffer();
</script>
</body>
</html>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment