Extract JitLogger from Logger class.
authorloislo@chromium.org <loislo@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Thu, 18 Jul 2013 13:18:46 +0000 (13:18 +0000)
committerloislo@chromium.org <loislo@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Thu, 18 Jul 2013 13:18:46 +0000 (13:18 +0000)
Second patch from the set.

BUG=260203
TEST=logic wasn't changed
R=yangguo@chromium.org, yurys@chromium.org

Review URL: https://codereview.chromium.org/19761003

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@15749 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

src/log.cc
src/log.h

index 843d128..9f2d983 100644 (file)
@@ -445,10 +445,10 @@ Logger::Logger(Isolate* isolate)
     cpu_profiler_nesting_(0),
     log_(new Log(this)),
     ll_logger_(NULL),
+    jit_logger_(NULL),
     name_buffer_(new NameBuffer),
     address_to_name_map_(NULL),
     is_initialized_(false),
-    code_event_handler_(NULL),
     last_address_(NULL),
     prev_sp_(NULL),
     prev_function_(NULL),
@@ -465,10 +465,38 @@ Logger::~Logger() {
 }
 
 
-void Logger::IssueCodeAddedEvent(Code* code,
-                                 Script* script,
-                                 const char* name,
-                                 size_t name_len) {
+class JitLogger {
+ public:
+  explicit JitLogger(JitCodeEventHandler code_event_handler);
+
+  void CodeCreateEvent(Code* code, Script* script,
+                       const char* name, size_t name_len);
+  void CodeMovedEvent(Address from, Address to);
+  void CodeRemovedEvent(Address from);
+  void  AddCodeLinePosInfoEvent(
+      void* jit_handler_data,
+      int pc_offset,
+      int position,
+      JitCodeEvent::PositionType position_type);
+  void* StartCodePosInfoEvent();
+  void EndCodePosInfoEvent(Code* code, void* jit_handler_data);
+
+ private:
+  JitCodeEventHandler code_event_handler_;
+};
+
+#define JIT_LOG(Call) if (jit_logger_) jit_logger_->Call;
+
+
+JitLogger::JitLogger(JitCodeEventHandler code_event_handler)
+    : code_event_handler_(code_event_handler) {
+}
+
+
+void JitLogger::CodeCreateEvent(Code* code,
+                                Script* script,
+                                const char* name,
+                                size_t name_len) {
   JitCodeEvent event;
   memset(&event, 0, sizeof(event));
   event.type = JitCodeEvent::CODE_ADDED;
@@ -484,7 +512,7 @@ void Logger::IssueCodeAddedEvent(Code* code,
 }
 
 
-void Logger::IssueCodeMovedEvent(Address from, Address to) {
+void JitLogger::CodeMovedEvent(Address from, Address to) {
   Code* from_code = Code::cast(HeapObject::FromAddress(from));
 
   JitCodeEvent event;
@@ -504,7 +532,7 @@ void Logger::IssueCodeMovedEvent(Address from, Address to) {
 }
 
 
-void Logger::IssueCodeRemovedEvent(Address from) {
+void JitLogger::CodeRemovedEvent(Address from) {
   Code* from_code = Code::cast(HeapObject::FromAddress(from));
 
   JitCodeEvent event;
@@ -515,7 +543,7 @@ void Logger::IssueCodeRemovedEvent(Address from) {
   code_event_handler_(&event);
 }
 
-void Logger::IssueAddCodeLinePosInfoEvent(
+void JitLogger::AddCodeLinePosInfoEvent(
     void* jit_handler_data,
     int pc_offset,
     int position,
@@ -532,7 +560,7 @@ void Logger::IssueAddCodeLinePosInfoEvent(
 }
 
 
-void* Logger::IssueStartCodePosInfoEvent() {
+void* JitLogger::StartCodePosInfoEvent() {
   JitCodeEvent event;
   memset(&event, 0, sizeof(event));
   event.type = JitCodeEvent::CODE_START_LINE_INFO_RECORDING;
@@ -542,7 +570,7 @@ void* Logger::IssueStartCodePosInfoEvent() {
 }
 
 
-void Logger::IssueEndCodePosInfoEvent(Code* code, void* jit_handler_data) {
+void JitLogger::EndCodePosInfoEvent(Code* code, void* jit_handler_data) {
   JitCodeEvent event;
   memset(&event, 0, sizeof(event));
   event.type = JitCodeEvent::CODE_END_LINE_INFO_RECORDING;
@@ -983,14 +1011,10 @@ void Logger::InitNameBuffer(LogEventsAndTags tag) {
 
 
 void Logger::LogRecordedBuffer(Code* code, SharedFunctionInfo* shared) {
-  if (code_event_handler_ != NULL) {
-    Script* script = shared && shared->script()->IsScript() ?
-        Script::cast(shared->script()) : NULL;
-    IssueCodeAddedEvent(code,
-                        script,
-                        name_buffer_->get(),
-                        name_buffer_->size());
-  }
+  Script* script = shared && shared->script()->IsScript() ?
+      Script::cast(shared->script()) : NULL;
+  JIT_LOG(CodeCreateEvent(code, script, name_buffer_->get(),
+                          name_buffer_->size()));
   if (!log_->IsEnabled()) return;
   LL_LOG(CodeCreateEvent(code, name_buffer_->get(), name_buffer_->size()));
   if (Serializer::enabled()) {
@@ -1029,7 +1053,7 @@ void Logger::CodeCreateEvent(LogEventsAndTags tag,
                              Code* code,
                              const char* comment) {
   if (!is_logging_code_events()) return;
-  if (FLAG_ll_prof || Serializer::enabled() || code_event_handler_ != NULL) {
+  if (FLAG_ll_prof || Serializer::enabled() || jit_logger_ != NULL) {
     InitNameBuffer(tag);
     name_buffer_->AppendBytes(comment);
     LogRecordedBuffer(code, NULL);
@@ -1048,7 +1072,7 @@ void Logger::CodeCreateEvent(LogEventsAndTags tag,
                              Code* code,
                              Name* name) {
   if (!is_logging_code_events()) return;
-  if (FLAG_ll_prof || Serializer::enabled() || code_event_handler_ != NULL) {
+  if (FLAG_ll_prof || Serializer::enabled() || jit_logger_ != NULL) {
     InitNameBuffer(tag);
     AppendName(name);
     LogRecordedBuffer(code, NULL);
@@ -1085,7 +1109,7 @@ void Logger::CodeCreateEvent(LogEventsAndTags tag,
                              CompilationInfo* info,
                              Name* name) {
   if (!is_logging_code_events()) return;
-  if (FLAG_ll_prof || Serializer::enabled() || code_event_handler_ != NULL) {
+  if (FLAG_ll_prof || Serializer::enabled() || jit_logger_ != NULL) {
     InitNameBuffer(tag);
     name_buffer_->AppendBytes(ComputeMarker(code));
     AppendName(name);
@@ -1123,7 +1147,7 @@ void Logger::CodeCreateEvent(LogEventsAndTags tag,
                              CompilationInfo* info,
                              Name* source, int line) {
   if (!is_logging_code_events()) return;
-  if (FLAG_ll_prof || Serializer::enabled() || code_event_handler_ != NULL) {
+  if (FLAG_ll_prof || Serializer::enabled() || jit_logger_ != NULL) {
     InitNameBuffer(tag);
     name_buffer_->AppendBytes(ComputeMarker(code));
     name_buffer_->AppendString(shared->DebugName());
@@ -1163,7 +1187,7 @@ void Logger::CodeCreateEvent(LogEventsAndTags tag,
 
 void Logger::CodeCreateEvent(LogEventsAndTags tag, Code* code, int args_count) {
   if (!is_logging_code_events()) return;
-  if (FLAG_ll_prof || Serializer::enabled() || code_event_handler_ != NULL) {
+  if (FLAG_ll_prof || Serializer::enabled() || jit_logger_ != NULL) {
     InitNameBuffer(tag);
     name_buffer_->AppendInt(args_count);
     LogRecordedBuffer(code, NULL);
@@ -1187,7 +1211,7 @@ void Logger::CodeMovingGCEvent() {
 
 void Logger::RegExpCodeCreateEvent(Code* code, String* source) {
   if (!is_logging_code_events()) return;
-  if (FLAG_ll_prof || Serializer::enabled() || code_event_handler_ != NULL) {
+  if (FLAG_ll_prof || Serializer::enabled() || jit_logger_ != NULL) {
     InitNameBuffer(REG_EXP_TAG);
     name_buffer_->AppendString(source);
     LogRecordedBuffer(code, NULL);
@@ -1205,7 +1229,7 @@ void Logger::RegExpCodeCreateEvent(Code* code, String* source) {
 
 
 void Logger::CodeMoveEvent(Address from, Address to) {
-  if (code_event_handler_ != NULL) IssueCodeMovedEvent(from, to);
+  JIT_LOG(CodeMovedEvent(from, to));
   if (!log_->IsEnabled()) return;
   LL_LOG(CodeMoveEvent(from, to));
   if (Serializer::enabled() && address_to_name_map_ != NULL) {
@@ -1216,7 +1240,7 @@ void Logger::CodeMoveEvent(Address from, Address to) {
 
 
 void Logger::CodeDeleteEvent(Address from) {
-  if (code_event_handler_ != NULL) IssueCodeRemovedEvent(from);
+  JIT_LOG(CodeRemovedEvent(from));
   if (!log_->IsEnabled()) return;
   LL_LOG(CodeDeleteEvent(from));
   if (Serializer::enabled() && address_to_name_map_ != NULL) {
@@ -1228,37 +1252,31 @@ void Logger::CodeDeleteEvent(Address from) {
 void Logger::CodeLinePosInfoAddPositionEvent(void* jit_handler_data,
                                      int pc_offset,
                                      int position) {
-  if (code_event_handler_ != NULL) {
-    IssueAddCodeLinePosInfoEvent(jit_handler_data,
-                                 pc_offset,
-                                 position,
-                                 JitCodeEvent::POSITION);
-  }
+  JIT_LOG(AddCodeLinePosInfoEvent(jit_handler_data,
+                                  pc_offset,
+                                  position,
+                                  JitCodeEvent::POSITION));
 }
 
 void Logger::CodeLinePosInfoAddStatementPositionEvent(void* jit_handler_data,
                                                       int pc_offset,
                                                       int position) {
-  if (code_event_handler_ != NULL) {
-    IssueAddCodeLinePosInfoEvent(jit_handler_data,
-                                 pc_offset,
-                                 position,
-                                 JitCodeEvent::STATEMENT_POSITION);
-  }
+  JIT_LOG(AddCodeLinePosInfoEvent(jit_handler_data,
+                                  pc_offset,
+                                  position,
+                                  JitCodeEvent::STATEMENT_POSITION));
 }
 
 
 void Logger::CodeStartLinePosInfoRecordEvent(PositionsRecorder* pos_recorder) {
-  if (code_event_handler_ != NULL) {
-      pos_recorder->AttachJITHandlerData(IssueStartCodePosInfoEvent());
+  if (jit_logger_ != NULL) {
+      pos_recorder->AttachJITHandlerData(jit_logger_->StartCodePosInfoEvent());
   }
 }
 
 void Logger::CodeEndLinePosInfoRecordEvent(Code* code,
                                            void* jit_handler_data) {
-  if (code_event_handler_ != NULL) {
-    IssueEndCodePosInfoEvent(code, jit_handler_data);
-  }
+  JIT_LOG(EndCodePosInfoEvent(code, jit_handler_data));
 }
 
 
@@ -1910,9 +1928,16 @@ bool Logger::SetUp(Isolate* isolate) {
 
 void Logger::SetCodeEventHandler(uint32_t options,
                                  JitCodeEventHandler event_handler) {
-  code_event_handler_ = event_handler;
+  if (jit_logger_) {
+      delete jit_logger_;
+      jit_logger_ = NULL;
+  }
 
-  if (code_event_handler_ != NULL && (options & kJitCodeEventEnumExisting)) {
+  if (event_handler) {
+    jit_logger_ = new JitLogger(event_handler);
+  }
+
+  if (jit_logger_ != NULL && (options & kJitCodeEventEnumExisting)) {
     HandleScope scope(isolate_);
     LogCodeObjects();
     LogCompiledFunctions();
@@ -1944,6 +1969,11 @@ FILE* Logger::TearDown() {
     ll_logger_ = NULL;
   }
 
+  if (jit_logger_) {
+    delete jit_logger_;
+    jit_logger_ = NULL;
+  }
+
   return log_->Close();
 }
 
index bb3dbd5..863f71d 100644 (file)
--- a/src/log.h
+++ b/src/log.h
@@ -151,6 +151,7 @@ class CompilationInfo;
 // original tags when writing to the log.
 
 
+class JitLogger;
 class LowLevelLogger;
 class Sampler;
 
@@ -337,12 +338,8 @@ class Logger {
     return logging_nesting_ > 0;
   }
 
-  bool is_code_event_handler_enabled() {
-    return code_event_handler_ != NULL;
-  }
-
   bool is_logging_code_events() {
-    return is_logging() || code_event_handler_ != NULL;
+    return is_logging() || jit_logger_ != NULL;
   }
 
   // Pause/Resume collection of profiling data.
@@ -383,19 +380,6 @@ class Logger {
   explicit Logger(Isolate* isolate);
   ~Logger();
 
-  // Issue code notifications.
-  void IssueCodeAddedEvent(Code* code,
-                           Script* script,
-                           const char* name,
-                           size_t name_len);
-  void IssueCodeMovedEvent(Address from, Address to);
-  void IssueCodeRemovedEvent(Address from);
-  void IssueAddCodeLinePosInfoEvent(void* jit_handler_data,
-                                    int pc_offset,
-                                    int position,
-                                    JitCodeEvent::PositionType position_Type);
-  void* IssueStartCodePosInfoEvent();
-  void IssueEndCodePosInfoEvent(Code* code, void* jit_handler_data);
   // Emits the profiler's first message.
   void ProfilerBeginEvent();
 
@@ -475,6 +459,7 @@ class Logger {
 
   Log* log_;
   LowLevelLogger* ll_logger_;
+  JitLogger* jit_logger_;
 
   NameBuffer* name_buffer_;
 
@@ -484,9 +469,6 @@ class Logger {
   // 'true' between SetUp() and TearDown().
   bool is_initialized_;
 
-  // The code event handler - if any.
-  JitCodeEventHandler code_event_handler_;
-
   // Support for 'incremental addresses' in compressed logs:
   //  LogMessageBuilder::AppendAddress(Address addr)
   Address last_address_;