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..0566c5d7c7d1f435bedafea958b8a23731cc5658 100644 |
| --- a/third_party/WebKit/Source/bindings/core/v8/SerializedScriptValue.cpp |
| +++ b/third_party/WebKit/Source/bindings/core/v8/SerializedScriptValue.cpp |
| @@ -128,7 +128,7 @@ SerializedScriptValue::~SerializedScriptValue() { |
| if (m_externallyAllocatedMemory) { |
| ASSERT(v8::Isolate::GetCurrent()); |
| v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory( |
| - -m_externallyAllocatedMemory); |
| + -m_externallyAllocatedMemory + 1); |
| } |
| } |
| @@ -444,13 +444,45 @@ SerializedScriptValue::transferArrayBufferContents( |
| return contents; |
| } |
| +void SerializedScriptValue::unregisterMemoryAllocatedByCurrentScriptContext() { |
| + if (m_externallyAllocatedMemory == 1) |
|
jbroman
2017/03/07 18:00:04
Use of this magic value is confusing. I'd suggest
sof
2017/03/07 19:14:03
It's not particularly clever; I can switch to an i
jbroman
2017/03/07 19:29:05
(u)int64_t + boolean in a bitfield would do the tr
sof
2017/03/07 19:30:20
Done.
|
| + return; |
| + if (m_externallyAllocatedMemory) { |
| + v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory( |
| + -(m_externallyAllocatedMemory - 1)); |
| + 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) { |
| + int64_t bufferSize = |
| + static_cast<int64_t>(m_arrayBufferContentsArray->at(i).sizeInBytes()); |
| + v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory( |
| + -bufferSize); |
| + } |
| + // Mark the value as needing re-registration by its target context. |
| + m_externallyAllocatedMemory = static_cast<intptr_t>(1); |
| + } |
| +} |
| + |
| void SerializedScriptValue::registerMemoryAllocatedWithCurrentScriptContext() { |
| - if (m_externallyAllocatedMemory) |
| + if (m_externallyAllocatedMemory != 1) |
| return; |
| - m_externallyAllocatedMemory = static_cast<intptr_t>(dataLengthInBytes()); |
| + bool registerTransferables = |
| + m_externallyAllocatedMemory == static_cast<intptr_t>(1); |
| + size_t size = dataLengthInBytes(); |
| v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory( |
| - m_externallyAllocatedMemory); |
| + static_cast<intptr_t>(size)); |
| + m_externallyAllocatedMemory = static_cast<int64_t>(size ? (size + 1) : 0); |
| + if (registerTransferables) { |
| + DCHECK(m_arrayBufferContentsArray); |
| + for (size_t i = 0; i < m_arrayBufferContentsArray->size(); ++i) { |
| + v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory( |
| + m_arrayBufferContentsArray->at(i).sizeInBytes()); |
| + } |
| + } |
| } |
| } // namespace blink |