Track Hydrogen statistics on a per-Isolate basis
authorsvenpanne@chromium.org <svenpanne@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Wed, 6 Mar 2013 10:49:34 +0000 (10:49 +0000)
committersvenpanne@chromium.org <svenpanne@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Wed, 6 Mar 2013 10:49:34 +0000 (10:49 +0000)
This is basically the same fix as the one for --trace-hydrogen, but now for
--hydrogen-stats. Removed a few train wrecks on the way.

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

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

src/compiler.cc
src/hydrogen-instructions.cc
src/hydrogen.cc
src/hydrogen.h
src/isolate.cc
src/isolate.h
src/lithium-allocator.h
src/lithium.h

index 9976847..100d100 100644 (file)
@@ -234,9 +234,9 @@ void OptimizingCompiler::RecordOptimizationStats() {
            compilation_time);
   }
   if (FLAG_hydrogen_stats) {
-    HStatistics::Instance()->IncrementSubtotals(time_taken_to_create_graph_,
-                                                time_taken_to_optimize_,
-                                                time_taken_to_codegen_);
+    isolate()->GetHStatistics()->IncrementSubtotals(time_taken_to_create_graph_,
+                                                    time_taken_to_optimize_,
+                                                    time_taken_to_codegen_);
   }
 }
 
index f622c25..97a7599 100644 (file)
@@ -78,7 +78,7 @@ int HValue::LoopWeight() const {
 
 Isolate* HValue::isolate() const {
   ASSERT(block() != NULL);
-  return block()->graph()->isolate();
+  return block()->isolate();
 }
 
 
index de06809..c2f3951 100644 (file)
@@ -75,6 +75,11 @@ HBasicBlock::HBasicBlock(HGraph* graph)
       is_osr_entry_(false) { }
 
 
+Isolate* HBasicBlock::isolate() const {
+  return graph_->isolate();
+}
+
+
 void HBasicBlock::AttachLoopInformation() {
   ASSERT(!IsLoopHeader());
   loop_information_ = new(zone()) HLoopInformation(this, zone());
@@ -829,8 +834,8 @@ void HGraphBuilder::LoopBuilder::EndBody() {
 
 HGraph* HGraphBuilder::CreateGraph() {
   graph_ = new(zone()) HGraph(info_);
-  if (FLAG_hydrogen_stats) HStatistics::Instance()->Initialize(info_);
-  HPhase phase("H_Block building", graph()->isolate());
+  if (FLAG_hydrogen_stats) isolate()->GetHStatistics()->Initialize(info_);
+  HPhase phase("H_Block building", isolate());
   set_current_block(graph()->entry_block());
   if (!BuildGraph()) return NULL;
   return graph_;
@@ -1001,7 +1006,7 @@ HInstruction* HGraphBuilder::BuildUncheckedMonomorphicElementAccess(
       AddInstruction(new(zone) HLoadElements(object, mapcheck));
   if (is_store && (fast_elements || fast_smi_only_elements)) {
     HCheckMaps* check_cow_map = new(zone) HCheckMaps(
-        elements, graph()->isolate()->factory()->fixed_array_map(), zone);
+        elements, isolate()->factory()->fixed_array_map(), zone);
     check_cow_map->ClearGVNFlag(kDependsOnElementsKind);
     AddInstruction(check_cow_map);
   }
@@ -1066,16 +1071,14 @@ HValue* HGraphBuilder::BuildAllocateElements(HContext* context,
   HValue* elements =
       AddInstruction(new(zone) HAllocate(context, total_size,
                                          HType::JSArray(), flags));
-  Isolate* isolate = graph()->isolate();
 
-  Factory* factory = isolate->factory();
+  Factory* factory = isolate()->factory();
   Handle<Map> map = IsFastDoubleElementsKind(kind)
       ? factory->fixed_double_array_map()
       : factory->fixed_array_map();
   BuildStoreMap(elements, map, BailoutId::StubEntry());
 
-  Handle<String> fixed_array_length_field_name =
-      isolate->factory()->length_field_string();
+  Handle<String> fixed_array_length_field_name = factory->length_field_string();
   HInstruction* store_length =
       new(zone) HStoreNamedField(elements, fixed_array_length_field_name,
                                  capacity, true, FixedArray::kLengthOffset);
@@ -1090,8 +1093,7 @@ HInstruction* HGraphBuilder::BuildStoreMap(HValue* object,
                                            HValue* map,
                                            BailoutId id) {
   Zone* zone = this->zone();
-  Isolate* isolate = graph()->isolate();
-  Factory* factory = isolate->factory();
+  Factory* factory = isolate()->factory();
   Handle<String> map_field_name = factory->map_field_string();
   HInstruction* store_map =
       new(zone) HStoreNamedField(object, map_field_name, map,
@@ -9380,7 +9382,7 @@ void HOptimizedGraphBuilder::VisitCompareOperation(CompareOperation* expr) {
     return HandleLiteralCompareTypeof(expr, typeof_expr, check);
   }
   HValue* sub_expr = NULL;
-  Factory* f = graph()->isolate()->factory();
+  Factory* f = isolate()->factory();
   if (IsLiteralCompareNil(left, op, right, f->undefined_value(), &sub_expr)) {
     return HandleLiteralCompareNil(expr, sub_expr, kUndefinedValue);
   }
@@ -10511,7 +10513,7 @@ void HTracer::TraceCompilation(CompilationInfo* info) {
 
 
 void HTracer::TraceLithium(const char* name, LChunk* chunk) {
-  AllowHandleDereference allow_handle_deref(chunk->graph()->isolate());
+  AllowHandleDereference allow_handle_deref(chunk->isolate());
   Trace(name, chunk->graph(), chunk);
 }
 
@@ -10810,12 +10812,12 @@ HPhase::HPhase(const char* name, HGraph* graph) {
 
 
 HPhase::HPhase(const char* name, LChunk* chunk) {
-  Init(chunk->graph()->isolate(), name, NULL, chunk, NULL);
+  Init(chunk->isolate(), name, NULL, chunk, NULL);
 }
 
 
 HPhase::HPhase(const char* name, LAllocator* allocator) {
-  Init(allocator->graph()->isolate(), name, NULL, NULL, allocator);
+  Init(allocator->isolate(), name, NULL, NULL, allocator);
 }
 
 
@@ -10843,7 +10845,7 @@ HPhase::~HPhase() {
   if (FLAG_hydrogen_stats) {
     int64_t ticks = OS::Ticks() - start_ticks_;
     unsigned size = Zone::allocation_size_ - start_allocation_size_;
-    HStatistics::Instance()->SaveTiming(name_, ticks, size);
+    isolate_->GetHStatistics()->SaveTiming(name_, ticks, size);
   }
 
   // Produce trace output if flag is set so that the first letter of the
index 6be7581..b3a056f 100644 (file)
@@ -61,6 +61,7 @@ class HBasicBlock: public ZoneObject {
   int block_id() const { return block_id_; }
   void set_block_id(int id) { block_id_ = id; }
   HGraph* graph() const { return graph_; }
+  Isolate* isolate() const;
   const ZoneList<HPhi*>* phis() const { return &phis_; }
   HInstruction* first() const { return first_; }
   HInstruction* last() const { return last_; }
@@ -870,7 +871,8 @@ class HGraphBuilder {
     return current_block()->last_environment();
   }
   Zone* zone() const { return info_->zone(); }
-  HGraph* graph() { return graph_; }
+  HGraph* graph() const { return graph_; }
+  Isolate* isolate() const { return graph_->isolate(); }
 
   HGraph* CreateGraph();
 
@@ -1534,16 +1536,20 @@ class HSideEffectMap BASE_EMBEDDED {
 
 class HStatistics: public Malloced {
  public:
+  HStatistics()
+      : timing_(5),
+        names_(5),
+        sizes_(5),
+        create_graph_(0),
+        optimize_graph_(0),
+        generate_code_(0),
+        total_size_(0),
+        full_code_gen_(0),
+        source_size_(0) { }
+
   void Initialize(CompilationInfo* info);
   void Print();
   void SaveTiming(const char* name, int64_t ticks, unsigned size);
-  static HStatistics* Instance() {
-    static SetOncePointer<HStatistics> instance;
-    if (!instance.is_set()) {
-      instance.set(new HStatistics());
-    }
-    return instance.get();
-  }
 
   void IncrementSubtotals(int64_t create_graph,
                           int64_t optimize_graph,
@@ -1554,17 +1560,6 @@ class HStatistics: public Malloced {
   }
 
  private:
-  HStatistics()
-      : timing_(5),
-        names_(5),
-        sizes_(5),
-        create_graph_(0),
-        optimize_graph_(0),
-        generate_code_(0),
-        total_size_(0),
-        full_code_gen_(0),
-        source_size_(0) { }
-
   List<int64_t> timing_;
   List<const char*> names_;
   List<unsigned> sizes_;
@@ -1589,10 +1584,10 @@ class HPhase BASE_EMBEDDED {
 
  private:
   void Init(Isolate* isolate,
-             const char* name,
-             HGraph* graph,
-             LChunk* chunk,
-             LAllocator* allocator);
+            const char* name,
+            HGraph* graph,
+            LChunk* chunk,
+            LAllocator* allocator);
 
   Isolate* isolate_;
   const char* name_;
index 98469a9..5129dbd 100644 (file)
@@ -1792,7 +1792,7 @@ void Isolate::Deinit() {
       delete[] marking_thread_;
     }
 
-    if (FLAG_hydrogen_stats) HStatistics::Instance()->Print();
+    if (FLAG_hydrogen_stats) GetHStatistics()->Print();
 
     // We must stop the logger before we tear down other components.
     logger_->EnsureTickerStopped();
@@ -2318,6 +2318,12 @@ void Isolate::UnlinkDeferredHandles(DeferredHandles* deferred) {
 }
 
 
+HStatistics* Isolate::GetHStatistics() {
+  if (hstatistics() == NULL) set_hstatistics(new HStatistics());
+  return hstatistics();
+}
+
+
 HTracer* Isolate::GetHTracer() {
   if (htracer() == NULL) set_htracer(new HTracer(id()));
   return htracer();
index 5b7b3e7..e6f6d16 100644 (file)
@@ -68,6 +68,7 @@ class Factory;
 class FunctionInfoListener;
 class HandleScopeImplementer;
 class HeapProfiler;
+class HStatistics;
 class HTracer;
 class InlineRuntimeFunctionsTable;
 class NoAllocationStringAllocator;
@@ -373,6 +374,7 @@ typedef List<HeapObject*, PreallocatedStorageAllocationPolicy> DebugObjectCache;
   V(CpuProfiler*, cpu_profiler, NULL)                                          \
   V(HeapProfiler*, heap_profiler, NULL)                                        \
   V(bool, observer_delivery_pending, false)                                    \
+  V(HStatistics*, hstatistics, NULL)                                           \
   V(HTracer*, htracer, NULL)                                                   \
   ISOLATE_DEBUGGER_INIT_LIST(V)
 
@@ -1102,6 +1104,7 @@ class Isolate {
     return sweeper_thread_;
   }
 
+  HStatistics* GetHStatistics();
   HTracer* GetHTracer();
 
  private:
index 2953550..2ca8537 100644 (file)
@@ -423,6 +423,7 @@ class LAllocator BASE_EMBEDDED {
 
   LPlatformChunk* chunk() const { return chunk_; }
   HGraph* graph() const { return graph_; }
+  Isolate* isolate() const { return graph_->isolate(); }
   Zone* zone() const { return zone_; }
 
   int GetVirtualRegister() {
index 420a262..9d5b0b9 100644 (file)
@@ -663,6 +663,7 @@ class LChunk: public ZoneObject {
   int spill_slot_count() const { return spill_slot_count_; }
   CompilationInfo* info() const { return info_; }
   HGraph* graph() const { return graph_; }
+  Isolate* isolate() const { return graph_->isolate(); }
   const ZoneList<LInstruction*>* instructions() const { return &instructions_; }
   void AddGapMove(int index, LOperand* from, LOperand* to);
   LGap* GetGapAt(int index) const;