Revision: 15749
Author:   [email protected]
Date:     Thu Jul 18 06:18:46 2013
Log:      Extract JitLogger from Logger class.

Second patch from the set.

BUG=260203
TEST=logic wasn't changed
[email protected], [email protected]

Review URL: https://codereview.chromium.org/19761003
http://code.google.com/p/v8/source/detail?r=15749

Modified:
 /branches/bleeding_edge/src/log.cc
 /branches/bleeding_edge/src/log.h

=======================================
--- /branches/bleeding_edge/src/log.cc  Mon Jul 15 04:35:39 2013
+++ /branches/bleeding_edge/src/log.cc  Thu Jul 18 06:18:46 2013
@@ -445,10 +445,10 @@
     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 @@
 }


-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::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::IssueCodeRemovedEvent(Address from) {
+void JitLogger::CodeRemovedEvent(Address from) {
   Code* from_code = Code::cast(HeapObject::FromAddress(from));

   JitCodeEvent event;
@@ -515,7 +543,7 @@
   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::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::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::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 @@
                              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 @@
                              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 @@
                              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 @@
                              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, 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::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::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::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::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 @@

 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();
@@ -1943,6 +1968,11 @@
     delete ll_logger_;
     ll_logger_ = NULL;
   }
+
+  if (jit_logger_) {
+    delete jit_logger_;
+    jit_logger_ = NULL;
+  }

   return log_->Close();
 }
=======================================
--- /branches/bleeding_edge/src/log.h   Mon Jul 15 04:35:39 2013
+++ /branches/bleeding_edge/src/log.h   Thu Jul 18 06:18:46 2013
@@ -151,6 +151,7 @@
 // original tags when writing to the log.


+class JitLogger;
 class LowLevelLogger;
 class Sampler;

@@ -336,13 +337,9 @@
   bool is_logging() {
     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 @@
   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 @@

   Log* log_;
   LowLevelLogger* ll_logger_;
+  JitLogger* jit_logger_;

   NameBuffer* name_buffer_;

@@ -484,9 +469,6 @@
   // '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_;

--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to