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