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

Unified Diff: src/profile-generator.cc

Issue 2808112: Heap profiler: Add static assertions for heap snapshot entities' sizes. (Closed)
Patch Set: Created 10 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/profile-generator.cc
diff --git a/src/profile-generator.cc b/src/profile-generator.cc
index 7653c095697ea04a0af1cb8a4b298abd70a75ba0..cc46606f8f57576536385196560a9db2299c3e63 100644
--- a/src/profile-generator.cc
+++ b/src/profile-generator.cc
@@ -1188,6 +1188,25 @@ void HeapGraphPath::Print() {
HeapObject *const HeapSnapshot::kInternalRootObject =
reinterpret_cast<HeapObject*>(1);
+
+// It is very important to keep objects that form a heap snapshot
+// as small as possible.
+namespace { // Avoid littering the global namespace.
+
+template <size_t ptr_size> struct SnapshotSizeConstants;
+
+template <> struct SnapshotSizeConstants<4> {
+ static const int kExpectedHeapGraphEdgeSize = 12;
+ static const int kExpectedHeapEntrySize = 32;
+};
+
+template <> struct SnapshotSizeConstants<8> {
+ static const int kExpectedHeapGraphEdgeSize = 24;
+ static const int kExpectedHeapEntrySize = 40;
+};
+
+} // namespace
+
HeapSnapshot::HeapSnapshot(HeapSnapshotsCollection* collection,
const char* title,
unsigned uid)
@@ -1197,6 +1216,12 @@ HeapSnapshot::HeapSnapshot(HeapSnapshotsCollection* collection,
root_entry_index_(-1),
raw_entries_(NULL),
entries_sorted_(false) {
+ STATIC_ASSERT(
+ sizeof(HeapGraphEdge) ==
+ SnapshotSizeConstants<sizeof(void*)>::kExpectedHeapGraphEdgeSize);
+ STATIC_ASSERT(
+ sizeof(HeapEntry) ==
+ SnapshotSizeConstants<sizeof(void*)>::kExpectedHeapEntrySize);
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698