| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/profiler/heap-snapshot-generator.h" | 5 #include "src/profiler/heap-snapshot-generator.h" |
| 6 | 6 |
| 7 #include "src/code-stubs.h" | 7 #include "src/code-stubs.h" |
| 8 #include "src/conversions.h" | 8 #include "src/conversions.h" |
| 9 #include "src/debug/debug.h" | 9 #include "src/debug/debug.h" |
| 10 #include "src/objects-body-descriptors.h" | 10 #include "src/objects-body-descriptors.h" |
| (...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 entries_.at(to_entry_info_index).addr = NULL; | 405 entries_.at(to_entry_info_index).addr = NULL; |
| 406 } | 406 } |
| 407 int from_entry_info_index = | 407 int from_entry_info_index = |
| 408 static_cast<int>(reinterpret_cast<intptr_t>(from_value)); | 408 static_cast<int>(reinterpret_cast<intptr_t>(from_value)); |
| 409 entries_.at(from_entry_info_index).addr = to; | 409 entries_.at(from_entry_info_index).addr = to; |
| 410 // Size of an object can change during its life, so to keep information | 410 // Size of an object can change during its life, so to keep information |
| 411 // about the object in entries_ consistent, we have to adjust size when the | 411 // about the object in entries_ consistent, we have to adjust size when the |
| 412 // object is migrated. | 412 // object is migrated. |
| 413 if (FLAG_heap_profiler_trace_objects) { | 413 if (FLAG_heap_profiler_trace_objects) { |
| 414 PrintF("Move object from %p to %p old size %6d new size %6d\n", | 414 PrintF("Move object from %p to %p old size %6d new size %6d\n", |
| 415 from, | 415 static_cast<void*>(from), static_cast<void*>(to), |
| 416 to, | 416 entries_.at(from_entry_info_index).size, object_size); |
| 417 entries_.at(from_entry_info_index).size, | |
| 418 object_size); | |
| 419 } | 417 } |
| 420 entries_.at(from_entry_info_index).size = object_size; | 418 entries_.at(from_entry_info_index).size = object_size; |
| 421 to_entry->value = from_value; | 419 to_entry->value = from_value; |
| 422 } | 420 } |
| 423 return from_value != NULL; | 421 return from_value != NULL; |
| 424 } | 422 } |
| 425 | 423 |
| 426 | 424 |
| 427 void HeapObjectsMap::UpdateObjectSize(Address addr, int size) { | 425 void HeapObjectsMap::UpdateObjectSize(Address addr, int size) { |
| 428 FindOrAddEntry(addr, size, false); | 426 FindOrAddEntry(addr, size, false); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 445 DCHECK(static_cast<uint32_t>(entries_.length()) > entries_map_.occupancy()); | 443 DCHECK(static_cast<uint32_t>(entries_.length()) > entries_map_.occupancy()); |
| 446 HashMap::Entry* entry = | 444 HashMap::Entry* entry = |
| 447 entries_map_.LookupOrInsert(addr, ComputePointerHash(addr)); | 445 entries_map_.LookupOrInsert(addr, ComputePointerHash(addr)); |
| 448 if (entry->value != NULL) { | 446 if (entry->value != NULL) { |
| 449 int entry_index = | 447 int entry_index = |
| 450 static_cast<int>(reinterpret_cast<intptr_t>(entry->value)); | 448 static_cast<int>(reinterpret_cast<intptr_t>(entry->value)); |
| 451 EntryInfo& entry_info = entries_.at(entry_index); | 449 EntryInfo& entry_info = entries_.at(entry_index); |
| 452 entry_info.accessed = accessed; | 450 entry_info.accessed = accessed; |
| 453 if (FLAG_heap_profiler_trace_objects) { | 451 if (FLAG_heap_profiler_trace_objects) { |
| 454 PrintF("Update object size : %p with old size %d and new size %d\n", | 452 PrintF("Update object size : %p with old size %d and new size %d\n", |
| 455 addr, | 453 static_cast<void*>(addr), entry_info.size, size); |
| 456 entry_info.size, | |
| 457 size); | |
| 458 } | 454 } |
| 459 entry_info.size = size; | 455 entry_info.size = size; |
| 460 return entry_info.id; | 456 return entry_info.id; |
| 461 } | 457 } |
| 462 entry->value = reinterpret_cast<void*>(entries_.length()); | 458 entry->value = reinterpret_cast<void*>(entries_.length()); |
| 463 SnapshotObjectId id = next_id_; | 459 SnapshotObjectId id = next_id_; |
| 464 next_id_ += kObjectIdStep; | 460 next_id_ += kObjectIdStep; |
| 465 entries_.Add(EntryInfo(id, addr, size, accessed)); | 461 entries_.Add(EntryInfo(id, addr, size, accessed)); |
| 466 DCHECK(static_cast<uint32_t>(entries_.length()) > entries_map_.occupancy()); | 462 DCHECK(static_cast<uint32_t>(entries_.length()) > entries_map_.occupancy()); |
| 467 return id; | 463 return id; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 480 } | 476 } |
| 481 heap_->CollectAllGarbage(Heap::kMakeHeapIterableMask, | 477 heap_->CollectAllGarbage(Heap::kMakeHeapIterableMask, |
| 482 "HeapObjectsMap::UpdateHeapObjectsMap"); | 478 "HeapObjectsMap::UpdateHeapObjectsMap"); |
| 483 HeapIterator iterator(heap_); | 479 HeapIterator iterator(heap_); |
| 484 for (HeapObject* obj = iterator.next(); | 480 for (HeapObject* obj = iterator.next(); |
| 485 obj != NULL; | 481 obj != NULL; |
| 486 obj = iterator.next()) { | 482 obj = iterator.next()) { |
| 487 FindOrAddEntry(obj->address(), obj->Size()); | 483 FindOrAddEntry(obj->address(), obj->Size()); |
| 488 if (FLAG_heap_profiler_trace_objects) { | 484 if (FLAG_heap_profiler_trace_objects) { |
| 489 PrintF("Update object : %p %6d. Next address is %p\n", | 485 PrintF("Update object : %p %6d. Next address is %p\n", |
| 490 obj->address(), | 486 static_cast<void*>(obj->address()), obj->Size(), |
| 491 obj->Size(), | 487 static_cast<void*>(obj->address() + obj->Size())); |
| 492 obj->address() + obj->Size()); | |
| 493 } | 488 } |
| 494 } | 489 } |
| 495 RemoveDeadEntries(); | 490 RemoveDeadEntries(); |
| 496 if (FLAG_heap_profiler_trace_objects) { | 491 if (FLAG_heap_profiler_trace_objects) { |
| 497 PrintF("End HeapObjectsMap::UpdateHeapObjectsMap. map has %d entries.\n", | 492 PrintF("End HeapObjectsMap::UpdateHeapObjectsMap. map has %d entries.\n", |
| 498 entries_map_.occupancy()); | 493 entries_map_.occupancy()); |
| 499 } | 494 } |
| 500 } | 495 } |
| 501 | 496 |
| 502 | 497 |
| 503 namespace { | 498 namespace { |
| 504 | 499 |
| 505 | 500 |
| 506 struct HeapObjectInfo { | 501 struct HeapObjectInfo { |
| 507 HeapObjectInfo(HeapObject* obj, int expected_size) | 502 HeapObjectInfo(HeapObject* obj, int expected_size) |
| 508 : obj(obj), | 503 : obj(obj), |
| 509 expected_size(expected_size) { | 504 expected_size(expected_size) { |
| 510 } | 505 } |
| 511 | 506 |
| 512 HeapObject* obj; | 507 HeapObject* obj; |
| 513 int expected_size; | 508 int expected_size; |
| 514 | 509 |
| 515 bool IsValid() const { return expected_size == obj->Size(); } | 510 bool IsValid() const { return expected_size == obj->Size(); } |
| 516 | 511 |
| 517 void Print() const { | 512 void Print() const { |
| 518 if (expected_size == 0) { | 513 if (expected_size == 0) { |
| 519 PrintF("Untracked object : %p %6d. Next address is %p\n", | 514 PrintF("Untracked object : %p %6d. Next address is %p\n", |
| 520 obj->address(), | 515 static_cast<void*>(obj->address()), obj->Size(), |
| 521 obj->Size(), | 516 static_cast<void*>(obj->address() + obj->Size())); |
| 522 obj->address() + obj->Size()); | |
| 523 } else if (obj->Size() != expected_size) { | 517 } else if (obj->Size() != expected_size) { |
| 524 PrintF("Wrong size %6d: %p %6d. Next address is %p\n", | 518 PrintF("Wrong size %6d: %p %6d. Next address is %p\n", expected_size, |
| 525 expected_size, | 519 static_cast<void*>(obj->address()), obj->Size(), |
| 526 obj->address(), | 520 static_cast<void*>(obj->address() + obj->Size())); |
| 527 obj->Size(), | |
| 528 obj->address() + obj->Size()); | |
| 529 } else { | 521 } else { |
| 530 PrintF("Good object : %p %6d. Next address is %p\n", | 522 PrintF("Good object : %p %6d. Next address is %p\n", |
| 531 obj->address(), | 523 static_cast<void*>(obj->address()), expected_size, |
| 532 expected_size, | 524 static_cast<void*>(obj->address() + obj->Size())); |
| 533 obj->address() + obj->Size()); | |
| 534 } | 525 } |
| 535 } | 526 } |
| 536 }; | 527 }; |
| 537 | 528 |
| 538 | 529 |
| 539 static int comparator(const HeapObjectInfo* a, const HeapObjectInfo* b) { | 530 static int comparator(const HeapObjectInfo* a, const HeapObjectInfo* b) { |
| 540 if (a->obj < b->obj) return -1; | 531 if (a->obj < b->obj) return -1; |
| 541 if (a->obj > b->obj) return 1; | 532 if (a->obj > b->obj) return 1; |
| 542 return 0; | 533 return 0; |
| 543 } | 534 } |
| (...skipping 2579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3123 for (int i = 1; i < sorted_strings.length(); ++i) { | 3114 for (int i = 1; i < sorted_strings.length(); ++i) { |
| 3124 writer_->AddCharacter(','); | 3115 writer_->AddCharacter(','); |
| 3125 SerializeString(sorted_strings[i]); | 3116 SerializeString(sorted_strings[i]); |
| 3126 if (writer_->aborted()) return; | 3117 if (writer_->aborted()) return; |
| 3127 } | 3118 } |
| 3128 } | 3119 } |
| 3129 | 3120 |
| 3130 | 3121 |
| 3131 } // namespace internal | 3122 } // namespace internal |
| 3132 } // namespace v8 | 3123 } // namespace v8 |
| OLD | NEW |