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

Side by Side Diff: src/heap-snapshot-generator.cc

Issue 22300005: Use standard routine to compute pointer hashs in heap profiler (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/heap-snapshot-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 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 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 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 // HeapObjectsMap::GenerateId) and odds for native objects. 362 // HeapObjectsMap::GenerateId) and odds for native objects.
363 const SnapshotObjectId HeapObjectsMap::kInternalRootObjectId = 1; 363 const SnapshotObjectId HeapObjectsMap::kInternalRootObjectId = 1;
364 const SnapshotObjectId HeapObjectsMap::kGcRootsObjectId = 364 const SnapshotObjectId HeapObjectsMap::kGcRootsObjectId =
365 HeapObjectsMap::kInternalRootObjectId + HeapObjectsMap::kObjectIdStep; 365 HeapObjectsMap::kInternalRootObjectId + HeapObjectsMap::kObjectIdStep;
366 const SnapshotObjectId HeapObjectsMap::kGcRootsFirstSubrootId = 366 const SnapshotObjectId HeapObjectsMap::kGcRootsFirstSubrootId =
367 HeapObjectsMap::kGcRootsObjectId + HeapObjectsMap::kObjectIdStep; 367 HeapObjectsMap::kGcRootsObjectId + HeapObjectsMap::kObjectIdStep;
368 const SnapshotObjectId HeapObjectsMap::kFirstAvailableObjectId = 368 const SnapshotObjectId HeapObjectsMap::kFirstAvailableObjectId =
369 HeapObjectsMap::kGcRootsFirstSubrootId + 369 HeapObjectsMap::kGcRootsFirstSubrootId +
370 VisitorSynchronization::kNumberOfSyncTags * HeapObjectsMap::kObjectIdStep; 370 VisitorSynchronization::kNumberOfSyncTags * HeapObjectsMap::kObjectIdStep;
371 371
372
373 static bool AddressesMatch(void* key1, void* key2) {
374 return key1 == key2;
375 }
376
377
372 HeapObjectsMap::HeapObjectsMap(Heap* heap) 378 HeapObjectsMap::HeapObjectsMap(Heap* heap)
373 : next_id_(kFirstAvailableObjectId), 379 : next_id_(kFirstAvailableObjectId),
374 entries_map_(AddressesMatch), 380 entries_map_(AddressesMatch),
375 heap_(heap) { 381 heap_(heap) {
376 // This dummy element solves a problem with entries_map_. 382 // This dummy element solves a problem with entries_map_.
377 // When we do lookup in HashMap we see no difference between two cases: 383 // When we do lookup in HashMap we see no difference between two cases:
378 // it has an entry with NULL as the value or it has created 384 // it has an entry with NULL as the value or it has created
379 // a new entry on the fly with NULL as the default value. 385 // a new entry on the fly with NULL as the default value.
380 // With such dummy element we have a guaranty that all entries_map_ entries 386 // With such dummy element we have a guaranty that all entries_map_ entries
381 // will have the value field grater than 0. 387 // will have the value field grater than 0.
382 // This fact is using in MoveObject method. 388 // This fact is using in MoveObject method.
383 entries_.Add(EntryInfo(0, NULL, 0)); 389 entries_.Add(EntryInfo(0, NULL, 0));
384 } 390 }
385 391
386 392
387 void HeapObjectsMap::SnapshotGenerationFinished() { 393 void HeapObjectsMap::SnapshotGenerationFinished() {
388 RemoveDeadEntries(); 394 RemoveDeadEntries();
389 } 395 }
390 396
391 397
392 void HeapObjectsMap::MoveObject(Address from, Address to) { 398 void HeapObjectsMap::MoveObject(Address from, Address to) {
393 ASSERT(to != NULL); 399 ASSERT(to != NULL);
394 ASSERT(from != NULL); 400 ASSERT(from != NULL);
395 if (from == to) return; 401 if (from == to) return;
396 void* from_value = entries_map_.Remove(from, AddressHash(from)); 402 void* from_value = entries_map_.Remove(from, ComputePointerHash(from));
397 if (from_value == NULL) { 403 if (from_value == NULL) {
398 // It may occur that some untracked object moves to an address X and there 404 // It may occur that some untracked object moves to an address X and there
399 // is a tracked object at that address. In this case we should remove the 405 // is a tracked object at that address. In this case we should remove the
400 // entry as we know that the object has died. 406 // entry as we know that the object has died.
401 void* to_value = entries_map_.Remove(to, AddressHash(to)); 407 void* to_value = entries_map_.Remove(to, ComputePointerHash(to));
402 if (to_value != NULL) { 408 if (to_value != NULL) {
403 int to_entry_info_index = 409 int to_entry_info_index =
404 static_cast<int>(reinterpret_cast<intptr_t>(to_value)); 410 static_cast<int>(reinterpret_cast<intptr_t>(to_value));
405 entries_.at(to_entry_info_index).addr = NULL; 411 entries_.at(to_entry_info_index).addr = NULL;
406 } 412 }
407 } else { 413 } else {
408 HashMap::Entry* to_entry = entries_map_.Lookup(to, AddressHash(to), true); 414 HashMap::Entry* to_entry = entries_map_.Lookup(to, ComputePointerHash(to),
415 true);
409 if (to_entry->value != NULL) { 416 if (to_entry->value != NULL) {
410 // We found the existing entry with to address for an old object. 417 // We found the existing entry with to address for an old object.
411 // Without this operation we will have two EntryInfo's with the same 418 // Without this operation we will have two EntryInfo's with the same
412 // value in addr field. It is bad because later at RemoveDeadEntries 419 // value in addr field. It is bad because later at RemoveDeadEntries
413 // one of this entry will be removed with the corresponding entries_map_ 420 // one of this entry will be removed with the corresponding entries_map_
414 // entry. 421 // entry.
415 int to_entry_info_index = 422 int to_entry_info_index =
416 static_cast<int>(reinterpret_cast<intptr_t>(to_entry->value)); 423 static_cast<int>(reinterpret_cast<intptr_t>(to_entry->value));
417 entries_.at(to_entry_info_index).addr = NULL; 424 entries_.at(to_entry_info_index).addr = NULL;
418 } 425 }
419 int from_entry_info_index = 426 int from_entry_info_index =
420 static_cast<int>(reinterpret_cast<intptr_t>(from_value)); 427 static_cast<int>(reinterpret_cast<intptr_t>(from_value));
421 entries_.at(from_entry_info_index).addr = to; 428 entries_.at(from_entry_info_index).addr = to;
422 to_entry->value = from_value; 429 to_entry->value = from_value;
423 } 430 }
424 } 431 }
425 432
426 433
427 SnapshotObjectId HeapObjectsMap::FindEntry(Address addr) { 434 SnapshotObjectId HeapObjectsMap::FindEntry(Address addr) {
428 HashMap::Entry* entry = entries_map_.Lookup(addr, AddressHash(addr), false); 435 HashMap::Entry* entry = entries_map_.Lookup(addr, ComputePointerHash(addr),
436 false);
429 if (entry == NULL) return 0; 437 if (entry == NULL) return 0;
430 int entry_index = static_cast<int>(reinterpret_cast<intptr_t>(entry->value)); 438 int entry_index = static_cast<int>(reinterpret_cast<intptr_t>(entry->value));
431 EntryInfo& entry_info = entries_.at(entry_index); 439 EntryInfo& entry_info = entries_.at(entry_index);
432 ASSERT(static_cast<uint32_t>(entries_.length()) > entries_map_.occupancy()); 440 ASSERT(static_cast<uint32_t>(entries_.length()) > entries_map_.occupancy());
433 return entry_info.id; 441 return entry_info.id;
434 } 442 }
435 443
436 444
437 SnapshotObjectId HeapObjectsMap::FindOrAddEntry(Address addr, 445 SnapshotObjectId HeapObjectsMap::FindOrAddEntry(Address addr,
438 unsigned int size) { 446 unsigned int size) {
439 ASSERT(static_cast<uint32_t>(entries_.length()) > entries_map_.occupancy()); 447 ASSERT(static_cast<uint32_t>(entries_.length()) > entries_map_.occupancy());
440 HashMap::Entry* entry = entries_map_.Lookup(addr, AddressHash(addr), true); 448 HashMap::Entry* entry = entries_map_.Lookup(addr, ComputePointerHash(addr),
449 true);
441 if (entry->value != NULL) { 450 if (entry->value != NULL) {
442 int entry_index = 451 int entry_index =
443 static_cast<int>(reinterpret_cast<intptr_t>(entry->value)); 452 static_cast<int>(reinterpret_cast<intptr_t>(entry->value));
444 EntryInfo& entry_info = entries_.at(entry_index); 453 EntryInfo& entry_info = entries_.at(entry_index);
445 entry_info.accessed = true; 454 entry_info.accessed = true;
446 entry_info.size = size; 455 entry_info.size = size;
447 return entry_info.id; 456 return entry_info.id;
448 } 457 }
449 entry->value = reinterpret_cast<void*>(entries_.length()); 458 entry->value = reinterpret_cast<void*>(entries_.length());
450 SnapshotObjectId id = next_id_; 459 SnapshotObjectId id = next_id_;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 entries_.at(0).addr == NULL); 534 entries_.at(0).addr == NULL);
526 int first_free_entry = 1; 535 int first_free_entry = 1;
527 for (int i = 1; i < entries_.length(); ++i) { 536 for (int i = 1; i < entries_.length(); ++i) {
528 EntryInfo& entry_info = entries_.at(i); 537 EntryInfo& entry_info = entries_.at(i);
529 if (entry_info.accessed) { 538 if (entry_info.accessed) {
530 if (first_free_entry != i) { 539 if (first_free_entry != i) {
531 entries_.at(first_free_entry) = entry_info; 540 entries_.at(first_free_entry) = entry_info;
532 } 541 }
533 entries_.at(first_free_entry).accessed = false; 542 entries_.at(first_free_entry).accessed = false;
534 HashMap::Entry* entry = entries_map_.Lookup( 543 HashMap::Entry* entry = entries_map_.Lookup(
535 entry_info.addr, AddressHash(entry_info.addr), false); 544 entry_info.addr, ComputePointerHash(entry_info.addr), false);
536 ASSERT(entry); 545 ASSERT(entry);
537 entry->value = reinterpret_cast<void*>(first_free_entry); 546 entry->value = reinterpret_cast<void*>(first_free_entry);
538 ++first_free_entry; 547 ++first_free_entry;
539 } else { 548 } else {
540 if (entry_info.addr) { 549 if (entry_info.addr) {
541 entries_map_.Remove(entry_info.addr, AddressHash(entry_info.addr)); 550 entries_map_.Remove(entry_info.addr,
551 ComputePointerHash(entry_info.addr));
542 } 552 }
543 } 553 }
544 } 554 }
545 entries_.Rewind(first_free_entry); 555 entries_.Rewind(first_free_entry);
546 ASSERT(static_cast<uint32_t>(entries_.length()) - 1 == 556 ASSERT(static_cast<uint32_t>(entries_.length()) - 1 ==
547 entries_map_.occupancy()); 557 entries_map_.occupancy());
548 } 558 }
549 559
550 560
551 SnapshotObjectId HeapObjectsMap::GenerateId(v8::RetainedObjectInfo* info) { 561 SnapshotObjectId HeapObjectsMap::GenerateId(v8::RetainedObjectInfo* info) {
(...skipping 2141 matching lines...) Expand 10 before | Expand all | Expand 10 after
2693 2703
2694 2704
2695 void HeapSnapshotJSONSerializer::SortHashMap( 2705 void HeapSnapshotJSONSerializer::SortHashMap(
2696 HashMap* map, List<HashMap::Entry*>* sorted_entries) { 2706 HashMap* map, List<HashMap::Entry*>* sorted_entries) {
2697 for (HashMap::Entry* p = map->Start(); p != NULL; p = map->Next(p)) 2707 for (HashMap::Entry* p = map->Start(); p != NULL; p = map->Next(p))
2698 sorted_entries->Add(p); 2708 sorted_entries->Add(p);
2699 sorted_entries->Sort(SortUsingEntryValue); 2709 sorted_entries->Sort(SortUsingEntryValue);
2700 } 2710 }
2701 2711
2702 } } // namespace v8::internal 2712 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/heap-snapshot-generator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698