Commit fcc1ebb5 authored by Alexei Filippov's avatar Alexei Filippov Committed by Commit Bot

[cpu-profiler] Extract rare used fields of CodeEntry to an optional object.

The RareData objects contain fields that often absent in CodeEntry'es.
They are created as needed when a corresponding field is added.
This reduces CodeEntry size on x64 by 40% from 136 to 80 bytes.

BUG=v8:7719

Change-Id: I1f3c6255aa2f228895e835b536c743396131db31
Reviewed-on: https://chromium-review.googlesource.com/1045885Reviewed-by: 's avatarPeter Marshall <petermarshall@chromium.org>
Commit-Queue: Alexei Filippov <alph@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53039}
parent ca1a502f
...@@ -24,8 +24,6 @@ CodeEntry::CodeEntry(CodeEventListener::LogEventsAndTags tag, const char* name, ...@@ -24,8 +24,6 @@ CodeEntry::CodeEntry(CodeEventListener::LogEventsAndTags tag, const char* name,
script_id_(v8::UnboundScript::kNoScriptId), script_id_(v8::UnboundScript::kNoScriptId),
position_(0), position_(0),
bailout_reason_(kEmptyBailoutReason), bailout_reason_(kEmptyBailoutReason),
deopt_reason_(kNoDeoptReason),
deopt_id_(kNoDeoptimizationId),
line_info_(std::move(line_info)), line_info_(std::move(line_info)),
instruction_start_(instruction_start) {} instruction_start_(instruction_start) {}
......
...@@ -117,23 +117,26 @@ int CodeEntry::GetSourceLine(int pc_offset) const { ...@@ -117,23 +117,26 @@ int CodeEntry::GetSourceLine(int pc_offset) const {
void CodeEntry::AddInlineStack( void CodeEntry::AddInlineStack(
int pc_offset, std::vector<std::unique_ptr<CodeEntry>> inline_stack) { int pc_offset, std::vector<std::unique_ptr<CodeEntry>> inline_stack) {
inline_locations_.insert(std::make_pair(pc_offset, std::move(inline_stack))); EnsureRareData()->inline_locations_.insert(
std::make_pair(pc_offset, std::move(inline_stack)));
} }
const std::vector<std::unique_ptr<CodeEntry>>* CodeEntry::GetInlineStack( const std::vector<std::unique_ptr<CodeEntry>>* CodeEntry::GetInlineStack(
int pc_offset) const { int pc_offset) const {
auto it = inline_locations_.find(pc_offset); if (!rare_data_) return nullptr;
return it != inline_locations_.end() ? &it->second : nullptr; auto it = rare_data_->inline_locations_.find(pc_offset);
return it != rare_data_->inline_locations_.end() ? &it->second : nullptr;
} }
void CodeEntry::AddDeoptInlinedFrames( void CodeEntry::AddDeoptInlinedFrames(
int deopt_id, std::vector<CpuProfileDeoptFrame> inlined_frames) { int deopt_id, std::vector<CpuProfileDeoptFrame> inlined_frames) {
deopt_inlined_frames_.insert( EnsureRareData()->deopt_inlined_frames_.insert(
std::make_pair(deopt_id, std::move(inlined_frames))); std::make_pair(deopt_id, std::move(inlined_frames)));
} }
bool CodeEntry::HasDeoptInlinedFramesFor(int deopt_id) const { bool CodeEntry::HasDeoptInlinedFramesFor(int deopt_id) const {
return deopt_inlined_frames_.find(deopt_id) != deopt_inlined_frames_.end(); return rare_data_ && rare_data_->deopt_inlined_frames_.find(deopt_id) !=
rare_data_->deopt_inlined_frames_.end();
} }
void CodeEntry::FillFunctionInfo(SharedFunctionInfo* shared) { void CodeEntry::FillFunctionInfo(SharedFunctionInfo* shared) {
...@@ -148,17 +151,24 @@ CpuProfileDeoptInfo CodeEntry::GetDeoptInfo() { ...@@ -148,17 +151,24 @@ CpuProfileDeoptInfo CodeEntry::GetDeoptInfo() {
DCHECK(has_deopt_info()); DCHECK(has_deopt_info());
CpuProfileDeoptInfo info; CpuProfileDeoptInfo info;
info.deopt_reason = deopt_reason_; info.deopt_reason = rare_data_->deopt_reason_;
DCHECK_NE(kNoDeoptimizationId, deopt_id_); DCHECK_NE(kNoDeoptimizationId, rare_data_->deopt_id_);
if (deopt_inlined_frames_.find(deopt_id_) == deopt_inlined_frames_.end()) { if (rare_data_->deopt_inlined_frames_.find(rare_data_->deopt_id_) ==
rare_data_->deopt_inlined_frames_.end()) {
info.stack.push_back(CpuProfileDeoptFrame( info.stack.push_back(CpuProfileDeoptFrame(
{script_id_, static_cast<size_t>(std::max(0, position()))})); {script_id_, static_cast<size_t>(std::max(0, position()))}));
} else { } else {
info.stack = deopt_inlined_frames_[deopt_id_]; info.stack = rare_data_->deopt_inlined_frames_[rare_data_->deopt_id_];
} }
return info; return info;
} }
CodeEntry::RareData* CodeEntry::EnsureRareData() {
if (!rare_data_) {
rare_data_.reset(new RareData());
}
return rare_data_.get();
}
void ProfileNode::CollectDeoptInfo(CodeEntry* entry) { void ProfileNode::CollectDeoptInfo(CodeEntry* entry) {
deopt_infos_.push_back(entry->GetDeoptInfo()); deopt_infos_.push_back(entry->GetDeoptInfo());
......
...@@ -37,7 +37,6 @@ class SourcePositionTable : public Malloced { ...@@ -37,7 +37,6 @@ class SourcePositionTable : public Malloced {
DISALLOW_COPY_AND_ASSIGN(SourcePositionTable); DISALLOW_COPY_AND_ASSIGN(SourcePositionTable);
}; };
class CodeEntry { class CodeEntry {
public: public:
// CodeEntry doesn't own name strings, just references them. // CodeEntry doesn't own name strings, just references them.
...@@ -64,14 +63,19 @@ class CodeEntry { ...@@ -64,14 +63,19 @@ class CodeEntry {
void set_deopt_info(const char* deopt_reason, int deopt_id) { void set_deopt_info(const char* deopt_reason, int deopt_id) {
DCHECK(!has_deopt_info()); DCHECK(!has_deopt_info());
deopt_reason_ = deopt_reason; RareData* rare_data = EnsureRareData();
deopt_id_ = deopt_id; rare_data->deopt_reason_ = deopt_reason;
rare_data->deopt_id_ = deopt_id;
} }
CpuProfileDeoptInfo GetDeoptInfo(); CpuProfileDeoptInfo GetDeoptInfo();
bool has_deopt_info() const { return deopt_id_ != kNoDeoptimizationId; } bool has_deopt_info() const {
return rare_data_ && rare_data_->deopt_id_ != kNoDeoptimizationId;
}
void clear_deopt_info() { void clear_deopt_info() {
deopt_reason_ = kNoDeoptReason; if (!rare_data_) return;
deopt_id_ = kNoDeoptimizationId; // TODO(alph): Clear rare_data_ if that was the only field in use.
rare_data_->deopt_reason_ = kNoDeoptReason;
rare_data_->deopt_id_ = kNoDeoptimizationId;
} }
void FillFunctionInfo(SharedFunctionInfo* shared); void FillFunctionInfo(SharedFunctionInfo* shared);
...@@ -120,6 +124,16 @@ class CodeEntry { ...@@ -120,6 +124,16 @@ class CodeEntry {
} }
private: private:
struct RareData {
const char* deopt_reason_ = kNoDeoptReason;
int deopt_id_ = kNoDeoptimizationId;
// Should be an unordered_map, but it doesn't currently work on Win & MacOS.
std::map<int, std::vector<std::unique_ptr<CodeEntry>>> inline_locations_;
std::map<int, std::vector<CpuProfileDeoptFrame>> deopt_inlined_frames_;
};
RareData* EnsureRareData();
struct ProgramEntryCreateTrait { struct ProgramEntryCreateTrait {
static CodeEntry* Create(); static CodeEntry* Create();
}; };
...@@ -153,13 +167,9 @@ class CodeEntry { ...@@ -153,13 +167,9 @@ class CodeEntry {
int script_id_; int script_id_;
int position_; int position_;
const char* bailout_reason_; const char* bailout_reason_;
const char* deopt_reason_;
int deopt_id_;
std::unique_ptr<SourcePositionTable> line_info_; std::unique_ptr<SourcePositionTable> line_info_;
Address instruction_start_; Address instruction_start_;
// Should be an unordered_map, but it doesn't currently work on Win & MacOS. std::unique_ptr<RareData> rare_data_;
std::map<int, std::vector<std::unique_ptr<CodeEntry>>> inline_locations_;
std::map<int, std::vector<CpuProfileDeoptFrame>> deopt_inlined_frames_;
DISALLOW_COPY_AND_ASSIGN(CodeEntry); DISALLOW_COPY_AND_ASSIGN(CodeEntry);
}; };
......
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