Reviewers: alph, loislo, Michael Starzinger,

Description:
Simplify allocation tracker API

Deprecated separate methods for starting/stopping allocation tracking in favor
of a bool param to Start/StopTrackingHeapObjects.

BUG=None
LOG=N

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

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

Affected files (+40, -40 lines):
  M include/v8-profiler.h
  src/api.cc
  M src/heap-profiler.h
  src/heap-profiler.cc
  M src/heap-snapshot-generator.h
  src/heap-snapshot-generator.cc
  M test/cctest/cctest.h
  test/cctest/test-heap-profiler.cc


Index: include/v8-profiler.h
diff --git a/include/v8-profiler.h b/include/v8-profiler.h
index 0882d6452732373293bf6deb2a4e3ba92c3eff0e..0ed6c5d216b3f8708bea6ae794937b18f844591f 100644
--- a/include/v8-profiler.h
+++ b/include/v8-profiler.h
@@ -425,8 +425,12 @@ class V8_EXPORT HeapProfiler {
    * Starts tracking of heap objects population statistics. After calling
* this method, all heap objects relocations done by the garbage collector
    * are being registered.
+   *
+   * |track_allocations| parameter controls whether stack trace of each
+   * allocation in the heap will be recorded and reported as part of
+   * HeapSnapshot.
    */
-  void StartTrackingHeapObjects();
+  void StartTrackingHeapObjects(bool track_allocations = false);

   /**
    * Adds a new time interval entry to the aggregated statistics array. The
@@ -479,13 +483,15 @@ class V8_EXPORT HeapProfiler {
* Starts recording JS allocations immediately as they arrive and tracking of
    * heap objects population statistics.
    */
-  void StartRecordingHeapAllocations();
+  V8_DEPRECATED("Use StartTrackingHeapObjects instead",
+                void StartRecordingHeapAllocations());

   /**
    * Stops recording JS allocations and tracking of heap objects population
* statistics, cleans all collected heap objects population statistics data.
    */
-  void StopRecordingHeapAllocations();
+  V8_DEPRECATED("Use StopTrackingHeapObjects instead",
+                void StopRecordingHeapAllocations());


  private:
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index 562985cc8ba1e700c6f4153c951fec2be8f73b57..90e50ccc79f51503f97b9f5d90e75c291f7131f9 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -7497,8 +7497,9 @@ const HeapSnapshot* HeapProfiler::TakeHeapSnapshot(
 }


-void HeapProfiler::StartTrackingHeapObjects() {
-  reinterpret_cast<i::HeapProfiler*>(this)->StartHeapObjectsTracking();
+void HeapProfiler::StartTrackingHeapObjects(bool track_allocations) {
+  reinterpret_cast<i::HeapProfiler*>(this)->StartHeapObjectsTracking(
+      track_allocations);
 }


@@ -7537,12 +7538,12 @@ void HeapProfiler::SetRetainedObjectInfo(UniqueId id,


 void HeapProfiler::StartRecordingHeapAllocations() {
- reinterpret_cast<i::HeapProfiler*>(this)->StartHeapAllocationsRecording();
+  reinterpret_cast<i::HeapProfiler*>(this)->StartHeapObjectsTracking(true);
 }


 void HeapProfiler::StopRecordingHeapAllocations() {
-  reinterpret_cast<i::HeapProfiler*>(this)->StopHeapAllocationsRecording();
+  reinterpret_cast<i::HeapProfiler*>(this)->StopHeapObjectsTracking();
 }


Index: src/heap-profiler.cc
diff --git a/src/heap-profiler.cc b/src/heap-profiler.cc
index 6f993607cafaca4aa1f6f9df27f24cac84b143a5..3d8e3364c90a8be445052865cf000270962a7146 100644
--- a/src/heap-profiler.cc
+++ b/src/heap-profiler.cc
@@ -98,9 +98,14 @@ HeapSnapshot* HeapProfiler::TakeSnapshot(
 }


-void HeapProfiler::StartHeapObjectsTracking() {
-  snapshots_->StartHeapObjectsTracking();
+void HeapProfiler::StartHeapObjectsTracking(bool track_allocations) {
+  snapshots_->StartHeapObjectsTracking(track_allocations);
   is_tracking_object_moves_ = true;
+  ASSERT(!is_tracking_allocations_);
+  if (track_allocations) {
+    heap()->DisableInlineAllocation();
+    is_tracking_allocations_ = true;
+  }
 }


@@ -111,6 +116,10 @@ SnapshotObjectId HeapProfiler::PushHeapObjectsStats(OutputStream* stream) {

 void HeapProfiler::StopHeapObjectsTracking() {
   snapshots_->StopHeapObjectsTracking();
+  if (is_tracking_allocations_) {
+    heap()->EnableInlineAllocation();
+    is_tracking_allocations_ = false;
+  }
 }


@@ -158,18 +167,4 @@ void HeapProfiler::SetRetainedObjectInfo(UniqueId id,
 }


-void HeapProfiler::StartHeapAllocationsRecording() {
-  StartHeapObjectsTracking();
-  heap()->DisableInlineAllocation();
-  is_tracking_allocations_ = true;
-}
-
-
-void HeapProfiler::StopHeapAllocationsRecording() {
-  StopHeapObjectsTracking();
-  heap()->EnableInlineAllocation();
-  is_tracking_allocations_ = false;
-}
-
-
 } }  // namespace v8::internal
Index: src/heap-profiler.h
diff --git a/src/heap-profiler.h b/src/heap-profiler.h
index 866a6780028e17e0355e3c4cdfd21efd20c158fa..13e605b12d38da21964cd6ff3459178cbf2aabe2 100644
--- a/src/heap-profiler.h
+++ b/src/heap-profiler.h
@@ -53,7 +53,7 @@ class HeapProfiler {
       v8::ActivityControl* control,
       v8::HeapProfiler::ObjectNameResolver* resolver);

-  void StartHeapObjectsTracking();
+  void StartHeapObjectsTracking(bool track_allocations);
   void StopHeapObjectsTracking();

   SnapshotObjectId PushHeapObjectsStats(OutputStream* stream);
@@ -78,9 +78,6 @@ class HeapProfiler {
bool is_tracking_object_moves() const { return is_tracking_object_moves_; }
   bool is_tracking_allocations() const { return is_tracking_allocations_; }

-  void StartHeapAllocationsRecording();
-  void StopHeapAllocationsRecording();
-
   int FindUntrackedObjects() {
     return snapshots_->FindUntrackedObjects();
   }
Index: src/heap-snapshot-generator.cc
diff --git a/src/heap-snapshot-generator.cc b/src/heap-snapshot-generator.cc
index b77414b32f7286e93a034b279d6eba009b8d466e..271f95c5ca0a40c871a99e822f793d1f078d077e 100644
--- a/src/heap-snapshot-generator.cc
+++ b/src/heap-snapshot-generator.cc
@@ -752,9 +752,10 @@ HeapSnapshotsCollection::~HeapSnapshotsCollection() {
 }


-void HeapSnapshotsCollection::StartHeapObjectsTracking() {
+void HeapSnapshotsCollection::StartHeapObjectsTracking(bool track_allocations) {
   ids_.UpdateHeapObjectsMap();
-  if (allocation_tracker_ == NULL) {
+  ASSERT(allocation_tracker_ == NULL);
+  if (track_allocations) {
     allocation_tracker_ = new AllocationTracker(&ids_, names());
   }
 }
Index: src/heap-snapshot-generator.h
diff --git a/src/heap-snapshot-generator.h b/src/heap-snapshot-generator.h
index 8fa840c6c28028b4daa6385bc8759003af1ff4b7..e55513f890dad9366f79f7017490eddb9ac5d396 100644
--- a/src/heap-snapshot-generator.h
+++ b/src/heap-snapshot-generator.h
@@ -296,7 +296,7 @@ class HeapSnapshotsCollection {
   SnapshotObjectId PushHeapObjectsStats(OutputStream* stream) {
     return ids_.PushHeapObjectsStats(stream);
   }
-  void StartHeapObjectsTracking();
+  void StartHeapObjectsTracking(bool track_allocations);
   void StopHeapObjectsTracking();

   HeapSnapshot* NewSnapshot(const char* name, unsigned uid);
Index: test/cctest/cctest.h
diff --git a/test/cctest/cctest.h b/test/cctest/cctest.h
index 4db0d83cb82047324be13ca8861d628e232676be..aec3e0e8384f8015226ff7291e166f984942ff4d 100644
--- a/test/cctest/cctest.h
+++ b/test/cctest/cctest.h
@@ -358,13 +358,13 @@ class HeapObjectsTracker {
   HeapObjectsTracker() {
     heap_profiler_ = i::Isolate::Current()->heap_profiler();
     CHECK_NE(NULL, heap_profiler_);
-    heap_profiler_->StartHeapAllocationsRecording();
+    heap_profiler_->StartHeapObjectsTracking(true);
   }

   ~HeapObjectsTracker() {
     i::Isolate::Current()->heap()->CollectAllAvailableGarbage();
     CHECK_EQ(0, heap_profiler_->FindUntrackedObjects());
-    heap_profiler_->StopHeapAllocationsRecording();
+    heap_profiler_->StopHeapObjectsTracking();
   }

  private:
Index: test/cctest/test-heap-profiler.cc
diff --git a/test/cctest/test-heap-profiler.cc b/test/cctest/test-heap-profiler.cc index fed108d8c1428ef84244dbba680987480beb7493..88be69366ac166962e355fb078e7346c4c500cf8 100644
--- a/test/cctest/test-heap-profiler.cc
+++ b/test/cctest/test-heap-profiler.cc
@@ -2191,7 +2191,7 @@ TEST(ArrayGrowLeftTrim) {
   LocalContext env;
   v8::HandleScope scope(env->GetIsolate());
   v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
-  heap_profiler->StartRecordingHeapAllocations();
+  heap_profiler->StartTrackingHeapObjects(true);

   CompileRun(
     "var a = [];\n"
@@ -2216,7 +2216,7 @@ TEST(ArrayGrowLeftTrim) {
   CHECK_NE(NULL, node);
   CHECK_GE(node->allocation_count(), 2);
   CHECK_GE(node->allocation_size(), 4 * 5);
-  heap_profiler->StopRecordingHeapAllocations();
+  heap_profiler->StopTrackingHeapObjects();
 }


@@ -2225,7 +2225,7 @@ TEST(TrackHeapAllocations) {
   LocalContext env;

   v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
-  heap_profiler->StartRecordingHeapAllocations();
+  heap_profiler->StartTrackingHeapObjects(true);

   CompileRun(record_trace_tree_source);

@@ -2246,7 +2246,7 @@ TEST(TrackHeapAllocations) {
   CHECK_NE(NULL, node);
   CHECK_GE(node->allocation_count(), 100);
   CHECK_GE(node->allocation_size(), 4 * node->allocation_count());
-  heap_profiler->StopRecordingHeapAllocations();
+  heap_profiler->StopTrackingHeapObjects();
 }


@@ -2278,7 +2278,7 @@ TEST(TrackBumpPointerAllocations) {
   const char* names[] = { "(anonymous function)", "start", "f_0", "f_1" };
   // First check that normally all allocations are recorded.
   {
-    heap_profiler->StartRecordingHeapAllocations();
+    heap_profiler->StartTrackingHeapObjects(true);

     CompileRun(inline_heap_allocation_source);

@@ -2297,11 +2297,11 @@ TEST(TrackBumpPointerAllocations) {
     CHECK_NE(NULL, node);
     CHECK_GE(node->allocation_count(), 100);
     CHECK_GE(node->allocation_size(), 4 * node->allocation_count());
-    heap_profiler->StopRecordingHeapAllocations();
+    heap_profiler->StopTrackingHeapObjects();
   }

   {
-    heap_profiler->StartRecordingHeapAllocations();
+    heap_profiler->StartTrackingHeapObjects(true);

// Now check that not all allocations are tracked if we manually reenable
     // inline allocations.
@@ -2326,6 +2326,6 @@ TEST(TrackBumpPointerAllocations) {
     CHECK_LT(node->allocation_count(), 100);

     CcTest::heap()->DisableInlineAllocation();
-    heap_profiler->StopRecordingHeapAllocations();
+    heap_profiler->StopTrackingHeapObjects();
   }
 }


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