Revert "[heap] Introduce backing store counters on Heap"

This reverts commit 9c67143f4a.

Reason for revert: Potential cause of mac gpu failures for the auto roller - https://ci.chromium.org/p/chromium/builders/luci.chromium.try/mac_optional_gpu_tests_rel/9158

Original change's description:
> [heap] Introduce backing store counters on Heap
> 
> - Update those counters from space
> - Add fast path for move memory
> 
> Bug: chromium:845409
> Change-Id: Icd72e551df2422a635801fb4e31588073f81544e
> Reviewed-on: https://chromium-review.googlesource.com/1219707
> Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
> Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#55798}

TBR=ulan@chromium.org,mlippautz@chromium.org

Change-Id: Iaa0d375d84f1c559a13dea9b9f1b7f6907cbd768
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: chromium:845409
Reviewed-on: https://chromium-review.googlesource.com/1220293
Reviewed-by: Deepti Gandluri <gdeepti@chromium.org>
Commit-Queue: Deepti Gandluri <gdeepti@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55807}
This commit is contained in:
Deepti Gandluri 2018-09-11 21:22:07 +00:00 committed by Commit Bot
parent fbcf0221fa
commit 0c62f5b39f
10 changed files with 65 additions and 137 deletions

View File

@ -100,11 +100,6 @@ void LocalArrayBufferTracker::Add(JSArrayBuffer* buffer, size_t length) {
page_->IncrementExternalBackingStoreBytes(
ExternalBackingStoreType::kArrayBuffer, length);
AddInternal(buffer, length);
}
void LocalArrayBufferTracker::AddInternal(JSArrayBuffer* buffer,
size_t length) {
auto ret = array_buffers_.insert(
{buffer,
{buffer->backing_store(), length, buffer->backing_store(),

View File

@ -26,10 +26,11 @@ void LocalArrayBufferTracker::Process(Callback callback) {
JSArrayBuffer* new_buffer = nullptr;
JSArrayBuffer* old_buffer = nullptr;
size_t freed_memory = 0;
size_t moved_memory = 0;
for (TrackingData::iterator it = array_buffers_.begin();
it != array_buffers_.end(); ++it) {
old_buffer = it->first;
DCHECK_EQ(page_, Page::FromAddress(old_buffer->address()));
Page* old_page = Page::FromAddress(old_buffer->address());
const CallbackResult result = callback(old_buffer, &new_buffer);
if (result == kKeepEntry) {
kept_array_buffers.insert(*it);
@ -48,25 +49,26 @@ void LocalArrayBufferTracker::Process(Callback callback) {
// We should decrement before adding to avoid potential overflows in
// the external memory counters.
DCHECK_EQ(it->first->is_wasm_memory(), it->second.is_wasm_memory);
tracker->AddInternal(new_buffer, length);
MemoryChunk::MoveExternalBackingStoreBytes(
ExternalBackingStoreType::kArrayBuffer,
static_cast<MemoryChunk*>(page_),
static_cast<MemoryChunk*>(target_page), length);
old_page->DecrementExternalBackingStoreBytes(
ExternalBackingStoreType::kArrayBuffer, length);
tracker->Add(new_buffer, length);
}
moved_memory += it->second.length;
} else if (result == kRemoveEntry) {
freed_memory += it->second.length;
const size_t length = it->second.length;
freed_memory += length;
// We pass backing_store() and stored length to the collector for freeing
// the backing store. Wasm allocations will go through their own tracker
// based on the backing store.
backing_stores_to_free.push_back(it->second);
old_page->DecrementExternalBackingStoreBytes(
ExternalBackingStoreType::kArrayBuffer, length);
} else {
UNREACHABLE();
}
}
if (freed_memory) {
page_->DecrementExternalBackingStoreBytes(
ExternalBackingStoreType::kArrayBuffer, freed_memory);
if (moved_memory || freed_memory) {
// TODO(wez): Remove backing-store from external memory accounting.
page_->heap()->update_external_memory_concurrently_freed(
static_cast<intptr_t>(freed_memory));

View File

@ -113,10 +113,6 @@ class LocalArrayBufferTracker {
typedef std::unordered_map<JSArrayBuffer*, JSArrayBuffer::Allocation, Hasher>
TrackingData;
// Internal version of add that does not update counters. Requires separate
// logic for updating external memory counters.
inline void AddInternal(JSArrayBuffer* buffer, size_t length);
inline Space* space();
Page* page_;

View File

@ -581,21 +581,6 @@ int Heap::MaxNumberToStringCacheSize() const {
// of entries.
return static_cast<int>(number_string_cache_size * 2);
}
void Heap::IncrementExternalBackingStoreBytes(ExternalBackingStoreType type,
size_t amount) {
DCHECK_GE(backing_store_bytes_ + amount, backing_store_bytes_);
backing_store_bytes_ += amount;
// TODO(mlippautz): Implement interrupt for global memory allocations that can
// trigger garbage collections.
}
void Heap::DecrementExternalBackingStoreBytes(ExternalBackingStoreType type,
size_t amount) {
DCHECK_GE(backing_store_bytes_, amount);
backing_store_bytes_ -= amount;
}
AlwaysAllocateScope::AlwaysAllocateScope(Isolate* isolate)
: heap_(isolate->heap()) {
heap_->always_allocate_scope_count_++;

View File

@ -155,7 +155,6 @@ Heap::Heap()
// Will be 4 * reserved_semispace_size_ to ensure that young
// generation can be aligned to its size.
maximum_committed_(0),
backing_store_bytes_(0),
survived_since_last_expansion_(0),
survived_last_scavenge_(0),
always_allocate_scope_count_(0),
@ -478,8 +477,6 @@ void Heap::PrintShortHeapStatistics() {
CommittedMemoryOfHeapAndUnmapper() / KB);
PrintIsolate(isolate_, "External memory reported: %6" PRId64 " KB\n",
external_memory_ / KB);
PrintIsolate(isolate_, "Backing store memory: %6" PRIuS " KB\n",
backing_store_bytes_ / KB);
PrintIsolate(isolate_, "External memory global %zu KB\n",
external_memory_callback_() / KB);
PrintIsolate(isolate_, "Total time spent in GC : %.1f ms\n",
@ -2292,6 +2289,15 @@ bool Heap::ExternalStringTable::Contains(HeapObject* obj) {
return false;
}
void Heap::ProcessMovedExternalString(Page* old_page, Page* new_page,
ExternalString* string) {
size_t size = string->ExternalPayloadSize();
new_page->IncrementExternalBackingStoreBytes(
ExternalBackingStoreType::kExternalString, size);
old_page->DecrementExternalBackingStoreBytes(
ExternalBackingStoreType::kExternalString, size);
}
String* Heap::UpdateNewSpaceReferenceInExternalStringTableEntry(Heap* heap,
Object** p) {
MapWord first_word = HeapObject::cast(*p)->map_word();
@ -2319,11 +2325,9 @@ String* Heap::UpdateNewSpaceReferenceInExternalStringTableEntry(Heap* heap,
// Filtering Thin strings out of the external string table.
return nullptr;
} else if (new_string->IsExternalString()) {
MemoryChunk::MoveExternalBackingStoreBytes(
ExternalBackingStoreType::kExternalString,
heap->ProcessMovedExternalString(
Page::FromAddress(reinterpret_cast<Address>(*p)),
Page::FromHeapObject(new_string),
ExternalString::cast(new_string)->ExternalPayloadSize());
Page::FromHeapObject(new_string), ExternalString::cast(new_string));
return new_string;
}

View File

@ -207,8 +207,6 @@ enum class ClearRecordedSlots { kYes, kNo };
enum class ClearFreedMemoryMode { kClearFreedMemory, kDontClearFreedMemory };
enum ExternalBackingStoreType { kArrayBuffer, kExternalString, kNumTypes };
enum class FixedArrayVisitationMode { kRegular, kIncremental };
enum class TraceRetainingPathMode { kEnabled, kDisabled };
@ -692,7 +690,8 @@ class Heap {
external_memory_concurrently_freed_ = 0;
}
size_t backing_store_bytes() const { return backing_store_bytes_; }
void ProcessMovedExternalString(Page* old_page, Page* new_page,
ExternalString* string);
void CompactWeakArrayLists(PretenureFlag pretenure);
@ -1844,12 +1843,6 @@ class Heap {
void CheckIneffectiveMarkCompact(size_t old_generation_size,
double mutator_utilization);
inline void IncrementExternalBackingStoreBytes(ExternalBackingStoreType type,
size_t amount);
inline void DecrementExternalBackingStoreBytes(ExternalBackingStoreType type,
size_t amount);
// ===========================================================================
// Growing strategy. =========================================================
// ===========================================================================
@ -2018,9 +2011,6 @@ class Heap {
bool old_generation_size_configured_;
size_t maximum_committed_;
// Backing store bytes (array buffers and external strings).
std::atomic<size_t> backing_store_bytes_;
// For keeping track of how much data has survived
// scavenge since last new space expansion.
size_t survived_since_last_expansion_;
@ -2296,7 +2286,6 @@ class Heap {
friend class Page;
friend class PagedSpace;
friend class Scavenger;
friend class Space;
friend class StoreBuffer;
friend class Sweeper;
friend class heap::TestMemoryAllocatorScope;

View File

@ -2274,11 +2274,9 @@ static String* UpdateReferenceInExternalStringTableEntry(Heap* heap,
String* new_string = String::cast(map_word.ToForwardingAddress());
if (new_string->IsExternalString()) {
MemoryChunk::MoveExternalBackingStoreBytes(
ExternalBackingStoreType::kExternalString,
heap->ProcessMovedExternalString(
Page::FromAddress(reinterpret_cast<Address>(*p)),
Page::FromHeapObject(new_string),
ExternalString::cast(new_string)->ExternalPayloadSize());
Page::FromHeapObject(new_string), ExternalString::cast(new_string));
}
return new_string;
}

View File

@ -93,33 +93,6 @@ HeapObject* HeapObjectIterator::FromCurrentPage() {
return nullptr;
}
void Space::IncrementExternalBackingStoreBytes(ExternalBackingStoreType type,
size_t amount) {
DCHECK_GE(external_backing_store_bytes_[type] + amount,
external_backing_store_bytes_[type]);
external_backing_store_bytes_[type] += amount;
heap()->IncrementExternalBackingStoreBytes(type, amount);
}
void Space::DecrementExternalBackingStoreBytes(ExternalBackingStoreType type,
size_t amount) {
DCHECK_GE(external_backing_store_bytes_[type], amount);
external_backing_store_bytes_[type] -= amount;
heap()->DecrementExternalBackingStoreBytes(type, amount);
}
void Space::MoveExternalBackingStoreBytes(ExternalBackingStoreType type,
Space* from, Space* to,
size_t amount) {
if (from == to) return;
DCHECK_GE(from->external_backing_store_bytes_[type], amount);
from->external_backing_store_bytes_[type] -= amount;
DCHECK_GE(to->external_backing_store_bytes_[type] + amount,
to->external_backing_store_bytes_[type]);
to->external_backing_store_bytes_[type] += amount;
}
// -----------------------------------------------------------------------------
// SemiSpace
@ -217,34 +190,6 @@ MemoryChunk* MemoryChunk::FromAnyPointerAddress(Heap* heap, Address addr) {
return chunk;
}
void MemoryChunk::IncrementExternalBackingStoreBytes(
ExternalBackingStoreType type, size_t amount) {
DCHECK_GE(external_backing_store_bytes_[type] + amount,
external_backing_store_bytes_[type]);
external_backing_store_bytes_[type] += amount;
owner()->IncrementExternalBackingStoreBytes(type, amount);
}
void MemoryChunk::DecrementExternalBackingStoreBytes(
ExternalBackingStoreType type, size_t amount) {
DCHECK_GE(external_backing_store_bytes_[type], amount);
external_backing_store_bytes_[type] -= amount;
owner()->DecrementExternalBackingStoreBytes(type, amount);
}
void MemoryChunk::MoveExternalBackingStoreBytes(ExternalBackingStoreType type,
MemoryChunk* from,
MemoryChunk* to,
size_t amount) {
DCHECK_GE(from->external_backing_store_bytes_[type], amount);
from->external_backing_store_bytes_[type] -= amount;
DCHECK_GE(to->external_backing_store_bytes_[type] + amount,
to->external_backing_store_bytes_[type]);
to->external_backing_store_bytes_[type] += amount;
Space::MoveExternalBackingStoreBytes(type, from->owner(), to->owner(),
amount);
}
void Page::MarkNeverAllocateForTesting() {
DCHECK(this->owner()->identity() != NEW_SPACE);
DCHECK(!IsFlagSet(NEVER_ALLOCATE_ON_PAGE));

View File

@ -1308,6 +1308,19 @@ void MemoryChunk::ReleaseYoungGenerationBitmap() {
young_generation_bitmap_ = nullptr;
}
void MemoryChunk::IncrementExternalBackingStoreBytes(
ExternalBackingStoreType type, size_t amount) {
external_backing_store_bytes_[type] += amount;
owner()->IncrementExternalBackingStoreBytes(type, amount);
}
void MemoryChunk::DecrementExternalBackingStoreBytes(
ExternalBackingStoreType type, size_t amount) {
DCHECK_GE(external_backing_store_bytes_[type], amount);
external_backing_store_bytes_[type] -= amount;
owner()->DecrementExternalBackingStoreBytes(type, amount);
}
// -----------------------------------------------------------------------------
// PagedSpace implementation

View File

@ -143,6 +143,12 @@ enum FreeMode { kLinkCategory, kDoNotLinkCategory };
enum class SpaceAccountingMode { kSpaceAccounted, kSpaceUnaccounted };
enum ExternalBackingStoreType {
kArrayBuffer,
kExternalString,
kNumTypes
};
enum RememberedSetType {
OLD_TO_NEW,
OLD_TO_OLD,
@ -373,7 +379,7 @@ class MemoryChunk {
kPointerSize // std::atomic<ConcurrentSweepingState> concurrent_sweeping_
+ kPointerSize // base::Mutex* page_protection_change_mutex_
+ kPointerSize // unitptr_t write_unprotect_counter_
+ kSizetSize * ExternalBackingStoreType::kNumTypes
+ kSizetSize * kNumTypes
// std::atomic<size_t> external_backing_store_bytes_
+ kSizetSize // size_t allocated_bytes_
+ kSizetSize // size_t wasted_memory_
@ -439,10 +445,6 @@ class MemoryChunk {
!chunk->high_water_mark_.compare_exchange_weak(old_mark, new_mark));
}
static inline void MoveExternalBackingStoreBytes(
ExternalBackingStoreType type, MemoryChunk* from, MemoryChunk* to,
size_t amount);
Address address() const {
return reinterpret_cast<Address>(const_cast<MemoryChunk*>(this));
}
@ -549,12 +551,10 @@ class MemoryChunk {
}
}
inline void IncrementExternalBackingStoreBytes(ExternalBackingStoreType type,
size_t amount);
inline void DecrementExternalBackingStoreBytes(ExternalBackingStoreType type,
size_t amount);
void IncrementExternalBackingStoreBytes(ExternalBackingStoreType type,
size_t amount);
void DecrementExternalBackingStoreBytes(ExternalBackingStoreType type,
size_t amount);
size_t ExternalBackingStoreBytes(ExternalBackingStoreType type) {
return external_backing_store_bytes_[type];
}
@ -945,9 +945,6 @@ class Space : public Malloced {
0;
}
static inline void MoveExternalBackingStoreBytes(
ExternalBackingStoreType type, Space* from, Space* to, size_t amount);
virtual ~Space() {
delete[] external_backing_store_bytes_;
external_backing_store_bytes_ = nullptr;
@ -987,6 +984,12 @@ class Space : public Malloced {
// (e.g. see LargeObjectSpace).
virtual size_t SizeOfObjects() { return Size(); }
// Returns amount of off-heap memory in-use by objects in this Space.
virtual size_t ExternalBackingStoreBytes(
ExternalBackingStoreType type) const {
return external_backing_store_bytes_[type];
}
// Approximate amount of physical memory committed for this space.
virtual size_t CommittedPhysicalMemory() = 0;
@ -1016,16 +1019,14 @@ class Space : public Malloced {
committed_ -= bytes;
}
inline void IncrementExternalBackingStoreBytes(ExternalBackingStoreType type,
size_t amount);
inline void DecrementExternalBackingStoreBytes(ExternalBackingStoreType type,
size_t amount);
// Returns amount of off-heap memory in-use by objects in this Space.
virtual size_t ExternalBackingStoreBytes(
ExternalBackingStoreType type) const {
return external_backing_store_bytes_[type];
void IncrementExternalBackingStoreBytes(ExternalBackingStoreType type,
size_t amount) {
external_backing_store_bytes_[type] += amount;
}
void DecrementExternalBackingStoreBytes(ExternalBackingStoreType type,
size_t amount) {
DCHECK_GE(external_backing_store_bytes_[type], amount);
external_backing_store_bytes_[type] -= amount;
}
V8_EXPORT_PRIVATE void* GetRandomMmapAddr();