Skip to content

Commit 8d08318

Browse files
Dominik InführCommit Bot
authored andcommitted
[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: Ulan Degenbaev <ulan@chromium.org> Cr-Commit-Position: refs/heads/master@{#66651}
1 parent 2cdbb99 commit 8d08318

7 files changed

Lines changed: 33 additions & 5 deletions

File tree

include/v8.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7608,6 +7608,7 @@ class V8_EXPORT HeapStatistics {
76087608
size_t total_physical_size() { return total_physical_size_; }
76097609
size_t total_available_size() { return total_available_size_; }
76107610
size_t total_global_handles_size() { return total_global_handles_size_; }
7611+
size_t used_global_handles_size() { return used_global_handles_size_; }
76117612
size_t used_heap_size() { return used_heap_size_; }
76127613
size_t heap_size_limit() { return heap_size_limit_; }
76137614
size_t malloced_memory() { return malloced_memory_; }
@@ -7636,6 +7637,7 @@ class V8_EXPORT HeapStatistics {
76367637
size_t number_of_native_contexts_;
76377638
size_t number_of_detached_contexts_;
76387639
size_t total_global_handles_size_;
7640+
size_t used_global_handles_size_;
76397641

76407642
friend class V8;
76417643
friend class Isolate;

src/api/api.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8515,6 +8515,7 @@ void Isolate::GetHeapStatistics(HeapStatistics* heap_statistics) {
85158515
heap_statistics->total_available_size_ = heap->Available();
85168516
heap_statistics->used_heap_size_ = heap->SizeOfObjects();
85178517
heap_statistics->total_global_handles_size_ = heap->TotalGlobalHandlesSize();
8518+
heap_statistics->used_global_handles_size_ = heap->UsedGlobalHandlesSize();
85188519

85198520
#ifndef V8_SHARED_RO_HEAP
85208521
i::ReadOnlySpace* ro_space = heap->read_only_space();

src/handles/global-handles.cc

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ class GlobalHandles::NodeSpace final {
187187
iterator end() { return iterator(nullptr); }
188188

189189
size_t TotalSize() const { return blocks_ * sizeof(NodeType) * kBlockSize; }
190+
size_t handles_count() const { return handles_count_; }
190191

191192
private:
192193
void PutNodesOnFreeList(BlockType* block);
@@ -197,6 +198,7 @@ class GlobalHandles::NodeSpace final {
197198
BlockType* first_used_block_ = nullptr;
198199
NodeType* first_free_ = nullptr;
199200
size_t blocks_ = 0;
201+
size_t handles_count_ = 0;
200202
};
201203

202204
template <class NodeType>
@@ -225,7 +227,7 @@ NodeType* GlobalHandles::NodeSpace<NodeType>::Acquire(Object object) {
225227
block->ListAdd(&first_used_block_);
226228
}
227229
global_handles_->isolate()->counters()->global_handles()->Increment();
228-
global_handles_->handles_count_++;
230+
handles_count_++;
229231
DCHECK(node->IsInUse());
230232
return node;
231233
}
@@ -257,7 +259,7 @@ void GlobalHandles::NodeSpace<NodeType>::Free(NodeType* node) {
257259
block->ListRemove(&first_used_block_);
258260
}
259261
global_handles_->isolate()->counters()->global_handles()->Decrement();
260-
global_handles_->handles_count_--;
262+
handles_count_--;
261263
}
262264

263265
template <class Child>
@@ -883,6 +885,15 @@ size_t GlobalHandles::TotalSize() const {
883885
return regular_nodes_->TotalSize() + traced_nodes_->TotalSize();
884886
}
885887

888+
size_t GlobalHandles::UsedSize() const {
889+
return regular_nodes_->handles_count() * sizeof(Node) +
890+
traced_nodes_->handles_count() * sizeof(TracedNode);
891+
}
892+
893+
size_t GlobalHandles::handles_count() const {
894+
return regular_nodes_->handles_count() + traced_nodes_->handles_count();
895+
}
896+
886897
void GlobalHandles::SetStackStart(void* stack_start) {
887898
on_stack_nodes_->SetStackStart(stack_start);
888899
}

src/handles/global-handles.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,10 @@ class V8_EXPORT_PRIVATE GlobalHandles final {
177177
Isolate* isolate() const { return isolate_; }
178178

179179
size_t TotalSize() const;
180+
size_t UsedSize() const;
180181

181182
// Number of global handles.
182-
size_t handles_count() const { return handles_count_; }
183+
size_t handles_count() const;
183184

184185
size_t GetAndResetGlobalHandleResetCount() {
185186
size_t old = number_of_phantom_handle_resets_;
@@ -239,8 +240,6 @@ class V8_EXPORT_PRIVATE GlobalHandles final {
239240
std::vector<TracedNode*> traced_young_nodes_;
240241
std::unique_ptr<OnStackTracedNodeSpace> on_stack_nodes_;
241242

242-
// Field always containing the number of handles to global objects.
243-
size_t handles_count_ = 0;
244243
size_t number_of_phantom_handle_resets_ = 0;
245244

246245
std::vector<std::pair<Node*, PendingPhantomCallback>>

src/heap/heap.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,10 @@ size_t Heap::TotalGlobalHandlesSize() {
871871
return isolate_->global_handles()->TotalSize();
872872
}
873873

874+
size_t Heap::UsedGlobalHandlesSize() {
875+
return isolate_->global_handles()->UsedSize();
876+
}
877+
874878
// static
875879
const char* Heap::GetSpaceName(AllocationSpace space) {
876880
switch (space) {

src/heap/heap.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,6 +1201,9 @@ class Heap {
12011201
// Returns size of all global handles in the heap.
12021202
V8_EXPORT_PRIVATE size_t TotalGlobalHandlesSize();
12031203

1204+
// Returns size of all allocated/used global handles in the heap.
1205+
V8_EXPORT_PRIVATE size_t UsedGlobalHandlesSize();
1206+
12041207
void UpdateSurvivalStatistics(int start_new_space_size);
12051208

12061209
inline void IncrementPromotedObjectsSize(size_t object_size) {

test/cctest/test-global-handles.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,9 +678,13 @@ TEST(TotalSizeRegularNode) {
678678

679679
v8::Global<v8::Object>* global = new Global<v8::Object>();
680680
CHECK_EQ(i_isolate->global_handles()->TotalSize(), 0);
681+
CHECK_EQ(i_isolate->global_handles()->UsedSize(), 0);
681682
ConstructJSObject(isolate, global);
682683
CHECK_GT(i_isolate->global_handles()->TotalSize(), 0);
684+
CHECK_GT(i_isolate->global_handles()->UsedSize(), 0);
683685
delete global;
686+
CHECK_GT(i_isolate->global_handles()->TotalSize(), 0);
687+
CHECK_EQ(i_isolate->global_handles()->UsedSize(), 0);
684688
}
685689

686690
TEST(TotalSizeTracedNode) {
@@ -691,9 +695,13 @@ TEST(TotalSizeTracedNode) {
691695

692696
v8::TracedGlobal<v8::Object>* global = new TracedGlobal<v8::Object>();
693697
CHECK_EQ(i_isolate->global_handles()->TotalSize(), 0);
698+
CHECK_EQ(i_isolate->global_handles()->UsedSize(), 0);
694699
ConstructJSObject(isolate, global);
695700
CHECK_GT(i_isolate->global_handles()->TotalSize(), 0);
701+
CHECK_GT(i_isolate->global_handles()->UsedSize(), 0);
696702
delete global;
703+
CHECK_GT(i_isolate->global_handles()->TotalSize(), 0);
704+
CHECK_EQ(i_isolate->global_handles()->UsedSize(), 0);
697705
}
698706

699707
} // namespace internal

0 commit comments

Comments
 (0)