From 23dd8ef207628b7b1e8fca8cffbc2a286fb46bdf Mon Sep 17 00:00:00 2001 From: Franziska Hinkelmann Date: Fri, 2 Feb 2018 13:49:52 +0100 Subject: [PATCH] [cpu-profiler] Use unique pointer for line info Change-Id: Ia1289985fa715ce4de66bec91675279c203afa36 Reviewed-on: https://chromium-review.googlesource.com/897811 Reviewed-by: Peter Marshall Reviewed-by: Clemens Hammacher Commit-Queue: Franziska Hinkelmann Cr-Commit-Position: refs/heads/master@{#51091} --- src/profiler/profile-generator-inl.h | 5 +++-- src/profiler/profile-generator.cc | 5 ----- src/profiler/profile-generator.h | 7 +++---- src/profiler/profiler-listener.cc | 13 +++++++------ src/profiler/profiler-listener.h | 2 +- 5 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/profiler/profile-generator-inl.h b/src/profiler/profile-generator-inl.h index 5a7017ad49..970d462937 100644 --- a/src/profiler/profile-generator-inl.h +++ b/src/profiler/profile-generator-inl.h @@ -13,7 +13,8 @@ namespace internal { CodeEntry::CodeEntry(CodeEventListener::LogEventsAndTags tag, const char* name, const char* name_prefix, const char* resource_name, int line_number, int column_number, - JITLineInfoTable* line_info, Address instruction_start) + std::unique_ptr line_info, + Address instruction_start) : bit_field_(TagField::encode(tag) | BuiltinIdField::encode(Builtins::builtin_count)), name_prefix_(name_prefix), @@ -26,7 +27,7 @@ CodeEntry::CodeEntry(CodeEventListener::LogEventsAndTags tag, const char* name, bailout_reason_(kEmptyBailoutReason), deopt_reason_(kNoDeoptReason), deopt_id_(kNoDeoptimizationId), - line_info_(line_info), + line_info_(std::move(line_info)), instruction_start_(instruction_start) {} ProfileNode::ProfileNode(ProfileTree* tree, CodeEntry* entry, diff --git a/src/profiler/profile-generator.cc b/src/profiler/profile-generator.cc index 4ab65416b1..b9ecbb8288 100644 --- a/src/profiler/profile-generator.cc +++ b/src/profiler/profile-generator.cc @@ -85,11 +85,6 @@ CodeEntry* CodeEntry::UnresolvedEntryCreateTrait::Create() { CodeEntry::kUnresolvedFunctionName); } -CodeEntry::~CodeEntry() { - delete line_info_; -} - - uint32_t CodeEntry::GetHash() const { uint32_t hash = ComputeIntegerHash(tag()); if (script_id_ != v8::UnboundScript::kNoScriptId) { diff --git a/src/profiler/profile-generator.h b/src/profiler/profile-generator.h index 86664932f4..bb86bfe7a4 100644 --- a/src/profiler/profile-generator.h +++ b/src/profiler/profile-generator.h @@ -47,9 +47,8 @@ class CodeEntry { const char* resource_name = CodeEntry::kEmptyResourceName, int line_number = v8::CpuProfileNode::kNoLineNumberInfo, int column_number = v8::CpuProfileNode::kNoColumnNumberInfo, - JITLineInfoTable* line_info = nullptr, + std::unique_ptr line_info = nullptr, Address instruction_start = nullptr); - ~CodeEntry(); const char* name_prefix() const { return name_prefix_; } bool has_name_prefix() const { return name_prefix_[0] != '\0'; } @@ -57,7 +56,7 @@ class CodeEntry { const char* resource_name() const { return resource_name_; } int line_number() const { return line_number_; } int column_number() const { return column_number_; } - const JITLineInfoTable* line_info() const { return line_info_; } + const JITLineInfoTable* line_info() const { return line_info_.get(); } int script_id() const { return script_id_; } void set_script_id(int script_id) { script_id_ = script_id; } int position() const { return position_; } @@ -162,7 +161,7 @@ class CodeEntry { const char* bailout_reason_; const char* deopt_reason_; int deopt_id_; - JITLineInfoTable* line_info_; + std::unique_ptr line_info_; Address instruction_start_; // Should be an unordered_map, but it doesn't currently work on Win & MacOS. std::map>> inline_locations_; diff --git a/src/profiler/profiler-listener.cc b/src/profiler/profiler-listener.cc index 052b8fa2b0..0c70986e3e 100644 --- a/src/profiler/profiler-listener.cc +++ b/src/profiler/profiler-listener.cc @@ -81,10 +81,10 @@ void ProfilerListener::CodeCreateEvent(CodeEventListener::LogEventsAndTags tag, CodeEventsContainer evt_rec(CodeEventRecord::CODE_CREATION); CodeCreateEventRecord* rec = &evt_rec.CodeCreateEventRecord_; rec->start = abstract_code->address(); - JITLineInfoTable* line_table = nullptr; + std::unique_ptr line_table; if (shared->script()->IsScript()) { Script* script = Script::cast(shared->script()); - line_table = new JITLineInfoTable(); + line_table.reset(new JITLineInfoTable()); int offset = abstract_code->IsCode() ? Code::kHeaderSize : BytecodeArray::kHeaderSize; for (SourcePositionTableIterator it(abstract_code->source_position_table()); @@ -101,8 +101,8 @@ void ProfilerListener::CodeCreateEvent(CodeEventListener::LogEventsAndTags tag, } rec->entry = NewCodeEntry( tag, GetFunctionName(shared->DebugName()), CodeEntry::kEmptyNamePrefix, - GetName(InferScriptName(script_name, shared)), line, column, line_table, - abstract_code->instruction_start()); + GetName(InferScriptName(script_name, shared)), line, column, + std::move(line_table), abstract_code->instruction_start()); RecordInliningInfo(rec->entry, abstract_code); RecordDeoptInlinedFrames(rec->entry, abstract_code); rec->entry->FillFunctionInfo(shared); @@ -276,10 +276,11 @@ void ProfilerListener::RecordDeoptInlinedFrames(CodeEntry* entry, CodeEntry* ProfilerListener::NewCodeEntry( CodeEventListener::LogEventsAndTags tag, const char* name, const char* name_prefix, const char* resource_name, int line_number, - int column_number, JITLineInfoTable* line_info, Address instruction_start) { + int column_number, std::unique_ptr line_info, + Address instruction_start) { std::unique_ptr code_entry = base::make_unique( tag, name, name_prefix, resource_name, line_number, column_number, - line_info, instruction_start); + std::move(line_info), instruction_start); CodeEntry* raw_code_entry = code_entry.get(); code_entries_.push_back(std::move(code_entry)); return raw_code_entry; diff --git a/src/profiler/profiler-listener.h b/src/profiler/profiler-listener.h index c111bf81c4..8605a89391 100644 --- a/src/profiler/profiler-listener.h +++ b/src/profiler/profiler-listener.h @@ -54,7 +54,7 @@ class ProfilerListener : public CodeEventListener { const char* resource_name = CodeEntry::kEmptyResourceName, int line_number = v8::CpuProfileNode::kNoLineNumberInfo, int column_number = v8::CpuProfileNode::kNoColumnNumberInfo, - JITLineInfoTable* line_info = nullptr, + std::unique_ptr line_info = nullptr, Address instruction_start = nullptr); void AddObserver(CodeEventObserver* observer);