Skip to content

Commit d868eb7

Browse files
ofrobotsrvagg
authored andcommitted
deps: V8: cherry-pick 502c6ae6 from upstream
Original commit message: [heap] Activate memory reducer on external memory activity. BUG=chromium:728228,chromium:626082 CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:linux_chromium_rel_ng Review-Url: https://codereview.chromium.org/2917853004 Cr-Commit-Position: refs/heads/master@{#45671} PR-URL: #21269 Fixes: #21021 Reviewed-By: Myles Borins <[email protected]>
1 parent 020057a commit d868eb7

File tree

5 files changed

+32
-5
lines changed

5 files changed

+32
-5
lines changed

deps/v8/include/v8-version.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#define V8_MAJOR_VERSION 6
1212
#define V8_MINOR_VERSION 2
1313
#define V8_BUILD_NUMBER 414
14-
#define V8_PATCH_LEVEL 55
14+
#define V8_PATCH_LEVEL 56
1515

1616
// Use 1 for candidates and 0 otherwise.
1717
// (Boolean macro values are not supported by all preprocessors.)

deps/v8/include/v8.h

+18
Original file line numberDiff line numberDiff line change
@@ -7770,6 +7770,7 @@ class V8_EXPORT Isolate {
77707770
friend class PersistentValueMapBase;
77717771

77727772
void ReportExternalAllocationLimitReached();
7773+
void CheckMemoryPressure();
77737774
};
77747775

77757776
class V8_EXPORT StartupData {
@@ -9019,6 +9020,8 @@ class Internals {
90199020
static const int kExternalMemoryOffset = 4 * kApiPointerSize;
90209021
static const int kExternalMemoryLimitOffset =
90219022
kExternalMemoryOffset + kApiInt64Size;
9023+
static const int kExternalMemoryAtLastMarkCompactOffset =
9024+
kExternalMemoryLimitOffset + kApiInt64Size;
90229025
static const int kIsolateRootsOffset = kExternalMemoryLimitOffset +
90239026
kApiInt64Size + kApiInt64Size +
90249027
kApiPointerSize + kApiPointerSize;
@@ -10244,13 +10247,28 @@ uint32_t Isolate::GetNumberOfDataSlots() {
1024410247

1024510248
int64_t Isolate::AdjustAmountOfExternalAllocatedMemory(
1024610249
int64_t change_in_bytes) {
10250+
const int64_t kMemoryReducerActivationLimit = 1024 * 1024;
1024710251
typedef internal::Internals I;
1024810252
int64_t* external_memory = reinterpret_cast<int64_t*>(
1024910253
reinterpret_cast<uint8_t*>(this) + I::kExternalMemoryOffset);
1025010254
const int64_t external_memory_limit = *reinterpret_cast<int64_t*>(
1025110255
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);
1025210259
const int64_t amount = *external_memory + change_in_bytes;
10260+
1025310261
*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+
1025410272
if (change_in_bytes > 0 && amount > external_memory_limit) {
1025510273
ReportExternalAllocationLimitReached();
1025610274
}

deps/v8/src/api.cc

+4
Original file line numberDiff line numberDiff line change
@@ -8405,6 +8405,10 @@ void Isolate::ReportExternalAllocationLimitReached() {
84058405
heap->ReportExternalMemoryPressure();
84068406
}
84078407

8408+
void Isolate::CheckMemoryPressure() {
8409+
i::Heap* heap = reinterpret_cast<i::Isolate*>(this)->heap();
8410+
heap->CheckMemoryPressure();
8411+
}
84088412

84098413
HeapProfiler* Isolate::GetHeapProfiler() {
84108414
i::HeapProfiler* heap_profiler =

deps/v8/src/heap/heap.cc

+6-4
Original file line numberDiff line numberDiff line change
@@ -4816,10 +4816,12 @@ void Heap::CheckMemoryPressure() {
48164816
GarbageCollectionReason::kMemoryPressure);
48174817
}
48184818
}
4819-
MemoryReducer::Event event;
4820-
event.type = MemoryReducer::kPossibleGarbage;
4821-
event.time_ms = MonotonicallyIncreasingTimeInMs();
4822-
memory_reducer_->NotifyPossibleGarbage(event);
4819+
if (memory_reducer_) {
4820+
MemoryReducer::Event event;
4821+
event.type = MemoryReducer::kPossibleGarbage;
4822+
event.time_ms = MonotonicallyIncreasingTimeInMs();
4823+
memory_reducer_->NotifyPossibleGarbage(event);
4824+
}
48234825
}
48244826

48254827
void Heap::CollectGarbageOnMemoryPressure() {

deps/v8/src/isolate.cc

+3
Original file line numberDiff line numberDiff line change
@@ -2837,6 +2837,9 @@ bool Isolate::Init(StartupDeserializer* des) {
28372837
Internals::kExternalMemoryOffset);
28382838
CHECK_EQ(static_cast<int>(OFFSET_OF(Isolate, heap_.external_memory_limit_)),
28392839
Internals::kExternalMemoryLimitOffset);
2840+
CHECK_EQ(static_cast<int>(
2841+
OFFSET_OF(Isolate, heap_.external_memory_at_last_mark_compact_)),
2842+
Internals::kExternalMemoryAtLastMarkCompactOffset);
28402843

28412844
time_millis_at_init_ = heap_.MonotonicallyIncreasingTimeInMs();
28422845

0 commit comments

Comments
 (0)