OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 #ifndef V8_PROFILE_GENERATOR_H_ | 5 #ifndef V8_PROFILE_GENERATOR_H_ |
6 #define V8_PROFILE_GENERATOR_H_ | 6 #define V8_PROFILE_GENERATOR_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include "include/v8-profiler.h" | 9 #include "include/v8-profiler.h" |
10 #include "src/allocation.h" | 10 #include "src/allocation.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 | 29 |
30 bool empty() const { return pc_offset_map_.empty(); } | 30 bool empty() const { return pc_offset_map_.empty(); } |
31 | 31 |
32 private: | 32 private: |
33 // pc_offset -> source line | 33 // pc_offset -> source line |
34 typedef std::map<int, int> PcOffsetMap; | 34 typedef std::map<int, int> PcOffsetMap; |
35 PcOffsetMap pc_offset_map_; | 35 PcOffsetMap pc_offset_map_; |
36 DISALLOW_COPY_AND_ASSIGN(JITLineInfoTable); | 36 DISALLOW_COPY_AND_ASSIGN(JITLineInfoTable); |
37 }; | 37 }; |
38 | 38 |
| 39 |
| 40 struct DeoptInfo { |
| 41 const char* deopt_reason; |
| 42 struct Frame { |
| 43 int script_id; |
| 44 int position; |
| 45 }; |
| 46 std::vector<Frame> stack; |
| 47 void AddInlineFrame(int script_id, int position) { |
| 48 Frame frame = {script_id, position}; |
| 49 stack.push_back(frame); |
| 50 } |
| 51 }; |
| 52 |
| 53 |
39 class CodeEntry { | 54 class CodeEntry { |
40 public: | 55 public: |
41 // CodeEntry doesn't own name strings, just references them. | 56 // CodeEntry doesn't own name strings, just references them. |
42 inline CodeEntry(Logger::LogEventsAndTags tag, const char* name, | 57 inline CodeEntry(Logger::LogEventsAndTags tag, const char* name, |
43 const char* name_prefix = CodeEntry::kEmptyNamePrefix, | 58 const char* name_prefix = CodeEntry::kEmptyNamePrefix, |
44 const char* resource_name = CodeEntry::kEmptyResourceName, | 59 const char* resource_name = CodeEntry::kEmptyResourceName, |
45 int line_number = v8::CpuProfileNode::kNoLineNumberInfo, | 60 int line_number = v8::CpuProfileNode::kNoLineNumberInfo, |
46 int column_number = v8::CpuProfileNode::kNoColumnNumberInfo, | 61 int column_number = v8::CpuProfileNode::kNoColumnNumberInfo, |
47 JITLineInfoTable* line_info = NULL, | 62 JITLineInfoTable* line_info = NULL, |
48 Address instruction_start = NULL); | 63 Address instruction_start = NULL); |
49 ~CodeEntry(); | 64 ~CodeEntry(); |
50 | 65 |
51 bool is_js_function() const { return is_js_function_tag(tag()); } | 66 bool is_js_function() const { return is_js_function_tag(tag()); } |
52 const char* name_prefix() const { return name_prefix_; } | 67 const char* name_prefix() const { return name_prefix_; } |
53 bool has_name_prefix() const { return name_prefix_[0] != '\0'; } | 68 bool has_name_prefix() const { return name_prefix_[0] != '\0'; } |
54 const char* name() const { return name_; } | 69 const char* name() const { return name_; } |
55 const char* resource_name() const { return resource_name_; } | 70 const char* resource_name() const { return resource_name_; } |
56 int line_number() const { return line_number_; } | 71 int line_number() const { return line_number_; } |
57 int column_number() const { return column_number_; } | 72 int column_number() const { return column_number_; } |
58 const JITLineInfoTable* line_info() const { return line_info_; } | 73 const JITLineInfoTable* line_info() const { return line_info_; } |
59 int script_id() const { return script_id_; } | 74 int script_id() const { return script_id_; } |
60 void set_script_id(int script_id) { script_id_ = script_id; } | 75 void set_script_id(int script_id) { script_id_ = script_id; } |
61 int position() const { return position_; } | 76 int position() const { return position_; } |
62 void set_position(int position) { position_ = position; } | 77 void set_position(int position) { position_ = position; } |
63 void set_bailout_reason(const char* bailout_reason) { | 78 void set_bailout_reason(const char* bailout_reason) { |
64 bailout_reason_ = bailout_reason; | 79 bailout_reason_ = bailout_reason; |
65 } | 80 } |
66 const char* bailout_reason() const { return bailout_reason_; } | 81 const char* bailout_reason() const { return bailout_reason_; } |
67 | 82 |
68 void set_deopt_info(const char* deopt_reason, SourcePosition position) { | 83 void set_deopt_info(const char* deopt_reason, SourcePosition position, |
| 84 int pc_offset) { |
69 DCHECK(deopt_position_.IsUnknown()); | 85 DCHECK(deopt_position_.IsUnknown()); |
70 deopt_reason_ = deopt_reason; | 86 deopt_reason_ = deopt_reason; |
71 deopt_position_ = position; | 87 deopt_position_ = position; |
| 88 pc_offset_ = pc_offset; |
72 } | 89 } |
| 90 DeoptInfo GetDeoptInfo(); |
73 const char* deopt_reason() const { return deopt_reason_; } | 91 const char* deopt_reason() const { return deopt_reason_; } |
74 SourcePosition deopt_position() const { return deopt_position_; } | 92 SourcePosition deopt_position() const { return deopt_position_; } |
75 bool has_deopt_info() const { return !deopt_position_.IsUnknown(); } | 93 bool has_deopt_info() const { return !deopt_position_.IsUnknown(); } |
76 void clear_deopt_info() { | 94 void clear_deopt_info() { |
77 deopt_reason_ = kNoDeoptReason; | 95 deopt_reason_ = kNoDeoptReason; |
78 deopt_position_ = SourcePosition::Unknown(); | 96 deopt_position_ = SourcePosition::Unknown(); |
79 } | 97 } |
80 | 98 |
81 void FillFunctionInfo(SharedFunctionInfo* shared); | 99 void FillFunctionInfo(SharedFunctionInfo* shared); |
82 | 100 |
83 static inline bool is_js_function_tag(Logger::LogEventsAndTags tag); | 101 static inline bool is_js_function_tag(Logger::LogEventsAndTags tag); |
84 | 102 |
85 List<OffsetRange>* no_frame_ranges() const { return no_frame_ranges_; } | 103 List<OffsetRange>* no_frame_ranges() const { return no_frame_ranges_; } |
86 void set_no_frame_ranges(List<OffsetRange>* ranges) { | 104 void set_no_frame_ranges(List<OffsetRange>* ranges) { |
87 no_frame_ranges_ = ranges; | 105 no_frame_ranges_ = ranges; |
88 } | 106 } |
| 107 void set_inlined_function_infos(std::vector<InlinedFunctionInfo>* infos) { |
| 108 DCHECK(!inlined_function_infos_); |
| 109 inlined_function_infos_ = infos; |
| 110 } |
| 111 std::vector<InlinedFunctionInfo>* ReleaseInlinedFunctionInfos() { |
| 112 std::vector<InlinedFunctionInfo>* tmp = inlined_function_infos_; |
| 113 inlined_function_infos_ = NULL; |
| 114 return tmp; |
| 115 } |
89 | 116 |
90 void SetBuiltinId(Builtins::Name id); | 117 void SetBuiltinId(Builtins::Name id); |
91 Builtins::Name builtin_id() const { | 118 Builtins::Name builtin_id() const { |
92 return BuiltinIdField::decode(bit_field_); | 119 return BuiltinIdField::decode(bit_field_); |
93 } | 120 } |
94 | 121 |
95 uint32_t GetHash() const; | 122 uint32_t GetHash() const; |
96 bool IsSameFunctionAs(CodeEntry* entry) const; | 123 bool IsSameFunctionAs(CodeEntry* entry) const; |
97 | 124 |
98 int GetSourceLine(int pc_offset) const; | 125 int GetSourceLine(int pc_offset) const; |
(...skipping 15 matching lines...) Expand all Loading... |
114 const char* name_; | 141 const char* name_; |
115 const char* resource_name_; | 142 const char* resource_name_; |
116 int line_number_; | 143 int line_number_; |
117 int column_number_; | 144 int column_number_; |
118 int script_id_; | 145 int script_id_; |
119 int position_; | 146 int position_; |
120 List<OffsetRange>* no_frame_ranges_; | 147 List<OffsetRange>* no_frame_ranges_; |
121 const char* bailout_reason_; | 148 const char* bailout_reason_; |
122 const char* deopt_reason_; | 149 const char* deopt_reason_; |
123 SourcePosition deopt_position_; | 150 SourcePosition deopt_position_; |
| 151 int pc_offset_; |
124 JITLineInfoTable* line_info_; | 152 JITLineInfoTable* line_info_; |
125 Address instruction_start_; | 153 Address instruction_start_; |
126 | 154 |
| 155 std::vector<InlinedFunctionInfo>* inlined_function_infos_; |
| 156 |
127 DISALLOW_COPY_AND_ASSIGN(CodeEntry); | 157 DISALLOW_COPY_AND_ASSIGN(CodeEntry); |
128 }; | 158 }; |
129 | 159 |
130 | 160 |
131 class ProfileTree; | 161 class ProfileTree; |
132 | 162 |
133 class ProfileNode { | 163 class ProfileNode { |
134 private: | |
135 struct DeoptInfo { | |
136 DeoptInfo(const char* deopt_reason, SourcePosition deopt_position) | |
137 : deopt_reason(deopt_reason), deopt_position(deopt_position) {} | |
138 DeoptInfo(const DeoptInfo& info) | |
139 : deopt_reason(info.deopt_reason), | |
140 deopt_position(info.deopt_position) {} | |
141 const char* deopt_reason; | |
142 SourcePosition deopt_position; | |
143 }; | |
144 | |
145 public: | 164 public: |
146 inline ProfileNode(ProfileTree* tree, CodeEntry* entry); | 165 inline ProfileNode(ProfileTree* tree, CodeEntry* entry); |
147 | 166 |
148 ProfileNode* FindChild(CodeEntry* entry); | 167 ProfileNode* FindChild(CodeEntry* entry); |
149 ProfileNode* FindOrAddChild(CodeEntry* entry); | 168 ProfileNode* FindOrAddChild(CodeEntry* entry); |
150 void IncrementSelfTicks() { ++self_ticks_; } | 169 void IncrementSelfTicks() { ++self_ticks_; } |
151 void IncreaseSelfTicks(unsigned amount) { self_ticks_ += amount; } | 170 void IncreaseSelfTicks(unsigned amount) { self_ticks_ += amount; } |
152 void IncrementLineTicks(int src_line); | 171 void IncrementLineTicks(int src_line); |
153 | 172 |
154 CodeEntry* entry() const { return entry_; } | 173 CodeEntry* entry() const { return entry_; } |
155 unsigned self_ticks() const { return self_ticks_; } | 174 unsigned self_ticks() const { return self_ticks_; } |
156 const List<ProfileNode*>* children() const { return &children_list_; } | 175 const List<ProfileNode*>* children() const { return &children_list_; } |
157 unsigned id() const { return id_; } | 176 unsigned id() const { return id_; } |
158 unsigned function_id() const; | 177 unsigned function_id() const; |
159 unsigned int GetHitLineCount() const { return line_ticks_.occupancy(); } | 178 unsigned int GetHitLineCount() const { return line_ticks_.occupancy(); } |
160 bool GetLineTicks(v8::CpuProfileNode::LineTick* entries, | 179 bool GetLineTicks(v8::CpuProfileNode::LineTick* entries, |
161 unsigned int length) const; | 180 unsigned int length) const; |
162 void CollectDeoptInfo(CodeEntry* entry); | 181 void CollectDeoptInfo(CodeEntry* entry); |
163 const List<DeoptInfo>& deopt_infos() const { return deopt_infos_; } | 182 const std::vector<DeoptInfo>& deopt_infos() const { return deopt_infos_; } |
164 | 183 |
165 void Print(int indent); | 184 void Print(int indent); |
166 | 185 |
167 static bool CodeEntriesMatch(void* entry1, void* entry2) { | 186 static bool CodeEntriesMatch(void* entry1, void* entry2) { |
168 return reinterpret_cast<CodeEntry*>(entry1) | 187 return reinterpret_cast<CodeEntry*>(entry1) |
169 ->IsSameFunctionAs(reinterpret_cast<CodeEntry*>(entry2)); | 188 ->IsSameFunctionAs(reinterpret_cast<CodeEntry*>(entry2)); |
170 } | 189 } |
171 | 190 |
172 private: | 191 private: |
173 static uint32_t CodeEntryHash(CodeEntry* entry) { return entry->GetHash(); } | 192 static uint32_t CodeEntryHash(CodeEntry* entry) { return entry->GetHash(); } |
174 | 193 |
175 static bool LineTickMatch(void* a, void* b) { return a == b; } | 194 static bool LineTickMatch(void* a, void* b) { return a == b; } |
176 | 195 |
177 ProfileTree* tree_; | 196 ProfileTree* tree_; |
178 CodeEntry* entry_; | 197 CodeEntry* entry_; |
179 unsigned self_ticks_; | 198 unsigned self_ticks_; |
180 // Mapping from CodeEntry* to ProfileNode* | 199 // Mapping from CodeEntry* to ProfileNode* |
181 HashMap children_; | 200 HashMap children_; |
182 List<ProfileNode*> children_list_; | 201 List<ProfileNode*> children_list_; |
183 unsigned id_; | 202 unsigned id_; |
184 HashMap line_ticks_; | 203 HashMap line_ticks_; |
185 | 204 |
186 List<DeoptInfo> deopt_infos_; | 205 std::vector<DeoptInfo> deopt_infos_; |
| 206 |
187 DISALLOW_COPY_AND_ASSIGN(ProfileNode); | 207 DISALLOW_COPY_AND_ASSIGN(ProfileNode); |
188 }; | 208 }; |
189 | 209 |
190 | 210 |
191 class ProfileTree { | 211 class ProfileTree { |
192 public: | 212 public: |
193 ProfileTree(); | 213 ProfileTree(); |
194 ~ProfileTree(); | 214 ~ProfileTree(); |
195 | 215 |
196 ProfileNode* AddPathFromEnd( | 216 ProfileNode* AddPathFromEnd( |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 CodeEntry* gc_entry_; | 395 CodeEntry* gc_entry_; |
376 CodeEntry* unresolved_entry_; | 396 CodeEntry* unresolved_entry_; |
377 | 397 |
378 DISALLOW_COPY_AND_ASSIGN(ProfileGenerator); | 398 DISALLOW_COPY_AND_ASSIGN(ProfileGenerator); |
379 }; | 399 }; |
380 | 400 |
381 | 401 |
382 } } // namespace v8::internal | 402 } } // namespace v8::internal |
383 | 403 |
384 #endif // V8_PROFILE_GENERATOR_H_ | 404 #endif // V8_PROFILE_GENERATOR_H_ |
OLD | NEW |