diff --git a/deps/v8/include/v8-version.h b/deps/v8/include/v8-version.h index 67c3d554da3ba4..7bbdf1cc3e6911 100644 --- a/deps/v8/include/v8-version.h +++ b/deps/v8/include/v8-version.h @@ -11,7 +11,7 @@ #define V8_MAJOR_VERSION 6 #define V8_MINOR_VERSION 2 #define V8_BUILD_NUMBER 414 -#define V8_PATCH_LEVEL 55 +#define V8_PATCH_LEVEL 56 // Use 1 for candidates and 0 otherwise. // (Boolean macro values are not supported by all preprocessors.) diff --git a/deps/v8/include/v8.h b/deps/v8/include/v8.h index 2691b4c9445f7b..a4ed3439494513 100644 --- a/deps/v8/include/v8.h +++ b/deps/v8/include/v8.h @@ -7770,6 +7770,7 @@ class V8_EXPORT Isolate { friend class PersistentValueMapBase; void ReportExternalAllocationLimitReached(); + void CheckMemoryPressure(); }; class V8_EXPORT StartupData { @@ -9019,6 +9020,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; @@ -10244,13 +10247,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(); } diff --git a/deps/v8/src/api.cc b/deps/v8/src/api.cc index e686722b4a39cc..99d79985ef2dae 100644 --- a/deps/v8/src/api.cc +++ b/deps/v8/src/api.cc @@ -8405,6 +8405,10 @@ void Isolate::ReportExternalAllocationLimitReached() { heap->ReportExternalMemoryPressure(); } +void Isolate::CheckMemoryPressure() { + i::Heap* heap = reinterpret_cast<i::Isolate*>(this)->heap(); + heap->CheckMemoryPressure(); +} HeapProfiler* Isolate::GetHeapProfiler() { i::HeapProfiler* heap_profiler = diff --git a/deps/v8/src/heap/heap.cc b/deps/v8/src/heap/heap.cc index e6762df9130d64..f736977d227e7e 100644 --- a/deps/v8/src/heap/heap.cc +++ b/deps/v8/src/heap/heap.cc @@ -4816,10 +4816,12 @@ void Heap::CheckMemoryPressure() { GarbageCollectionReason::kMemoryPressure); } } - MemoryReducer::Event event; - event.type = MemoryReducer::kPossibleGarbage; - event.time_ms = MonotonicallyIncreasingTimeInMs(); - memory_reducer_->NotifyPossibleGarbage(event); + if (memory_reducer_) { + MemoryReducer::Event event; + event.type = MemoryReducer::kPossibleGarbage; + event.time_ms = MonotonicallyIncreasingTimeInMs(); + memory_reducer_->NotifyPossibleGarbage(event); + } } void Heap::CollectGarbageOnMemoryPressure() { diff --git a/deps/v8/src/isolate.cc b/deps/v8/src/isolate.cc index 8a4f2ee12b36ca..64c082b429fc30 100644 --- a/deps/v8/src/isolate.cc +++ b/deps/v8/src/isolate.cc @@ -2837,6 +2837,9 @@ bool Isolate::Init(StartupDeserializer* des) { Internals::kExternalMemoryOffset); CHECK_EQ(static_cast<int>(OFFSET_OF(Isolate, heap_.external_memory_limit_)), Internals::kExternalMemoryLimitOffset); + CHECK_EQ(static_cast<int>( + OFFSET_OF(Isolate, heap_.external_memory_at_last_mark_compact_)), + Internals::kExternalMemoryAtLastMarkCompactOffset); time_millis_at_init_ = heap_.MonotonicallyIncreasingTimeInMs();