| OLD | NEW |
| 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 #include "vm/code_descriptors.h" | 5 #include "vm/code_descriptors.h" |
| 6 | 6 |
| 7 #include "vm/log.h" | 7 #include "vm/log.h" |
| 8 | 8 |
| 9 namespace dart { | 9 namespace dart { |
| 10 | 10 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 PcDescriptors::EncodeInteger(&encoded_data_, deopt_id - prev_deopt_id); | 27 PcDescriptors::EncodeInteger(&encoded_data_, deopt_id - prev_deopt_id); |
| 28 PcDescriptors::EncodeInteger(&encoded_data_, | 28 PcDescriptors::EncodeInteger(&encoded_data_, |
| 29 token_pos.value() - prev_token_pos); | 29 token_pos.value() - prev_token_pos); |
| 30 | 30 |
| 31 prev_pc_offset = pc_offset; | 31 prev_pc_offset = pc_offset; |
| 32 prev_deopt_id = deopt_id; | 32 prev_deopt_id = deopt_id; |
| 33 prev_token_pos = token_pos.value(); | 33 prev_token_pos = token_pos.value(); |
| 34 } | 34 } |
| 35 } | 35 } |
| 36 | 36 |
| 37 | |
| 38 RawPcDescriptors* DescriptorList::FinalizePcDescriptors(uword entry_point) { | 37 RawPcDescriptors* DescriptorList::FinalizePcDescriptors(uword entry_point) { |
| 39 if (encoded_data_.length() == 0) { | 38 if (encoded_data_.length() == 0) { |
| 40 return Object::empty_descriptors().raw(); | 39 return Object::empty_descriptors().raw(); |
| 41 } | 40 } |
| 42 return PcDescriptors::New(&encoded_data_); | 41 return PcDescriptors::New(&encoded_data_); |
| 43 } | 42 } |
| 44 | 43 |
| 45 | |
| 46 void StackMapTableBuilder::AddEntry(intptr_t pc_offset, | 44 void StackMapTableBuilder::AddEntry(intptr_t pc_offset, |
| 47 BitmapBuilder* bitmap, | 45 BitmapBuilder* bitmap, |
| 48 intptr_t register_bit_count) { | 46 intptr_t register_bit_count) { |
| 49 stack_map_ = StackMap::New(pc_offset, bitmap, register_bit_count); | 47 stack_map_ = StackMap::New(pc_offset, bitmap, register_bit_count); |
| 50 list_.Add(stack_map_, Heap::kOld); | 48 list_.Add(stack_map_, Heap::kOld); |
| 51 } | 49 } |
| 52 | 50 |
| 53 | |
| 54 bool StackMapTableBuilder::Verify() { | 51 bool StackMapTableBuilder::Verify() { |
| 55 intptr_t num_entries = Length(); | 52 intptr_t num_entries = Length(); |
| 56 StackMap& map1 = StackMap::Handle(); | 53 StackMap& map1 = StackMap::Handle(); |
| 57 StackMap& map2 = StackMap::Handle(); | 54 StackMap& map2 = StackMap::Handle(); |
| 58 for (intptr_t i = 1; i < num_entries; i++) { | 55 for (intptr_t i = 1; i < num_entries; i++) { |
| 59 map1 = MapAt(i - 1); | 56 map1 = MapAt(i - 1); |
| 60 map2 = MapAt(i); | 57 map2 = MapAt(i); |
| 61 // Ensure there are no duplicates and the entries are sorted. | 58 // Ensure there are no duplicates and the entries are sorted. |
| 62 if (map1.PcOffset() >= map2.PcOffset()) { | 59 if (map1.PcOffset() >= map2.PcOffset()) { |
| 63 return false; | 60 return false; |
| 64 } | 61 } |
| 65 } | 62 } |
| 66 return true; | 63 return true; |
| 67 } | 64 } |
| 68 | 65 |
| 69 | |
| 70 RawArray* StackMapTableBuilder::FinalizeStackMaps(const Code& code) { | 66 RawArray* StackMapTableBuilder::FinalizeStackMaps(const Code& code) { |
| 71 ASSERT(Verify()); | 67 ASSERT(Verify()); |
| 72 intptr_t num_entries = Length(); | 68 intptr_t num_entries = Length(); |
| 73 if (num_entries == 0) { | 69 if (num_entries == 0) { |
| 74 return Object::empty_array().raw(); | 70 return Object::empty_array().raw(); |
| 75 } | 71 } |
| 76 return Array::MakeFixedLength(list_); | 72 return Array::MakeFixedLength(list_); |
| 77 } | 73 } |
| 78 | 74 |
| 79 | |
| 80 RawStackMap* StackMapTableBuilder::MapAt(intptr_t index) const { | 75 RawStackMap* StackMapTableBuilder::MapAt(intptr_t index) const { |
| 81 StackMap& map = StackMap::Handle(); | 76 StackMap& map = StackMap::Handle(); |
| 82 map ^= list_.At(index); | 77 map ^= list_.At(index); |
| 83 return map.raw(); | 78 return map.raw(); |
| 84 } | 79 } |
| 85 | 80 |
| 86 | |
| 87 RawExceptionHandlers* ExceptionHandlerList::FinalizeExceptionHandlers( | 81 RawExceptionHandlers* ExceptionHandlerList::FinalizeExceptionHandlers( |
| 88 uword entry_point) const { | 82 uword entry_point) const { |
| 89 intptr_t num_handlers = Length(); | 83 intptr_t num_handlers = Length(); |
| 90 if (num_handlers == 0) { | 84 if (num_handlers == 0) { |
| 91 return Object::empty_exception_handlers().raw(); | 85 return Object::empty_exception_handlers().raw(); |
| 92 } | 86 } |
| 93 const ExceptionHandlers& handlers = | 87 const ExceptionHandlers& handlers = |
| 94 ExceptionHandlers::Handle(ExceptionHandlers::New(num_handlers)); | 88 ExceptionHandlers::Handle(ExceptionHandlers::New(num_handlers)); |
| 95 for (intptr_t i = 0; i < num_handlers; i++) { | 89 for (intptr_t i = 0; i < num_handlers; i++) { |
| 96 // Assert that every element in the array has been initialized. | 90 // Assert that every element in the array has been initialized. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 109 const bool has_catch_all = ContainsDynamic(*list_[i].handler_types); | 103 const bool has_catch_all = ContainsDynamic(*list_[i].handler_types); |
| 110 handlers.SetHandlerInfo(i, list_[i].outer_try_index, list_[i].pc_offset, | 104 handlers.SetHandlerInfo(i, list_[i].outer_try_index, list_[i].pc_offset, |
| 111 list_[i].needs_stacktrace, has_catch_all, | 105 list_[i].needs_stacktrace, has_catch_all, |
| 112 list_[i].token_pos, list_[i].is_generated); | 106 list_[i].token_pos, list_[i].is_generated); |
| 113 handlers.SetHandledTypes(i, *list_[i].handler_types); | 107 handlers.SetHandledTypes(i, *list_[i].handler_types); |
| 114 } | 108 } |
| 115 } | 109 } |
| 116 return handlers.raw(); | 110 return handlers.raw(); |
| 117 } | 111 } |
| 118 | 112 |
| 119 | |
| 120 static uint8_t* zone_allocator(uint8_t* ptr, | 113 static uint8_t* zone_allocator(uint8_t* ptr, |
| 121 intptr_t old_size, | 114 intptr_t old_size, |
| 122 intptr_t new_size) { | 115 intptr_t new_size) { |
| 123 Zone* zone = Thread::Current()->zone(); | 116 Zone* zone = Thread::Current()->zone(); |
| 124 return zone->Realloc<uint8_t>(ptr, old_size, new_size); | 117 return zone->Realloc<uint8_t>(ptr, old_size, new_size); |
| 125 } | 118 } |
| 126 | 119 |
| 127 | |
| 128 class CatchEntryStateMapBuilder::TrieNode : public ZoneAllocated { | 120 class CatchEntryStateMapBuilder::TrieNode : public ZoneAllocated { |
| 129 public: | 121 public: |
| 130 TrieNode() : pair_(), entry_state_offset_(-1) {} | 122 TrieNode() : pair_(), entry_state_offset_(-1) {} |
| 131 TrieNode(CatchEntryStatePair pair, intptr_t index) | 123 TrieNode(CatchEntryStatePair pair, intptr_t index) |
| 132 : pair_(pair), entry_state_offset_(index) {} | 124 : pair_(pair), entry_state_offset_(index) {} |
| 133 | 125 |
| 134 intptr_t Offset() { return entry_state_offset_; } | 126 intptr_t Offset() { return entry_state_offset_; } |
| 135 | 127 |
| 136 TrieNode* Insert(TrieNode* node) { | 128 TrieNode* Insert(TrieNode* node) { |
| 137 children_.Add(node); | 129 children_.Add(node); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 151 GrowableArray<TrieNode*> children_; | 143 GrowableArray<TrieNode*> children_; |
| 152 }; | 144 }; |
| 153 | 145 |
| 154 CatchEntryStateMapBuilder::CatchEntryStateMapBuilder() | 146 CatchEntryStateMapBuilder::CatchEntryStateMapBuilder() |
| 155 : zone_(Thread::Current()->zone()), | 147 : zone_(Thread::Current()->zone()), |
| 156 root_(new TrieNode()), | 148 root_(new TrieNode()), |
| 157 current_pc_offset_(0), | 149 current_pc_offset_(0), |
| 158 buffer_(NULL), | 150 buffer_(NULL), |
| 159 stream_(&buffer_, zone_allocator, 64) {} | 151 stream_(&buffer_, zone_allocator, 64) {} |
| 160 | 152 |
| 161 | |
| 162 void CatchEntryStateMapBuilder::AppendMove(intptr_t src_slot, | 153 void CatchEntryStateMapBuilder::AppendMove(intptr_t src_slot, |
| 163 intptr_t dest_slot) { | 154 intptr_t dest_slot) { |
| 164 moves_.Add(CatchEntryStatePair::FromMove(src_slot, dest_slot)); | 155 moves_.Add(CatchEntryStatePair::FromMove(src_slot, dest_slot)); |
| 165 } | 156 } |
| 166 | 157 |
| 167 | |
| 168 void CatchEntryStateMapBuilder::AppendConstant(intptr_t pool_id, | 158 void CatchEntryStateMapBuilder::AppendConstant(intptr_t pool_id, |
| 169 intptr_t dest_slot) { | 159 intptr_t dest_slot) { |
| 170 moves_.Add(CatchEntryStatePair::FromConstant(pool_id, dest_slot)); | 160 moves_.Add(CatchEntryStatePair::FromConstant(pool_id, dest_slot)); |
| 171 } | 161 } |
| 172 | 162 |
| 173 | |
| 174 void CatchEntryStateMapBuilder::NewMapping(intptr_t pc_offset) { | 163 void CatchEntryStateMapBuilder::NewMapping(intptr_t pc_offset) { |
| 175 moves_.Clear(); | 164 moves_.Clear(); |
| 176 current_pc_offset_ = pc_offset; | 165 current_pc_offset_ = pc_offset; |
| 177 } | 166 } |
| 178 | 167 |
| 179 | |
| 180 void CatchEntryStateMapBuilder::EndMapping() { | 168 void CatchEntryStateMapBuilder::EndMapping() { |
| 181 intptr_t suffix_length = 0; | 169 intptr_t suffix_length = 0; |
| 182 TrieNode* suffix = root_; | 170 TrieNode* suffix = root_; |
| 183 // Find the largest common suffix, get the last node of the path. | 171 // Find the largest common suffix, get the last node of the path. |
| 184 for (intptr_t i = moves_.length() - 1; i >= 0; i--) { | 172 for (intptr_t i = moves_.length() - 1; i >= 0; i--) { |
| 185 TrieNode* n = suffix->Follow(moves_[i]); | 173 TrieNode* n = suffix->Follow(moves_[i]); |
| 186 if (n == NULL) break; | 174 if (n == NULL) break; |
| 187 suffix_length++; | 175 suffix_length++; |
| 188 suffix = n; | 176 suffix = n; |
| 189 } | 177 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 201 for (intptr_t i = length - 1; i >= 0; i--) { | 189 for (intptr_t i = length - 1; i >= 0; i--) { |
| 202 Writer::Write(&stream_, moves_[i].src); | 190 Writer::Write(&stream_, moves_[i].src); |
| 203 Writer::Write(&stream_, moves_[i].dest); | 191 Writer::Write(&stream_, moves_[i].dest); |
| 204 | 192 |
| 205 TrieNode* child = new (zone_) TrieNode(moves_[i], current_offset); | 193 TrieNode* child = new (zone_) TrieNode(moves_[i], current_offset); |
| 206 node->Insert(child); | 194 node->Insert(child); |
| 207 node = child; | 195 node = child; |
| 208 } | 196 } |
| 209 } | 197 } |
| 210 | 198 |
| 211 | |
| 212 RawTypedData* CatchEntryStateMapBuilder::FinalizeCatchEntryStateMap() { | 199 RawTypedData* CatchEntryStateMapBuilder::FinalizeCatchEntryStateMap() { |
| 213 TypedData& td = TypedData::Handle(TypedData::New( | 200 TypedData& td = TypedData::Handle(TypedData::New( |
| 214 kTypedDataInt8ArrayCid, stream_.bytes_written(), Heap::kOld)); | 201 kTypedDataInt8ArrayCid, stream_.bytes_written(), Heap::kOld)); |
| 215 NoSafepointScope no_safepoint; | 202 NoSafepointScope no_safepoint; |
| 216 uint8_t* dest = reinterpret_cast<uint8_t*>(td.DataAddr(0)); | 203 uint8_t* dest = reinterpret_cast<uint8_t*>(td.DataAddr(0)); |
| 217 uint8_t* src = stream_.buffer(); | 204 uint8_t* src = stream_.buffer(); |
| 218 for (intptr_t i = 0; i < stream_.bytes_written(); i++) { | 205 for (intptr_t i = 0; i < stream_.bytes_written(); i++) { |
| 219 dest[i] = src[i]; | 206 dest[i] = src[i]; |
| 220 } | 207 } |
| 221 return td.raw(); | 208 return td.raw(); |
| 222 } | 209 } |
| 223 | 210 |
| 224 | |
| 225 const TokenPosition CodeSourceMapBuilder::kInitialPosition = | 211 const TokenPosition CodeSourceMapBuilder::kInitialPosition = |
| 226 TokenPosition(TokenPosition::kDartCodeProloguePos); | 212 TokenPosition(TokenPosition::kDartCodeProloguePos); |
| 227 | 213 |
| 228 | |
| 229 CodeSourceMapBuilder::CodeSourceMapBuilder( | 214 CodeSourceMapBuilder::CodeSourceMapBuilder( |
| 230 bool stack_traces_only, | 215 bool stack_traces_only, |
| 231 const GrowableArray<intptr_t>& caller_inline_id, | 216 const GrowableArray<intptr_t>& caller_inline_id, |
| 232 const GrowableArray<TokenPosition>& inline_id_to_token_pos, | 217 const GrowableArray<TokenPosition>& inline_id_to_token_pos, |
| 233 const GrowableArray<const Function*>& inline_id_to_function) | 218 const GrowableArray<const Function*>& inline_id_to_function) |
| 234 : buffered_pc_offset_(0), | 219 : buffered_pc_offset_(0), |
| 235 buffered_inline_id_stack_(), | 220 buffered_inline_id_stack_(), |
| 236 buffered_token_pos_stack_(), | 221 buffered_token_pos_stack_(), |
| 237 written_pc_offset_(0), | 222 written_pc_offset_(0), |
| 238 written_inline_id_stack_(), | 223 written_inline_id_stack_(), |
| 239 written_token_pos_stack_(), | 224 written_token_pos_stack_(), |
| 240 caller_inline_id_(caller_inline_id), | 225 caller_inline_id_(caller_inline_id), |
| 241 inline_id_to_token_pos_(inline_id_to_token_pos), | 226 inline_id_to_token_pos_(inline_id_to_token_pos), |
| 242 inline_id_to_function_(inline_id_to_function), | 227 inline_id_to_function_(inline_id_to_function), |
| 243 inlined_functions_( | 228 inlined_functions_( |
| 244 GrowableObjectArray::Handle(GrowableObjectArray::New(Heap::kOld))), | 229 GrowableObjectArray::Handle(GrowableObjectArray::New(Heap::kOld))), |
| 245 buffer_(NULL), | 230 buffer_(NULL), |
| 246 stream_(&buffer_, zone_allocator, 64), | 231 stream_(&buffer_, zone_allocator, 64), |
| 247 stack_traces_only_(stack_traces_only) { | 232 stack_traces_only_(stack_traces_only) { |
| 248 buffered_inline_id_stack_.Add(0); | 233 buffered_inline_id_stack_.Add(0); |
| 249 buffered_token_pos_stack_.Add(kInitialPosition); | 234 buffered_token_pos_stack_.Add(kInitialPosition); |
| 250 written_inline_id_stack_.Add(0); | 235 written_inline_id_stack_.Add(0); |
| 251 written_token_pos_stack_.Add(kInitialPosition); | 236 written_token_pos_stack_.Add(kInitialPosition); |
| 252 } | 237 } |
| 253 | 238 |
| 254 | |
| 255 void CodeSourceMapBuilder::FlushBuffer() { | 239 void CodeSourceMapBuilder::FlushBuffer() { |
| 256 FlushBufferStack(); | 240 FlushBufferStack(); |
| 257 FlushBufferPosition(); | 241 FlushBufferPosition(); |
| 258 FlushBufferPC(); | 242 FlushBufferPC(); |
| 259 } | 243 } |
| 260 | 244 |
| 261 | |
| 262 void CodeSourceMapBuilder::FlushBufferStack() { | 245 void CodeSourceMapBuilder::FlushBufferStack() { |
| 263 for (intptr_t i = buffered_inline_id_stack_.length() - 1; i >= 0; i--) { | 246 for (intptr_t i = buffered_inline_id_stack_.length() - 1; i >= 0; i--) { |
| 264 intptr_t buffered_id = buffered_inline_id_stack_[i]; | 247 intptr_t buffered_id = buffered_inline_id_stack_[i]; |
| 265 if (i < written_inline_id_stack_.length()) { | 248 if (i < written_inline_id_stack_.length()) { |
| 266 intptr_t written_id = written_inline_id_stack_[i]; | 249 intptr_t written_id = written_inline_id_stack_[i]; |
| 267 if (buffered_id == written_id) { | 250 if (buffered_id == written_id) { |
| 268 // i is the top-most position where the buffered and written stack | 251 // i is the top-most position where the buffered and written stack |
| 269 // match. | 252 // match. |
| 270 while (written_inline_id_stack_.length() > i + 1) { | 253 while (written_inline_id_stack_.length() > i + 1) { |
| 271 WritePop(); | 254 WritePop(); |
| 272 } | 255 } |
| 273 for (intptr_t j = i + 1; j < buffered_inline_id_stack_.length(); j++) { | 256 for (intptr_t j = i + 1; j < buffered_inline_id_stack_.length(); j++) { |
| 274 TokenPosition buffered_pos = buffered_token_pos_stack_[j - 1]; | 257 TokenPosition buffered_pos = buffered_token_pos_stack_[j - 1]; |
| 275 TokenPosition written_pos = written_token_pos_stack_[j - 1]; | 258 TokenPosition written_pos = written_token_pos_stack_[j - 1]; |
| 276 if (buffered_pos != written_pos) { | 259 if (buffered_pos != written_pos) { |
| 277 WriteChangePosition(buffered_pos); | 260 WriteChangePosition(buffered_pos); |
| 278 } | 261 } |
| 279 WritePush(buffered_inline_id_stack_[j]); | 262 WritePush(buffered_inline_id_stack_[j]); |
| 280 } | 263 } |
| 281 return; | 264 return; |
| 282 } | 265 } |
| 283 } | 266 } |
| 284 } | 267 } |
| 285 UNREACHABLE(); | 268 UNREACHABLE(); |
| 286 } | 269 } |
| 287 | 270 |
| 288 | |
| 289 void CodeSourceMapBuilder::FlushBufferPosition() { | 271 void CodeSourceMapBuilder::FlushBufferPosition() { |
| 290 ASSERT(buffered_token_pos_stack_.length() == | 272 ASSERT(buffered_token_pos_stack_.length() == |
| 291 written_token_pos_stack_.length()); | 273 written_token_pos_stack_.length()); |
| 292 | 274 |
| 293 intptr_t top = buffered_token_pos_stack_.length() - 1; | 275 intptr_t top = buffered_token_pos_stack_.length() - 1; |
| 294 TokenPosition buffered_pos = buffered_token_pos_stack_[top]; | 276 TokenPosition buffered_pos = buffered_token_pos_stack_[top]; |
| 295 TokenPosition written_pos = written_token_pos_stack_[top]; | 277 TokenPosition written_pos = written_token_pos_stack_[top]; |
| 296 if (buffered_pos != written_pos) { | 278 if (buffered_pos != written_pos) { |
| 297 WriteChangePosition(buffered_pos); | 279 WriteChangePosition(buffered_pos); |
| 298 } | 280 } |
| 299 } | 281 } |
| 300 | 282 |
| 301 | |
| 302 void CodeSourceMapBuilder::FlushBufferPC() { | 283 void CodeSourceMapBuilder::FlushBufferPC() { |
| 303 if (buffered_pc_offset_ != written_pc_offset_) { | 284 if (buffered_pc_offset_ != written_pc_offset_) { |
| 304 WriteAdvancePC(buffered_pc_offset_ - written_pc_offset_); | 285 WriteAdvancePC(buffered_pc_offset_ - written_pc_offset_); |
| 305 } | 286 } |
| 306 } | 287 } |
| 307 | 288 |
| 308 | |
| 309 void CodeSourceMapBuilder::StartInliningInterval(int32_t pc_offset, | 289 void CodeSourceMapBuilder::StartInliningInterval(int32_t pc_offset, |
| 310 intptr_t inline_id) { | 290 intptr_t inline_id) { |
| 311 if (buffered_inline_id_stack_.Last() == inline_id) { | 291 if (buffered_inline_id_stack_.Last() == inline_id) { |
| 312 // No change in function stack. | 292 // No change in function stack. |
| 313 return; | 293 return; |
| 314 } | 294 } |
| 315 if (inline_id == -1) { | 295 if (inline_id == -1) { |
| 316 // Basic blocking missing an inline_id. | 296 // Basic blocking missing an inline_id. |
| 317 return; | 297 return; |
| 318 } | 298 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 UNREACHABLE(); | 330 UNREACHABLE(); |
| 351 } | 331 } |
| 352 | 332 |
| 353 // Report caller as at the position of the call. | 333 // Report caller as at the position of the call. |
| 354 BufferChangePosition(call_token); | 334 BufferChangePosition(call_token); |
| 355 | 335 |
| 356 BufferPush(callee_id); | 336 BufferPush(callee_id); |
| 357 } | 337 } |
| 358 } | 338 } |
| 359 | 339 |
| 360 | |
| 361 void CodeSourceMapBuilder::BeginCodeSourceRange(int32_t pc_offset) {} | 340 void CodeSourceMapBuilder::BeginCodeSourceRange(int32_t pc_offset) {} |
| 362 | 341 |
| 363 | |
| 364 void CodeSourceMapBuilder::EndCodeSourceRange(int32_t pc_offset, | 342 void CodeSourceMapBuilder::EndCodeSourceRange(int32_t pc_offset, |
| 365 TokenPosition pos) { | 343 TokenPosition pos) { |
| 366 if (pc_offset == buffered_pc_offset_) { | 344 if (pc_offset == buffered_pc_offset_) { |
| 367 return; // Empty intermediate instruction. | 345 return; // Empty intermediate instruction. |
| 368 } | 346 } |
| 369 if (pos != buffered_token_pos_stack_.Last()) { | 347 if (pos != buffered_token_pos_stack_.Last()) { |
| 370 if (!stack_traces_only_) { | 348 if (!stack_traces_only_) { |
| 371 FlushBuffer(); | 349 FlushBuffer(); |
| 372 } | 350 } |
| 373 BufferChangePosition(pos); | 351 BufferChangePosition(pos); |
| 374 } | 352 } |
| 375 BufferAdvancePC(pc_offset - buffered_pc_offset_); | 353 BufferAdvancePC(pc_offset - buffered_pc_offset_); |
| 376 } | 354 } |
| 377 | 355 |
| 378 | |
| 379 void CodeSourceMapBuilder::NoteDescriptor(RawPcDescriptors::Kind kind, | 356 void CodeSourceMapBuilder::NoteDescriptor(RawPcDescriptors::Kind kind, |
| 380 int32_t pc_offset, | 357 int32_t pc_offset, |
| 381 TokenPosition pos) { | 358 TokenPosition pos) { |
| 382 const uint8_t kCanThrow = | 359 const uint8_t kCanThrow = |
| 383 RawPcDescriptors::kIcCall | RawPcDescriptors::kUnoptStaticCall | | 360 RawPcDescriptors::kIcCall | RawPcDescriptors::kUnoptStaticCall | |
| 384 RawPcDescriptors::kRuntimeCall | RawPcDescriptors::kOther; | 361 RawPcDescriptors::kRuntimeCall | RawPcDescriptors::kOther; |
| 385 if (stack_traces_only_ && ((kind & kCanThrow) != 0)) { | 362 if (stack_traces_only_ && ((kind & kCanThrow) != 0)) { |
| 386 BufferChangePosition(pos); | 363 BufferChangePosition(pos); |
| 387 BufferAdvancePC(pc_offset - buffered_pc_offset_); | 364 BufferAdvancePC(pc_offset - buffered_pc_offset_); |
| 388 FlushBuffer(); | 365 FlushBuffer(); |
| 389 } | 366 } |
| 390 } | 367 } |
| 391 | 368 |
| 392 | |
| 393 intptr_t CodeSourceMapBuilder::GetFunctionId(intptr_t inline_id) { | 369 intptr_t CodeSourceMapBuilder::GetFunctionId(intptr_t inline_id) { |
| 394 const Function& function = *inline_id_to_function_[inline_id]; | 370 const Function& function = *inline_id_to_function_[inline_id]; |
| 395 for (intptr_t i = 0; i < inlined_functions_.Length(); i++) { | 371 for (intptr_t i = 0; i < inlined_functions_.Length(); i++) { |
| 396 if (inlined_functions_.At(i) == function.raw()) { | 372 if (inlined_functions_.At(i) == function.raw()) { |
| 397 return i; | 373 return i; |
| 398 } | 374 } |
| 399 } | 375 } |
| 400 inlined_functions_.Add(function, Heap::kOld); | 376 inlined_functions_.Add(function, Heap::kOld); |
| 401 return inlined_functions_.Length() - 1; | 377 return inlined_functions_.Length() - 1; |
| 402 } | 378 } |
| 403 | 379 |
| 404 | |
| 405 RawArray* CodeSourceMapBuilder::InliningIdToFunction() { | 380 RawArray* CodeSourceMapBuilder::InliningIdToFunction() { |
| 406 if (inlined_functions_.Length() == 0) { | 381 if (inlined_functions_.Length() == 0) { |
| 407 return Object::empty_array().raw(); | 382 return Object::empty_array().raw(); |
| 408 } | 383 } |
| 409 return Array::MakeFixedLength(inlined_functions_); | 384 return Array::MakeFixedLength(inlined_functions_); |
| 410 } | 385 } |
| 411 | 386 |
| 412 | |
| 413 RawCodeSourceMap* CodeSourceMapBuilder::Finalize() { | 387 RawCodeSourceMap* CodeSourceMapBuilder::Finalize() { |
| 414 if (!stack_traces_only_) { | 388 if (!stack_traces_only_) { |
| 415 FlushBuffer(); | 389 FlushBuffer(); |
| 416 } | 390 } |
| 417 intptr_t length = stream_.bytes_written(); | 391 intptr_t length = stream_.bytes_written(); |
| 418 const CodeSourceMap& map = CodeSourceMap::Handle(CodeSourceMap::New(length)); | 392 const CodeSourceMap& map = CodeSourceMap::Handle(CodeSourceMap::New(length)); |
| 419 NoSafepointScope no_safepoint; | 393 NoSafepointScope no_safepoint; |
| 420 memmove(map.Data(), buffer_, length); | 394 memmove(map.Data(), buffer_, length); |
| 421 return map.raw(); | 395 return map.raw(); |
| 422 } | 396 } |
| 423 | 397 |
| 424 | |
| 425 void CodeSourceMapBuilder::WriteChangePosition(TokenPosition pos) { | 398 void CodeSourceMapBuilder::WriteChangePosition(TokenPosition pos) { |
| 426 stream_.Write<uint8_t>(kChangePosition); | 399 stream_.Write<uint8_t>(kChangePosition); |
| 427 if (FLAG_precompiled_mode) { | 400 if (FLAG_precompiled_mode) { |
| 428 intptr_t line = -1; | 401 intptr_t line = -1; |
| 429 intptr_t inline_id = buffered_inline_id_stack_.Last(); | 402 intptr_t inline_id = buffered_inline_id_stack_.Last(); |
| 430 if (inline_id < inline_id_to_function_.length()) { | 403 if (inline_id < inline_id_to_function_.length()) { |
| 431 const Function* function = inline_id_to_function_[inline_id]; | 404 const Function* function = inline_id_to_function_[inline_id]; |
| 432 Script& script = Script::Handle(function->script()); | 405 Script& script = Script::Handle(function->script()); |
| 433 line = script.GetTokenLineUsingLineStarts(pos.SourcePosition()); | 406 line = script.GetTokenLineUsingLineStarts(pos.SourcePosition()); |
| 434 } | 407 } |
| 435 stream_.Write<int32_t>(static_cast<int32_t>(line)); | 408 stream_.Write<int32_t>(static_cast<int32_t>(line)); |
| 436 } else { | 409 } else { |
| 437 stream_.Write<int32_t>(static_cast<int32_t>(pos.value())); | 410 stream_.Write<int32_t>(static_cast<int32_t>(pos.value())); |
| 438 } | 411 } |
| 439 written_token_pos_stack_.Last() = pos; | 412 written_token_pos_stack_.Last() = pos; |
| 440 } | 413 } |
| 441 | 414 |
| 442 | |
| 443 void CodeSourceMapReader::GetInlinedFunctionsAt( | 415 void CodeSourceMapReader::GetInlinedFunctionsAt( |
| 444 int32_t pc_offset, | 416 int32_t pc_offset, |
| 445 GrowableArray<const Function*>* function_stack, | 417 GrowableArray<const Function*>* function_stack, |
| 446 GrowableArray<TokenPosition>* token_positions) { | 418 GrowableArray<TokenPosition>* token_positions) { |
| 447 function_stack->Clear(); | 419 function_stack->Clear(); |
| 448 token_positions->Clear(); | 420 token_positions->Clear(); |
| 449 | 421 |
| 450 NoSafepointScope no_safepoint; | 422 NoSafepointScope no_safepoint; |
| 451 ReadStream stream(map_.Data(), map_.Length()); | 423 ReadStream stream(map_.Data(), map_.Length()); |
| 452 | 424 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 function_stack->RemoveLast(); | 457 function_stack->RemoveLast(); |
| 486 token_positions->RemoveLast(); | 458 token_positions->RemoveLast(); |
| 487 break; | 459 break; |
| 488 } | 460 } |
| 489 default: | 461 default: |
| 490 UNREACHABLE(); | 462 UNREACHABLE(); |
| 491 } | 463 } |
| 492 } | 464 } |
| 493 } | 465 } |
| 494 | 466 |
| 495 | |
| 496 #ifndef PRODUCT | 467 #ifndef PRODUCT |
| 497 void CodeSourceMapReader::PrintJSONInlineIntervals(JSONObject* jsobj) { | 468 void CodeSourceMapReader::PrintJSONInlineIntervals(JSONObject* jsobj) { |
| 498 { | 469 { |
| 499 JSONArray inlined_functions(jsobj, "_inlinedFunctions"); | 470 JSONArray inlined_functions(jsobj, "_inlinedFunctions"); |
| 500 Function& function = Function::Handle(); | 471 Function& function = Function::Handle(); |
| 501 for (intptr_t i = 0; i < functions_.Length(); i++) { | 472 for (intptr_t i = 0; i < functions_.Length(); i++) { |
| 502 function ^= functions_.At(i); | 473 function ^= functions_.At(i); |
| 503 ASSERT(!function.IsNull()); | 474 ASSERT(!function.IsNull()); |
| 504 inlined_functions.AddValue(function); | 475 inlined_functions.AddValue(function); |
| 505 } | 476 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 function_stack.RemoveLast(); | 515 function_stack.RemoveLast(); |
| 545 break; | 516 break; |
| 546 } | 517 } |
| 547 default: | 518 default: |
| 548 UNREACHABLE(); | 519 UNREACHABLE(); |
| 549 } | 520 } |
| 550 } | 521 } |
| 551 } | 522 } |
| 552 #endif // !PRODUCT | 523 #endif // !PRODUCT |
| 553 | 524 |
| 554 | |
| 555 void CodeSourceMapReader::DumpInlineIntervals(uword start) { | 525 void CodeSourceMapReader::DumpInlineIntervals(uword start) { |
| 556 GrowableArray<const Function*> function_stack; | 526 GrowableArray<const Function*> function_stack; |
| 557 LogBlock lb; | 527 LogBlock lb; |
| 558 NoSafepointScope no_safepoint; | 528 NoSafepointScope no_safepoint; |
| 559 ReadStream stream(map_.Data(), map_.Length()); | 529 ReadStream stream(map_.Data(), map_.Length()); |
| 560 | 530 |
| 561 int32_t current_pc_offset = 0; | 531 int32_t current_pc_offset = 0; |
| 562 function_stack.Add(&root_); | 532 function_stack.Add(&root_); |
| 563 | 533 |
| 564 THR_Print("Inline intervals {\n"); | 534 THR_Print("Inline intervals {\n"); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 592 function_stack.RemoveLast(); | 562 function_stack.RemoveLast(); |
| 593 break; | 563 break; |
| 594 } | 564 } |
| 595 default: | 565 default: |
| 596 UNREACHABLE(); | 566 UNREACHABLE(); |
| 597 } | 567 } |
| 598 } | 568 } |
| 599 THR_Print("}\n"); | 569 THR_Print("}\n"); |
| 600 } | 570 } |
| 601 | 571 |
| 602 | |
| 603 void CodeSourceMapReader::DumpSourcePositions(uword start) { | 572 void CodeSourceMapReader::DumpSourcePositions(uword start) { |
| 604 GrowableArray<const Function*> function_stack; | 573 GrowableArray<const Function*> function_stack; |
| 605 GrowableArray<TokenPosition> token_positions; | 574 GrowableArray<TokenPosition> token_positions; |
| 606 LogBlock lb; | 575 LogBlock lb; |
| 607 NoSafepointScope no_safepoint; | 576 NoSafepointScope no_safepoint; |
| 608 ReadStream stream(map_.Data(), map_.Length()); | 577 ReadStream stream(map_.Data(), map_.Length()); |
| 609 | 578 |
| 610 int32_t current_pc_offset = 0; | 579 int32_t current_pc_offset = 0; |
| 611 function_stack.Add(&root_); | 580 function_stack.Add(&root_); |
| 612 token_positions.Add(CodeSourceMapBuilder::kInitialPosition); | 581 token_positions.Add(CodeSourceMapBuilder::kInitialPosition); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 648 break; | 617 break; |
| 649 } | 618 } |
| 650 default: | 619 default: |
| 651 UNREACHABLE(); | 620 UNREACHABLE(); |
| 652 } | 621 } |
| 653 } | 622 } |
| 654 THR_Print("}\n"); | 623 THR_Print("}\n"); |
| 655 } | 624 } |
| 656 | 625 |
| 657 } // namespace dart | 626 } // namespace dart |
| OLD | NEW |