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,
script_id_(v8::UnboundScript::kNoScriptId),
position_(0),
bailout_reason_(kEmptyBailoutReason),
deopt_reason_(kNoDeoptReason),
deopt_id_(kNoDeoptimizationId),
line_info_(std::move(line_info)),
instruction_start_(instruction_start) {}
......
......@@ -117,23 +117,26 @@ int CodeEntry::GetSourceLine(int pc_offset) const {
void CodeEntry::AddInlineStack(
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(
int pc_offset) const {
auto it = inline_locations_.find(pc_offset);
return it != inline_locations_.end() ? &it->second : nullptr;
if (!rare_data_) return nullptr;
auto it = rare_data_->inline_locations_.find(pc_offset);
return it != rare_data_->inline_locations_.end() ? &it->second : nullptr;
}
void CodeEntry::AddDeoptInlinedFrames(
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)));
}
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) {
......@@ -148,17 +151,24 @@ CpuProfileDeoptInfo CodeEntry::GetDeoptInfo() {
DCHECK(has_deopt_info());
CpuProfileDeoptInfo info;
info.deopt_reason = deopt_reason_;
DCHECK_NE(kNoDeoptimizationId, deopt_id_);
if (deopt_inlined_frames_.find(deopt_id_) == deopt_inlined_frames_.end()) {
info.deopt_reason = rare_data_->deopt_reason_;
DCHECK_NE(kNoDeoptimizationId, rare_data_->deopt_id_);
if (rare_data_->deopt_inlined_frames_.find(rare_data_->deopt_id_) ==
rare_data_->deopt_inlined_frames_.end()) {
info.stack.push_back(CpuProfileDeoptFrame(
{script_id_, static_cast<size_t>(std::max(0, position()))}));
} else {
info.stack = deopt_inlined_frames_[deopt_id_];
info.stack = rare_data_->deopt_inlined_frames_[rare_data_->deopt_id_];
}
return info;
}
CodeEntry::RareData* CodeEntry::EnsureRareData() {
if (!rare_data_) {
rare_data_.reset(new RareData());
}
return rare_data_.get();
}
void ProfileNode::CollectDeoptInfo(CodeEntry* entry) {
deopt_infos_.push_back(entry->GetDeoptInfo());
......
......@@ -37,7 +37,6 @@ class SourcePositionTable : public Malloced {
DISALLOW_COPY_AND_ASSIGN(SourcePositionTable);
};
class CodeEntry {
public:
// CodeEntry doesn't own name strings, just references them.
......@@ -64,14 +63,19 @@ class CodeEntry {
void set_deopt_info(const char* deopt_reason, int deopt_id) {
DCHECK(!has_deopt_info());
deopt_reason_ = deopt_reason;
deopt_id_ = deopt_id;
RareData* rare_data = EnsureRareData();
rare_data->deopt_reason_ = deopt_reason;
rare_data->deopt_id_ = deopt_id;
}
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() {
deopt_reason_ = kNoDeoptReason;
deopt_id_ = kNoDeoptimizationId;
if (!rare_data_) return;
// 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);
......@@ -120,6 +124,16 @@ class CodeEntry {
}
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 {
static CodeEntry* Create();
};
......@@ -153,13 +167,9 @@ class CodeEntry {
int script_id_;
int position_;
const char* bailout_reason_;
const char* deopt_reason_;
int deopt_id_;
std::unique_ptr<SourcePositionTable> line_info_;
Address instruction_start_;
// 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_;
std::unique_ptr<RareData> rare_data_;
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