Index: test/cctest/test-heap-profiler.cc |
diff --git a/test/cctest/test-heap-profiler.cc b/test/cctest/test-heap-profiler.cc |
index 5c7d9d8f58d2e06432e9a4d2cc2284cd9df5cab1..1f7a9d38eceaab0c61d452f938a8b9808fed1df5 100644 |
--- a/test/cctest/test-heap-profiler.cc |
+++ b/test/cctest/test-heap-profiler.cc |
@@ -1041,6 +1041,48 @@ 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(); |
alph
2013/12/04 08:39:38
Maybe force a GC here to make the objects move.
|
+ |
+ 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->FindHeapObjectById(ids[i]); |
+ CHECK_EQ(objects[i], obj); |
+ } |
+ |
+ heap_profiler->ClearHeapObjectIds(); |
+ 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->FindHeapObjectById(ids[i]); |
+ CHECK(obj.IsEmpty()); |
+ } |
+} |
+ |
+ |
static void CheckChildrenIds(const v8::HeapSnapshot* snapshot, |
const v8::HeapGraphNode* node, |
int level, int max_level) { |