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

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

Issue 9617006: Replace uint64_t type with ObjectId and use uint32_t as the base for ObjectId type. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Alexey's comment addressed. I've landed a patch for GetHash functuion. http://trac.webkit.org/chang… Created 8 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « src/profile-generator.h ('k') | src/profile-generator-inl.h » ('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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 947 matching lines...) Expand 10 before | Expand all | Expand 10 after
958 958
959 959
960 HeapEntry* HeapGraphEdge::From() { 960 HeapEntry* HeapGraphEdge::From() {
961 return reinterpret_cast<HeapEntry*>(this - child_index_) - 1; 961 return reinterpret_cast<HeapEntry*>(this - child_index_) - 1;
962 } 962 }
963 963
964 964
965 void HeapEntry::Init(HeapSnapshot* snapshot, 965 void HeapEntry::Init(HeapSnapshot* snapshot,
966 Type type, 966 Type type,
967 const char* name, 967 const char* name,
968 uint64_t id, 968 SnapshotObjectId id,
969 int self_size, 969 int self_size,
970 int children_count, 970 int children_count,
971 int retainers_count) { 971 int retainers_count) {
972 snapshot_ = snapshot; 972 snapshot_ = snapshot;
973 type_ = type; 973 type_ = type;
974 painted_ = false; 974 painted_ = false;
975 name_ = name; 975 name_ = name;
976 self_size_ = self_size; 976 self_size_ = self_size;
977 retained_size_ = 0; 977 retained_size_ = 0;
978 children_count_ = children_count; 978 children_count_ = children_count;
979 retainers_count_ = retainers_count; 979 retainers_count_ = retainers_count;
980 dominator_ = NULL; 980 dominator_ = NULL;
981 981
982 union { 982 union {
983 uint64_t set_id; 983 SnapshotObjectId set_id;
984 Id stored_id; 984 Id stored_id;
985 } id_adaptor = {id}; 985 } id_adaptor = {id};
986 id_ = id_adaptor.stored_id; 986 id_ = id_adaptor.stored_id;
987 } 987 }
988 988
989 989
990 void HeapEntry::SetNamedReference(HeapGraphEdge::Type type, 990 void HeapEntry::SetNamedReference(HeapGraphEdge::Type type,
991 int child_index, 991 int child_index,
992 const char* name, 992 const char* name,
993 HeapEntry* entry, 993 HeapEntry* entry,
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
1214 VisitorSynchronization::kTagNames[tag], 1214 VisitorSynchronization::kTagNames[tag],
1215 HeapObjectsMap::GetNthGcSubrootId(tag), 1215 HeapObjectsMap::GetNthGcSubrootId(tag),
1216 0, 1216 0,
1217 children_count, 1217 children_count,
1218 retainers_count)); 1218 retainers_count));
1219 } 1219 }
1220 1220
1221 1221
1222 HeapEntry* HeapSnapshot::AddEntry(HeapEntry::Type type, 1222 HeapEntry* HeapSnapshot::AddEntry(HeapEntry::Type type,
1223 const char* name, 1223 const char* name,
1224 uint64_t id, 1224 SnapshotObjectId id,
1225 int size, 1225 int size,
1226 int children_count, 1226 int children_count,
1227 int retainers_count) { 1227 int retainers_count) {
1228 HeapEntry* entry = GetNextEntryToInit(); 1228 HeapEntry* entry = GetNextEntryToInit();
1229 entry->Init(this, type, name, id, size, children_count, retainers_count); 1229 entry->Init(this, type, name, id, size, children_count, retainers_count);
1230 return entry; 1230 return entry;
1231 } 1231 }
1232 1232
1233 1233
1234 void HeapSnapshot::SetDominatorsToSelf() { 1234 void HeapSnapshot::SetDominatorsToSelf() {
(...skipping 11 matching lines...) Expand all
1246 reinterpret_cast<char*>(last_entry) + last_entry->EntrySize())); 1246 reinterpret_cast<char*>(last_entry) + last_entry->EntrySize()));
1247 } else { 1247 } else {
1248 entries_.Add(reinterpret_cast<HeapEntry*>(raw_entries_)); 1248 entries_.Add(reinterpret_cast<HeapEntry*>(raw_entries_));
1249 } 1249 }
1250 ASSERT(reinterpret_cast<char*>(entries_.last()) < 1250 ASSERT(reinterpret_cast<char*>(entries_.last()) <
1251 (raw_entries_ + raw_entries_size_)); 1251 (raw_entries_ + raw_entries_size_));
1252 return entries_.last(); 1252 return entries_.last();
1253 } 1253 }
1254 1254
1255 1255
1256 HeapEntry* HeapSnapshot::GetEntryById(uint64_t id) { 1256 HeapEntry* HeapSnapshot::GetEntryById(SnapshotObjectId id) {
1257 List<HeapEntry*>* entries_by_id = GetSortedEntriesList(); 1257 List<HeapEntry*>* entries_by_id = GetSortedEntriesList();
1258 1258
1259 // Perform a binary search by id. 1259 // Perform a binary search by id.
1260 int low = 0; 1260 int low = 0;
1261 int high = entries_by_id->length() - 1; 1261 int high = entries_by_id->length() - 1;
1262 while (low <= high) { 1262 while (low <= high) {
1263 int mid = 1263 int mid =
1264 (static_cast<unsigned int>(low) + static_cast<unsigned int>(high)) >> 1; 1264 (static_cast<unsigned int>(low) + static_cast<unsigned int>(high)) >> 1;
1265 uint64_t mid_id = entries_by_id->at(mid)->id(); 1265 SnapshotObjectId mid_id = entries_by_id->at(mid)->id();
1266 if (mid_id > id) 1266 if (mid_id > id)
1267 high = mid - 1; 1267 high = mid - 1;
1268 else if (mid_id < id) 1268 else if (mid_id < id)
1269 low = mid + 1; 1269 low = mid + 1;
1270 else 1270 else
1271 return entries_by_id->at(mid); 1271 return entries_by_id->at(mid);
1272 } 1272 }
1273 return NULL; 1273 return NULL;
1274 } 1274 }
1275 1275
(...skipping 15 matching lines...) Expand all
1291 } 1291 }
1292 1292
1293 1293
1294 void HeapSnapshot::Print(int max_depth) { 1294 void HeapSnapshot::Print(int max_depth) {
1295 root()->Print("", "", max_depth, 0); 1295 root()->Print("", "", max_depth, 0);
1296 } 1296 }
1297 1297
1298 1298
1299 // We split IDs on evens for embedder objects (see 1299 // We split IDs on evens for embedder objects (see
1300 // HeapObjectsMap::GenerateId) and odds for native objects. 1300 // HeapObjectsMap::GenerateId) and odds for native objects.
1301 const uint64_t HeapObjectsMap::kInternalRootObjectId = 1; 1301 const SnapshotObjectId HeapObjectsMap::kInternalRootObjectId = 1;
1302 const uint64_t HeapObjectsMap::kGcRootsObjectId = 1302 const SnapshotObjectId HeapObjectsMap::kGcRootsObjectId =
1303 HeapObjectsMap::kInternalRootObjectId + HeapObjectsMap::kObjectIdStep; 1303 HeapObjectsMap::kInternalRootObjectId + HeapObjectsMap::kObjectIdStep;
1304 const uint64_t HeapObjectsMap::kGcRootsFirstSubrootId = 1304 const SnapshotObjectId HeapObjectsMap::kGcRootsFirstSubrootId =
1305 HeapObjectsMap::kGcRootsObjectId + HeapObjectsMap::kObjectIdStep; 1305 HeapObjectsMap::kGcRootsObjectId + HeapObjectsMap::kObjectIdStep;
1306 const uint64_t HeapObjectsMap::kFirstAvailableObjectId = 1306 const SnapshotObjectId HeapObjectsMap::kFirstAvailableObjectId =
1307 HeapObjectsMap::kGcRootsFirstSubrootId + 1307 HeapObjectsMap::kGcRootsFirstSubrootId +
1308 VisitorSynchronization::kNumberOfSyncTags * HeapObjectsMap::kObjectIdStep; 1308 VisitorSynchronization::kNumberOfSyncTags * HeapObjectsMap::kObjectIdStep;
1309 1309
1310 HeapObjectsMap::HeapObjectsMap() 1310 HeapObjectsMap::HeapObjectsMap()
1311 : initial_fill_mode_(true), 1311 : initial_fill_mode_(true),
1312 next_id_(kFirstAvailableObjectId), 1312 next_id_(kFirstAvailableObjectId),
1313 entries_map_(AddressesMatch), 1313 entries_map_(AddressesMatch),
1314 entries_(new List<EntryInfo>()) { } 1314 entries_(new List<EntryInfo>()) { }
1315 1315
1316 1316
1317 HeapObjectsMap::~HeapObjectsMap() { 1317 HeapObjectsMap::~HeapObjectsMap() {
1318 delete entries_; 1318 delete entries_;
1319 } 1319 }
1320 1320
1321 1321
1322 void HeapObjectsMap::SnapshotGenerationFinished() { 1322 void HeapObjectsMap::SnapshotGenerationFinished() {
1323 initial_fill_mode_ = false; 1323 initial_fill_mode_ = false;
1324 RemoveDeadEntries(); 1324 RemoveDeadEntries();
1325 } 1325 }
1326 1326
1327 1327
1328 uint64_t HeapObjectsMap::FindObject(Address addr) { 1328 SnapshotObjectId HeapObjectsMap::FindObject(Address addr) {
1329 if (!initial_fill_mode_) { 1329 if (!initial_fill_mode_) {
1330 uint64_t existing = FindEntry(addr); 1330 SnapshotObjectId existing = FindEntry(addr);
1331 if (existing != 0) return existing; 1331 if (existing != 0) return existing;
1332 } 1332 }
1333 uint64_t id = next_id_; 1333 SnapshotObjectId id = next_id_;
1334 next_id_ += kObjectIdStep; 1334 next_id_ += kObjectIdStep;
1335 AddEntry(addr, id); 1335 AddEntry(addr, id);
1336 return id; 1336 return id;
1337 } 1337 }
1338 1338
1339 1339
1340 void HeapObjectsMap::MoveObject(Address from, Address to) { 1340 void HeapObjectsMap::MoveObject(Address from, Address to) {
1341 if (from == to) return; 1341 if (from == to) return;
1342 HashMap::Entry* entry = entries_map_.Lookup(from, AddressHash(from), false); 1342 HashMap::Entry* entry = entries_map_.Lookup(from, AddressHash(from), false);
1343 if (entry != NULL) { 1343 if (entry != NULL) {
1344 void* value = entry->value; 1344 void* value = entry->value;
1345 entries_map_.Remove(from, AddressHash(from)); 1345 entries_map_.Remove(from, AddressHash(from));
1346 if (to != NULL) { 1346 if (to != NULL) {
1347 entry = entries_map_.Lookup(to, AddressHash(to), true); 1347 entry = entries_map_.Lookup(to, AddressHash(to), true);
1348 // We can have an entry at the new location, it is OK, as GC can overwrite 1348 // We can have an entry at the new location, it is OK, as GC can overwrite
1349 // dead objects with alive objects being moved. 1349 // dead objects with alive objects being moved.
1350 entry->value = value; 1350 entry->value = value;
1351 } 1351 }
1352 } 1352 }
1353 } 1353 }
1354 1354
1355 1355
1356 void HeapObjectsMap::AddEntry(Address addr, uint64_t id) { 1356 void HeapObjectsMap::AddEntry(Address addr, SnapshotObjectId id) {
1357 HashMap::Entry* entry = entries_map_.Lookup(addr, AddressHash(addr), true); 1357 HashMap::Entry* entry = entries_map_.Lookup(addr, AddressHash(addr), true);
1358 ASSERT(entry->value == NULL); 1358 ASSERT(entry->value == NULL);
1359 entry->value = reinterpret_cast<void*>(entries_->length()); 1359 entry->value = reinterpret_cast<void*>(entries_->length());
1360 entries_->Add(EntryInfo(id)); 1360 entries_->Add(EntryInfo(id));
1361 } 1361 }
1362 1362
1363 1363
1364 uint64_t HeapObjectsMap::FindEntry(Address addr) { 1364 SnapshotObjectId HeapObjectsMap::FindEntry(Address addr) {
1365 HashMap::Entry* entry = entries_map_.Lookup(addr, AddressHash(addr), false); 1365 HashMap::Entry* entry = entries_map_.Lookup(addr, AddressHash(addr), false);
1366 if (entry != NULL) { 1366 if (entry != NULL) {
1367 int entry_index = 1367 int entry_index =
1368 static_cast<int>(reinterpret_cast<intptr_t>(entry->value)); 1368 static_cast<int>(reinterpret_cast<intptr_t>(entry->value));
1369 EntryInfo& entry_info = entries_->at(entry_index); 1369 EntryInfo& entry_info = entries_->at(entry_index);
1370 entry_info.accessed = true; 1370 entry_info.accessed = true;
1371 return entry_info.id; 1371 return entry_info.id;
1372 } else { 1372 } else {
1373 return 0; 1373 return 0;
1374 } 1374 }
(...skipping 19 matching lines...) Expand all
1394 for (int i = 0; i < dead_entries.length(); ++i) { 1394 for (int i = 0; i < dead_entries.length(); ++i) {
1395 void* raw_entry = dead_entries[i]; 1395 void* raw_entry = dead_entries[i];
1396 entries_map_.Remove( 1396 entries_map_.Remove(
1397 raw_entry, AddressHash(reinterpret_cast<Address>(raw_entry))); 1397 raw_entry, AddressHash(reinterpret_cast<Address>(raw_entry)));
1398 } 1398 }
1399 delete entries_; 1399 delete entries_;
1400 entries_ = new_entries; 1400 entries_ = new_entries;
1401 } 1401 }
1402 1402
1403 1403
1404 uint64_t HeapObjectsMap::GenerateId(v8::RetainedObjectInfo* info) { 1404 SnapshotObjectId HeapObjectsMap::GenerateId(v8::RetainedObjectInfo* info) {
1405 uint64_t id = static_cast<uint64_t>(info->GetHash()); 1405 SnapshotObjectId id = static_cast<SnapshotObjectId>(info->GetHash());
1406 const char* label = info->GetLabel(); 1406 const char* label = info->GetLabel();
1407 id ^= HashSequentialString(label, 1407 id ^= HashSequentialString(label,
1408 static_cast<int>(strlen(label)), 1408 static_cast<int>(strlen(label)),
1409 HEAP->HashSeed()); 1409 HEAP->HashSeed());
1410 intptr_t element_count = info->GetElementCount(); 1410 intptr_t element_count = info->GetElementCount();
1411 if (element_count != -1) 1411 if (element_count != -1)
1412 id ^= ComputeIntegerHash(static_cast<uint32_t>(element_count), 1412 id ^= ComputeIntegerHash(static_cast<uint32_t>(element_count),
1413 v8::internal::kZeroHashSeed); 1413 v8::internal::kZeroHashSeed);
1414 return id << 1; 1414 return id << 1;
1415 } 1415 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1465 1465
1466 1466
1467 void HeapSnapshotsCollection::RemoveSnapshot(HeapSnapshot* snapshot) { 1467 void HeapSnapshotsCollection::RemoveSnapshot(HeapSnapshot* snapshot) {
1468 snapshots_.RemoveElement(snapshot); 1468 snapshots_.RemoveElement(snapshot);
1469 unsigned uid = snapshot->uid(); 1469 unsigned uid = snapshot->uid();
1470 snapshots_uids_.Remove(reinterpret_cast<void*>(uid), 1470 snapshots_uids_.Remove(reinterpret_cast<void*>(uid),
1471 static_cast<uint32_t>(uid)); 1471 static_cast<uint32_t>(uid));
1472 } 1472 }
1473 1473
1474 1474
1475 Handle<HeapObject> HeapSnapshotsCollection::FindHeapObjectById(uint64_t id) { 1475 Handle<HeapObject> HeapSnapshotsCollection::FindHeapObjectById(SnapshotObjectId id) {
mnaganov (inactive) 2012/03/08 15:31:22 nit: 80 chars
1476 // First perform a full GC in order to avoid dead objects. 1476 // First perform a full GC in order to avoid dead objects.
1477 HEAP->CollectAllGarbage(Heap::kMakeHeapIterableMask, 1477 HEAP->CollectAllGarbage(Heap::kMakeHeapIterableMask,
1478 "HeapSnapshotsCollection::FindHeapObjectById"); 1478 "HeapSnapshotsCollection::FindHeapObjectById");
1479 AssertNoAllocation no_allocation; 1479 AssertNoAllocation no_allocation;
1480 HeapObject* object = NULL; 1480 HeapObject* object = NULL;
1481 HeapIterator iterator(HeapIterator::kFilterUnreachable); 1481 HeapIterator iterator(HeapIterator::kFilterUnreachable);
1482 // Make sure that object with the given id is still reachable. 1482 // Make sure that object with the given id is still reachable.
1483 for (HeapObject* obj = iterator.next(); 1483 for (HeapObject* obj = iterator.next();
1484 obj != NULL; 1484 obj != NULL;
1485 obj = iterator.next()) { 1485 obj = iterator.next()) {
(...skipping 2033 matching lines...) Expand 10 before | Expand all | Expand 10 after
3519 STATIC_CHECK(sizeof(int) == sizeof(GetNodeId(edge->to()))); // NOLINT 3519 STATIC_CHECK(sizeof(int) == sizeof(GetNodeId(edge->to()))); // NOLINT
3520 int result = OS::SNPrintF(buffer, ",%d,%d,%d", 3520 int result = OS::SNPrintF(buffer, ",%d,%d,%d",
3521 edge->type(), edge_name_or_index, GetNodeId(edge->to())); 3521 edge->type(), edge_name_or_index, GetNodeId(edge->to()));
3522 USE(result); 3522 USE(result);
3523 ASSERT(result != -1); 3523 ASSERT(result != -1);
3524 writer_->AddString(buffer.start()); 3524 writer_->AddString(buffer.start());
3525 } 3525 }
3526 3526
3527 3527
3528 void HeapSnapshotJSONSerializer::SerializeNode(HeapEntry* entry) { 3528 void HeapSnapshotJSONSerializer::SerializeNode(HeapEntry* entry) {
3529 // The buffer needs space for 6 ints, 1 uint64_t, 7 commas, \n and \0 3529 // The buffer needs space for 6 ints, 1 uint32_t, 7 commas, \n and \0
3530 static const int kBufferSize = 3530 static const int kBufferSize =
3531 6 * MaxDecimalDigitsIn<sizeof(int)>::kSigned // NOLINT 3531 6 * MaxDecimalDigitsIn<sizeof(int)>::kSigned // NOLINT
3532 + MaxDecimalDigitsIn<sizeof(uint64_t)>::kUnsigned // NOLINT 3532 + MaxDecimalDigitsIn<sizeof(uint32_t)>::kUnsigned // NOLINT
mnaganov (inactive) 2012/03/08 15:31:22 Perhaps, using SnapshotObjectId here will make it
3533 + 7 + 1 + 1; 3533 + 7 + 1 + 1;
3534 EmbeddedVector<char, kBufferSize> buffer; 3534 EmbeddedVector<char, kBufferSize> buffer;
3535 Vector<HeapGraphEdge> children = entry->children(); 3535 Vector<HeapGraphEdge> children = entry->children();
3536 STATIC_CHECK(sizeof(int) == sizeof(entry->type())); // NOLINT 3536 STATIC_CHECK(sizeof(int) == sizeof(entry->type())); // NOLINT
3537 STATIC_CHECK(sizeof(int) == sizeof(GetStringId(entry->name()))); // NOLINT 3537 STATIC_CHECK(sizeof(int) == sizeof(GetStringId(entry->name()))); // NOLINT
3538 STATIC_CHECK(sizeof(uint64_t) == sizeof(entry->id())); // NOLINT 3538 STATIC_CHECK(sizeof(unsigned) == sizeof(entry->id())); // NOLINT
3539 STATIC_CHECK(sizeof(int) == sizeof(entry->self_size())); // NOLINT 3539 STATIC_CHECK(sizeof(int) == sizeof(entry->self_size())); // NOLINT
3540 STATIC_CHECK(sizeof(int) == sizeof(entry->retained_size())); // NOLINT 3540 STATIC_CHECK(sizeof(int) == sizeof(entry->retained_size())); // NOLINT
3541 STATIC_CHECK(sizeof(int) == sizeof(GetNodeId(entry->dominator()))); // NOLINT 3541 STATIC_CHECK(sizeof(int) == sizeof(GetNodeId(entry->dominator()))); // NOLINT
3542 STATIC_CHECK(sizeof(int) == sizeof(children.length())); // NOLINT 3542 STATIC_CHECK(sizeof(int) == sizeof(children.length())); // NOLINT
3543 int result = OS::SNPrintF(buffer, "\n,%d,%d,%llu,%d,%d,%d,%d", 3543 int result = OS::SNPrintF(buffer, "\n,%d,%d,%u,%d,%d,%d,%d",
3544 entry->type(), 3544 entry->type(),
3545 GetStringId(entry->name()), 3545 GetStringId(entry->name()),
3546 entry->id(), 3546 entry->id(),
3547 entry->self_size(), 3547 entry->self_size(),
3548 entry->retained_size(), 3548 entry->retained_size(),
3549 GetNodeId(entry->dominator()), 3549 GetNodeId(entry->dominator()),
3550 children.length()); 3550 children.length());
3551 USE(result); 3551 USE(result);
3552 ASSERT(result != -1); 3552 ASSERT(result != -1);
3553 writer_->AddString(buffer.start()); 3553 writer_->AddString(buffer.start());
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
3734 3734
3735 3735
3736 void HeapSnapshotJSONSerializer::SortHashMap( 3736 void HeapSnapshotJSONSerializer::SortHashMap(
3737 HashMap* map, List<HashMap::Entry*>* sorted_entries) { 3737 HashMap* map, List<HashMap::Entry*>* sorted_entries) {
3738 for (HashMap::Entry* p = map->Start(); p != NULL; p = map->Next(p)) 3738 for (HashMap::Entry* p = map->Start(); p != NULL; p = map->Next(p))
3739 sorted_entries->Add(p); 3739 sorted_entries->Add(p);
3740 sorted_entries->Sort(SortUsingEntryValue); 3740 sorted_entries->Sort(SortUsingEntryValue);
3741 } 3741 }
3742 3742
3743 } } // namespace v8::internal 3743 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/profile-generator.h ('k') | src/profile-generator-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698