OLD | NEW |
---|---|
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 1388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1399 entry_info.accessed = true; | 1399 entry_info.accessed = true; |
1400 ASSERT(static_cast<uint32_t>(entries_->length()) > | 1400 ASSERT(static_cast<uint32_t>(entries_->length()) > |
1401 entries_map_.occupancy()); | 1401 entries_map_.occupancy()); |
1402 return entry_info.id; | 1402 return entry_info.id; |
1403 } else { | 1403 } else { |
1404 return 0; | 1404 return 0; |
1405 } | 1405 } |
1406 } | 1406 } |
1407 | 1407 |
1408 | 1408 |
1409 SnapshotObjectId HeapObjectsMap::FindOrAddEntry(Address addr) { | |
1410 ASSERT(static_cast<uint32_t>(entries_->length()) > entries_map_.occupancy()); | |
1411 HashMap::Entry* entry = entries_map_.Lookup(addr, AddressHash(addr), true); | |
1412 if (entry->value != NULL) { | |
1413 int entry_index = | |
1414 static_cast<int>(reinterpret_cast<intptr_t>(entry->value)); | |
1415 EntryInfo& entry_info = entries_->at(entry_index); | |
1416 entry_info.accessed = true; | |
1417 return entry_info.id; | |
1418 } | |
1419 entry->value = reinterpret_cast<void*>(entries_->length()); | |
1420 SnapshotObjectId id = next_id_; | |
1421 next_id_ += kObjectIdStep; | |
1422 entries_->Add(EntryInfo(id, addr)); | |
1423 ASSERT(static_cast<uint32_t>(entries_->length()) > entries_map_.occupancy()); | |
1424 return id; | |
1425 } | |
1426 | |
1427 | |
1428 void HeapObjectsMap::StartHeapObjectsTracking() { | |
alexeif
2012/04/11 13:53:36
Do you plan to put something in here?
| |
1429 } | |
1430 | |
1431 | |
1432 void HeapObjectsMap::StopHeapObjectsTracking() { | |
1433 fragment_infos_.Clear(); | |
1434 } | |
1435 | |
1436 void HeapObjectsMap::UpdateHeapObjectsMap() { | |
1437 uint64_t start = OS::Ticks(); | |
alexeif
2012/04/11 13:53:36
leftover?
| |
1438 HEAP->CollectAllGarbage(Heap::kMakeHeapIterableMask, | |
1439 "HeapSnapshotsCollection::UpdateHeapObjectsMap"); | |
1440 int entries = 0; | |
1441 SnapshotObjectId current_id = next_id_; | |
1442 HeapIterator iterator(HeapIterator::kFilterUnreachable); | |
1443 for (HeapObject* obj = iterator.next(); | |
1444 obj != NULL; | |
1445 obj = iterator.next()) { | |
1446 FindOrAddEntry(obj->address()); | |
1447 ++entries; | |
1448 } | |
1449 initial_fill_mode_ = false; | |
1450 RemoveDeadEntries(); | |
1451 } | |
1452 | |
1453 | |
1454 void HeapObjectsMap::PushHeapObjectsStats(OutputStream* stream) { | |
1455 UpdateHeapObjectsMap(); | |
1456 uint64_t start = OS::Ticks(); | |
alexeif
2012/04/11 13:53:36
ditto
| |
1457 fragment_infos_.Add(FragmentInfo(next_id_)); | |
1458 int collected_fragment_updates = 0; | |
1459 int prefered_chunk_size = stream->GetChunkSize(); | |
1460 List<uint32_t> stats_buffer; | |
1461 ASSERT(entries_->length()); | |
1462 EntryInfo* entry_info = &entries_->first(); | |
1463 EntryInfo* end_entry_info = &entries_->last() + 1; | |
1464 uint32_t count = 0; | |
1465 for (int fragment_index = 0; | |
1466 fragment_index < fragment_infos_.length(); | |
1467 ++fragment_index) { | |
1468 FragmentInfo& fragment_info = fragment_infos_[fragment_index]; | |
1469 SnapshotObjectId fragment_id = fragment_info.id; | |
1470 while (entry_info < end_entry_info && entry_info->id < fragment_id) { | |
1471 ++count; | |
1472 ++entry_info; | |
1473 } | |
1474 if (fragment_info.count != count) { | |
1475 stats_buffer.Add(fragment_index); | |
1476 stats_buffer.Add(fragment_info.count = count); | |
1477 ++collected_fragment_updates; | |
1478 if (stats_buffer.length() >= prefered_chunk_size) { | |
1479 stream->WriteUint32Chunk(&stats_buffer.first(), | |
1480 stats_buffer.length()); | |
1481 stats_buffer.Clear(); | |
1482 } | |
1483 } | |
1484 count = 0; | |
1485 } | |
1486 ASSERT(entry_info == end_entry_info); | |
1487 if (stats_buffer.length()) { | |
1488 stream->WriteUint32Chunk(&stats_buffer.first(), stats_buffer.length()); | |
1489 } | |
1490 stream->EndOfStream(); | |
1491 } | |
1492 | |
1493 | |
1409 void HeapObjectsMap::RemoveDeadEntries() { | 1494 void HeapObjectsMap::RemoveDeadEntries() { |
1495 uint64_t start = OS::Ticks(); | |
1410 ASSERT(entries_->length() > 0 && | 1496 ASSERT(entries_->length() > 0 && |
1411 entries_->at(0).id == 0 && | 1497 entries_->at(0).id == 0 && |
1412 entries_->at(0).addr == NULL); | 1498 entries_->at(0).addr == NULL); |
1413 int first_free_entry = 1; | 1499 int first_free_entry = 1; |
1414 for (int i = 1; i < entries_->length(); ++i) { | 1500 for (int i = 1; i < entries_->length(); ++i) { |
1415 EntryInfo& entry_info = entries_->at(i); | 1501 EntryInfo& entry_info = entries_->at(i); |
1416 if (entry_info.accessed) { | 1502 if (entry_info.accessed) { |
1417 if (first_free_entry != i) { | 1503 if (first_free_entry != i) { |
1418 entries_->at(first_free_entry) = entry_info; | 1504 entries_->at(first_free_entry) = entry_info; |
1419 } | 1505 } |
(...skipping 2366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3786 | 3872 |
3787 | 3873 |
3788 void HeapSnapshotJSONSerializer::SortHashMap( | 3874 void HeapSnapshotJSONSerializer::SortHashMap( |
3789 HashMap* map, List<HashMap::Entry*>* sorted_entries) { | 3875 HashMap* map, List<HashMap::Entry*>* sorted_entries) { |
3790 for (HashMap::Entry* p = map->Start(); p != NULL; p = map->Next(p)) | 3876 for (HashMap::Entry* p = map->Start(); p != NULL; p = map->Next(p)) |
3791 sorted_entries->Add(p); | 3877 sorted_entries->Add(p); |
3792 sorted_entries->Sort(SortUsingEntryValue); | 3878 sorted_entries->Sort(SortUsingEntryValue); |
3793 } | 3879 } |
3794 | 3880 |
3795 } } // namespace v8::internal | 3881 } } // namespace v8::internal |
OLD | NEW |