diff options
Diffstat (limited to 'deps/v8/src/profiler/profile-generator.cc')
-rw-r--r-- | deps/v8/src/profiler/profile-generator.cc | 79 |
1 files changed, 34 insertions, 45 deletions
diff --git a/deps/v8/src/profiler/profile-generator.cc b/deps/v8/src/profiler/profile-generator.cc index 93075d4f7c..5ccdb03025 100644 --- a/deps/v8/src/profiler/profile-generator.cc +++ b/deps/v8/src/profiler/profile-generator.cc @@ -157,21 +157,18 @@ bool CodeEntry::IsSameFunctionAs(const CodeEntry* entry) const { line_number_ == entry->line_number_; } - -void CodeEntry::SetBuiltinId(Builtins::Name id) { +void CodeEntry::SetBuiltinId(Builtin id) { bit_field_ = TagField::update(bit_field_, CodeEventListener::BUILTIN_TAG); - bit_field_ = BuiltinIdField::update(bit_field_, id); + bit_field_ = BuiltinField::update(bit_field_, id); } - int CodeEntry::GetSourceLine(int pc_offset) const { if (line_info_) return line_info_->GetSourceLineNumber(pc_offset); return v8::CpuProfileNode::kNoLineNumberInfo; } void CodeEntry::SetInlineStacks( - std::unordered_set<std::unique_ptr<CodeEntry>, Hasher, Equals> - inline_entries, + std::unordered_set<CodeEntry*, Hasher, Equals> inline_entries, std::unordered_map<int, std::vector<CodeEntryAndLineNumber>> inline_stacks) { EnsureRareData()->inline_entries_ = std::move(inline_entries); @@ -233,6 +230,8 @@ CodeEntry::RareData* CodeEntry::EnsureRareData() { } void CodeEntry::ReleaseStrings(StringsStorage& strings) { + DCHECK_EQ(ref_count_, 0UL); + if (name_) { strings.Release(name_); name_ = nullptr; @@ -241,14 +240,6 @@ void CodeEntry::ReleaseStrings(StringsStorage& strings) { strings.Release(resource_name_); resource_name_ = nullptr; } - - if (rare_data_) { - // All inline entries are exclusively owned by the CodeEntry. They'll be - // deallocated when the CodeEntry is deallocated. - for (auto& entry : rare_data_->inline_entries_) { - entry->ReleaseStrings(strings); - } - } } void CodeEntry::print() const { @@ -298,6 +289,10 @@ void CodeEntry::print() const { base::OS::Print("\n"); } +ProfileNode::~ProfileNode() { + if (tree_->code_entries()) tree_->code_entries()->DecRef(entry_); +} + CpuProfileNode::SourceType ProfileNode::source_type() const { // Handle metadata and VM state code entry types. if (entry_ == CodeEntry::program_entry() || @@ -435,10 +430,11 @@ class DeleteNodesCallback { void AfterChildTraversed(ProfileNode*, ProfileNode*) { } }; -ProfileTree::ProfileTree(Isolate* isolate) +ProfileTree::ProfileTree(Isolate* isolate, CodeEntryStorage* storage) : next_node_id_(1), - root_(new ProfileNode(this, CodeEntry::root_entry(), nullptr)), - isolate_(isolate) {} + isolate_(isolate), + code_entries_(storage), + root_(new ProfileNode(this, CodeEntry::root_entry(), nullptr)) {} ProfileTree::~ProfileTree() { DeleteNodesCallback cb; @@ -550,7 +546,7 @@ CpuProfile::CpuProfile(CpuProfiler* profiler, const char* title, options_(options), delegate_(std::move(delegate)), start_time_(base::TimeTicks::HighResolutionNow()), - top_down_(profiler->isolate()), + top_down_(profiler->isolate(), profiler->code_entries()), profiler_(profiler), streaming_next_sample_(0), id_(++last_id_) { @@ -741,31 +737,37 @@ void CpuProfile::Print() const { ProfilerStats::Instance()->Clear(); } -CodeMap::CodeMap(StringsStorage& function_and_resource_names) - : function_and_resource_names_(function_and_resource_names) {} +void CodeEntryStorage::AddRef(CodeEntry* entry) { + if (entry->is_ref_counted()) entry->AddRef(); +} + +void CodeEntryStorage::DecRef(CodeEntry* entry) { + if (entry->is_ref_counted() && entry->DecRef() == 0) { + if (entry->rare_data_) { + for (auto* inline_entry : entry->rare_data_->inline_entries_) { + DecRef(inline_entry); + } + } + entry->ReleaseStrings(function_and_resource_names_); + delete entry; + } +} + +CodeMap::CodeMap(CodeEntryStorage& storage) : code_entries_(storage) {} CodeMap::~CodeMap() { Clear(); } void CodeMap::Clear() { for (auto& slot : code_map_) { if (CodeEntry* entry = slot.second.entry) { - entry->ReleaseStrings(function_and_resource_names_); - delete entry; + code_entries_.DecRef(entry); } else { // We expect all entries in the code mapping to contain a CodeEntry. UNREACHABLE(); } } - // Free all CodeEntry objects that are no longer in the map, but in a profile. - // TODO(acomminos): Remove this deque after we refcount CodeEntry objects. - for (CodeEntry* entry : used_entries_) { - DCHECK(entry->used()); - DeleteCodeEntry(entry); - } - code_map_.clear(); - used_entries_.clear(); } void CodeMap::AddCode(Address addr, CodeEntry* entry, unsigned size) { @@ -777,11 +779,7 @@ bool CodeMap::RemoveCode(CodeEntry* entry) { auto range = code_map_.equal_range(entry->instruction_start()); for (auto i = range.first; i != range.second; ++i) { if (i->second.entry == entry) { - if (!entry->used()) { - DeleteCodeEntry(entry); - } else { - used_entries_.push_back(entry); - } + code_entries_.DecRef(entry); code_map_.erase(i); return true; } @@ -797,11 +795,7 @@ void CodeMap::ClearCodesInRange(Address start, Address end) { } auto right = left; for (; right != code_map_.end() && right->first < end; ++right) { - if (!right->second.entry->used()) { - DeleteCodeEntry(right->second.entry); - } else { - used_entries_.push_back(right->second.entry); - } + code_entries_.DecRef(right->second.entry); } code_map_.erase(left, right); } @@ -844,11 +838,6 @@ void CodeMap::MoveCode(Address from, Address to) { code_map_.erase(range.first, it); } -void CodeMap::DeleteCodeEntry(CodeEntry* entry) { - entry->ReleaseStrings(function_and_resource_names_); - delete entry; -} - void CodeMap::Print() { for (const auto& pair : code_map_) { base::OS::Print("%p %5d %s\n", reinterpret_cast<void*>(pair.first), |