| 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 974 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 985 parent_(parent), | 985 parent_(parent), |
| 986 next_index_(0) { | 986 next_index_(0) { |
| 987 } | 987 } |
| 988 void VisitCodeEntry(Address entry_address) { | 988 void VisitCodeEntry(Address entry_address) { |
| 989 Code* code = Code::cast(Code::GetObjectFromEntryAddress(entry_address)); | 989 Code* code = Code::cast(Code::GetObjectFromEntryAddress(entry_address)); |
| 990 generator_->SetInternalReference(parent_obj_, parent_, "code", code); | 990 generator_->SetInternalReference(parent_obj_, parent_, "code", code); |
| 991 generator_->TagCodeObject(code); | 991 generator_->TagCodeObject(code); |
| 992 } | 992 } |
| 993 void VisitPointers(Object** start, Object** end) { | 993 void VisitPointers(Object** start, Object** end) { |
| 994 for (Object** p = start; p < end; p++) { | 994 for (Object** p = start; p < end; p++) { |
| 995 ++next_index_; |
| 995 if (CheckVisitedAndUnmark(p)) continue; | 996 if (CheckVisitedAndUnmark(p)) continue; |
| 996 generator_->SetHiddenReference(parent_obj_, parent_, next_index_++, *p); | 997 generator_->SetHiddenReference(parent_obj_, parent_, next_index_, *p); |
| 997 } | 998 } |
| 998 } | 999 } |
| 999 static void MarkVisitedField(HeapObject* obj, int offset) { | 1000 static void MarkVisitedField(HeapObject* obj, int offset) { |
| 1000 if (offset < 0) return; | 1001 if (offset < 0) return; |
| 1001 Address field = obj->address() + offset; | 1002 Address field = obj->address() + offset; |
| 1002 ASSERT(!Memory::Object_at(field)->IsFailure()); | 1003 ASSERT(!Memory::Object_at(field)->IsFailure()); |
| 1003 ASSERT(Memory::Object_at(field)->IsHeapObject()); | 1004 ASSERT(Memory::Object_at(field)->IsHeapObject()); |
| 1004 *field |= kFailureTag; | 1005 *field |= kFailureTag; |
| 1005 } | 1006 } |
| 1006 | 1007 |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1124 == JSFunction::kSize); | 1125 == JSFunction::kSize); |
| 1125 } else if (obj->IsGlobalObject()) { | 1126 } else if (obj->IsGlobalObject()) { |
| 1126 GlobalObject* global_obj = GlobalObject::cast(obj); | 1127 GlobalObject* global_obj = GlobalObject::cast(obj); |
| 1127 SetInternalReference(global_obj, entry, | 1128 SetInternalReference(global_obj, entry, |
| 1128 "builtins", global_obj->builtins(), | 1129 "builtins", global_obj->builtins(), |
| 1129 GlobalObject::kBuiltinsOffset); | 1130 GlobalObject::kBuiltinsOffset); |
| 1130 SetInternalReference(global_obj, entry, | 1131 SetInternalReference(global_obj, entry, |
| 1131 "native_context", global_obj->native_context(), | 1132 "native_context", global_obj->native_context(), |
| 1132 GlobalObject::kNativeContextOffset); | 1133 GlobalObject::kNativeContextOffset); |
| 1133 SetInternalReference(global_obj, entry, | 1134 SetInternalReference(global_obj, entry, |
| 1135 "global_context", global_obj->global_context(), |
| 1136 GlobalObject::kGlobalContextOffset); |
| 1137 SetInternalReference(global_obj, entry, |
| 1134 "global_receiver", global_obj->global_receiver(), | 1138 "global_receiver", global_obj->global_receiver(), |
| 1135 GlobalObject::kGlobalReceiverOffset); | 1139 GlobalObject::kGlobalReceiverOffset); |
| 1140 STATIC_CHECK(GlobalObject::kHeaderSize - JSObject::kHeaderSize == |
| 1141 4 * kPointerSize); |
| 1136 } else if (obj->IsJSArrayBufferView()) { | 1142 } else if (obj->IsJSArrayBufferView()) { |
| 1137 JSArrayBufferView* view = JSArrayBufferView::cast(obj); | 1143 JSArrayBufferView* view = JSArrayBufferView::cast(obj); |
| 1138 SetInternalReference(view, entry, "buffer", view->buffer(), | 1144 SetInternalReference(view, entry, "buffer", view->buffer(), |
| 1139 JSArrayBufferView::kBufferOffset); | 1145 JSArrayBufferView::kBufferOffset); |
| 1140 SetWeakReference(view, entry, "weak_next", view->weak_next(), | 1146 SetWeakReference(view, entry, "weak_next", view->weak_next(), |
| 1141 JSArrayBufferView::kWeakNextOffset); | 1147 JSArrayBufferView::kWeakNextOffset); |
| 1142 } else if (obj->IsJSArrayBuffer()) { | 1148 } else if (obj->IsJSArrayBuffer()) { |
| 1143 JSArrayBuffer* buffer = JSArrayBuffer::cast(obj); | 1149 JSArrayBuffer* buffer = JSArrayBuffer::cast(obj); |
| 1144 SetWeakReference(buffer, entry, "weak_next", buffer->weak_next(), | 1150 SetWeakReference(buffer, entry, "weak_next", buffer->weak_next(), |
| 1145 JSArrayBuffer::kWeakNextOffset); | 1151 JSArrayBuffer::kWeakNextOffset); |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1358 SetInternalReference(code_cache, entry, | 1364 SetInternalReference(code_cache, entry, |
| 1359 "default_cache", code_cache->default_cache(), | 1365 "default_cache", code_cache->default_cache(), |
| 1360 CodeCache::kDefaultCacheOffset); | 1366 CodeCache::kDefaultCacheOffset); |
| 1361 TagObject(code_cache->normal_type_cache(), "(code type cache)"); | 1367 TagObject(code_cache->normal_type_cache(), "(code type cache)"); |
| 1362 SetInternalReference(code_cache, entry, | 1368 SetInternalReference(code_cache, entry, |
| 1363 "type_cache", code_cache->normal_type_cache(), | 1369 "type_cache", code_cache->normal_type_cache(), |
| 1364 CodeCache::kNormalTypeCacheOffset); | 1370 CodeCache::kNormalTypeCacheOffset); |
| 1365 } | 1371 } |
| 1366 | 1372 |
| 1367 | 1373 |
| 1368 void V8HeapExplorer::TagCodeObject(Code* code, const char* external_name) { | 1374 void V8HeapExplorer::TagBuiltinCodeObject(Code* code, const char* name) { |
| 1369 TagObject(code, names_->GetFormatted("(%s code)", external_name)); | 1375 TagObject(code, names_->GetFormatted("(%s builtin)", name)); |
| 1370 } | 1376 } |
| 1371 | 1377 |
| 1372 | 1378 |
| 1373 void V8HeapExplorer::TagCodeObject(Code* code) { | 1379 void V8HeapExplorer::TagCodeObject(Code* code) { |
| 1374 if (code->kind() == Code::STUB) { | 1380 if (code->kind() == Code::STUB) { |
| 1375 TagObject(code, names_->GetFormatted( | 1381 TagObject(code, names_->GetFormatted( |
| 1376 "(%s code)", CodeStub::MajorName( | 1382 "(%s code)", CodeStub::MajorName( |
| 1377 static_cast<CodeStub::Major>(code->major_key()), true))); | 1383 static_cast<CodeStub::Major>(code->major_key()), true))); |
| 1378 } | 1384 } |
| 1379 } | 1385 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1396 SetInternalReference(code, entry, | 1402 SetInternalReference(code, entry, |
| 1397 "type_feedback_info", code->type_feedback_info(), | 1403 "type_feedback_info", code->type_feedback_info(), |
| 1398 Code::kTypeFeedbackInfoOffset); | 1404 Code::kTypeFeedbackInfoOffset); |
| 1399 } | 1405 } |
| 1400 SetInternalReference(code, entry, | 1406 SetInternalReference(code, entry, |
| 1401 "gc_metadata", code->gc_metadata(), | 1407 "gc_metadata", code->gc_metadata(), |
| 1402 Code::kGCMetadataOffset); | 1408 Code::kGCMetadataOffset); |
| 1403 SetInternalReference(code, entry, | 1409 SetInternalReference(code, entry, |
| 1404 "constant_pool", code->constant_pool(), | 1410 "constant_pool", code->constant_pool(), |
| 1405 Code::kConstantPoolOffset); | 1411 Code::kConstantPoolOffset); |
| 1412 if (code->kind() == Code::OPTIMIZED_FUNCTION) { |
| 1413 SetWeakReference(code, entry, |
| 1414 "next_code_link", code->next_code_link(), |
| 1415 Code::kNextCodeLinkOffset); |
| 1416 } |
| 1406 } | 1417 } |
| 1407 | 1418 |
| 1408 | 1419 |
| 1409 void V8HeapExplorer::ExtractCellReferences(int entry, Cell* cell) { | 1420 void V8HeapExplorer::ExtractCellReferences(int entry, Cell* cell) { |
| 1410 SetInternalReference(cell, entry, "value", cell->value(), Cell::kValueOffset); | 1421 SetInternalReference(cell, entry, "value", cell->value(), Cell::kValueOffset); |
| 1411 } | 1422 } |
| 1412 | 1423 |
| 1413 | 1424 |
| 1414 void V8HeapExplorer::ExtractPropertyCellReferences(int entry, | 1425 void V8HeapExplorer::ExtractPropertyCellReferences(int entry, |
| 1415 PropertyCell* cell) { | 1426 PropertyCell* cell) { |
| 1416 ExtractCellReferences(entry, cell); | 1427 ExtractCellReferences(entry, cell); |
| 1417 SetInternalReference(cell, entry, "type", cell->type(), | 1428 SetInternalReference(cell, entry, "type", cell->type(), |
| 1418 PropertyCell::kTypeOffset); | 1429 PropertyCell::kTypeOffset); |
| 1419 SetInternalReference(cell, entry, "dependent_code", cell->dependent_code(), | 1430 SetInternalReference(cell, entry, "dependent_code", cell->dependent_code(), |
| 1420 PropertyCell::kDependentCodeOffset); | 1431 PropertyCell::kDependentCodeOffset); |
| 1421 } | 1432 } |
| 1422 | 1433 |
| 1423 | 1434 |
| 1424 void V8HeapExplorer::ExtractAllocationSiteReferences(int entry, | 1435 void V8HeapExplorer::ExtractAllocationSiteReferences(int entry, |
| 1425 AllocationSite* site) { | 1436 AllocationSite* site) { |
| 1426 SetInternalReference(site, entry, "transition_info", site->transition_info(), | 1437 SetInternalReference(site, entry, "transition_info", site->transition_info(), |
| 1427 AllocationSite::kTransitionInfoOffset); | 1438 AllocationSite::kTransitionInfoOffset); |
| 1428 SetInternalReference(site, entry, "nested_site", site->nested_site(), | 1439 SetInternalReference(site, entry, "nested_site", site->nested_site(), |
| 1429 AllocationSite::kNestedSiteOffset); | 1440 AllocationSite::kNestedSiteOffset); |
| 1430 SetInternalReference(site, entry, "pretenure_data", | |
| 1431 site->pretenure_data(), | |
| 1432 AllocationSite::kPretenureDataOffset); | |
| 1433 SetInternalReference(site, entry, "pretenure_create_count", | |
| 1434 site->pretenure_create_count(), | |
| 1435 AllocationSite::kPretenureCreateCountOffset); | |
| 1436 SetInternalReference(site, entry, "dependent_code", site->dependent_code(), | 1441 SetInternalReference(site, entry, "dependent_code", site->dependent_code(), |
| 1437 AllocationSite::kDependentCodeOffset); | 1442 AllocationSite::kDependentCodeOffset); |
| 1443 // Do not visit weak_next as it is not visited by the StaticVisitor, |
| 1444 // and we're not very interested in weak_next field here. |
| 1445 STATIC_CHECK(AllocationSite::kWeakNextOffset >= |
| 1446 AllocationSite::BodyDescriptor::kEndOffset); |
| 1438 } | 1447 } |
| 1439 | 1448 |
| 1440 | 1449 |
| 1441 void V8HeapExplorer::ExtractClosureReferences(JSObject* js_obj, int entry) { | 1450 void V8HeapExplorer::ExtractClosureReferences(JSObject* js_obj, int entry) { |
| 1442 if (!js_obj->IsJSFunction()) return; | 1451 if (!js_obj->IsJSFunction()) return; |
| 1443 | 1452 |
| 1444 JSFunction* func = JSFunction::cast(js_obj); | 1453 JSFunction* func = JSFunction::cast(js_obj); |
| 1445 if (func->shared()->bound()) { | 1454 if (func->shared()->bound()) { |
| 1446 FixedArray* bindings = func->function_bindings(); | 1455 FixedArray* bindings = func->function_bindings(); |
| 1447 SetNativeBindReference(js_obj, entry, "bound_this", | 1456 SetNativeBindReference(js_obj, entry, "bound_this", |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1652 void SetCollectingAllReferences() { collecting_all_references_ = true; } | 1661 void SetCollectingAllReferences() { collecting_all_references_ = true; } |
| 1653 | 1662 |
| 1654 void FillReferences(V8HeapExplorer* explorer) { | 1663 void FillReferences(V8HeapExplorer* explorer) { |
| 1655 ASSERT(strong_references_.length() <= all_references_.length()); | 1664 ASSERT(strong_references_.length() <= all_references_.length()); |
| 1656 Builtins* builtins = heap_->isolate()->builtins(); | 1665 Builtins* builtins = heap_->isolate()->builtins(); |
| 1657 for (int i = 0; i < reference_tags_.length(); ++i) { | 1666 for (int i = 0; i < reference_tags_.length(); ++i) { |
| 1658 explorer->SetGcRootsReference(reference_tags_[i].tag); | 1667 explorer->SetGcRootsReference(reference_tags_[i].tag); |
| 1659 } | 1668 } |
| 1660 int strong_index = 0, all_index = 0, tags_index = 0, builtin_index = 0; | 1669 int strong_index = 0, all_index = 0, tags_index = 0, builtin_index = 0; |
| 1661 while (all_index < all_references_.length()) { | 1670 while (all_index < all_references_.length()) { |
| 1662 if (strong_index < strong_references_.length() && | 1671 bool is_strong = strong_index < strong_references_.length() |
| 1663 strong_references_[strong_index] == all_references_[all_index]) { | 1672 && strong_references_[strong_index] == all_references_[all_index]; |
| 1664 explorer->SetGcSubrootReference(reference_tags_[tags_index].tag, | 1673 explorer->SetGcSubrootReference(reference_tags_[tags_index].tag, |
| 1665 false, | 1674 !is_strong, |
| 1666 all_references_[all_index]); | 1675 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 == | 1676 if (reference_tags_[tags_index].tag == |
| 1674 VisitorSynchronization::kBuiltins) { | 1677 VisitorSynchronization::kBuiltins) { |
| 1675 ASSERT(all_references_[all_index]->IsCode()); | 1678 ASSERT(all_references_[all_index]->IsCode()); |
| 1676 explorer->TagCodeObject(Code::cast(all_references_[all_index]), | 1679 explorer->TagBuiltinCodeObject( |
| 1680 Code::cast(all_references_[all_index]), |
| 1677 builtins->name(builtin_index++)); | 1681 builtins->name(builtin_index++)); |
| 1678 } | 1682 } |
| 1679 ++all_index; | 1683 ++all_index; |
| 1684 if (is_strong) ++strong_index; |
| 1680 if (reference_tags_[tags_index].index == all_index) ++tags_index; | 1685 if (reference_tags_[tags_index].index == all_index) ++tags_index; |
| 1681 } | 1686 } |
| 1682 } | 1687 } |
| 1683 | 1688 |
| 1684 void Synchronize(VisitorSynchronization::SyncTag tag) { | 1689 void Synchronize(VisitorSynchronization::SyncTag tag) { |
| 1685 if (collecting_all_references_ && | 1690 if (collecting_all_references_ && |
| 1686 previous_reference_count_ != all_references_.length()) { | 1691 previous_reference_count_ != all_references_.length()) { |
| 1687 previous_reference_count_ = all_references_.length(); | 1692 previous_reference_count_ = all_references_.length(); |
| 1688 reference_tags_.Add(IndexTag(previous_reference_count_, tag)); | 1693 reference_tags_.Add(IndexTag(previous_reference_count_, tag)); |
| 1689 } | 1694 } |
| 1690 } | 1695 } |
| 1691 | 1696 |
| 1692 private: | 1697 private: |
| 1693 bool collecting_all_references_; | 1698 bool collecting_all_references_; |
| 1694 List<Object*> strong_references_; | 1699 List<Object*> strong_references_; |
| 1695 List<Object*> all_references_; | 1700 List<Object*> all_references_; |
| 1696 int previous_reference_count_; | 1701 int previous_reference_count_; |
| 1697 List<IndexTag> reference_tags_; | 1702 List<IndexTag> reference_tags_; |
| 1698 Heap* heap_; | 1703 Heap* heap_; |
| 1699 }; | 1704 }; |
| 1700 | 1705 |
| 1701 | 1706 |
| 1702 bool V8HeapExplorer::IterateAndExtractReferences( | 1707 bool V8HeapExplorer::IterateAndExtractReferences( |
| 1703 SnapshotFillerInterface* filler) { | 1708 SnapshotFillerInterface* filler) { |
| 1709 filler_ = filler; |
| 1710 |
| 1711 // Make sure builtin code objects get their builtin tags |
| 1712 // first. Otherwise a particular JSFunction object could set |
| 1713 // its custom name to a generic builtin. |
| 1714 SetRootGcRootsReference(); |
| 1715 RootsReferencesExtractor extractor(heap_); |
| 1716 heap_->IterateRoots(&extractor, VISIT_ONLY_STRONG); |
| 1717 extractor.SetCollectingAllReferences(); |
| 1718 heap_->IterateRoots(&extractor, VISIT_ALL); |
| 1719 extractor.FillReferences(this); |
| 1720 |
| 1721 // Now iterate the whole heap. |
| 1722 bool interrupted = false; |
| 1704 HeapIterator iterator(heap_, HeapIterator::kFilterUnreachable); | 1723 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. | 1724 // Heap iteration with filtering must be finished in any case. |
| 1710 for (HeapObject* obj = iterator.next(); | 1725 for (HeapObject* obj = iterator.next(); |
| 1711 obj != NULL; | 1726 obj != NULL; |
| 1712 obj = iterator.next(), progress_->ProgressStep()) { | 1727 obj = iterator.next(), progress_->ProgressStep()) { |
| 1713 if (!interrupted) { | 1728 if (!interrupted) { |
| 1714 ExtractReferences(obj); | 1729 ExtractReferences(obj); |
| 1715 if (!progress_->ProgressReport(false)) interrupted = true; | 1730 if (!progress_->ProgressReport(false)) interrupted = true; |
| 1716 } | 1731 } |
| 1717 } | 1732 } |
| 1718 if (interrupted) { | 1733 if (interrupted) { |
| 1719 filler_ = NULL; | 1734 filler_ = NULL; |
| 1720 return false; | 1735 return false; |
| 1721 } | 1736 } |
| 1722 | 1737 |
| 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; | 1738 filler_ = NULL; |
| 1730 return progress_->ProgressReport(true); | 1739 return progress_->ProgressReport(true); |
| 1731 } | 1740 } |
| 1732 | 1741 |
| 1733 | 1742 |
| 1734 bool V8HeapExplorer::IsEssentialObject(Object* object) { | 1743 bool V8HeapExplorer::IsEssentialObject(Object* object) { |
| 1735 return object->IsHeapObject() | 1744 return object->IsHeapObject() |
| 1736 && !object->IsOddball() | 1745 && !object->IsOddball() |
| 1737 && object != heap_->empty_byte_array() | 1746 && object != heap_->empty_byte_array() |
| 1738 && object != heap_->empty_fixed_array() | 1747 && object != heap_->empty_fixed_array() |
| (...skipping 1245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2984 writer_->AddString("\"<dummy>\""); | 2993 writer_->AddString("\"<dummy>\""); |
| 2985 for (int i = 1; i < sorted_strings.length(); ++i) { | 2994 for (int i = 1; i < sorted_strings.length(); ++i) { |
| 2986 writer_->AddCharacter(','); | 2995 writer_->AddCharacter(','); |
| 2987 SerializeString(sorted_strings[i]); | 2996 SerializeString(sorted_strings[i]); |
| 2988 if (writer_->aborted()) return; | 2997 if (writer_->aborted()) return; |
| 2989 } | 2998 } |
| 2990 } | 2999 } |
| 2991 | 3000 |
| 2992 | 3001 |
| 2993 } } // namespace v8::internal | 3002 } } // namespace v8::internal |
| OLD | NEW |