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::StopHeapObjectsTracking() { |
| 1429 time_intervals_.Clear(); |
| 1430 } |
| 1431 |
| 1432 void HeapObjectsMap::UpdateHeapObjectsMap() { |
| 1433 HEAP->CollectAllGarbage(Heap::kMakeHeapIterableMask, |
| 1434 "HeapSnapshotsCollection::UpdateHeapObjectsMap"); |
| 1435 HeapIterator iterator(HeapIterator::kFilterUnreachable); |
| 1436 for (HeapObject* obj = iterator.next(); |
| 1437 obj != NULL; |
| 1438 obj = iterator.next()) { |
| 1439 FindOrAddEntry(obj->address()); |
| 1440 } |
| 1441 initial_fill_mode_ = false; |
| 1442 RemoveDeadEntries(); |
| 1443 } |
| 1444 |
| 1445 |
| 1446 void HeapObjectsMap::PushHeapObjectsStats(OutputStream* stream) { |
| 1447 UpdateHeapObjectsMap(); |
| 1448 time_intervals_.Add(TimeInterval(next_id_)); |
| 1449 int prefered_chunk_size = stream->GetChunkSize(); |
| 1450 List<uint32_t> stats_buffer; |
| 1451 ASSERT(!entries_->is_empty()); |
| 1452 EntryInfo* entry_info = &entries_->first(); |
| 1453 EntryInfo* end_entry_info = &entries_->last() + 1; |
| 1454 for (int time_interval_index = 0; |
| 1455 time_interval_index < time_intervals_.length(); |
| 1456 ++time_interval_index) { |
| 1457 TimeInterval& time_interval = time_intervals_[time_interval_index]; |
| 1458 SnapshotObjectId time_interval_id = time_interval.id; |
| 1459 uint32_t entries_count = 0; |
| 1460 while (entry_info < end_entry_info && entry_info->id < time_interval_id) { |
| 1461 ++entries_count; |
| 1462 ++entry_info; |
| 1463 } |
| 1464 if (time_interval.count != entries_count) { |
| 1465 stats_buffer.Add(time_interval_index); |
| 1466 stats_buffer.Add(time_interval.count = entries_count); |
| 1467 if (stats_buffer.length() >= prefered_chunk_size) { |
| 1468 OutputStream::WriteResult result = stream->WriteUint32Chunk( |
| 1469 &stats_buffer.first(), stats_buffer.length()); |
| 1470 if (result == OutputStream::kAbort) return; |
| 1471 stats_buffer.Clear(); |
| 1472 } |
| 1473 } |
| 1474 } |
| 1475 ASSERT(entry_info == end_entry_info); |
| 1476 if (!stats_buffer.is_empty()) { |
| 1477 OutputStream::WriteResult result = |
| 1478 stream->WriteUint32Chunk(&stats_buffer.first(), stats_buffer.length()); |
| 1479 if (result == OutputStream::kAbort) return; |
| 1480 } |
| 1481 stream->EndOfStream(); |
| 1482 } |
| 1483 |
| 1484 |
1409 void HeapObjectsMap::RemoveDeadEntries() { | 1485 void HeapObjectsMap::RemoveDeadEntries() { |
1410 ASSERT(entries_->length() > 0 && | 1486 ASSERT(entries_->length() > 0 && |
1411 entries_->at(0).id == 0 && | 1487 entries_->at(0).id == 0 && |
1412 entries_->at(0).addr == NULL); | 1488 entries_->at(0).addr == NULL); |
1413 int first_free_entry = 1; | 1489 int first_free_entry = 1; |
1414 for (int i = 1; i < entries_->length(); ++i) { | 1490 for (int i = 1; i < entries_->length(); ++i) { |
1415 EntryInfo& entry_info = entries_->at(i); | 1491 EntryInfo& entry_info = entries_->at(i); |
1416 if (entry_info.accessed) { | 1492 if (entry_info.accessed) { |
1417 if (first_free_entry != i) { | 1493 if (first_free_entry != i) { |
1418 entries_->at(first_free_entry) = entry_info; | 1494 entries_->at(first_free_entry) = entry_info; |
(...skipping 2367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3786 | 3862 |
3787 | 3863 |
3788 void HeapSnapshotJSONSerializer::SortHashMap( | 3864 void HeapSnapshotJSONSerializer::SortHashMap( |
3789 HashMap* map, List<HashMap::Entry*>* sorted_entries) { | 3865 HashMap* map, List<HashMap::Entry*>* sorted_entries) { |
3790 for (HashMap::Entry* p = map->Start(); p != NULL; p = map->Next(p)) | 3866 for (HashMap::Entry* p = map->Start(); p != NULL; p = map->Next(p)) |
3791 sorted_entries->Add(p); | 3867 sorted_entries->Add(p); |
3792 sorted_entries->Sort(SortUsingEntryValue); | 3868 sorted_entries->Sort(SortUsingEntryValue); |
3793 } | 3869 } |
3794 | 3870 |
3795 } } // namespace v8::internal | 3871 } } // namespace v8::internal |
OLD | NEW |