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 {
* 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:
......
......@@ -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();
}
......
......@@ -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
......@@ -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();
}
......
......@@ -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());
}
}
......
......@@ -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);
......
......@@ -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:
......
......@@ -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();
}
}
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