Reviewers: Toon Verwaest,

Description:
Track Hydrogen statistics on a per-Isolate basis

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.


Please review this at https://codereview.chromium.org/12481015/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files:
  M src/compiler.cc
  M src/hydrogen-instructions.cc
  M src/hydrogen.h
  M src/hydrogen.cc
  M src/isolate.h
  M src/isolate.cc
  M src/lithium-allocator.h
  M src/lithium.h


Index: src/compiler.cc
diff --git a/src/compiler.cc b/src/compiler.cc
index 99768472e0969fa681dc055a43ea5885f546103f..100d100d3518f624c9fb643dfc1920f1e6ef8015 100644
--- a/src/compiler.cc
+++ b/src/compiler.cc
@@ -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: src/hydrogen-instructions.cc
diff --git a/src/hydrogen-instructions.cc b/src/hydrogen-instructions.cc
index f622c25496f0a6d66ffce227bb6bb45c207396a3..97a759974bb8a21b7d20c18ed97e2908e51eb985 100644
--- a/src/hydrogen-instructions.cc
+++ b/src/hydrogen-instructions.cc
@@ -78,7 +78,7 @@ int HValue::LoopWeight() const {

 Isolate* HValue::isolate() const {
   ASSERT(block() != NULL);
-  return block()->graph()->isolate();
+  return block()->isolate();
 }


Index: src/hydrogen.cc
diff --git a/src/hydrogen.cc b/src/hydrogen.cc
index de068094de98089bd780dd06a92c648001ac6561..c2f3951494e647936183cdb1d25659c8d5ee187f 100644
--- a/src/hydrogen.cc
+++ b/src/hydrogen.cc
@@ -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: src/hydrogen.h
diff --git a/src/hydrogen.h b/src/hydrogen.h
index 6be75816826a9184bd772737af466afd16c9181b..b3a056fa1b35d2f2c04b98d8a3e1f84f31080b05 100644
--- a/src/hydrogen.h
+++ b/src/hydrogen.h
@@ -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: src/isolate.cc
diff --git a/src/isolate.cc b/src/isolate.cc
index 98469a98dc06c777694581dd0f8786f625e3118d..5129dbd96e65047c64c4139b661a7a6415eb55b1 100644
--- a/src/isolate.cc
+++ b/src/isolate.cc
@@ -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: src/isolate.h
diff --git a/src/isolate.h b/src/isolate.h
index 5b7b3e73c89b94c9575926123656b4aa14114fff..e6f6d167f15e0a095b9ddf37dbec0959e79ddbb1 100644
--- a/src/isolate.h
+++ b/src/isolate.h
@@ -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: src/lithium-allocator.h
diff --git a/src/lithium-allocator.h b/src/lithium-allocator.h
index 2953550ae8e879742ed19d0c4a9bba6cfc5bf5af..2ca853763e893343bf01315f2dafbfd5018c43d5 100644
--- a/src/lithium-allocator.h
+++ b/src/lithium-allocator.h
@@ -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: src/lithium.h
diff --git a/src/lithium.h b/src/lithium.h
index 420a262180e34e74f2e8bba094b83dd0e6e364ea..9d5b0b9eecf05fbc51eccfca89e6273c615bde18 100644
--- a/src/lithium.h
+++ b/src/lithium.h
@@ -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;


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