Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/profile-generator.cc

Issue 3531005: Fix HeapSnapshotsDiff test, diff implementation, and a bug introduced (Closed)
Patch Set: Created 10 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/profile-generator.h ('k') | test/cctest/cctest.status » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 934 matching lines...) Expand 10 before | Expand all | Expand 10 after
945 void Apply(HeapEntry* entry) { } 945 void Apply(HeapEntry* entry) { }
946 }; 946 };
947 947
948 void HeapEntry::PaintAllReachable() { 948 void HeapEntry::PaintAllReachable() {
949 NullClass null; 949 NullClass null;
950 ApplyAndPaintAllReachable(&null); 950 ApplyAndPaintAllReachable(&null);
951 } 951 }
952 952
953 953
954 void HeapEntry::Print(int max_depth, int indent) { 954 void HeapEntry::Print(int max_depth, int indent) {
955 OS::Print("%6d %6d %6d [%ld] ", 955 OS::Print("%6d %6d %6d [%llu] ",
956 self_size(), ReachableSize(), RetainedSize(), id_); 956 self_size(), ReachableSize(), RetainedSize(), id_);
957 if (type() != kString) { 957 if (type() != kString) {
958 OS::Print("%s %.40s\n", TypeAsString(), name_); 958 OS::Print("%s %.40s\n", TypeAsString(), name_);
959 } else { 959 } else {
960 OS::Print("\""); 960 OS::Print("\"");
961 const char* c = name_; 961 const char* c = name_;
962 while (*c && (c - name_) <= 40) { 962 while (*c && (c - name_) <= 40) {
963 if (*c != '\n') 963 if (*c != '\n')
964 OS::Print("%c", *c); 964 OS::Print("%c", *c);
965 else 965 else
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
1230 } // namespace 1230 } // namespace
1231 1231
1232 HeapSnapshot::HeapSnapshot(HeapSnapshotsCollection* collection, 1232 HeapSnapshot::HeapSnapshot(HeapSnapshotsCollection* collection,
1233 HeapSnapshot::Type type, 1233 HeapSnapshot::Type type,
1234 const char* title, 1234 const char* title,
1235 unsigned uid) 1235 unsigned uid)
1236 : collection_(collection), 1236 : collection_(collection),
1237 type_(type), 1237 type_(type),
1238 title_(title), 1238 title_(title),
1239 uid_(uid), 1239 uid_(uid),
1240 root_entry_index_(-1), 1240 root_entry_(NULL),
1241 raw_entries_(NULL), 1241 raw_entries_(NULL),
1242 entries_sorted_(false) { 1242 entries_sorted_(false) {
1243 STATIC_ASSERT( 1243 STATIC_ASSERT(
1244 sizeof(HeapGraphEdge) == 1244 sizeof(HeapGraphEdge) ==
1245 SnapshotSizeConstants<sizeof(void*)>::kExpectedHeapGraphEdgeSize); // NOL INT 1245 SnapshotSizeConstants<sizeof(void*)>::kExpectedHeapGraphEdgeSize); // NOL INT
1246 STATIC_ASSERT( 1246 STATIC_ASSERT(
1247 sizeof(HeapEntry) == 1247 sizeof(HeapEntry) ==
1248 SnapshotSizeConstants<sizeof(void*)>::kExpectedHeapEntrySize); // NOLINT 1248 SnapshotSizeConstants<sizeof(void*)>::kExpectedHeapEntrySize); // NOLINT
1249 } 1249 }
1250 1250
(...skipping 18 matching lines...) Expand all
1269 raw_entries_size_ = 1269 raw_entries_size_ =
1270 HeapEntry::EntriesSize(entries_count, children_count, retainers_count); 1270 HeapEntry::EntriesSize(entries_count, children_count, retainers_count);
1271 #endif 1271 #endif
1272 } 1272 }
1273 1273
1274 1274
1275 HeapEntry* HeapSnapshot::AddEntry(HeapObject* object, 1275 HeapEntry* HeapSnapshot::AddEntry(HeapObject* object,
1276 int children_count, 1276 int children_count,
1277 int retainers_count) { 1277 int retainers_count) {
1278 if (object == kInternalRootObject) { 1278 if (object == kInternalRootObject) {
1279 ASSERT(root_entry_index_ == -1); 1279 ASSERT(root_entry_ == NULL);
1280 root_entry_index_ = entries_.length();
1281 ASSERT(retainers_count == 0); 1280 ASSERT(retainers_count == 0);
1282 return AddEntry( 1281 root_entry_ = AddEntry(
1283 HeapEntry::kInternal, "", 0, 0, children_count, retainers_count); 1282 HeapEntry::kInternal, "", 0, 0, children_count, retainers_count);
1283 return root_entry_;
1284 } else if (object->IsJSFunction()) { 1284 } else if (object->IsJSFunction()) {
1285 JSFunction* func = JSFunction::cast(object); 1285 JSFunction* func = JSFunction::cast(object);
1286 SharedFunctionInfo* shared = func->shared(); 1286 SharedFunctionInfo* shared = func->shared();
1287 String* name = String::cast(shared->name())->length() > 0 ? 1287 String* name = String::cast(shared->name())->length() > 0 ?
1288 String::cast(shared->name()) : shared->inferred_name(); 1288 String::cast(shared->name()) : shared->inferred_name();
1289 return AddEntry(object, 1289 return AddEntry(object,
1290 HeapEntry::kClosure, 1290 HeapEntry::kClosure,
1291 collection_->GetFunctionName(name), 1291 collection_->GetFunctionName(name),
1292 children_count, 1292 children_count,
1293 retainers_count); 1293 retainers_count);
(...skipping 794 matching lines...) Expand 10 before | Expand all | Expand 10 after
2088 delete *diff_ptr; 2088 delete *diff_ptr;
2089 } 2089 }
2090 2090
2091 HeapSnapshotsComparator::~HeapSnapshotsComparator() { 2091 HeapSnapshotsComparator::~HeapSnapshotsComparator() {
2092 diffs_.Iterate(DeleteHeapSnapshotsDiff); 2092 diffs_.Iterate(DeleteHeapSnapshotsDiff);
2093 } 2093 }
2094 2094
2095 2095
2096 HeapSnapshotsDiff* HeapSnapshotsComparator::Compare(HeapSnapshot* snapshot1, 2096 HeapSnapshotsDiff* HeapSnapshotsComparator::Compare(HeapSnapshot* snapshot1,
2097 HeapSnapshot* snapshot2) { 2097 HeapSnapshot* snapshot2) {
2098 snapshot1->ClearPaint();
2099 snapshot1->root()->PaintAllReachable();
2100 snapshot2->ClearPaint();
2101 snapshot2->root()->PaintAllReachable();
2102
2098 List<HeapEntry*>* entries1 = snapshot1->GetSortedEntriesList(); 2103 List<HeapEntry*>* entries1 = snapshot1->GetSortedEntriesList();
2099 List<HeapEntry*>* entries2 = snapshot2->GetSortedEntriesList(); 2104 List<HeapEntry*>* entries2 = snapshot2->GetSortedEntriesList();
2100 int i = 0, j = 0; 2105 int i = 0, j = 0;
2101 List<HeapEntry*> added_entries, deleted_entries; 2106 List<HeapEntry*> added_entries, deleted_entries;
2102 while (i < entries1->length() && j < entries2->length()) { 2107 while (i < entries1->length() && j < entries2->length()) {
2103 uint64_t id1 = entries1->at(i)->id(); 2108 uint64_t id1 = entries1->at(i)->id();
2104 uint64_t id2 = entries2->at(j)->id(); 2109 uint64_t id2 = entries2->at(j)->id();
2105 if (id1 == id2) { 2110 if (id1 == id2) {
2106 i++; 2111 HeapEntry* entry1 = entries1->at(i++);
2107 j++; 2112 HeapEntry* entry2 = entries2->at(j++);
2113 if (entry1->painted_reachable() != entry2->painted_reachable()) {
2114 if (entry1->painted_reachable())
2115 deleted_entries.Add(entry1);
2116 else
2117 added_entries.Add(entry2);
2118 }
2108 } else if (id1 < id2) { 2119 } else if (id1 < id2) {
2109 HeapEntry* entry = entries1->at(i++); 2120 HeapEntry* entry = entries1->at(i++);
2110 deleted_entries.Add(entry); 2121 deleted_entries.Add(entry);
2111 } else { 2122 } else {
2112 HeapEntry* entry = entries2->at(j++); 2123 HeapEntry* entry = entries2->at(j++);
2113 added_entries.Add(entry); 2124 added_entries.Add(entry);
2114 } 2125 }
2115 } 2126 }
2116 while (i < entries1->length()) { 2127 while (i < entries1->length()) {
2117 HeapEntry* entry = entries1->at(i++); 2128 HeapEntry* entry = entries1->at(i++);
2118 deleted_entries.Add(entry); 2129 deleted_entries.Add(entry);
2119 } 2130 }
2120 while (j < entries2->length()) { 2131 while (j < entries2->length()) {
2121 HeapEntry* entry = entries2->at(j++); 2132 HeapEntry* entry = entries2->at(j++);
2122 added_entries.Add(entry); 2133 added_entries.Add(entry);
2123 } 2134 }
2124 2135
2125 snapshot1->ClearPaint();
2126 snapshot1->root()->PaintAllReachable();
2127 snapshot2->ClearPaint();
2128 snapshot2->root()->PaintAllReachable();
2129 int reachable_deleted_entries = 0, reachable_added_entries = 0;
2130 for (int i = 0; i < deleted_entries.length(); ++i) {
2131 HeapEntry* entry = deleted_entries[i];
2132 if (entry->painted_reachable()) ++reachable_deleted_entries;
2133 }
2134 for (int i = 0; i < added_entries.length(); ++i) {
2135 HeapEntry* entry = added_entries[i];
2136 if (entry->painted_reachable()) ++reachable_added_entries;
2137 }
2138
2139 HeapSnapshotsDiff* diff = new HeapSnapshotsDiff(snapshot1, snapshot2); 2136 HeapSnapshotsDiff* diff = new HeapSnapshotsDiff(snapshot1, snapshot2);
2140 diffs_.Add(diff); 2137 diffs_.Add(diff);
2141 diff->CreateRoots(reachable_added_entries, reachable_deleted_entries); 2138 diff->CreateRoots(added_entries.length(), deleted_entries.length());
2142 2139
2143 int del_child_index = 0, deleted_entry_index = 1;
2144 for (int i = 0; i < deleted_entries.length(); ++i) { 2140 for (int i = 0; i < deleted_entries.length(); ++i) {
2145 HeapEntry* entry = deleted_entries[i]; 2141 HeapEntry* entry = deleted_entries[i];
2146 if (entry->painted_reachable()) 2142 diff->AddDeletedEntry(i, i + 1, entry);
2147 diff->AddDeletedEntry(del_child_index++, deleted_entry_index++, entry);
2148 } 2143 }
2149 int add_child_index = 0, added_entry_index = 1;
2150 for (int i = 0; i < added_entries.length(); ++i) { 2144 for (int i = 0; i < added_entries.length(); ++i) {
2151 HeapEntry* entry = added_entries[i]; 2145 HeapEntry* entry = added_entries[i];
2152 if (entry->painted_reachable()) 2146 diff->AddAddedEntry(i, i + 1, entry);
2153 diff->AddAddedEntry(add_child_index++, added_entry_index++, entry);
2154 } 2147 }
2155 return diff; 2148 return diff;
2156 } 2149 }
2157 2150
2158 2151
2159 class OutputStreamWriter { 2152 class OutputStreamWriter {
2160 public: 2153 public:
2161 explicit OutputStreamWriter(v8::OutputStream* stream) 2154 explicit OutputStreamWriter(v8::OutputStream* stream)
2162 : stream_(stream), 2155 : stream_(stream),
2163 chunk_size_(stream->GetChunkSize()), 2156 chunk_size_(stream->GetChunkSize()),
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
2502 void HeapSnapshotJSONSerializer::SortHashMap( 2495 void HeapSnapshotJSONSerializer::SortHashMap(
2503 HashMap* map, List<HashMap::Entry*>* sorted_entries) { 2496 HashMap* map, List<HashMap::Entry*>* sorted_entries) {
2504 for (HashMap::Entry* p = map->Start(); p != NULL; p = map->Next(p)) 2497 for (HashMap::Entry* p = map->Start(); p != NULL; p = map->Next(p))
2505 sorted_entries->Add(p); 2498 sorted_entries->Add(p);
2506 sorted_entries->Sort(SortUsingEntryValue); 2499 sorted_entries->Sort(SortUsingEntryValue);
2507 } 2500 }
2508 2501
2509 } } // namespace v8::internal 2502 } } // namespace v8::internal
2510 2503
2511 #endif // ENABLE_LOGGING_AND_PROFILING 2504 #endif // ENABLE_LOGGING_AND_PROFILING
OLDNEW
« no previous file with comments | « src/profile-generator.h ('k') | test/cctest/cctest.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698