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) { | |
mnaganov (inactive)
2012/04/11 14:35:40
This functions seems to reuse code from FindEntry,
| |
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() { | |
1429 } | |
1430 | |
1431 | |
1432 void HeapObjectsMap::StopHeapObjectsTracking() { | |
1433 fragment_infos_.Clear(); | |
1434 } | |
1435 | |
1436 void HeapObjectsMap::UpdateHeapObjectsMap() { | |
1437 HEAP->CollectAllGarbage(Heap::kMakeHeapIterableMask, | |
1438 "HeapSnapshotsCollection::UpdateHeapObjectsMap"); | |
1439 int entries = 0; | |
1440 HeapIterator iterator(HeapIterator::kFilterUnreachable); | |
1441 for (HeapObject* obj = iterator.next(); | |
1442 obj != NULL; | |
1443 obj = iterator.next()) { | |
1444 FindOrAddEntry(obj->address()); | |
1445 ++entries; | |
1446 } | |
1447 initial_fill_mode_ = false; | |
1448 RemoveDeadEntries(); | |
1449 } | |
1450 | |
1451 | |
1452 void HeapObjectsMap::PushHeapObjectsStats(OutputStream* stream) { | |
1453 UpdateHeapObjectsMap(); | |
1454 fragment_infos_.Add(FragmentInfo(next_id_)); | |
1455 int collected_fragment_updates = 0; | |
mnaganov (inactive)
2012/04/11 14:35:40
This variable seems to be write-only.
| |
1456 int prefered_chunk_size = stream->GetChunkSize(); | |
1457 List<uint32_t> stats_buffer; | |
1458 ASSERT(entries_->length()); | |
1459 EntryInfo* entry_info = &entries_->first(); | |
1460 EntryInfo* end_entry_info = &entries_->last() + 1; | |
1461 uint32_t count = 0; | |
1462 for (int fragment_index = 0; | |
1463 fragment_index < fragment_infos_.length(); | |
1464 ++fragment_index) { | |
1465 FragmentInfo& fragment_info = fragment_infos_[fragment_index]; | |
1466 SnapshotObjectId fragment_id = fragment_info.id; | |
1467 while (entry_info < end_entry_info && entry_info->id < fragment_id) { | |
1468 ++count; | |
1469 ++entry_info; | |
1470 } | |
1471 if (fragment_info.count != count) { | |
1472 stats_buffer.Add(fragment_index); | |
1473 stats_buffer.Add(fragment_info.count = count); | |
1474 ++collected_fragment_updates; | |
1475 if (stats_buffer.length() >= prefered_chunk_size) { | |
1476 stream->WriteUint32Chunk(&stats_buffer.first(), | |
1477 stats_buffer.length()); | |
1478 stats_buffer.Clear(); | |
1479 } | |
1480 } | |
1481 count = 0; | |
1482 } | |
1483 ASSERT(entry_info == end_entry_info); | |
1484 if (stats_buffer.length()) { | |
1485 stream->WriteUint32Chunk(&stats_buffer.first(), stats_buffer.length()); | |
1486 } | |
1487 stream->EndOfStream(); | |
1488 } | |
1489 | |
1490 | |
1409 void HeapObjectsMap::RemoveDeadEntries() { | 1491 void HeapObjectsMap::RemoveDeadEntries() { |
1410 ASSERT(entries_->length() > 0 && | 1492 ASSERT(entries_->length() > 0 && |
1411 entries_->at(0).id == 0 && | 1493 entries_->at(0).id == 0 && |
1412 entries_->at(0).addr == NULL); | 1494 entries_->at(0).addr == NULL); |
1413 int first_free_entry = 1; | 1495 int first_free_entry = 1; |
1414 for (int i = 1; i < entries_->length(); ++i) { | 1496 for (int i = 1; i < entries_->length(); ++i) { |
1415 EntryInfo& entry_info = entries_->at(i); | 1497 EntryInfo& entry_info = entries_->at(i); |
1416 if (entry_info.accessed) { | 1498 if (entry_info.accessed) { |
1417 if (first_free_entry != i) { | 1499 if (first_free_entry != i) { |
1418 entries_->at(first_free_entry) = entry_info; | 1500 entries_->at(first_free_entry) = entry_info; |
(...skipping 2367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3786 | 3868 |
3787 | 3869 |
3788 void HeapSnapshotJSONSerializer::SortHashMap( | 3870 void HeapSnapshotJSONSerializer::SortHashMap( |
3789 HashMap* map, List<HashMap::Entry*>* sorted_entries) { | 3871 HashMap* map, List<HashMap::Entry*>* sorted_entries) { |
3790 for (HashMap::Entry* p = map->Start(); p != NULL; p = map->Next(p)) | 3872 for (HashMap::Entry* p = map->Start(); p != NULL; p = map->Next(p)) |
3791 sorted_entries->Add(p); | 3873 sorted_entries->Add(p); |
3792 sorted_entries->Sort(SortUsingEntryValue); | 3874 sorted_entries->Sort(SortUsingEntryValue); |
3793 } | 3875 } |
3794 | 3876 |
3795 } } // namespace v8::internal | 3877 } } // namespace v8::internal |
OLD | NEW |