Chromium Code Reviews| Index: third_party/WebKit/Source/bindings/core/v8/SerializedScriptValue.cpp |
| diff --git a/third_party/WebKit/Source/bindings/core/v8/SerializedScriptValue.cpp b/third_party/WebKit/Source/bindings/core/v8/SerializedScriptValue.cpp |
| index a75fca0dd2f36a3bb7e437581a0bf871b6ab9e4d..3d3c1e7ab5ed49bfce9641cb1f7e3bf7e62130b1 100644 |
| --- a/third_party/WebKit/Source/bindings/core/v8/SerializedScriptValue.cpp |
| +++ b/third_party/WebKit/Source/bindings/core/v8/SerializedScriptValue.cpp |
| @@ -109,10 +109,12 @@ PassRefPtr<SerializedScriptValue> SerializedScriptValue::create( |
| } |
| SerializedScriptValue::SerializedScriptValue() |
| - : m_externallyAllocatedMemory(0) {} |
| + : m_externallyAllocatedMemory(0), |
| + m_adjustTransferableExternalAllocationOnContextTransfer(false) {} |
| SerializedScriptValue::SerializedScriptValue(const String& wireData) |
| - : m_externallyAllocatedMemory(0) { |
| + : m_externallyAllocatedMemory(0), |
| + m_adjustTransferableExternalAllocationOnContextTransfer(false) { |
| size_t byteLength = wireData.length() * 2; |
| m_dataBuffer.reset(static_cast<uint8_t*>(WTF::Partitions::bufferMalloc( |
| byteLength, "SerializedScriptValue buffer"))); |
| @@ -128,7 +130,7 @@ SerializedScriptValue::~SerializedScriptValue() { |
| if (m_externallyAllocatedMemory) { |
| ASSERT(v8::Isolate::GetCurrent()); |
| v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory( |
| - -m_externallyAllocatedMemory); |
| + -static_cast<int64_t>(m_externallyAllocatedMemory)); |
| } |
| } |
| @@ -444,13 +446,46 @@ SerializedScriptValue::transferArrayBufferContents( |
| return contents; |
| } |
| +void SerializedScriptValue::unregisterMemoryAllocatedByCurrentScriptContext() { |
| + if (m_adjustTransferableExternalAllocationOnContextTransfer) |
| + return; |
| + if (m_externallyAllocatedMemory) { |
| + v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory( |
| + -static_cast<int64_t>(m_externallyAllocatedMemory)); |
| + m_externallyAllocatedMemory = 0; |
| + } |
| + // TODO: if other transferables start accounting for their external |
| + // allocations with V8, extend this with corresponding cases. |
| + if (m_arrayBufferContentsArray) { |
| + for (size_t i = 0; i < m_arrayBufferContentsArray->size(); ++i) { |
|
jbroman
2017/03/08 22:43:16
super-nit: here and below, a range-based loop woul
sof
2017/03/09 06:24:33
Switched idiom.
|
| + WTF::ArrayBufferContents& buffer = m_arrayBufferContentsArray->at(i); |
| + buffer.adjustExternalAllocatedMemoryUponContextTransfer( |
| + WTF::ArrayBufferContents::Leave); |
| + } |
| + // Mark value as needing re-registration of external allocation |
| + // costs in its target context, as handled by |
| + // |registerMemoryAllocatedWithCurrentScriptContext()|. |
| + m_adjustTransferableExternalAllocationOnContextTransfer = true; |
| + } |
| +} |
| + |
| void SerializedScriptValue::registerMemoryAllocatedWithCurrentScriptContext() { |
| if (m_externallyAllocatedMemory) |
| return; |
| - m_externallyAllocatedMemory = static_cast<intptr_t>(dataLengthInBytes()); |
| - v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory( |
| - m_externallyAllocatedMemory); |
| + m_externallyAllocatedMemory = dataLengthInBytes(); |
| + int64_t diff = static_cast<int64_t>(m_externallyAllocatedMemory); |
|
jbroman
2017/03/08 22:43:16
nit: intptr_t, since that's what AdjustAmountOfExt
sof
2017/03/09 06:24:33
int64_t Isolate::AdjustAmountOfExternalAllocatedMe
|
| + DCHECK_GE(diff, 0); |
| + v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(diff); |
| + if (m_adjustTransferableExternalAllocationOnContextTransfer) { |
| + DCHECK(m_arrayBufferContentsArray); |
| + for (size_t i = 0; i < m_arrayBufferContentsArray->size(); ++i) { |
| + WTF::ArrayBufferContents& buffer = m_arrayBufferContentsArray->at(i); |
| + buffer.adjustExternalAllocatedMemoryUponContextTransfer( |
| + WTF::ArrayBufferContents::Enter); |
| + } |
| + m_adjustTransferableExternalAllocationOnContextTransfer = false; |
| + } |
| } |
| } // namespace blink |