OLD | NEW |
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 { |
51 Handle<Script> script(Script::cast(function->script())); | 48 Handle<Script> script(Script::cast(function->script())); |
52 SourcePositionInfo result(*this); | 49 SourcePositionInfo result(*this, function); |
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; |
80 Handle<SharedFunctionInfo> function( | 77 std::vector<SourcePositionInfo> stack; |
81 SharedFunctionInfo::cast(deopt_data->SharedFunctionInfo())); | 78 while (pos.isInlined()) { |
82 | 79 InliningPosition inl = |
83 return std::vector<SourcePositionInfo>{Info(function)}; | 80 deopt_data->InliningPositions()->get(pos.InliningId()); |
84 } else { | 81 DCHECK(inl.inlined_function_id != -1); |
85 InliningPosition inl = deopt_data->InliningPositions()->get(InliningId()); | 82 Handle<SharedFunctionInfo> function(SharedFunctionInfo::cast( |
86 std::vector<SourcePositionInfo> stack = inl.position.InliningStack(code); | 83 deopt_data->LiteralArray()->get(inl.inlined_function_id))); |
87 if (inl.inlined_function_id == -1) { | 84 stack.push_back(pos.Info(function)); |
88 stack.push_back(SourcePositionInfo(*this)); | 85 pos = inl.position; |
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 } | 86 } |
| 87 Handle<SharedFunctionInfo> function( |
| 88 SharedFunctionInfo::cast(deopt_data->SharedFunctionInfo())); |
| 89 stack.push_back(pos.Info(function)); |
| 90 return stack; |
96 } | 91 } |
97 | 92 |
98 void SourcePosition::Print(std::ostream& out, | 93 void SourcePosition::Print(std::ostream& out, |
99 SharedFunctionInfo* function) const { | 94 SharedFunctionInfo* function) const { |
100 Script* script = Script::cast(function->script()); | 95 Script* script = Script::cast(function->script()); |
101 Object* source_name = script->name(); | 96 Object* source_name = script->name(); |
102 Script::PositionInfo pos; | 97 Script::PositionInfo pos; |
103 script->GetPositionInfo(ScriptOffset(), &pos, Script::WITH_OFFSET); | 98 script->GetPositionInfo(ScriptOffset(), &pos, Script::WITH_OFFSET); |
104 out << "<"; | 99 out << "<"; |
105 if (source_name->IsString()) { | 100 if (source_name->IsString()) { |
(...skipping 22 matching lines...) Expand all Loading... |
128 deopt_data->LiteralArray()->get(inl.inlined_function_id)); | 123 deopt_data->LiteralArray()->get(inl.inlined_function_id)); |
129 Print(out, function); | 124 Print(out, function); |
130 } | 125 } |
131 out << " inlined at "; | 126 out << " inlined at "; |
132 inl.position.Print(out, code); | 127 inl.position.Print(out, code); |
133 } | 128 } |
134 } | 129 } |
135 | 130 |
136 } // namespace internal | 131 } // namespace internal |
137 } // namespace v8 | 132 } // namespace v8 |
OLD | NEW |