Index: src/log.cc |
diff --git a/src/log.cc b/src/log.cc |
index e327308b845e5634e4e7a13f385290dc058642f1..040109535b247f2cf660b7f3e5646fef23afed89 100644 |
--- a/src/log.cc |
+++ b/src/log.cc |
@@ -31,23 +31,10 @@ namespace internal { |
#define DECLARE_EVENT(ignore1, name) name, |
-static const char* const kLogEventsNames[Logger::NUMBER_OF_LOG_EVENTS] = { |
- LOG_EVENTS_AND_TAGS_LIST(DECLARE_EVENT) |
-}; |
+static const char* kLogEventsNames[CodeEventListener::NUMBER_OF_LOG_EVENTS] = { |
+ LOG_EVENTS_AND_TAGS_LIST(DECLARE_EVENT)}; |
#undef DECLARE_EVENT |
- |
-#define CALL_LISTENERS(Call) \ |
-for (int i = 0; i < listeners_.length(); ++i) { \ |
- listeners_[i]->Call; \ |
-} |
- |
-#define PROFILER_LOG(Call) \ |
- if (isolate_->is_profiling()) { \ |
- isolate_->cpu_profiler()->Call; \ |
- } else { \ |
- } |
- |
static const char* ComputeMarker(SharedFunctionInfo* shared, |
AbstractCode* code) { |
switch (code->kind()) { |
@@ -70,7 +57,7 @@ class CodeEventLogger::NameBuffer { |
utf8_pos_ = 0; |
} |
- void Init(Logger::LogEventsAndTags tag) { |
+ void Init(CodeEventListener::LogEventsAndTags tag) { |
Reset(); |
AppendBytes(kLogEventsNames[tag]); |
AppendByte(':'); |
@@ -164,21 +151,21 @@ CodeEventLogger::CodeEventLogger() : name_buffer_(new NameBuffer) { } |
CodeEventLogger::~CodeEventLogger() { delete name_buffer_; } |
-void CodeEventLogger::CodeCreateEvent(Logger::LogEventsAndTags tag, |
+void CodeEventLogger::CodeCreateEvent(CodeEventListener::LogEventsAndTags tag, |
AbstractCode* code, const char* comment) { |
name_buffer_->Init(tag); |
name_buffer_->AppendBytes(comment); |
LogRecordedBuffer(code, NULL, name_buffer_->get(), name_buffer_->size()); |
} |
-void CodeEventLogger::CodeCreateEvent(Logger::LogEventsAndTags tag, |
+void CodeEventLogger::CodeCreateEvent(CodeEventListener::LogEventsAndTags tag, |
AbstractCode* code, Name* name) { |
name_buffer_->Init(tag); |
name_buffer_->AppendName(name); |
LogRecordedBuffer(code, NULL, name_buffer_->get(), name_buffer_->size()); |
} |
-void CodeEventLogger::CodeCreateEvent(Logger::LogEventsAndTags tag, |
+void CodeEventLogger::CodeCreateEvent(CodeEventListener::LogEventsAndTags tag, |
AbstractCode* code, |
SharedFunctionInfo* shared, Name* name) { |
name_buffer_->Init(tag); |
@@ -187,7 +174,7 @@ void CodeEventLogger::CodeCreateEvent(Logger::LogEventsAndTags tag, |
LogRecordedBuffer(code, shared, name_buffer_->get(), name_buffer_->size()); |
} |
-void CodeEventLogger::CodeCreateEvent(Logger::LogEventsAndTags tag, |
+void CodeEventLogger::CodeCreateEvent(CodeEventListener::LogEventsAndTags tag, |
AbstractCode* code, |
SharedFunctionInfo* shared, Name* source, |
int line, int column) { |
@@ -207,7 +194,7 @@ void CodeEventLogger::CodeCreateEvent(Logger::LogEventsAndTags tag, |
LogRecordedBuffer(code, shared, name_buffer_->get(), name_buffer_->size()); |
} |
-void CodeEventLogger::CodeCreateEvent(Logger::LogEventsAndTags tag, |
+void CodeEventLogger::CodeCreateEvent(CodeEventListener::LogEventsAndTags tag, |
AbstractCode* code, int args_count) { |
name_buffer_->Init(tag); |
name_buffer_->AppendInt(args_count); |
@@ -216,7 +203,7 @@ void CodeEventLogger::CodeCreateEvent(Logger::LogEventsAndTags tag, |
void CodeEventLogger::RegExpCodeCreateEvent(AbstractCode* code, |
String* source) { |
- name_buffer_->Init(Logger::REG_EXP_TAG); |
+ name_buffer_->Init(CodeEventListener::REG_EXP_TAG); |
name_buffer_->AppendString(source); |
LogRecordedBuffer(code, NULL, name_buffer_->get(), name_buffer_->size()); |
} |
@@ -774,24 +761,16 @@ Logger::~Logger() { |
delete log_; |
} |
- |
void Logger::addCodeEventListener(CodeEventListener* listener) { |
- DCHECK(!hasCodeEventListener(listener)); |
- listeners_.Add(listener); |
+ bool result = isolate_->code_event_dispatcher()->AddListener(listener); |
+ USE(result); |
+ DCHECK(result); |
} |
- |
void Logger::removeCodeEventListener(CodeEventListener* listener) { |
- DCHECK(hasCodeEventListener(listener)); |
- listeners_.RemoveElement(listener); |
-} |
- |
- |
-bool Logger::hasCodeEventListener(CodeEventListener* listener) { |
- return listeners_.Contains(listener); |
+ isolate_->code_event_dispatcher()->RemoveListener(listener); |
} |
- |
void Logger::ProfilerBeginEvent() { |
if (!log_->IsEnabled()) return; |
Log::MessageBuilder msg(log_); |
@@ -879,7 +858,6 @@ void Logger::SharedLibraryEvent(const std::string& library_path, |
void Logger::CodeDeoptEvent(Code* code, Address pc, int fp_to_sp_delta) { |
- PROFILER_LOG(CodeDeoptEvent(code, pc, fp_to_sp_delta)); |
if (!log_->IsEnabled() || !FLAG_log_internal_timer_events) return; |
Log::MessageBuilder msg(log_); |
int since_epoch = static_cast<int>(timer_.Elapsed().InMicroseconds()); |
@@ -1071,8 +1049,8 @@ void Logger::CallbackEventInternal(const char* prefix, Name* name, |
if (!FLAG_log_code || !log_->IsEnabled()) return; |
Log::MessageBuilder msg(log_); |
msg.Append("%s,%s,-2,", |
- kLogEventsNames[CODE_CREATION_EVENT], |
- kLogEventsNames[CALLBACK_TAG]); |
+ kLogEventsNames[CodeEventListener::CODE_CREATION_EVENT], |
+ kLogEventsNames[CodeEventListener::CALLBACK_TAG]); |
msg.AppendAddress(entry_point); |
if (name->IsString()) { |
base::SmartArrayPointer<char> str = |
@@ -1095,41 +1073,33 @@ void Logger::CallbackEventInternal(const char* prefix, Name* name, |
void Logger::CallbackEvent(Name* name, Address entry_point) { |
- PROFILER_LOG(CallbackEvent(name, entry_point)); |
CallbackEventInternal("", name, entry_point); |
} |
void Logger::GetterCallbackEvent(Name* name, Address entry_point) { |
- PROFILER_LOG(GetterCallbackEvent(name, entry_point)); |
CallbackEventInternal("get ", name, entry_point); |
} |
void Logger::SetterCallbackEvent(Name* name, Address entry_point) { |
- PROFILER_LOG(SetterCallbackEvent(name, entry_point)); |
CallbackEventInternal("set ", name, entry_point); |
} |
static void AppendCodeCreateHeader(Log::MessageBuilder* msg, |
- Logger::LogEventsAndTags tag, |
+ CodeEventListener::LogEventsAndTags tag, |
AbstractCode* code) { |
DCHECK(msg); |
msg->Append("%s,%s,%d,", |
- kLogEventsNames[Logger::CODE_CREATION_EVENT], |
- kLogEventsNames[tag], |
- code->kind()); |
+ kLogEventsNames[CodeEventListener::CODE_CREATION_EVENT], |
+ kLogEventsNames[tag], code->kind()); |
msg->AppendAddress(code->address()); |
msg->Append(",%d,", code->ExecutableSize()); |
} |
-void Logger::CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code, |
- const char* comment) { |
- PROFILER_LOG(CodeCreateEvent(tag, code, comment)); |
- |
+void Logger::CodeCreateEvent(CodeEventListener::LogEventsAndTags tag, |
+ AbstractCode* code, const char* comment) { |
if (!is_logging_code_events()) return; |
- CALL_LISTENERS(CodeCreateEvent(tag, code, comment)); |
- |
if (!FLAG_log_code || !log_->IsEnabled()) return; |
Log::MessageBuilder msg(log_); |
AppendCodeCreateHeader(&msg, tag, code); |
@@ -1137,13 +1107,9 @@ void Logger::CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code, |
msg.WriteToLogFile(); |
} |
-void Logger::CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code, |
- Name* name) { |
- PROFILER_LOG(CodeCreateEvent(tag, code, name)); |
- |
+void Logger::CodeCreateEvent(CodeEventListener::LogEventsAndTags tag, |
+ AbstractCode* code, Name* name) { |
if (!is_logging_code_events()) return; |
- CALL_LISTENERS(CodeCreateEvent(tag, code, name)); |
- |
if (!FLAG_log_code || !log_->IsEnabled()) return; |
Log::MessageBuilder msg(log_); |
AppendCodeCreateHeader(&msg, tag, code); |
@@ -1157,13 +1123,10 @@ void Logger::CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code, |
msg.WriteToLogFile(); |
} |
-void Logger::CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code, |
- SharedFunctionInfo* shared, Name* name) { |
- PROFILER_LOG(CodeCreateEvent(tag, code, shared, name)); |
- |
+void Logger::CodeCreateEvent(CodeEventListener::LogEventsAndTags tag, |
+ AbstractCode* code, SharedFunctionInfo* shared, |
+ Name* name) { |
if (!is_logging_code_events()) return; |
- CALL_LISTENERS(CodeCreateEvent(tag, code, shared, name)); |
- |
if (!FLAG_log_code || !log_->IsEnabled()) return; |
if (code == AbstractCode::cast( |
isolate_->builtins()->builtin(Builtins::kCompileLazy))) { |
@@ -1189,14 +1152,10 @@ void Logger::CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code, |
// Although, it is possible to extract source and line from |
// the SharedFunctionInfo object, we left it to caller |
// to leave logging functions free from heap allocations. |
-void Logger::CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code, |
- SharedFunctionInfo* shared, Name* source, int line, |
- int column) { |
- PROFILER_LOG(CodeCreateEvent(tag, code, shared, source, line, column)); |
- |
+void Logger::CodeCreateEvent(CodeEventListener::LogEventsAndTags tag, |
+ AbstractCode* code, SharedFunctionInfo* shared, |
+ Name* source, int line, int column) { |
if (!is_logging_code_events()) return; |
- CALL_LISTENERS(CodeCreateEvent(tag, code, shared, source, line, column)); |
- |
if (!FLAG_log_code || !log_->IsEnabled()) return; |
Log::MessageBuilder msg(log_); |
AppendCodeCreateHeader(&msg, tag, code); |
@@ -1216,13 +1175,9 @@ void Logger::CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code, |
msg.WriteToLogFile(); |
} |
-void Logger::CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code, |
- int args_count) { |
- PROFILER_LOG(CodeCreateEvent(tag, code, args_count)); |
- |
+void Logger::CodeCreateEvent(CodeEventListener::LogEventsAndTags tag, |
+ AbstractCode* code, int args_count) { |
if (!is_logging_code_events()) return; |
- CALL_LISTENERS(CodeCreateEvent(tag, code, args_count)); |
- |
if (!FLAG_log_code || !log_->IsEnabled()) return; |
Log::MessageBuilder msg(log_); |
AppendCodeCreateHeader(&msg, tag, code); |
@@ -1232,14 +1187,10 @@ void Logger::CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code, |
void Logger::CodeDisableOptEvent(AbstractCode* code, |
SharedFunctionInfo* shared) { |
- PROFILER_LOG(CodeDisableOptEvent(code, shared)); |
- |
if (!is_logging_code_events()) return; |
- CALL_LISTENERS(CodeDisableOptEvent(code, shared)); |
- |
if (!FLAG_log_code || !log_->IsEnabled()) return; |
Log::MessageBuilder msg(log_); |
- msg.Append("%s,", kLogEventsNames[CODE_DISABLE_OPT_EVENT]); |
+ msg.Append("%s,", kLogEventsNames[CodeEventListener::CODE_DISABLE_OPT_EVENT]); |
base::SmartArrayPointer<char> name = |
shared->DebugName()->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
msg.Append("\"%s\",", name.get()); |
@@ -1249,23 +1200,16 @@ void Logger::CodeDisableOptEvent(AbstractCode* code, |
void Logger::CodeMovingGCEvent() { |
- PROFILER_LOG(CodeMovingGCEvent()); |
- |
if (!is_logging_code_events()) return; |
if (!log_->IsEnabled() || !FLAG_ll_prof) return; |
- CALL_LISTENERS(CodeMovingGCEvent()); |
base::OS::SignalCodeMovingGC(); |
} |
void Logger::RegExpCodeCreateEvent(AbstractCode* code, String* source) { |
- PROFILER_LOG(RegExpCodeCreateEvent(code, source)); |
- |
if (!is_logging_code_events()) return; |
- CALL_LISTENERS(RegExpCodeCreateEvent(code, source)); |
- |
if (!FLAG_log_code || !log_->IsEnabled()) return; |
Log::MessageBuilder msg(log_); |
- AppendCodeCreateHeader(&msg, REG_EXP_TAG, code); |
+ AppendCodeCreateHeader(&msg, CodeEventListener::REG_EXP_TAG, code); |
msg.Append('"'); |
msg.AppendDetailed(source, false); |
msg.Append('"'); |
@@ -1273,11 +1217,8 @@ void Logger::RegExpCodeCreateEvent(AbstractCode* code, String* source) { |
} |
void Logger::CodeMoveEvent(AbstractCode* from, Address to) { |
- PROFILER_LOG(CodeMoveEvent(from, to)); |
- |
if (!is_logging_code_events()) return; |
- CALL_LISTENERS(CodeMoveEvent(from, to)); |
- MoveEventInternal(CODE_MOVE_EVENT, from->address(), to); |
+ MoveEventInternal(CodeEventListener::CODE_MOVE_EVENT, from->address(), to); |
} |
void Logger::CodeLinePosInfoAddPositionEvent(void* jit_handler_data, |
@@ -1314,7 +1255,8 @@ void Logger::CodeEndLinePosInfoRecordEvent(AbstractCode* code, |
void Logger::CodeNameEvent(Address addr, int pos, const char* code_name) { |
if (code_name == NULL) return; // Not a code object. |
Log::MessageBuilder msg(log_); |
- msg.Append("%s,%d,", kLogEventsNames[SNAPSHOT_CODE_NAME_EVENT], pos); |
+ msg.Append("%s,%d,", |
+ kLogEventsNames[CodeEventListener::SNAPSHOT_CODE_NAME_EVENT], pos); |
msg.AppendDoubleQuotedString(code_name); |
msg.WriteToLogFile(); |
} |
@@ -1322,13 +1264,11 @@ void Logger::CodeNameEvent(Address addr, int pos, const char* code_name) { |
void Logger::SharedFunctionInfoMoveEvent(Address from, Address to) { |
if (!is_logging_code_events()) return; |
- MoveEventInternal(SHARED_FUNC_MOVE_EVENT, from, to); |
+ MoveEventInternal(CodeEventListener::SHARED_FUNC_MOVE_EVENT, from, to); |
} |
- |
-void Logger::MoveEventInternal(LogEventsAndTags event, |
- Address from, |
- Address to) { |
+void Logger::MoveEventInternal(CodeEventListener::LogEventsAndTags event, |
+ Address from, Address to) { |
if (!FLAG_log_code || !log_->IsEnabled()) return; |
Log::MessageBuilder msg(log_); |
msg.Append("%s,", kLogEventsNames[event]); |
@@ -1440,7 +1380,7 @@ void Logger::TickEvent(TickSample* sample, bool overflow) { |
RuntimeCallTimerEvent(); |
} |
Log::MessageBuilder msg(log_); |
- msg.Append("%s,", kLogEventsNames[TICK_EVENT]); |
+ msg.Append("%s,", kLogEventsNames[CodeEventListener::TICK_EVENT]); |
msg.AppendAddress(sample->pc); |
msg.Append(",%d", static_cast<int>(timer_.Elapsed().InMicroseconds())); |
if (sample->has_external_callback) { |
@@ -1467,6 +1407,7 @@ void Logger::StopProfiler() { |
if (profiler_ != NULL) { |
profiler_->pause(); |
is_logging_ = false; |
+ removeCodeEventListener(this); |
} |
} |
@@ -1548,7 +1489,7 @@ static int EnumerateCompiledFunctions(Heap* heap, |
void Logger::LogCodeObject(Object* object) { |
AbstractCode* code_object = AbstractCode::cast(object); |
- LogEventsAndTags tag = Logger::STUB_TAG; |
+ CodeEventListener::LogEventsAndTags tag = CodeEventListener::STUB_TAG; |
const char* description = "Unknown code from the snapshot"; |
switch (code_object->kind()) { |
case AbstractCode::FUNCTION: |
@@ -1566,28 +1507,28 @@ void Logger::LogCodeObject(Object* object) { |
CodeStub::MajorName(CodeStub::GetMajorKey(code_object->GetCode())); |
if (description == NULL) |
description = "A stub from the snapshot"; |
- tag = Logger::STUB_TAG; |
+ tag = CodeEventListener::STUB_TAG; |
break; |
case AbstractCode::REGEXP: |
description = "Regular expression code"; |
- tag = Logger::REG_EXP_TAG; |
+ tag = CodeEventListener::REG_EXP_TAG; |
break; |
case AbstractCode::BUILTIN: |
description = |
isolate_->builtins()->name(code_object->GetCode()->builtin_index()); |
- tag = Logger::BUILTIN_TAG; |
+ tag = CodeEventListener::BUILTIN_TAG; |
break; |
case AbstractCode::HANDLER: |
description = "An IC handler from the snapshot"; |
- tag = Logger::HANDLER_TAG; |
+ tag = CodeEventListener::HANDLER_TAG; |
break; |
case AbstractCode::KEYED_LOAD_IC: |
description = "A keyed load IC from the snapshot"; |
- tag = Logger::KEYED_LOAD_IC_TAG; |
+ tag = CodeEventListener::KEYED_LOAD_IC_TAG; |
break; |
case AbstractCode::LOAD_IC: |
description = "A load IC from the snapshot"; |
- tag = Logger::LOAD_IC_TAG; |
+ tag = CodeEventListener::LOAD_IC_TAG; |
break; |
case AbstractCode::LOAD_GLOBAL_IC: |
description = "A load global IC from the snapshot"; |
@@ -1595,27 +1536,27 @@ void Logger::LogCodeObject(Object* object) { |
break; |
case AbstractCode::CALL_IC: |
description = "A call IC from the snapshot"; |
- tag = Logger::CALL_IC_TAG; |
+ tag = CodeEventListener::CALL_IC_TAG; |
break; |
case AbstractCode::STORE_IC: |
description = "A store IC from the snapshot"; |
- tag = Logger::STORE_IC_TAG; |
+ tag = CodeEventListener::STORE_IC_TAG; |
break; |
case AbstractCode::KEYED_STORE_IC: |
description = "A keyed store IC from the snapshot"; |
- tag = Logger::KEYED_STORE_IC_TAG; |
+ tag = CodeEventListener::KEYED_STORE_IC_TAG; |
break; |
case AbstractCode::WASM_FUNCTION: |
description = "A Wasm function"; |
- tag = Logger::STUB_TAG; |
+ tag = CodeEventListener::STUB_TAG; |
break; |
case AbstractCode::JS_TO_WASM_FUNCTION: |
description = "A JavaScript to Wasm adapter"; |
- tag = Logger::STUB_TAG; |
+ tag = CodeEventListener::STUB_TAG; |
break; |
case AbstractCode::WASM_TO_JS_FUNCTION: |
description = "A Wasm to JavaScript adapter"; |
- tag = Logger::STUB_TAG; |
+ tag = CodeEventListener::STUB_TAG; |
break; |
case AbstractCode::NUMBER_OF_KINDS: |
UNIMPLEMENTED(); |
@@ -1654,8 +1595,8 @@ void Logger::LogBytecodeHandlers() { |
Code* code = interpreter->GetBytecodeHandler(bytecode, operand_scale); |
std::string bytecode_name = |
interpreter::Bytecodes::ToString(bytecode, operand_scale); |
- CodeCreateEvent(Logger::BYTECODE_HANDLER_TAG, AbstractCode::cast(code), |
- bytecode_name.c_str()); |
+ CodeCreateEvent(CodeEventListener::BYTECODE_HANDLER_TAG, |
+ AbstractCode::cast(code), bytecode_name.c_str()); |
} |
} |
} |
@@ -1674,20 +1615,22 @@ void Logger::LogExistingFunction(Handle<SharedFunctionInfo> shared, |
if (line_num > 0) { |
PROFILE(isolate_, |
CodeCreateEvent( |
- Logger::ToNativeByScript(Logger::LAZY_COMPILE_TAG, *script), |
+ Logger::ToNativeByScript( |
+ CodeEventListener::LAZY_COMPILE_TAG, *script), |
*code, *shared, *script_name, line_num, column_num)); |
} else { |
// Can't distinguish eval and script here, so always use Script. |
- PROFILE(isolate_, CodeCreateEvent(Logger::ToNativeByScript( |
- Logger::SCRIPT_TAG, *script), |
- *code, *shared, *script_name)); |
+ PROFILE(isolate_, |
+ CodeCreateEvent(Logger::ToNativeByScript( |
+ CodeEventListener::SCRIPT_TAG, *script), |
+ *code, *shared, *script_name)); |
} |
} else { |
PROFILE(isolate_, |
- CodeCreateEvent( |
- Logger::ToNativeByScript(Logger::LAZY_COMPILE_TAG, *script), |
- *code, *shared, isolate_->heap()->empty_string(), line_num, |
- column_num)); |
+ CodeCreateEvent(Logger::ToNativeByScript( |
+ CodeEventListener::LAZY_COMPILE_TAG, *script), |
+ *code, *shared, isolate_->heap()->empty_string(), |
+ line_num, column_num)); |
} |
} else if (shared->IsApiFunction()) { |
// API function. |
@@ -1703,8 +1646,8 @@ void Logger::LogExistingFunction(Handle<SharedFunctionInfo> shared, |
PROFILE(isolate_, CallbackEvent(*func_name, entry_point)); |
} |
} else { |
- PROFILE(isolate_, CodeCreateEvent(Logger::LAZY_COMPILE_TAG, *code, *shared, |
- *func_name)); |
+ PROFILE(isolate_, CodeCreateEvent(CodeEventListener::LAZY_COMPILE_TAG, |
+ *code, *shared, *func_name)); |
} |
} |
@@ -1817,7 +1760,6 @@ bool Logger::SetUp(Isolate* isolate) { |
PrepareLogFileName(log_file_name, isolate, FLAG_logfile); |
log_->Initialize(log_file_name.str().c_str()); |
- |
if (FLAG_perf_basic_prof) { |
perf_basic_logger_ = new PerfBasicLogger(); |
addCodeEventListener(perf_basic_logger_); |
@@ -1847,6 +1789,10 @@ bool Logger::SetUp(Isolate* isolate) { |
profiler_->Engage(); |
} |
+ if (is_logging_) { |
+ addCodeEventListener(this); |
+ } |
+ |
return true; |
} |