| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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/disassembler.h" | 5 #include "vm/disassembler.h" |
| 6 | 6 |
| 7 #include "vm/assembler.h" | 7 #include "vm/assembler.h" |
| 8 #include "vm/deopt_instructions.h" | 8 #include "vm/deopt_instructions.h" |
| 9 #include "vm/globals.h" | 9 #include "vm/globals.h" |
| 10 #include "vm/il_printer.h" | 10 #include "vm/il_printer.h" |
| 11 #include "vm/instructions.h" | 11 #include "vm/instructions.h" |
| 12 #include "vm/json_stream.h" | 12 #include "vm/json_stream.h" |
| 13 #include "vm/log.h" | 13 #include "vm/log.h" |
| 14 #include "vm/os.h" | 14 #include "vm/os.h" |
| 15 #include "vm/code_patcher.h" | 15 #include "vm/code_patcher.h" |
| 16 | 16 |
| 17 | 17 |
| 18 namespace dart { | 18 namespace dart { |
| 19 | 19 |
| 20 #ifndef PRODUCT | 20 #ifndef PRODUCT |
| 21 | 21 |
| 22 DECLARE_FLAG(bool, trace_inlining_intervals); | 22 DECLARE_FLAG(bool, trace_inlining_intervals); |
| 23 DEFINE_FLAG(bool, trace_source_positions, false, "Source position diagnostics"); |
| 23 | 24 |
| 24 void DisassembleToStdout::ConsumeInstruction(const Code& code, | 25 void DisassembleToStdout::ConsumeInstruction(const Code& code, |
| 25 char* hex_buffer, | 26 char* hex_buffer, |
| 26 intptr_t hex_size, | 27 intptr_t hex_size, |
| 27 char* human_buffer, | 28 char* human_buffer, |
| 28 intptr_t human_size, | 29 intptr_t human_size, |
| 29 Object* object, | 30 Object* object, |
| 30 uword pc) { | 31 uword pc) { |
| 31 static const int kHexColumnWidth = 23; | 32 static const int kHexColumnWidth = 23; |
| 32 uint8_t* pc_ptr = reinterpret_cast<uint8_t*>(pc); | 33 uint8_t* pc_ptr = reinterpret_cast<uint8_t*>(pc); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 uword end, | 106 uword end, |
| 106 DisassemblyFormatter* formatter, | 107 DisassemblyFormatter* formatter, |
| 107 const Code& code) { | 108 const Code& code) { |
| 108 const Code::Comments& comments = | 109 const Code::Comments& comments = |
| 109 code.IsNull() ? Code::Comments::New(0) : code.comments(); | 110 code.IsNull() ? Code::Comments::New(0) : code.comments(); |
| 110 ASSERT(formatter != NULL); | 111 ASSERT(formatter != NULL); |
| 111 char hex_buffer[kHexadecimalBufferSize]; // Instruction in hexadecimal form. | 112 char hex_buffer[kHexadecimalBufferSize]; // Instruction in hexadecimal form. |
| 112 char human_buffer[kUserReadableBufferSize]; // Human-readable instruction. | 113 char human_buffer[kUserReadableBufferSize]; // Human-readable instruction. |
| 113 uword pc = start; | 114 uword pc = start; |
| 114 intptr_t comment_finger = 0; | 115 intptr_t comment_finger = 0; |
| 115 GrowableArray<Function*> inlined_functions; | 116 GrowableArray<const Function*> inlined_functions; |
| 117 GrowableArray<TokenPosition> token_positions; |
| 116 while (pc < end) { | 118 while (pc < end) { |
| 117 const intptr_t offset = pc - start; | 119 const intptr_t offset = pc - start; |
| 118 const intptr_t old_comment_finger = comment_finger; | 120 const intptr_t old_comment_finger = comment_finger; |
| 119 while (comment_finger < comments.Length() && | 121 while (comment_finger < comments.Length() && |
| 120 comments.PCOffsetAt(comment_finger) <= offset) { | 122 comments.PCOffsetAt(comment_finger) <= offset) { |
| 121 formatter->Print( | 123 formatter->Print( |
| 122 " ;; %s\n", | 124 " ;; %s\n", |
| 123 String::Handle(comments.CommentAt(comment_finger)).ToCString()); | 125 String::Handle(comments.CommentAt(comment_finger)).ToCString()); |
| 124 comment_finger++; | 126 comment_finger++; |
| 125 } | 127 } |
| 126 if (old_comment_finger != comment_finger) { | 128 if (old_comment_finger != comment_finger) { |
| 127 char str[4000]; | 129 char str[4000]; |
| 128 BufferFormatter f(str, sizeof(str)); | 130 BufferFormatter f(str, sizeof(str)); |
| 129 // Comment emitted, emit inlining information. | 131 // Comment emitted, emit inlining information. |
| 130 code.GetInlinedFunctionsAt(offset, &inlined_functions); | 132 code.GetInlinedFunctionsAt(offset, &inlined_functions, &token_positions); |
| 131 // Skip top scope function printing (last entry in 'inlined_functions'). | 133 // Skip top scope function printing (last entry in 'inlined_functions'). |
| 132 bool first = true; | 134 bool first = true; |
| 133 for (intptr_t i = inlined_functions.length() - 2; i >= 0; i--) { | 135 for (intptr_t i = 1; i < inlined_functions.length(); i++) { |
| 134 const char* name = inlined_functions[i]->ToQualifiedCString(); | 136 const char* name = inlined_functions[i]->ToQualifiedCString(); |
| 135 if (first) { | 137 if (first) { |
| 136 f.Print(" ;; Inlined [%s", name); | 138 f.Print(" ;; Inlined [%s", name); |
| 137 first = false; | 139 first = false; |
| 138 } else { | 140 } else { |
| 139 f.Print(" -> %s", name); | 141 f.Print(" -> %s", name); |
| 140 } | 142 } |
| 141 } | 143 } |
| 142 if (!first) { | 144 if (!first) { |
| 143 f.Print("]\n"); | 145 f.Print("]\n"); |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 start + offset.Value(), cls.ToCString(), code.raw()); | 285 start + offset.Value(), cls.ToCString(), code.raw()); |
| 284 } | 286 } |
| 285 } else { | 287 } else { |
| 286 THR_Print(" 0x%" Px ": %s, %p\n", start + offset.Value(), | 288 THR_Print(" 0x%" Px ": %s, %p\n", start + offset.Value(), |
| 287 function.ToFullyQualifiedCString(), code.raw()); | 289 function.ToFullyQualifiedCString(), code.raw()); |
| 288 } | 290 } |
| 289 } | 291 } |
| 290 THR_Print("}\n"); | 292 THR_Print("}\n"); |
| 291 } | 293 } |
| 292 if (optimized && FLAG_trace_inlining_intervals) { | 294 if (optimized && FLAG_trace_inlining_intervals) { |
| 293 code.DumpInlinedIntervals(); | 295 code.DumpInlineIntervals(); |
| 296 } |
| 297 if (FLAG_trace_source_positions) { |
| 298 code.DumpSourcePositions(); |
| 294 } | 299 } |
| 295 } | 300 } |
| 296 | 301 |
| 297 | 302 |
| 298 void Disassembler::DisassembleCode(const Function& function, bool optimized) { | 303 void Disassembler::DisassembleCode(const Function& function, bool optimized) { |
| 299 const char* function_fullname = function.ToFullyQualifiedCString(); | 304 const char* function_fullname = function.ToFullyQualifiedCString(); |
| 300 const Code& code = Code::Handle(function.CurrentCode()); | 305 const Code& code = Code::Handle(function.CurrentCode()); |
| 301 DisassembleCodeHelper(function_fullname, code, optimized); | 306 DisassembleCodeHelper(function_fullname, code, optimized); |
| 302 } | 307 } |
| 303 | 308 |
| 304 | 309 |
| 305 void Disassembler::DisassembleCodeUnoptimized(const Function& function, | 310 void Disassembler::DisassembleCodeUnoptimized(const Function& function, |
| 306 bool optimized) { | 311 bool optimized) { |
| 307 const char* function_fullname = function.ToFullyQualifiedCString(); | 312 const char* function_fullname = function.ToFullyQualifiedCString(); |
| 308 const Code& code = Code::Handle(function.unoptimized_code()); | 313 const Code& code = Code::Handle(function.unoptimized_code()); |
| 309 DisassembleCodeHelper(function_fullname, code, optimized); | 314 DisassembleCodeHelper(function_fullname, code, optimized); |
| 310 } | 315 } |
| 311 | 316 |
| 312 | 317 |
| 313 #endif // !PRODUCT | 318 #endif // !PRODUCT |
| 314 | 319 |
| 315 } // namespace dart | 320 } // namespace dart |
| OLD | NEW |