Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(962)

Unified Diff: third_party/WebKit/Source/wtf/typed_arrays/ArrayBufferContents.h

Issue 2741793003: Accurate transfer of SerializedScriptValue allocation costs. (Closed)
Patch Set: sanity check diff adjustments Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/wtf/typed_arrays/ArrayBufferContents.h
diff --git a/third_party/WebKit/Source/wtf/typed_arrays/ArrayBufferContents.h b/third_party/WebKit/Source/wtf/typed_arrays/ArrayBufferContents.h
index 2bd5903ddf6eacff831c5f022c7e37eaa8c5709c..b574c9bd0612416a984c24388f3f75a51c3c51b9 100644
--- a/third_party/WebKit/Source/wtf/typed_arrays/ArrayBufferContents.h
+++ b/third_party/WebKit/Source/wtf/typed_arrays/ArrayBufferContents.h
@@ -102,27 +102,14 @@ class WTF_EXPORT ArrayBufferContents {
s_adjustAmountOfExternalAllocatedMemoryFunction = function;
}
- enum LeaveOrEnter {
- Leave,
- Enter,
- };
+ void registerExternalAllocationWithCurrentContext() {
+ if (m_holder)
+ m_holder->registerExternalAllocationWithCurrentContext();
+ }
- // Externally allocated memory is kept track of per context (isolate),
- // hence when moving ArrayBufferContents to another context, its
- // externally allocated memory needs to be registered with its
- // destination context.
- //
- // Expose |adjustExternalAllocatedMemoryUponContextTransfer| in order to do
- // so, which postMessage() implementations make use of when transferring
- // array buffers.
- void adjustExternalAllocatedMemoryUponContextTransfer(
- LeaveOrEnter direction) {
- int64_t diff = static_cast<int64_t>(sizeInBytes());
- if (!diff)
- return;
- if (direction == Leave)
- diff = -diff;
- m_holder->adjustAmountOfExternalAllocatedMemory(diff);
+ void unregisterExternalAllocationWithCurrentContext() {
+ if (m_holder)
+ m_holder->unregisterExternalAllocationWithCurrentContext();
}
private:
@@ -149,12 +136,17 @@ class WTF_EXPORT ArrayBufferContents {
unsigned sizeInBytes() const { return m_sizeInBytes; }
bool isShared() const { return m_isShared == Shared; }
+ void registerExternalAllocationWithCurrentContext();
+ void unregisterExternalAllocationWithCurrentContext();
+
+ private:
void adjustAmountOfExternalAllocatedMemory(int64_t diff) {
+ m_hasRegisteredExternalAllocation = !m_hasRegisteredExternalAllocation;
+ DCHECK(!diff || (m_hasRegisteredExternalAllocation == (diff > 0)));
checkIfAdjustAmountOfExternalAllocatedMemoryIsConsistent();
s_adjustAmountOfExternalAllocatedMemoryFunction(diff);
}
- private:
void adjustAmountOfExternalAllocatedMemory(unsigned diff) {
adjustAmountOfExternalAllocatedMemory(static_cast<int64_t>(diff));
}
@@ -177,6 +169,7 @@ class WTF_EXPORT ArrayBufferContents {
DataHandle m_data;
unsigned m_sizeInBytes;
SharingType m_isShared;
+ bool m_hasRegisteredExternalAllocation;
};
RefPtr<DataHolder> m_holder;

Powered by Google App Engine
This is Rietveld 408576698