OLD | NEW |
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 1347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1358 SetInternalReference(code_cache, entry, | 1358 SetInternalReference(code_cache, entry, |
1359 "default_cache", code_cache->default_cache(), | 1359 "default_cache", code_cache->default_cache(), |
1360 CodeCache::kDefaultCacheOffset); | 1360 CodeCache::kDefaultCacheOffset); |
1361 TagObject(code_cache->normal_type_cache(), "(code type cache)"); | 1361 TagObject(code_cache->normal_type_cache(), "(code type cache)"); |
1362 SetInternalReference(code_cache, entry, | 1362 SetInternalReference(code_cache, entry, |
1363 "type_cache", code_cache->normal_type_cache(), | 1363 "type_cache", code_cache->normal_type_cache(), |
1364 CodeCache::kNormalTypeCacheOffset); | 1364 CodeCache::kNormalTypeCacheOffset); |
1365 } | 1365 } |
1366 | 1366 |
1367 | 1367 |
1368 void V8HeapExplorer::TagCodeObject(Code* code, const char* external_name) { | 1368 void V8HeapExplorer::TagBuiltinCodeObject(Code* code, const char* name) { |
1369 TagObject(code, names_->GetFormatted("(%s code)", external_name)); | 1369 TagObject(code, names_->GetFormatted("(%s builtin)", name)); |
1370 } | 1370 } |
1371 | 1371 |
1372 | 1372 |
1373 void V8HeapExplorer::TagCodeObject(Code* code) { | 1373 void V8HeapExplorer::TagCodeObject(Code* code) { |
1374 if (code->kind() == Code::STUB) { | 1374 if (code->kind() == Code::STUB) { |
1375 TagObject(code, names_->GetFormatted( | 1375 TagObject(code, names_->GetFormatted( |
1376 "(%s code)", CodeStub::MajorName( | 1376 "(%s code)", CodeStub::MajorName( |
1377 static_cast<CodeStub::Major>(code->major_key()), true))); | 1377 static_cast<CodeStub::Major>(code->major_key()), true))); |
1378 } | 1378 } |
1379 } | 1379 } |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1652 void SetCollectingAllReferences() { collecting_all_references_ = true; } | 1652 void SetCollectingAllReferences() { collecting_all_references_ = true; } |
1653 | 1653 |
1654 void FillReferences(V8HeapExplorer* explorer) { | 1654 void FillReferences(V8HeapExplorer* explorer) { |
1655 ASSERT(strong_references_.length() <= all_references_.length()); | 1655 ASSERT(strong_references_.length() <= all_references_.length()); |
1656 Builtins* builtins = heap_->isolate()->builtins(); | 1656 Builtins* builtins = heap_->isolate()->builtins(); |
1657 for (int i = 0; i < reference_tags_.length(); ++i) { | 1657 for (int i = 0; i < reference_tags_.length(); ++i) { |
1658 explorer->SetGcRootsReference(reference_tags_[i].tag); | 1658 explorer->SetGcRootsReference(reference_tags_[i].tag); |
1659 } | 1659 } |
1660 int strong_index = 0, all_index = 0, tags_index = 0, builtin_index = 0; | 1660 int strong_index = 0, all_index = 0, tags_index = 0, builtin_index = 0; |
1661 while (all_index < all_references_.length()) { | 1661 while (all_index < all_references_.length()) { |
1662 if (strong_index < strong_references_.length() && | 1662 bool is_strong = strong_index < strong_references_.length() |
1663 strong_references_[strong_index] == all_references_[all_index]) { | 1663 && strong_references_[strong_index] == all_references_[all_index]; |
1664 explorer->SetGcSubrootReference(reference_tags_[tags_index].tag, | 1664 explorer->SetGcSubrootReference(reference_tags_[tags_index].tag, |
1665 false, | 1665 !is_strong, |
1666 all_references_[all_index]); | 1666 all_references_[all_index]); |
1667 ++strong_index; | |
1668 } else { | |
1669 explorer->SetGcSubrootReference(reference_tags_[tags_index].tag, | |
1670 true, | |
1671 all_references_[all_index]); | |
1672 } | |
1673 if (reference_tags_[tags_index].tag == | 1667 if (reference_tags_[tags_index].tag == |
1674 VisitorSynchronization::kBuiltins) { | 1668 VisitorSynchronization::kBuiltins) { |
1675 ASSERT(all_references_[all_index]->IsCode()); | 1669 ASSERT(all_references_[all_index]->IsCode()); |
1676 explorer->TagCodeObject(Code::cast(all_references_[all_index]), | 1670 explorer->TagBuiltinCodeObject( |
| 1671 Code::cast(all_references_[all_index]), |
1677 builtins->name(builtin_index++)); | 1672 builtins->name(builtin_index++)); |
1678 } | 1673 } |
1679 ++all_index; | 1674 ++all_index; |
| 1675 if (is_strong) ++strong_index; |
1680 if (reference_tags_[tags_index].index == all_index) ++tags_index; | 1676 if (reference_tags_[tags_index].index == all_index) ++tags_index; |
1681 } | 1677 } |
1682 } | 1678 } |
1683 | 1679 |
1684 void Synchronize(VisitorSynchronization::SyncTag tag) { | 1680 void Synchronize(VisitorSynchronization::SyncTag tag) { |
1685 if (collecting_all_references_ && | 1681 if (collecting_all_references_ && |
1686 previous_reference_count_ != all_references_.length()) { | 1682 previous_reference_count_ != all_references_.length()) { |
1687 previous_reference_count_ = all_references_.length(); | 1683 previous_reference_count_ = all_references_.length(); |
1688 reference_tags_.Add(IndexTag(previous_reference_count_, tag)); | 1684 reference_tags_.Add(IndexTag(previous_reference_count_, tag)); |
1689 } | 1685 } |
1690 } | 1686 } |
1691 | 1687 |
1692 private: | 1688 private: |
1693 bool collecting_all_references_; | 1689 bool collecting_all_references_; |
1694 List<Object*> strong_references_; | 1690 List<Object*> strong_references_; |
1695 List<Object*> all_references_; | 1691 List<Object*> all_references_; |
1696 int previous_reference_count_; | 1692 int previous_reference_count_; |
1697 List<IndexTag> reference_tags_; | 1693 List<IndexTag> reference_tags_; |
1698 Heap* heap_; | 1694 Heap* heap_; |
1699 }; | 1695 }; |
1700 | 1696 |
1701 | 1697 |
1702 bool V8HeapExplorer::IterateAndExtractReferences( | 1698 bool V8HeapExplorer::IterateAndExtractReferences( |
1703 SnapshotFillerInterface* filler) { | 1699 SnapshotFillerInterface* filler) { |
| 1700 filler_ = filler; |
| 1701 |
| 1702 // Make sure builtin code objects get their builtin tags |
| 1703 // first. Otherwise a particular JSFunction object could set |
| 1704 // its custom name to a generic builtin. |
| 1705 SetRootGcRootsReference(); |
| 1706 RootsReferencesExtractor extractor(heap_); |
| 1707 heap_->IterateRoots(&extractor, VISIT_ONLY_STRONG); |
| 1708 extractor.SetCollectingAllReferences(); |
| 1709 heap_->IterateRoots(&extractor, VISIT_ALL); |
| 1710 extractor.FillReferences(this); |
| 1711 |
| 1712 // Now iterate the whole heap. |
| 1713 bool interrupted = false; |
1704 HeapIterator iterator(heap_, HeapIterator::kFilterUnreachable); | 1714 HeapIterator iterator(heap_, HeapIterator::kFilterUnreachable); |
1705 | |
1706 filler_ = filler; | |
1707 bool interrupted = false; | |
1708 | |
1709 // Heap iteration with filtering must be finished in any case. | 1715 // Heap iteration with filtering must be finished in any case. |
1710 for (HeapObject* obj = iterator.next(); | 1716 for (HeapObject* obj = iterator.next(); |
1711 obj != NULL; | 1717 obj != NULL; |
1712 obj = iterator.next(), progress_->ProgressStep()) { | 1718 obj = iterator.next(), progress_->ProgressStep()) { |
1713 if (!interrupted) { | 1719 if (!interrupted) { |
1714 ExtractReferences(obj); | 1720 ExtractReferences(obj); |
1715 if (!progress_->ProgressReport(false)) interrupted = true; | 1721 if (!progress_->ProgressReport(false)) interrupted = true; |
1716 } | 1722 } |
1717 } | 1723 } |
1718 if (interrupted) { | 1724 if (interrupted) { |
1719 filler_ = NULL; | 1725 filler_ = NULL; |
1720 return false; | 1726 return false; |
1721 } | 1727 } |
1722 | 1728 |
1723 SetRootGcRootsReference(); | |
1724 RootsReferencesExtractor extractor(heap_); | |
1725 heap_->IterateRoots(&extractor, VISIT_ONLY_STRONG); | |
1726 extractor.SetCollectingAllReferences(); | |
1727 heap_->IterateRoots(&extractor, VISIT_ALL); | |
1728 extractor.FillReferences(this); | |
1729 filler_ = NULL; | 1729 filler_ = NULL; |
1730 return progress_->ProgressReport(true); | 1730 return progress_->ProgressReport(true); |
1731 } | 1731 } |
1732 | 1732 |
1733 | 1733 |
1734 bool V8HeapExplorer::IsEssentialObject(Object* object) { | 1734 bool V8HeapExplorer::IsEssentialObject(Object* object) { |
1735 return object->IsHeapObject() | 1735 return object->IsHeapObject() |
1736 && !object->IsOddball() | 1736 && !object->IsOddball() |
1737 && object != heap_->empty_byte_array() | 1737 && object != heap_->empty_byte_array() |
1738 && object != heap_->empty_fixed_array() | 1738 && object != heap_->empty_fixed_array() |
(...skipping 1245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2984 writer_->AddString("\"<dummy>\""); | 2984 writer_->AddString("\"<dummy>\""); |
2985 for (int i = 1; i < sorted_strings.length(); ++i) { | 2985 for (int i = 1; i < sorted_strings.length(); ++i) { |
2986 writer_->AddCharacter(','); | 2986 writer_->AddCharacter(','); |
2987 SerializeString(sorted_strings[i]); | 2987 SerializeString(sorted_strings[i]); |
2988 if (writer_->aborted()) return; | 2988 if (writer_->aborted()) return; |
2989 } | 2989 } |
2990 } | 2990 } |
2991 | 2991 |
2992 | 2992 |
2993 } } // namespace v8::internal | 2993 } } // namespace v8::internal |
OLD | NEW |