Reviewers: Vyacheslav Egorov,

Message:
Slava,

may you have a look?

Description:
Add information about memory allocator's size and capacity and heap snapshot
into heap stats.

That might help us debug OOM crashes in V8.

Please review this at http://codereview.chromium.org/3046049/show

Affected files:
  M src/api.cc
  M src/heap.h
  M src/heap.cc


Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index 48c64b314088fc40e8f048c78c1e0b9a77e649a8..af84909352d10f415e9f6e4344c6622e0ba4908e 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -166,6 +166,14 @@ void i::V8::FatalProcessOutOfMemory(const char* location) { heap_stats.near_death_global_handle_count = &near_death_global_handle_count;
   int destroyed_global_handle_count;
heap_stats.destroyed_global_handle_count = &destroyed_global_handle_count;
+  int memory_allocator_size;
+  heap_stats.memory_allocator_size = &memory_allocator_size;
+  int memory_allocator_capacity;
+  heap_stats.memory_allocator_capacity = &memory_allocator_capacity;
+  int objects_per_type[LAST_TYPE + 1] = {0};
+  heap_stats.objects_per_type = objects_per_type;
+  int size_per_type[LAST_TYPE + 1] = {0};
+  heap_stats.size_per_type = size_per_type;
   int end_marker;
   heap_stats.end_marker = &end_marker;
   i::Heap::RecordStats(&heap_stats);
Index: src/heap.cc
diff --git a/src/heap.cc b/src/heap.cc
index 9f27a49039225c76c6fede8e20ad1df3295ac87e..10480d556a0123eb309ff14a8800e5aaf70013f2 100644
--- a/src/heap.cc
+++ b/src/heap.cc
@@ -4123,6 +4123,17 @@ void Heap::RecordStats(HeapStats* stats) {
   *stats->cell_space_capacity = cell_space_->Capacity();
   *stats->lo_space_size = lo_space_->Size();
   GlobalHandles::RecordStats(stats);
+  *stats->memory_allocator_size = MemoryAllocator::Size();
+  *stats->memory_allocator_capacity =
+      MemoryAllocator::Size() + MemoryAllocator::Available();
+  HeapIterator iterator;
+ for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) {
+    if (FreeListNode::IsFreeListNode(obj)) continue;
+    InstanceType type = obj->map()->instance_type();
+    ASSERT(0 <= type && type <= LAST_TYPE);
+    stats->objects_per_type[type]++;
+    stats->size_per_type[type] += obj->Size();
+  }
 }


Index: src/heap.h
diff --git a/src/heap.h b/src/heap.h
index 2994a6d6e0440a873d55e54fbdbc24a79f85d1f7..d79615507c729c93de2edb79d97b35425a21678e 100644
--- a/src/heap.h
+++ b/src/heap.h
@@ -1324,26 +1324,30 @@ class Heap : public AllStatic {

 class HeapStats {
  public:
-  int* start_marker;
-  int* new_space_size;
-  int* new_space_capacity;
-  int* old_pointer_space_size;
-  int* old_pointer_space_capacity;
-  int* old_data_space_size;
-  int* old_data_space_capacity;
-  int* code_space_size;
-  int* code_space_capacity;
-  int* map_space_size;
-  int* map_space_capacity;
-  int* cell_space_size;
-  int* cell_space_capacity;
-  int* lo_space_size;
-  int* global_handle_count;
-  int* weak_global_handle_count;
-  int* pending_global_handle_count;
-  int* near_death_global_handle_count;
-  int* destroyed_global_handle_count;
-  int* end_marker;
+  int* start_marker;                    //  0
+  int* new_space_size;                  //  1
+  int* new_space_capacity;              //  2
+  int* old_pointer_space_size;          //  3
+  int* old_pointer_space_capacity;      //  4
+  int* old_data_space_size;             //  5
+  int* old_data_space_capacity;         //  6
+  int* code_space_size;                 //  7
+  int* code_space_capacity;             //  8
+  int* map_space_size;                  //  9
+  int* map_space_capacity;              // 10
+  int* cell_space_size;                 // 11
+  int* cell_space_capacity;             // 12
+  int* lo_space_size;                   // 13
+  int* global_handle_count;             // 14
+  int* weak_global_handle_count;        // 15
+  int* pending_global_handle_count;     // 16
+  int* near_death_global_handle_count;  // 17
+  int* destroyed_global_handle_count;   // 18
+  int* memory_allocator_size;           // 19
+  int* memory_allocator_capacity;       // 20
+  int* objects_per_type;                // 21
+  int* size_per_type;                   // 22
+  int* end_marker;                      // 23
 };




--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to