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

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

Issue 2686813006: Reapply "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 | « runtime/vm/clustered_snapshot.cc ('k') | 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"
13 14
14 namespace dart { 15 namespace dart {
15 16
16 class DescriptorList : public ZoneAllocated { 17 class DescriptorList : public ZoneAllocated {
17 public: 18 public:
18 explicit DescriptorList(intptr_t initial_capacity) 19 explicit DescriptorList(intptr_t initial_capacity)
19 : encoded_data_(initial_capacity), 20 : encoded_data_(initial_capacity),
20 prev_pc_offset(0), 21 prev_pc_offset(0),
21 prev_deopt_id(0), 22 prev_deopt_id(0),
22 prev_token_pos(0) {} 23 prev_token_pos(0) {}
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 } 133 }
133 134
134 RawExceptionHandlers* FinalizeExceptionHandlers(uword entry_point) const; 135 RawExceptionHandlers* FinalizeExceptionHandlers(uword entry_point) const;
135 136
136 private: 137 private:
137 GrowableArray<struct HandlerDesc> list_; 138 GrowableArray<struct HandlerDesc> list_;
138 DISALLOW_COPY_AND_ASSIGN(ExceptionHandlerList); 139 DISALLOW_COPY_AND_ASSIGN(ExceptionHandlerList);
139 }; 140 };
140 141
141 142
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.
142 class CodeSourceMapBuilder : public ZoneAllocated { 153 class CodeSourceMapBuilder : public ZoneAllocated {
143 public: 154 public:
144 CodeSourceMapBuilder( 155 CodeSourceMapBuilder(
156 bool stack_traces_only,
145 const GrowableArray<intptr_t>& caller_inline_id, 157 const GrowableArray<intptr_t>& caller_inline_id,
146 const GrowableArray<TokenPosition>& inline_id_to_token_pos, 158 const GrowableArray<TokenPosition>& inline_id_to_token_pos,
147 const GrowableArray<const Function*>& inline_id_to_function); 159 const GrowableArray<const Function*>& inline_id_to_function);
148 160
149 // The position at which a function implicitly starts, for both the root and 161 // The position at which a function implicitly starts, for both the root and
150 // after a push bytecode. We use the classifying position kDartCodePrologue 162 // after a push bytecode. We use the classifying position kDartCodePrologue
151 // since it is the most common. 163 // since it is the most common.
152 static const TokenPosition kInitialPosition; 164 static const TokenPosition kInitialPosition;
153 165
154 static const uint8_t kChangePosition = 0; 166 static const uint8_t kChangePosition = 0;
155 static const uint8_t kAdvancePC = 1; 167 static const uint8_t kAdvancePC = 1;
156 static const uint8_t kPushFunction = 2; 168 static const uint8_t kPushFunction = 2;
157 static const uint8_t kPopFunction = 3; 169 static const uint8_t kPopFunction = 3;
158 170
159 void StartInliningInterval(int32_t pc_offset, intptr_t inline_id); 171 void StartInliningInterval(int32_t pc_offset, intptr_t inline_id);
160 void BeginCodeSourceRange(int32_t pc_offset); 172 void BeginCodeSourceRange(int32_t pc_offset);
161 void EndCodeSourceRange(int32_t pc_offset, TokenPosition pos); 173 void EndCodeSourceRange(int32_t pc_offset, TokenPosition pos);
174 void NoteDescriptor(RawPcDescriptors::Kind kind,
175 int32_t pc_offset,
176 TokenPosition pos);
162 177
163 RawArray* InliningIdToFunction(); 178 RawArray* InliningIdToFunction();
164 RawCodeSourceMap* Finalize(); 179 RawCodeSourceMap* Finalize();
165 180
166 private: 181 private:
167 void EmitPosition(TokenPosition pos) { 182 void BufferChangePosition(TokenPosition pos) {
168 FlushPeephole(); 183 buffered_token_pos_stack_.Last() = pos;
184 }
185 void WriteChangePosition(TokenPosition pos) {
169 stream_.Write<uint8_t>(kChangePosition); 186 stream_.Write<uint8_t>(kChangePosition);
170 stream_.Write<int32_t>(static_cast<int32_t>(pos.value())); 187 stream_.Write<int32_t>(static_cast<int32_t>(pos.value()));
188 written_token_pos_stack_.Last() = pos;
171 } 189 }
172 void EmitAdvancePC(int32_t distance) { advance_pc_peephole_ += distance; } 190 void BufferAdvancePC(int32_t distance) { buffered_pc_offset_ += distance; }
173 void FlushPeephole() { 191 void WriteAdvancePC(int32_t distance) {
174 if (advance_pc_peephole_ != 0) { 192 stream_.Write<uint8_t>(kAdvancePC);
175 stream_.Write<uint8_t>(kAdvancePC); 193 stream_.Write<int32_t>(distance);
176 stream_.Write<int32_t>(advance_pc_peephole_); 194 written_pc_offset_ += distance;
177 advance_pc_peephole_ = 0;
178 }
179 } 195 }
180 void EmitPush(intptr_t inline_id) { 196 void BufferPush(intptr_t inline_id) {
181 FlushPeephole(); 197 buffered_inline_id_stack_.Add(inline_id);
198 buffered_token_pos_stack_.Add(kInitialPosition);
199 }
200 void WritePush(intptr_t inline_id) {
182 stream_.Write<uint8_t>(kPushFunction); 201 stream_.Write<uint8_t>(kPushFunction);
183 stream_.Write<int32_t>(inline_id); 202 stream_.Write<int32_t>(inline_id);
203 written_inline_id_stack_.Add(inline_id);
204 written_token_pos_stack_.Add(kInitialPosition);
184 } 205 }
185 void EmitPop() { 206 void BufferPop() {
186 FlushPeephole(); 207 buffered_inline_id_stack_.RemoveLast();
208 buffered_token_pos_stack_.RemoveLast();
209 }
210 void WritePop() {
187 stream_.Write<uint8_t>(kPopFunction); 211 stream_.Write<uint8_t>(kPopFunction);
212 written_inline_id_stack_.RemoveLast();
213 written_token_pos_stack_.RemoveLast();
188 } 214 }
189 215
190 bool IsOnStack(intptr_t inline_id) { 216 void FlushBuffer();
191 for (intptr_t i = 0; i < inline_id_stack_.length(); i++) { 217 void FlushBufferStack();
192 if (inline_id_stack_[i] == inline_id) { 218 void FlushBufferPosition();
193 return true; 219 void FlushBufferPC();
194 } 220
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;
195 } 224 }
196 return false; 225 return false;
197 } 226 }
198 227
199 intptr_t pc_offset_; 228 intptr_t buffered_pc_offset_;
200 intptr_t advance_pc_peephole_; 229 GrowableArray<intptr_t> buffered_inline_id_stack_;
201 GrowableArray<intptr_t> inline_id_stack_; 230 GrowableArray<TokenPosition> buffered_token_pos_stack_;
202 GrowableArray<TokenPosition> token_pos_stack_; 231
232 intptr_t written_pc_offset_;
233 GrowableArray<intptr_t> written_inline_id_stack_;
234 GrowableArray<TokenPosition> written_token_pos_stack_;
203 235
204 const GrowableArray<intptr_t>& caller_inline_id_; 236 const GrowableArray<intptr_t>& caller_inline_id_;
205 const GrowableArray<TokenPosition>& inline_id_to_token_pos_; 237 const GrowableArray<TokenPosition>& inline_id_to_token_pos_;
206 const GrowableArray<const Function*>& inline_id_to_function_; 238 const GrowableArray<const Function*>& inline_id_to_function_;
207 239
208 uint8_t* buffer_; 240 uint8_t* buffer_;
209 WriteStream stream_; 241 WriteStream stream_;
210 242
243 const bool stack_traces_only_;
244
211 DISALLOW_COPY_AND_ASSIGN(CodeSourceMapBuilder); 245 DISALLOW_COPY_AND_ASSIGN(CodeSourceMapBuilder);
212 }; 246 };
213 247
214 248
215 class CodeSourceMapReader : public ValueObject { 249 class CodeSourceMapReader : public ValueObject {
216 public: 250 public:
217 CodeSourceMapReader(const CodeSourceMap& map, 251 CodeSourceMapReader(const CodeSourceMap& map,
218 const Array& functions, 252 const Array& functions,
219 const Function& root) 253 const Function& root)
220 : map_(map), functions_(functions), root_(root) {} 254 : map_(map), functions_(functions), root_(root) {}
221 255
222 void GetInlinedFunctionsAt(int32_t pc_offset, 256 void GetInlinedFunctionsAt(int32_t pc_offset,
223 GrowableArray<const Function*>* function_stack, 257 GrowableArray<const Function*>* function_stack,
224 GrowableArray<TokenPosition>* token_positions); 258 GrowableArray<TokenPosition>* token_positions);
225 NOT_IN_PRODUCT(void PrintJSONInlineIntervals(JSONObject* jsobj)); 259 NOT_IN_PRODUCT(void PrintJSONInlineIntervals(JSONObject* jsobj));
226 void DumpInlineIntervals(uword start); 260 void DumpInlineIntervals(uword start);
227 void DumpSourcePositions(uword start); 261 void DumpSourcePositions(uword start);
228 262
229 private: 263 private:
230 const CodeSourceMap& map_; 264 const CodeSourceMap& map_;
231 const Array& functions_; 265 const Array& functions_;
232 const Function& root_; 266 const Function& root_;
233 267
234 DISALLOW_COPY_AND_ASSIGN(CodeSourceMapReader); 268 DISALLOW_COPY_AND_ASSIGN(CodeSourceMapReader);
235 }; 269 };
236 270
237 } // namespace dart 271 } // namespace dart
238 272
239 #endif // RUNTIME_VM_CODE_DESCRIPTORS_H_ 273 #endif // RUNTIME_VM_CODE_DESCRIPTORS_H_
OLDNEW
« no previous file with comments | « runtime/vm/clustered_snapshot.cc ('k') | runtime/vm/code_descriptors.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698