OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 namespace internal { | 47 namespace internal { |
48 | 48 |
49 | 49 |
50 #define DECLARE_EVENT(ignore1, name) name, | 50 #define DECLARE_EVENT(ignore1, name) name, |
51 static const char* const kLogEventsNames[Logger::NUMBER_OF_LOG_EVENTS] = { | 51 static const char* const kLogEventsNames[Logger::NUMBER_OF_LOG_EVENTS] = { |
52 LOG_EVENTS_AND_TAGS_LIST(DECLARE_EVENT) | 52 LOG_EVENTS_AND_TAGS_LIST(DECLARE_EVENT) |
53 }; | 53 }; |
54 #undef DECLARE_EVENT | 54 #undef DECLARE_EVENT |
55 | 55 |
56 | 56 |
| 57 #define CALL_LISTENERS(Call) \ |
| 58 for (int i = 0; i < listeners_.length(); ++i) { \ |
| 59 listeners_[i]->Call; \ |
| 60 } |
| 61 |
57 #define PROFILER_LOG(Call) \ | 62 #define PROFILER_LOG(Call) \ |
58 do { \ | 63 do { \ |
59 CpuProfiler* cpu_profiler = isolate_->cpu_profiler(); \ | 64 CpuProfiler* cpu_profiler = isolate_->cpu_profiler(); \ |
60 if (cpu_profiler->is_profiling()) { \ | 65 if (cpu_profiler->is_profiling()) { \ |
61 cpu_profiler->Call; \ | 66 cpu_profiler->Call; \ |
62 } \ | 67 } \ |
63 } while (false); | 68 } while (false); |
64 | 69 |
65 // ComputeMarker must only be used when SharedFunctionInfo is known. | 70 // ComputeMarker must only be used when SharedFunctionInfo is known. |
66 static const char* ComputeMarker(Code* code) { | 71 static const char* ComputeMarker(Code* code) { |
67 switch (code->kind()) { | 72 switch (code->kind()) { |
68 case Code::FUNCTION: return code->optimizable() ? "~" : ""; | 73 case Code::FUNCTION: return code->optimizable() ? "~" : ""; |
69 case Code::OPTIMIZED_FUNCTION: return "*"; | 74 case Code::OPTIMIZED_FUNCTION: return "*"; |
70 default: return ""; | 75 default: return ""; |
71 } | 76 } |
72 } | 77 } |
73 | 78 |
74 | 79 |
75 class CodeEventLogger { | 80 class CodeEventLogger::NameBuffer { |
76 public: | 81 public: |
77 virtual ~CodeEventLogger() { } | 82 NameBuffer() { Reset(); } |
78 | 83 |
79 void CodeCreateEvent(Logger::LogEventsAndTags tag, | 84 void Reset() { |
80 Code* code, | 85 utf8_pos_ = 0; |
81 const char* comment); | 86 } |
82 void CodeCreateEvent(Logger::LogEventsAndTags tag, | |
83 Code* code, | |
84 Name* name); | |
85 void CodeCreateEvent(Logger::LogEventsAndTags tag, | |
86 Code* code, | |
87 int args_count); | |
88 void CodeCreateEvent(Logger::LogEventsAndTags tag, | |
89 Code* code, | |
90 SharedFunctionInfo* shared, | |
91 CompilationInfo* info, | |
92 Name* name); | |
93 void CodeCreateEvent(Logger::LogEventsAndTags tag, | |
94 Code* code, | |
95 SharedFunctionInfo* shared, | |
96 CompilationInfo* info, | |
97 Name* source, | |
98 int line); | |
99 void RegExpCodeCreateEvent(Code* code, String* source); | |
100 | 87 |
101 protected: | 88 void Init(Logger::LogEventsAndTags tag) { |
102 class NameBuffer { | 89 Reset(); |
103 public: | 90 AppendBytes(kLogEventsNames[tag]); |
104 NameBuffer() { Reset(); } | 91 AppendByte(':'); |
| 92 } |
105 | 93 |
106 void Reset() { | 94 void AppendName(Name* name) { |
107 utf8_pos_ = 0; | 95 if (name->IsString()) { |
| 96 AppendString(String::cast(name)); |
| 97 } else { |
| 98 Symbol* symbol = Symbol::cast(name); |
| 99 AppendBytes("symbol("); |
| 100 if (!symbol->name()->IsUndefined()) { |
| 101 AppendBytes("\""); |
| 102 AppendString(String::cast(symbol->name())); |
| 103 AppendBytes("\" "); |
| 104 } |
| 105 AppendBytes("hash "); |
| 106 AppendHex(symbol->Hash()); |
| 107 AppendByte(')'); |
108 } | 108 } |
| 109 } |
109 | 110 |
110 void Init(Logger::LogEventsAndTags tag) { | 111 void AppendString(String* str) { |
111 Reset(); | 112 if (str == NULL) return; |
112 AppendBytes(kLogEventsNames[tag]); | 113 int uc16_length = Min(str->length(), kUtf16BufferSize); |
113 AppendByte(':'); | 114 String::WriteToFlat(str, utf16_buffer, 0, uc16_length); |
| 115 int previous = unibrow::Utf16::kNoPreviousCharacter; |
| 116 for (int i = 0; i < uc16_length && utf8_pos_ < kUtf8BufferSize; ++i) { |
| 117 uc16 c = utf16_buffer[i]; |
| 118 if (c <= unibrow::Utf8::kMaxOneByteChar) { |
| 119 utf8_buffer_[utf8_pos_++] = static_cast<char>(c); |
| 120 } else { |
| 121 int char_length = unibrow::Utf8::Length(c, previous); |
| 122 if (utf8_pos_ + char_length > kUtf8BufferSize) break; |
| 123 unibrow::Utf8::Encode(utf8_buffer_ + utf8_pos_, c, previous); |
| 124 utf8_pos_ += char_length; |
| 125 } |
| 126 previous = c; |
114 } | 127 } |
| 128 } |
115 | 129 |
116 void AppendName(Name* name) { | 130 void AppendBytes(const char* bytes, int size) { |
117 if (name->IsString()) { | 131 size = Min(size, kUtf8BufferSize - utf8_pos_); |
118 AppendString(String::cast(name)); | 132 OS::MemCopy(utf8_buffer_ + utf8_pos_, bytes, size); |
119 } else { | 133 utf8_pos_ += size; |
120 Symbol* symbol = Symbol::cast(name); | 134 } |
121 AppendBytes("symbol("); | |
122 if (!symbol->name()->IsUndefined()) { | |
123 AppendBytes("\""); | |
124 AppendString(String::cast(symbol->name())); | |
125 AppendBytes("\" "); | |
126 } | |
127 AppendBytes("hash "); | |
128 AppendHex(symbol->Hash()); | |
129 AppendByte(')'); | |
130 } | |
131 } | |
132 | 135 |
133 void AppendString(String* str) { | 136 void AppendBytes(const char* bytes) { |
134 if (str == NULL) return; | 137 AppendBytes(bytes, StrLength(bytes)); |
135 int uc16_length = Min(str->length(), kUtf16BufferSize); | 138 } |
136 String::WriteToFlat(str, utf16_buffer, 0, uc16_length); | |
137 int previous = unibrow::Utf16::kNoPreviousCharacter; | |
138 for (int i = 0; i < uc16_length && utf8_pos_ < kUtf8BufferSize; ++i) { | |
139 uc16 c = utf16_buffer[i]; | |
140 if (c <= unibrow::Utf8::kMaxOneByteChar) { | |
141 utf8_buffer_[utf8_pos_++] = static_cast<char>(c); | |
142 } else { | |
143 int char_length = unibrow::Utf8::Length(c, previous); | |
144 if (utf8_pos_ + char_length > kUtf8BufferSize) break; | |
145 unibrow::Utf8::Encode(utf8_buffer_ + utf8_pos_, c, previous); | |
146 utf8_pos_ += char_length; | |
147 } | |
148 previous = c; | |
149 } | |
150 } | |
151 | 139 |
152 void AppendBytes(const char* bytes, int size) { | 140 void AppendByte(char c) { |
153 size = Min(size, kUtf8BufferSize - utf8_pos_); | 141 if (utf8_pos_ >= kUtf8BufferSize) return; |
154 OS::MemCopy(utf8_buffer_ + utf8_pos_, bytes, size); | 142 utf8_buffer_[utf8_pos_++] = c; |
| 143 } |
| 144 |
| 145 void AppendInt(int n) { |
| 146 Vector<char> buffer(utf8_buffer_ + utf8_pos_, |
| 147 kUtf8BufferSize - utf8_pos_); |
| 148 int size = OS::SNPrintF(buffer, "%d", n); |
| 149 if (size > 0 && utf8_pos_ + size <= kUtf8BufferSize) { |
155 utf8_pos_ += size; | 150 utf8_pos_ += size; |
156 } | 151 } |
| 152 } |
157 | 153 |
158 void AppendBytes(const char* bytes) { | 154 void AppendHex(uint32_t n) { |
159 AppendBytes(bytes, StrLength(bytes)); | 155 Vector<char> buffer(utf8_buffer_ + utf8_pos_, |
| 156 kUtf8BufferSize - utf8_pos_); |
| 157 int size = OS::SNPrintF(buffer, "%x", n); |
| 158 if (size > 0 && utf8_pos_ + size <= kUtf8BufferSize) { |
| 159 utf8_pos_ += size; |
160 } | 160 } |
| 161 } |
161 | 162 |
162 void AppendByte(char c) { | 163 const char* get() { return utf8_buffer_; } |
163 if (utf8_pos_ >= kUtf8BufferSize) return; | 164 int size() const { return utf8_pos_; } |
164 utf8_buffer_[utf8_pos_++] = c; | |
165 } | |
166 | |
167 void AppendInt(int n) { | |
168 Vector<char> buffer(utf8_buffer_ + utf8_pos_, | |
169 kUtf8BufferSize - utf8_pos_); | |
170 int size = OS::SNPrintF(buffer, "%d", n); | |
171 if (size > 0 && utf8_pos_ + size <= kUtf8BufferSize) { | |
172 utf8_pos_ += size; | |
173 } | |
174 } | |
175 | |
176 void AppendHex(uint32_t n) { | |
177 Vector<char> buffer(utf8_buffer_ + utf8_pos_, | |
178 kUtf8BufferSize - utf8_pos_); | |
179 int size = OS::SNPrintF(buffer, "%x", n); | |
180 if (size > 0 && utf8_pos_ + size <= kUtf8BufferSize) { | |
181 utf8_pos_ += size; | |
182 } | |
183 } | |
184 | |
185 const char* get() { return utf8_buffer_; } | |
186 int size() const { return utf8_pos_; } | |
187 | |
188 private: | |
189 static const int kUtf8BufferSize = 512; | |
190 static const int kUtf16BufferSize = 128; | |
191 | |
192 int utf8_pos_; | |
193 char utf8_buffer_[kUtf8BufferSize]; | |
194 uc16 utf16_buffer[kUtf16BufferSize]; | |
195 }; | |
196 | 165 |
197 private: | 166 private: |
198 virtual void LogRecordedBuffer(Code* code, | 167 static const int kUtf8BufferSize = 512; |
199 SharedFunctionInfo* shared, | 168 static const int kUtf16BufferSize = 128; |
200 NameBuffer* name_buffer) = 0; | |
201 | 169 |
202 NameBuffer name_buffer_; | 170 int utf8_pos_; |
| 171 char utf8_buffer_[kUtf8BufferSize]; |
| 172 uc16 utf16_buffer[kUtf16BufferSize]; |
203 }; | 173 }; |
204 | 174 |
205 | 175 |
| 176 CodeEventLogger::CodeEventLogger() : name_buffer_(new NameBuffer) { } |
| 177 |
| 178 CodeEventLogger::~CodeEventLogger() { delete name_buffer_; } |
| 179 |
| 180 |
206 void CodeEventLogger::CodeCreateEvent(Logger::LogEventsAndTags tag, | 181 void CodeEventLogger::CodeCreateEvent(Logger::LogEventsAndTags tag, |
207 Code* code, | 182 Code* code, |
208 const char* comment) { | 183 const char* comment) { |
209 name_buffer_.Init(tag); | 184 name_buffer_->Init(tag); |
210 name_buffer_.AppendBytes(comment); | 185 name_buffer_->AppendBytes(comment); |
211 LogRecordedBuffer(code, NULL, &name_buffer_); | 186 LogRecordedBuffer(code, NULL, name_buffer_->get(), name_buffer_->size()); |
212 } | 187 } |
213 | 188 |
214 | 189 |
215 void CodeEventLogger::CodeCreateEvent(Logger::LogEventsAndTags tag, | 190 void CodeEventLogger::CodeCreateEvent(Logger::LogEventsAndTags tag, |
216 Code* code, | 191 Code* code, |
217 Name* name) { | 192 Name* name) { |
218 name_buffer_.Init(tag); | 193 name_buffer_->Init(tag); |
219 name_buffer_.AppendName(name); | 194 name_buffer_->AppendName(name); |
220 LogRecordedBuffer(code, NULL, &name_buffer_); | 195 LogRecordedBuffer(code, NULL, name_buffer_->get(), name_buffer_->size()); |
221 } | 196 } |
222 | 197 |
223 | 198 |
224 void CodeEventLogger::CodeCreateEvent(Logger::LogEventsAndTags tag, | 199 void CodeEventLogger::CodeCreateEvent(Logger::LogEventsAndTags tag, |
225 Code* code, | 200 Code* code, |
226 SharedFunctionInfo* shared, | 201 SharedFunctionInfo* shared, |
227 CompilationInfo* info, | 202 CompilationInfo* info, |
228 Name* name) { | 203 Name* name) { |
229 name_buffer_.Init(tag); | 204 name_buffer_->Init(tag); |
230 name_buffer_.AppendBytes(ComputeMarker(code)); | 205 name_buffer_->AppendBytes(ComputeMarker(code)); |
231 name_buffer_.AppendName(name); | 206 name_buffer_->AppendName(name); |
232 LogRecordedBuffer(code, shared, &name_buffer_); | 207 LogRecordedBuffer(code, shared, name_buffer_->get(), name_buffer_->size()); |
233 } | 208 } |
234 | 209 |
235 | 210 |
236 void CodeEventLogger::CodeCreateEvent(Logger::LogEventsAndTags tag, | 211 void CodeEventLogger::CodeCreateEvent(Logger::LogEventsAndTags tag, |
237 Code* code, | 212 Code* code, |
238 SharedFunctionInfo* shared, | 213 SharedFunctionInfo* shared, |
239 CompilationInfo* info, | 214 CompilationInfo* info, |
240 Name* source, int line) { | 215 Name* source, int line) { |
241 name_buffer_.Init(tag); | 216 name_buffer_->Init(tag); |
242 name_buffer_.AppendBytes(ComputeMarker(code)); | 217 name_buffer_->AppendBytes(ComputeMarker(code)); |
243 name_buffer_.AppendString(shared->DebugName()); | 218 name_buffer_->AppendString(shared->DebugName()); |
244 name_buffer_.AppendByte(' '); | 219 name_buffer_->AppendByte(' '); |
245 if (source->IsString()) { | 220 if (source->IsString()) { |
246 name_buffer_.AppendString(String::cast(source)); | 221 name_buffer_->AppendString(String::cast(source)); |
247 } else { | 222 } else { |
248 name_buffer_.AppendBytes("symbol(hash "); | 223 name_buffer_->AppendBytes("symbol(hash "); |
249 name_buffer_.AppendHex(Name::cast(source)->Hash()); | 224 name_buffer_->AppendHex(Name::cast(source)->Hash()); |
250 name_buffer_.AppendByte(')'); | 225 name_buffer_->AppendByte(')'); |
251 } | 226 } |
252 name_buffer_.AppendByte(':'); | 227 name_buffer_->AppendByte(':'); |
253 name_buffer_.AppendInt(line); | 228 name_buffer_->AppendInt(line); |
254 LogRecordedBuffer(code, shared, &name_buffer_); | 229 LogRecordedBuffer(code, shared, name_buffer_->get(), name_buffer_->size()); |
255 } | 230 } |
256 | 231 |
257 | 232 |
258 void CodeEventLogger::CodeCreateEvent(Logger::LogEventsAndTags tag, | 233 void CodeEventLogger::CodeCreateEvent(Logger::LogEventsAndTags tag, |
259 Code* code, | 234 Code* code, |
260 int args_count) { | 235 int args_count) { |
261 name_buffer_.Init(tag); | 236 name_buffer_->Init(tag); |
262 name_buffer_.AppendInt(args_count); | 237 name_buffer_->AppendInt(args_count); |
263 LogRecordedBuffer(code, NULL, &name_buffer_); | 238 LogRecordedBuffer(code, NULL, name_buffer_->get(), name_buffer_->size()); |
264 } | 239 } |
265 | 240 |
266 | 241 |
267 void CodeEventLogger::RegExpCodeCreateEvent(Code* code, String* source) { | 242 void CodeEventLogger::RegExpCodeCreateEvent(Code* code, String* source) { |
268 name_buffer_.Init(Logger::REG_EXP_TAG); | 243 name_buffer_->Init(Logger::REG_EXP_TAG); |
269 name_buffer_.AppendString(source); | 244 name_buffer_->AppendString(source); |
270 LogRecordedBuffer(code, NULL, &name_buffer_); | 245 LogRecordedBuffer(code, NULL, name_buffer_->get(), name_buffer_->size()); |
271 } | 246 } |
272 | 247 |
273 | 248 |
274 // Low-level logging support. | 249 // Low-level logging support. |
| 250 #define LL_LOG(Call) if (ll_logger_) ll_logger_->Call; |
| 251 |
275 class LowLevelLogger : public CodeEventLogger { | 252 class LowLevelLogger : public CodeEventLogger { |
276 public: | 253 public: |
277 explicit LowLevelLogger(const char* file_name); | 254 explicit LowLevelLogger(const char* file_name); |
278 virtual ~LowLevelLogger(); | 255 virtual ~LowLevelLogger(); |
279 | 256 |
280 void CodeMoveEvent(Address from, Address to); | 257 virtual void CodeMoveEvent(Address from, Address to); |
281 void CodeDeleteEvent(Address from); | 258 virtual void CodeDeleteEvent(Address from); |
282 void SnapshotPositionEvent(Address addr, int pos); | 259 virtual void SnapshotPositionEvent(Address addr, int pos); |
283 void CodeMovingGCEvent(); | 260 virtual void CodeMovingGCEvent(); |
284 | 261 |
285 private: | 262 private: |
286 virtual void LogRecordedBuffer(Code* code, | 263 virtual void LogRecordedBuffer(Code* code, |
287 SharedFunctionInfo* shared, | 264 SharedFunctionInfo* shared, |
288 NameBuffer* name_buffer); | 265 const char* name, |
| 266 int length); |
289 | 267 |
290 // Low-level profiling event structures. | 268 // Low-level profiling event structures. |
291 struct CodeCreateStruct { | 269 struct CodeCreateStruct { |
292 static const char kTag = 'C'; | 270 static const char kTag = 'C'; |
293 | 271 |
294 int32_t name_size; | 272 int32_t name_size; |
295 Address code_address; | 273 Address code_address; |
296 int32_t code_size; | 274 int32_t code_size; |
297 }; | 275 }; |
298 | 276 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 const char arch[] = "mips"; | 354 const char arch[] = "mips"; |
377 #else | 355 #else |
378 const char arch[] = "unknown"; | 356 const char arch[] = "unknown"; |
379 #endif | 357 #endif |
380 LogWriteBytes(arch, sizeof(arch)); | 358 LogWriteBytes(arch, sizeof(arch)); |
381 } | 359 } |
382 | 360 |
383 | 361 |
384 void LowLevelLogger::LogRecordedBuffer(Code* code, | 362 void LowLevelLogger::LogRecordedBuffer(Code* code, |
385 SharedFunctionInfo*, | 363 SharedFunctionInfo*, |
386 NameBuffer* name_buffer) { | 364 const char* name, |
| 365 int length) { |
387 CodeCreateStruct event; | 366 CodeCreateStruct event; |
388 event.name_size = name_buffer->size(); | 367 event.name_size = length; |
389 event.code_address = code->instruction_start(); | 368 event.code_address = code->instruction_start(); |
390 ASSERT(event.code_address == code->address() + Code::kHeaderSize); | 369 ASSERT(event.code_address == code->address() + Code::kHeaderSize); |
391 event.code_size = code->instruction_size(); | 370 event.code_size = code->instruction_size(); |
392 LogWriteStruct(event); | 371 LogWriteStruct(event); |
393 LogWriteBytes(name_buffer->get(), name_buffer->size()); | 372 LogWriteBytes(name, length); |
394 LogWriteBytes( | 373 LogWriteBytes( |
395 reinterpret_cast<const char*>(code->instruction_start()), | 374 reinterpret_cast<const char*>(code->instruction_start()), |
396 code->instruction_size()); | 375 code->instruction_size()); |
397 } | 376 } |
398 | 377 |
399 | 378 |
400 void LowLevelLogger::CodeMoveEvent(Address from, Address to) { | 379 void LowLevelLogger::CodeMoveEvent(Address from, Address to) { |
401 CodeMoveStruct event; | 380 CodeMoveStruct event; |
402 event.from_address = from + Code::kHeaderSize; | 381 event.from_address = from + Code::kHeaderSize; |
403 event.to_address = to + Code::kHeaderSize; | 382 event.to_address = to + Code::kHeaderSize; |
(...skipping 23 matching lines...) Expand all Loading... |
427 } | 406 } |
428 | 407 |
429 | 408 |
430 void LowLevelLogger::CodeMovingGCEvent() { | 409 void LowLevelLogger::CodeMovingGCEvent() { |
431 const char tag = kCodeMovingGCTag; | 410 const char tag = kCodeMovingGCTag; |
432 | 411 |
433 LogWriteBytes(&tag, sizeof(tag)); | 412 LogWriteBytes(&tag, sizeof(tag)); |
434 } | 413 } |
435 | 414 |
436 | 415 |
437 #define LL_LOG(Call) if (ll_logger_) ll_logger_->Call; | 416 #define JIT_LOG(Call) if (jit_logger_) jit_logger_->Call; |
438 | |
439 | |
440 class CodeAddressMap: public CodeEventLogger { | |
441 public: | |
442 CodeAddressMap() { } | |
443 virtual ~CodeAddressMap() { } | |
444 | |
445 void CodeMoveEvent(Address from, Address to) { | |
446 address_to_name_map_.Move(from, to); | |
447 } | |
448 | |
449 void CodeDeleteEvent(Address from) { | |
450 address_to_name_map_.Remove(from); | |
451 } | |
452 | |
453 const char* Lookup(Address address) { | |
454 return address_to_name_map_.Lookup(address); | |
455 } | |
456 | |
457 private: | |
458 class NameMap { | |
459 public: | |
460 NameMap() : impl_(&PointerEquals) {} | |
461 | |
462 ~NameMap() { | |
463 for (HashMap::Entry* p = impl_.Start(); p != NULL; p = impl_.Next(p)) { | |
464 DeleteArray(static_cast<const char*>(p->value)); | |
465 } | |
466 } | |
467 | |
468 void Insert(Address code_address, const char* name, int name_size) { | |
469 HashMap::Entry* entry = FindOrCreateEntry(code_address); | |
470 if (entry->value == NULL) { | |
471 entry->value = CopyName(name, name_size); | |
472 } | |
473 } | |
474 | |
475 const char* Lookup(Address code_address) { | |
476 HashMap::Entry* entry = FindEntry(code_address); | |
477 return (entry != NULL) ? static_cast<const char*>(entry->value) : NULL; | |
478 } | |
479 | |
480 void Remove(Address code_address) { | |
481 HashMap::Entry* entry = FindEntry(code_address); | |
482 if (entry != NULL) { | |
483 DeleteArray(static_cast<char*>(entry->value)); | |
484 RemoveEntry(entry); | |
485 } | |
486 } | |
487 | |
488 void Move(Address from, Address to) { | |
489 if (from == to) return; | |
490 HashMap::Entry* from_entry = FindEntry(from); | |
491 ASSERT(from_entry != NULL); | |
492 void* value = from_entry->value; | |
493 RemoveEntry(from_entry); | |
494 HashMap::Entry* to_entry = FindOrCreateEntry(to); | |
495 ASSERT(to_entry->value == NULL); | |
496 to_entry->value = value; | |
497 } | |
498 | |
499 private: | |
500 static bool PointerEquals(void* lhs, void* rhs) { | |
501 return lhs == rhs; | |
502 } | |
503 | |
504 static char* CopyName(const char* name, int name_size) { | |
505 char* result = NewArray<char>(name_size + 1); | |
506 for (int i = 0; i < name_size; ++i) { | |
507 char c = name[i]; | |
508 if (c == '\0') c = ' '; | |
509 result[i] = c; | |
510 } | |
511 result[name_size] = '\0'; | |
512 return result; | |
513 } | |
514 | |
515 HashMap::Entry* FindOrCreateEntry(Address code_address) { | |
516 return impl_.Lookup(code_address, ComputePointerHash(code_address), true); | |
517 } | |
518 | |
519 HashMap::Entry* FindEntry(Address code_address) { | |
520 return impl_.Lookup(code_address, | |
521 ComputePointerHash(code_address), | |
522 false); | |
523 } | |
524 | |
525 void RemoveEntry(HashMap::Entry* entry) { | |
526 impl_.Remove(entry->key, entry->hash); | |
527 } | |
528 | |
529 HashMap impl_; | |
530 | |
531 DISALLOW_COPY_AND_ASSIGN(NameMap); | |
532 }; | |
533 | |
534 virtual void LogRecordedBuffer(Code* code, | |
535 SharedFunctionInfo*, | |
536 NameBuffer* name_buffer) { | |
537 address_to_name_map_.Insert(code->address(), | |
538 name_buffer->get(), | |
539 name_buffer->size()); | |
540 } | |
541 | |
542 NameMap address_to_name_map_; | |
543 }; | |
544 | |
545 | |
546 #define CODE_ADDRESS_MAP_LOG(Call)\ | |
547 if (Serializer::enabled()) code_address_map_->Call; | |
548 | 417 |
549 | 418 |
550 class JitLogger : public CodeEventLogger { | 419 class JitLogger : public CodeEventLogger { |
551 public: | 420 public: |
552 explicit JitLogger(JitCodeEventHandler code_event_handler); | 421 explicit JitLogger(JitCodeEventHandler code_event_handler); |
553 | 422 |
554 void CodeMoveEvent(Address from, Address to); | 423 virtual void CodeMoveEvent(Address from, Address to); |
555 void CodeDeleteEvent(Address from); | 424 virtual void CodeDeleteEvent(Address from); |
556 void AddCodeLinePosInfoEvent( | 425 virtual void AddCodeLinePosInfoEvent( |
557 void* jit_handler_data, | 426 void* jit_handler_data, |
558 int pc_offset, | 427 int pc_offset, |
559 int position, | 428 int position, |
560 JitCodeEvent::PositionType position_type); | 429 JitCodeEvent::PositionType position_type); |
| 430 |
561 void* StartCodePosInfoEvent(); | 431 void* StartCodePosInfoEvent(); |
562 void EndCodePosInfoEvent(Code* code, void* jit_handler_data); | 432 void EndCodePosInfoEvent(Code* code, void* jit_handler_data); |
563 | 433 |
564 private: | 434 private: |
565 virtual void LogRecordedBuffer(Code* code, | 435 virtual void LogRecordedBuffer(Code* code, |
566 SharedFunctionInfo* shared, | 436 SharedFunctionInfo* shared, |
567 CodeEventLogger::NameBuffer* name_buffer); | 437 const char* name, |
| 438 int length); |
568 | 439 |
569 JitCodeEventHandler code_event_handler_; | 440 JitCodeEventHandler code_event_handler_; |
570 }; | 441 }; |
571 | 442 |
572 #define JIT_LOG(Call) if (jit_logger_) jit_logger_->Call; | |
573 | |
574 | 443 |
575 JitLogger::JitLogger(JitCodeEventHandler code_event_handler) | 444 JitLogger::JitLogger(JitCodeEventHandler code_event_handler) |
576 : code_event_handler_(code_event_handler) { | 445 : code_event_handler_(code_event_handler) { |
577 } | 446 } |
578 | 447 |
579 | 448 |
580 void JitLogger::LogRecordedBuffer(Code* code, | 449 void JitLogger::LogRecordedBuffer(Code* code, |
581 SharedFunctionInfo* shared, | 450 SharedFunctionInfo* shared, |
582 CodeEventLogger::NameBuffer* name_buffer) { | 451 const char* name, |
| 452 int length) { |
583 JitCodeEvent event; | 453 JitCodeEvent event; |
584 memset(&event, 0, sizeof(event)); | 454 memset(&event, 0, sizeof(event)); |
585 event.type = JitCodeEvent::CODE_ADDED; | 455 event.type = JitCodeEvent::CODE_ADDED; |
586 event.code_start = code->instruction_start(); | 456 event.code_start = code->instruction_start(); |
587 event.code_len = code->instruction_size(); | 457 event.code_len = code->instruction_size(); |
588 Handle<Script> script_handle; | 458 Handle<Script> script_handle; |
589 if (shared && shared->script()->IsScript()) { | 459 if (shared && shared->script()->IsScript()) { |
590 script_handle = Handle<Script>(Script::cast(shared->script())); | 460 script_handle = Handle<Script>(Script::cast(shared->script())); |
591 } | 461 } |
592 event.script = ToApiHandle<v8::Script>(script_handle); | 462 event.script = ToApiHandle<v8::Script>(script_handle); |
593 event.name.str = name_buffer->get(); | 463 event.name.str = name; |
594 event.name.len = name_buffer->size(); | 464 event.name.len = length; |
595 code_event_handler_(&event); | 465 code_event_handler_(&event); |
596 } | 466 } |
597 | 467 |
598 | 468 |
599 void JitLogger::CodeMoveEvent(Address from, Address to) { | 469 void JitLogger::CodeMoveEvent(Address from, Address to) { |
600 Code* from_code = Code::cast(HeapObject::FromAddress(from)); | 470 Code* from_code = Code::cast(HeapObject::FromAddress(from)); |
601 | 471 |
602 JitCodeEvent event; | 472 JitCodeEvent event; |
603 event.type = JitCodeEvent::CODE_MOVED; | 473 event.type = JitCodeEvent::CODE_MOVED; |
604 event.code_start = from_code->instruction_start(); | 474 event.code_start = from_code->instruction_start(); |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
837 Logger::Logger(Isolate* isolate) | 707 Logger::Logger(Isolate* isolate) |
838 : isolate_(isolate), | 708 : isolate_(isolate), |
839 ticker_(NULL), | 709 ticker_(NULL), |
840 profiler_(NULL), | 710 profiler_(NULL), |
841 log_events_(NULL), | 711 log_events_(NULL), |
842 logging_nesting_(0), | 712 logging_nesting_(0), |
843 cpu_profiler_nesting_(0), | 713 cpu_profiler_nesting_(0), |
844 log_(new Log(this)), | 714 log_(new Log(this)), |
845 ll_logger_(NULL), | 715 ll_logger_(NULL), |
846 jit_logger_(NULL), | 716 jit_logger_(NULL), |
847 code_address_map_(new CodeAddressMap), | 717 listeners_(5), |
848 is_initialized_(false), | 718 is_initialized_(false), |
849 last_address_(NULL), | 719 last_address_(NULL), |
850 prev_sp_(NULL), | 720 prev_sp_(NULL), |
851 prev_function_(NULL), | 721 prev_function_(NULL), |
852 prev_to_(NULL), | 722 prev_to_(NULL), |
853 prev_code_(NULL), | 723 prev_code_(NULL), |
854 epoch_(0) { | 724 epoch_(0) { |
855 } | 725 } |
856 | 726 |
857 | 727 |
858 Logger::~Logger() { | 728 Logger::~Logger() { |
859 delete code_address_map_; | |
860 delete log_; | 729 delete log_; |
861 } | 730 } |
862 | 731 |
863 | 732 |
| 733 void Logger::addCodeEventListener(CodeEventListener* listener) { |
| 734 ASSERT(!hasCodeEventListener(listener)); |
| 735 listeners_.Add(listener); |
| 736 } |
| 737 |
| 738 |
| 739 void Logger::removeCodeEventListener(CodeEventListener* listener) { |
| 740 ASSERT(hasCodeEventListener(listener)); |
| 741 listeners_.RemoveElement(listener); |
| 742 } |
| 743 |
| 744 |
| 745 bool Logger::hasCodeEventListener(CodeEventListener* listener) { |
| 746 return listeners_.Contains(listener); |
| 747 } |
| 748 |
| 749 |
864 void Logger::ProfilerBeginEvent() { | 750 void Logger::ProfilerBeginEvent() { |
865 if (!log_->IsEnabled()) return; | 751 if (!log_->IsEnabled()) return; |
866 Log::MessageBuilder msg(log_); | 752 Log::MessageBuilder msg(log_); |
867 msg.Append("profiler,\"begin\",%d\n", kSamplingIntervalMs); | 753 msg.Append("profiler,\"begin\",%d\n", kSamplingIntervalMs); |
868 msg.WriteToLogFile(); | 754 msg.WriteToLogFile(); |
869 } | 755 } |
870 | 756 |
871 | 757 |
872 void Logger::StringEvent(const char* name, const char* value) { | 758 void Logger::StringEvent(const char* name, const char* value) { |
873 if (FLAG_log) UncheckedStringEvent(name, value); | 759 if (FLAG_log) UncheckedStringEvent(name, value); |
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1272 msg->Append(",%d,", code->ExecutableSize()); | 1158 msg->Append(",%d,", code->ExecutableSize()); |
1273 } | 1159 } |
1274 | 1160 |
1275 | 1161 |
1276 void Logger::CodeCreateEvent(LogEventsAndTags tag, | 1162 void Logger::CodeCreateEvent(LogEventsAndTags tag, |
1277 Code* code, | 1163 Code* code, |
1278 const char* comment) { | 1164 const char* comment) { |
1279 PROFILER_LOG(CodeCreateEvent(tag, code, comment)); | 1165 PROFILER_LOG(CodeCreateEvent(tag, code, comment)); |
1280 | 1166 |
1281 if (!is_logging_code_events()) return; | 1167 if (!is_logging_code_events()) return; |
1282 JIT_LOG(CodeCreateEvent(tag, code, comment)); | 1168 CALL_LISTENERS(CodeCreateEvent(tag, code, comment)); |
1283 LL_LOG(CodeCreateEvent(tag, code, comment)); | |
1284 CODE_ADDRESS_MAP_LOG(CodeCreateEvent(tag, code, comment)); | |
1285 | 1169 |
1286 if (!FLAG_log_code || !log_->IsEnabled()) return; | 1170 if (!FLAG_log_code || !log_->IsEnabled()) return; |
1287 Log::MessageBuilder msg(log_); | 1171 Log::MessageBuilder msg(log_); |
1288 AppendCodeCreateHeader(&msg, tag, code); | 1172 AppendCodeCreateHeader(&msg, tag, code); |
1289 msg.AppendDoubleQuotedString(comment); | 1173 msg.AppendDoubleQuotedString(comment); |
1290 msg.Append('\n'); | 1174 msg.Append('\n'); |
1291 msg.WriteToLogFile(); | 1175 msg.WriteToLogFile(); |
1292 } | 1176 } |
1293 | 1177 |
1294 | 1178 |
1295 void Logger::CodeCreateEvent(LogEventsAndTags tag, | 1179 void Logger::CodeCreateEvent(LogEventsAndTags tag, |
1296 Code* code, | 1180 Code* code, |
1297 Name* name) { | 1181 Name* name) { |
1298 PROFILER_LOG(CodeCreateEvent(tag, code, name)); | 1182 PROFILER_LOG(CodeCreateEvent(tag, code, name)); |
1299 | 1183 |
1300 if (!is_logging_code_events()) return; | 1184 if (!is_logging_code_events()) return; |
1301 JIT_LOG(CodeCreateEvent(tag, code, name)); | 1185 CALL_LISTENERS(CodeCreateEvent(tag, code, name)); |
1302 LL_LOG(CodeCreateEvent(tag, code, name)); | |
1303 CODE_ADDRESS_MAP_LOG(CodeCreateEvent(tag, code, name)); | |
1304 | 1186 |
1305 if (!FLAG_log_code || !log_->IsEnabled()) return; | 1187 if (!FLAG_log_code || !log_->IsEnabled()) return; |
1306 Log::MessageBuilder msg(log_); | 1188 Log::MessageBuilder msg(log_); |
1307 AppendCodeCreateHeader(&msg, tag, code); | 1189 AppendCodeCreateHeader(&msg, tag, code); |
1308 if (name->IsString()) { | 1190 if (name->IsString()) { |
1309 msg.Append('"'); | 1191 msg.Append('"'); |
1310 msg.AppendDetailed(String::cast(name), false); | 1192 msg.AppendDetailed(String::cast(name), false); |
1311 msg.Append('"'); | 1193 msg.Append('"'); |
1312 } else { | 1194 } else { |
1313 msg.AppendSymbolName(Symbol::cast(name)); | 1195 msg.AppendSymbolName(Symbol::cast(name)); |
1314 } | 1196 } |
1315 msg.Append('\n'); | 1197 msg.Append('\n'); |
1316 msg.WriteToLogFile(); | 1198 msg.WriteToLogFile(); |
1317 } | 1199 } |
1318 | 1200 |
1319 | 1201 |
1320 void Logger::CodeCreateEvent(LogEventsAndTags tag, | 1202 void Logger::CodeCreateEvent(LogEventsAndTags tag, |
1321 Code* code, | 1203 Code* code, |
1322 SharedFunctionInfo* shared, | 1204 SharedFunctionInfo* shared, |
1323 CompilationInfo* info, | 1205 CompilationInfo* info, |
1324 Name* name) { | 1206 Name* name) { |
1325 PROFILER_LOG(CodeCreateEvent(tag, code, shared, info, name)); | 1207 PROFILER_LOG(CodeCreateEvent(tag, code, shared, info, name)); |
1326 | 1208 |
1327 if (!is_logging_code_events()) return; | 1209 if (!is_logging_code_events()) return; |
1328 JIT_LOG(CodeCreateEvent(tag, code, shared, info, name)); | 1210 CALL_LISTENERS(CodeCreateEvent(tag, code, shared, info, name)); |
1329 LL_LOG(CodeCreateEvent(tag, code, shared, info, name)); | |
1330 CODE_ADDRESS_MAP_LOG(CodeCreateEvent(tag, code, shared, info, name)); | |
1331 | 1211 |
1332 if (!FLAG_log_code || !log_->IsEnabled()) return; | 1212 if (!FLAG_log_code || !log_->IsEnabled()) return; |
1333 if (code == isolate_->builtins()->builtin( | 1213 if (code == isolate_->builtins()->builtin( |
1334 Builtins::kLazyCompile)) | 1214 Builtins::kLazyCompile)) |
1335 return; | 1215 return; |
1336 | 1216 |
1337 Log::MessageBuilder msg(log_); | 1217 Log::MessageBuilder msg(log_); |
1338 AppendCodeCreateHeader(&msg, tag, code); | 1218 AppendCodeCreateHeader(&msg, tag, code); |
1339 if (name->IsString()) { | 1219 if (name->IsString()) { |
1340 SmartArrayPointer<char> str = | 1220 SmartArrayPointer<char> str = |
(...skipping 14 matching lines...) Expand all Loading... |
1355 // the SharedFunctionInfo object, we left it to caller | 1235 // the SharedFunctionInfo object, we left it to caller |
1356 // to leave logging functions free from heap allocations. | 1236 // to leave logging functions free from heap allocations. |
1357 void Logger::CodeCreateEvent(LogEventsAndTags tag, | 1237 void Logger::CodeCreateEvent(LogEventsAndTags tag, |
1358 Code* code, | 1238 Code* code, |
1359 SharedFunctionInfo* shared, | 1239 SharedFunctionInfo* shared, |
1360 CompilationInfo* info, | 1240 CompilationInfo* info, |
1361 Name* source, int line) { | 1241 Name* source, int line) { |
1362 PROFILER_LOG(CodeCreateEvent(tag, code, shared, info, source, line)); | 1242 PROFILER_LOG(CodeCreateEvent(tag, code, shared, info, source, line)); |
1363 | 1243 |
1364 if (!is_logging_code_events()) return; | 1244 if (!is_logging_code_events()) return; |
1365 JIT_LOG(CodeCreateEvent(tag, code, shared, info, source, line)); | 1245 CALL_LISTENERS(CodeCreateEvent(tag, code, shared, info, source, line)); |
1366 LL_LOG(CodeCreateEvent(tag, code, shared, info, source, line)); | |
1367 CODE_ADDRESS_MAP_LOG(CodeCreateEvent(tag, code, shared, info, source, line)); | |
1368 | 1246 |
1369 if (!FLAG_log_code || !log_->IsEnabled()) return; | 1247 if (!FLAG_log_code || !log_->IsEnabled()) return; |
1370 Log::MessageBuilder msg(log_); | 1248 Log::MessageBuilder msg(log_); |
1371 AppendCodeCreateHeader(&msg, tag, code); | 1249 AppendCodeCreateHeader(&msg, tag, code); |
1372 SmartArrayPointer<char> name = | 1250 SmartArrayPointer<char> name = |
1373 shared->DebugName()->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); | 1251 shared->DebugName()->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
1374 msg.Append("\"%s ", *name); | 1252 msg.Append("\"%s ", *name); |
1375 if (source->IsString()) { | 1253 if (source->IsString()) { |
1376 SmartArrayPointer<char> sourcestr = | 1254 SmartArrayPointer<char> sourcestr = |
1377 String::cast(source)->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); | 1255 String::cast(source)->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
1378 msg.Append("%s", *sourcestr); | 1256 msg.Append("%s", *sourcestr); |
1379 } else { | 1257 } else { |
1380 msg.AppendSymbolName(Symbol::cast(source)); | 1258 msg.AppendSymbolName(Symbol::cast(source)); |
1381 } | 1259 } |
1382 msg.Append(":%d\",", line); | 1260 msg.Append(":%d\",", line); |
1383 msg.AppendAddress(shared->address()); | 1261 msg.AppendAddress(shared->address()); |
1384 msg.Append(",%s", ComputeMarker(code)); | 1262 msg.Append(",%s", ComputeMarker(code)); |
1385 msg.Append('\n'); | 1263 msg.Append('\n'); |
1386 msg.WriteToLogFile(); | 1264 msg.WriteToLogFile(); |
1387 } | 1265 } |
1388 | 1266 |
1389 | 1267 |
1390 void Logger::CodeCreateEvent(LogEventsAndTags tag, | 1268 void Logger::CodeCreateEvent(LogEventsAndTags tag, |
1391 Code* code, | 1269 Code* code, |
1392 int args_count) { | 1270 int args_count) { |
1393 PROFILER_LOG(CodeCreateEvent(tag, code, args_count)); | 1271 PROFILER_LOG(CodeCreateEvent(tag, code, args_count)); |
1394 | 1272 |
1395 if (!is_logging_code_events()) return; | 1273 if (!is_logging_code_events()) return; |
1396 JIT_LOG(CodeCreateEvent(tag, code, args_count)); | 1274 CALL_LISTENERS(CodeCreateEvent(tag, code, args_count)); |
1397 LL_LOG(CodeCreateEvent(tag, code, args_count)); | |
1398 CODE_ADDRESS_MAP_LOG(CodeCreateEvent(tag, code, args_count)); | |
1399 | 1275 |
1400 if (!FLAG_log_code || !log_->IsEnabled()) return; | 1276 if (!FLAG_log_code || !log_->IsEnabled()) return; |
1401 Log::MessageBuilder msg(log_); | 1277 Log::MessageBuilder msg(log_); |
1402 AppendCodeCreateHeader(&msg, tag, code); | 1278 AppendCodeCreateHeader(&msg, tag, code); |
1403 msg.Append("\"args_count: %d\"", args_count); | 1279 msg.Append("\"args_count: %d\"", args_count); |
1404 msg.Append('\n'); | 1280 msg.Append('\n'); |
1405 msg.WriteToLogFile(); | 1281 msg.WriteToLogFile(); |
1406 } | 1282 } |
1407 | 1283 |
1408 | 1284 |
1409 void Logger::CodeMovingGCEvent() { | 1285 void Logger::CodeMovingGCEvent() { |
1410 PROFILER_LOG(CodeMovingGCEvent()); | 1286 PROFILER_LOG(CodeMovingGCEvent()); |
1411 | 1287 |
1412 if (!is_logging_code_events()) return; | 1288 if (!is_logging_code_events()) return; |
1413 if (!log_->IsEnabled() || !FLAG_ll_prof) return; | 1289 if (!log_->IsEnabled() || !FLAG_ll_prof) return; |
1414 LL_LOG(CodeMovingGCEvent()); | 1290 CALL_LISTENERS(CodeMovingGCEvent()); |
1415 OS::SignalCodeMovingGC(); | 1291 OS::SignalCodeMovingGC(); |
1416 } | 1292 } |
1417 | 1293 |
1418 | 1294 |
1419 void Logger::RegExpCodeCreateEvent(Code* code, String* source) { | 1295 void Logger::RegExpCodeCreateEvent(Code* code, String* source) { |
1420 PROFILER_LOG(RegExpCodeCreateEvent(code, source)); | 1296 PROFILER_LOG(RegExpCodeCreateEvent(code, source)); |
1421 | 1297 |
1422 if (!is_logging_code_events()) return; | 1298 if (!is_logging_code_events()) return; |
1423 JIT_LOG(RegExpCodeCreateEvent(code, source)); | 1299 CALL_LISTENERS(RegExpCodeCreateEvent(code, source)); |
1424 LL_LOG(RegExpCodeCreateEvent(code, source)); | |
1425 CODE_ADDRESS_MAP_LOG(RegExpCodeCreateEvent(code, source)); | |
1426 | 1300 |
1427 if (!FLAG_log_code || !log_->IsEnabled()) return; | 1301 if (!FLAG_log_code || !log_->IsEnabled()) return; |
1428 Log::MessageBuilder msg(log_); | 1302 Log::MessageBuilder msg(log_); |
1429 AppendCodeCreateHeader(&msg, REG_EXP_TAG, code); | 1303 AppendCodeCreateHeader(&msg, REG_EXP_TAG, code); |
1430 msg.Append('"'); | 1304 msg.Append('"'); |
1431 msg.AppendDetailed(source, false); | 1305 msg.AppendDetailed(source, false); |
1432 msg.Append('"'); | 1306 msg.Append('"'); |
1433 msg.Append('\n'); | 1307 msg.Append('\n'); |
1434 msg.WriteToLogFile(); | 1308 msg.WriteToLogFile(); |
1435 } | 1309 } |
1436 | 1310 |
1437 | 1311 |
1438 void Logger::CodeMoveEvent(Address from, Address to) { | 1312 void Logger::CodeMoveEvent(Address from, Address to) { |
1439 PROFILER_LOG(CodeMoveEvent(from, to)); | 1313 PROFILER_LOG(CodeMoveEvent(from, to)); |
1440 | 1314 |
1441 if (!is_logging_code_events()) return; | 1315 if (!is_logging_code_events()) return; |
1442 JIT_LOG(CodeMoveEvent(from, to)); | 1316 CALL_LISTENERS(CodeMoveEvent(from, to)); |
1443 LL_LOG(CodeMoveEvent(from, to)); | |
1444 CODE_ADDRESS_MAP_LOG(CodeMoveEvent(from, to)); | |
1445 MoveEventInternal(CODE_MOVE_EVENT, from, to); | 1317 MoveEventInternal(CODE_MOVE_EVENT, from, to); |
1446 } | 1318 } |
1447 | 1319 |
1448 | 1320 |
1449 void Logger::CodeDeleteEvent(Address from) { | 1321 void Logger::CodeDeleteEvent(Address from) { |
1450 PROFILER_LOG(CodeDeleteEvent(from)); | 1322 PROFILER_LOG(CodeDeleteEvent(from)); |
1451 | 1323 |
1452 if (!is_logging_code_events()) return; | 1324 if (!is_logging_code_events()) return; |
1453 JIT_LOG(CodeDeleteEvent(from)); | 1325 CALL_LISTENERS(CodeDeleteEvent(from)); |
1454 LL_LOG(CodeDeleteEvent(from)); | |
1455 CODE_ADDRESS_MAP_LOG(CodeDeleteEvent(from)); | |
1456 | 1326 |
1457 if (!FLAG_log_code || !log_->IsEnabled()) return; | 1327 if (!FLAG_log_code || !log_->IsEnabled()) return; |
1458 Log::MessageBuilder msg(log_); | 1328 Log::MessageBuilder msg(log_); |
1459 msg.Append("%s,", kLogEventsNames[CODE_DELETE_EVENT]); | 1329 msg.Append("%s,", kLogEventsNames[CODE_DELETE_EVENT]); |
1460 msg.AppendAddress(from); | 1330 msg.AppendAddress(from); |
1461 msg.Append('\n'); | 1331 msg.Append('\n'); |
1462 msg.WriteToLogFile(); | 1332 msg.WriteToLogFile(); |
1463 } | 1333 } |
1464 | 1334 |
1465 | 1335 |
(...skipping 23 matching lines...) Expand all Loading... |
1489 } | 1359 } |
1490 } | 1360 } |
1491 | 1361 |
1492 | 1362 |
1493 void Logger::CodeEndLinePosInfoRecordEvent(Code* code, | 1363 void Logger::CodeEndLinePosInfoRecordEvent(Code* code, |
1494 void* jit_handler_data) { | 1364 void* jit_handler_data) { |
1495 JIT_LOG(EndCodePosInfoEvent(code, jit_handler_data)); | 1365 JIT_LOG(EndCodePosInfoEvent(code, jit_handler_data)); |
1496 } | 1366 } |
1497 | 1367 |
1498 | 1368 |
| 1369 void Logger::CodeNameEvent(Address addr, int pos, const char* code_name) { |
| 1370 if (code_name == NULL) return; // Not a code object. |
| 1371 Log::MessageBuilder msg(log_); |
| 1372 msg.Append("%s,%d,", kLogEventsNames[SNAPSHOT_CODE_NAME_EVENT], pos); |
| 1373 msg.AppendDoubleQuotedString(code_name); |
| 1374 msg.Append("\n"); |
| 1375 msg.WriteToLogFile(); |
| 1376 } |
| 1377 |
| 1378 |
1499 void Logger::SnapshotPositionEvent(Address addr, int pos) { | 1379 void Logger::SnapshotPositionEvent(Address addr, int pos) { |
1500 if (!log_->IsEnabled()) return; | 1380 if (!log_->IsEnabled()) return; |
1501 LL_LOG(SnapshotPositionEvent(addr, pos)); | 1381 LL_LOG(SnapshotPositionEvent(addr, pos)); |
1502 if (Serializer::enabled()) { | |
1503 const char* code_name = code_address_map_->Lookup(addr); | |
1504 if (code_name == NULL) return; // Not a code object. | |
1505 Log::MessageBuilder msg(log_); | |
1506 msg.Append("%s,%d,", kLogEventsNames[SNAPSHOT_CODE_NAME_EVENT], pos); | |
1507 msg.AppendDoubleQuotedString(code_name); | |
1508 msg.Append("\n"); | |
1509 msg.WriteToLogFile(); | |
1510 } | |
1511 if (!FLAG_log_snapshot_positions) return; | 1382 if (!FLAG_log_snapshot_positions) return; |
1512 Log::MessageBuilder msg(log_); | 1383 Log::MessageBuilder msg(log_); |
1513 msg.Append("%s,", kLogEventsNames[SNAPSHOT_POSITION_EVENT]); | 1384 msg.Append("%s,", kLogEventsNames[SNAPSHOT_POSITION_EVENT]); |
1514 msg.AppendAddress(addr); | 1385 msg.AppendAddress(addr); |
1515 msg.Append(",%d", pos); | 1386 msg.Append(",%d", pos); |
1516 msg.Append('\n'); | 1387 msg.Append('\n'); |
1517 msg.WriteToLogFile(); | 1388 msg.WriteToLogFile(); |
1518 } | 1389 } |
1519 | 1390 |
1520 | 1391 |
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2003 FLAG_log_code = false; | 1874 FLAG_log_code = false; |
2004 FLAG_prof_auto = false; | 1875 FLAG_prof_auto = false; |
2005 } | 1876 } |
2006 | 1877 |
2007 SmartArrayPointer<const char> log_file_name = | 1878 SmartArrayPointer<const char> log_file_name = |
2008 PrepareLogFileName(FLAG_logfile); | 1879 PrepareLogFileName(FLAG_logfile); |
2009 log_->Initialize(*log_file_name); | 1880 log_->Initialize(*log_file_name); |
2010 | 1881 |
2011 if (FLAG_ll_prof) { | 1882 if (FLAG_ll_prof) { |
2012 ll_logger_ = new LowLevelLogger(*log_file_name); | 1883 ll_logger_ = new LowLevelLogger(*log_file_name); |
| 1884 addCodeEventListener(ll_logger_); |
2013 } | 1885 } |
2014 | 1886 |
2015 ticker_ = new Ticker(isolate, kSamplingIntervalMs); | 1887 ticker_ = new Ticker(isolate, kSamplingIntervalMs); |
2016 | 1888 |
2017 if (Log::InitLogAtStart()) { | 1889 if (Log::InitLogAtStart()) { |
2018 logging_nesting_ = 1; | 1890 logging_nesting_ = 1; |
2019 } | 1891 } |
2020 | 1892 |
2021 if (FLAG_prof) { | 1893 if (FLAG_prof) { |
2022 profiler_ = new Profiler(isolate); | 1894 profiler_ = new Profiler(isolate); |
2023 if (!FLAG_prof_auto) { | 1895 if (!FLAG_prof_auto) { |
2024 profiler_->pause(); | 1896 profiler_->pause(); |
2025 } else { | 1897 } else { |
2026 logging_nesting_ = 1; | 1898 logging_nesting_ = 1; |
2027 } | 1899 } |
2028 if (!FLAG_prof_lazy) { | 1900 if (!FLAG_prof_lazy) { |
2029 profiler_->Engage(); | 1901 profiler_->Engage(); |
2030 } | 1902 } |
2031 } | 1903 } |
2032 | 1904 |
2033 if (FLAG_log_internal_timer_events || FLAG_prof) epoch_ = OS::Ticks(); | 1905 if (FLAG_log_internal_timer_events || FLAG_prof) epoch_ = OS::Ticks(); |
2034 | 1906 |
2035 return true; | 1907 return true; |
2036 } | 1908 } |
2037 | 1909 |
2038 | 1910 |
2039 void Logger::SetCodeEventHandler(uint32_t options, | 1911 void Logger::SetCodeEventHandler(uint32_t options, |
2040 JitCodeEventHandler event_handler) { | 1912 JitCodeEventHandler event_handler) { |
2041 if (jit_logger_) { | 1913 if (jit_logger_) { |
| 1914 removeCodeEventListener(jit_logger_); |
2042 delete jit_logger_; | 1915 delete jit_logger_; |
2043 jit_logger_ = NULL; | 1916 jit_logger_ = NULL; |
2044 } | 1917 } |
2045 | 1918 |
2046 if (event_handler) { | 1919 if (event_handler) { |
2047 jit_logger_ = new JitLogger(event_handler); | 1920 jit_logger_ = new JitLogger(event_handler); |
2048 } | 1921 addCodeEventListener(jit_logger_); |
2049 | 1922 if (options & kJitCodeEventEnumExisting) { |
2050 if (jit_logger_ != NULL && (options & kJitCodeEventEnumExisting)) { | 1923 HandleScope scope(isolate_); |
2051 HandleScope scope(isolate_); | 1924 LogCodeObjects(); |
2052 LogCodeObjects(); | 1925 LogCompiledFunctions(); |
2053 LogCompiledFunctions(); | 1926 } |
2054 } | 1927 } |
2055 } | 1928 } |
2056 | 1929 |
2057 | 1930 |
2058 Sampler* Logger::sampler() { | 1931 Sampler* Logger::sampler() { |
2059 return ticker_; | 1932 return ticker_; |
2060 } | 1933 } |
2061 | 1934 |
2062 | 1935 |
2063 FILE* Logger::TearDown() { | 1936 FILE* Logger::TearDown() { |
2064 if (!is_initialized_) return NULL; | 1937 if (!is_initialized_) return NULL; |
2065 is_initialized_ = false; | 1938 is_initialized_ = false; |
2066 | 1939 |
2067 // Stop the profiler before closing the file. | 1940 // Stop the profiler before closing the file. |
2068 if (profiler_ != NULL) { | 1941 if (profiler_ != NULL) { |
2069 profiler_->Disengage(); | 1942 profiler_->Disengage(); |
2070 delete profiler_; | 1943 delete profiler_; |
2071 profiler_ = NULL; | 1944 profiler_ = NULL; |
2072 } | 1945 } |
2073 | 1946 |
2074 delete ticker_; | 1947 delete ticker_; |
2075 ticker_ = NULL; | 1948 ticker_ = NULL; |
2076 | 1949 |
2077 if (ll_logger_) { | 1950 if (ll_logger_) { |
| 1951 removeCodeEventListener(ll_logger_); |
2078 delete ll_logger_; | 1952 delete ll_logger_; |
2079 ll_logger_ = NULL; | 1953 ll_logger_ = NULL; |
2080 } | 1954 } |
2081 | 1955 |
2082 if (jit_logger_) { | 1956 if (jit_logger_) { |
| 1957 removeCodeEventListener(jit_logger_); |
2083 delete jit_logger_; | 1958 delete jit_logger_; |
2084 jit_logger_ = NULL; | 1959 jit_logger_ = NULL; |
2085 } | 1960 } |
2086 | 1961 |
2087 return log_->Close(); | 1962 return log_->Close(); |
2088 } | 1963 } |
2089 | 1964 |
2090 } } // namespace v8::internal | 1965 } } // namespace v8::internal |
OLD | NEW |