CpuProfiler: simplify inlined function info magic.
authorloislo <loislo@chromium.org>
Wed, 11 Mar 2015 13:51:18 +0000 (06:51 -0700)
committerCommit bot <commit-bot@chromium.org>
Wed, 11 Mar 2015 13:51:25 +0000 (13:51 +0000)
I did some investigation and found that in the most cases
the old schema with the separate List for functions and inlines
gives us no memory benefits because more frequently we inlines
different functions into parent function. So the plain schema
wins a tens or even hundreds bytes a few thousand times.

The only drawback is that we will print the inlined body
the each time when we inline it. But is not a problem
because it happens only under FLAG_hydrogen_track_positions.

Also I added script_id to the structure, so it could be used later
by cpu-profiler.

BUG=chromium:452067
LOG=n

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

Cr-Commit-Position: refs/heads/master@{#27134}

src/compiler.cc
src/compiler.h
src/hydrogen.cc

index 2e07a671d892ecdfca81564f3686906da3e7ef29..2aceedbd95de7822011d2444e3f9af6b9c995c24 100644 (file)
@@ -118,10 +118,8 @@ void CompilationInfo::Initialize(Isolate* isolate,
                    ? new List<OffsetRange>(2) : NULL;
   if (FLAG_hydrogen_track_positions) {
     inlined_function_infos_ = new List<InlinedFunctionInfo>(5);
-    inlining_id_to_function_id_ = new List<int>(5);
   } else {
     inlined_function_infos_ = NULL;
-    inlining_id_to_function_id_ = NULL;
   }
 
   for (int i = 0; i < DependentCode::kGroupCount; i++) {
@@ -163,7 +161,6 @@ CompilationInfo::~CompilationInfo() {
   delete deferred_handles_;
   delete no_frame_ranges_;
   delete inlined_function_infos_;
-  delete inlining_id_to_function_id_;
 #ifdef DEBUG
   // Check that no dependent maps have been added or added dependent maps have
   // been rolled back or committed.
@@ -277,52 +274,46 @@ bool CompilationInfo::is_simple_parameter_list() {
 
 
 int CompilationInfo::TraceInlinedFunction(Handle<SharedFunctionInfo> shared,
-                                          SourcePosition position) {
+                                          SourcePosition position,
+                                          int parent_id) {
   DCHECK(FLAG_hydrogen_track_positions);
-
   DCHECK(inlined_function_infos_);
-  DCHECK(inlining_id_to_function_id_);
-  int id = 0;
-  for (; id < inlined_function_infos_->length(); id++) {
-    if (inlined_function_infos_->at(id).shared().is_identical_to(shared)) {
-      break;
-    }
-  }
-  if (id == inlined_function_infos_->length()) {
-    inlined_function_infos_->Add(InlinedFunctionInfo(shared));
-
-    if (!shared->script()->IsUndefined()) {
-      Handle<Script> script(Script::cast(shared->script()));
-      if (!script->source()->IsUndefined()) {
-        CodeTracer::Scope tracing_scope(isolate()->GetCodeTracer());
-        OFStream os(tracing_scope.file());
-        os << "--- FUNCTION SOURCE (" << shared->DebugName()->ToCString().get()
-           << ") id{" << optimization_id() << "," << id << "} ---\n";
-        {
-          DisallowHeapAllocation no_allocation;
-          int start = shared->start_position();
-          int len = shared->end_position() - start;
-          String::SubStringRange source(String::cast(script->source()), start,
-                                        len);
-          for (const auto& c : source) {
-            os << AsReversiblyEscapedUC16(c);
-          }
-        }
 
-        os << "\n--- END ---\n";
+  int inline_id = inlined_function_infos_->length();
+  InlinedFunctionInfo info(parent_id, position, UnboundScript::kNoScriptId,
+      shared->start_position());
+  if (!shared->script()->IsUndefined()) {
+    Handle<Script> script(Script::cast(shared->script()));
+    info.script_id = script->id()->value();
+
+    if (!script->source()->IsUndefined()) {
+      CodeTracer::Scope tracing_scope(isolate()->GetCodeTracer());
+      OFStream os(tracing_scope.file());
+      os << "--- FUNCTION SOURCE (" << shared->DebugName()->ToCString().get()
+         << ") id{" << optimization_id() << "," << inline_id << "} ---\n";
+      {
+        DisallowHeapAllocation no_allocation;
+        int start = shared->start_position();
+        int len = shared->end_position() - start;
+        String::SubStringRange source(String::cast(script->source()), start,
+                                      len);
+        for (const auto& c : source) {
+          os << AsReversiblyEscapedUC16(c);
+        }
       }
+
+      os << "\n--- END ---\n";
     }
   }
 
-  int inline_id = inlining_id_to_function_id_->length();
-  inlining_id_to_function_id_->Add(id);
+  inlined_function_infos_->Add(info);
 
   if (inline_id != 0) {
     CodeTracer::Scope tracing_scope(isolate()->GetCodeTracer());
     OFStream os(tracing_scope.file());
     os << "INLINE (" << shared->DebugName()->ToCString().get() << ") id{"
-       << optimization_id() << "," << id << "} AS " << inline_id << " AT "
-       << position << std::endl;
+       << optimization_id() << "," << inline_id << "} AS " << inline_id
+       << " AT " << position << std::endl;
   }
 
   return inline_id;
index 598c7c51c30c66eeb8010b1629de012542c0cbc3..b3f49931cc3acc8807ab68f7dcdfc9d6d64b2a84 100644 (file)
@@ -86,17 +86,19 @@ class SourcePosition {
 std::ostream& operator<<(std::ostream& os, const SourcePosition& p);
 
 
-class InlinedFunctionInfo {
- public:
-  explicit InlinedFunctionInfo(Handle<SharedFunctionInfo> shared)
-      : shared_(shared), start_position_(shared->start_position()) {}
-
-  Handle<SharedFunctionInfo> shared() const { return shared_; }
-  int start_position() const { return start_position_; }
-
- private:
-  Handle<SharedFunctionInfo> shared_;
-  int start_position_;
+struct InlinedFunctionInfo {
+  InlinedFunctionInfo(int parent_id, SourcePosition inline_position,
+                      int script_id, int start_position)
+      : parent_id(parent_id),
+        inline_position(inline_position),
+        script_id(script_id),
+        start_position(start_position) {}
+  int parent_id;
+  SourcePosition inline_position;
+  int script_id;
+  int start_position;
+
+  static const int kNoParentId = -1;
 };
 
 
@@ -338,11 +340,8 @@ class CompilationInfo {
   List<InlinedFunctionInfo>* inlined_function_infos() {
     return inlined_function_infos_;
   }
-  List<int>* inlining_id_to_function_id() {
-    return inlining_id_to_function_id_;
-  }
   int TraceInlinedFunction(Handle<SharedFunctionInfo> shared,
-                           SourcePosition position);
+                           SourcePosition position, int pareint_id);
 
   Handle<Foreign> object_wrapper() {
     if (object_wrapper_.is_null()) {
@@ -450,7 +449,6 @@ class CompilationInfo {
 
   List<OffsetRange>* no_frame_ranges_;
   List<InlinedFunctionInfo>* inlined_function_infos_;
-  List<int>* inlining_id_to_function_id_;
 
   // A copy of shared_info()->opt_count() to avoid handle deref
   // during graph optimization.
index 5b332b3aada09edb8399bfd9c56325f9cbfaffa9..867bcf9c6bfdecca2659d7094368af7cbd8c399b 100644 (file)
@@ -3452,8 +3452,8 @@ HGraph::HGraph(CompilationInfo* info)
         HEnvironment(zone_, descriptor.GetEnvironmentParameterCount());
   } else {
     if (FLAG_hydrogen_track_positions) {
-      info->TraceInlinedFunction(info->shared_info(),
-                                 SourcePosition::Unknown());
+      info->TraceInlinedFunction(info->shared_info(), SourcePosition::Unknown(),
+                                 InlinedFunctionInfo::kNoParentId);
     }
     start_environment_ =
         new(zone_) HEnvironment(NULL, info->scope(), info->closure(), zone_);
@@ -3487,9 +3487,8 @@ int HGraph::SourcePositionToScriptPosition(SourcePosition pos) {
     return pos.raw();
   }
 
-  const int id = info()->inlining_id_to_function_id()->at(pos.inlining_id());
-  return info()->inlined_function_infos()->at(id).start_position() +
-         pos.position();
+  return info()->inlined_function_infos()->at(pos.inlining_id())
+      .start_position + pos.position();
 }
 
 
@@ -7922,8 +7921,8 @@ bool HOptimizedGraphBuilder::TryInline(Handle<JSFunction> target,
 
   int function_id = 0;
   if (FLAG_hydrogen_track_positions) {
-    function_id =
-        top_info()->TraceInlinedFunction(target_shared, source_position());
+    function_id = top_info()->TraceInlinedFunction(
+        target_shared, source_position(), function_state()->inlining_id());
   }
 
   // Save the pending call context. Set up new one for the inlined function.