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

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: style errors were fixed 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/hashmap.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 1297 matching lines...) Expand 10 before | Expand all | Expand 10 after
1308 const SnapshotObjectId HeapObjectsMap::kGcRootsFirstSubrootId = 1308 const SnapshotObjectId HeapObjectsMap::kGcRootsFirstSubrootId =
1309 HeapObjectsMap::kGcRootsObjectId + HeapObjectsMap::kObjectIdStep; 1309 HeapObjectsMap::kGcRootsObjectId + HeapObjectsMap::kObjectIdStep;
1310 const SnapshotObjectId HeapObjectsMap::kFirstAvailableObjectId = 1310 const SnapshotObjectId HeapObjectsMap::kFirstAvailableObjectId =
1311 HeapObjectsMap::kGcRootsFirstSubrootId + 1311 HeapObjectsMap::kGcRootsFirstSubrootId +
1312 VisitorSynchronization::kNumberOfSyncTags * HeapObjectsMap::kObjectIdStep; 1312 VisitorSynchronization::kNumberOfSyncTags * HeapObjectsMap::kObjectIdStep;
1313 1313
1314 HeapObjectsMap::HeapObjectsMap() 1314 HeapObjectsMap::HeapObjectsMap()
1315 : initial_fill_mode_(true), 1315 : initial_fill_mode_(true),
1316 next_id_(kFirstAvailableObjectId), 1316 next_id_(kFirstAvailableObjectId),
1317 entries_map_(AddressesMatch), 1317 entries_map_(AddressesMatch),
1318 entries_(new List<EntryInfo>()) { } 1318 entries_(new List<EntryInfo>()) {
1319 entries_->Add(EntryInfo(0, NULL));
yurys 2012/04/10 16:46:35 Could you add a comment that it is for simplifying
1320 }
1319 1321
1320 1322
1321 HeapObjectsMap::~HeapObjectsMap() { 1323 HeapObjectsMap::~HeapObjectsMap() {
1322 delete entries_; 1324 delete entries_;
1323 } 1325 }
1324 1326
1325 1327
1326 void HeapObjectsMap::SnapshotGenerationFinished() { 1328 void HeapObjectsMap::SnapshotGenerationFinished() {
1327 initial_fill_mode_ = false; 1329 initial_fill_mode_ = false;
1328 RemoveDeadEntries(); 1330 RemoveDeadEntries();
1329 } 1331 }
1330 1332
1331 1333
1332 SnapshotObjectId HeapObjectsMap::FindObject(Address addr) { 1334 SnapshotObjectId HeapObjectsMap::FindObject(Address addr) {
1333 if (!initial_fill_mode_) { 1335 if (!initial_fill_mode_) {
1334 SnapshotObjectId existing = FindEntry(addr); 1336 SnapshotObjectId existing = FindEntry(addr);
1335 if (existing != 0) return existing; 1337 if (existing != 0) return existing;
1336 } 1338 }
1337 SnapshotObjectId id = next_id_; 1339 SnapshotObjectId id = next_id_;
1338 next_id_ += kObjectIdStep; 1340 next_id_ += kObjectIdStep;
1339 AddEntry(addr, id); 1341 AddEntry(addr, id);
1342 ASSERT(static_cast<uint32_t>(entries_->length()) > entries_map_.occupancy());
1340 return id; 1343 return id;
1341 } 1344 }
1342 1345
1343 1346
1344 void HeapObjectsMap::MoveObject(Address from, Address to) { 1347 void HeapObjectsMap::MoveObject(Address from, Address to) {
1348 ASSERT(to != NULL);
1349 ASSERT(from != NULL);
1350 ASSERT(from != to);
mnaganov (inactive) 2012/04/10 21:12:04 I'm sure you will be hitting this assert. I think
1345 if (from == to) return; 1351 if (from == to) return;
1346 HashMap::Entry* entry = entries_map_.Lookup(from, AddressHash(from), false); 1352 void* from_value = entries_map_.Remove(from, AddressHash(from));
1347 if (entry != NULL) { 1353 if (from_value == NULL) return;
1348 void* value = entry->value; 1354 int from_entry_info_index =
1349 entries_map_.Remove(from, AddressHash(from)); 1355 static_cast<int>(reinterpret_cast<intptr_t>(from_value));
1350 if (to != NULL) { 1356 entries_->at(from_entry_info_index).addr = to;
1351 entry = entries_map_.Lookup(to, AddressHash(to), true); 1357 HashMap::Entry* to_entry = entries_map_.Lookup(to, AddressHash(to), true);
1352 // We can have an entry at the new location, it is OK, as GC can overwrite 1358 if (to_entry->value != NULL) {
1353 // dead objects with alive objects being moved. 1359 int to_entry_info_index =
1354 entry->value = value; 1360 static_cast<int>(reinterpret_cast<intptr_t>(to_entry->value));
1355 } 1361 entries_->at(to_entry_info_index).addr = NULL;
1356 } 1362 }
1363 to_entry->value = reinterpret_cast<void*>(from_entry_info_index);
1357 } 1364 }
1358 1365
1359 1366
1360 void HeapObjectsMap::AddEntry(Address addr, SnapshotObjectId id) { 1367 void HeapObjectsMap::AddEntry(Address addr, SnapshotObjectId id) {
1361 HashMap::Entry* entry = entries_map_.Lookup(addr, AddressHash(addr), true); 1368 HashMap::Entry* entry = entries_map_.Lookup(addr, AddressHash(addr), true);
1362 ASSERT(entry->value == NULL); 1369 ASSERT(entry->value == NULL);
1370 ASSERT(entries_->length() > 0 &&
1371 entries_->at(0).id == 0 &&
1372 entries_->at(0).addr == NULL);
1373 ASSERT(entries_->length() == 1 ||
mnaganov (inactive) 2012/04/10 21:12:04 The first part seems to be superfluous, as if entr
1374 entries_->at(entries_->length() - 1).id < id);
1363 entry->value = reinterpret_cast<void*>(entries_->length()); 1375 entry->value = reinterpret_cast<void*>(entries_->length());
1364 entries_->Add(EntryInfo(id)); 1376 entries_->Add(EntryInfo(id, addr));
1377 ASSERT(static_cast<uint32_t>(entries_->length()) > entries_map_.occupancy());
yurys 2012/04/10 16:46:35 Comment on why it is strictly greater?
1365 } 1378 }
1366 1379
1367 1380
1368 SnapshotObjectId HeapObjectsMap::FindEntry(Address addr) { 1381 SnapshotObjectId HeapObjectsMap::FindEntry(Address addr) {
1369 HashMap::Entry* entry = entries_map_.Lookup(addr, AddressHash(addr), false); 1382 HashMap::Entry* entry = entries_map_.Lookup(addr, AddressHash(addr), false);
1370 if (entry != NULL) { 1383 if (entry != NULL) {
1371 int entry_index = 1384 int entry_index =
1372 static_cast<int>(reinterpret_cast<intptr_t>(entry->value)); 1385 static_cast<int>(reinterpret_cast<intptr_t>(entry->value));
1373 EntryInfo& entry_info = entries_->at(entry_index); 1386 EntryInfo& entry_info = entries_->at(entry_index);
1374 entry_info.accessed = true; 1387 entry_info.accessed = true;
1388 ASSERT((uint32_t)entries_->length() > entries_map_.occupancy());
alexeif 2012/04/10 16:55:24 still ditto ;-)
1375 return entry_info.id; 1389 return entry_info.id;
1376 } else { 1390 } else {
1377 return 0; 1391 return 0;
1378 } 1392 }
1379 } 1393 }
1380 1394
1381 1395
1382 void HeapObjectsMap::RemoveDeadEntries() { 1396 void HeapObjectsMap::RemoveDeadEntries() {
1383 List<EntryInfo>* new_entries = new List<EntryInfo>(); 1397 ASSERT(entries_->length() > 0 &&
1384 List<void*> dead_entries; 1398 entries_->at(0).id == 0 &&
1385 for (HashMap::Entry* entry = entries_map_.Start(); 1399 entries_->at(0).addr == NULL);
1386 entry != NULL; 1400 int first_free_entry = 1;
1387 entry = entries_map_.Next(entry)) { 1401 for (int i = 1; i < entries_->length(); ++i) {
1388 int entry_index = 1402 EntryInfo& entry_info = entries_->at(i);
1389 static_cast<int>(reinterpret_cast<intptr_t>(entry->value));
1390 EntryInfo& entry_info = entries_->at(entry_index);
1391 if (entry_info.accessed) { 1403 if (entry_info.accessed) {
1392 entry->value = reinterpret_cast<void*>(new_entries->length()); 1404 if (first_free_entry != i) {
1393 new_entries->Add(EntryInfo(entry_info.id, false)); 1405 entries_->at(first_free_entry) = entry_info;
1406 }
1407 entries_->at(first_free_entry).accessed = false;
1408 HashMap::Entry* entry = entries_map_.Lookup(
1409 entry_info.addr, AddressHash(entry_info.addr), false);
1410 ASSERT(entry);
1411 entry->value = reinterpret_cast<void*>(first_free_entry);
1412 ++first_free_entry;
1394 } else { 1413 } else {
1395 dead_entries.Add(entry->key); 1414 if (entry_info.addr) {
1415 entries_map_.Remove(entry_info.addr, AddressHash(entry_info.addr));
1416 }
1396 } 1417 }
1397 } 1418 }
1398 for (int i = 0; i < dead_entries.length(); ++i) { 1419 entries_->Rewind(first_free_entry);
1399 void* raw_entry = dead_entries[i]; 1420 ASSERT(static_cast<uint32_t>(entries_->length()) - 1 ==
1400 entries_map_.Remove( 1421 entries_map_.occupancy());
1401 raw_entry, AddressHash(reinterpret_cast<Address>(raw_entry)));
1402 }
1403 delete entries_;
1404 entries_ = new_entries;
1405 } 1422 }
1406 1423
1407 1424
1408 SnapshotObjectId HeapObjectsMap::GenerateId(v8::RetainedObjectInfo* info) { 1425 SnapshotObjectId HeapObjectsMap::GenerateId(v8::RetainedObjectInfo* info) {
1409 SnapshotObjectId id = static_cast<SnapshotObjectId>(info->GetHash()); 1426 SnapshotObjectId id = static_cast<SnapshotObjectId>(info->GetHash());
1410 const char* label = info->GetLabel(); 1427 const char* label = info->GetLabel();
1411 id ^= HashSequentialString(label, 1428 id ^= HashSequentialString(label,
1412 static_cast<int>(strlen(label)), 1429 static_cast<int>(strlen(label)),
1413 HEAP->HashSeed()); 1430 HEAP->HashSeed());
1414 intptr_t element_count = info->GetElementCount(); 1431 intptr_t element_count = info->GetElementCount();
(...skipping 2341 matching lines...) Expand 10 before | Expand all | Expand 10 after
3756 3773
3757 3774
3758 void HeapSnapshotJSONSerializer::SortHashMap( 3775 void HeapSnapshotJSONSerializer::SortHashMap(
3759 HashMap* map, List<HashMap::Entry*>* sorted_entries) { 3776 HashMap* map, List<HashMap::Entry*>* sorted_entries) {
3760 for (HashMap::Entry* p = map->Start(); p != NULL; p = map->Next(p)) 3777 for (HashMap::Entry* p = map->Start(); p != NULL; p = map->Next(p))
3761 sorted_entries->Add(p); 3778 sorted_entries->Add(p);
3762 sorted_entries->Sort(SortUsingEntryValue); 3779 sorted_entries->Sort(SortUsingEntryValue);
3763 } 3780 }
3764 3781
3765 } } // namespace v8::internal 3782 } } // namespace v8::internal
OLDNEW
« src/hashmap.h ('K') | « src/profile-generator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698