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/profiler/profiler-listener.h" | 5 #include "src/profiler/profiler-listener.h" |
6 | 6 |
7 #include "src/deoptimizer.h" | 7 #include "src/deoptimizer.h" |
8 #include "src/interpreter/source-position-table.h" | |
9 #include "src/profiler/cpu-profiler.h" | 8 #include "src/profiler/cpu-profiler.h" |
10 #include "src/profiler/profile-generator-inl.h" | 9 #include "src/profiler/profile-generator-inl.h" |
| 10 #include "src/source-position-table.h" |
11 | 11 |
12 namespace v8 { | 12 namespace v8 { |
13 namespace internal { | 13 namespace internal { |
14 | 14 |
15 ProfilerListener::ProfilerListener(Isolate* isolate) | 15 ProfilerListener::ProfilerListener(Isolate* isolate) |
16 : function_and_resource_names_(isolate->heap()) {} | 16 : function_and_resource_names_(isolate->heap()) {} |
17 | 17 |
18 ProfilerListener::~ProfilerListener() { | 18 ProfilerListener::~ProfilerListener() { |
19 for (auto code_entry : code_entries_) { | 19 for (auto code_entry : code_entries_) { |
20 delete code_entry; | 20 delete code_entry; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 AbstractCode* abstract_code, | 80 AbstractCode* abstract_code, |
81 SharedFunctionInfo* shared, | 81 SharedFunctionInfo* shared, |
82 Name* script_name, int line, | 82 Name* script_name, int line, |
83 int column) { | 83 int column) { |
84 CodeEventsContainer evt_rec(CodeEventRecord::CODE_CREATION); | 84 CodeEventsContainer evt_rec(CodeEventRecord::CODE_CREATION); |
85 CodeCreateEventRecord* rec = &evt_rec.CodeCreateEventRecord_; | 85 CodeCreateEventRecord* rec = &evt_rec.CodeCreateEventRecord_; |
86 rec->start = abstract_code->address(); | 86 rec->start = abstract_code->address(); |
87 Script* script = Script::cast(shared->script()); | 87 Script* script = Script::cast(shared->script()); |
88 JITLineInfoTable* line_table = NULL; | 88 JITLineInfoTable* line_table = NULL; |
89 if (script) { | 89 if (script) { |
| 90 line_table = new JITLineInfoTable(); |
90 if (abstract_code->IsCode()) { | 91 if (abstract_code->IsCode()) { |
91 Code* code = abstract_code->GetCode(); | 92 Code* code = abstract_code->GetCode(); |
92 int start_position = shared->start_position(); | 93 int start_position = shared->start_position(); |
93 int end_position = shared->end_position(); | 94 int end_position = shared->end_position(); |
94 line_table = new JITLineInfoTable(); | 95 if (code->kind() == Code::FUNCTION) { |
95 for (RelocIterator it(code); !it.done(); it.next()) { | 96 SourcePositionTableIterator it(code->source_position_table()); |
96 RelocInfo* reloc_info = it.rinfo(); | 97 for (; !it.done(); it.Advance()) { |
97 if (!RelocInfo::IsPosition(reloc_info->rmode())) continue; | 98 int line_number = script->GetLineNumber(it.source_position()) + 1; |
98 int position = static_cast<int>(reloc_info->data()); | 99 int pc_offset = it.code_offset() + BytecodeArray::kHeaderSize; |
99 // TODO(alph): in case of inlining the position may correspond | 100 line_table->SetPosition(pc_offset, line_number); |
100 // to an inlined function source code. Do not collect positions | 101 } |
101 // that fall beyond the function source code. There's however a | 102 } else { |
102 // chance the inlined function has similar positions but in another | 103 for (RelocIterator it(code); !it.done(); it.next()) { |
103 // script. So the proper fix is to store script_id in some form | 104 RelocInfo* reloc_info = it.rinfo(); |
104 // along with the inlined function positions. | 105 if (!RelocInfo::IsPosition(reloc_info->rmode())) continue; |
105 if (position < start_position || position >= end_position) continue; | 106 int position = static_cast<int>(reloc_info->data()); |
106 int pc_offset = static_cast<int>(reloc_info->pc() - code->address()); | 107 // TODO(alph): in case of inlining the position may correspond to an |
107 int line_number = script->GetLineNumber(position) + 1; | 108 // inlined function source code. Do not collect positions that fall |
108 line_table->SetPosition(pc_offset, line_number); | 109 // beyond the function source code. There's however a chance the |
| 110 // inlined function has similar positions but in another script. So |
| 111 // the proper fix is to store script_id in some form along with the |
| 112 // inlined function positions. |
| 113 if (position < start_position || position >= end_position) continue; |
| 114 int pc_offset = static_cast<int>(reloc_info->pc() - code->address()); |
| 115 int line_number = script->GetLineNumber(position) + 1; |
| 116 line_table->SetPosition(pc_offset, line_number); |
| 117 } |
109 } | 118 } |
110 } else { | 119 } else { |
111 BytecodeArray* bytecode = abstract_code->GetBytecodeArray(); | 120 BytecodeArray* bytecode = abstract_code->GetBytecodeArray(); |
112 line_table = new JITLineInfoTable(); | 121 SourcePositionTableIterator it(bytecode->source_position_table()); |
113 interpreter::SourcePositionTableIterator it( | |
114 bytecode->source_position_table()); | |
115 for (; !it.done(); it.Advance()) { | 122 for (; !it.done(); it.Advance()) { |
116 int line_number = script->GetLineNumber(it.source_position()) + 1; | 123 int line_number = script->GetLineNumber(it.source_position()) + 1; |
117 int pc_offset = it.bytecode_offset() + BytecodeArray::kHeaderSize; | 124 int pc_offset = it.code_offset() + BytecodeArray::kHeaderSize; |
118 line_table->SetPosition(pc_offset, line_number); | 125 line_table->SetPosition(pc_offset, line_number); |
119 } | 126 } |
120 } | 127 } |
121 } | 128 } |
122 rec->entry = NewCodeEntry( | 129 rec->entry = NewCodeEntry( |
123 tag, GetFunctionName(shared->DebugName()), CodeEntry::kEmptyNamePrefix, | 130 tag, GetFunctionName(shared->DebugName()), CodeEntry::kEmptyNamePrefix, |
124 GetName(InferScriptName(script_name, shared)), line, column, line_table, | 131 GetName(InferScriptName(script_name, shared)), line, column, line_table, |
125 abstract_code->instruction_start()); | 132 abstract_code->instruction_start()); |
126 RecordInliningInfo(rec->entry, abstract_code); | 133 RecordInliningInfo(rec->entry, abstract_code); |
127 RecordDeoptInlinedFrames(rec->entry, abstract_code); | 134 RecordDeoptInlinedFrames(rec->entry, abstract_code); |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 } | 337 } |
331 | 338 |
332 void ProfilerListener::RemoveObserver(CodeEventObserver* observer) { | 339 void ProfilerListener::RemoveObserver(CodeEventObserver* observer) { |
333 auto it = std::find(observers_.begin(), observers_.end(), observer); | 340 auto it = std::find(observers_.begin(), observers_.end(), observer); |
334 if (it == observers_.end()) return; | 341 if (it == observers_.end()) return; |
335 observers_.erase(it); | 342 observers_.erase(it); |
336 } | 343 } |
337 | 344 |
338 } // namespace internal | 345 } // namespace internal |
339 } // namespace v8 | 346 } // namespace v8 |
OLD | NEW |