Commit c8704891 authored by Dan Elphick's avatar Dan Elphick Committed by Commit Bot

[api] SharedMemoryStatistics now reports RO-Heap stats

If V8_SHARED_RO_HEAP is set, then GetSharedMemoryStatistics now reports
the size of RO_SPACE. Additionally size values for RO_SPACE are zeroed
in the per-isolate Heap and Space stats.

Bug: v8:7464
Change-Id: I2d6843c001b55974460d1df034f08d1ed5b0d8da
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1900459
Commit-Queue: Dan Elphick <delphick@chromium.org>
Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#65231}
parent 24710f3e
......@@ -5766,9 +5766,17 @@ void v8::V8::InitializeExternalStartupDataFromFile(const char* snapshot_blob) {
const char* v8::V8::GetVersion() { return i::Version::GetVersion(); }
void V8::GetSharedMemoryStatistics(SharedMemoryStatistics* statistics) {
#ifdef V8_SHARED_RO_HEAP
i::ReadOnlySpace* ro_space = i::ReadOnlyHeap::Instance()->read_only_space();
statistics->read_only_space_size_ = ro_space->CommittedMemory();
statistics->read_only_space_used_size_ = ro_space->SizeOfObjects();
statistics->read_only_space_physical_size_ =
ro_space->CommittedPhysicalMemory();
#else
statistics->read_only_space_size_ = 0;
statistics->read_only_space_used_size_ = 0;
statistics->read_only_space_physical_size_ = 0;
#endif // V8_SHARED_RO_HEAP
}
template <typename ObjectType>
......@@ -8487,18 +8495,22 @@ i::Address* Isolate::GetDataFromSnapshotOnce(size_t index) {
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();
heap_statistics->total_physical_size_ = heap->CommittedPhysicalMemory();
heap_statistics->total_available_size_ = heap->Available();
heap_statistics->used_heap_size_ = heap->SizeOfObjects();
#ifndef V8_SHARED_RO_HEAP
i::ReadOnlySpace* ro_space = heap->read_only_space();
heap_statistics->total_heap_size_ += ro_space->CommittedMemory();
heap_statistics->total_physical_size_ += ro_space->CommittedPhysicalMemory();
heap_statistics->total_available_size_ += ro_space->Available();
heap_statistics->used_heap_size_ += ro_space->SizeOfObjects();
#endif // V8_SHARED_RO_HEAP
heap_statistics->total_heap_size_ =
heap->CommittedMemory() + ro_space->CommittedMemory();
heap_statistics->total_heap_size_executable_ =
heap->CommittedMemoryExecutable();
heap_statistics->total_physical_size_ =
heap->CommittedPhysicalMemory() + ro_space->CommittedPhysicalMemory();
heap_statistics->total_available_size_ =
heap->Available() + ro_space->Available();
heap_statistics->used_heap_size_ =
heap->SizeOfObjects() + ro_space->SizeOfObjects();
heap_statistics->heap_size_limit_ = heap->MaxReserved();
// TODO(7424): There is no public API for the {WasmEngine} yet. Once such an
// API becomes available we should report the malloced memory separately. For
......@@ -8530,12 +8542,21 @@ bool Isolate::GetHeapSpaceStatistics(HeapSpaceStatistics* space_statistics,
i::Heap* heap = isolate->heap();
i::Space* space = heap->space(static_cast<int>(index));
space_statistics->space_name_ =
i::Heap::GetSpaceName(static_cast<i::AllocationSpace>(index));
space_statistics->space_size_ = space->CommittedMemory();
space_statistics->space_used_size_ = space->SizeOfObjects();
space_statistics->space_available_size_ = space->Available();
space_statistics->physical_space_size_ = space->CommittedPhysicalMemory();
i::AllocationSpace allocation_space = static_cast<i::AllocationSpace>(index);
space_statistics->space_name_ = i::Heap::GetSpaceName(allocation_space);
if (allocation_space == i::RO_SPACE && V8_SHARED_RO_HEAP_BOOL) {
// RO_SPACE memory is accounted for elsewhere when ReadOnlyHeap is shared.
space_statistics->space_size_ = 0;
space_statistics->space_used_size_ = 0;
space_statistics->space_available_size_ = 0;
space_statistics->physical_space_size_ = 0;
} else {
space_statistics->space_size_ = space->CommittedMemory();
space_statistics->space_used_size_ = space->SizeOfObjects();
space_statistics->space_available_size_ = space->Available();
space_statistics->physical_space_size_ = space->CommittedPhysicalMemory();
}
return true;
}
......
......@@ -305,6 +305,12 @@ DEFINE_BOOL(icu_timezone_data, true, "get information about timezones from ICU")
#define V8_LAZY_SOURCE_POSITIONS_BOOL false
#endif
#ifdef V8_SHARED_RO_HEAP
#define V8_SHARED_RO_HEAP_BOOL true
#else
#define V8_SHARED_RO_HEAP_BOOL false
#endif
DEFINE_BOOL(lite_mode, V8_LITE_BOOL,
"enables trade-off of performance for memory savings")
......
......@@ -120,6 +120,11 @@ void ReadOnlyHeap::OnHeapTearDown() {
#endif
}
#ifdef V8_SHARED_RO_HEAP
// static
const ReadOnlyHeap* ReadOnlyHeap::Instance() { return shared_ro_heap_; }
#endif
// static
void ReadOnlyHeap::ClearSharedHeapForTest() {
#ifdef V8_SHARED_RO_HEAP
......
......@@ -42,6 +42,10 @@ class ReadOnlyHeap final {
// and it may be safely disposed of.
void OnHeapTearDown();
#ifdef V8_SHARED_RO_HEAP
static const ReadOnlyHeap* Instance();
#endif
// Returns whether the address is within the read-only space.
V8_EXPORT_PRIVATE static bool Contains(Address address);
// Returns whether the object resides in the read-only space.
......
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