Commit 1ce7d5d0 authored by yurys@chromium.org's avatar yurys@chromium.org

Add method for resolving SnapshotObjectId by given object

Review URL: https://chromiumcodereview.appspot.com/10094011

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@11339 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent ab26fb6b
......@@ -412,6 +412,19 @@ class V8EXPORT HeapProfiler {
/** Returns a profile by uid. */
static const HeapSnapshot* FindSnapshot(unsigned uid);
/**
* Returns SnapshotObjectId for a heap object referenced by |value| if
* it has been seen by the heap profiler, kUnknownObjectId otherwise.
*/
static SnapshotObjectId GetSnapshotObjectId(Handle<Value> value);
/**
* A constant for invalid SnapshotObjectId. GetSnapshotObjectId will return
* it in case heap profiler cannot find id for the object passed as
* parameter. HeapSnapshot::GetNodeById will always return NULL for such id.
*/
static const SnapshotObjectId kUnknownObjectId = 0;
/**
* Takes a heap snapshot and returns it. Title may be an empty string.
* See HeapSnapshot::Type for types description.
......
......@@ -6218,6 +6218,14 @@ const HeapSnapshot* HeapProfiler::FindSnapshot(unsigned uid) {
}
SnapshotObjectId HeapProfiler::GetSnapshotObjectId(Handle<Value> value) {
i::Isolate* isolate = i::Isolate::Current();
IsDeadCheck(isolate, "v8::HeapProfiler::GetSnapshotObjectId");
i::Handle<i::Object> obj = Utils::OpenHandle(*value);
return i::HeapProfiler::GetSnapshotObjectId(obj);
}
const HeapSnapshot* HeapProfiler::TakeSnapshot(Handle<String> title,
HeapSnapshot::Type type,
ActivityControl* control) {
......
......@@ -189,6 +189,15 @@ HeapSnapshot* HeapProfiler::FindSnapshot(unsigned uid) {
}
SnapshotObjectId HeapProfiler::GetSnapshotObjectId(Handle<Object> obj) {
if (!obj->IsHeapObject())
return v8::HeapProfiler::kUnknownObjectId;
HeapProfiler* profiler = Isolate::Current()->heap_profiler();
ASSERT(profiler != NULL);
return profiler->snapshots_->FindObjectId(HeapObject::cast(*obj) ->address());
}
void HeapProfiler::DeleteAllSnapshots() {
HeapProfiler* profiler = Isolate::Current()->heap_profiler();
ASSERT(profiler != NULL);
......
......@@ -62,6 +62,7 @@ class HeapProfiler {
static int GetSnapshotsCount();
static HeapSnapshot* GetSnapshot(int index);
static HeapSnapshot* FindSnapshot(unsigned uid);
static SnapshotObjectId GetSnapshotObjectId(Handle<Object> obj);
static void DeleteAllSnapshots();
void ObjectMoveEvent(Address from, Address to);
......
......@@ -1362,7 +1362,6 @@ SnapshotObjectId HeapObjectsMap::FindEntry(Address addr) {
if (entry == NULL) return 0;
int entry_index = static_cast<int>(reinterpret_cast<intptr_t>(entry->value));
EntryInfo& entry_info = entries_->at(entry_index);
entry_info.accessed = true;
ASSERT(static_cast<uint32_t>(entries_->length()) > entries_map_.occupancy());
return entry_info.id;
}
......
......@@ -790,6 +790,9 @@ class HeapSnapshotsCollection {
StringsStorage* names() { return &names_; }
TokenEnumerator* token_enumerator() { return token_enumerator_; }
SnapshotObjectId FindObjectId(Address object_addr) {
return ids_.FindEntry(object_addr);
}
SnapshotObjectId GetObjectId(Address object_addr, int object_size) {
return ids_.FindOrAddEntry(object_addr, object_size);
}
......
......@@ -909,6 +909,42 @@ TEST(HeapSnapshotGetNodeById) {
}
TEST(HeapSnapshotGetSnapshotObjectId) {
v8::HandleScope scope;
LocalContext env;
CompileRun("globalObject = {};\n");
const v8::HeapSnapshot* snapshot =
v8::HeapProfiler::TakeSnapshot(v8_str("get_snapshot_object_id"));
const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
const v8::HeapGraphNode* global_object =
GetProperty(global, v8::HeapGraphEdge::kProperty, "globalObject");
CHECK(global_object);
v8::Local<v8::Value> globalObjectHandle =
env->Global()->Get(v8::String::New("globalObject"));
CHECK(!globalObjectHandle.IsEmpty());
CHECK(globalObjectHandle->IsObject());
v8::SnapshotObjectId id =
v8::HeapProfiler::GetSnapshotObjectId(globalObjectHandle);
CHECK_NE(static_cast<int>(v8::HeapProfiler::kUnknownObjectId),
id);
CHECK_EQ(static_cast<int>(id), global_object->GetId());
}
TEST(HeapSnapshotUnknownSnapshotObjectId) {
v8::HandleScope scope;
LocalContext env;
CompileRun("globalObject = {};\n");
const v8::HeapSnapshot* snapshot =
v8::HeapProfiler::TakeSnapshot(v8_str("unknown_object_id"));
const v8::HeapGraphNode* node =
snapshot->GetNodeById(v8::HeapProfiler::kUnknownObjectId);
CHECK_EQ(NULL, node);
}
namespace {
class TestActivityControl : public v8::ActivityControl {
......
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