From c594a20ed3b15fbeed0c0051eac290cc90069207 Mon Sep 17 00:00:00 2001 From: Peter Marshall Date: Thu, 21 Jan 2021 13:48:09 +0100 Subject: [PATCH] [cpu-profiler] Use base::LeakyObject for static CodeEntry objects This is preferred over the older LazyInstance based stuff, and has a lot less boilerplate and is easier to follow. Bug: v8:8600 Change-Id: I7c5c5ae04c064b0fc598dc01f1ed5442dc21a17b Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2640475 Commit-Queue: Peter Marshall Reviewed-by: Clemens Backes Cr-Commit-Position: refs/heads/master@{#72224} --- src/profiler/profile-generator-inl.h | 55 ++++++++++++++++++++++++++- src/profiler/profile-generator.cc | 56 ---------------------------- src/profiler/profile-generator.h | 43 +++------------------ src/profiler/symbolizer.cc | 2 +- 4 files changed, 60 insertions(+), 96 deletions(-) diff --git a/src/profiler/profile-generator-inl.h b/src/profiler/profile-generator-inl.h index a9a6de016d..3d7fe520d4 100644 --- a/src/profiler/profile-generator-inl.h +++ b/src/profiler/profile-generator-inl.h @@ -5,10 +5,11 @@ #ifndef V8_PROFILER_PROFILE_GENERATOR_INL_H_ #define V8_PROFILER_PROFILE_GENERATOR_INL_H_ -#include "src/profiler/profile-generator.h" - #include +#include "src/base/lazy-instance.h" +#include "src/profiler/profile-generator.h" + namespace v8 { namespace internal { @@ -40,6 +41,56 @@ ProfileNode::ProfileNode(ProfileTree* tree, CodeEntry* entry, tree_->EnqueueNode(this); } +// static +inline CodeEntry* CodeEntry::program_entry() { + static base::LeakyObject kProgramEntry( + CodeEventListener::FUNCTION_TAG, CodeEntry::kProgramEntryName, + CodeEntry::kEmptyResourceName, v8::CpuProfileNode::kNoLineNumberInfo, + v8::CpuProfileNode::kNoColumnNumberInfo, nullptr, false, + CodeEntry::CodeType::OTHER); + return kProgramEntry.get(); +} + +// static +inline CodeEntry* CodeEntry::idle_entry() { + static base::LeakyObject kIdleEntry( + CodeEventListener::FUNCTION_TAG, CodeEntry::kIdleEntryName, + CodeEntry::kEmptyResourceName, v8::CpuProfileNode::kNoLineNumberInfo, + v8::CpuProfileNode::kNoColumnNumberInfo, nullptr, false, + CodeEntry::CodeType::OTHER); + return kIdleEntry.get(); +} + +// static +inline CodeEntry* CodeEntry::gc_entry() { + static base::LeakyObject kGcEntry( + CodeEventListener::BUILTIN_TAG, CodeEntry::kGarbageCollectorEntryName, + CodeEntry::kEmptyResourceName, v8::CpuProfileNode::kNoLineNumberInfo, + v8::CpuProfileNode::kNoColumnNumberInfo, nullptr, false, + CodeEntry::CodeType::OTHER); + return kGcEntry.get(); +} + +// static +inline CodeEntry* CodeEntry::unresolved_entry() { + static base::LeakyObject kUnresolvedEntry( + CodeEventListener::FUNCTION_TAG, CodeEntry::kUnresolvedFunctionName, + CodeEntry::kEmptyResourceName, v8::CpuProfileNode::kNoLineNumberInfo, + v8::CpuProfileNode::kNoColumnNumberInfo, nullptr, false, + CodeEntry::CodeType::OTHER); + return kUnresolvedEntry.get(); +} + +// static +inline CodeEntry* CodeEntry::root_entry() { + static base::LeakyObject kRootEntry( + CodeEventListener::FUNCTION_TAG, CodeEntry::kRootEntryName, + CodeEntry::kEmptyResourceName, v8::CpuProfileNode::kNoLineNumberInfo, + v8::CpuProfileNode::kNoColumnNumberInfo, nullptr, false, + CodeEntry::CodeType::OTHER); + return kRootEntry.get(); +} + inline CpuProfileNode::SourceType ProfileNode::source_type() const { // Handle metadata and VM state code entry types. if (entry_ == CodeEntry::program_entry() || diff --git a/src/profiler/profile-generator.cc b/src/profiler/profile-generator.cc index be5bb27e14..614e6ca14c 100644 --- a/src/profiler/profile-generator.cc +++ b/src/profiler/profile-generator.cc @@ -81,62 +81,6 @@ const char* const CodeEntry::kGarbageCollectorEntryName = "(garbage collector)"; const char* const CodeEntry::kUnresolvedFunctionName = "(unresolved function)"; const char* const CodeEntry::kRootEntryName = "(root)"; -base::LazyDynamicInstance::type - CodeEntry::kProgramEntry = LAZY_DYNAMIC_INSTANCE_INITIALIZER; - -base::LazyDynamicInstance::type - CodeEntry::kIdleEntry = LAZY_DYNAMIC_INSTANCE_INITIALIZER; - -base::LazyDynamicInstance::type - CodeEntry::kGCEntry = LAZY_DYNAMIC_INSTANCE_INITIALIZER; - -base::LazyDynamicInstance::type - CodeEntry::kUnresolvedEntry = LAZY_DYNAMIC_INSTANCE_INITIALIZER; - -base::LazyDynamicInstance::type - CodeEntry::kRootEntry = LAZY_DYNAMIC_INSTANCE_INITIALIZER; - -CodeEntry* CodeEntry::ProgramEntryCreateTrait::Create() { - return new CodeEntry( - CodeEventListener::FUNCTION_TAG, CodeEntry::kProgramEntryName, - CodeEntry::kEmptyResourceName, v8::CpuProfileNode::kNoLineNumberInfo, - v8::CpuProfileNode::kNoColumnNumberInfo, nullptr, false, - CodeEntry::CodeType::OTHER); -} - -CodeEntry* CodeEntry::IdleEntryCreateTrait::Create() { - return new CodeEntry(CodeEventListener::FUNCTION_TAG, - CodeEntry::kIdleEntryName, CodeEntry::kEmptyResourceName, - v8::CpuProfileNode::kNoLineNumberInfo, - v8::CpuProfileNode::kNoColumnNumberInfo, nullptr, false, - CodeEntry::CodeType::OTHER); -} - -CodeEntry* CodeEntry::GCEntryCreateTrait::Create() { - return new CodeEntry( - CodeEventListener::BUILTIN_TAG, CodeEntry::kGarbageCollectorEntryName, - CodeEntry::kEmptyResourceName, v8::CpuProfileNode::kNoLineNumberInfo, - v8::CpuProfileNode::kNoColumnNumberInfo, nullptr, false, - CodeEntry::CodeType::OTHER); -} - -CodeEntry* CodeEntry::UnresolvedEntryCreateTrait::Create() { - return new CodeEntry( - CodeEventListener::FUNCTION_TAG, CodeEntry::kUnresolvedFunctionName, - CodeEntry::kEmptyResourceName, v8::CpuProfileNode::kNoLineNumberInfo, - v8::CpuProfileNode::kNoColumnNumberInfo, nullptr, false, - CodeEntry::CodeType::OTHER); -} - -CodeEntry* CodeEntry::RootEntryCreateTrait::Create() { - return new CodeEntry(CodeEventListener::FUNCTION_TAG, - CodeEntry::kRootEntryName, CodeEntry::kEmptyResourceName, - v8::CpuProfileNode::kNoLineNumberInfo, - v8::CpuProfileNode::kNoColumnNumberInfo, nullptr, false, - CodeEntry::CodeType::OTHER); -} - uint32_t CodeEntry::GetHash() const { uint32_t hash = ComputeUnseededHash(tag()); if (script_id_ != v8::UnboundScript::kNoScriptId) { diff --git a/src/profiler/profile-generator.h b/src/profiler/profile-generator.h index 1dc823961b..26d7ee1c3f 100644 --- a/src/profiler/profile-generator.h +++ b/src/profiler/profile-generator.h @@ -162,21 +162,17 @@ class CodeEntry { V8_EXPORT_PRIVATE static const char* const kProgramEntryName; V8_EXPORT_PRIVATE static const char* const kIdleEntryName; - static const char* const kGarbageCollectorEntryName; + V8_EXPORT_PRIVATE static const char* const kGarbageCollectorEntryName; // Used to represent frames for which we have no reliable way to // detect function. V8_EXPORT_PRIVATE static const char* const kUnresolvedFunctionName; V8_EXPORT_PRIVATE static const char* const kRootEntryName; - V8_INLINE static CodeEntry* program_entry() { - return kProgramEntry.Pointer(); - } - V8_INLINE static CodeEntry* idle_entry() { return kIdleEntry.Pointer(); } - V8_INLINE static CodeEntry* gc_entry() { return kGCEntry.Pointer(); } - V8_INLINE static CodeEntry* unresolved_entry() { - return kUnresolvedEntry.Pointer(); - } - V8_INLINE static CodeEntry* root_entry() { return kRootEntry.Pointer(); } + inline static CodeEntry* program_entry(); + inline static CodeEntry* idle_entry(); + inline static CodeEntry* gc_entry(); + inline static CodeEntry* unresolved_entry(); + inline static CodeEntry* root_entry(); // Releases strings owned by this CodeEntry, which may be allocated in the // provided StringsStorage instance. This instance is not stored directly @@ -199,33 +195,6 @@ class CodeEntry { RareData* EnsureRareData(); - struct V8_EXPORT_PRIVATE ProgramEntryCreateTrait { - static CodeEntry* Create(); - }; - struct V8_EXPORT_PRIVATE IdleEntryCreateTrait { - static CodeEntry* Create(); - }; - struct V8_EXPORT_PRIVATE GCEntryCreateTrait { - static CodeEntry* Create(); - }; - struct V8_EXPORT_PRIVATE UnresolvedEntryCreateTrait { - static CodeEntry* Create(); - }; - struct V8_EXPORT_PRIVATE RootEntryCreateTrait { - static CodeEntry* Create(); - }; - - V8_EXPORT_PRIVATE static base::LazyDynamicInstance< - CodeEntry, ProgramEntryCreateTrait>::type kProgramEntry; - V8_EXPORT_PRIVATE static base::LazyDynamicInstance< - CodeEntry, IdleEntryCreateTrait>::type kIdleEntry; - V8_EXPORT_PRIVATE static base::LazyDynamicInstance< - CodeEntry, GCEntryCreateTrait>::type kGCEntry; - V8_EXPORT_PRIVATE static base::LazyDynamicInstance< - CodeEntry, UnresolvedEntryCreateTrait>::type kUnresolvedEntry; - V8_EXPORT_PRIVATE static base::LazyDynamicInstance< - CodeEntry, RootEntryCreateTrait>::type kRootEntry; - using TagField = base::BitField; using BuiltinIdField = base::BitField; static_assert(Builtins::builtin_count <= BuiltinIdField::kNumValues, diff --git a/src/profiler/symbolizer.cc b/src/profiler/symbolizer.cc index ca6eb269fa..708b9289fc 100644 --- a/src/profiler/symbolizer.cc +++ b/src/profiler/symbolizer.cc @@ -5,7 +5,7 @@ #include "src/profiler/symbolizer.h" #include "src/execution/vm-state.h" -#include "src/profiler/profile-generator.h" +#include "src/profiler/profile-generator-inl.h" #include "src/profiler/profiler-stats.h" #include "src/profiler/tick-sample.h"