Chromium Code Reviews| Index: include/v8.h |
| diff --git a/include/v8.h b/include/v8.h |
| index b1da55e2c5ee0d2cf566c976b95dde2e0396a27b..0c049bda6cae648ef389b49961aa87f398a0b0de 100644 |
| --- a/include/v8.h |
| +++ b/include/v8.h |
| @@ -4215,7 +4215,8 @@ class V8_EXPORT Isolate { |
| * kept alive by JavaScript objects. |
| * \returns the adjusted value. |
| */ |
| - int64_t AdjustAmountOfExternalAllocatedMemory(int64_t change_in_bytes); |
| + V8_INLINE int64_t |
| + AdjustAmountOfExternalAllocatedMemory(int64_t change_in_bytes); |
| /** |
| * Returns heap profiler for this isolate. Will return NULL until the isolate |
| @@ -4418,6 +4419,7 @@ class V8_EXPORT Isolate { |
| void SetObjectGroupId(internal::Object** object, UniqueId id); |
| void SetReferenceFromGroup(UniqueId id, internal::Object** object); |
| void SetReference(internal::Object** parent, internal::Object** child); |
| + int64_t SlowAdjustAmountOfExternalAllocatedMemory(int64_t change_in_bytes); |
| }; |
| class V8_EXPORT StartupData { |
| @@ -5464,6 +5466,7 @@ namespace internal { |
| const int kApiPointerSize = sizeof(void*); // NOLINT |
| const int kApiIntSize = sizeof(int); // NOLINT |
| +const int kApiInt64Size = sizeof(int64_t); // NOLINT |
| // Tag information for HeapObject. |
| const int kHeapObjectTag = 1; |
| @@ -5562,7 +5565,11 @@ class Internals { |
| static const int kExternalAsciiRepresentationTag = 0x06; |
| static const int kIsolateEmbedderDataOffset = 0 * kApiPointerSize; |
| - static const int kIsolateRootsOffset = 5 * kApiPointerSize; |
| + static const int kAmountOfExternalAllocatedMemoryOffset = 5 * kApiPointerSize; |
| + static const int kAmountOfExternalAllocatedMemoryAtLastGlobalGCOffset = |
| + 5 * kApiPointerSize + kApiInt64Size; |
| + static const int kIsolateRootsOffset = |
| + 5 * kApiPointerSize + 2 * kApiInt64Size; |
| static const int kUndefinedValueRootIndex = 5; |
| static const int kNullValueRootIndex = 7; |
| static const int kTrueValueRootIndex = 8; |
| @@ -6588,6 +6595,49 @@ uint32_t Isolate::GetNumberOfDataSlots() { |
| } |
| +int64_t Isolate::AdjustAmountOfExternalAllocatedMemory( |
| + int64_t change_in_bytes) { |
| +#ifndef V8_ENABLE_CHECKS |
| + typedef internal::Internals I; |
| + int64_t* amount_of_external_allocated_memory = |
| + reinterpret_cast<int64_t*>(reinterpret_cast<uint8_t*>(this) + |
| + I::kAmountOfExternalAllocatedMemoryOffset); |
| + int64_t* amount_of_external_allocated_memory_at_last_global_gc = |
| + reinterpret_cast<int64_t*>( |
| + reinterpret_cast<uint8_t*>(this) + |
| + I::kAmountOfExternalAllocatedMemoryAtLastGlobalGCOffset); |
| + int64_t amount = *amount_of_external_allocated_memory + change_in_bytes; |
| + if (change_in_bytes > 0) { |
| + // Avoid overflow. |
| + if (amount > *amount_of_external_allocated_memory) { |
| + if (amount - *amount_of_external_allocated_memory_at_last_global_gc > |
| + 192 * 1024 * 1024) { |
|
Hannes Payer (out of office)
2014/06/04 11:24:49
192? Please don't use a hard-coded value here.
jochen (gone - plz use gerrit)
2014/06/04 11:41:24
Done.
|
| + // Will likely trigger a GC. |
| + return SlowAdjustAmountOfExternalAllocatedMemory(change_in_bytes); |
| + } |
| + *amount_of_external_allocated_memory = amount; |
| + } else { |
| + // Give up and reset the counters in case of an overflow. |
| + *amount_of_external_allocated_memory = 0; |
| + *amount_of_external_allocated_memory_at_last_global_gc = 0; |
| + } |
| + } else { |
| + // Avoid underflow. |
| + if (amount >= 0) { |
| + *amount_of_external_allocated_memory = amount; |
| + } else { |
| + // Give up and reset the counters in case of an underflow. |
| + *amount_of_external_allocated_memory = 0; |
| + *amount_of_external_allocated_memory_at_last_global_gc = 0; |
| + } |
| + } |
| + return *amount_of_external_allocated_memory; |
| +#else |
| + return SlowAdjustAmountOfExternalAllocatedMemory(change_in_bytes); |
| +#endif |
| +} |
| + |
| + |
| template<typename T> |
| void Isolate::SetObjectGroupId(const Persistent<T>& object, |
| UniqueId id) { |