Revision: 13631
Author:   [email protected]
Date:     Fri Feb  8 04:41:55 2013
Log:      Added new GetHeapStatistics API entry and deprecated old one.

Simplified the HeapStatistics class a bit, following Uncle Bob's advice that
adding accessors to DTOs only satisfies some design fundamentalists, but serves
no other purpose. :-)

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

Modified:
 /branches/bleeding_edge/include/v8.h
 /branches/bleeding_edge/src/api.cc
 /branches/bleeding_edge/test/cctest/test-api.cc

=======================================
--- /branches/bleeding_edge/include/v8.h        Fri Jan 25 00:31:46 2013
+++ /branches/bleeding_edge/include/v8.h        Fri Feb  8 04:41:55 2013
@@ -2840,16 +2840,6 @@
   size_t heap_size_limit() { return heap_size_limit_; }

  private:
-  void set_total_heap_size(size_t size) { total_heap_size_ = size; }
-  void set_total_heap_size_executable(size_t size) {
-    total_heap_size_executable_ = size;
-  }
-  void set_total_physical_size(size_t size) {
-    total_physical_size_ = size;
-  }
-  void set_used_heap_size(size_t size) { used_heap_size_ = size; }
-  void set_heap_size_limit(size_t size) { heap_size_limit_ = size; }
-
   size_t total_heap_size_;
   size_t total_heap_size_executable_;
   size_t total_physical_size_;
@@ -2857,6 +2847,7 @@
   size_t heap_size_limit_;

   friend class V8;
+  friend class Isolate;
 };


@@ -2946,6 +2937,11 @@
    */
   V8_INLINE(void* GetData());

+  /**
+   * Get statistics about the heap memory usage.
+   */
+  void GetHeapStatistics(HeapStatistics* heap_statistics);
+
  private:
   Isolate();
   Isolate(const Isolate&);
@@ -3500,10 +3496,8 @@
    */
   static bool Dispose();

-  /**
-   * Get statistics about the heap memory usage.
-   */
-  static void GetHeapStatistics(HeapStatistics* heap_statistics);
+  /** Deprecated. Use Isolate::GetHeapStatistics instead. */
+ V8_DEPRECATED(static void GetHeapStatistics(HeapStatistics* heap_statistics));

   /**
* Iterates through all external resources referenced from current isolate
=======================================
--- /branches/bleeding_edge/src/api.cc  Fri Jan 25 00:31:46 2013
+++ /branches/bleeding_edge/src/api.cc  Fri Feb  8 04:41:55 2013
@@ -4407,23 +4407,18 @@


 void v8::V8::GetHeapStatistics(HeapStatistics* heap_statistics) {
-  if (!i::Isolate::Current()->IsInitialized()) {
+  i::Isolate* isolate = i::Isolate::UncheckedCurrent();
+  if (isolate == NULL || !isolate->IsInitialized()) {
     // Isolate is unitialized thus heap is not configured yet.
-    heap_statistics->set_total_heap_size(0);
-    heap_statistics->set_total_heap_size_executable(0);
-    heap_statistics->set_total_physical_size(0);
-    heap_statistics->set_used_heap_size(0);
-    heap_statistics->set_heap_size_limit(0);
+    heap_statistics->total_heap_size_ = 0;
+    heap_statistics->total_heap_size_executable_ = 0;
+    heap_statistics->total_physical_size_ = 0;
+    heap_statistics->used_heap_size_ = 0;
+    heap_statistics->heap_size_limit_ = 0;
     return;
   }
-
-  i::Heap* heap = i::Isolate::Current()->heap();
-  heap_statistics->set_total_heap_size(heap->CommittedMemory());
-  heap_statistics->set_total_heap_size_executable(
-      heap->CommittedMemoryExecutable());
- heap_statistics->set_total_physical_size(heap->CommittedPhysicalMemory());
-  heap_statistics->set_used_heap_size(heap->SizeOfObjects());
-  heap_statistics->set_heap_size_limit(heap->MaxReserved());
+  Isolate* ext_isolate = reinterpret_cast<Isolate*>(isolate);
+  return ext_isolate->GetHeapStatistics(heap_statistics);
 }


@@ -5607,6 +5602,18 @@
   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
   isolate->Exit();
 }
+
+
+void Isolate::GetHeapStatistics(HeapStatistics* heap_statistics) {
+  i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
+  i::Heap* heap = isolate->heap();
+  heap_statistics->total_heap_size_ = heap->CommittedMemory();
+  heap_statistics->total_heap_size_executable_ =
+      heap->CommittedMemoryExecutable();
+  heap_statistics->total_physical_size_ = heap->CommittedPhysicalMemory();
+  heap_statistics->used_heap_size_ = heap->SizeOfObjects();
+  heap_statistics->heap_size_limit_ = heap->MaxReserved();
+}


 String::Utf8Value::Utf8Value(v8::Handle<v8::Value> obj)
=======================================
--- /branches/bleeding_edge/test/cctest/test-api.cc     Wed Feb  6 05:21:28 2013
+++ /branches/bleeding_edge/test/cctest/test-api.cc     Fri Feb  8 04:41:55 2013
@@ -15205,7 +15205,7 @@
   v8::HeapStatistics heap_statistics;
   CHECK_EQ(static_cast<int>(heap_statistics.total_heap_size()), 0);
   CHECK_EQ(static_cast<int>(heap_statistics.used_heap_size()), 0);
-  v8::V8::GetHeapStatistics(&heap_statistics);
+  c1->GetIsolate()->GetHeapStatistics(&heap_statistics);
   CHECK_NE(static_cast<int>(heap_statistics.total_heap_size()), 0);
   CHECK_NE(static_cast<int>(heap_statistics.used_heap_size()), 0);
 }

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