Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: src/source-position.cc

Issue 2503393002: [cpu-profiler] use new source position information for deoptimization in cpu profiler (Closed)
Patch Set: addressed comment Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/source-position.h ('k') | test/cctest/test-cpu-profiler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/source-position.h" 5 #include "src/source-position.h"
6 #include "src/compilation-info.h" 6 #include "src/compilation-info.h"
7 #include "src/objects-inl.h" 7 #include "src/objects-inl.h"
8 8
9 namespace v8 { 9 namespace v8 {
10 namespace internal { 10 namespace internal {
11 11
12 std::ostream& operator<<(std::ostream& out, const SourcePositionInfo& pos) { 12 std::ostream& operator<<(std::ostream& out, const SourcePositionInfo& pos) {
13 Handle<SharedFunctionInfo> function; 13 Handle<SharedFunctionInfo> function(pos.function);
14 if (pos.function.ToHandle(&function)) { 14 Handle<Script> script(Script::cast(function->script()));
15 Handle<Script> script(Script::cast(function->script())); 15 out << "<";
16 out << "<"; 16 if (script->name()->IsString()) {
17 if (script->name()->IsString()) { 17 out << String::cast(script->name())->ToCString(DISALLOW_NULLS).get();
18 out << String::cast(script->name())->ToCString(DISALLOW_NULLS).get();
19 } else {
20 out << "unknown";
21 }
22 out << ":" << pos.line + 1 << ":" << pos.column + 1 << ">";
23 } else { 18 } else {
24 out << "<unknown:" << pos.position.ScriptOffset() << ">"; 19 out << "unknown";
25 } 20 }
21 out << ":" << pos.line + 1 << ":" << pos.column + 1 << ">";
26 return out; 22 return out;
27 } 23 }
28 24
29 std::ostream& operator<<(std::ostream& out, 25 std::ostream& operator<<(std::ostream& out,
30 const std::vector<SourcePositionInfo>& stack) { 26 const std::vector<SourcePositionInfo>& stack) {
31 out << stack.back(); 27 bool first = true;
32 for (int i = static_cast<int>(stack.size()) - 2; i >= 0; --i) { 28 for (const SourcePositionInfo& pos : stack) {
33 out << " inlined at "; 29 if (!first) out << " inlined at ";
34 out << stack[i]; 30 out << pos;
31 first = false;
35 } 32 }
36 return out; 33 return out;
37 } 34 }
38 35
39 std::ostream& operator<<(std::ostream& out, const SourcePosition& pos) { 36 std::ostream& operator<<(std::ostream& out, const SourcePosition& pos) {
40 if (pos.isInlined()) { 37 if (pos.isInlined()) {
41 out << "<inlined(" << pos.InliningId() << "):"; 38 out << "<inlined(" << pos.InliningId() << "):";
42 } else { 39 } else {
43 out << "<not inlined:"; 40 out << "<not inlined:";
44 } 41 }
45 out << pos.ScriptOffset() << ">"; 42 out << pos.ScriptOffset() << ">";
46 return out; 43 return out;
47 } 44 }
48 45
49 SourcePositionInfo SourcePosition::Info( 46 SourcePositionInfo SourcePosition::Info(
50 Handle<SharedFunctionInfo> function) const { 47 Handle<SharedFunctionInfo> function) const {
48 SourcePositionInfo result(*this, function);
51 Handle<Script> script(Script::cast(function->script())); 49 Handle<Script> script(Script::cast(function->script()));
52 SourcePositionInfo result(*this);
53 Script::PositionInfo pos; 50 Script::PositionInfo pos;
54 if (Script::GetPositionInfo(script, ScriptOffset(), &pos, 51 if (Script::GetPositionInfo(script, ScriptOffset(), &pos,
55 Script::WITH_OFFSET)) { 52 Script::WITH_OFFSET)) {
56 result.line = pos.line; 53 result.line = pos.line;
57 result.column = pos.column; 54 result.column = pos.column;
58 } 55 }
59 result.function = function;
60 return result; 56 return result;
61 } 57 }
62 58
63 std::vector<SourcePositionInfo> SourcePosition::InliningStack( 59 std::vector<SourcePositionInfo> SourcePosition::InliningStack(
64 CompilationInfo* cinfo) const { 60 CompilationInfo* cinfo) const {
65 if (!isInlined()) { 61 SourcePosition pos = *this;
66 return std::vector<SourcePositionInfo>{Info(cinfo->shared_info())}; 62 std::vector<SourcePositionInfo> stack;
67 } else { 63 while (pos.isInlined()) {
68 InliningPosition inl = cinfo->inlined_functions()[InliningId()].position; 64 const auto& inl = cinfo->inlined_functions()[pos.InliningId()];
69 std::vector<SourcePositionInfo> stack = inl.position.InliningStack(cinfo); 65 stack.push_back(pos.Info(inl.shared_info));
70 stack.push_back(Info(cinfo->inlined_functions()[InliningId()].shared_info)); 66 pos = inl.position.position;
71 return stack;
72 } 67 }
68 stack.push_back(pos.Info(cinfo->shared_info()));
69 return stack;
73 } 70 }
74 71
75 std::vector<SourcePositionInfo> SourcePosition::InliningStack( 72 std::vector<SourcePositionInfo> SourcePosition::InliningStack(
76 Handle<Code> code) const { 73 Handle<Code> code) const {
77 Handle<DeoptimizationInputData> deopt_data( 74 Handle<DeoptimizationInputData> deopt_data(
78 DeoptimizationInputData::cast(code->deoptimization_data())); 75 DeoptimizationInputData::cast(code->deoptimization_data()));
79 if (!isInlined()) { 76 SourcePosition pos = *this;
77 std::vector<SourcePositionInfo> stack;
78 while (pos.isInlined()) {
79 InliningPosition inl =
80 deopt_data->InliningPositions()->get(pos.InliningId());
80 Handle<SharedFunctionInfo> function( 81 Handle<SharedFunctionInfo> function(
81 SharedFunctionInfo::cast(deopt_data->SharedFunctionInfo())); 82 deopt_data->GetInlinedFunction(inl.inlined_function_id));
82 83 stack.push_back(pos.Info(function));
83 return std::vector<SourcePositionInfo>{Info(function)}; 84 pos = inl.position;
84 } else {
85 InliningPosition inl = deopt_data->InliningPositions()->get(InliningId());
86 std::vector<SourcePositionInfo> stack = inl.position.InliningStack(code);
87 if (inl.inlined_function_id == -1) {
88 stack.push_back(SourcePositionInfo(*this));
89 } else {
90 Handle<SharedFunctionInfo> function(SharedFunctionInfo::cast(
91 deopt_data->LiteralArray()->get(inl.inlined_function_id)));
92 stack.push_back(Info(function));
93 }
94 return stack;
95 } 85 }
86 Handle<SharedFunctionInfo> function(
87 SharedFunctionInfo::cast(deopt_data->SharedFunctionInfo()));
88 stack.push_back(pos.Info(function));
89 return stack;
96 } 90 }
97 91
98 void SourcePosition::Print(std::ostream& out, 92 void SourcePosition::Print(std::ostream& out,
99 SharedFunctionInfo* function) const { 93 SharedFunctionInfo* function) const {
100 Script* script = Script::cast(function->script()); 94 Script* script = Script::cast(function->script());
101 Object* source_name = script->name(); 95 Object* source_name = script->name();
102 Script::PositionInfo pos; 96 Script::PositionInfo pos;
103 script->GetPositionInfo(ScriptOffset(), &pos, Script::WITH_OFFSET); 97 script->GetPositionInfo(ScriptOffset(), &pos, Script::WITH_OFFSET);
104 out << "<"; 98 out << "<";
105 if (source_name->IsString()) { 99 if (source_name->IsString()) {
(...skipping 11 matching lines...) Expand all
117 DeoptimizationInputData::cast(code->deoptimization_data()); 111 DeoptimizationInputData::cast(code->deoptimization_data());
118 if (!isInlined()) { 112 if (!isInlined()) {
119 SharedFunctionInfo* function( 113 SharedFunctionInfo* function(
120 SharedFunctionInfo::cast(deopt_data->SharedFunctionInfo())); 114 SharedFunctionInfo::cast(deopt_data->SharedFunctionInfo()));
121 Print(out, function); 115 Print(out, function);
122 } else { 116 } else {
123 InliningPosition inl = deopt_data->InliningPositions()->get(InliningId()); 117 InliningPosition inl = deopt_data->InliningPositions()->get(InliningId());
124 if (inl.inlined_function_id == -1) { 118 if (inl.inlined_function_id == -1) {
125 out << *this; 119 out << *this;
126 } else { 120 } else {
127 SharedFunctionInfo* function = SharedFunctionInfo::cast( 121 SharedFunctionInfo* function =
128 deopt_data->LiteralArray()->get(inl.inlined_function_id)); 122 deopt_data->GetInlinedFunction(inl.inlined_function_id);
129 Print(out, function); 123 Print(out, function);
130 } 124 }
131 out << " inlined at "; 125 out << " inlined at ";
132 inl.position.Print(out, code); 126 inl.position.Print(out, code);
133 } 127 }
134 } 128 }
135 129
136 } // namespace internal 130 } // namespace internal
137 } // namespace v8 131 } // namespace v8
OLDNEW
« no previous file with comments | « src/source-position.h ('k') | test/cctest/test-cpu-profiler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698