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

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

Issue 10031032: I'd like to add addr field into EntryInfo struct. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 8 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
« src/profile-generator.h ('K') | « src/profile-generator.h ('k') | no next file » | 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 1319 matching lines...) Expand 10 before | Expand all | Expand 10 after
1330 1330
1331 1331
1332 SnapshotObjectId HeapObjectsMap::FindObject(Address addr) { 1332 SnapshotObjectId HeapObjectsMap::FindObject(Address addr) {
1333 if (!initial_fill_mode_) { 1333 if (!initial_fill_mode_) {
1334 SnapshotObjectId existing = FindEntry(addr); 1334 SnapshotObjectId existing = FindEntry(addr);
1335 if (existing != 0) return existing; 1335 if (existing != 0) return existing;
1336 } 1336 }
1337 SnapshotObjectId id = next_id_; 1337 SnapshotObjectId id = next_id_;
1338 next_id_ += kObjectIdStep; 1338 next_id_ += kObjectIdStep;
1339 AddEntry(addr, id); 1339 AddEntry(addr, id);
1340 ASSERT((uint32_t)entries_->length() >= entries_map_.occupancy());
yurys 2012/04/10 14:03:35 Please use static_cast<uint32_t>
1340 return id; 1341 return id;
1341 } 1342 }
1342 1343
1343 1344
1345 int HeapObjectsMap::UpdateEntryInfoAddress(Address addr,
mnaganov (inactive) 2012/04/10 13:50:14 I don't see a clear reason for having EntryInfo lo
1346 uint32_t hash,
1347 Address new_addr) {
1348 HashMap::Entry* entry = entries_map_.Lookup(addr, hash, false);
1349 if (entry == NULL) return -1;
1350 int entry_index =
1351 static_cast<int>(reinterpret_cast<intptr_t>(entry->value));
1352 EntryInfo& entry_info = entries_->at(entry_index);
1353 entry_info.addr = new_addr;
1354 return entry_index;
1355 }
1356
1357
1344 void HeapObjectsMap::MoveObject(Address from, Address to) { 1358 void HeapObjectsMap::MoveObject(Address from, Address to) {
1359 ASSERT(to != NULL);
1360 ASSERT(from != to);
1345 if (from == to) return; 1361 if (from == to) return;
1346 HashMap::Entry* entry = entries_map_.Lookup(from, AddressHash(from), false); 1362 // 1. lookup for From address entry in the map and update EntryInfo.addr.
yurys 2012/04/10 14:03:35 From -> |from|, To -> |to|
1347 if (entry != NULL) { 1363 // 2. remove From address entry from the map.
1348 void* value = entry->value; 1364 // 3. lookup for To address entry in the map and clear EntryInfo.addr.
1349 entries_map_.Remove(from, AddressHash(from)); 1365 // 4. create/update the map entry for To address and point it to
1350 if (to != NULL) { 1366 // From's entry_info index.
1351 entry = entries_map_.Lookup(to, AddressHash(to), true); 1367 uint32_t from_hash = AddressHash(from);
1352 // We can have an entry at the new location, it is OK, as GC can overwrite 1368 int from_entry_info_index = UpdateEntryInfoAddress(from, from_hash, to);
1353 // dead objects with alive objects being moved. 1369 if (from_entry_info_index != -1) {
1354 entry->value = value; 1370 entries_map_.Remove(from, from_hash);
1355 } 1371 uint32_t to_hash = AddressHash(to);
1372 UpdateEntryInfoAddress(to, to_hash, NULL);
mnaganov (inactive) 2012/04/10 13:50:14 Why are you making 2 map lookups here?
yurys 2012/04/10 14:03:35 This is an overhead, we should instead do entries
1373 HashMap::Entry* entry = entries_map_.Lookup(to, to_hash, true);
1374 entry->value = reinterpret_cast<void*>(from_entry_info_index);
1356 } 1375 }
1357 } 1376 }
1358 1377
1359 1378
1360 void HeapObjectsMap::AddEntry(Address addr, SnapshotObjectId id) { 1379 void HeapObjectsMap::AddEntry(Address addr, SnapshotObjectId id) {
1361 HashMap::Entry* entry = entries_map_.Lookup(addr, AddressHash(addr), true); 1380 HashMap::Entry* entry = entries_map_.Lookup(addr, AddressHash(addr), true);
1362 ASSERT(entry->value == NULL); 1381 ASSERT(entry->value == NULL);
1382 ASSERT(!entries_->length() || entries_->at(entries_->length() - 1).id < id);
1363 entry->value = reinterpret_cast<void*>(entries_->length()); 1383 entry->value = reinterpret_cast<void*>(entries_->length());
1364 entries_->Add(EntryInfo(id)); 1384 entries_->Add(EntryInfo(id, addr));
1385 ASSERT((uint32_t)entries_->length() >= entries_map_.occupancy());
yurys 2012/04/10 14:03:35 static_cast please.
1365 } 1386 }
1366 1387
1367 1388
1368 SnapshotObjectId HeapObjectsMap::FindEntry(Address addr) { 1389 SnapshotObjectId HeapObjectsMap::FindEntry(Address addr) {
1369 HashMap::Entry* entry = entries_map_.Lookup(addr, AddressHash(addr), false); 1390 HashMap::Entry* entry = entries_map_.Lookup(addr, AddressHash(addr), false);
1370 if (entry != NULL) { 1391 if (entry != NULL) {
1371 int entry_index = 1392 int entry_index =
1372 static_cast<int>(reinterpret_cast<intptr_t>(entry->value)); 1393 static_cast<int>(reinterpret_cast<intptr_t>(entry->value));
1373 EntryInfo& entry_info = entries_->at(entry_index); 1394 EntryInfo& entry_info = entries_->at(entry_index);
1374 entry_info.accessed = true; 1395 entry_info.accessed = true;
1396 ASSERT((uint32_t)entries_->length() >= entries_map_.occupancy());
yurys 2012/04/10 14:03:35 ditto
1375 return entry_info.id; 1397 return entry_info.id;
1376 } else { 1398 } else {
1377 return 0; 1399 return 0;
1378 } 1400 }
1379 } 1401 }
1380 1402
1381 1403
1382 void HeapObjectsMap::RemoveDeadEntries() { 1404 void HeapObjectsMap::RemoveDeadEntries() {
1383 List<EntryInfo>* new_entries = new List<EntryInfo>(); 1405 int first_free_entry = 0;
1384 List<void*> dead_entries; 1406 for (int i = 0; i < entries_->length(); ++i) {
1385 for (HashMap::Entry* entry = entries_map_.Start(); 1407 EntryInfo& entry_info = entries_->at(i);
1386 entry != NULL;
1387 entry = entries_map_.Next(entry)) {
1388 int entry_index =
1389 static_cast<int>(reinterpret_cast<intptr_t>(entry->value));
1390 EntryInfo& entry_info = entries_->at(entry_index);
1391 if (entry_info.accessed) { 1408 if (entry_info.accessed) {
1392 entry->value = reinterpret_cast<void*>(new_entries->length()); 1409 if (first_free_entry != i) {
1393 new_entries->Add(EntryInfo(entry_info.id, false)); 1410 entries_->at(first_free_entry) = entry_info;
1411 }
1412 entries_->at(first_free_entry).accessed = false;
1413 HashMap::Entry* entry = entries_map_.Lookup(
1414 entry_info.addr, AddressHash(entry_info.addr), false);
1415 ASSERT(entry);
1416 entry->value = reinterpret_cast<void*>(first_free_entry);
1417 ++first_free_entry;
1394 } else { 1418 } else {
1395 dead_entries.Add(entry->key); 1419 if (entry_info.addr) {
1420 entries_map_.Remove(entry_info.addr, AddressHash(entry_info.addr));
1421 }
1396 } 1422 }
1397 } 1423 }
1398 for (int i = 0; i < dead_entries.length(); ++i) { 1424 entries_->Rewind(first_free_entry);
1399 void* raw_entry = dead_entries[i]; 1425 ASSERT((uint32_t)entries_->length() == entries_map_.occupancy());
yurys 2012/04/10 14:03:35 ditto.
1400 entries_map_.Remove(
1401 raw_entry, AddressHash(reinterpret_cast<Address>(raw_entry)));
1402 }
1403 delete entries_;
1404 entries_ = new_entries;
1405 } 1426 }
1406 1427
1407 1428
1408 SnapshotObjectId HeapObjectsMap::GenerateId(v8::RetainedObjectInfo* info) { 1429 SnapshotObjectId HeapObjectsMap::GenerateId(v8::RetainedObjectInfo* info) {
1409 SnapshotObjectId id = static_cast<SnapshotObjectId>(info->GetHash()); 1430 SnapshotObjectId id = static_cast<SnapshotObjectId>(info->GetHash());
1410 const char* label = info->GetLabel(); 1431 const char* label = info->GetLabel();
1411 id ^= HashSequentialString(label, 1432 id ^= HashSequentialString(label,
1412 static_cast<int>(strlen(label)), 1433 static_cast<int>(strlen(label)),
1413 HEAP->HashSeed()); 1434 HEAP->HashSeed());
1414 intptr_t element_count = info->GetElementCount(); 1435 intptr_t element_count = info->GetElementCount();
(...skipping 2341 matching lines...) Expand 10 before | Expand all | Expand 10 after
3756 3777
3757 3778
3758 void HeapSnapshotJSONSerializer::SortHashMap( 3779 void HeapSnapshotJSONSerializer::SortHashMap(
3759 HashMap* map, List<HashMap::Entry*>* sorted_entries) { 3780 HashMap* map, List<HashMap::Entry*>* sorted_entries) {
3760 for (HashMap::Entry* p = map->Start(); p != NULL; p = map->Next(p)) 3781 for (HashMap::Entry* p = map->Start(); p != NULL; p = map->Next(p))
3761 sorted_entries->Add(p); 3782 sorted_entries->Add(p);
3762 sorted_entries->Sort(SortUsingEntryValue); 3783 sorted_entries->Sort(SortUsingEntryValue);
3763 } 3784 }
3764 3785
3765 } } // namespace v8::internal 3786 } } // namespace v8::internal
OLDNEW
« src/profile-generator.h ('K') | « src/profile-generator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698