Index: include/v8.h |
diff --git a/include/v8.h b/include/v8.h |
index 30445457c20638b5cd2512e29649ae370ab7f97f..112fe4c9f07a2f829c1fac1d22111f81266d0bc5 100644 |
--- a/include/v8.h |
+++ b/include/v8.h |
@@ -7589,6 +7589,7 @@ class V8_EXPORT Isolate { |
friend class PersistentValueMapBase; |
void ReportExternalAllocationLimitReached(); |
+ void CheckMemoryPressure(); |
}; |
class V8_EXPORT StartupData { |
@@ -8816,6 +8817,8 @@ class Internals { |
static const int kExternalMemoryOffset = 4 * kApiPointerSize; |
static const int kExternalMemoryLimitOffset = |
kExternalMemoryOffset + kApiInt64Size; |
+ static const int kExternalMemoryAtLastMarkCompactOffset = |
+ kExternalMemoryLimitOffset + kApiInt64Size; |
static const int kIsolateRootsOffset = kExternalMemoryLimitOffset + |
kApiInt64Size + kApiInt64Size + |
kApiPointerSize + kApiPointerSize; |
@@ -10033,13 +10036,28 @@ uint32_t Isolate::GetNumberOfDataSlots() { |
int64_t Isolate::AdjustAmountOfExternalAllocatedMemory( |
int64_t change_in_bytes) { |
+ const int64_t kMemoryReducerActivationLimit = 1024 * 1024; |
typedef internal::Internals I; |
int64_t* external_memory = reinterpret_cast<int64_t*>( |
reinterpret_cast<uint8_t*>(this) + I::kExternalMemoryOffset); |
const int64_t external_memory_limit = *reinterpret_cast<int64_t*>( |
reinterpret_cast<uint8_t*>(this) + I::kExternalMemoryLimitOffset); |
+ int64_t* external_memory_at_last_mc = |
+ reinterpret_cast<int64_t*>(reinterpret_cast<uint8_t*>(this) + |
+ I::kExternalMemoryAtLastMarkCompactOffset); |
const int64_t amount = *external_memory + change_in_bytes; |
+ |
*external_memory = amount; |
+ |
+ int64_t allocation_diff_since_last_mc = |
+ *external_memory_at_last_mc - *external_memory; |
+ allocation_diff_since_last_mc = allocation_diff_since_last_mc < 0 |
+ ? -allocation_diff_since_last_mc |
+ : allocation_diff_since_last_mc; |
+ if (allocation_diff_since_last_mc > kMemoryReducerActivationLimit) { |
+ CheckMemoryPressure(); |
+ } |
+ |
if (change_in_bytes > 0 && amount > external_memory_limit) { |
ReportExternalAllocationLimitReached(); |
} |