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

Side by Side Diff: runtime/vm/code_descriptors.h

Issue 2685723004: Revert "Use CodeSourceMap for stack traces (still JIT only)." (Closed)
Patch Set: Created 3 years, 10 months 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 | « no previous file | runtime/vm/code_descriptors.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 (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #ifndef RUNTIME_VM_CODE_DESCRIPTORS_H_ 5 #ifndef RUNTIME_VM_CODE_DESCRIPTORS_H_
6 #define RUNTIME_VM_CODE_DESCRIPTORS_H_ 6 #define RUNTIME_VM_CODE_DESCRIPTORS_H_
7 7
8 #include "vm/ast.h" 8 #include "vm/ast.h"
9 #include "vm/code_generator.h" 9 #include "vm/code_generator.h"
10 #include "vm/globals.h" 10 #include "vm/globals.h"
11 #include "vm/growable_array.h" 11 #include "vm/growable_array.h"
12 #include "vm/object.h" 12 #include "vm/object.h"
13 #include "vm/log.h"
14 13
15 namespace dart { 14 namespace dart {
16 15
17 class DescriptorList : public ZoneAllocated { 16 class DescriptorList : public ZoneAllocated {
18 public: 17 public:
19 explicit DescriptorList(intptr_t initial_capacity) 18 explicit DescriptorList(intptr_t initial_capacity)
20 : encoded_data_(initial_capacity), 19 : encoded_data_(initial_capacity),
21 prev_pc_offset(0), 20 prev_pc_offset(0),
22 prev_deopt_id(0), 21 prev_deopt_id(0),
23 prev_token_pos(0) {} 22 prev_token_pos(0) {}
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 } 132 }
134 133
135 RawExceptionHandlers* FinalizeExceptionHandlers(uword entry_point) const; 134 RawExceptionHandlers* FinalizeExceptionHandlers(uword entry_point) const;
136 135
137 private: 136 private:
138 GrowableArray<struct HandlerDesc> list_; 137 GrowableArray<struct HandlerDesc> list_;
139 DISALLOW_COPY_AND_ASSIGN(ExceptionHandlerList); 138 DISALLOW_COPY_AND_ASSIGN(ExceptionHandlerList);
140 }; 139 };
141 140
142 141
143 // A CodeSourceMap maps from pc offsets to a stack of inlined functions and
144 // their positions. This is encoded as a little bytecode that pushes and pops
145 // functions and changes the top function's position as the PC advances.
146 // Decoding happens by running this bytecode until we reach the desired PC.
147 //
148 // The implementation keeps track of two sets of state: one written to the byte
149 // stream and one that is buffered. On the JIT, this buffering effectively gives
150 // us a peephole optimization that merges adjacent advance PC bytecodes. On AOT,
151 // this allows to skip encoding our position until we reach a PC where we might
152 // throw.
153 class CodeSourceMapBuilder : public ZoneAllocated { 142 class CodeSourceMapBuilder : public ZoneAllocated {
154 public: 143 public:
155 CodeSourceMapBuilder( 144 CodeSourceMapBuilder(
156 bool stack_traces_only,
157 const GrowableArray<intptr_t>& caller_inline_id, 145 const GrowableArray<intptr_t>& caller_inline_id,
158 const GrowableArray<TokenPosition>& inline_id_to_token_pos, 146 const GrowableArray<TokenPosition>& inline_id_to_token_pos,
159 const GrowableArray<const Function*>& inline_id_to_function); 147 const GrowableArray<const Function*>& inline_id_to_function);
160 148
161 // The position at which a function implicitly starts, for both the root and 149 // The position at which a function implicitly starts, for both the root and
162 // after a push bytecode. We use the classifying position kDartCodePrologue 150 // after a push bytecode. We use the classifying position kDartCodePrologue
163 // since it is the most common. 151 // since it is the most common.
164 static const TokenPosition kInitialPosition; 152 static const TokenPosition kInitialPosition;
165 153
166 static const uint8_t kChangePosition = 0; 154 static const uint8_t kChangePosition = 0;
167 static const uint8_t kAdvancePC = 1; 155 static const uint8_t kAdvancePC = 1;
168 static const uint8_t kPushFunction = 2; 156 static const uint8_t kPushFunction = 2;
169 static const uint8_t kPopFunction = 3; 157 static const uint8_t kPopFunction = 3;
170 158
171 void StartInliningInterval(int32_t pc_offset, intptr_t inline_id); 159 void StartInliningInterval(int32_t pc_offset, intptr_t inline_id);
172 void BeginCodeSourceRange(int32_t pc_offset); 160 void BeginCodeSourceRange(int32_t pc_offset);
173 void EndCodeSourceRange(int32_t pc_offset, TokenPosition pos); 161 void EndCodeSourceRange(int32_t pc_offset, TokenPosition pos);
174 void NoteDescriptor(RawPcDescriptors::Kind kind,
175 int32_t pc_offset,
176 TokenPosition pos);
177 162
178 RawArray* InliningIdToFunction(); 163 RawArray* InliningIdToFunction();
179 RawCodeSourceMap* Finalize(); 164 RawCodeSourceMap* Finalize();
180 165
181 private: 166 private:
182 void BufferChangePosition(TokenPosition pos) { 167 void EmitPosition(TokenPosition pos) {
183 buffered_token_pos_stack_.Last() = pos; 168 FlushPeephole();
184 }
185 void WriteChangePosition(TokenPosition pos) {
186 stream_.Write<uint8_t>(kChangePosition); 169 stream_.Write<uint8_t>(kChangePosition);
187 stream_.Write<int32_t>(static_cast<int32_t>(pos.value())); 170 stream_.Write<int32_t>(static_cast<int32_t>(pos.value()));
188 written_token_pos_stack_.Last() = pos;
189 } 171 }
190 void BufferAdvancePC(int32_t distance) { buffered_pc_offset_ += distance; } 172 void EmitAdvancePC(int32_t distance) { advance_pc_peephole_ += distance; }
191 void WriteAdvancePC(int32_t distance) { 173 void FlushPeephole() {
192 stream_.Write<uint8_t>(kAdvancePC); 174 if (advance_pc_peephole_ != 0) {
193 stream_.Write<int32_t>(distance); 175 stream_.Write<uint8_t>(kAdvancePC);
194 written_pc_offset_ += distance; 176 stream_.Write<int32_t>(advance_pc_peephole_);
177 advance_pc_peephole_ = 0;
178 }
195 } 179 }
196 void BufferPush(intptr_t inline_id) { 180 void EmitPush(intptr_t inline_id) {
197 buffered_inline_id_stack_.Add(inline_id); 181 FlushPeephole();
198 buffered_token_pos_stack_.Add(kInitialPosition);
199 }
200 void WritePush(intptr_t inline_id) {
201 stream_.Write<uint8_t>(kPushFunction); 182 stream_.Write<uint8_t>(kPushFunction);
202 stream_.Write<int32_t>(inline_id); 183 stream_.Write<int32_t>(inline_id);
203 written_inline_id_stack_.Add(inline_id);
204 written_token_pos_stack_.Add(kInitialPosition);
205 } 184 }
206 void BufferPop() { 185 void EmitPop() {
207 buffered_inline_id_stack_.RemoveLast(); 186 FlushPeephole();
208 buffered_token_pos_stack_.RemoveLast();
209 }
210 void WritePop() {
211 stream_.Write<uint8_t>(kPopFunction); 187 stream_.Write<uint8_t>(kPopFunction);
212 written_inline_id_stack_.RemoveLast();
213 written_token_pos_stack_.RemoveLast();
214 } 188 }
215 189
216 void FlushBuffer(); 190 bool IsOnStack(intptr_t inline_id) {
217 void FlushBufferStack(); 191 for (intptr_t i = 0; i < inline_id_stack_.length(); i++) {
218 void FlushBufferPosition(); 192 if (inline_id_stack_[i] == inline_id) {
219 void FlushBufferPC(); 193 return true;
220 194 }
221 bool IsOnBufferedStack(intptr_t inline_id) {
222 for (intptr_t i = 0; i < buffered_inline_id_stack_.length(); i++) {
223 if (buffered_inline_id_stack_[i] == inline_id) return true;
224 } 195 }
225 return false; 196 return false;
226 } 197 }
227 198
228 intptr_t buffered_pc_offset_; 199 intptr_t pc_offset_;
229 GrowableArray<intptr_t> buffered_inline_id_stack_; 200 intptr_t advance_pc_peephole_;
230 GrowableArray<TokenPosition> buffered_token_pos_stack_; 201 GrowableArray<intptr_t> inline_id_stack_;
231 202 GrowableArray<TokenPosition> token_pos_stack_;
232 intptr_t written_pc_offset_;
233 GrowableArray<intptr_t> written_inline_id_stack_;
234 GrowableArray<TokenPosition> written_token_pos_stack_;
235 203
236 const GrowableArray<intptr_t>& caller_inline_id_; 204 const GrowableArray<intptr_t>& caller_inline_id_;
237 const GrowableArray<TokenPosition>& inline_id_to_token_pos_; 205 const GrowableArray<TokenPosition>& inline_id_to_token_pos_;
238 const GrowableArray<const Function*>& inline_id_to_function_; 206 const GrowableArray<const Function*>& inline_id_to_function_;
239 207
240 uint8_t* buffer_; 208 uint8_t* buffer_;
241 WriteStream stream_; 209 WriteStream stream_;
242 210
243 const bool stack_traces_only_;
244
245 DISALLOW_COPY_AND_ASSIGN(CodeSourceMapBuilder); 211 DISALLOW_COPY_AND_ASSIGN(CodeSourceMapBuilder);
246 }; 212 };
247 213
248 214
249 class CodeSourceMapReader : public ValueObject { 215 class CodeSourceMapReader : public ValueObject {
250 public: 216 public:
251 CodeSourceMapReader(const CodeSourceMap& map, 217 CodeSourceMapReader(const CodeSourceMap& map,
252 const Array& functions, 218 const Array& functions,
253 const Function& root) 219 const Function& root)
254 : map_(map), functions_(functions), root_(root) {} 220 : map_(map), functions_(functions), root_(root) {}
255 221
256 void GetInlinedFunctionsAt(int32_t pc_offset, 222 void GetInlinedFunctionsAt(int32_t pc_offset,
257 GrowableArray<const Function*>* function_stack, 223 GrowableArray<const Function*>* function_stack,
258 GrowableArray<TokenPosition>* token_positions); 224 GrowableArray<TokenPosition>* token_positions);
259 NOT_IN_PRODUCT(void PrintJSONInlineIntervals(JSONObject* jsobj)); 225 NOT_IN_PRODUCT(void PrintJSONInlineIntervals(JSONObject* jsobj));
260 void DumpInlineIntervals(uword start); 226 void DumpInlineIntervals(uword start);
261 void DumpSourcePositions(uword start); 227 void DumpSourcePositions(uword start);
262 228
263 private: 229 private:
264 const CodeSourceMap& map_; 230 const CodeSourceMap& map_;
265 const Array& functions_; 231 const Array& functions_;
266 const Function& root_; 232 const Function& root_;
267 233
268 DISALLOW_COPY_AND_ASSIGN(CodeSourceMapReader); 234 DISALLOW_COPY_AND_ASSIGN(CodeSourceMapReader);
269 }; 235 };
270 236
271 } // namespace dart 237 } // namespace dart
272 238
273 #endif // RUNTIME_VM_CODE_DESCRIPTORS_H_ 239 #endif // RUNTIME_VM_CODE_DESCRIPTORS_H_
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/code_descriptors.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698