Commit e87fe7b7 authored by yurys@chromium.org's avatar yurys@chromium.org

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
R=loislo@chromium.org, mstarzinger@chromium.org

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@18197 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent bf3d84e3
...@@ -425,8 +425,12 @@ class V8_EXPORT HeapProfiler { ...@@ -425,8 +425,12 @@ class V8_EXPORT HeapProfiler {
* Starts tracking of heap objects population statistics. After calling * Starts tracking of heap objects population statistics. After calling
* this method, all heap objects relocations done by the garbage collector * this method, all heap objects relocations done by the garbage collector
* are being registered. * 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 * Adds a new time interval entry to the aggregated statistics array. The
...@@ -479,13 +483,15 @@ class V8_EXPORT HeapProfiler { ...@@ -479,13 +483,15 @@ class V8_EXPORT HeapProfiler {
* Starts recording JS allocations immediately as they arrive and tracking of * Starts recording JS allocations immediately as they arrive and tracking of
* heap objects population statistics. * heap objects population statistics.
*/ */
void StartRecordingHeapAllocations(); V8_DEPRECATED("Use StartTrackingHeapObjects instead",
void StartRecordingHeapAllocations());
/** /**
* Stops recording JS allocations and tracking of heap objects population * Stops recording JS allocations and tracking of heap objects population
* statistics, cleans all collected heap objects population statistics data. * statistics, cleans all collected heap objects population statistics data.
*/ */
void StopRecordingHeapAllocations(); V8_DEPRECATED("Use StopTrackingHeapObjects instead",
void StopRecordingHeapAllocations());
private: private:
......
...@@ -7497,8 +7497,9 @@ const HeapSnapshot* HeapProfiler::TakeHeapSnapshot( ...@@ -7497,8 +7497,9 @@ const HeapSnapshot* HeapProfiler::TakeHeapSnapshot(
} }
void HeapProfiler::StartTrackingHeapObjects() { void HeapProfiler::StartTrackingHeapObjects(bool track_allocations) {
reinterpret_cast<i::HeapProfiler*>(this)->StartHeapObjectsTracking(); reinterpret_cast<i::HeapProfiler*>(this)->StartHeapObjectsTracking(
track_allocations);
} }
...@@ -7537,12 +7538,12 @@ void HeapProfiler::SetRetainedObjectInfo(UniqueId id, ...@@ -7537,12 +7538,12 @@ void HeapProfiler::SetRetainedObjectInfo(UniqueId id,
void HeapProfiler::StartRecordingHeapAllocations() { void HeapProfiler::StartRecordingHeapAllocations() {
reinterpret_cast<i::HeapProfiler*>(this)->StartHeapAllocationsRecording(); reinterpret_cast<i::HeapProfiler*>(this)->StartHeapObjectsTracking(true);
} }
void HeapProfiler::StopRecordingHeapAllocations() { void HeapProfiler::StopRecordingHeapAllocations() {
reinterpret_cast<i::HeapProfiler*>(this)->StopHeapAllocationsRecording(); reinterpret_cast<i::HeapProfiler*>(this)->StopHeapObjectsTracking();
} }
......
...@@ -98,9 +98,14 @@ HeapSnapshot* HeapProfiler::TakeSnapshot( ...@@ -98,9 +98,14 @@ HeapSnapshot* HeapProfiler::TakeSnapshot(
} }
void HeapProfiler::StartHeapObjectsTracking() { void HeapProfiler::StartHeapObjectsTracking(bool track_allocations) {
snapshots_->StartHeapObjectsTracking(); snapshots_->StartHeapObjectsTracking(track_allocations);
is_tracking_object_moves_ = true; 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) { ...@@ -111,6 +116,10 @@ SnapshotObjectId HeapProfiler::PushHeapObjectsStats(OutputStream* stream) {
void HeapProfiler::StopHeapObjectsTracking() { void HeapProfiler::StopHeapObjectsTracking() {
snapshots_->StopHeapObjectsTracking(); snapshots_->StopHeapObjectsTracking();
if (is_tracking_allocations_) {
heap()->EnableInlineAllocation();
is_tracking_allocations_ = false;
}
} }
...@@ -158,18 +167,4 @@ void HeapProfiler::SetRetainedObjectInfo(UniqueId id, ...@@ -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 } } // namespace v8::internal
...@@ -53,7 +53,7 @@ class HeapProfiler { ...@@ -53,7 +53,7 @@ class HeapProfiler {
v8::ActivityControl* control, v8::ActivityControl* control,
v8::HeapProfiler::ObjectNameResolver* resolver); v8::HeapProfiler::ObjectNameResolver* resolver);
void StartHeapObjectsTracking(); void StartHeapObjectsTracking(bool track_allocations);
void StopHeapObjectsTracking(); void StopHeapObjectsTracking();
SnapshotObjectId PushHeapObjectsStats(OutputStream* stream); SnapshotObjectId PushHeapObjectsStats(OutputStream* stream);
...@@ -78,9 +78,6 @@ class HeapProfiler { ...@@ -78,9 +78,6 @@ class HeapProfiler {
bool is_tracking_object_moves() const { return is_tracking_object_moves_; } bool is_tracking_object_moves() const { return is_tracking_object_moves_; }
bool is_tracking_allocations() const { return is_tracking_allocations_; } bool is_tracking_allocations() const { return is_tracking_allocations_; }
void StartHeapAllocationsRecording();
void StopHeapAllocationsRecording();
int FindUntrackedObjects() { int FindUntrackedObjects() {
return snapshots_->FindUntrackedObjects(); return snapshots_->FindUntrackedObjects();
} }
......
...@@ -752,9 +752,10 @@ HeapSnapshotsCollection::~HeapSnapshotsCollection() { ...@@ -752,9 +752,10 @@ HeapSnapshotsCollection::~HeapSnapshotsCollection() {
} }
void HeapSnapshotsCollection::StartHeapObjectsTracking() { void HeapSnapshotsCollection::StartHeapObjectsTracking(bool track_allocations) {
ids_.UpdateHeapObjectsMap(); ids_.UpdateHeapObjectsMap();
if (allocation_tracker_ == NULL) { ASSERT(allocation_tracker_ == NULL);
if (track_allocations) {
allocation_tracker_ = new AllocationTracker(&ids_, names()); allocation_tracker_ = new AllocationTracker(&ids_, names());
} }
} }
......
...@@ -296,7 +296,7 @@ class HeapSnapshotsCollection { ...@@ -296,7 +296,7 @@ class HeapSnapshotsCollection {
SnapshotObjectId PushHeapObjectsStats(OutputStream* stream) { SnapshotObjectId PushHeapObjectsStats(OutputStream* stream) {
return ids_.PushHeapObjectsStats(stream); return ids_.PushHeapObjectsStats(stream);
} }
void StartHeapObjectsTracking(); void StartHeapObjectsTracking(bool track_allocations);
void StopHeapObjectsTracking(); void StopHeapObjectsTracking();
HeapSnapshot* NewSnapshot(const char* name, unsigned uid); HeapSnapshot* NewSnapshot(const char* name, unsigned uid);
......
...@@ -358,13 +358,13 @@ class HeapObjectsTracker { ...@@ -358,13 +358,13 @@ class HeapObjectsTracker {
HeapObjectsTracker() { HeapObjectsTracker() {
heap_profiler_ = i::Isolate::Current()->heap_profiler(); heap_profiler_ = i::Isolate::Current()->heap_profiler();
CHECK_NE(NULL, heap_profiler_); CHECK_NE(NULL, heap_profiler_);
heap_profiler_->StartHeapAllocationsRecording(); heap_profiler_->StartHeapObjectsTracking(true);
} }
~HeapObjectsTracker() { ~HeapObjectsTracker() {
i::Isolate::Current()->heap()->CollectAllAvailableGarbage(); i::Isolate::Current()->heap()->CollectAllAvailableGarbage();
CHECK_EQ(0, heap_profiler_->FindUntrackedObjects()); CHECK_EQ(0, heap_profiler_->FindUntrackedObjects());
heap_profiler_->StopHeapAllocationsRecording(); heap_profiler_->StopHeapObjectsTracking();
} }
private: private:
......
...@@ -2191,7 +2191,7 @@ TEST(ArrayGrowLeftTrim) { ...@@ -2191,7 +2191,7 @@ TEST(ArrayGrowLeftTrim) {
LocalContext env; LocalContext env;
v8::HandleScope scope(env->GetIsolate()); v8::HandleScope scope(env->GetIsolate());
v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
heap_profiler->StartRecordingHeapAllocations(); heap_profiler->StartTrackingHeapObjects(true);
CompileRun( CompileRun(
"var a = [];\n" "var a = [];\n"
...@@ -2216,7 +2216,7 @@ TEST(ArrayGrowLeftTrim) { ...@@ -2216,7 +2216,7 @@ TEST(ArrayGrowLeftTrim) {
CHECK_NE(NULL, node); CHECK_NE(NULL, node);
CHECK_GE(node->allocation_count(), 2); CHECK_GE(node->allocation_count(), 2);
CHECK_GE(node->allocation_size(), 4 * 5); CHECK_GE(node->allocation_size(), 4 * 5);
heap_profiler->StopRecordingHeapAllocations(); heap_profiler->StopTrackingHeapObjects();
} }
...@@ -2225,7 +2225,7 @@ TEST(TrackHeapAllocations) { ...@@ -2225,7 +2225,7 @@ TEST(TrackHeapAllocations) {
LocalContext env; LocalContext env;
v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
heap_profiler->StartRecordingHeapAllocations(); heap_profiler->StartTrackingHeapObjects(true);
CompileRun(record_trace_tree_source); CompileRun(record_trace_tree_source);
...@@ -2246,7 +2246,7 @@ TEST(TrackHeapAllocations) { ...@@ -2246,7 +2246,7 @@ TEST(TrackHeapAllocations) {
CHECK_NE(NULL, node); CHECK_NE(NULL, node);
CHECK_GE(node->allocation_count(), 100); CHECK_GE(node->allocation_count(), 100);
CHECK_GE(node->allocation_size(), 4 * node->allocation_count()); CHECK_GE(node->allocation_size(), 4 * node->allocation_count());
heap_profiler->StopRecordingHeapAllocations(); heap_profiler->StopTrackingHeapObjects();
} }
...@@ -2278,7 +2278,7 @@ TEST(TrackBumpPointerAllocations) { ...@@ -2278,7 +2278,7 @@ TEST(TrackBumpPointerAllocations) {
const char* names[] = { "(anonymous function)", "start", "f_0", "f_1" }; const char* names[] = { "(anonymous function)", "start", "f_0", "f_1" };
// First check that normally all allocations are recorded. // First check that normally all allocations are recorded.
{ {
heap_profiler->StartRecordingHeapAllocations(); heap_profiler->StartTrackingHeapObjects(true);
CompileRun(inline_heap_allocation_source); CompileRun(inline_heap_allocation_source);
...@@ -2297,11 +2297,11 @@ TEST(TrackBumpPointerAllocations) { ...@@ -2297,11 +2297,11 @@ TEST(TrackBumpPointerAllocations) {
CHECK_NE(NULL, node); CHECK_NE(NULL, node);
CHECK_GE(node->allocation_count(), 100); CHECK_GE(node->allocation_count(), 100);
CHECK_GE(node->allocation_size(), 4 * node->allocation_count()); 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 // Now check that not all allocations are tracked if we manually reenable
// inline allocations. // inline allocations.
...@@ -2326,6 +2326,6 @@ TEST(TrackBumpPointerAllocations) { ...@@ -2326,6 +2326,6 @@ TEST(TrackBumpPointerAllocations) {
CHECK_LT(node->allocation_count(), 100); CHECK_LT(node->allocation_count(), 100);
CcTest::heap()->DisableInlineAllocation(); CcTest::heap()->DisableInlineAllocation();
heap_profiler->StopRecordingHeapAllocations(); heap_profiler->StopTrackingHeapObjects();
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment