Index: src/compilation-info.cc |
diff --git a/src/compilation-info.cc b/src/compilation-info.cc |
index 5758b41a6b7a7fd7803420f353543073322810b1..4f5985efedf8f22e5d08fcbfd30f61befb7d9062 100644 |
--- a/src/compilation-info.cc |
+++ b/src/compilation-info.cc |
@@ -215,11 +215,94 @@ JSGlobalObject* CompilationInfo::global_object() const { |
return has_global_object() ? native_context()->global_object() : nullptr; |
} |
+bool CompilationInfo::AssignSourceIdToInlining(int inlining_id, |
+ int* source_id) { |
+ if (inlining_id == SourcePosition::kNotInlined) { |
+ // This is a function that is being compiled. Always dump its source. |
+ *source_id = -1; |
Tobias Tebbi
2016/12/15 16:22:01
Is -1 here InlinedFunctionHolder::kSourceNotDumped
|
+ return true; |
+ } |
+ |
+ InlinedFunctionHolder* inl = &inlined_functions_[inlining_id]; |
+ DCHECK_EQ(InlinedFunctionHolder::kSourceNotDumped, inl->source_id); |
+ |
+ // Search for the same function among inlined once and use its source id. |
+ // If its the first time we are inlining this particular function the |
+ // assign a new source id to it and request the source dump. |
+ int max_source_id = InlinedFunctionHolder::kSourceNotDumped; |
+ for (InlinedFunctionHolder& h : inlined_functions_) { |
+ max_source_id = std::max(h.source_id, max_source_id); |
+ if (h.shared_info.is_identical_to(inl->shared_info) && |
+ h.source_id != InlinedFunctionHolder::kSourceNotDumped) { |
+ inl->source_id = *source_id = h.source_id; |
+ return false; |
+ } |
+ } |
+ inl->source_id = *source_id = (max_source_id + 1); |
+ return true; |
+} |
+ |
+void CompilationInfo::TraceInlinedFunction(Handle<SharedFunctionInfo> shared, |
+ SourcePosition position, |
+ int inlining_id) { |
+ if (!FLAG_hydrogen_track_positions) { |
+ return; |
+ } |
+ |
+ int source_id = InlinedFunctionHolder::kSourceNotDumped; |
+ if (AssignSourceIdToInlining(inlining_id, &source_id) && |
+ !shared->script()->IsUndefined(isolate())) { |
+ Handle<Script> script(Script::cast(shared->script()), isolate()); |
+ |
+ if (!script->source()->IsUndefined(isolate())) { |
+ CodeTracer::Scope tracing_scope(isolate()->GetCodeTracer()); |
+ Object* source_name = script->name(); |
+ OFStream os(tracing_scope.file()); |
+ os << "--- FUNCTION SOURCE ("; |
+ if (source_name->IsString()) { |
+ os << String::cast(source_name)->ToCString().get() << ":"; |
+ } |
+ os << shared->DebugName()->ToCString().get() << ") id{"; |
+ os << optimization_id() << "," << source_id << "} start{"; |
+ os << shared->start_position() << "} ---\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"; |
+ } |
+ } |
+ |
+ if (inlining_id != SourcePosition::kNotInlined) { |
+ CodeTracer::Scope tracing_scope(isolate()->GetCodeTracer()); |
+ OFStream os(tracing_scope.file()); |
+ os << "INLINE (" << shared->DebugName()->ToCString().get() << ") id{" |
+ << optimization_id() << "," << source_id << "} AS " << inlining_id |
+ << " AT "; |
+ if (position.IsKnown()) { |
+ os << "<" << position.InliningId() << ":" << position.ScriptOffset() |
+ << ">"; |
+ } else { |
+ os << "<?>"; |
+ } |
+ os << std::endl; |
+ } |
+} |
+ |
void CompilationInfo::SetOptimizing() { |
DCHECK(has_shared_info()); |
SetMode(OPTIMIZE); |
optimization_id_ = isolate()->NextOptimizationId(); |
code_flags_ = Code::KindField::update(code_flags_, Code::OPTIMIZED_FUNCTION); |
+ TraceInlinedFunction(shared_info(), SourcePosition::Unknown(), |
+ SourcePosition::kNotInlined); |
} |
int CompilationInfo::AddInlinedFunction( |
@@ -227,6 +310,7 @@ int CompilationInfo::AddInlinedFunction( |
int id = static_cast<int>(inlined_functions_.size()); |
inlined_functions_.push_back(InlinedFunctionHolder( |
inlined_function, handle(inlined_function->code()), pos)); |
+ TraceInlinedFunction(inlined_function, pos, id); |
return id; |
} |