Commit d02ab0e1 authored by Dominik Inführ's avatar Dominik Inführ Committed by Commit Bot

[heap] Ensure Isolate::GetHeapStatistics uses space mutex

PagedSpace::CommittedPhysicalMemory() needs to use mutex when iterating
chunks due to concurrent allocations.

Also reorder sampling of memory statistics according to this order:

1) used memory
2) committed physical memory
3) committed memory

That way, used <= committed physical <= committed should hold.

Bug: v8:10315
Change-Id: Ie922ecc4846f724a09c71667a898bf74a8652220
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2390768
Commit-Queue: Dominik Inführ <dinfuehr@chromium.org>
Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#69698}
parent b469661e
......@@ -8543,21 +8543,34 @@ void Isolate::GetHeapStatistics(HeapStatistics* heap_statistics) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
i::Heap* heap = isolate->heap();
heap_statistics->total_heap_size_ = heap->CommittedMemory();
// The order of acquiring memory statistics is important here. We query in
// this order because of concurrent allocation: 1) used memory 2) comitted
// physical memory 3) committed memory. Therefore the condition used <=
// committed physical <= committed should hold.
heap_statistics->used_global_handles_size_ = heap->UsedGlobalHandlesSize();
heap_statistics->total_global_handles_size_ = heap->TotalGlobalHandlesSize();
DCHECK_LE(heap_statistics->used_global_handles_size_,
heap_statistics->total_global_handles_size_);
heap_statistics->used_heap_size_ = heap->SizeOfObjects();
heap_statistics->total_physical_size_ = heap->CommittedPhysicalMemory();
heap_statistics->total_heap_size_ = heap->CommittedMemory();
heap_statistics->total_available_size_ = heap->Available();
heap_statistics->used_heap_size_ = heap->SizeOfObjects();
heap_statistics->total_global_handles_size_ = heap->TotalGlobalHandlesSize();
heap_statistics->used_global_handles_size_ = heap->UsedGlobalHandlesSize();
if (!i::ReadOnlyHeap::IsReadOnlySpaceShared()) {
i::ReadOnlySpace* ro_space = heap->read_only_space();
heap_statistics->total_heap_size_ += ro_space->CommittedMemory();
heap_statistics->used_heap_size_ += ro_space->Size();
heap_statistics->total_physical_size_ +=
ro_space->CommittedPhysicalMemory();
heap_statistics->used_heap_size_ += ro_space->Size();
heap_statistics->total_heap_size_ += ro_space->CommittedMemory();
}
// TODO(dinfuehr): Right now used <= committed physical does not hold. Fix
// this and add DCHECK.
DCHECK_LE(heap_statistics->used_heap_size_,
heap_statistics->total_heap_size_);
heap_statistics->total_heap_size_executable_ =
heap->CommittedMemoryExecutable();
heap_statistics->heap_size_limit_ = heap->MaxReserved();
......
......@@ -200,6 +200,7 @@ void PagedSpace::MergeLocalSpace(LocalSpace* other) {
size_t PagedSpace::CommittedPhysicalMemory() {
if (!base::OS::HasLazyCommits()) return CommittedMemory();
BasicMemoryChunk::UpdateHighWaterMark(allocation_info_.top());
base::MutexGuard guard(mutex());
size_t size = 0;
for (Page* page : *this) {
size += page->CommittedPhysicalMemory();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment