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##_;
......
...@@ -129,6 +129,7 @@ static bool HasString(const v8::HeapGraphNode* node, const char* contents) { ...@@ -129,6 +129,7 @@ static bool HasString(const v8::HeapGraphNode* node, const char* contents) {
TEST(HeapSnapshot) { TEST(HeapSnapshot) {
LocalContext env2; LocalContext env2;
v8::HandleScope scope(env2->GetIsolate()); v8::HandleScope scope(env2->GetIsolate());
v8::HeapProfiler* heap_profiler = env2->GetIsolate()->GetHeapProfiler();
CompileRun( CompileRun(
"function A2() {}\n" "function A2() {}\n"
...@@ -138,7 +139,7 @@ TEST(HeapSnapshot) { ...@@ -138,7 +139,7 @@ TEST(HeapSnapshot) {
"var b2_1 = new B2(a2), b2_2 = new B2(a2);\n" "var b2_1 = new B2(a2), b2_2 = new B2(a2);\n"
"var c2 = new C2(a2);"); "var c2 = new C2(a2);");
const v8::HeapSnapshot* snapshot_env2 = const v8::HeapSnapshot* snapshot_env2 =
v8::HeapProfiler::TakeSnapshot(v8_str("env2")); heap_profiler->TakeHeapSnapshot(v8_str("env2"));
const v8::HeapGraphNode* global_env2 = GetGlobalObject(snapshot_env2); const v8::HeapGraphNode* global_env2 = GetGlobalObject(snapshot_env2);
// Verify, that JS global object of env2 has '..2' properties. // Verify, that JS global object of env2 has '..2' properties.
...@@ -163,6 +164,7 @@ TEST(HeapSnapshot) { ...@@ -163,6 +164,7 @@ TEST(HeapSnapshot) {
TEST(HeapSnapshotObjectSizes) { TEST(HeapSnapshotObjectSizes) {
LocalContext env; LocalContext env;
v8::HandleScope scope(env->GetIsolate()); v8::HandleScope scope(env->GetIsolate());
v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
// -a-> X1 --a // -a-> X1 --a
// x -b-> X2 <-| // x -b-> X2 <-|
...@@ -172,7 +174,7 @@ TEST(HeapSnapshotObjectSizes) { ...@@ -172,7 +174,7 @@ TEST(HeapSnapshotObjectSizes) {
"dummy = new X();\n" "dummy = new X();\n"
"(function() { x.a.a = x.b; })();"); "(function() { x.a.a = x.b; })();");
const v8::HeapSnapshot* snapshot = const v8::HeapSnapshot* snapshot =
v8::HeapProfiler::TakeSnapshot(v8_str("sizes")); heap_profiler->TakeHeapSnapshot(v8_str("sizes"));
const v8::HeapGraphNode* global = GetGlobalObject(snapshot); const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
const v8::HeapGraphNode* x = const v8::HeapGraphNode* x =
GetProperty(global, v8::HeapGraphEdge::kProperty, "x"); GetProperty(global, v8::HeapGraphEdge::kProperty, "x");
...@@ -194,12 +196,13 @@ TEST(HeapSnapshotObjectSizes) { ...@@ -194,12 +196,13 @@ TEST(HeapSnapshotObjectSizes) {
TEST(BoundFunctionInSnapshot) { TEST(BoundFunctionInSnapshot) {
LocalContext env; LocalContext env;
v8::HandleScope scope(env->GetIsolate()); v8::HandleScope scope(env->GetIsolate());
v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
CompileRun( CompileRun(
"function myFunction(a, b) { this.a = a; this.b = b; }\n" "function myFunction(a, b) { this.a = a; this.b = b; }\n"
"function AAAAA() {}\n" "function AAAAA() {}\n"
"boundFunction = myFunction.bind(new AAAAA(), 20, new Number(12)); \n"); "boundFunction = myFunction.bind(new AAAAA(), 20, new Number(12)); \n");
const v8::HeapSnapshot* snapshot = const v8::HeapSnapshot* snapshot =
v8::HeapProfiler::TakeSnapshot(v8_str("sizes")); heap_profiler->TakeHeapSnapshot(v8_str("sizes"));
const v8::HeapGraphNode* global = GetGlobalObject(snapshot); const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
const v8::HeapGraphNode* f = const v8::HeapGraphNode* f =
GetProperty(global, v8::HeapGraphEdge::kProperty, "boundFunction"); GetProperty(global, v8::HeapGraphEdge::kProperty, "boundFunction");
...@@ -231,12 +234,13 @@ TEST(BoundFunctionInSnapshot) { ...@@ -231,12 +234,13 @@ TEST(BoundFunctionInSnapshot) {
TEST(HeapSnapshotEntryChildren) { TEST(HeapSnapshotEntryChildren) {
LocalContext env; LocalContext env;
v8::HandleScope scope(env->GetIsolate()); v8::HandleScope scope(env->GetIsolate());
v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
CompileRun( CompileRun(
"function A() { }\n" "function A() { }\n"
"a = new A;"); "a = new A;");
const v8::HeapSnapshot* snapshot = const v8::HeapSnapshot* snapshot =
v8::HeapProfiler::TakeSnapshot(v8_str("children")); heap_profiler->TakeHeapSnapshot(v8_str("children"));
const v8::HeapGraphNode* global = GetGlobalObject(snapshot); const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
for (int i = 0, count = global->GetChildrenCount(); i < count; ++i) { for (int i = 0, count = global->GetChildrenCount(); i < count; ++i) {
const v8::HeapGraphEdge* prop = global->GetChild(i); const v8::HeapGraphEdge* prop = global->GetChild(i);
...@@ -255,6 +259,7 @@ TEST(HeapSnapshotEntryChildren) { ...@@ -255,6 +259,7 @@ TEST(HeapSnapshotEntryChildren) {
TEST(HeapSnapshotCodeObjects) { TEST(HeapSnapshotCodeObjects) {
LocalContext env; LocalContext env;
v8::HandleScope scope(env->GetIsolate()); v8::HandleScope scope(env->GetIsolate());
v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
CompileRun( CompileRun(
"function lazy(x) { return x - 1; }\n" "function lazy(x) { return x - 1; }\n"
...@@ -262,7 +267,7 @@ TEST(HeapSnapshotCodeObjects) { ...@@ -262,7 +267,7 @@ TEST(HeapSnapshotCodeObjects) {
"var anonymous = (function() { return function() { return 0; } })();\n" "var anonymous = (function() { return function() { return 0; } })();\n"
"compiled(1)"); "compiled(1)");
const v8::HeapSnapshot* snapshot = const v8::HeapSnapshot* snapshot =
v8::HeapProfiler::TakeSnapshot(v8_str("code")); heap_profiler->TakeHeapSnapshot(v8_str("code"));
const v8::HeapGraphNode* global = GetGlobalObject(snapshot); const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
const v8::HeapGraphNode* compiled = const v8::HeapGraphNode* compiled =
...@@ -320,11 +325,12 @@ TEST(HeapSnapshotCodeObjects) { ...@@ -320,11 +325,12 @@ TEST(HeapSnapshotCodeObjects) {
TEST(HeapSnapshotHeapNumbers) { TEST(HeapSnapshotHeapNumbers) {
LocalContext env; LocalContext env;
v8::HandleScope scope(env->GetIsolate()); v8::HandleScope scope(env->GetIsolate());
v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
CompileRun( CompileRun(
"a = 1; // a is Smi\n" "a = 1; // a is Smi\n"
"b = 2.5; // b is HeapNumber"); "b = 2.5; // b is HeapNumber");
const v8::HeapSnapshot* snapshot = const v8::HeapSnapshot* snapshot =
v8::HeapProfiler::TakeSnapshot(v8_str("numbers")); heap_profiler->TakeHeapSnapshot(v8_str("numbers"));
const v8::HeapGraphNode* global = GetGlobalObject(snapshot); const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
CHECK_EQ(NULL, GetProperty(global, v8::HeapGraphEdge::kProperty, "a")); CHECK_EQ(NULL, GetProperty(global, v8::HeapGraphEdge::kProperty, "a"));
const v8::HeapGraphNode* b = const v8::HeapGraphNode* b =
...@@ -336,6 +342,7 @@ TEST(HeapSnapshotHeapNumbers) { ...@@ -336,6 +342,7 @@ TEST(HeapSnapshotHeapNumbers) {
TEST(HeapSnapshotSlicedString) { TEST(HeapSnapshotSlicedString) {
LocalContext env; LocalContext env;
v8::HandleScope scope(env->GetIsolate()); v8::HandleScope scope(env->GetIsolate());
v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
CompileRun( CompileRun(
"parent_string = \"123456789.123456789.123456789.123456789.123456789." "parent_string = \"123456789.123456789.123456789.123456789.123456789."
"123456789.123456789.123456789.123456789.123456789." "123456789.123456789.123456789.123456789.123456789."
...@@ -343,7 +350,7 @@ TEST(HeapSnapshotSlicedString) { ...@@ -343,7 +350,7 @@ TEST(HeapSnapshotSlicedString) {
"123456789.123456789.123456789.123456789.123456789.\";" "123456789.123456789.123456789.123456789.123456789.\";"
"child_string = parent_string.slice(100);"); "child_string = parent_string.slice(100);");
const v8::HeapSnapshot* snapshot = const v8::HeapSnapshot* snapshot =
v8::HeapProfiler::TakeSnapshot(v8_str("strings")); heap_profiler->TakeHeapSnapshot(v8_str("strings"));
const v8::HeapGraphNode* global = GetGlobalObject(snapshot); const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
const v8::HeapGraphNode* parent_string = const v8::HeapGraphNode* parent_string =
GetProperty(global, v8::HeapGraphEdge::kProperty, "parent_string"); GetProperty(global, v8::HeapGraphEdge::kProperty, "parent_string");
...@@ -357,7 +364,8 @@ TEST(HeapSnapshotSlicedString) { ...@@ -357,7 +364,8 @@ TEST(HeapSnapshotSlicedString) {
} }
TEST(HeapSnapshotInternalReferences) { TEST(HeapSnapshotInternalReferences) {
v8::HandleScope scope(v8::Isolate::GetCurrent()); v8::Isolate* isolate = v8::Isolate::GetCurrent();
v8::HandleScope scope(isolate);
v8::Local<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); v8::Local<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
global_template->SetInternalFieldCount(2); global_template->SetInternalFieldCount(2);
LocalContext env(NULL, global_template); LocalContext env(NULL, global_template);
...@@ -367,8 +375,9 @@ TEST(HeapSnapshotInternalReferences) { ...@@ -367,8 +375,9 @@ TEST(HeapSnapshotInternalReferences) {
v8::Local<v8::Object> obj = v8::Object::New(); v8::Local<v8::Object> obj = v8::Object::New();
global->SetInternalField(0, v8_num(17)); global->SetInternalField(0, v8_num(17));
global->SetInternalField(1, obj); global->SetInternalField(1, obj);
v8::HeapProfiler* heap_profiler = isolate->GetHeapProfiler();
const v8::HeapSnapshot* snapshot = const v8::HeapSnapshot* snapshot =
v8::HeapProfiler::TakeSnapshot(v8_str("internals")); heap_profiler->TakeHeapSnapshot(v8_str("internals"));
const v8::HeapGraphNode* global_node = GetGlobalObject(snapshot); const v8::HeapGraphNode* global_node = GetGlobalObject(snapshot);
// The first reference will not present, because it's a Smi. // The first reference will not present, because it's a Smi.
CHECK_EQ(NULL, GetProperty(global_node, v8::HeapGraphEdge::kInternal, "0")); CHECK_EQ(NULL, GetProperty(global_node, v8::HeapGraphEdge::kInternal, "0"));
...@@ -388,6 +397,7 @@ TEST(HeapSnapshotInternalReferences) { ...@@ -388,6 +397,7 @@ TEST(HeapSnapshotInternalReferences) {
TEST(HeapSnapshotAddressReuse) { TEST(HeapSnapshotAddressReuse) {
LocalContext env; LocalContext env;
v8::HandleScope scope(env->GetIsolate()); v8::HandleScope scope(env->GetIsolate());
v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
CompileRun( CompileRun(
"function A() {}\n" "function A() {}\n"
...@@ -395,7 +405,7 @@ TEST(HeapSnapshotAddressReuse) { ...@@ -395,7 +405,7 @@ TEST(HeapSnapshotAddressReuse) {
"for (var i = 0; i < 10000; ++i)\n" "for (var i = 0; i < 10000; ++i)\n"
" a[i] = new A();\n"); " a[i] = new A();\n");
const v8::HeapSnapshot* snapshot1 = const v8::HeapSnapshot* snapshot1 =
v8::HeapProfiler::TakeSnapshot(v8_str("snapshot1")); heap_profiler->TakeHeapSnapshot(v8_str("snapshot1"));
v8::SnapshotObjectId maxId1 = snapshot1->GetMaxSnapshotJSObjectId(); v8::SnapshotObjectId maxId1 = snapshot1->GetMaxSnapshotJSObjectId();
CompileRun( CompileRun(
...@@ -404,7 +414,7 @@ TEST(HeapSnapshotAddressReuse) { ...@@ -404,7 +414,7 @@ TEST(HeapSnapshotAddressReuse) {
HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
const v8::HeapSnapshot* snapshot2 = const v8::HeapSnapshot* snapshot2 =
v8::HeapProfiler::TakeSnapshot(v8_str("snapshot2")); heap_profiler->TakeHeapSnapshot(v8_str("snapshot2"));
const v8::HeapGraphNode* global2 = GetGlobalObject(snapshot2); const v8::HeapGraphNode* global2 = GetGlobalObject(snapshot2);
const v8::HeapGraphNode* array_node = const v8::HeapGraphNode* array_node =
...@@ -426,6 +436,7 @@ TEST(HeapSnapshotAddressReuse) { ...@@ -426,6 +436,7 @@ TEST(HeapSnapshotAddressReuse) {
TEST(HeapEntryIdsAndArrayShift) { TEST(HeapEntryIdsAndArrayShift) {
LocalContext env; LocalContext env;
v8::HandleScope scope(env->GetIsolate()); v8::HandleScope scope(env->GetIsolate());
v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
CompileRun( CompileRun(
"function AnObject() {\n" "function AnObject() {\n"
...@@ -436,7 +447,7 @@ TEST(HeapEntryIdsAndArrayShift) { ...@@ -436,7 +447,7 @@ TEST(HeapEntryIdsAndArrayShift) {
"for (var i = 0; i < 10; ++i)\n" "for (var i = 0; i < 10; ++i)\n"
" a.push(new AnObject());\n"); " a.push(new AnObject());\n");
const v8::HeapSnapshot* snapshot1 = const v8::HeapSnapshot* snapshot1 =
v8::HeapProfiler::TakeSnapshot(v8_str("s1")); heap_profiler->TakeHeapSnapshot(v8_str("s1"));
CompileRun( CompileRun(
"for (var i = 0; i < 1; ++i)\n" "for (var i = 0; i < 1; ++i)\n"
...@@ -445,7 +456,7 @@ TEST(HeapEntryIdsAndArrayShift) { ...@@ -445,7 +456,7 @@ TEST(HeapEntryIdsAndArrayShift) {
HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
const v8::HeapSnapshot* snapshot2 = const v8::HeapSnapshot* snapshot2 =
v8::HeapProfiler::TakeSnapshot(v8_str("s2")); heap_profiler->TakeHeapSnapshot(v8_str("s2"));
const v8::HeapGraphNode* global1 = GetGlobalObject(snapshot1); const v8::HeapGraphNode* global1 = GetGlobalObject(snapshot1);
const v8::HeapGraphNode* global2 = GetGlobalObject(snapshot2); const v8::HeapGraphNode* global2 = GetGlobalObject(snapshot2);
...@@ -472,6 +483,7 @@ TEST(HeapEntryIdsAndArrayShift) { ...@@ -472,6 +483,7 @@ TEST(HeapEntryIdsAndArrayShift) {
TEST(HeapEntryIdsAndGC) { TEST(HeapEntryIdsAndGC) {
LocalContext env; LocalContext env;
v8::HandleScope scope(env->GetIsolate()); v8::HandleScope scope(env->GetIsolate());
v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
CompileRun( CompileRun(
"function A() {}\n" "function A() {}\n"
...@@ -481,12 +493,12 @@ TEST(HeapEntryIdsAndGC) { ...@@ -481,12 +493,12 @@ TEST(HeapEntryIdsAndGC) {
v8::Local<v8::String> s1_str = v8_str("s1"); v8::Local<v8::String> s1_str = v8_str("s1");
v8::Local<v8::String> s2_str = v8_str("s2"); v8::Local<v8::String> s2_str = v8_str("s2");
const v8::HeapSnapshot* snapshot1 = const v8::HeapSnapshot* snapshot1 =
v8::HeapProfiler::TakeSnapshot(s1_str); heap_profiler->TakeHeapSnapshot(s1_str);
HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
const v8::HeapSnapshot* snapshot2 = const v8::HeapSnapshot* snapshot2 =
v8::HeapProfiler::TakeSnapshot(s2_str); heap_profiler->TakeHeapSnapshot(s2_str);
CHECK_GT(snapshot1->GetMaxSnapshotJSObjectId(), 7000); CHECK_GT(snapshot1->GetMaxSnapshotJSObjectId(), 7000);
CHECK(snapshot1->GetMaxSnapshotJSObjectId() <= CHECK(snapshot1->GetMaxSnapshotJSObjectId() <=
...@@ -534,8 +546,9 @@ TEST(HeapEntryIdsAndGC) { ...@@ -534,8 +546,9 @@ TEST(HeapEntryIdsAndGC) {
TEST(HeapSnapshotRootPreservedAfterSorting) { TEST(HeapSnapshotRootPreservedAfterSorting) {
LocalContext env; LocalContext env;
v8::HandleScope scope(env->GetIsolate()); v8::HandleScope scope(env->GetIsolate());
v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
const v8::HeapSnapshot* snapshot = const v8::HeapSnapshot* snapshot =
v8::HeapProfiler::TakeSnapshot(v8_str("s")); heap_profiler->TakeHeapSnapshot(v8_str("s"));
const v8::HeapGraphNode* root1 = snapshot->GetRoot(); const v8::HeapGraphNode* root1 = snapshot->GetRoot();
const_cast<i::HeapSnapshot*>(reinterpret_cast<const i::HeapSnapshot*>( const_cast<i::HeapSnapshot*>(reinterpret_cast<const i::HeapSnapshot*>(
snapshot))->GetSortedEntriesList(); snapshot))->GetSortedEntriesList();
...@@ -592,6 +605,7 @@ class AsciiResource: public v8::String::ExternalAsciiStringResource { ...@@ -592,6 +605,7 @@ class AsciiResource: public v8::String::ExternalAsciiStringResource {
TEST(HeapSnapshotJSONSerialization) { TEST(HeapSnapshotJSONSerialization) {
LocalContext env; LocalContext env;
v8::HandleScope scope(env->GetIsolate()); v8::HandleScope scope(env->GetIsolate());
v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
#define STRING_LITERAL_FOR_TEST \ #define STRING_LITERAL_FOR_TEST \
"\"String \\n\\r\\u0008\\u0081\\u0101\\u0801\\u8001\"" "\"String \\n\\r\\u0008\\u0081\\u0101\\u0801\\u8001\""
...@@ -601,7 +615,7 @@ TEST(HeapSnapshotJSONSerialization) { ...@@ -601,7 +615,7 @@ TEST(HeapSnapshotJSONSerialization) {
"var a = new A(" STRING_LITERAL_FOR_TEST ");\n" "var a = new A(" STRING_LITERAL_FOR_TEST ");\n"
"var b = new B(a);"); "var b = new B(a);");
const v8::HeapSnapshot* snapshot = const v8::HeapSnapshot* snapshot =
v8::HeapProfiler::TakeSnapshot(v8_str("json")); heap_profiler->TakeHeapSnapshot(v8_str("json"));
TestJSONStream stream; TestJSONStream stream;
snapshot->Serialize(&stream, v8::HeapSnapshot::kJSON); snapshot->Serialize(&stream, v8::HeapSnapshot::kJSON);
CHECK_GT(stream.size(), 0); CHECK_GT(stream.size(), 0);
...@@ -694,8 +708,9 @@ TEST(HeapSnapshotJSONSerialization) { ...@@ -694,8 +708,9 @@ TEST(HeapSnapshotJSONSerialization) {
TEST(HeapSnapshotJSONSerializationAborting) { TEST(HeapSnapshotJSONSerializationAborting) {
LocalContext env; LocalContext env;
v8::HandleScope scope(env->GetIsolate()); v8::HandleScope scope(env->GetIsolate());
v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
const v8::HeapSnapshot* snapshot = const v8::HeapSnapshot* snapshot =
v8::HeapProfiler::TakeSnapshot(v8_str("abort")); heap_profiler->TakeHeapSnapshot(v8_str("abort"));
TestJSONStream stream(5); TestJSONStream stream(5);
snapshot->Serialize(&stream, v8::HeapSnapshot::kJSON); snapshot->Serialize(&stream, v8::HeapSnapshot::kJSON);
CHECK_GT(stream.size(), 0); CHECK_GT(stream.size(), 0);
...@@ -761,10 +776,10 @@ class TestStatsStream : public v8::OutputStream { ...@@ -761,10 +776,10 @@ class TestStatsStream : public v8::OutputStream {
} // namespace } // namespace
static TestStatsStream GetHeapStatsUpdate( static TestStatsStream GetHeapStatsUpdate(
v8::HeapProfiler* heap_profiler,
v8::SnapshotObjectId* object_id = NULL) { v8::SnapshotObjectId* object_id = NULL) {
TestStatsStream stream; TestStatsStream stream;
v8::SnapshotObjectId last_seen_id = v8::SnapshotObjectId last_seen_id = heap_profiler->GetHeapStats(&stream);
v8::HeapProfiler::PushHeapObjectsStats(&stream);
if (object_id) if (object_id)
*object_id = last_seen_id; *object_id = last_seen_id;
CHECK_EQ(1, stream.eos_signaled()); CHECK_EQ(1, stream.eos_signaled());
...@@ -775,8 +790,9 @@ static TestStatsStream GetHeapStatsUpdate( ...@@ -775,8 +790,9 @@ static TestStatsStream GetHeapStatsUpdate(
TEST(HeapSnapshotObjectsStats) { TEST(HeapSnapshotObjectsStats) {
LocalContext env; LocalContext env;
v8::HandleScope scope(env->GetIsolate()); v8::HandleScope scope(env->GetIsolate());
v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
v8::HeapProfiler::StartHeapObjectsTracking(); heap_profiler->StartTrackingHeapObjects();
// We have to call GC 6 times. In other case the garbage will be // We have to call GC 6 times. In other case the garbage will be
// the reason of flakiness. // the reason of flakiness.
for (int i = 0; i < 6; ++i) { for (int i = 0; i < 6; ++i) {
...@@ -786,7 +802,8 @@ TEST(HeapSnapshotObjectsStats) { ...@@ -786,7 +802,8 @@ TEST(HeapSnapshotObjectsStats) {
v8::SnapshotObjectId initial_id; v8::SnapshotObjectId initial_id;
{ {
// Single chunk of data expected in update. Initial data. // Single chunk of data expected in update. Initial data.
TestStatsStream stats_update = GetHeapStatsUpdate(&initial_id); TestStatsStream stats_update = GetHeapStatsUpdate(heap_profiler,
&initial_id);
CHECK_EQ(1, stats_update.intervals_count()); CHECK_EQ(1, stats_update.intervals_count());
CHECK_EQ(1, stats_update.updates_written()); CHECK_EQ(1, stats_update.updates_written());
CHECK_LT(0, stats_update.entries_size()); CHECK_LT(0, stats_update.entries_size());
...@@ -795,7 +812,7 @@ TEST(HeapSnapshotObjectsStats) { ...@@ -795,7 +812,7 @@ TEST(HeapSnapshotObjectsStats) {
// No data expected in update because nothing has happened. // No data expected in update because nothing has happened.
v8::SnapshotObjectId same_id; v8::SnapshotObjectId same_id;
CHECK_EQ(0, GetHeapStatsUpdate(&same_id).updates_written()); CHECK_EQ(0, GetHeapStatsUpdate(heap_profiler, &same_id).updates_written());
CHECK_EQ_SNAPSHOT_OBJECT_ID(initial_id, same_id); CHECK_EQ_SNAPSHOT_OBJECT_ID(initial_id, same_id);
{ {
...@@ -804,7 +821,8 @@ TEST(HeapSnapshotObjectsStats) { ...@@ -804,7 +821,8 @@ TEST(HeapSnapshotObjectsStats) {
v8_str("string1"); v8_str("string1");
{ {
// Single chunk of data with one new entry expected in update. // Single chunk of data with one new entry expected in update.
TestStatsStream stats_update = GetHeapStatsUpdate(&additional_string_id); TestStatsStream stats_update = GetHeapStatsUpdate(heap_profiler,
&additional_string_id);
CHECK_LT(same_id, additional_string_id); CHECK_LT(same_id, additional_string_id);
CHECK_EQ(1, stats_update.intervals_count()); CHECK_EQ(1, stats_update.intervals_count());
CHECK_EQ(1, stats_update.updates_written()); CHECK_EQ(1, stats_update.updates_written());
...@@ -815,7 +833,7 @@ TEST(HeapSnapshotObjectsStats) { ...@@ -815,7 +833,7 @@ TEST(HeapSnapshotObjectsStats) {
// No data expected in update because nothing happened. // No data expected in update because nothing happened.
v8::SnapshotObjectId last_id; v8::SnapshotObjectId last_id;
CHECK_EQ(0, GetHeapStatsUpdate(&last_id).updates_written()); CHECK_EQ(0, GetHeapStatsUpdate(heap_profiler, &last_id).updates_written());
CHECK_EQ_SNAPSHOT_OBJECT_ID(additional_string_id, last_id); CHECK_EQ_SNAPSHOT_OBJECT_ID(additional_string_id, last_id);
{ {
...@@ -830,7 +848,7 @@ TEST(HeapSnapshotObjectsStats) { ...@@ -830,7 +848,7 @@ TEST(HeapSnapshotObjectsStats) {
{ {
// Single chunk of data with three new entries expected in update. // Single chunk of data with three new entries expected in update.
TestStatsStream stats_update = GetHeapStatsUpdate(); TestStatsStream stats_update = GetHeapStatsUpdate(heap_profiler);
CHECK_EQ(1, stats_update.intervals_count()); CHECK_EQ(1, stats_update.intervals_count());
CHECK_EQ(1, stats_update.updates_written()); CHECK_EQ(1, stats_update.updates_written());
CHECK_LT(0, entries_size = stats_update.entries_size()); CHECK_LT(0, entries_size = stats_update.entries_size());
...@@ -841,7 +859,7 @@ TEST(HeapSnapshotObjectsStats) { ...@@ -841,7 +859,7 @@ TEST(HeapSnapshotObjectsStats) {
{ {
// Single chunk of data with two left entries expected in update. // Single chunk of data with two left entries expected in update.
TestStatsStream stats_update = GetHeapStatsUpdate(); TestStatsStream stats_update = GetHeapStatsUpdate(heap_profiler);
CHECK_EQ(1, stats_update.intervals_count()); CHECK_EQ(1, stats_update.intervals_count());
CHECK_EQ(1, stats_update.updates_written()); CHECK_EQ(1, stats_update.updates_written());
CHECK_GT(entries_size, stats_update.entries_size()); CHECK_GT(entries_size, stats_update.entries_size());
...@@ -853,7 +871,7 @@ TEST(HeapSnapshotObjectsStats) { ...@@ -853,7 +871,7 @@ TEST(HeapSnapshotObjectsStats) {
{ {
// Single chunk of data with 0 left entries expected in update. // Single chunk of data with 0 left entries expected in update.
TestStatsStream stats_update = GetHeapStatsUpdate(); TestStatsStream stats_update = GetHeapStatsUpdate(heap_profiler);
CHECK_EQ(1, stats_update.intervals_count()); CHECK_EQ(1, stats_update.intervals_count());
CHECK_EQ(1, stats_update.updates_written()); CHECK_EQ(1, stats_update.updates_written());
CHECK_EQ(0, stats_update.entries_size()); CHECK_EQ(0, stats_update.entries_size());
...@@ -864,7 +882,7 @@ TEST(HeapSnapshotObjectsStats) { ...@@ -864,7 +882,7 @@ TEST(HeapSnapshotObjectsStats) {
} }
{ {
// Single chunk of data with 0 left entries expected in update. // Single chunk of data with 0 left entries expected in update.
TestStatsStream stats_update = GetHeapStatsUpdate(); TestStatsStream stats_update = GetHeapStatsUpdate(heap_profiler);
CHECK_EQ(1, stats_update.intervals_count()); CHECK_EQ(1, stats_update.intervals_count());
CHECK_EQ(1, stats_update.updates_written()); CHECK_EQ(1, stats_update.updates_written());
CHECK_EQ(0, stats_update.entries_size()); CHECK_EQ(0, stats_update.entries_size());
...@@ -881,7 +899,7 @@ TEST(HeapSnapshotObjectsStats) { ...@@ -881,7 +899,7 @@ TEST(HeapSnapshotObjectsStats) {
uint32_t entries_size; uint32_t entries_size;
{ {
// Single chunk of data with 2 entries expected in update. // Single chunk of data with 2 entries expected in update.
TestStatsStream stats_update = GetHeapStatsUpdate(); TestStatsStream stats_update = GetHeapStatsUpdate(heap_profiler);
CHECK_EQ(1, stats_update.intervals_count()); CHECK_EQ(1, stats_update.intervals_count());
CHECK_EQ(1, stats_update.updates_written()); CHECK_EQ(1, stats_update.updates_written());
CHECK_LT(0, entries_size = stats_update.entries_size()); CHECK_LT(0, entries_size = stats_update.entries_size());
...@@ -895,7 +913,7 @@ TEST(HeapSnapshotObjectsStats) { ...@@ -895,7 +913,7 @@ TEST(HeapSnapshotObjectsStats) {
{ {
// Single chunk of data with 1 entry expected in update. // Single chunk of data with 1 entry expected in update.
TestStatsStream stats_update = GetHeapStatsUpdate(); TestStatsStream stats_update = GetHeapStatsUpdate(heap_profiler);
CHECK_EQ(1, stats_update.intervals_count()); CHECK_EQ(1, stats_update.intervals_count());
// The first interval was changed because old buffer was collected. // The first interval was changed because old buffer was collected.
// The second interval was changed because new buffer was allocated. // The second interval was changed because new buffer was allocated.
...@@ -905,7 +923,7 @@ TEST(HeapSnapshotObjectsStats) { ...@@ -905,7 +923,7 @@ TEST(HeapSnapshotObjectsStats) {
CHECK_EQ(8, stats_update.first_interval_index()); CHECK_EQ(8, stats_update.first_interval_index());
} }
v8::HeapProfiler::StopHeapObjectsTracking(); heap_profiler->StopTrackingHeapObjects();
} }
...@@ -928,9 +946,10 @@ static void CheckChildrenIds(const v8::HeapSnapshot* snapshot, ...@@ -928,9 +946,10 @@ static void CheckChildrenIds(const v8::HeapSnapshot* snapshot,
TEST(HeapSnapshotGetNodeById) { TEST(HeapSnapshotGetNodeById) {
LocalContext env; LocalContext env;
v8::HandleScope scope(env->GetIsolate()); v8::HandleScope scope(env->GetIsolate());
v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
const v8::HeapSnapshot* snapshot = const v8::HeapSnapshot* snapshot =
v8::HeapProfiler::TakeSnapshot(v8_str("id")); heap_profiler->TakeHeapSnapshot(v8_str("id"));
const v8::HeapGraphNode* root = snapshot->GetRoot(); const v8::HeapGraphNode* root = snapshot->GetRoot();
CheckChildrenIds(snapshot, root, 0, 3); CheckChildrenIds(snapshot, root, 0, 3);
// Check a big id, which should not exist yet. // Check a big id, which should not exist yet.
...@@ -941,9 +960,10 @@ TEST(HeapSnapshotGetNodeById) { ...@@ -941,9 +960,10 @@ TEST(HeapSnapshotGetNodeById) {
TEST(HeapSnapshotGetSnapshotObjectId) { TEST(HeapSnapshotGetSnapshotObjectId) {
LocalContext env; LocalContext env;
v8::HandleScope scope(env->GetIsolate()); v8::HandleScope scope(env->GetIsolate());
v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
CompileRun("globalObject = {};\n"); CompileRun("globalObject = {};\n");
const v8::HeapSnapshot* snapshot = const v8::HeapSnapshot* snapshot =
v8::HeapProfiler::TakeSnapshot(v8_str("get_snapshot_object_id")); heap_profiler->TakeHeapSnapshot(v8_str("get_snapshot_object_id"));
const v8::HeapGraphNode* global = GetGlobalObject(snapshot); const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
const v8::HeapGraphNode* global_object = const v8::HeapGraphNode* global_object =
GetProperty(global, v8::HeapGraphEdge::kProperty, "globalObject"); GetProperty(global, v8::HeapGraphEdge::kProperty, "globalObject");
...@@ -954,8 +974,7 @@ TEST(HeapSnapshotGetSnapshotObjectId) { ...@@ -954,8 +974,7 @@ TEST(HeapSnapshotGetSnapshotObjectId) {
CHECK(!globalObjectHandle.IsEmpty()); CHECK(!globalObjectHandle.IsEmpty());
CHECK(globalObjectHandle->IsObject()); CHECK(globalObjectHandle->IsObject());
v8::SnapshotObjectId id = v8::SnapshotObjectId id = heap_profiler->GetObjectId(globalObjectHandle);
v8::HeapProfiler::GetSnapshotObjectId(globalObjectHandle);
CHECK_NE(static_cast<int>(v8::HeapProfiler::kUnknownObjectId), CHECK_NE(static_cast<int>(v8::HeapProfiler::kUnknownObjectId),
id); id);
CHECK_EQ(static_cast<int>(id), global_object->GetId()); CHECK_EQ(static_cast<int>(id), global_object->GetId());
...@@ -965,9 +984,10 @@ TEST(HeapSnapshotGetSnapshotObjectId) { ...@@ -965,9 +984,10 @@ TEST(HeapSnapshotGetSnapshotObjectId) {
TEST(HeapSnapshotUnknownSnapshotObjectId) { TEST(HeapSnapshotUnknownSnapshotObjectId) {
LocalContext env; LocalContext env;
v8::HandleScope scope(env->GetIsolate()); v8::HandleScope scope(env->GetIsolate());
v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
CompileRun("globalObject = {};\n"); CompileRun("globalObject = {};\n");
const v8::HeapSnapshot* snapshot = const v8::HeapSnapshot* snapshot =
v8::HeapProfiler::TakeSnapshot(v8_str("unknown_object_id")); heap_profiler->TakeHeapSnapshot(v8_str("unknown_object_id"));
const v8::HeapGraphNode* node = const v8::HeapGraphNode* node =
snapshot->GetNodeById(v8::HeapProfiler::kUnknownObjectId); snapshot->GetNodeById(v8::HeapProfiler::kUnknownObjectId);
CHECK_EQ(NULL, node); CHECK_EQ(NULL, node);
...@@ -999,23 +1019,22 @@ TEST(TakeHeapSnapshotAborting) { ...@@ -999,23 +1019,22 @@ TEST(TakeHeapSnapshotAborting) {
LocalContext env; LocalContext env;
v8::HandleScope scope(env->GetIsolate()); v8::HandleScope scope(env->GetIsolate());
const int snapshots_count = v8::HeapProfiler::GetSnapshotsCount(); v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
const int snapshots_count = heap_profiler->GetSnapshotCount();
TestActivityControl aborting_control(1); TestActivityControl aborting_control(1);
const v8::HeapSnapshot* no_snapshot = const v8::HeapSnapshot* no_snapshot =
v8::HeapProfiler::TakeSnapshot(v8_str("abort"), heap_profiler->TakeHeapSnapshot(v8_str("abort"),
v8::HeapSnapshot::kFull,
&aborting_control); &aborting_control);
CHECK_EQ(NULL, no_snapshot); CHECK_EQ(NULL, no_snapshot);
CHECK_EQ(snapshots_count, v8::HeapProfiler::GetSnapshotsCount()); CHECK_EQ(snapshots_count, heap_profiler->GetSnapshotCount());
CHECK_GT(aborting_control.total(), aborting_control.done()); CHECK_GT(aborting_control.total(), aborting_control.done());
TestActivityControl control(-1); // Don't abort. TestActivityControl control(-1); // Don't abort.
const v8::HeapSnapshot* snapshot = const v8::HeapSnapshot* snapshot =
v8::HeapProfiler::TakeSnapshot(v8_str("full"), heap_profiler->TakeHeapSnapshot(v8_str("full"),
v8::HeapSnapshot::kFull,
&control); &control);
CHECK_NE(NULL, snapshot); CHECK_NE(NULL, snapshot);
CHECK_EQ(snapshots_count + 1, v8::HeapProfiler::GetSnapshotsCount()); CHECK_EQ(snapshots_count + 1, heap_profiler->GetSnapshotCount());
CHECK_EQ(control.total(), control.done()); CHECK_EQ(control.total(), control.done());
CHECK_GT(control.total(), 0); CHECK_GT(control.total(), 0);
} }
...@@ -1109,10 +1128,11 @@ TEST(HeapSnapshotRetainedObjectInfo) { ...@@ -1109,10 +1128,11 @@ TEST(HeapSnapshotRetainedObjectInfo) {
LocalContext env; LocalContext env;
v8::Isolate* isolate = env->GetIsolate(); v8::Isolate* isolate = env->GetIsolate();
v8::HandleScope scope(isolate); v8::HandleScope scope(isolate);
v8::HeapProfiler* heap_profiler = isolate->GetHeapProfiler();
v8::HeapProfiler::DefineWrapperClass( heap_profiler->SetWrapperClassInfoProvider(
1, TestRetainedObjectInfo::WrapperInfoCallback); 1, TestRetainedObjectInfo::WrapperInfoCallback);
v8::HeapProfiler::DefineWrapperClass( heap_profiler->SetWrapperClassInfoProvider(
2, TestRetainedObjectInfo::WrapperInfoCallback); 2, TestRetainedObjectInfo::WrapperInfoCallback);
v8::Persistent<v8::String> p_AAA = v8::Persistent<v8::String> p_AAA =
v8::Persistent<v8::String>::New(isolate, v8_str("AAA")); v8::Persistent<v8::String>::New(isolate, v8_str("AAA"));
...@@ -1125,7 +1145,7 @@ TEST(HeapSnapshotRetainedObjectInfo) { ...@@ -1125,7 +1145,7 @@ TEST(HeapSnapshotRetainedObjectInfo) {
p_CCC.SetWrapperClassId(isolate, 2); p_CCC.SetWrapperClassId(isolate, 2);
CHECK_EQ(0, TestRetainedObjectInfo::instances.length()); CHECK_EQ(0, TestRetainedObjectInfo::instances.length());
const v8::HeapSnapshot* snapshot = const v8::HeapSnapshot* snapshot =
v8::HeapProfiler::TakeSnapshot(v8_str("retained")); heap_profiler->TakeHeapSnapshot(v8_str("retained"));
CHECK_EQ(3, TestRetainedObjectInfo::instances.length()); CHECK_EQ(3, TestRetainedObjectInfo::instances.length());
for (int i = 0; i < TestRetainedObjectInfo::instances.length(); ++i) { for (int i = 0; i < TestRetainedObjectInfo::instances.length(); ++i) {
...@@ -1205,12 +1225,13 @@ GraphWithImplicitRefs* GraphWithImplicitRefs::instance_ = NULL; ...@@ -1205,12 +1225,13 @@ GraphWithImplicitRefs* GraphWithImplicitRefs::instance_ = NULL;
TEST(HeapSnapshotImplicitReferences) { TEST(HeapSnapshotImplicitReferences) {
LocalContext env; LocalContext env;
v8::HandleScope scope(env->GetIsolate()); v8::HandleScope scope(env->GetIsolate());
v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
GraphWithImplicitRefs graph(&env); GraphWithImplicitRefs graph(&env);
v8::V8::AddGCPrologueCallback(&GraphWithImplicitRefs::gcPrologue); v8::V8::AddGCPrologueCallback(&GraphWithImplicitRefs::gcPrologue);
const v8::HeapSnapshot* snapshot = const v8::HeapSnapshot* snapshot =
v8::HeapProfiler::TakeSnapshot(v8_str("implicit_refs")); heap_profiler->TakeHeapSnapshot(v8_str("implicit_refs"));
const v8::HeapGraphNode* global_object = GetGlobalObject(snapshot); const v8::HeapGraphNode* global_object = GetGlobalObject(snapshot);
const v8::HeapGraphNode* obj0 = GetProperty( const v8::HeapGraphNode* obj0 = GetProperty(
...@@ -1237,58 +1258,60 @@ TEST(HeapSnapshotImplicitReferences) { ...@@ -1237,58 +1258,60 @@ TEST(HeapSnapshotImplicitReferences) {
TEST(DeleteAllHeapSnapshots) { TEST(DeleteAllHeapSnapshots) {
LocalContext env; LocalContext env;
v8::HandleScope scope(env->GetIsolate()); v8::HandleScope scope(env->GetIsolate());
v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
CHECK_EQ(0, v8::HeapProfiler::GetSnapshotsCount());
v8::HeapProfiler::DeleteAllSnapshots(); CHECK_EQ(0, heap_profiler->GetSnapshotCount());
CHECK_EQ(0, v8::HeapProfiler::GetSnapshotsCount()); heap_profiler->DeleteAllHeapSnapshots();
CHECK_NE(NULL, v8::HeapProfiler::TakeSnapshot(v8_str("1"))); CHECK_EQ(0, heap_profiler->GetSnapshotCount());
CHECK_EQ(1, v8::HeapProfiler::GetSnapshotsCount()); CHECK_NE(NULL, heap_profiler->TakeHeapSnapshot(v8_str("1")));
v8::HeapProfiler::DeleteAllSnapshots(); CHECK_EQ(1, heap_profiler->GetSnapshotCount());
CHECK_EQ(0, v8::HeapProfiler::GetSnapshotsCount()); heap_profiler->DeleteAllHeapSnapshots();
CHECK_NE(NULL, v8::HeapProfiler::TakeSnapshot(v8_str("1"))); CHECK_EQ(0, heap_profiler->GetSnapshotCount());
CHECK_NE(NULL, v8::HeapProfiler::TakeSnapshot(v8_str("2"))); CHECK_NE(NULL, heap_profiler->TakeHeapSnapshot(v8_str("1")));
CHECK_EQ(2, v8::HeapProfiler::GetSnapshotsCount()); CHECK_NE(NULL, heap_profiler->TakeHeapSnapshot(v8_str("2")));
v8::HeapProfiler::DeleteAllSnapshots(); CHECK_EQ(2, heap_profiler->GetSnapshotCount());
CHECK_EQ(0, v8::HeapProfiler::GetSnapshotsCount()); heap_profiler->DeleteAllHeapSnapshots();
CHECK_EQ(0, heap_profiler->GetSnapshotCount());
} }
TEST(DeleteHeapSnapshot) { TEST(DeleteHeapSnapshot) {
LocalContext env; LocalContext env;
v8::HandleScope scope(env->GetIsolate()); v8::HandleScope scope(env->GetIsolate());
v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
CHECK_EQ(0, v8::HeapProfiler::GetSnapshotsCount()); CHECK_EQ(0, heap_profiler->GetSnapshotCount());
const v8::HeapSnapshot* s1 = const v8::HeapSnapshot* s1 =
v8::HeapProfiler::TakeSnapshot(v8_str("1")); heap_profiler->TakeHeapSnapshot(v8_str("1"));
CHECK_NE(NULL, s1); CHECK_NE(NULL, s1);
CHECK_EQ(1, v8::HeapProfiler::GetSnapshotsCount()); CHECK_EQ(1, heap_profiler->GetSnapshotCount());
unsigned uid1 = s1->GetUid(); unsigned uid1 = s1->GetUid();
CHECK_EQ(s1, v8::HeapProfiler::FindSnapshot(uid1)); CHECK_EQ(s1, heap_profiler->FindHeapSnapshot(uid1));
const_cast<v8::HeapSnapshot*>(s1)->Delete(); const_cast<v8::HeapSnapshot*>(s1)->Delete();
CHECK_EQ(0, v8::HeapProfiler::GetSnapshotsCount()); CHECK_EQ(0, heap_profiler->GetSnapshotCount());
CHECK_EQ(NULL, v8::HeapProfiler::FindSnapshot(uid1)); CHECK_EQ(NULL, heap_profiler->FindHeapSnapshot(uid1));
const v8::HeapSnapshot* s2 = const v8::HeapSnapshot* s2 =
v8::HeapProfiler::TakeSnapshot(v8_str("2")); heap_profiler->TakeHeapSnapshot(v8_str("2"));
CHECK_NE(NULL, s2); CHECK_NE(NULL, s2);
CHECK_EQ(1, v8::HeapProfiler::GetSnapshotsCount()); CHECK_EQ(1, heap_profiler->GetSnapshotCount());
unsigned uid2 = s2->GetUid(); unsigned uid2 = s2->GetUid();
CHECK_NE(static_cast<int>(uid1), static_cast<int>(uid2)); CHECK_NE(static_cast<int>(uid1), static_cast<int>(uid2));
CHECK_EQ(s2, v8::HeapProfiler::FindSnapshot(uid2)); CHECK_EQ(s2, heap_profiler->FindHeapSnapshot(uid2));
const v8::HeapSnapshot* s3 = const v8::HeapSnapshot* s3 =
v8::HeapProfiler::TakeSnapshot(v8_str("3")); heap_profiler->TakeHeapSnapshot(v8_str("3"));
CHECK_NE(NULL, s3); CHECK_NE(NULL, s3);
CHECK_EQ(2, v8::HeapProfiler::GetSnapshotsCount()); CHECK_EQ(2, heap_profiler->GetSnapshotCount());
unsigned uid3 = s3->GetUid(); unsigned uid3 = s3->GetUid();
CHECK_NE(static_cast<int>(uid1), static_cast<int>(uid3)); CHECK_NE(static_cast<int>(uid1), static_cast<int>(uid3));
CHECK_EQ(s3, v8::HeapProfiler::FindSnapshot(uid3)); CHECK_EQ(s3, heap_profiler->FindHeapSnapshot(uid3));
const_cast<v8::HeapSnapshot*>(s2)->Delete(); const_cast<v8::HeapSnapshot*>(s2)->Delete();
CHECK_EQ(1, v8::HeapProfiler::GetSnapshotsCount()); CHECK_EQ(1, heap_profiler->GetSnapshotCount());
CHECK_EQ(NULL, v8::HeapProfiler::FindSnapshot(uid2)); CHECK_EQ(NULL, heap_profiler->FindHeapSnapshot(uid2));
CHECK_EQ(s3, v8::HeapProfiler::FindSnapshot(uid3)); CHECK_EQ(s3, heap_profiler->FindHeapSnapshot(uid3));
const_cast<v8::HeapSnapshot*>(s3)->Delete(); const_cast<v8::HeapSnapshot*>(s3)->Delete();
CHECK_EQ(0, v8::HeapProfiler::GetSnapshotsCount()); CHECK_EQ(0, heap_profiler->GetSnapshotCount());
CHECK_EQ(NULL, v8::HeapProfiler::FindSnapshot(uid3)); CHECK_EQ(NULL, heap_profiler->FindHeapSnapshot(uid3));
} }
...@@ -1302,13 +1325,13 @@ class NameResolver : public v8::HeapProfiler::ObjectNameResolver { ...@@ -1302,13 +1325,13 @@ class NameResolver : public v8::HeapProfiler::ObjectNameResolver {
TEST(GlobalObjectName) { TEST(GlobalObjectName) {
LocalContext env; LocalContext env;
v8::HandleScope scope(env->GetIsolate()); v8::HandleScope scope(env->GetIsolate());
v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
CompileRun("document = { URL:\"abcdefgh\" };"); CompileRun("document = { URL:\"abcdefgh\" };");
NameResolver name_resolver; NameResolver name_resolver;
const v8::HeapSnapshot* snapshot = const v8::HeapSnapshot* snapshot =
v8::HeapProfiler::TakeSnapshot(v8_str("document"), heap_profiler->TakeHeapSnapshot(v8_str("document"),
v8::HeapSnapshot::kFull,
NULL, NULL,
&name_resolver); &name_resolver);
const v8::HeapGraphNode* global = GetGlobalObject(snapshot); const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
...@@ -1322,13 +1345,14 @@ TEST(GlobalObjectName) { ...@@ -1322,13 +1345,14 @@ TEST(GlobalObjectName) {
TEST(NoHandleLeaks) { TEST(NoHandleLeaks) {
LocalContext env; LocalContext env;
v8::HandleScope scope(env->GetIsolate()); v8::HandleScope scope(env->GetIsolate());
v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
CompileRun("document = { URL:\"abcdefgh\" };"); CompileRun("document = { URL:\"abcdefgh\" };");
v8::Handle<v8::String> name(v8_str("leakz")); v8::Handle<v8::String> name(v8_str("leakz"));
i::Isolate* isolate = i::Isolate::Current(); i::Isolate* isolate = i::Isolate::Current();
int count_before = i::HandleScope::NumberOfHandles(isolate); int count_before = i::HandleScope::NumberOfHandles(isolate);
v8::HeapProfiler::TakeSnapshot(name); heap_profiler->TakeHeapSnapshot(name);
int count_after = i::HandleScope::NumberOfHandles(isolate); int count_after = i::HandleScope::NumberOfHandles(isolate);
CHECK_EQ(count_before, count_after); CHECK_EQ(count_before, count_after);
} }
...@@ -1337,8 +1361,9 @@ TEST(NoHandleLeaks) { ...@@ -1337,8 +1361,9 @@ TEST(NoHandleLeaks) {
TEST(NodesIteration) { TEST(NodesIteration) {
LocalContext env; LocalContext env;
v8::HandleScope scope(env->GetIsolate()); v8::HandleScope scope(env->GetIsolate());
v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
const v8::HeapSnapshot* snapshot = const v8::HeapSnapshot* snapshot =
v8::HeapProfiler::TakeSnapshot(v8_str("iteration")); heap_profiler->TakeHeapSnapshot(v8_str("iteration"));
const v8::HeapGraphNode* global = GetGlobalObject(snapshot); const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
CHECK_NE(NULL, global); CHECK_NE(NULL, global);
// Verify that we can find this object by iteration. // Verify that we can find this object by iteration.
...@@ -1355,10 +1380,11 @@ TEST(NodesIteration) { ...@@ -1355,10 +1380,11 @@ TEST(NodesIteration) {
TEST(GetHeapValue) { TEST(GetHeapValue) {
LocalContext env; LocalContext env;
v8::HandleScope scope(env->GetIsolate()); v8::HandleScope scope(env->GetIsolate());
v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
CompileRun("a = { s_prop: \'value\', n_prop: 0.1 };"); CompileRun("a = { s_prop: \'value\', n_prop: 0.1 };");
const v8::HeapSnapshot* snapshot = const v8::HeapSnapshot* snapshot =
v8::HeapProfiler::TakeSnapshot(v8_str("value")); heap_profiler->TakeHeapSnapshot(v8_str("value"));
const v8::HeapGraphNode* global = GetGlobalObject(snapshot); const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
CHECK(global->GetHeapValue()->IsObject()); CHECK(global->GetHeapValue()->IsObject());
v8::Local<v8::Object> js_global = v8::Local<v8::Object> js_global =
...@@ -1385,13 +1411,14 @@ TEST(GetHeapValue) { ...@@ -1385,13 +1411,14 @@ TEST(GetHeapValue) {
TEST(GetHeapValueForDeletedObject) { TEST(GetHeapValueForDeletedObject) {
LocalContext env; LocalContext env;
v8::HandleScope scope(env->GetIsolate()); v8::HandleScope scope(env->GetIsolate());
v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
// It is impossible to delete a global property, so we are about to delete a // It is impossible to delete a global property, so we are about to delete a
// property of the "a" object. Also, the "p" object can't be an empty one // property of the "a" object. Also, the "p" object can't be an empty one
// because the empty object is static and isn't actually deleted. // because the empty object is static and isn't actually deleted.
CompileRun("a = { p: { r: {} } };"); CompileRun("a = { p: { r: {} } };");
const v8::HeapSnapshot* snapshot = const v8::HeapSnapshot* snapshot =
v8::HeapProfiler::TakeSnapshot(v8_str("snapshot")); heap_profiler->TakeHeapSnapshot(v8_str("snapshot"));
const v8::HeapGraphNode* global = GetGlobalObject(snapshot); const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
const v8::HeapGraphNode* obj = GetProperty( const v8::HeapGraphNode* obj = GetProperty(
global, v8::HeapGraphEdge::kProperty, "a"); global, v8::HeapGraphEdge::kProperty, "a");
...@@ -1467,6 +1494,7 @@ TEST(GetConstructorName) { ...@@ -1467,6 +1494,7 @@ TEST(GetConstructorName) {
TEST(FastCaseGetter) { TEST(FastCaseGetter) {
LocalContext env; LocalContext env;
v8::HandleScope scope(env->GetIsolate()); v8::HandleScope scope(env->GetIsolate());
v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
CompileRun("var obj1 = {};\n" CompileRun("var obj1 = {};\n"
"obj1.__defineGetter__('propWithGetter', function Y() {\n" "obj1.__defineGetter__('propWithGetter', function Y() {\n"
...@@ -1476,7 +1504,7 @@ TEST(FastCaseGetter) { ...@@ -1476,7 +1504,7 @@ TEST(FastCaseGetter) {
" return this.value_ = value;\n" " return this.value_ = value;\n"
"});\n"); "});\n");
const v8::HeapSnapshot* snapshot = const v8::HeapSnapshot* snapshot =
v8::HeapProfiler::TakeSnapshot(v8_str("fastCaseGetter")); heap_profiler->TakeHeapSnapshot(v8_str("fastCaseGetter"));
const v8::HeapGraphNode* global = GetGlobalObject(snapshot); const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
CHECK_NE(NULL, global); CHECK_NE(NULL, global);
...@@ -1494,12 +1522,13 @@ TEST(FastCaseGetter) { ...@@ -1494,12 +1522,13 @@ TEST(FastCaseGetter) {
TEST(HiddenPropertiesFastCase) { TEST(HiddenPropertiesFastCase) {
LocalContext env; LocalContext env;
v8::HandleScope scope(env->GetIsolate()); v8::HandleScope scope(env->GetIsolate());
v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
CompileRun( CompileRun(
"function C(x) { this.a = this; this.b = x; }\n" "function C(x) { this.a = this; this.b = x; }\n"
"c = new C(2012);\n"); "c = new C(2012);\n");
const v8::HeapSnapshot* snapshot = const v8::HeapSnapshot* snapshot =
v8::HeapProfiler::TakeSnapshot(v8_str("HiddenPropertiesFastCase1")); heap_profiler->TakeHeapSnapshot(v8_str("HiddenPropertiesFastCase1"));
const v8::HeapGraphNode* global = GetGlobalObject(snapshot); const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
const v8::HeapGraphNode* c = const v8::HeapGraphNode* c =
GetProperty(global, v8::HeapGraphEdge::kProperty, "c"); GetProperty(global, v8::HeapGraphEdge::kProperty, "c");
...@@ -1512,7 +1541,7 @@ TEST(HiddenPropertiesFastCase) { ...@@ -1512,7 +1541,7 @@ TEST(HiddenPropertiesFastCase) {
CHECK(!cHandle.IsEmpty() && cHandle->IsObject()); CHECK(!cHandle.IsEmpty() && cHandle->IsObject());
cHandle->ToObject()->SetHiddenValue(v8_str("key"), v8_str("val")); cHandle->ToObject()->SetHiddenValue(v8_str("key"), v8_str("val"));
snapshot = v8::HeapProfiler::TakeSnapshot( snapshot = heap_profiler->TakeHeapSnapshot(
v8_str("HiddenPropertiesFastCase2")); v8_str("HiddenPropertiesFastCase2"));
global = GetGlobalObject(snapshot); global = GetGlobalObject(snapshot);
c = GetProperty(global, v8::HeapGraphEdge::kProperty, "c"); c = GetProperty(global, v8::HeapGraphEdge::kProperty, "c");
...@@ -1532,8 +1561,10 @@ bool HasWeakEdge(const v8::HeapGraphNode* node) { ...@@ -1532,8 +1561,10 @@ bool HasWeakEdge(const v8::HeapGraphNode* node) {
bool HasWeakGlobalHandle() { bool HasWeakGlobalHandle() {
v8::Isolate* isolate = v8::Isolate::GetCurrent();
v8::HeapProfiler* heap_profiler = isolate->GetHeapProfiler();
const v8::HeapSnapshot* snapshot = const v8::HeapSnapshot* snapshot =
v8::HeapProfiler::TakeSnapshot(v8_str("weaks")); heap_profiler->TakeHeapSnapshot(v8_str("weaks"));
const v8::HeapGraphNode* gc_roots = GetNode( const v8::HeapGraphNode* gc_roots = GetNode(
snapshot->GetRoot(), v8::HeapGraphNode::kObject, "(GC roots)"); snapshot->GetRoot(), v8::HeapGraphNode::kObject, "(GC roots)");
CHECK_NE(NULL, gc_roots); CHECK_NE(NULL, gc_roots);
...@@ -1568,9 +1599,10 @@ TEST(WeakGlobalHandle) { ...@@ -1568,9 +1599,10 @@ TEST(WeakGlobalHandle) {
TEST(WeakNativeContextRefs) { TEST(WeakNativeContextRefs) {
LocalContext env; LocalContext env;
v8::HandleScope scope(env->GetIsolate()); v8::HandleScope scope(env->GetIsolate());
v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
const v8::HeapSnapshot* snapshot = const v8::HeapSnapshot* snapshot =
v8::HeapProfiler::TakeSnapshot(v8_str("weaks")); heap_profiler->TakeHeapSnapshot(v8_str("weaks"));
const v8::HeapGraphNode* gc_roots = GetNode( const v8::HeapGraphNode* gc_roots = GetNode(
snapshot->GetRoot(), v8::HeapGraphNode::kObject, "(GC roots)"); snapshot->GetRoot(), v8::HeapGraphNode::kObject, "(GC roots)");
CHECK_NE(NULL, gc_roots); CHECK_NE(NULL, gc_roots);
...@@ -1587,11 +1619,12 @@ TEST(WeakNativeContextRefs) { ...@@ -1587,11 +1619,12 @@ TEST(WeakNativeContextRefs) {
TEST(SfiAndJsFunctionWeakRefs) { TEST(SfiAndJsFunctionWeakRefs) {
LocalContext env; LocalContext env;
v8::HandleScope scope(env->GetIsolate()); v8::HandleScope scope(env->GetIsolate());
v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
CompileRun( CompileRun(
"fun = (function (x) { return function () { return x + 1; } })(1);"); "fun = (function (x) { return function () { return x + 1; } })(1);");
const v8::HeapSnapshot* snapshot = const v8::HeapSnapshot* snapshot =
v8::HeapProfiler::TakeSnapshot(v8_str("fun")); heap_profiler->TakeHeapSnapshot(v8_str("fun"));
const v8::HeapGraphNode* global = GetGlobalObject(snapshot); const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
CHECK_NE(NULL, global); CHECK_NE(NULL, global);
const v8::HeapGraphNode* fun = const v8::HeapGraphNode* fun =
...@@ -1607,11 +1640,12 @@ TEST(SfiAndJsFunctionWeakRefs) { ...@@ -1607,11 +1640,12 @@ TEST(SfiAndJsFunctionWeakRefs) {
TEST(NoDebugObjectInSnapshot) { TEST(NoDebugObjectInSnapshot) {
LocalContext env; LocalContext env;
v8::HandleScope scope(env->GetIsolate()); v8::HandleScope scope(env->GetIsolate());
v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
v8::internal::Isolate::Current()->debug()->Load(); v8::internal::Isolate::Current()->debug()->Load();
CompileRun("foo = {};"); CompileRun("foo = {};");
const v8::HeapSnapshot* snapshot = const v8::HeapSnapshot* snapshot =
v8::HeapProfiler::TakeSnapshot(v8_str("snapshot")); heap_profiler->TakeHeapSnapshot(v8_str("snapshot"));
const v8::HeapGraphNode* root = snapshot->GetRoot(); const v8::HeapGraphNode* root = snapshot->GetRoot();
int globals_count = 0; int globals_count = 0;
for (int i = 0; i < root->GetChildrenCount(); ++i) { for (int i = 0; i < root->GetChildrenCount(); ++i) {
...@@ -1667,10 +1701,11 @@ TEST(PersistentHandleCount) { ...@@ -1667,10 +1701,11 @@ TEST(PersistentHandleCount) {
TEST(AllStrongGcRootsHaveNames) { TEST(AllStrongGcRootsHaveNames) {
LocalContext env; LocalContext env;
v8::HandleScope scope(env->GetIsolate()); v8::HandleScope scope(env->GetIsolate());
v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
CompileRun("foo = {};"); CompileRun("foo = {};");
const v8::HeapSnapshot* snapshot = const v8::HeapSnapshot* snapshot =
v8::HeapProfiler::TakeSnapshot(v8_str("snapshot")); heap_profiler->TakeHeapSnapshot(v8_str("snapshot"));
const v8::HeapGraphNode* gc_roots = GetNode( const v8::HeapGraphNode* gc_roots = GetNode(
snapshot->GetRoot(), v8::HeapGraphNode::kObject, "(GC roots)"); snapshot->GetRoot(), v8::HeapGraphNode::kObject, "(GC roots)");
CHECK_NE(NULL, gc_roots); CHECK_NE(NULL, gc_roots);
...@@ -1689,9 +1724,10 @@ TEST(AllStrongGcRootsHaveNames) { ...@@ -1689,9 +1724,10 @@ TEST(AllStrongGcRootsHaveNames) {
TEST(NoRefsToNonEssentialEntries) { TEST(NoRefsToNonEssentialEntries) {
LocalContext env; LocalContext env;
v8::HandleScope scope(env->GetIsolate()); v8::HandleScope scope(env->GetIsolate());
v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
CompileRun("global_object = {};\n"); CompileRun("global_object = {};\n");
const v8::HeapSnapshot* snapshot = const v8::HeapSnapshot* snapshot =
v8::HeapProfiler::TakeSnapshot(v8_str("snapshot")); heap_profiler->TakeHeapSnapshot(v8_str("snapshot"));
const v8::HeapGraphNode* global = GetGlobalObject(snapshot); const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
const v8::HeapGraphNode* global_object = const v8::HeapGraphNode* global_object =
GetProperty(global, v8::HeapGraphEdge::kProperty, "global_object"); GetProperty(global, v8::HeapGraphEdge::kProperty, "global_object");
...@@ -1708,9 +1744,10 @@ TEST(NoRefsToNonEssentialEntries) { ...@@ -1708,9 +1744,10 @@ TEST(NoRefsToNonEssentialEntries) {
TEST(MapHasDescriptorsAndTransitions) { TEST(MapHasDescriptorsAndTransitions) {
LocalContext env; LocalContext env;
v8::HandleScope scope(env->GetIsolate()); v8::HandleScope scope(env->GetIsolate());
v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
CompileRun("obj = { a: 10 };\n"); CompileRun("obj = { a: 10 };\n");
const v8::HeapSnapshot* snapshot = const v8::HeapSnapshot* snapshot =
v8::HeapProfiler::TakeSnapshot(v8_str("snapshot")); heap_profiler->TakeHeapSnapshot(v8_str("snapshot"));
const v8::HeapGraphNode* global = GetGlobalObject(snapshot); const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
const v8::HeapGraphNode* global_object = const v8::HeapGraphNode* global_object =
GetProperty(global, v8::HeapGraphEdge::kProperty, "obj"); GetProperty(global, v8::HeapGraphEdge::kProperty, "obj");
...@@ -1729,8 +1766,9 @@ TEST(MapHasDescriptorsAndTransitions) { ...@@ -1729,8 +1766,9 @@ TEST(MapHasDescriptorsAndTransitions) {
TEST(ManyLocalsInSharedContext) { TEST(ManyLocalsInSharedContext) {
v8::HandleScope scope;
LocalContext env; LocalContext env;
v8::HandleScope scope(env->GetIsolate());
v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
int num_objects = 6000; int num_objects = 6000;
CompileRun( CompileRun(
"var n = 6000;" "var n = 6000;"
...@@ -1747,7 +1785,7 @@ TEST(ManyLocalsInSharedContext) { ...@@ -1747,7 +1785,7 @@ TEST(ManyLocalsInSharedContext) {
"result.push('})()');" "result.push('})()');"
"var ok = eval(result.join('\\n'));"); "var ok = eval(result.join('\\n'));");
const v8::HeapSnapshot* snapshot = const v8::HeapSnapshot* snapshot =
v8::HeapProfiler::TakeSnapshot(v8_str("snapshot")); heap_profiler->TakeHeapSnapshot(v8_str("snapshot"));
const v8::HeapGraphNode* global = GetGlobalObject(snapshot); const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
CHECK_NE(NULL, global); CHECK_NE(NULL, global);
const v8::HeapGraphNode* ok_object = const v8::HeapGraphNode* ok_object =
......
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