Skip to content

Commit

Permalink
deps: V8: cherry-pick 502c6ae6 from upstream
Browse files Browse the repository at this point in the history
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 <myles.borins@gmail.com>
  • Loading branch information
ofrobots authored and MylesBorins committed Jun 14, 2018
1 parent f493001 commit ce5ba6d
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 5 deletions.
2 changes: 1 addition & 1 deletion deps/v8/include/v8-version.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.)
Expand Down
18 changes: 18 additions & 0 deletions deps/v8/include/v8.h
Original file line number Diff line number Diff line change
Expand Up @@ -7770,6 +7770,7 @@ class V8_EXPORT Isolate {
friend class PersistentValueMapBase;

void ReportExternalAllocationLimitReached();
void CheckMemoryPressure();
};

class V8_EXPORT StartupData {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down
4 changes: 4 additions & 0 deletions deps/v8/src/api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
10 changes: 6 additions & 4 deletions deps/v8/src/heap/heap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
3 changes: 3 additions & 0 deletions deps/v8/src/isolate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit ce5ba6d

Please sign in to comment.