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/profiler/cpu-profiler.h" | 8 #include "src/profiler/cpu-profiler.h" |
9 #include "src/profiler/profile-generator-inl.h" | 9 #include "src/profiler/profile-generator-inl.h" |
10 #include "src/source-position-table.h" | 10 #include "src/source-position-table.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 line_table = new JITLineInfoTable(); |
91 if (abstract_code->IsCode()) { | 91 if (abstract_code->IsCode()) { |
92 Code* code = abstract_code->GetCode(); | 92 Code* code = abstract_code->GetCode(); |
93 if (code->kind() == Code::FUNCTION) { | 93 int start_position = shared->start_position(); |
94 SourcePositionTableIterator it(code->source_position_table()); | 94 int end_position = shared->end_position(); |
95 for (; !it.done(); it.Advance()) { | 95 if (code->kind() == Code::FUNCTION || |
| 96 (code->is_optimized_code() && !code->is_turbofanned())) { |
| 97 for (SourcePositionTableIterator it(code->source_position_table()); |
| 98 !it.done(); it.Advance()) { |
| 99 int position = it.source_position(); |
| 100 // TODO(alph): in case of inlining the position may correspond to an |
| 101 // inlined function source code. Do not collect positions that fall |
| 102 // beyond the function source code. There's however a chance the |
| 103 // inlined function has similar positions but in another script. So |
| 104 // the proper fix is to store script_id in some form along with the |
| 105 // inlined function positions. |
| 106 if (position < start_position || position >= end_position) continue; |
96 int line_number = script->GetLineNumber(it.source_position()) + 1; | 107 int line_number = script->GetLineNumber(it.source_position()) + 1; |
97 int pc_offset = it.code_offset() + Code::kHeaderSize; | 108 int pc_offset = it.code_offset() + Code::kHeaderSize; |
98 line_table->SetPosition(pc_offset, line_number); | 109 line_table->SetPosition(pc_offset, line_number); |
99 } | 110 } |
100 } else { | 111 } else { |
101 int start_position = shared->start_position(); | |
102 int end_position = shared->end_position(); | |
103 for (RelocIterator it(code); !it.done(); it.next()) { | 112 for (RelocIterator it(code); !it.done(); it.next()) { |
104 RelocInfo* reloc_info = it.rinfo(); | 113 RelocInfo* reloc_info = it.rinfo(); |
105 if (!RelocInfo::IsPosition(reloc_info->rmode())) continue; | 114 if (!RelocInfo::IsPosition(reloc_info->rmode())) continue; |
106 int position = static_cast<int>(reloc_info->data()); | 115 int position = static_cast<int>(reloc_info->data()); |
107 // TODO(alph): in case of inlining the position may correspond to an | 116 // TODO(alph): in case of inlining the position may correspond to an |
108 // inlined function source code. Do not collect positions that fall | 117 // inlined function source code. Do not collect positions that fall |
109 // beyond the function source code. There's however a chance the | 118 // beyond the function source code. There's however a chance the |
110 // inlined function has similar positions but in another script. So | 119 // 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 | 120 // the proper fix is to store script_id in some form along with the |
112 // inlined function positions. | 121 // inlined function positions. |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 } | 346 } |
338 | 347 |
339 void ProfilerListener::RemoveObserver(CodeEventObserver* observer) { | 348 void ProfilerListener::RemoveObserver(CodeEventObserver* observer) { |
340 auto it = std::find(observers_.begin(), observers_.end(), observer); | 349 auto it = std::find(observers_.begin(), observers_.end(), observer); |
341 if (it == observers_.end()) return; | 350 if (it == observers_.end()) return; |
342 observers_.erase(it); | 351 observers_.erase(it); |
343 } | 352 } |
344 | 353 |
345 } // namespace internal | 354 } // namespace internal |
346 } // namespace v8 | 355 } // namespace v8 |
OLD | NEW |