[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 <petermarshall@chromium.org> Reviewed-by: Clemens Backes <clemensb@chromium.org> Cr-Commit-Position: refs/heads/master@{#72224}
This commit is contained in:
parent
fa6b7a6970
commit
c594a20ed3
@ -5,10 +5,11 @@
|
|||||||
#ifndef V8_PROFILER_PROFILE_GENERATOR_INL_H_
|
#ifndef V8_PROFILER_PROFILE_GENERATOR_INL_H_
|
||||||
#define V8_PROFILER_PROFILE_GENERATOR_INL_H_
|
#define V8_PROFILER_PROFILE_GENERATOR_INL_H_
|
||||||
|
|
||||||
#include "src/profiler/profile-generator.h"
|
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
#include "src/base/lazy-instance.h"
|
||||||
|
#include "src/profiler/profile-generator.h"
|
||||||
|
|
||||||
namespace v8 {
|
namespace v8 {
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
|
||||||
@ -40,6 +41,56 @@ ProfileNode::ProfileNode(ProfileTree* tree, CodeEntry* entry,
|
|||||||
tree_->EnqueueNode(this);
|
tree_->EnqueueNode(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// static
|
||||||
|
inline CodeEntry* CodeEntry::program_entry() {
|
||||||
|
static base::LeakyObject<CodeEntry> 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<CodeEntry> 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<CodeEntry> 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<CodeEntry> 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<CodeEntry> 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 {
|
inline CpuProfileNode::SourceType ProfileNode::source_type() const {
|
||||||
// Handle metadata and VM state code entry types.
|
// Handle metadata and VM state code entry types.
|
||||||
if (entry_ == CodeEntry::program_entry() ||
|
if (entry_ == CodeEntry::program_entry() ||
|
||||||
|
@ -81,62 +81,6 @@ const char* const CodeEntry::kGarbageCollectorEntryName = "(garbage collector)";
|
|||||||
const char* const CodeEntry::kUnresolvedFunctionName = "(unresolved function)";
|
const char* const CodeEntry::kUnresolvedFunctionName = "(unresolved function)";
|
||||||
const char* const CodeEntry::kRootEntryName = "(root)";
|
const char* const CodeEntry::kRootEntryName = "(root)";
|
||||||
|
|
||||||
base::LazyDynamicInstance<CodeEntry, CodeEntry::ProgramEntryCreateTrait>::type
|
|
||||||
CodeEntry::kProgramEntry = LAZY_DYNAMIC_INSTANCE_INITIALIZER;
|
|
||||||
|
|
||||||
base::LazyDynamicInstance<CodeEntry, CodeEntry::IdleEntryCreateTrait>::type
|
|
||||||
CodeEntry::kIdleEntry = LAZY_DYNAMIC_INSTANCE_INITIALIZER;
|
|
||||||
|
|
||||||
base::LazyDynamicInstance<CodeEntry, CodeEntry::GCEntryCreateTrait>::type
|
|
||||||
CodeEntry::kGCEntry = LAZY_DYNAMIC_INSTANCE_INITIALIZER;
|
|
||||||
|
|
||||||
base::LazyDynamicInstance<CodeEntry,
|
|
||||||
CodeEntry::UnresolvedEntryCreateTrait>::type
|
|
||||||
CodeEntry::kUnresolvedEntry = LAZY_DYNAMIC_INSTANCE_INITIALIZER;
|
|
||||||
|
|
||||||
base::LazyDynamicInstance<CodeEntry, CodeEntry::RootEntryCreateTrait>::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 CodeEntry::GetHash() const {
|
||||||
uint32_t hash = ComputeUnseededHash(tag());
|
uint32_t hash = ComputeUnseededHash(tag());
|
||||||
if (script_id_ != v8::UnboundScript::kNoScriptId) {
|
if (script_id_ != v8::UnboundScript::kNoScriptId) {
|
||||||
|
@ -162,21 +162,17 @@ class CodeEntry {
|
|||||||
|
|
||||||
V8_EXPORT_PRIVATE static const char* const kProgramEntryName;
|
V8_EXPORT_PRIVATE static const char* const kProgramEntryName;
|
||||||
V8_EXPORT_PRIVATE static const char* const kIdleEntryName;
|
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
|
// Used to represent frames for which we have no reliable way to
|
||||||
// detect function.
|
// detect function.
|
||||||
V8_EXPORT_PRIVATE static const char* const kUnresolvedFunctionName;
|
V8_EXPORT_PRIVATE static const char* const kUnresolvedFunctionName;
|
||||||
V8_EXPORT_PRIVATE static const char* const kRootEntryName;
|
V8_EXPORT_PRIVATE static const char* const kRootEntryName;
|
||||||
|
|
||||||
V8_INLINE static CodeEntry* program_entry() {
|
inline static CodeEntry* program_entry();
|
||||||
return kProgramEntry.Pointer();
|
inline static CodeEntry* idle_entry();
|
||||||
}
|
inline static CodeEntry* gc_entry();
|
||||||
V8_INLINE static CodeEntry* idle_entry() { return kIdleEntry.Pointer(); }
|
inline static CodeEntry* unresolved_entry();
|
||||||
V8_INLINE static CodeEntry* gc_entry() { return kGCEntry.Pointer(); }
|
inline static CodeEntry* root_entry();
|
||||||
V8_INLINE static CodeEntry* unresolved_entry() {
|
|
||||||
return kUnresolvedEntry.Pointer();
|
|
||||||
}
|
|
||||||
V8_INLINE static CodeEntry* root_entry() { return kRootEntry.Pointer(); }
|
|
||||||
|
|
||||||
// Releases strings owned by this CodeEntry, which may be allocated in the
|
// Releases strings owned by this CodeEntry, which may be allocated in the
|
||||||
// provided StringsStorage instance. This instance is not stored directly
|
// provided StringsStorage instance. This instance is not stored directly
|
||||||
@ -199,33 +195,6 @@ class CodeEntry {
|
|||||||
|
|
||||||
RareData* EnsureRareData();
|
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<CodeEventListener::LogEventsAndTags, 0, 8>;
|
using TagField = base::BitField<CodeEventListener::LogEventsAndTags, 0, 8>;
|
||||||
using BuiltinIdField = base::BitField<Builtins::Name, 8, 20>;
|
using BuiltinIdField = base::BitField<Builtins::Name, 8, 20>;
|
||||||
static_assert(Builtins::builtin_count <= BuiltinIdField::kNumValues,
|
static_assert(Builtins::builtin_count <= BuiltinIdField::kNumValues,
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
#include "src/profiler/symbolizer.h"
|
#include "src/profiler/symbolizer.h"
|
||||||
|
|
||||||
#include "src/execution/vm-state.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/profiler-stats.h"
|
||||||
#include "src/profiler/tick-sample.h"
|
#include "src/profiler/tick-sample.h"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user