Changeset 126196 in webkit


Ignore:
Timestamp:
Aug 21, 2012 3:32:32 PM (12 years ago)
Author:
commit-queue@webkit.org
Message:

Call AdjustAmountOfExternalAllocatedMemory when V8ArrayBuffer constructed and destructed
https://bugs.webkit.org/show_bug.cgi?id=92993

Patch by Ulan Degenbaev <ulan@chromium.org> on 2012-08-21
Reviewed by Kenneth Russell.

Call AdjustAmountOfExternalAllocatedMemory when V8ArrayBuffer
is constructed and destructed so that V8's garbage collection
heuristics can account for the memory held by these objects.

.:

  • ManualTests/typed-array-memory.html: Added.

Source/WebCore:

  • WebCore.gypi:
  • bindings/v8/SerializedScriptValue.cpp:
  • bindings/v8/custom/V8ArrayBufferCustom.cpp:

(WebCore::V8ArrayBufferDeallocationObserver::instance):
(WebCore):
(WebCore::V8ArrayBuffer::constructorCallback):

  • bindings/v8/custom/V8ArrayBufferCustom.h: Added.

(WebCore):

  • bindings/v8/custom/V8ArrayBufferViewCustom.cpp:
  • bindings/v8/custom/V8ArrayBufferViewCustom.h:

(WebCore::constructWebGLArray):

  • dom/MessageEvent.cpp:

(WebCore::MessageEvent::MessageEvent):
(WebCore::MessageEvent::initMessageEvent):

Source/WTF:

  • wtf/ArrayBuffer.h:

(WTF):
(ArrayBufferDeallocationObserver):
(WTF::ArrayBufferContents::ArrayBufferContents):
(WTF::ArrayBufferContents::transfer):
(ArrayBufferContents):
(ArrayBuffer):
(WTF::ArrayBuffer::setDeallocationObserver):
(WTF::ArrayBufferContents::~ArrayBufferContents):

Location:
trunk
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/ChangeLog

    r126182 r126196  
     12012-08-21  Ulan Degenbaev  <ulan@chromium.org>
     2
     3        Call AdjustAmountOfExternalAllocatedMemory when V8ArrayBuffer constructed and destructed
     4        https://bugs.webkit.org/show_bug.cgi?id=92993
     5
     6        Reviewed by Kenneth Russell.
     7
     8        Call AdjustAmountOfExternalAllocatedMemory when V8ArrayBuffer
     9        is constructed and destructed so that V8's garbage collection
     10        heuristics can account for the memory held by these objects.
     11
     12        * ManualTests/typed-array-memory.html: Added.
     13
    1142012-08-21  Martin Robinson  <mrobinson@igalia.com>
    215
  • trunk/Source/WTF/ChangeLog

    r126191 r126196  
     12012-08-21  Ulan Degenbaev  <ulan@chromium.org>
     2
     3        Call AdjustAmountOfExternalAllocatedMemory when V8ArrayBuffer constructed and destructed
     4        https://bugs.webkit.org/show_bug.cgi?id=92993
     5
     6        Reviewed by Kenneth Russell.
     7
     8        Call AdjustAmountOfExternalAllocatedMemory when V8ArrayBuffer
     9        is constructed and destructed so that V8's garbage collection
     10        heuristics can account for the memory held by these objects.
     11
     12        * wtf/ArrayBuffer.h:
     13        (WTF):
     14        (ArrayBufferDeallocationObserver):
     15        (WTF::ArrayBufferContents::ArrayBufferContents):
     16        (WTF::ArrayBufferContents::transfer):
     17        (ArrayBufferContents):
     18        (ArrayBuffer):
     19        (WTF::ArrayBuffer::setDeallocationObserver):
     20        (WTF::ArrayBufferContents::~ArrayBufferContents):
     21
    1222012-08-21  Benjamin Poulain  <bpoulain@apple.com>
    223
  • trunk/Source/WTF/wtf/ArrayBuffer.h

    r114992 r126196  
    3737class ArrayBufferView;
    3838
     39#if defined(WTF_USE_V8)
     40// The current implementation assumes that the instance of this class is a
     41// singleton living for the entire process's lifetime.
     42class ArrayBufferDeallocationObserver {
     43public:
     44    virtual void ArrayBufferDeallocated(unsigned sizeInBytes) = 0;
     45};
     46#endif
     47
     48
    3949class ArrayBufferContents {
    4050    WTF_MAKE_NONCOPYABLE(ArrayBufferContents);
     
    4353        : m_data(0)
    4454        , m_sizeInBytes(0)
     55#if defined(WTF_USE_V8)
     56        , m_deallocationObserver(0)
     57#endif
    4558    { }
    4659
     
    5467        : m_data(data)
    5568        , m_sizeInBytes(sizeInBytes)
     69#if defined(WTF_USE_V8)
     70        , m_deallocationObserver(0)
     71#endif
    5672    { }
    5773
     
    7187        m_data = 0;
    7288        m_sizeInBytes = 0;
     89#if defined(WTF_USE_V8)
     90        // Notify the current V8 isolate that the buffer is gone.
     91        if (m_deallocationObserver)
     92            m_deallocationObserver->ArrayBufferDeallocated(other.m_sizeInBytes);
     93        ASSERT(!other.m_deallocationObserver);
     94        m_deallocationObserver = 0;
     95#endif
    7396    }
    7497
    7598    void* m_data;
    7699    unsigned m_sizeInBytes;
     100
     101#if defined(WTF_USE_V8)
     102    ArrayBufferDeallocationObserver* m_deallocationObserver;
     103#endif
    77104};
    78105
     
    99126    WTF_EXPORT_PRIVATE bool transfer(ArrayBufferContents&, Vector<RefPtr<ArrayBufferView> >& neuteredViews);
    100127    bool isNeutered() { return !m_contents.m_data; }
     128
     129#if defined(WTF_USE_V8)
     130    void setDeallocationObserver(ArrayBufferDeallocationObserver* deallocationObserver)
     131    {
     132        m_contents.m_deallocationObserver = deallocationObserver;
     133    }
     134#endif
    101135
    102136    ~ArrayBuffer() { }
     
    239273ArrayBufferContents::~ArrayBufferContents()
    240274{
     275#if defined (WTF_USE_V8)
     276    if (m_deallocationObserver)
     277        m_deallocationObserver->ArrayBufferDeallocated(m_sizeInBytes);
     278#endif
    241279    WTF::fastFree(m_data);
    242280}
  • trunk/Source/WebCore/ChangeLog

    r126195 r126196  
     12012-08-21  Ulan Degenbaev  <ulan@chromium.org>
     2
     3        Call AdjustAmountOfExternalAllocatedMemory when V8ArrayBuffer constructed and destructed
     4        https://bugs.webkit.org/show_bug.cgi?id=92993
     5
     6        Reviewed by Kenneth Russell.
     7
     8        Call AdjustAmountOfExternalAllocatedMemory when V8ArrayBuffer
     9        is constructed and destructed so that V8's garbage collection
     10        heuristics can account for the memory held by these objects.
     11
     12        * WebCore.gypi:
     13        * bindings/v8/SerializedScriptValue.cpp:
     14        * bindings/v8/custom/V8ArrayBufferCustom.cpp:
     15        (WebCore::V8ArrayBufferDeallocationObserver::instance):
     16        (WebCore):
     17        (WebCore::V8ArrayBuffer::constructorCallback):
     18        * bindings/v8/custom/V8ArrayBufferCustom.h: Added.
     19        (WebCore):
     20        * bindings/v8/custom/V8ArrayBufferViewCustom.cpp:
     21        * bindings/v8/custom/V8ArrayBufferViewCustom.h:
     22        (WebCore::constructWebGLArray):
     23        * dom/MessageEvent.cpp:
     24        (WebCore::MessageEvent::MessageEvent):
     25        (WebCore::MessageEvent::initMessageEvent):
     26
    1272012-08-21  Taiju Tsuiki  <tzik@chromium.org>
    228
  • trunk/Source/WebCore/WebCore.gypi

    r126193 r126196  
    23112311            'bindings/v8/WrapperTypeInfo.h',
    23122312            'bindings/v8/custom/V8ArrayBufferCustom.cpp',
     2313            'bindings/v8/custom/V8ArrayBufferCustom.h',
    23132314            'bindings/v8/custom/V8ArrayBufferViewCustom.cpp',
    23142315            'bindings/v8/custom/V8ArrayBufferViewCustom.h',
  • trunk/Source/WebCore/bindings/v8/custom/V8ArrayBufferCustom.cpp

    r125495 r126196  
    3030
    3131#include "config.h"
     32#include "V8ArrayBufferCustom.h"
     33
    3234#include <wtf/ArrayBuffer.h>
     35#include <wtf/StdLibExtras.h>
    3336
    3437#include "ExceptionCode.h"
     38#include "V8ArrayBuffer.h"
    3539#include "V8Binding.h"
    36 #include "V8ArrayBuffer.h"
    3740#include "V8Proxy.h"
    3841
    3942namespace WebCore {
     43
     44V8ArrayBufferDeallocationObserver* V8ArrayBufferDeallocationObserver::instance()
     45{
     46    DEFINE_STATIC_LOCAL(V8ArrayBufferDeallocationObserver, deallocationObserver, ());
     47    return &deallocationObserver;
     48}
     49
    4050
    4151v8::Handle<v8::Value> V8ArrayBuffer::constructorCallback(const v8::Arguments& args)
     
    7282    if (!buffer.get())
    7383        return throwError(RangeError, "ArrayBuffer size is not a small enough positive integer.", args.GetIsolate());
     84    buffer->setDeallocationObserver(V8ArrayBufferDeallocationObserver::instance());
     85    v8::V8::AdjustAmountOfExternalAllocatedMemory(buffer->byteLength());
    7486    // Transform the holder into a wrapper object for the array.
    7587    v8::Handle<v8::Object> wrapper = args.Holder();
  • trunk/Source/WebCore/bindings/v8/custom/V8ArrayBufferViewCustom.cpp

    r119070 r126196  
    1 
    21/*
    32 * Copyright (C) 2011 Google Inc. All rights reserved.
  • trunk/Source/WebCore/bindings/v8/custom/V8ArrayBufferViewCustom.h

    r125947 r126196  
    3636
    3737#include "V8ArrayBuffer.h"
     38#include "V8ArrayBufferCustom.h"
    3839#include "V8Binding.h"
    3940#include "V8Proxy.h"
     
    148149            return throwError(RangeError, tooLargeSize, args.GetIsolate());
    149150
     151        array->buffer()->setDeallocationObserver(V8ArrayBufferDeallocationObserver::instance());
     152        v8::V8::AdjustAmountOfExternalAllocatedMemory(array->byteLength());
     153
    150154        memcpy(array->baseAddress(), source->baseAddress(), length * sizeof(ElementType));
    151155
     
    182186    if (!array.get())
    183187        return throwError(RangeError, tooLargeSize, args.GetIsolate());
     188
     189    if (doInstantiation) {
     190        array->buffer()->setDeallocationObserver(V8ArrayBufferDeallocationObserver::instance());
     191        v8::V8::AdjustAmountOfExternalAllocatedMemory(array->byteLength());
     192    }
    184193
    185194
Note: See TracChangeset for help on using the changeset viewer.