diff --git a/src/profile-generator.cc b/src/profile-generator.cc index acab8a092f..2315fc5388 100644 --- a/src/profile-generator.cc +++ b/src/profile-generator.cc @@ -1158,6 +1158,11 @@ void HeapSnapshot::Delete() { } +void HeapSnapshot::RememberLastJSObjectId() { + max_snapshot_js_object_id_ = collection_->last_assigned_id(); +} + + void HeapSnapshot::AllocateEntries(int entries_count, int children_count, int retainers_count) { @@ -1224,11 +1229,6 @@ HeapEntry* HeapSnapshot::AddEntry(HeapEntry::Type type, int retainers_count) { HeapEntry* entry = GetNextEntryToInit(); entry->Init(this, type, name, id, size, children_count, retainers_count); - - // Track only js objects. They have odd ids. - if (id % HeapObjectsMap::kObjectIdStep && id > max_snapshot_js_object_id_) - max_snapshot_js_object_id_ = id; - return entry; } @@ -3111,6 +3111,8 @@ bool HeapSnapshotGenerator::GenerateSnapshot() { // Pass 2. Fill references. if (!FillReferences()) return false; + snapshot_->RememberLastJSObjectId(); + if (!SetEntriesDominators()) return false; if (!CalculateRetainedSizes()) return false; diff --git a/src/profile-generator.h b/src/profile-generator.h index 8010538cc9..b9de69bce3 100644 --- a/src/profile-generator.h +++ b/src/profile-generator.h @@ -645,6 +645,7 @@ class HeapSnapshot { HeapEntry* gc_subroot(int index) { return gc_subroot_entries_[index]; } List* entries() { return &entries_; } size_t raw_entries_size() { return raw_entries_size_; } + void RememberLastJSObjectId(); SnapshotObjectId max_snapshot_js_object_id() const { return max_snapshot_js_object_id_; } @@ -704,6 +705,9 @@ class HeapObjectsMap { void SnapshotGenerationFinished(); SnapshotObjectId FindObject(Address addr); void MoveObject(Address from, Address to); + SnapshotObjectId last_assigned_id() const { + return next_id_ - kObjectIdStep; + } static SnapshotObjectId GenerateId(v8::RetainedObjectInfo* info); static inline SnapshotObjectId GetNthGcSubrootId(int delta); @@ -768,6 +772,9 @@ class HeapSnapshotsCollection { SnapshotObjectId GetObjectId(Address addr) { return ids_.FindObject(addr); } Handle FindHeapObjectById(SnapshotObjectId id); void ObjectMoveEvent(Address from, Address to) { ids_.MoveObject(from, to); } + SnapshotObjectId last_assigned_id() const { + return ids_.last_assigned_id(); + } private: INLINE(static bool HeapSnapshotsMatch(void* key1, void* key2)) { diff --git a/test/cctest/test-heap-profiler.cc b/test/cctest/test-heap-profiler.cc index d6adfea3dd..44cd6094f3 100644 --- a/test/cctest/test-heap-profiler.cc +++ b/test/cctest/test-heap-profiler.cc @@ -424,12 +424,9 @@ TEST(HeapEntryIdsAndGC) { const v8::HeapSnapshot* snapshot2 = v8::HeapProfiler::TakeSnapshot(s2_str); - // Second snapshot has one more string, it is it's name 's2'. - CHECK( - snapshot1->GetMaxSnapshotJSObjectId() <= - snapshot2->GetMaxSnapshotJSObjectId() && - snapshot2->GetMaxSnapshotJSObjectId() <= - snapshot1->GetMaxSnapshotJSObjectId() + i::HeapObjectsMap::kObjectIdStep); + CHECK(snapshot1->GetMaxSnapshotJSObjectId() > 7000); + CHECK(snapshot1->GetMaxSnapshotJSObjectId() <= + snapshot2->GetMaxSnapshotJSObjectId()); const v8::HeapGraphNode* global1 = GetGlobalObject(snapshot1); const v8::HeapGraphNode* global2 = GetGlobalObject(snapshot2);