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

Side by Side Diff: runtime/vm/disassembler.cc

Issue 2363413004: VM: Avoid allocating strings when disassembling code. (Closed)
Patch Set: addressed comments Created 4 years, 2 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/compiler.cc ('k') | runtime/vm/object.h » ('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) 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"
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 jsarr_.AddValue(p); 98 jsarr_.AddValue(p);
99 jsarr_.AddValueNull(); 99 jsarr_.AddValueNull();
100 free(p); 100 free(p);
101 } 101 }
102 102
103 103
104 void Disassembler::Disassemble(uword start, 104 void Disassembler::Disassemble(uword start,
105 uword end, 105 uword end,
106 DisassemblyFormatter* formatter, 106 DisassemblyFormatter* formatter,
107 const Code& code) { 107 const Code& code) {
108 NoSafepointScope no_safepoint;
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<Function*> inlined_functions;
116 while (pc < end) { 117 while (pc < end) {
117 const intptr_t offset = pc - start; 118 const intptr_t offset = pc - start;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 sizeof(human_buffer), 159 sizeof(human_buffer),
159 object, 160 object,
160 pc); 161 pc);
161 pc += instruction_length; 162 pc += instruction_length;
162 } 163 }
163 } 164 }
164 165
165 166
166 void Disassembler::DisassembleCodeHelper( 167 void Disassembler::DisassembleCodeHelper(
167 const char* function_fullname, const Code& code, bool optimized) { 168 const char* function_fullname, const Code& code, bool optimized) {
169 LocalVarDescriptors& var_descriptors = LocalVarDescriptors::Handle();
170 if (FLAG_print_variable_descriptors) {
171 // This flag is not on by default, and for debugging purposes only.
172 // Since this may allocate, do it outside the NoSafepointScope.
173 var_descriptors = code.GetLocalVarDescriptors();
174 }
175 NoSafepointScope no_safepoint;
168 THR_Print("Code for %sfunction '%s' {\n", 176 THR_Print("Code for %sfunction '%s' {\n",
169 optimized ? "optimized " : "", 177 optimized ? "optimized " : "",
170 function_fullname); 178 function_fullname);
171 code.Disassemble(); 179 code.Disassemble();
172 THR_Print("}\n"); 180 THR_Print("}\n");
173 181
174 #if defined(TARGET_ARCH_IA32) 182 #if defined(TARGET_ARCH_IA32)
175 THR_Print("Pointer offsets for function: {\n"); 183 THR_Print("Pointer offsets for function: {\n");
176 // Pointer offsets are stored in descending order. 184 // Pointer offsets are stored in descending order.
177 Object& obj = Object::Handle(); 185 Object& obj = Object::Handle();
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 for (intptr_t i = 0; i < stackmap_table.Length(); ++i) { 233 for (intptr_t i = 0; i < stackmap_table.Length(); ++i) {
226 map ^= stackmap_table.At(i); 234 map ^= stackmap_table.At(i);
227 THR_Print("%s\n", map.ToCString()); 235 THR_Print("%s\n", map.ToCString());
228 } 236 }
229 } 237 }
230 THR_Print("}\n"); 238 THR_Print("}\n");
231 239
232 if (FLAG_print_variable_descriptors) { 240 if (FLAG_print_variable_descriptors) {
233 THR_Print("Variable Descriptors for function '%s' {\n", 241 THR_Print("Variable Descriptors for function '%s' {\n",
234 function_fullname); 242 function_fullname);
235 const LocalVarDescriptors& var_descriptors =
236 LocalVarDescriptors::Handle(code.GetLocalVarDescriptors());
237 intptr_t var_desc_length = 243 intptr_t var_desc_length =
238 var_descriptors.IsNull() ? 0 : var_descriptors.Length(); 244 var_descriptors.IsNull() ? 0 : var_descriptors.Length();
239 String& var_name = String::Handle(); 245 String& var_name = String::Handle();
240 for (intptr_t i = 0; i < var_desc_length; i++) { 246 for (intptr_t i = 0; i < var_desc_length; i++) {
241 var_name = var_descriptors.GetName(i); 247 var_name = var_descriptors.GetName(i);
242 RawLocalVarDescriptors::VarInfo var_info; 248 RawLocalVarDescriptors::VarInfo var_info;
243 var_descriptors.GetInfo(i, &var_info); 249 var_descriptors.GetInfo(i, &var_info);
244 const int8_t kind = var_info.kind(); 250 const int8_t kind = var_info.kind();
245 if (kind == RawLocalVarDescriptors::kSavedCurrentContext) { 251 if (kind == RawLocalVarDescriptors::kSavedCurrentContext) {
246 THR_Print(" saved current CTX reg offset %d\n", var_info.index()); 252 THR_Print(" saved current CTX reg offset %d\n", var_info.index());
(...skipping 29 matching lines...) Expand all
276 Code& code = Code::Handle(); 282 Code& code = Code::Handle();
277 for (intptr_t i = 0; i < table.Length(); 283 for (intptr_t i = 0; i < table.Length();
278 i += Code::kSCallTableEntryLength) { 284 i += Code::kSCallTableEntryLength) {
279 offset ^= table.At(i + Code::kSCallTableOffsetEntry); 285 offset ^= table.At(i + Code::kSCallTableOffsetEntry);
280 function ^= table.At(i + Code::kSCallTableFunctionEntry); 286 function ^= table.At(i + Code::kSCallTableFunctionEntry);
281 code ^= table.At(i + Code::kSCallTableCodeEntry); 287 code ^= table.At(i + Code::kSCallTableCodeEntry);
282 if (function.IsNull()) { 288 if (function.IsNull()) {
283 Class& cls = Class::Handle(); 289 Class& cls = Class::Handle();
284 cls ^= code.owner(); 290 cls ^= code.owner();
285 if (cls.IsNull()) { 291 if (cls.IsNull()) {
286 const String& code_name = String::Handle(code.Name());
287 THR_Print(" 0x%" Px ": %s, %p\n", 292 THR_Print(" 0x%" Px ": %s, %p\n",
288 start + offset.Value(), 293 start + offset.Value(),
289 code_name.ToCString(), 294 code.Name(),
290 code.raw()); 295 code.raw());
291 } else { 296 } else {
292 THR_Print(" 0x%" Px ": allocation stub for %s, %p\n", 297 THR_Print(" 0x%" Px ": allocation stub for %s, %p\n",
293 start + offset.Value(), 298 start + offset.Value(),
294 cls.ToCString(), 299 cls.ToCString(),
295 code.raw()); 300 code.raw());
296 } 301 }
297 } else { 302 } else {
298 THR_Print(" 0x%" Px ": %s, %p\n", 303 THR_Print(" 0x%" Px ": %s, %p\n",
299 start + offset.Value(), 304 start + offset.Value(),
(...skipping 20 matching lines...) Expand all
320 const Function& function, bool optimized) { 325 const Function& function, bool optimized) {
321 const char* function_fullname = function.ToFullyQualifiedCString(); 326 const char* function_fullname = function.ToFullyQualifiedCString();
322 const Code& code = Code::Handle(function.unoptimized_code()); 327 const Code& code = Code::Handle(function.unoptimized_code());
323 DisassembleCodeHelper(function_fullname, code, optimized); 328 DisassembleCodeHelper(function_fullname, code, optimized);
324 } 329 }
325 330
326 331
327 #endif // !PRODUCT 332 #endif // !PRODUCT
328 333
329 } // namespace dart 334 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/compiler.cc ('k') | runtime/vm/object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698