Commit 8b542494 authored by yurys@chromium.org's avatar yurys@chromium.org

Add methods for finding object by its snapshot id and id for an object

Object<-->id mapping doesn't depend on a particular snapshot, actually same object may appear in several heap snapshots. The API for converting between id and heap object should be provided by HeapProfiler itself. There is already GetObjectId method which I extended with FindObjectById/ClearObjectIds. As the next step I'm going to deprecate and remove HeapGraphNode::GetHeapValue.

BUG=chromium:324769
LOG=N
R=alph@chromium.org, hpayer@chromium.org, mstarzinger@chromium.org

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@18334 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 402139f6
...@@ -388,6 +388,19 @@ class V8_EXPORT HeapProfiler { ...@@ -388,6 +388,19 @@ class V8_EXPORT HeapProfiler {
*/ */
SnapshotObjectId GetObjectId(Handle<Value> value); SnapshotObjectId GetObjectId(Handle<Value> value);
/**
* Returns heap object with given SnapshotObjectId if the object is alive,
* otherwise empty handle is returned.
*/
Handle<Value> FindObjectById(SnapshotObjectId id);
/**
* Clears internal map from SnapshotObjectId to heap object. The new objects
* will not be added into it unless a heap snapshot is taken or heap object
* tracking is kicked off.
*/
void ClearObjectIds();
/** /**
* A constant for invalid SnapshotObjectId. GetSnapshotObjectId will return * A constant for invalid SnapshotObjectId. GetSnapshotObjectId will return
* it in case heap profiler cannot find id for the object passed as * it in case heap profiler cannot find id for the object passed as
......
...@@ -7235,6 +7235,19 @@ SnapshotObjectId HeapProfiler::GetObjectId(Handle<Value> value) { ...@@ -7235,6 +7235,19 @@ SnapshotObjectId HeapProfiler::GetObjectId(Handle<Value> value) {
} }
Handle<Value> HeapProfiler::FindObjectById(SnapshotObjectId id) {
i::Handle<i::Object> obj =
reinterpret_cast<i::HeapProfiler*>(this)->FindHeapObjectById(id);
if (obj.is_null()) return Local<Value>();
return Utils::ToLocal(obj);
}
void HeapProfiler::ClearObjectIds() {
reinterpret_cast<i::HeapProfiler*>(this)->ClearHeapObjectMap();
}
const HeapSnapshot* HeapProfiler::TakeHeapSnapshot( const HeapSnapshot* HeapProfiler::TakeHeapSnapshot(
Handle<String> title, Handle<String> title,
ActivityControl* control, ActivityControl* control,
......
...@@ -212,4 +212,10 @@ Handle<HeapObject> HeapProfiler::FindHeapObjectById(SnapshotObjectId id) { ...@@ -212,4 +212,10 @@ Handle<HeapObject> HeapProfiler::FindHeapObjectById(SnapshotObjectId id) {
} }
void HeapProfiler::ClearHeapObjectMap() {
ids_.Reset(new HeapObjectsMap(heap()));
if (!is_tracking_allocations()) is_tracking_object_moves_ = false;
}
} } // namespace v8::internal } } // namespace v8::internal
...@@ -87,6 +87,7 @@ class HeapProfiler { ...@@ -87,6 +87,7 @@ class HeapProfiler {
} }
Handle<HeapObject> FindHeapObjectById(SnapshotObjectId id); Handle<HeapObject> FindHeapObjectById(SnapshotObjectId id);
void ClearHeapObjectMap();
private: private:
Heap* heap() const { return ids_->heap(); } Heap* heap() const { return ids_->heap(); }
......
...@@ -1041,6 +1041,49 @@ TEST(HeapSnapshotObjectsStats) { ...@@ -1041,6 +1041,49 @@ TEST(HeapSnapshotObjectsStats) {
} }
TEST(HeapObjectIds) {
LocalContext env;
v8::Isolate* isolate = env->GetIsolate();
v8::HandleScope scope(isolate);
v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
const int kLength = 10;
v8::Handle<v8::Object> objects[kLength];
v8::SnapshotObjectId ids[kLength];
heap_profiler->StartTrackingHeapObjects(false);
for (int i = 0; i < kLength; i++) {
objects[i] = v8::Object::New(isolate);
}
GetHeapStatsUpdate(heap_profiler);
for (int i = 0; i < kLength; i++) {
v8::SnapshotObjectId id = heap_profiler->GetObjectId(objects[i]);
CHECK_NE(v8::HeapProfiler::kUnknownObjectId, static_cast<int>(id));
ids[i] = id;
}
heap_profiler->StopTrackingHeapObjects();
CcTest::heap()->CollectAllAvailableGarbage();
for (int i = 0; i < kLength; i++) {
v8::SnapshotObjectId id = heap_profiler->GetObjectId(objects[i]);
CHECK_EQ(static_cast<int>(ids[i]), static_cast<int>(id));
v8::Handle<v8::Value> obj = heap_profiler->FindObjectById(ids[i]);
CHECK_EQ(objects[i], obj);
}
heap_profiler->ClearObjectIds();
for (int i = 0; i < kLength; i++) {
v8::SnapshotObjectId id = heap_profiler->GetObjectId(objects[i]);
CHECK_EQ(v8::HeapProfiler::kUnknownObjectId, static_cast<int>(id));
v8::Handle<v8::Value> obj = heap_profiler->FindObjectById(ids[i]);
CHECK(obj.IsEmpty());
}
}
static void CheckChildrenIds(const v8::HeapSnapshot* snapshot, static void CheckChildrenIds(const v8::HeapSnapshot* snapshot,
const v8::HeapGraphNode* node, const v8::HeapGraphNode* node,
int level, int max_level) { int level, int max_level) {
......
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