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

[heap] Report allocated size of global handles

Report the allocated size of global handles in GetHeapStatistics as
well, not including free handles.

Bug: chromium:1060192
Change-Id: I1aedba36735f897cd8518edbb5ef2261cc348bff
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2093493
Commit-Queue: Dominik Inführ <dinfuehr@chromium.org>
Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#66651}
parent 2cdbb99b
...@@ -7608,6 +7608,7 @@ class V8_EXPORT HeapStatistics { ...@@ -7608,6 +7608,7 @@ class V8_EXPORT HeapStatistics {
size_t total_physical_size() { return total_physical_size_; } size_t total_physical_size() { return total_physical_size_; }
size_t total_available_size() { return total_available_size_; } size_t total_available_size() { return total_available_size_; }
size_t total_global_handles_size() { return total_global_handles_size_; } size_t total_global_handles_size() { return total_global_handles_size_; }
size_t used_global_handles_size() { return used_global_handles_size_; }
size_t used_heap_size() { return used_heap_size_; } size_t used_heap_size() { return used_heap_size_; }
size_t heap_size_limit() { return heap_size_limit_; } size_t heap_size_limit() { return heap_size_limit_; }
size_t malloced_memory() { return malloced_memory_; } size_t malloced_memory() { return malloced_memory_; }
...@@ -7636,6 +7637,7 @@ class V8_EXPORT HeapStatistics { ...@@ -7636,6 +7637,7 @@ class V8_EXPORT HeapStatistics {
size_t number_of_native_contexts_; size_t number_of_native_contexts_;
size_t number_of_detached_contexts_; size_t number_of_detached_contexts_;
size_t total_global_handles_size_; size_t total_global_handles_size_;
size_t used_global_handles_size_;
friend class V8; friend class V8;
friend class Isolate; friend class Isolate;
......
...@@ -8515,6 +8515,7 @@ void Isolate::GetHeapStatistics(HeapStatistics* heap_statistics) { ...@@ -8515,6 +8515,7 @@ void Isolate::GetHeapStatistics(HeapStatistics* heap_statistics) {
heap_statistics->total_available_size_ = heap->Available(); heap_statistics->total_available_size_ = heap->Available();
heap_statistics->used_heap_size_ = heap->SizeOfObjects(); heap_statistics->used_heap_size_ = heap->SizeOfObjects();
heap_statistics->total_global_handles_size_ = heap->TotalGlobalHandlesSize(); heap_statistics->total_global_handles_size_ = heap->TotalGlobalHandlesSize();
heap_statistics->used_global_handles_size_ = heap->UsedGlobalHandlesSize();
#ifndef V8_SHARED_RO_HEAP #ifndef V8_SHARED_RO_HEAP
i::ReadOnlySpace* ro_space = heap->read_only_space(); i::ReadOnlySpace* ro_space = heap->read_only_space();
......
...@@ -187,6 +187,7 @@ class GlobalHandles::NodeSpace final { ...@@ -187,6 +187,7 @@ class GlobalHandles::NodeSpace final {
iterator end() { return iterator(nullptr); } iterator end() { return iterator(nullptr); }
size_t TotalSize() const { return blocks_ * sizeof(NodeType) * kBlockSize; } size_t TotalSize() const { return blocks_ * sizeof(NodeType) * kBlockSize; }
size_t handles_count() const { return handles_count_; }
private: private:
void PutNodesOnFreeList(BlockType* block); void PutNodesOnFreeList(BlockType* block);
...@@ -197,6 +198,7 @@ class GlobalHandles::NodeSpace final { ...@@ -197,6 +198,7 @@ class GlobalHandles::NodeSpace final {
BlockType* first_used_block_ = nullptr; BlockType* first_used_block_ = nullptr;
NodeType* first_free_ = nullptr; NodeType* first_free_ = nullptr;
size_t blocks_ = 0; size_t blocks_ = 0;
size_t handles_count_ = 0;
}; };
template <class NodeType> template <class NodeType>
...@@ -225,7 +227,7 @@ NodeType* GlobalHandles::NodeSpace<NodeType>::Acquire(Object object) { ...@@ -225,7 +227,7 @@ NodeType* GlobalHandles::NodeSpace<NodeType>::Acquire(Object object) {
block->ListAdd(&first_used_block_); block->ListAdd(&first_used_block_);
} }
global_handles_->isolate()->counters()->global_handles()->Increment(); global_handles_->isolate()->counters()->global_handles()->Increment();
global_handles_->handles_count_++; handles_count_++;
DCHECK(node->IsInUse()); DCHECK(node->IsInUse());
return node; return node;
} }
...@@ -257,7 +259,7 @@ void GlobalHandles::NodeSpace<NodeType>::Free(NodeType* node) { ...@@ -257,7 +259,7 @@ void GlobalHandles::NodeSpace<NodeType>::Free(NodeType* node) {
block->ListRemove(&first_used_block_); block->ListRemove(&first_used_block_);
} }
global_handles_->isolate()->counters()->global_handles()->Decrement(); global_handles_->isolate()->counters()->global_handles()->Decrement();
global_handles_->handles_count_--; handles_count_--;
} }
template <class Child> template <class Child>
...@@ -883,6 +885,15 @@ size_t GlobalHandles::TotalSize() const { ...@@ -883,6 +885,15 @@ size_t GlobalHandles::TotalSize() const {
return regular_nodes_->TotalSize() + traced_nodes_->TotalSize(); return regular_nodes_->TotalSize() + traced_nodes_->TotalSize();
} }
size_t GlobalHandles::UsedSize() const {
return regular_nodes_->handles_count() * sizeof(Node) +
traced_nodes_->handles_count() * sizeof(TracedNode);
}
size_t GlobalHandles::handles_count() const {
return regular_nodes_->handles_count() + traced_nodes_->handles_count();
}
void GlobalHandles::SetStackStart(void* stack_start) { void GlobalHandles::SetStackStart(void* stack_start) {
on_stack_nodes_->SetStackStart(stack_start); on_stack_nodes_->SetStackStart(stack_start);
} }
......
...@@ -177,9 +177,10 @@ class V8_EXPORT_PRIVATE GlobalHandles final { ...@@ -177,9 +177,10 @@ class V8_EXPORT_PRIVATE GlobalHandles final {
Isolate* isolate() const { return isolate_; } Isolate* isolate() const { return isolate_; }
size_t TotalSize() const; size_t TotalSize() const;
size_t UsedSize() const;
// Number of global handles. // Number of global handles.
size_t handles_count() const { return handles_count_; } size_t handles_count() const;
size_t GetAndResetGlobalHandleResetCount() { size_t GetAndResetGlobalHandleResetCount() {
size_t old = number_of_phantom_handle_resets_; size_t old = number_of_phantom_handle_resets_;
...@@ -239,8 +240,6 @@ class V8_EXPORT_PRIVATE GlobalHandles final { ...@@ -239,8 +240,6 @@ class V8_EXPORT_PRIVATE GlobalHandles final {
std::vector<TracedNode*> traced_young_nodes_; std::vector<TracedNode*> traced_young_nodes_;
std::unique_ptr<OnStackTracedNodeSpace> on_stack_nodes_; std::unique_ptr<OnStackTracedNodeSpace> on_stack_nodes_;
// Field always containing the number of handles to global objects.
size_t handles_count_ = 0;
size_t number_of_phantom_handle_resets_ = 0; size_t number_of_phantom_handle_resets_ = 0;
std::vector<std::pair<Node*, PendingPhantomCallback>> std::vector<std::pair<Node*, PendingPhantomCallback>>
......
...@@ -871,6 +871,10 @@ size_t Heap::TotalGlobalHandlesSize() { ...@@ -871,6 +871,10 @@ size_t Heap::TotalGlobalHandlesSize() {
return isolate_->global_handles()->TotalSize(); return isolate_->global_handles()->TotalSize();
} }
size_t Heap::UsedGlobalHandlesSize() {
return isolate_->global_handles()->UsedSize();
}
// static // static
const char* Heap::GetSpaceName(AllocationSpace space) { const char* Heap::GetSpaceName(AllocationSpace space) {
switch (space) { switch (space) {
......
...@@ -1201,6 +1201,9 @@ class Heap { ...@@ -1201,6 +1201,9 @@ class Heap {
// Returns size of all global handles in the heap. // Returns size of all global handles in the heap.
V8_EXPORT_PRIVATE size_t TotalGlobalHandlesSize(); V8_EXPORT_PRIVATE size_t TotalGlobalHandlesSize();
// Returns size of all allocated/used global handles in the heap.
V8_EXPORT_PRIVATE size_t UsedGlobalHandlesSize();
void UpdateSurvivalStatistics(int start_new_space_size); void UpdateSurvivalStatistics(int start_new_space_size);
inline void IncrementPromotedObjectsSize(size_t object_size) { inline void IncrementPromotedObjectsSize(size_t object_size) {
......
...@@ -678,9 +678,13 @@ TEST(TotalSizeRegularNode) { ...@@ -678,9 +678,13 @@ TEST(TotalSizeRegularNode) {
v8::Global<v8::Object>* global = new Global<v8::Object>(); v8::Global<v8::Object>* global = new Global<v8::Object>();
CHECK_EQ(i_isolate->global_handles()->TotalSize(), 0); CHECK_EQ(i_isolate->global_handles()->TotalSize(), 0);
CHECK_EQ(i_isolate->global_handles()->UsedSize(), 0);
ConstructJSObject(isolate, global); ConstructJSObject(isolate, global);
CHECK_GT(i_isolate->global_handles()->TotalSize(), 0); CHECK_GT(i_isolate->global_handles()->TotalSize(), 0);
CHECK_GT(i_isolate->global_handles()->UsedSize(), 0);
delete global; delete global;
CHECK_GT(i_isolate->global_handles()->TotalSize(), 0);
CHECK_EQ(i_isolate->global_handles()->UsedSize(), 0);
} }
TEST(TotalSizeTracedNode) { TEST(TotalSizeTracedNode) {
...@@ -691,9 +695,13 @@ TEST(TotalSizeTracedNode) { ...@@ -691,9 +695,13 @@ TEST(TotalSizeTracedNode) {
v8::TracedGlobal<v8::Object>* global = new TracedGlobal<v8::Object>(); v8::TracedGlobal<v8::Object>* global = new TracedGlobal<v8::Object>();
CHECK_EQ(i_isolate->global_handles()->TotalSize(), 0); CHECK_EQ(i_isolate->global_handles()->TotalSize(), 0);
CHECK_EQ(i_isolate->global_handles()->UsedSize(), 0);
ConstructJSObject(isolate, global); ConstructJSObject(isolate, global);
CHECK_GT(i_isolate->global_handles()->TotalSize(), 0); CHECK_GT(i_isolate->global_handles()->TotalSize(), 0);
CHECK_GT(i_isolate->global_handles()->UsedSize(), 0);
delete global; delete global;
CHECK_GT(i_isolate->global_handles()->TotalSize(), 0);
CHECK_EQ(i_isolate->global_handles()->UsedSize(), 0);
} }
} // namespace internal } // namespace internal
......
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