Revision: 13834
Author:   [email protected]
Date:     Tue Mar  5 23:25:46 2013
Log:      Separate output files for --trace-hydrogen.

The output filenames have now the form "hydrogen-<ProcessId>-<IsolateId>.cfg".
Minor cleanup on the way.

Note that we have a similar bug regarding statistics, but this will be handled
in a separate CL.

BUG=v8:2563

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

Modified:
 /branches/bleeding_edge/src/code-stubs-hydrogen.cc
 /branches/bleeding_edge/src/compiler.cc
 /branches/bleeding_edge/src/hydrogen.cc
 /branches/bleeding_edge/src/hydrogen.h
 /branches/bleeding_edge/src/isolate.cc
 /branches/bleeding_edge/src/isolate.h

=======================================
--- /branches/bleeding_edge/src/code-stubs-hydrogen.cc Fri Mar 1 08:06:34 2013 +++ /branches/bleeding_edge/src/code-stubs-hydrogen.cc Tue Mar 5 23:25:46 2013
@@ -59,9 +59,9 @@
   CodeStubGraphBuilderBase(Isolate* isolate, HydrogenCodeStub* stub)
       : HGraphBuilder(&info_), info_(stub, isolate), context_(NULL) {
     int major_key = stub->MajorKey();
- descriptor_ = info_.isolate()->code_stub_interface_descriptor(major_key);
+    descriptor_ = isolate->code_stub_interface_descriptor(major_key);
     if (descriptor_->register_param_count_ < 0) {
-      stub->InitializeInterfaceDescriptor(info_.isolate(), descriptor_);
+      stub->InitializeInterfaceDescriptor(isolate, descriptor_);
     }
     parameters_.Reset(new HParameter*[descriptor_->register_param_count_]);
   }
@@ -88,7 +88,7 @@
     const char* name = CodeStub::MajorName(stub()->MajorKey(), false);
PrintF("-----------------------------------------------------------\n");
     PrintF("Compiling stub %s using hydrogen\n", name);
-    HTracer::Instance()->TraceCompilation(&info_);
+    isolate()->GetHTracer()->TraceCompilation(&info_);
   }

   Zone* zone = this->zone();
=======================================
--- /branches/bleeding_edge/src/compiler.cc     Tue Mar  5 08:22:08 2013
+++ /branches/bleeding_edge/src/compiler.cc     Tue Mar  5 23:25:46 2013
@@ -277,7 +277,7 @@
   // Fall back to using the full code generator if it's not possible
   // to use the Hydrogen-based optimizing compiler. We already have
   // generated code for this from the shared function object.
-  if (AlwaysFullCompiler(info()->isolate())) {
+  if (AlwaysFullCompiler(isolate())) {
     info()->SetCode(code);
     return SetLastStatus(BAILED_OUT);
   }
@@ -330,7 +330,7 @@
   // performance of the hydrogen-based compiler.
bool should_recompile = !info()->shared_info()->has_deoptimization_support();
   if (should_recompile || FLAG_hydrogen_stats) {
-    HPhase phase(HPhase::kFullCodeGen);
+    HPhase phase(HPhase::kFullCodeGen, isolate());
     CompilationInfoWithZone unoptimized(info()->shared_info());
     // Note that we use the same AST that we will use for generating the
     // optimized code.
@@ -360,18 +360,18 @@
   if (FLAG_trace_hydrogen) {
PrintF("-----------------------------------------------------------\n");
     PrintF("Compiling method %s using hydrogen\n", *name->ToCString());
-    HTracer::Instance()->TraceCompilation(info());
+    isolate()->GetHTracer()->TraceCompilation(info());
   }
   Handle<Context> native_context(
       info()->closure()->context()->native_context());
   oracle_ = new(info()->zone()) TypeFeedbackOracle(
-      code, native_context, info()->isolate(), info()->zone());
+      code, native_context, isolate(), info()->zone());
graph_builder_ = new(info()->zone()) HOptimizedGraphBuilder(info(), oracle_);

   Timer t(this, &time_taken_to_create_graph_);
   graph_ = graph_builder_->CreateGraph();

-  if (info()->isolate()->has_pending_exception()) {
+  if (isolate()->has_pending_exception()) {
     info()->SetCode(Handle<Code>::null());
     return SetLastStatus(FAILED);
   }
=======================================
--- /branches/bleeding_edge/src/hydrogen.cc     Mon Mar  4 04:34:49 2013
+++ /branches/bleeding_edge/src/hydrogen.cc     Tue Mar  5 23:25:46 2013
@@ -830,7 +830,7 @@
 HGraph* HGraphBuilder::CreateGraph() {
   graph_ = new(zone()) HGraph(info_);
   if (FLAG_hydrogen_stats) HStatistics::Instance()->Initialize(info_);
-  HPhase phase("H_Block building");
+  HPhase phase("H_Block building", graph()->isolate());
   set_current_block(graph()->entry_block());
   if (!BuildGraph()) return NULL;
   return graph_;
@@ -1553,7 +1553,7 @@


 void HGraph::OrderBlocks() {
-  HPhase phase("H_Block ordering");
+  HPhase phase("H_Block ordering", isolate());
   BitVector visited(blocks_.length(), zone());

   ZoneList<HBasicBlock*> reverse_result(8, zone());
@@ -10713,7 +10713,7 @@


 void HTracer::FlushToFile() {
-  AppendChars(filename_, *trace_.ToCString(), trace_.length(), false);
+ AppendChars(filename_.start(), *trace_.ToCString(), trace_.length(), false);
   trace_.Reset();
 }

@@ -10798,10 +10798,33 @@

 const char* const HPhase::kFullCodeGen = "Full code generator";

-void HPhase::Begin(const char* name,
-                   HGraph* graph,
-                   LChunk* chunk,
-                   LAllocator* allocator) {
+
+HPhase::HPhase(const char* name, Isolate* isolate) {
+  Init(isolate, name, NULL, NULL, NULL);
+}
+
+
+HPhase::HPhase(const char* name, HGraph* graph) {
+  Init(graph->isolate(), name, graph, NULL, NULL);
+}
+
+
+HPhase::HPhase(const char* name, LChunk* chunk) {
+  Init(chunk->graph()->isolate(), name, NULL, chunk, NULL);
+}
+
+
+HPhase::HPhase(const char* name, LAllocator* allocator) {
+  Init(allocator->graph()->isolate(), name, NULL, NULL, allocator);
+}
+
+
+void HPhase::Init(Isolate* isolate,
+                  const char* name,
+                  HGraph* graph,
+                  LChunk* chunk,
+                  LAllocator* allocator) {
+  isolate_ = isolate;
   name_ = name;
   graph_ = graph;
   chunk_ = chunk;
@@ -10809,26 +10832,32 @@
   if (allocator != NULL && chunk_ == NULL) {
     chunk_ = allocator->chunk();
   }
-  if (FLAG_hydrogen_stats) start_ = OS::Ticks();
-  start_allocation_size_ = Zone::allocation_size_;
+  if (FLAG_hydrogen_stats) {
+    start_ticks_ = OS::Ticks();
+    start_allocation_size_ = Zone::allocation_size_;
+  }
 }


-void HPhase::End() const {
+HPhase::~HPhase() {
   if (FLAG_hydrogen_stats) {
-    int64_t end = OS::Ticks();
+    int64_t ticks = OS::Ticks() - start_ticks_;
     unsigned size = Zone::allocation_size_ - start_allocation_size_;
-    HStatistics::Instance()->SaveTiming(name_, end - start_, size);
+    HStatistics::Instance()->SaveTiming(name_, ticks, size);
   }

   // Produce trace output if flag is set so that the first letter of the
   // phase name matches the command line parameter FLAG_trace_phase.
   if (FLAG_trace_hydrogen &&
       OS::StrChr(const_cast<char*>(FLAG_trace_phase), name_[0]) != NULL) {
-    if (graph_ != NULL) HTracer::Instance()->TraceHydrogen(name_, graph_);
-    if (chunk_ != NULL) HTracer::Instance()->TraceLithium(name_, chunk_);
+    if (graph_ != NULL) {
+      isolate_->GetHTracer()->TraceHydrogen(name_, graph_);
+    }
+    if (chunk_ != NULL) {
+      isolate_->GetHTracer()->TraceLithium(name_, chunk_);
+    }
     if (allocator_ != NULL) {
-      HTracer::Instance()->TraceLiveRanges(name_, allocator_);
+      isolate_->GetHTracer()->TraceLiveRanges(name_, allocator_);
     }
   }

=======================================
--- /branches/bleeding_edge/src/hydrogen.h      Tue Feb 26 05:08:08 2013
+++ /branches/bleeding_edge/src/hydrogen.h      Tue Mar  5 23:25:46 2013
@@ -1581,52 +1581,45 @@
  public:
   static const char* const kFullCodeGen;

-  explicit HPhase(const char* name) { Begin(name, NULL, NULL, NULL); }
-  HPhase(const char* name, HGraph* graph) {
-    Begin(name, graph, NULL, NULL);
-  }
-  HPhase(const char* name, LChunk* chunk) {
-    Begin(name, NULL, chunk, NULL);
-  }
-  HPhase(const char* name, LAllocator* allocator) {
-    Begin(name, NULL, NULL, allocator);
-  }
-
-  ~HPhase() {
-    End();
-  }
+  HPhase(const char* name, Isolate* isolate);
+  HPhase(const char* name, HGraph* graph);
+  HPhase(const char* name, LChunk* chunk);
+  HPhase(const char* name, LAllocator* allocator);
+  ~HPhase();

  private:
-  void Begin(const char* name,
+  void Init(Isolate* isolate,
+             const char* name,
              HGraph* graph,
              LChunk* chunk,
              LAllocator* allocator);
-  void End() const;

-  int64_t start_;
+  Isolate* isolate_;
   const char* name_;
   HGraph* graph_;
   LChunk* chunk_;
   LAllocator* allocator_;
+  int64_t start_ticks_;
   unsigned start_allocation_size_;
 };


 class HTracer: public Malloced {
  public:
+  explicit HTracer(int isolate_id)
+      : trace_(&string_allocator_), indent_(0) {
+    OS::SNPrintF(filename_,
+                 "hydrogen-%d-%d.cfg",
+                 OS::GetCurrentProcessId(),
+                 isolate_id);
+    WriteChars(filename_.start(), "", 0, false);
+  }
+
   void TraceCompilation(CompilationInfo* info);
   void TraceHydrogen(const char* name, HGraph* graph);
   void TraceLithium(const char* name, LChunk* chunk);
   void TraceLiveRanges(const char* name, LAllocator* allocator);

-  static HTracer* Instance() {
-    static SetOncePointer<HTracer> instance;
-    if (!instance.is_set()) {
-      instance.set(new HTracer("hydrogen.cfg"));
-    }
-    return instance.get();
-  }
-
  private:
   class Tag BASE_EMBEDDED {
    public:
@@ -1650,11 +1643,6 @@
     HTracer* tracer_;
     const char* name_;
   };
-
-  explicit HTracer(const char* filename)
-      : filename_(filename), trace_(&string_allocator_), indent_(0) {
-    WriteChars(filename, "", 0, false);
-  }

   void TraceLiveRange(LiveRange* range, const char* type, Zone* zone);
   void Trace(const char* name, HGraph* graph, LChunk* chunk);
@@ -1691,7 +1679,7 @@
     }
   }

-  const char* filename_;
+  EmbeddedVector<char, 64> filename_;
   HeapStringAllocator string_allocator_;
   StringStream trace_;
   int indent_;
=======================================
--- /branches/bleeding_edge/src/isolate.cc      Tue Mar  5 08:22:08 2013
+++ /branches/bleeding_edge/src/isolate.cc      Tue Mar  5 23:25:46 2013
@@ -338,7 +338,7 @@
 Thread::LocalStorageKey Isolate::per_isolate_thread_data_key_;
 Mutex* Isolate::process_wide_mutex_ = OS::CreateMutex();
 Isolate::ThreadDataTable* Isolate::thread_data_table_ = NULL;
-
+Atomic32 Isolate::isolate_counter_ = 0;

 Isolate::PerIsolateThreadData* Isolate::AllocatePerIsolateThreadData(
     ThreadId thread_id) {
@@ -1624,7 +1624,8 @@
 #define TRACE_ISOLATE(tag)                                              \
   do {                                                                  \
     if (FLAG_trace_isolates) {                                          \
-      PrintF("Isolate %p " #tag "\n", reinterpret_cast<void*>(this));   \
+      PrintF("Isolate %p (id %d)" #tag "\n",                            \
+             reinterpret_cast<void*>(this), id());                      \
     }                                                                   \
   } while (false)
 #else
@@ -1684,6 +1685,7 @@
       optimizing_compiler_thread_(this),
       marking_thread_(NULL),
       sweeper_thread_(NULL) {
+  id_ = NoBarrier_AtomicIncrement(&isolate_counter_, 1);
   TRACE_ISOLATE(constructor);

   memset(isolate_addresses_, 0,
@@ -2314,6 +2316,12 @@
     deferred->previous_->next_ = deferred->next_;
   }
 }
+
+
+HTracer* Isolate::GetHTracer() {
+  if (htracer() == NULL) set_htracer(new HTracer(id()));
+  return htracer();
+}


 CodeStubInterfaceDescriptor*
=======================================
--- /branches/bleeding_edge/src/isolate.h       Tue Mar  5 08:22:08 2013
+++ /branches/bleeding_edge/src/isolate.h       Tue Mar  5 23:25:46 2013
@@ -68,6 +68,7 @@
 class FunctionInfoListener;
 class HandleScopeImplementer;
 class HeapProfiler;
+class HTracer;
 class InlineRuntimeFunctionsTable;
 class NoAllocationStringAllocator;
 class InnerPointerToCodeCache;
@@ -372,6 +373,7 @@
V(CpuProfiler*, cpu_profiler, NULL) \ V(HeapProfiler*, heap_profiler, NULL) \ V(bool, observer_delivery_pending, false) \ + V(HTracer*, htracer, NULL) \
   ISOLATE_DEBUGGER_INIT_LIST(V)

 class Isolate {
@@ -1099,9 +1101,13 @@
   SweeperThread** sweeper_threads() {
     return sweeper_thread_;
   }
+
+  HTracer* GetHTracer();

  private:
   Isolate();
+
+  int id() const { return static_cast<int>(id_); }

   friend struct GlobalState;
   friend struct InitializeGlobalState;
@@ -1170,6 +1176,9 @@
   static Isolate* default_isolate_;
   static ThreadDataTable* thread_data_table_;

+  // A global counter for all generated Isolates, might overflow.
+  static Atomic32 isolate_counter_;
+
   void Deinit();

   static void SetIsolateThreadLocals(Isolate* isolate,
@@ -1214,6 +1223,7 @@
   // the Error object.
   bool IsErrorObject(Handle<Object> obj);

+  Atomic32 id_;
   EntryStackItem* entry_stack_;
   int stack_trace_nesting_level_;
   StringStream* incomplete_message_;

--
--
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