Commit 047f6f97 authored by yurys@chromium.org's avatar yurys@chromium.org

Isolatify HeapProfiler

Re-landing r13997 that was reverted in r14031

TBR=danno
BUG=None

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@14106 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 9cbb34a0
...@@ -385,7 +385,8 @@ class V8EXPORT HeapSnapshot { ...@@ -385,7 +385,8 @@ class V8EXPORT HeapSnapshot {
class RetainedObjectInfo; class RetainedObjectInfo;
/** /**
* Interface for controlling heap profiling. * Interface for controlling heap profiling. Instance of the
* profiler can be retrieved using v8::Isolate::GetHeapProfiler.
*/ */
class V8EXPORT HeapProfiler { class V8EXPORT HeapProfiler {
public: public:
...@@ -398,20 +399,28 @@ class V8EXPORT HeapProfiler { ...@@ -398,20 +399,28 @@ class V8EXPORT HeapProfiler {
typedef RetainedObjectInfo* (*WrapperInfoCallback) typedef RetainedObjectInfo* (*WrapperInfoCallback)
(uint16_t class_id, Handle<Value> wrapper); (uint16_t class_id, Handle<Value> wrapper);
/** Returns the number of snapshots taken. */ /** Deprecated. Use GetSnapshotCount instead. */
static int GetSnapshotsCount(); static int GetSnapshotsCount();
/** Returns the number of snapshots taken. */
int GetSnapshotCount();
/** Returns a snapshot by index. */ /** Deprecated. Use GetHeapSnapshot instead. */
static const HeapSnapshot* GetSnapshot(int index); static const HeapSnapshot* GetSnapshot(int index);
/** Returns a snapshot by index. */
const HeapSnapshot* GetHeapSnapshot(int index);
/** Returns a profile by uid. */ /** Deprecated. Use FindHeapSnapshot instead. */
static const HeapSnapshot* FindSnapshot(unsigned uid); static const HeapSnapshot* FindSnapshot(unsigned uid);
/** Returns a profile by uid. */
const HeapSnapshot* FindHeapSnapshot(unsigned uid);
/** Deprecated. Use GetObjectId instead. */
static SnapshotObjectId GetSnapshotObjectId(Handle<Value> value);
/** /**
* Returns SnapshotObjectId for a heap object referenced by |value| if * Returns SnapshotObjectId for a heap object referenced by |value| if
* it has been seen by the heap profiler, kUnknownObjectId otherwise. * it has been seen by the heap profiler, kUnknownObjectId otherwise.
*/ */
static SnapshotObjectId GetSnapshotObjectId(Handle<Value> value); SnapshotObjectId GetObjectId(Handle<Value> value);
/** /**
* A constant for invalid SnapshotObjectId. GetSnapshotObjectId will return * A constant for invalid SnapshotObjectId. GetSnapshotObjectId will return
...@@ -424,33 +433,43 @@ class V8EXPORT HeapProfiler { ...@@ -424,33 +433,43 @@ class V8EXPORT HeapProfiler {
* Callback interface for retrieving user friendly names of global objects. * Callback interface for retrieving user friendly names of global objects.
*/ */
class ObjectNameResolver { class ObjectNameResolver {
public: public:
/** /**
* Returns name to be used in the heap snapshot for given node. Returned * Returns name to be used in the heap snapshot for given node. Returned
* string must stay alive until snapshot collection is completed. * string must stay alive until snapshot collection is completed.
*/ */
virtual const char* GetName(Handle<Object> object) = 0; virtual const char* GetName(Handle<Object> object) = 0;
protected: protected:
virtual ~ObjectNameResolver() {} virtual ~ObjectNameResolver() {}
}; };
/** Deprecated. Use TakeHeapSnapshot instead. */
static const HeapSnapshot* TakeSnapshot(
Handle<String> title,
HeapSnapshot::Type type = HeapSnapshot::kFull,
ActivityControl* control = NULL,
ObjectNameResolver* global_object_name_resolver = NULL);
/** /**
* Takes a heap snapshot and returns it. Title may be an empty string. * Takes a heap snapshot and returns it. Title may be an empty string.
* See HeapSnapshot::Type for types description. * See HeapSnapshot::Type for types description.
*/ */
static const HeapSnapshot* TakeSnapshot( const HeapSnapshot* TakeHeapSnapshot(
Handle<String> title, Handle<String> title,
HeapSnapshot::Type type = HeapSnapshot::kFull,
ActivityControl* control = NULL, ActivityControl* control = NULL,
ObjectNameResolver* global_object_name_resolver = NULL); ObjectNameResolver* global_object_name_resolver = NULL);
/** Deprecated. Use StartTrackingHeapObjects instead. */
static void StartHeapObjectsTracking();
/** /**
* 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.
*/ */
static void StartHeapObjectsTracking(); void StartTrackingHeapObjects();
/** Deprecated. Use GetHeapStats instead. */
static SnapshotObjectId PushHeapObjectsStats(OutputStream* stream);
/** /**
* Adds a new time interval entry to the aggregated statistics array. The * Adds a new time interval entry to the aggregated statistics array. The
* time interval entry contains information on the current heap objects * time interval entry contains information on the current heap objects
...@@ -460,28 +479,36 @@ class V8EXPORT HeapProfiler { ...@@ -460,28 +479,36 @@ class V8EXPORT HeapProfiler {
* HeapStatsUpdate structure instances. * HeapStatsUpdate structure instances.
* The return value of the function is the last seen heap object Id. * The return value of the function is the last seen heap object Id.
* *
* StartHeapObjectsTracking must be called before the first call to this * StartTrackingHeapObjects must be called before the first call to this
* method. * method.
*/ */
static SnapshotObjectId PushHeapObjectsStats(OutputStream* stream); SnapshotObjectId GetHeapStats(OutputStream* stream);
/** Deprecated. Use StopTrackingHeapObjects instead. */
static void StopHeapObjectsTracking();
/** /**
* Stops tracking of heap objects population statistics, cleans up all * Stops tracking of heap objects population statistics, cleans up all
* collected data. StartHeapObjectsTracking must be called again prior to * collected data. StartHeapObjectsTracking must be called again prior to
* calling PushHeapObjectsStats next time. * calling PushHeapObjectsStats next time.
*/ */
static void StopHeapObjectsTracking(); void StopTrackingHeapObjects();
/** Deprecated. Use DeleteAllHeapSnapshots instead. */
static void DeleteAllSnapshots();
/** /**
* Deletes all snapshots taken. All previously returned pointers to * Deletes all snapshots taken. All previously returned pointers to
* snapshots and their contents become invalid after this call. * snapshots and their contents become invalid after this call.
*/ */
static void DeleteAllSnapshots(); void DeleteAllHeapSnapshots();
/** Binds a callback to embedder's class ID. */ /** Deprecated. Use SetWrapperClassInfoProvider instead. */
static void DefineWrapperClass( static void DefineWrapperClass(
uint16_t class_id, uint16_t class_id,
WrapperInfoCallback callback); WrapperInfoCallback callback);
/** Binds a callback to embedder's class ID. */
void SetWrapperClassInfoProvider(
uint16_t class_id,
WrapperInfoCallback callback);
/** /**
* Default value of persistent handle class ID. Must not be used to * Default value of persistent handle class ID. Must not be used to
...@@ -490,11 +517,21 @@ class V8EXPORT HeapProfiler { ...@@ -490,11 +517,21 @@ class V8EXPORT HeapProfiler {
*/ */
static const uint16_t kPersistentHandleNoClassId = 0; static const uint16_t kPersistentHandleNoClassId = 0;
/** Returns the number of currently existing persistent handles. */ /**
* Deprecated. Returns the number of currently existing persistent handles.
*/
static int GetPersistentHandleCount(); static int GetPersistentHandleCount();
/** Returns memory used for profiler internal data and snapshots. */ /** Deprecated. Use GetHeapProfilerMemorySize instead. */
static size_t GetMemorySizeUsedByProfiler(); static size_t GetMemorySizeUsedByProfiler();
/** Returns memory used for profiler internal data and snapshots. */
size_t GetProfilerMemorySize();
private:
HeapProfiler();
~HeapProfiler();
HeapProfiler(const HeapProfiler&);
HeapProfiler& operator=(const HeapProfiler&);
}; };
...@@ -574,7 +611,7 @@ class V8EXPORT RetainedObjectInfo { // NOLINT ...@@ -574,7 +611,7 @@ class V8EXPORT RetainedObjectInfo { // NOLINT
/** /**
* A struct for exporting HeapStats data from V8, using "push" model. * A struct for exporting HeapStats data from V8, using "push" model.
* See HeapProfiler::PushHeapObjectsStats. * See HeapProfiler::GetHeapStats.
*/ */
struct HeapStatsUpdate { struct HeapStatsUpdate {
HeapStatsUpdate(uint32_t index, uint32_t count, uint32_t size) HeapStatsUpdate(uint32_t index, uint32_t count, uint32_t size)
......
...@@ -109,6 +109,7 @@ class DeclaredAccessorDescriptor; ...@@ -109,6 +109,7 @@ class DeclaredAccessorDescriptor;
class External; class External;
class Function; class Function;
class FunctionTemplate; class FunctionTemplate;
class HeapProfiler;
class ImplementationUtilities; class ImplementationUtilities;
class Int32; class Int32;
class Integer; class Integer;
...@@ -3022,6 +3023,12 @@ class V8EXPORT Isolate { ...@@ -3022,6 +3023,12 @@ class V8EXPORT Isolate {
*/ */
intptr_t AdjustAmountOfExternalAllocatedMemory(intptr_t change_in_bytes); intptr_t AdjustAmountOfExternalAllocatedMemory(intptr_t change_in_bytes);
/**
* Returns heap profiler for this isolate. Will return NULL until the isolate
* is initialized.
*/
HeapProfiler* GetHeapProfiler();
private: private:
Isolate(); Isolate();
Isolate(const Isolate&); Isolate(const Isolate&);
......
...@@ -5799,6 +5799,13 @@ intptr_t V8::AdjustAmountOfExternalAllocatedMemory(intptr_t change_in_bytes) { ...@@ -5799,6 +5799,13 @@ intptr_t V8::AdjustAmountOfExternalAllocatedMemory(intptr_t change_in_bytes) {
} }
HeapProfiler* Isolate::GetHeapProfiler() {
i::HeapProfiler* heap_profiler =
reinterpret_cast<i::Isolate*>(this)->heap_profiler();
return reinterpret_cast<HeapProfiler*>(heap_profiler);
}
void V8::SetGlobalGCPrologueCallback(GCCallback callback) { void V8::SetGlobalGCPrologueCallback(GCCallback callback) {
i::Isolate* isolate = i::Isolate::Current(); i::Isolate* isolate = i::Isolate::Current();
if (IsDeadCheck(isolate, "v8::V8::SetGlobalGCPrologueCallback()")) return; if (IsDeadCheck(isolate, "v8::V8::SetGlobalGCPrologueCallback()")) return;
...@@ -6708,11 +6715,11 @@ static i::HeapSnapshot* ToInternal(const HeapSnapshot* snapshot) { ...@@ -6708,11 +6715,11 @@ static i::HeapSnapshot* ToInternal(const HeapSnapshot* snapshot) {
void HeapSnapshot::Delete() { void HeapSnapshot::Delete() {
i::Isolate* isolate = i::Isolate::Current(); i::Isolate* isolate = i::Isolate::Current();
IsDeadCheck(isolate, "v8::HeapSnapshot::Delete"); IsDeadCheck(isolate, "v8::HeapSnapshot::Delete");
if (i::HeapProfiler::GetSnapshotsCount() > 1) { if (isolate->heap_profiler()->GetSnapshotsCount() > 1) {
ToInternal(this)->Delete(); ToInternal(this)->Delete();
} else { } else {
// If this is the last snapshot, clean up all accessory data as well. // If this is the last snapshot, clean up all accessory data as well.
i::HeapProfiler::DeleteAllSnapshots(); isolate->heap_profiler()->DeleteAllSnapshots();
} }
} }
...@@ -6797,7 +6804,12 @@ void HeapSnapshot::Serialize(OutputStream* stream, ...@@ -6797,7 +6804,12 @@ void HeapSnapshot::Serialize(OutputStream* stream,
int HeapProfiler::GetSnapshotsCount() { int HeapProfiler::GetSnapshotsCount() {
i::Isolate* isolate = i::Isolate::Current(); i::Isolate* isolate = i::Isolate::Current();
IsDeadCheck(isolate, "v8::HeapProfiler::GetSnapshotsCount"); IsDeadCheck(isolate, "v8::HeapProfiler::GetSnapshotsCount");
return i::HeapProfiler::GetSnapshotsCount(); return isolate->heap_profiler()->GetSnapshotsCount();
}
int HeapProfiler::GetSnapshotCount() {
return reinterpret_cast<i::HeapProfiler*>(this)->GetSnapshotsCount();
} }
...@@ -6805,7 +6817,13 @@ const HeapSnapshot* HeapProfiler::GetSnapshot(int index) { ...@@ -6805,7 +6817,13 @@ const HeapSnapshot* HeapProfiler::GetSnapshot(int index) {
i::Isolate* isolate = i::Isolate::Current(); i::Isolate* isolate = i::Isolate::Current();
IsDeadCheck(isolate, "v8::HeapProfiler::GetSnapshot"); IsDeadCheck(isolate, "v8::HeapProfiler::GetSnapshot");
return reinterpret_cast<const HeapSnapshot*>( return reinterpret_cast<const HeapSnapshot*>(
i::HeapProfiler::GetSnapshot(index)); isolate->heap_profiler()->GetSnapshot(index));
}
const HeapSnapshot* HeapProfiler::GetHeapSnapshot(int index) {
return reinterpret_cast<const HeapSnapshot*>(
reinterpret_cast<i::HeapProfiler*>(this)->GetSnapshot(index));
} }
...@@ -6813,7 +6831,13 @@ const HeapSnapshot* HeapProfiler::FindSnapshot(unsigned uid) { ...@@ -6813,7 +6831,13 @@ const HeapSnapshot* HeapProfiler::FindSnapshot(unsigned uid) {
i::Isolate* isolate = i::Isolate::Current(); i::Isolate* isolate = i::Isolate::Current();
IsDeadCheck(isolate, "v8::HeapProfiler::FindSnapshot"); IsDeadCheck(isolate, "v8::HeapProfiler::FindSnapshot");
return reinterpret_cast<const HeapSnapshot*>( return reinterpret_cast<const HeapSnapshot*>(
i::HeapProfiler::FindSnapshot(uid)); isolate->heap_profiler()->FindSnapshot(uid));
}
const HeapSnapshot* HeapProfiler::FindHeapSnapshot(unsigned uid) {
return reinterpret_cast<const HeapSnapshot*>(
reinterpret_cast<i::HeapProfiler*>(this)->FindSnapshot(uid));
} }
...@@ -6821,7 +6845,13 @@ SnapshotObjectId HeapProfiler::GetSnapshotObjectId(Handle<Value> value) { ...@@ -6821,7 +6845,13 @@ SnapshotObjectId HeapProfiler::GetSnapshotObjectId(Handle<Value> value) {
i::Isolate* isolate = i::Isolate::Current(); i::Isolate* isolate = i::Isolate::Current();
IsDeadCheck(isolate, "v8::HeapProfiler::GetSnapshotObjectId"); IsDeadCheck(isolate, "v8::HeapProfiler::GetSnapshotObjectId");
i::Handle<i::Object> obj = Utils::OpenHandle(*value); i::Handle<i::Object> obj = Utils::OpenHandle(*value);
return i::HeapProfiler::GetSnapshotObjectId(obj); return isolate->heap_profiler()->GetSnapshotObjectId(obj);
}
SnapshotObjectId HeapProfiler::GetObjectId(Handle<Value> value) {
i::Handle<i::Object> obj = Utils::OpenHandle(*value);
return reinterpret_cast<i::HeapProfiler*>(this)->GetSnapshotObjectId(obj);
} }
...@@ -6840,36 +6870,67 @@ const HeapSnapshot* HeapProfiler::TakeSnapshot(Handle<String> title, ...@@ -6840,36 +6870,67 @@ const HeapSnapshot* HeapProfiler::TakeSnapshot(Handle<String> title,
UNREACHABLE(); UNREACHABLE();
} }
return reinterpret_cast<const HeapSnapshot*>( return reinterpret_cast<const HeapSnapshot*>(
i::HeapProfiler::TakeSnapshot( isolate->heap_profiler()->TakeSnapshot(
*Utils::OpenHandle(*title), internal_type, control, resolver)); *Utils::OpenHandle(*title), internal_type, control, resolver));
} }
const HeapSnapshot* HeapProfiler::TakeHeapSnapshot(
Handle<String> title,
ActivityControl* control,
ObjectNameResolver* resolver) {
return reinterpret_cast<const HeapSnapshot*>(
reinterpret_cast<i::HeapProfiler*>(this)->TakeSnapshot(
*Utils::OpenHandle(*title), i::HeapSnapshot::kFull,
control, resolver));
}
void HeapProfiler::StartHeapObjectsTracking() { void HeapProfiler::StartHeapObjectsTracking() {
i::Isolate* isolate = i::Isolate::Current(); i::Isolate* isolate = i::Isolate::Current();
IsDeadCheck(isolate, "v8::HeapProfiler::StartHeapObjectsTracking"); IsDeadCheck(isolate, "v8::HeapProfiler::StartHeapObjectsTracking");
i::HeapProfiler::StartHeapObjectsTracking(); isolate->heap_profiler()->StartHeapObjectsTracking();
}
void HeapProfiler::StartTrackingHeapObjects() {
reinterpret_cast<i::HeapProfiler*>(this)->StartHeapObjectsTracking();
} }
void HeapProfiler::StopHeapObjectsTracking() { void HeapProfiler::StopHeapObjectsTracking() {
i::Isolate* isolate = i::Isolate::Current(); i::Isolate* isolate = i::Isolate::Current();
IsDeadCheck(isolate, "v8::HeapProfiler::StopHeapObjectsTracking"); IsDeadCheck(isolate, "v8::HeapProfiler::StopHeapObjectsTracking");
i::HeapProfiler::StopHeapObjectsTracking(); isolate->heap_profiler()->StopHeapObjectsTracking();
}
void HeapProfiler::StopTrackingHeapObjects() {
reinterpret_cast<i::HeapProfiler*>(this)->StopHeapObjectsTracking();
} }
SnapshotObjectId HeapProfiler::PushHeapObjectsStats(OutputStream* stream) { SnapshotObjectId HeapProfiler::PushHeapObjectsStats(OutputStream* stream) {
i::Isolate* isolate = i::Isolate::Current(); i::Isolate* isolate = i::Isolate::Current();
IsDeadCheck(isolate, "v8::HeapProfiler::PushHeapObjectsStats"); IsDeadCheck(isolate, "v8::HeapProfiler::PushHeapObjectsStats");
return i::HeapProfiler::PushHeapObjectsStats(stream); return isolate->heap_profiler()->PushHeapObjectsStats(stream);
}
SnapshotObjectId HeapProfiler::GetHeapStats(OutputStream* stream) {
return reinterpret_cast<i::HeapProfiler*>(this)->PushHeapObjectsStats(stream);
} }
void HeapProfiler::DeleteAllSnapshots() { void HeapProfiler::DeleteAllSnapshots() {
i::Isolate* isolate = i::Isolate::Current(); i::Isolate* isolate = i::Isolate::Current();
IsDeadCheck(isolate, "v8::HeapProfiler::DeleteAllSnapshots"); IsDeadCheck(isolate, "v8::HeapProfiler::DeleteAllSnapshots");
i::HeapProfiler::DeleteAllSnapshots(); isolate->heap_profiler()->DeleteAllSnapshots();
}
void HeapProfiler::DeleteAllHeapSnapshots() {
reinterpret_cast<i::HeapProfiler*>(this)->DeleteAllSnapshots();
} }
...@@ -6880,6 +6941,13 @@ void HeapProfiler::DefineWrapperClass(uint16_t class_id, ...@@ -6880,6 +6941,13 @@ void HeapProfiler::DefineWrapperClass(uint16_t class_id,
} }
void HeapProfiler::SetWrapperClassInfoProvider(uint16_t class_id,
WrapperInfoCallback callback) {
reinterpret_cast<i::HeapProfiler*>(this)->DefineWrapperClass(class_id,
callback);
}
int HeapProfiler::GetPersistentHandleCount() { int HeapProfiler::GetPersistentHandleCount() {
i::Isolate* isolate = i::Isolate::Current(); i::Isolate* isolate = i::Isolate::Current();
return isolate->global_handles()->NumberOfGlobalHandles(); return isolate->global_handles()->NumberOfGlobalHandles();
...@@ -6887,7 +6955,13 @@ int HeapProfiler::GetPersistentHandleCount() { ...@@ -6887,7 +6955,13 @@ int HeapProfiler::GetPersistentHandleCount() {
size_t HeapProfiler::GetMemorySizeUsedByProfiler() { size_t HeapProfiler::GetMemorySizeUsedByProfiler() {
return i::HeapProfiler::GetMemorySizeUsedByProfiler(); return i::Isolate::Current()->heap_profiler()->GetMemorySizeUsedByProfiler();
}
size_t HeapProfiler::GetProfilerMemorySize() {
return reinterpret_cast<i::HeapProfiler*>(this)->
GetMemorySizeUsedByProfiler();
} }
......
...@@ -44,72 +44,13 @@ HeapProfiler::~HeapProfiler() { ...@@ -44,72 +44,13 @@ HeapProfiler::~HeapProfiler() {
} }
void HeapProfiler::ResetSnapshots() { void HeapProfiler::DeleteAllSnapshots() {
Heap* the_heap = heap(); Heap* the_heap = heap();
delete snapshots_; delete snapshots_;
snapshots_ = new HeapSnapshotsCollection(the_heap); snapshots_ = new HeapSnapshotsCollection(the_heap);
} }
void HeapProfiler::SetUp() {
Isolate* isolate = Isolate::Current();
if (isolate->heap_profiler() == NULL) {
isolate->set_heap_profiler(new HeapProfiler(isolate->heap()));
}
}
void HeapProfiler::TearDown() {
Isolate* isolate = Isolate::Current();
delete isolate->heap_profiler();
isolate->set_heap_profiler(NULL);
}
HeapSnapshot* HeapProfiler::TakeSnapshot(
const char* name,
int type,
v8::ActivityControl* control,
v8::HeapProfiler::ObjectNameResolver* resolver) {
ASSERT(Isolate::Current()->heap_profiler() != NULL);
return Isolate::Current()->heap_profiler()->TakeSnapshotImpl(name,
type,
control,
resolver);
}
HeapSnapshot* HeapProfiler::TakeSnapshot(
String* name,
int type,
v8::ActivityControl* control,
v8::HeapProfiler::ObjectNameResolver* resolver) {
ASSERT(Isolate::Current()->heap_profiler() != NULL);
return Isolate::Current()->heap_profiler()->TakeSnapshotImpl(name,
type,
control,
resolver);
}
void HeapProfiler::StartHeapObjectsTracking() {
ASSERT(Isolate::Current()->heap_profiler() != NULL);
Isolate::Current()->heap_profiler()->StartHeapObjectsTrackingImpl();
}
void HeapProfiler::StopHeapObjectsTracking() {
ASSERT(Isolate::Current()->heap_profiler() != NULL);
Isolate::Current()->heap_profiler()->StopHeapObjectsTrackingImpl();
}
SnapshotObjectId HeapProfiler::PushHeapObjectsStats(v8::OutputStream* stream) {
ASSERT(Isolate::Current()->heap_profiler() != NULL);
return Isolate::Current()->heap_profiler()->PushHeapObjectsStatsImpl(stream);
}
void HeapProfiler::DefineWrapperClass( void HeapProfiler::DefineWrapperClass(
uint16_t class_id, v8::HeapProfiler::WrapperInfoCallback callback) { uint16_t class_id, v8::HeapProfiler::WrapperInfoCallback callback) {
ASSERT(class_id != v8::HeapProfiler::kPersistentHandleNoClassId); ASSERT(class_id != v8::HeapProfiler::kPersistentHandleNoClassId);
...@@ -129,7 +70,7 @@ v8::RetainedObjectInfo* HeapProfiler::ExecuteWrapperClassCallback( ...@@ -129,7 +70,7 @@ v8::RetainedObjectInfo* HeapProfiler::ExecuteWrapperClassCallback(
} }
HeapSnapshot* HeapProfiler::TakeSnapshotImpl( HeapSnapshot* HeapProfiler::TakeSnapshot(
const char* name, const char* name,
int type, int type,
v8::ActivityControl* control, v8::ActivityControl* control,
...@@ -156,72 +97,54 @@ HeapSnapshot* HeapProfiler::TakeSnapshotImpl( ...@@ -156,72 +97,54 @@ HeapSnapshot* HeapProfiler::TakeSnapshotImpl(
} }
HeapSnapshot* HeapProfiler::TakeSnapshotImpl( HeapSnapshot* HeapProfiler::TakeSnapshot(
String* name, String* name,
int type, int type,
v8::ActivityControl* control, v8::ActivityControl* control,
v8::HeapProfiler::ObjectNameResolver* resolver) { v8::HeapProfiler::ObjectNameResolver* resolver) {
return TakeSnapshotImpl(snapshots_->names()->GetName(name), type, control, return TakeSnapshot(snapshots_->names()->GetName(name), type, control,
resolver); resolver);
} }
void HeapProfiler::StartHeapObjectsTrackingImpl() { void HeapProfiler::StartHeapObjectsTracking() {
snapshots_->StartHeapObjectsTracking(); snapshots_->StartHeapObjectsTracking();
} }
SnapshotObjectId HeapProfiler::PushHeapObjectsStatsImpl(OutputStream* stream) { SnapshotObjectId HeapProfiler::PushHeapObjectsStats(OutputStream* stream) {
return snapshots_->PushHeapObjectsStats(stream); return snapshots_->PushHeapObjectsStats(stream);
} }
void HeapProfiler::StopHeapObjectsTrackingImpl() { void HeapProfiler::StopHeapObjectsTracking() {
snapshots_->StopHeapObjectsTracking(); snapshots_->StopHeapObjectsTracking();
} }
size_t HeapProfiler::GetMemorySizeUsedByProfiler() { size_t HeapProfiler::GetMemorySizeUsedByProfiler() {
HeapProfiler* profiler = Isolate::Current()->heap_profiler(); return snapshots_->GetUsedMemorySize();
ASSERT(profiler != NULL);
size_t size = profiler->snapshots_->GetUsedMemorySize();
return size;
} }
int HeapProfiler::GetSnapshotsCount() { int HeapProfiler::GetSnapshotsCount() {
HeapProfiler* profiler = Isolate::Current()->heap_profiler(); return snapshots_->snapshots()->length();
ASSERT(profiler != NULL);
return profiler->snapshots_->snapshots()->length();
} }
HeapSnapshot* HeapProfiler::GetSnapshot(int index) { HeapSnapshot* HeapProfiler::GetSnapshot(int index) {
HeapProfiler* profiler = Isolate::Current()->heap_profiler(); return snapshots_->snapshots()->at(index);
ASSERT(profiler != NULL);
return profiler->snapshots_->snapshots()->at(index);
} }
HeapSnapshot* HeapProfiler::FindSnapshot(unsigned uid) { HeapSnapshot* HeapProfiler::FindSnapshot(unsigned uid) {
HeapProfiler* profiler = Isolate::Current()->heap_profiler(); return snapshots_->GetSnapshot(uid);
ASSERT(profiler != NULL);
return profiler->snapshots_->GetSnapshot(uid);
} }
SnapshotObjectId HeapProfiler::GetSnapshotObjectId(Handle<Object> obj) { SnapshotObjectId HeapProfiler::GetSnapshotObjectId(Handle<Object> obj) {
if (!obj->IsHeapObject()) if (!obj->IsHeapObject())
return v8::HeapProfiler::kUnknownObjectId; return v8::HeapProfiler::kUnknownObjectId;
HeapProfiler* profiler = Isolate::Current()->heap_profiler(); return snapshots_->FindObjectId(HeapObject::cast(*obj)->address());
ASSERT(profiler != NULL);
return profiler->snapshots_->FindObjectId(HeapObject::cast(*obj)->address());
}
void HeapProfiler::DeleteAllSnapshots() {
HeapProfiler* profiler = Isolate::Current()->heap_profiler();
ASSERT(profiler != NULL);
profiler->ResetSnapshots();
} }
......
...@@ -46,30 +46,30 @@ class HeapSnapshotsCollection; ...@@ -46,30 +46,30 @@ class HeapSnapshotsCollection;
class HeapProfiler { class HeapProfiler {
public: public:
static void SetUp(); explicit HeapProfiler(Heap* heap);
static void TearDown(); ~HeapProfiler();
static size_t GetMemorySizeUsedByProfiler(); size_t GetMemorySizeUsedByProfiler();
static HeapSnapshot* TakeSnapshot( HeapSnapshot* TakeSnapshot(
const char* name, const char* name,
int type, int type,
v8::ActivityControl* control, v8::ActivityControl* control,
v8::HeapProfiler::ObjectNameResolver* resolver); v8::HeapProfiler::ObjectNameResolver* resolver);
static HeapSnapshot* TakeSnapshot( HeapSnapshot* TakeSnapshot(
String* name, String* name,
int type, int type,
v8::ActivityControl* control, v8::ActivityControl* control,
v8::HeapProfiler::ObjectNameResolver* resolver); v8::HeapProfiler::ObjectNameResolver* resolver);
static void StartHeapObjectsTracking(); void StartHeapObjectsTracking();
static void StopHeapObjectsTracking(); void StopHeapObjectsTracking();
static SnapshotObjectId PushHeapObjectsStats(OutputStream* stream); SnapshotObjectId PushHeapObjectsStats(OutputStream* stream);
static int GetSnapshotsCount(); int GetSnapshotsCount();
static HeapSnapshot* GetSnapshot(int index); HeapSnapshot* GetSnapshot(int index);
static HeapSnapshot* FindSnapshot(unsigned uid); HeapSnapshot* FindSnapshot(unsigned uid);
static SnapshotObjectId GetSnapshotObjectId(Handle<Object> obj); SnapshotObjectId GetSnapshotObjectId(Handle<Object> obj);
static void DeleteAllSnapshots(); void DeleteAllSnapshots();
void ObjectMoveEvent(Address from, Address to); void ObjectMoveEvent(Address from, Address to);
...@@ -83,24 +83,6 @@ class HeapProfiler { ...@@ -83,24 +83,6 @@ class HeapProfiler {
} }
private: private:
explicit HeapProfiler(Heap* heap);
~HeapProfiler();
HeapSnapshot* TakeSnapshotImpl(
const char* name,
int type,
v8::ActivityControl* control,
v8::HeapProfiler::ObjectNameResolver* resolver);
HeapSnapshot* TakeSnapshotImpl(
String* name,
int type,
v8::ActivityControl* control,
v8::HeapProfiler::ObjectNameResolver* resolver);
void ResetSnapshots();
void StartHeapObjectsTrackingImpl();
void StopHeapObjectsTrackingImpl();
SnapshotObjectId PushHeapObjectsStatsImpl(OutputStream* stream);
Heap* heap() const { return snapshots_->heap(); } Heap* heap() const { return snapshots_->heap(); }
HeapSnapshotsCollection* snapshots_; HeapSnapshotsCollection* snapshots_;
......
...@@ -1694,6 +1694,7 @@ Isolate::Isolate() ...@@ -1694,6 +1694,7 @@ Isolate::Isolate()
code_stub_interface_descriptors_(NULL), code_stub_interface_descriptors_(NULL),
context_exit_happened_(false), context_exit_happened_(false),
cpu_profiler_(NULL), cpu_profiler_(NULL),
heap_profiler_(NULL),
deferred_handles_head_(NULL), deferred_handles_head_(NULL),
optimizing_compiler_thread_(this), optimizing_compiler_thread_(this),
marking_thread_(NULL), marking_thread_(NULL),
...@@ -1825,7 +1826,8 @@ void Isolate::Deinit() { ...@@ -1825,7 +1826,8 @@ void Isolate::Deinit() {
preallocated_message_space_ = NULL; preallocated_message_space_ = NULL;
PreallocatedMemoryThreadStop(); PreallocatedMemoryThreadStop();
HeapProfiler::TearDown(); delete heap_profiler_;
heap_profiler_ = NULL;
delete cpu_profiler_; delete cpu_profiler_;
cpu_profiler_ = NULL; cpu_profiler_ = NULL;
...@@ -2058,7 +2060,7 @@ bool Isolate::Init(Deserializer* des) { ...@@ -2058,7 +2060,7 @@ bool Isolate::Init(Deserializer* des) {
logger_->SetUp(); logger_->SetUp();
cpu_profiler_ = new CpuProfiler(this); cpu_profiler_ = new CpuProfiler(this);
HeapProfiler::SetUp(); heap_profiler_ = new HeapProfiler(heap());
// Initialize other runtime facilities // Initialize other runtime facilities
#if defined(USE_SIMULATOR) #if defined(USE_SIMULATOR)
......
...@@ -368,7 +368,6 @@ typedef List<HeapObject*, PreallocatedStorageAllocationPolicy> DebugObjectCache; ...@@ -368,7 +368,6 @@ typedef List<HeapObject*, PreallocatedStorageAllocationPolicy> DebugObjectCache;
V(unsigned, ast_node_count, 0) \ V(unsigned, ast_node_count, 0) \
/* SafeStackFrameIterator activations count. */ \ /* SafeStackFrameIterator activations count. */ \
V(int, safe_stack_iterator_counter, 0) \ V(int, safe_stack_iterator_counter, 0) \
V(HeapProfiler*, heap_profiler, NULL) \
V(bool, observer_delivery_pending, false) \ V(bool, observer_delivery_pending, false) \
V(HStatistics*, hstatistics, NULL) \ V(HStatistics*, hstatistics, NULL) \
V(HTracer*, htracer, NULL) \ V(HTracer*, htracer, NULL) \
...@@ -976,6 +975,7 @@ class Isolate { ...@@ -976,6 +975,7 @@ class Isolate {
inline bool DebuggerHasBreakPoints(); inline bool DebuggerHasBreakPoints();
CpuProfiler* cpu_profiler() const { return cpu_profiler_; } CpuProfiler* cpu_profiler() const { return cpu_profiler_; }
HeapProfiler* heap_profiler() const { return heap_profiler_; }
#ifdef DEBUG #ifdef DEBUG
HistogramInfo* heap_histograms() { return heap_histograms_; } HistogramInfo* heap_histograms() { return heap_histograms_; }
...@@ -1313,6 +1313,7 @@ class Isolate { ...@@ -1313,6 +1313,7 @@ class Isolate {
Debug* debug_; Debug* debug_;
#endif #endif
CpuProfiler* cpu_profiler_; CpuProfiler* cpu_profiler_;
HeapProfiler* heap_profiler_;
#define GLOBAL_BACKING_STORE(type, name, initialvalue) \ #define GLOBAL_BACKING_STORE(type, name, initialvalue) \
type name##_; type name##_;
......
This diff is collapsed.
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