@@ -7770,6 +7770,7 @@ class V8_EXPORT Isolate {
7770
7770
friend class PersistentValueMapBase;
7771
7771
7772
7772
void ReportExternalAllocationLimitReached();
7773
+ void CheckMemoryPressure();
7773
7774
};
7774
7775
7775
7776
class V8_EXPORT StartupData {
@@ -9019,6 +9020,8 @@ class Internals {
9019
9020
static const int kExternalMemoryOffset = 4 * kApiPointerSize;
9020
9021
static const int kExternalMemoryLimitOffset =
9021
9022
kExternalMemoryOffset + kApiInt64Size;
9023
+ static const int kExternalMemoryAtLastMarkCompactOffset =
9024
+ kExternalMemoryLimitOffset + kApiInt64Size;
9022
9025
static const int kIsolateRootsOffset = kExternalMemoryLimitOffset +
9023
9026
kApiInt64Size + kApiInt64Size +
9024
9027
kApiPointerSize + kApiPointerSize;
@@ -10244,13 +10247,28 @@ uint32_t Isolate::GetNumberOfDataSlots() {
10244
10247
10245
10248
int64_t Isolate::AdjustAmountOfExternalAllocatedMemory(
10246
10249
int64_t change_in_bytes) {
10250
+ const int64_t kMemoryReducerActivationLimit = 1024 * 1024;
10247
10251
typedef internal::Internals I;
10248
10252
int64_t* external_memory = reinterpret_cast<int64_t*>(
10249
10253
reinterpret_cast<uint8_t*>(this) + I::kExternalMemoryOffset);
10250
10254
const int64_t external_memory_limit = *reinterpret_cast<int64_t*>(
10251
10255
reinterpret_cast<uint8_t*>(this) + I::kExternalMemoryLimitOffset);
10256
+ int64_t* external_memory_at_last_mc =
10257
+ reinterpret_cast<int64_t*>(reinterpret_cast<uint8_t*>(this) +
10258
+ I::kExternalMemoryAtLastMarkCompactOffset);
10252
10259
const int64_t amount = *external_memory + change_in_bytes;
10260
+
10253
10261
*external_memory = amount;
10262
+
10263
+ int64_t allocation_diff_since_last_mc =
10264
+ *external_memory_at_last_mc - *external_memory;
10265
+ allocation_diff_since_last_mc = allocation_diff_since_last_mc < 0
10266
+ ? -allocation_diff_since_last_mc
10267
+ : allocation_diff_since_last_mc;
10268
+ if (allocation_diff_since_last_mc > kMemoryReducerActivationLimit) {
10269
+ CheckMemoryPressure();
10270
+ }
10271
+
10254
10272
if (change_in_bytes > 0 && amount > external_memory_limit) {
10255
10273
ReportExternalAllocationLimitReached();
10256
10274
}
0 commit comments