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

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

Issue 1331623002: Uses SNPRINT macro where possible. Otherwise uses #define for format. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Add back assembler functions Created 5 years, 3 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
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 #include "vm/globals.h" 5 #include "vm/globals.h"
6 #if defined(TARGET_OS_LINUX) 6 #if defined(TARGET_OS_LINUX)
7 7
8 #include "vm/os.h" 8 #include "vm/os.h"
9 9
10 #include <errno.h> // NOLINT 10 #include <errno.h> // NOLINT
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 "Writes jitdump data for profiling with perf annotate"); 42 "Writes jitdump data for profiling with perf annotate");
43 43
44 44
45 class PerfCodeObserver : public CodeObserver { 45 class PerfCodeObserver : public CodeObserver {
46 public: 46 public:
47 PerfCodeObserver() : out_file_(NULL) { 47 PerfCodeObserver() : out_file_(NULL) {
48 Dart_FileOpenCallback file_open = Isolate::file_open_callback(); 48 Dart_FileOpenCallback file_open = Isolate::file_open_callback();
49 if (file_open == NULL) { 49 if (file_open == NULL) {
50 return; 50 return;
51 } 51 }
52 const char* format = "/tmp/perf-%" Pd ".map";
53 intptr_t pid = getpid(); 52 intptr_t pid = getpid();
54 intptr_t len = OS::SNPrint(NULL, 0, format, pid); 53 char* filename = OS::SNCreate(NULL, "/tmp/perf-%" Pd ".map", pid);
55 char* filename = new char[len + 1];
56 OS::SNPrint(filename, len + 1, format, pid);
57 out_file_ = (*file_open)(filename, true); 54 out_file_ = (*file_open)(filename, true);
58 delete[] filename; 55 free(filename);
59 } 56 }
60 57
61 ~PerfCodeObserver() { 58 ~PerfCodeObserver() {
62 Dart_FileCloseCallback file_close = Isolate::file_close_callback(); 59 Dart_FileCloseCallback file_close = Isolate::file_close_callback();
63 if ((file_close == NULL) || (out_file_ == NULL)) { 60 if ((file_close == NULL) || (out_file_ == NULL)) {
64 return; 61 return;
65 } 62 }
66 (*file_close)(out_file_); 63 (*file_close)(out_file_);
67 } 64 }
68 65
69 virtual bool IsActive() const { 66 virtual bool IsActive() const {
70 return FLAG_generate_perf_events_symbols && (out_file_ != NULL); 67 return FLAG_generate_perf_events_symbols && (out_file_ != NULL);
71 } 68 }
72 69
73 virtual void Notify(const char* name, 70 virtual void Notify(const char* name,
74 uword base, 71 uword base,
75 uword prologue_offset, 72 uword prologue_offset,
76 uword size, 73 uword size,
77 bool optimized) { 74 bool optimized) {
78 Dart_FileWriteCallback file_write = Isolate::file_write_callback(); 75 Dart_FileWriteCallback file_write = Isolate::file_write_callback();
79 if ((file_write == NULL) || (out_file_ == NULL)) { 76 if ((file_write == NULL) || (out_file_ == NULL)) {
80 return; 77 return;
81 } 78 }
82 const char* format = "%" Px " %" Px " %s%s\n";
83 const char* marker = optimized ? "*" : ""; 79 const char* marker = optimized ? "*" : "";
84 intptr_t len = OS::SNPrint(NULL, 0, format, base, size, marker, name); 80 char* buffer = OS::SNCreate(Thread::Current()->zone(),
85 char* buffer = Thread::Current()->zone()->Alloc<char>(len + 1); 81 "%" Px " %" Px " %s%s\n", base, size, marker, name);
86 OS::SNPrint(buffer, len + 1, format, base, size, marker, name);
87 { 82 {
88 MutexLocker ml(CodeObservers::mutex()); 83 MutexLocker ml(CodeObservers::mutex());
89 (*file_write)(buffer, len, out_file_); 84 (*file_write)(buffer, strlen(buffer), out_file_);
90 } 85 }
91 } 86 }
92 87
93 private: 88 private:
94 void* out_file_; 89 void* out_file_;
95 90
96 DISALLOW_COPY_AND_ASSIGN(PerfCodeObserver); 91 DISALLOW_COPY_AND_ASSIGN(PerfCodeObserver);
97 }; 92 };
98 93
99 94
100 class GdbCodeObserver : public CodeObserver { 95 class GdbCodeObserver : public CodeObserver {
101 public: 96 public:
102 GdbCodeObserver() { } 97 GdbCodeObserver() { }
103 98
104 virtual bool IsActive() const { 99 virtual bool IsActive() const {
105 return FLAG_generate_gdb_symbols; 100 return FLAG_generate_gdb_symbols;
106 } 101 }
107 102
108 virtual void Notify(const char* name, 103 virtual void Notify(const char* name,
109 uword base, 104 uword base,
110 uword prologue_offset, 105 uword prologue_offset,
111 uword size, 106 uword size,
112 bool optimized) { 107 bool optimized) {
113 if (prologue_offset > 0) { 108 if (prologue_offset > 0) {
114 // In order to ensure that gdb sees the first instruction of a function 109 // In order to ensure that gdb sees the first instruction of a function
115 // as the prologue sequence we register two symbols for the cases when 110 // as the prologue sequence we register two symbols for the cases when
116 // the prologue sequence is not the first instruction: 111 // the prologue sequence is not the first instruction:
117 // <name>_entry is used for code preceding the prologue sequence. 112 // <name>_entry is used for code preceding the prologue sequence.
118 // <name> for rest of the code (first instruction is prologue sequence). 113 // <name> for rest of the code (first instruction is prologue sequence).
119 const char* kFormat = "%s_%s"; 114 char* pname = OS::SNCreate(Thread::Current()->zone(),
120 intptr_t len = OS::SNPrint(NULL, 0, kFormat, name, "entry"); 115 "%s_%s", name, "entry");
121 char* pname = Thread::Current()->zone()->Alloc<char>(len + 1);
122 OS::SNPrint(pname, (len + 1), kFormat, name, "entry");
123 DebugInfo::RegisterSection(pname, base, size); 116 DebugInfo::RegisterSection(pname, base, size);
124 DebugInfo::RegisterSection(name, 117 DebugInfo::RegisterSection(name,
125 (base + prologue_offset), 118 (base + prologue_offset),
126 (size - prologue_offset)); 119 (size - prologue_offset));
127 } else { 120 } else {
128 DebugInfo::RegisterSection(name, base, size); 121 DebugInfo::RegisterSection(name, base, size);
129 } 122 }
130 } 123 }
131 124
132 private: 125 private:
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 struct jr_prefix prefix; 231 struct jr_prefix prefix;
239 uint32_t pid; 232 uint32_t pid;
240 uint32_t tid; 233 uint32_t tid;
241 uint64_t vma; 234 uint64_t vma;
242 uint64_t code_addr; 235 uint64_t code_addr;
243 uint64_t code_size; 236 uint64_t code_size;
244 uint64_t code_index; 237 uint64_t code_index;
245 }; 238 };
246 239
247 const char* GenerateCodeName(const char* name, bool optimized) { 240 const char* GenerateCodeName(const char* name, bool optimized) {
248 const char* format = "%s%s";
249 const char* marker = optimized ? "*" : ""; 241 const char* marker = optimized ? "*" : "";
250 intptr_t len = OS::SNPrint(NULL, 0, format, marker, name); 242 return OS::SNCreate(Thread::Current()->zone(), "%s%s", marker, name);
251 char* buffer = Thread::Current()->zone()->Alloc<char>(len + 1);
252 OS::SNPrint(buffer, len + 1, format, marker, name);
253 return buffer;
254 } 243 }
255 244
256 uint32_t GetElfMach() { 245 uint32_t GetElfMach() {
257 #if defined(TARGET_ARCH_IA32) 246 #if defined(TARGET_ARCH_IA32)
258 return kElfMachIA32; 247 return kElfMachIA32;
259 #elif defined(TARGET_ARCH_X64) 248 #elif defined(TARGET_ARCH_X64)
260 return kElfMachX64; 249 return kElfMachX64;
261 #elif defined(TARGET_ARCH_ARM) 250 #elif defined(TARGET_ARCH_ARM)
262 return kElfMachARM; 251 return kElfMachARM;
263 #elif defined(TARGET_ARCH_ARM64) 252 #elif defined(TARGET_ARCH_ARM64)
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 522
534 int OS::SNPrint(char* str, size_t size, const char* format, ...) { 523 int OS::SNPrint(char* str, size_t size, const char* format, ...) {
535 va_list args; 524 va_list args;
536 va_start(args, format); 525 va_start(args, format);
537 int retval = VSNPrint(str, size, format, args); 526 int retval = VSNPrint(str, size, format, args);
538 va_end(args); 527 va_end(args);
539 return retval; 528 return retval;
540 } 529 }
541 530
542 531
532 char* OS::SNCreate(Zone* zone, const char* format, ...) {
533 va_list args;
534 va_start(args, format);
535
536 // Measure.
537 va_list measure_args;
538 va_copy(measure_args, args);
539 intptr_t len = VSNPrint(NULL, 0, format, measure_args);
540 va_end(measure_args);
541
542 char* buffer;
543 if (zone) {
544 buffer = zone->Alloc<char>(len + 1);
545 } else {
546 buffer = reinterpret_cast<char*>(malloc(len + 1));
547 }
548 ASSERT(buffer != NULL);
549
550 // Print.
551 va_list print_args;
552 va_copy(print_args, args);
553 VSNPrint(buffer, len + 1, format, print_args);
554 va_end(print_args);
555 va_end(args);
556 return buffer;
557 }
558
559
543 int OS::VSNPrint(char* str, size_t size, const char* format, va_list args) { 560 int OS::VSNPrint(char* str, size_t size, const char* format, va_list args) {
544 int retval = vsnprintf(str, size, format, args); 561 int retval = vsnprintf(str, size, format, args);
545 if (retval < 0) { 562 if (retval < 0) {
546 FATAL1("Fatal error in OS::VSNPrint with format '%s'", format); 563 FATAL1("Fatal error in OS::VSNPrint with format '%s'", format);
547 } 564 }
548 return retval; 565 return retval;
549 } 566 }
550 567
551 568
552 bool OS::StringToInt64(const char* str, int64_t* value) { 569 bool OS::StringToInt64(const char* str, int64_t* value) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 } 628 }
612 629
613 630
614 void OS::Exit(int code) { 631 void OS::Exit(int code) {
615 exit(code); 632 exit(code);
616 } 633 }
617 634
618 } // namespace dart 635 } // namespace dart
619 636
620 #endif // defined(TARGET_OS_LINUX) 637 #endif // defined(TARGET_OS_LINUX)
OLDNEW
« runtime/vm/os_android.cc ('K') | « runtime/vm/os_android.cc ('k') | runtime/vm/os_macos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698