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

[heap] Report total size of global handles

Report the total size of global handles in GetHeapStatistics as well.
This size includes used and free global handles.

Change-Id: I08c0647d993a810a37ae9f332732de9551b5ea8d
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2083020
Commit-Queue: Dominik Inführ <dinfuehr@chromium.org>
Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#66562}
parent a1cb3326
......@@ -7578,6 +7578,7 @@ class V8_EXPORT HeapStatistics {
size_t total_heap_size_executable() { return total_heap_size_executable_; }
size_t total_physical_size() { return total_physical_size_; }
size_t total_available_size() { return total_available_size_; }
size_t total_global_handles_size() { return total_global_handles_size_; }
size_t used_heap_size() { return used_heap_size_; }
size_t heap_size_limit() { return heap_size_limit_; }
size_t malloced_memory() { return malloced_memory_; }
......@@ -7605,6 +7606,7 @@ class V8_EXPORT HeapStatistics {
bool does_zap_garbage_;
size_t number_of_native_contexts_;
size_t number_of_detached_contexts_;
size_t total_global_handles_size_;
friend class V8;
friend class Isolate;
......
......@@ -8483,6 +8483,7 @@ void Isolate::GetHeapStatistics(HeapStatistics* heap_statistics) {
heap_statistics->total_physical_size_ = heap->CommittedPhysicalMemory();
heap_statistics->total_available_size_ = heap->Available();
heap_statistics->used_heap_size_ = heap->SizeOfObjects();
heap_statistics->total_global_handles_size_ = heap->TotalGlobalHandlesSize();
#ifndef V8_SHARED_RO_HEAP
i::ReadOnlySpace* ro_space = heap->read_only_space();
......
......@@ -186,6 +186,8 @@ class GlobalHandles::NodeSpace final {
iterator begin() { return iterator(first_used_block_); }
iterator end() { return iterator(nullptr); }
size_t TotalSize() const { return blocks_ * sizeof(NodeType) * kBlockSize; }
private:
void PutNodesOnFreeList(BlockType* block);
V8_INLINE void Free(NodeType* node);
......@@ -194,6 +196,7 @@ class GlobalHandles::NodeSpace final {
BlockType* first_block_ = nullptr;
BlockType* first_used_block_ = nullptr;
NodeType* first_free_ = nullptr;
size_t blocks_ = 0;
};
template <class NodeType>
......@@ -210,6 +213,7 @@ template <class NodeType>
NodeType* GlobalHandles::NodeSpace<NodeType>::Acquire(Object object) {
if (first_free_ == nullptr) {
first_block_ = new BlockType(global_handles_, this, first_block_);
blocks_++;
PutNodesOnFreeList(first_block_);
}
DCHECK_NOT_NULL(first_free_);
......@@ -875,6 +879,10 @@ size_t GlobalHandles::NumberOfOnStackHandlesForTesting() {
return on_stack_nodes_->NumberOfHandlesForTesting();
}
size_t GlobalHandles::TotalSize() const {
return regular_nodes_->TotalSize() + traced_nodes_->TotalSize();
}
void GlobalHandles::SetStackStart(void* stack_start) {
on_stack_nodes_->SetStackStart(stack_start);
}
......
......@@ -176,6 +176,8 @@ class V8_EXPORT_PRIVATE GlobalHandles final {
Isolate* isolate() const { return isolate_; }
size_t TotalSize() const;
// Number of global handles.
size_t handles_count() const { return handles_count_; }
......
......@@ -867,6 +867,10 @@ size_t Heap::SizeOfObjects() {
return total;
}
size_t Heap::TotalGlobalHandlesSize() {
return isolate_->global_handles()->TotalSize();
}
// static
const char* Heap::GetSpaceName(AllocationSpace space) {
switch (space) {
......
......@@ -1195,9 +1195,12 @@ class Heap {
// all available bytes. Check MaxHeapObjectSize() instead.
size_t Available();
// Returns of size of all objects residing in the heap.
// Returns size of all objects residing in the heap.
V8_EXPORT_PRIVATE size_t SizeOfObjects();
// Returns size of all global handles in the heap.
V8_EXPORT_PRIVATE size_t TotalGlobalHandlesSize();
void UpdateSurvivalStatistics(int start_new_space_size);
inline void IncrementPromotedObjectsSize(size_t object_size) {
......
......@@ -98,6 +98,15 @@ void ConstructJSObject(v8::Isolate* isolate, v8::Global<v8::Object>* global) {
CHECK(!global->IsEmpty());
}
void ConstructJSObject(v8::Isolate* isolate,
v8::TracedGlobal<v8::Object>* traced) {
v8::HandleScope scope(isolate);
v8::Local<v8::Object> object(v8::Object::New(isolate));
CHECK(!object.IsEmpty());
*traced = v8::TracedGlobal<v8::Object>(isolate, object);
CHECK(!traced->IsEmpty());
}
template <typename HandleContainer>
void ConstructJSApiObject(v8::Isolate* isolate, v8::Local<v8::Context> context,
HandleContainer* flag_and_persistent) {
......@@ -667,5 +676,31 @@ TEST(MoveWeakGlobal) {
InvokeMarkSweep();
}
TEST(TotalSizeRegularNode) {
CcTest::InitializeVM();
v8::Isolate* isolate = CcTest::isolate();
Isolate* i_isolate = CcTest::i_isolate();
v8::HandleScope scope(isolate);
v8::Global<v8::Object>* global = new Global<v8::Object>();
CHECK_EQ(i_isolate->global_handles()->TotalSize(), 0);
ConstructJSObject(isolate, global);
CHECK_GT(i_isolate->global_handles()->TotalSize(), 0);
delete global;
}
TEST(TotalSizeTracedNode) {
CcTest::InitializeVM();
v8::Isolate* isolate = CcTest::isolate();
Isolate* i_isolate = CcTest::i_isolate();
v8::HandleScope scope(isolate);
v8::TracedGlobal<v8::Object>* global = new TracedGlobal<v8::Object>();
CHECK_EQ(i_isolate->global_handles()->TotalSize(), 0);
ConstructJSObject(isolate, global);
CHECK_GT(i_isolate->global_handles()->TotalSize(), 0);
delete global;
}
} // namespace internal
} // namespace v8
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