Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / v8 / src / profile-generator.cc
index 9e7a869..6017f12 100644 (file)
@@ -8,8 +8,8 @@
 
 #include "src/compiler.h"
 #include "src/debug.h"
-#include "src/sampler.h"
 #include "src/global-handles.h"
+#include "src/sampler.h"
 #include "src/scopeinfo.h"
 #include "src/unicode.h"
 #include "src/zone-inl.h"
@@ -107,17 +107,12 @@ const char* StringsStorage::GetName(int index) {
 
 
 const char* StringsStorage::GetFunctionName(Name* name) {
-  return BeautifyFunctionName(GetName(name));
+  return GetName(name);
 }
 
 
 const char* StringsStorage::GetFunctionName(const char* name) {
-  return BeautifyFunctionName(GetCopy(name));
-}
-
-
-const char* StringsStorage::BeautifyFunctionName(const char* name) {
-  return (*name == 0) ? ProfileGenerator::kAnonymousFunctionName : name;
+  return GetCopy(name);
 }
 
 
@@ -207,53 +202,13 @@ ProfileNode* ProfileNode::FindOrAddChild(CodeEntry* entry) {
 }
 
 
-void ProfileNode::IncrementLineTicks(int src_line) {
-  if (src_line == v8::CpuProfileNode::kNoLineNumberInfo) return;
-  // Increment a hit counter of a certain source line.
-  // Add a new source line if not found.
-  HashMap::Entry* e =
-    line_ticks_.Lookup(reinterpret_cast<void*>(src_line), src_line, true);
-  if (NULL != e) {
-    e->value = static_cast<char*>(e->value) + 1;
-  }
-}
-
-
-bool ProfileNode::GetLineTicks(LineTick* entries,
-                               unsigned int number) const {
-  if (NULL == entries || number == 0) {
-    return false;
-  }
-
-  unsigned lineNumber = line_ticks_.occupancy();
-  if (lineNumber == 0) return false;
-  if (number < lineNumber) return false;
-
-  LineTick* entry = entries;
-
-  for (HashMap::Entry* p = line_ticks_.Start();
-       p != NULL;
-       p = line_ticks_.Next(p), entry++) {
-    entry->line = reinterpret_cast<intptr_t>(p->key);
-    entry->ticks = reinterpret_cast<intptr_t>(p->value);
-  }
-
-  return true;
-}
-
-
 void ProfileNode::Print(int indent) {
-  OS::Print("%5u %*s %s%s %d #%d %s",
-            self_ticks_,
-            indent, "",
-            entry_->name_prefix(),
-            entry_->name(),
-            entry_->script_id(),
-            id(),
-            entry_->bailout_reason());
+  base::OS::Print("%5u %*s %s%s %d #%d %s", self_ticks_, indent, "",
+                  entry_->name_prefix(), entry_->name(), entry_->script_id(),
+                  id(), entry_->bailout_reason());
   if (entry_->resource_name()[0] != '\0')
-    OS::Print(" %s:%d", entry_->resource_name(), entry_->line_number());
-  OS::Print("\n");
+    base::OS::Print(" %s:%d", entry_->resource_name(), entry_->line_number());
+  base::OS::Print("\n");
   for (HashMap::Entry* p = children_.Start();
        p != NULL;
        p = children_.Next(p)) {
@@ -287,8 +242,7 @@ ProfileTree::~ProfileTree() {
 }
 
 
-ProfileNode* ProfileTree::AddPathFromEnd(const Vector<CodeEntry*>& path,
-                                         int src_line) {
+ProfileNode* ProfileTree::AddPathFromEnd(const Vector<CodeEntry*>& path) {
   ProfileNode* node = root_;
   for (CodeEntry** entry = path.start() + path.length() - 1;
        entry != path.start() - 1;
@@ -298,15 +252,11 @@ ProfileNode* ProfileTree::AddPathFromEnd(const Vector<CodeEntry*>& path,
     }
   }
   node->IncrementSelfTicks();
-  if (src_line != v8::CpuProfileNode::kNoLineNumberInfo) {
-    node->IncrementLineTicks(src_line);
-  }
   return node;
 }
 
 
-void ProfileTree::AddPathFromStart(const Vector<CodeEntry*>& path,
-                                   int src_line) {
+void ProfileTree::AddPathFromStart(const Vector<CodeEntry*>& path) {
   ProfileNode* node = root_;
   for (CodeEntry** entry = path.start();
        entry != path.start() + path.length();
@@ -316,9 +266,6 @@ void ProfileTree::AddPathFromStart(const Vector<CodeEntry*>& path,
     }
   }
   node->IncrementSelfTicks();
-  if (src_line != v8::CpuProfileNode::kNoLineNumberInfo) {
-    node->IncrementLineTicks(src_line);
-  }
 }
 
 
@@ -375,13 +322,13 @@ void ProfileTree::TraverseDepthFirst(Callback* callback) {
 CpuProfile::CpuProfile(const char* title, bool record_samples)
     : title_(title),
       record_samples_(record_samples),
-      start_time_(TimeTicks::HighResolutionNow()) {
+      start_time_(base::TimeTicks::HighResolutionNow()) {
 }
 
 
-void CpuProfile::AddPath(TimeTicks timestamp, const Vector<CodeEntry*>& path,
-                         int src_line) {
-  ProfileNode* top_frame_node = top_down_.AddPathFromEnd(path, src_line);
+void CpuProfile::AddPath(base::TimeTicks timestamp,
+                         const Vector<CodeEntry*>& path) {
+  ProfileNode* top_frame_node = top_down_.AddPathFromEnd(path);
   if (record_samples_) {
     timestamps_.Add(timestamp);
     samples_.Add(top_frame_node);
@@ -390,12 +337,12 @@ void CpuProfile::AddPath(TimeTicks timestamp, const Vector<CodeEntry*>& path,
 
 
 void CpuProfile::CalculateTotalTicksAndSamplingRate() {
-  end_time_ = TimeTicks::HighResolutionNow();
+  end_time_ = base::TimeTicks::HighResolutionNow();
 }
 
 
 void CpuProfile::Print() {
-  OS::Print("[Top down]:\n");
+  base::OS::Print("[Top down]:\n");
   top_down_.Print();
 }
 
@@ -447,7 +394,7 @@ int CodeMap::GetSharedId(Address addr) {
   // For shared function entries, 'size' field is used to store their IDs.
   if (tree_.Find(addr, &locator)) {
     const CodeEntryInfo& entry = locator.value();
-    ASSERT(entry.entry == kSharedFunctionCodeEntry);
+    DCHECK(entry.entry == kSharedFunctionCodeEntry);
     return entry.size;
   } else {
     tree_.Insert(addr, &locator);
@@ -472,9 +419,9 @@ void CodeMap::CodeTreePrinter::Call(
     const Address& key, const CodeMap::CodeEntryInfo& value) {
   // For shared function entries, 'size' field is used to store their IDs.
   if (value.entry == kSharedFunctionCodeEntry) {
-    OS::Print("%p SharedFunctionInfo %d\n", key, value.size);
+    base::OS::Print("%p SharedFunctionInfo %d\n", key, value.size);
   } else {
-    OS::Print("%p %5d %s\n", key, value.size, value.entry->name());
+    base::OS::Print("%p %5d %s\n", key, value.size, value.entry->name());
   }
 }
 
@@ -517,9 +464,10 @@ bool CpuProfilesCollection::StartProfiling(const char* title,
   }
   for (int i = 0; i < current_profiles_.length(); ++i) {
     if (strcmp(current_profiles_[i]->title(), title) == 0) {
-      // Ignore attempts to start profile with the same title.
+      // Ignore attempts to start profile with the same title...
       current_profiles_semaphore_.Signal();
-      return false;
+      // ... though return true to force it collect a sample.
+      return true;
     }
   }
   current_profiles_.Add(new CpuProfile(title, record_samples));
@@ -569,13 +517,13 @@ void CpuProfilesCollection::RemoveProfile(CpuProfile* profile) {
 
 
 void CpuProfilesCollection::AddPathToCurrentProfiles(
-    TimeTicks timestamp, const Vector<CodeEntry*>& path, int src_line) {
+    base::TimeTicks timestamp, const Vector<CodeEntry*>& path) {
   // As starting / stopping profiles is rare relatively to this
   // method, we don't bother minimizing the duration of lock holding,
   // e.g. copying contents of the list to a local vector.
   current_profiles_semaphore_.Wait();
   for (int i = 0; i < current_profiles_.length(); ++i) {
-    current_profiles_[i]->AddPath(timestamp, path, src_line);
+    current_profiles_[i]->AddPath(timestamp, path);
   }
   current_profiles_semaphore_.Signal();
 }
@@ -587,22 +535,18 @@ CodeEntry* CpuProfilesCollection::NewCodeEntry(
       const char* name_prefix,
       const char* resource_name,
       int line_number,
-      int column_number,
-      JITLineInfoTable* line_info) {
+      int column_number) {
   CodeEntry* code_entry = new CodeEntry(tag,
                                         name,
                                         name_prefix,
                                         resource_name,
                                         line_number,
-                                        column_number,
-                                        line_info);
+                                        column_number);
   code_entries_.Add(code_entry);
   return code_entry;
 }
 
 
-const char* const ProfileGenerator::kAnonymousFunctionName =
-    "(anonymous function)";
 const char* const ProfileGenerator::kProgramEntryName =
     "(program)";
 const char* const ProfileGenerator::kIdleEntryName =
@@ -628,15 +572,6 @@ ProfileGenerator::ProfileGenerator(CpuProfilesCollection* profiles)
 }
 
 
-static int GetSourceLine(unsigned int pc_offset, CodeEntry* entry) {
-  int src_line = v8::CpuProfileNode::kNoLineNumberInfo;
-  const JITLineInfoTable& table = entry->line_info();
-  if (!table.entries()->length()) return src_line;
-  src_line = table.GetSourceLineNumber(pc_offset);
-  return src_line;
-}
-
-
 void ProfileGenerator::RecordTickSample(const TickSample& sample) {
   // Allocate space for stack frames + pc + function + vm-state.
   ScopedVector<CodeEntry*> entries(sample.frames_count + 3);
@@ -644,7 +579,6 @@ void ProfileGenerator::RecordTickSample(const TickSample& sample) {
   // entries vector with NULL values.
   CodeEntry** entry = entries.start();
   memset(entry, 0, entries.length() * sizeof(*entry));
-  int src_line = v8::CpuProfileNode::kNoLineNumberInfo;
   if (sample.pc != NULL) {
     if (sample.has_external_callback && sample.state == EXTERNAL &&
         sample.top_frame_type == StackFrame::EXIT) {
@@ -660,11 +594,9 @@ void ProfileGenerator::RecordTickSample(const TickSample& sample) {
       // ebp contains return address of the current function and skips caller's
       // frame. Check for this case and just skip such samples.
       if (pc_entry) {
-        Code* code = Code::cast(HeapObject::FromAddress(start));
         List<OffsetRange>* ranges = pc_entry->no_frame_ranges();
-        src_line = GetSourceLine(sample.pc - code->instruction_start(),
-                                 pc_entry);
         if (ranges) {
+          Code* code = Code::cast(HeapObject::FromAddress(start));
           int pc_offset = static_cast<int>(
               sample.pc - code->instruction_start());
           for (int i = 0; i < ranges->length(); i++) {
@@ -690,25 +622,11 @@ void ProfileGenerator::RecordTickSample(const TickSample& sample) {
       }
     }
 
-    bool unresolved_src = (src_line == v8::CpuProfileNode::kNoLineNumberInfo) ?
-                          true : false;
-
     for (const Address* stack_pos = sample.stack,
            *stack_end = stack_pos + sample.frames_count;
          stack_pos != stack_end;
          ++stack_pos) {
-      Address start = NULL;
-      *entry = code_map_.FindEntry(*stack_pos, &start);
-      if (unresolved_src && NULL != *entry) {
-          Code* code = Code::cast(HeapObject::FromAddress(start));
-          src_line = GetSourceLine(*stack_pos - code->instruction_start(),
-                                   *entry);
-          if (src_line == v8::CpuProfileNode::kNoLineNumberInfo) {
-            src_line = (*entry)->line_number();
-          }
-          unresolved_src = false;
-      }
-      entry++;
+      *entry++ = code_map_.FindEntry(*stack_pos);
     }
   }
 
@@ -726,7 +644,7 @@ void ProfileGenerator::RecordTickSample(const TickSample& sample) {
     }
   }
 
-  profiles_->AddPathToCurrentProfiles(sample.timestamp, entries, src_line);
+  profiles_->AddPathToCurrentProfiles(sample.timestamp, entries);
 }