CpuProfiler: simplify inlined function info magic.
I did some investigation and found that in the most cases the old schema with the separate List for functions and inlines gives us no memory benefits because more frequently we inlines different functions into parent function. So the plain schema wins a tens or even hundreds bytes a few thousand times. The only drawback is that we will print the inlined body the each time when we inline it. But is not a problem because it happens only under FLAG_hydrogen_track_positions. Also I added script_id to the structure, so it could be used later by cpu-profiler. BUG=chromium:452067 LOG=n Review URL: https://codereview.chromium.org/996153003 Cr-Commit-Position: refs/heads/master@{#27134}
This commit is contained in:
parent
ee4f1bd81d
commit
df9e6fe329
@ -118,10 +118,8 @@ void CompilationInfo::Initialize(Isolate* isolate,
|
||||
? new List<OffsetRange>(2) : NULL;
|
||||
if (FLAG_hydrogen_track_positions) {
|
||||
inlined_function_infos_ = new List<InlinedFunctionInfo>(5);
|
||||
inlining_id_to_function_id_ = new List<int>(5);
|
||||
} else {
|
||||
inlined_function_infos_ = NULL;
|
||||
inlining_id_to_function_id_ = NULL;
|
||||
}
|
||||
|
||||
for (int i = 0; i < DependentCode::kGroupCount; i++) {
|
||||
@ -163,7 +161,6 @@ CompilationInfo::~CompilationInfo() {
|
||||
delete deferred_handles_;
|
||||
delete no_frame_ranges_;
|
||||
delete inlined_function_infos_;
|
||||
delete inlining_id_to_function_id_;
|
||||
#ifdef DEBUG
|
||||
// Check that no dependent maps have been added or added dependent maps have
|
||||
// been rolled back or committed.
|
||||
@ -277,52 +274,46 @@ bool CompilationInfo::is_simple_parameter_list() {
|
||||
|
||||
|
||||
int CompilationInfo::TraceInlinedFunction(Handle<SharedFunctionInfo> shared,
|
||||
SourcePosition position) {
|
||||
SourcePosition position,
|
||||
int parent_id) {
|
||||
DCHECK(FLAG_hydrogen_track_positions);
|
||||
|
||||
DCHECK(inlined_function_infos_);
|
||||
DCHECK(inlining_id_to_function_id_);
|
||||
int id = 0;
|
||||
for (; id < inlined_function_infos_->length(); id++) {
|
||||
if (inlined_function_infos_->at(id).shared().is_identical_to(shared)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (id == inlined_function_infos_->length()) {
|
||||
inlined_function_infos_->Add(InlinedFunctionInfo(shared));
|
||||
|
||||
if (!shared->script()->IsUndefined()) {
|
||||
Handle<Script> script(Script::cast(shared->script()));
|
||||
if (!script->source()->IsUndefined()) {
|
||||
CodeTracer::Scope tracing_scope(isolate()->GetCodeTracer());
|
||||
OFStream os(tracing_scope.file());
|
||||
os << "--- FUNCTION SOURCE (" << shared->DebugName()->ToCString().get()
|
||||
<< ") id{" << optimization_id() << "," << id << "} ---\n";
|
||||
{
|
||||
DisallowHeapAllocation no_allocation;
|
||||
int start = shared->start_position();
|
||||
int len = shared->end_position() - start;
|
||||
String::SubStringRange source(String::cast(script->source()), start,
|
||||
len);
|
||||
for (const auto& c : source) {
|
||||
os << AsReversiblyEscapedUC16(c);
|
||||
}
|
||||
int inline_id = inlined_function_infos_->length();
|
||||
InlinedFunctionInfo info(parent_id, position, UnboundScript::kNoScriptId,
|
||||
shared->start_position());
|
||||
if (!shared->script()->IsUndefined()) {
|
||||
Handle<Script> script(Script::cast(shared->script()));
|
||||
info.script_id = script->id()->value();
|
||||
|
||||
if (!script->source()->IsUndefined()) {
|
||||
CodeTracer::Scope tracing_scope(isolate()->GetCodeTracer());
|
||||
OFStream os(tracing_scope.file());
|
||||
os << "--- FUNCTION SOURCE (" << shared->DebugName()->ToCString().get()
|
||||
<< ") id{" << optimization_id() << "," << inline_id << "} ---\n";
|
||||
{
|
||||
DisallowHeapAllocation no_allocation;
|
||||
int start = shared->start_position();
|
||||
int len = shared->end_position() - start;
|
||||
String::SubStringRange source(String::cast(script->source()), start,
|
||||
len);
|
||||
for (const auto& c : source) {
|
||||
os << AsReversiblyEscapedUC16(c);
|
||||
}
|
||||
|
||||
os << "\n--- END ---\n";
|
||||
}
|
||||
|
||||
os << "\n--- END ---\n";
|
||||
}
|
||||
}
|
||||
|
||||
int inline_id = inlining_id_to_function_id_->length();
|
||||
inlining_id_to_function_id_->Add(id);
|
||||
inlined_function_infos_->Add(info);
|
||||
|
||||
if (inline_id != 0) {
|
||||
CodeTracer::Scope tracing_scope(isolate()->GetCodeTracer());
|
||||
OFStream os(tracing_scope.file());
|
||||
os << "INLINE (" << shared->DebugName()->ToCString().get() << ") id{"
|
||||
<< optimization_id() << "," << id << "} AS " << inline_id << " AT "
|
||||
<< position << std::endl;
|
||||
<< optimization_id() << "," << inline_id << "} AS " << inline_id
|
||||
<< " AT " << position << std::endl;
|
||||
}
|
||||
|
||||
return inline_id;
|
||||
|
@ -86,17 +86,19 @@ class SourcePosition {
|
||||
std::ostream& operator<<(std::ostream& os, const SourcePosition& p);
|
||||
|
||||
|
||||
class InlinedFunctionInfo {
|
||||
public:
|
||||
explicit InlinedFunctionInfo(Handle<SharedFunctionInfo> shared)
|
||||
: shared_(shared), start_position_(shared->start_position()) {}
|
||||
struct InlinedFunctionInfo {
|
||||
InlinedFunctionInfo(int parent_id, SourcePosition inline_position,
|
||||
int script_id, int start_position)
|
||||
: parent_id(parent_id),
|
||||
inline_position(inline_position),
|
||||
script_id(script_id),
|
||||
start_position(start_position) {}
|
||||
int parent_id;
|
||||
SourcePosition inline_position;
|
||||
int script_id;
|
||||
int start_position;
|
||||
|
||||
Handle<SharedFunctionInfo> shared() const { return shared_; }
|
||||
int start_position() const { return start_position_; }
|
||||
|
||||
private:
|
||||
Handle<SharedFunctionInfo> shared_;
|
||||
int start_position_;
|
||||
static const int kNoParentId = -1;
|
||||
};
|
||||
|
||||
|
||||
@ -338,11 +340,8 @@ class CompilationInfo {
|
||||
List<InlinedFunctionInfo>* inlined_function_infos() {
|
||||
return inlined_function_infos_;
|
||||
}
|
||||
List<int>* inlining_id_to_function_id() {
|
||||
return inlining_id_to_function_id_;
|
||||
}
|
||||
int TraceInlinedFunction(Handle<SharedFunctionInfo> shared,
|
||||
SourcePosition position);
|
||||
SourcePosition position, int pareint_id);
|
||||
|
||||
Handle<Foreign> object_wrapper() {
|
||||
if (object_wrapper_.is_null()) {
|
||||
@ -450,7 +449,6 @@ class CompilationInfo {
|
||||
|
||||
List<OffsetRange>* no_frame_ranges_;
|
||||
List<InlinedFunctionInfo>* inlined_function_infos_;
|
||||
List<int>* inlining_id_to_function_id_;
|
||||
|
||||
// A copy of shared_info()->opt_count() to avoid handle deref
|
||||
// during graph optimization.
|
||||
|
@ -3452,8 +3452,8 @@ HGraph::HGraph(CompilationInfo* info)
|
||||
HEnvironment(zone_, descriptor.GetEnvironmentParameterCount());
|
||||
} else {
|
||||
if (FLAG_hydrogen_track_positions) {
|
||||
info->TraceInlinedFunction(info->shared_info(),
|
||||
SourcePosition::Unknown());
|
||||
info->TraceInlinedFunction(info->shared_info(), SourcePosition::Unknown(),
|
||||
InlinedFunctionInfo::kNoParentId);
|
||||
}
|
||||
start_environment_ =
|
||||
new(zone_) HEnvironment(NULL, info->scope(), info->closure(), zone_);
|
||||
@ -3487,9 +3487,8 @@ int HGraph::SourcePositionToScriptPosition(SourcePosition pos) {
|
||||
return pos.raw();
|
||||
}
|
||||
|
||||
const int id = info()->inlining_id_to_function_id()->at(pos.inlining_id());
|
||||
return info()->inlined_function_infos()->at(id).start_position() +
|
||||
pos.position();
|
||||
return info()->inlined_function_infos()->at(pos.inlining_id())
|
||||
.start_position + pos.position();
|
||||
}
|
||||
|
||||
|
||||
@ -7922,8 +7921,8 @@ bool HOptimizedGraphBuilder::TryInline(Handle<JSFunction> target,
|
||||
|
||||
int function_id = 0;
|
||||
if (FLAG_hydrogen_track_positions) {
|
||||
function_id =
|
||||
top_info()->TraceInlinedFunction(target_shared, source_position());
|
||||
function_id = top_info()->TraceInlinedFunction(
|
||||
target_shared, source_position(), function_state()->inlining_id());
|
||||
}
|
||||
|
||||
// Save the pending call context. Set up new one for the inlined function.
|
||||
|
Loading…
Reference in New Issue
Block a user