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 1657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1668 SharedFunctionInfo* shared = func->shared(); | 1668 SharedFunctionInfo* shared = func->shared(); |
1669 const char* name = shared->bound() ? "native_bind" : | 1669 const char* name = shared->bound() ? "native_bind" : |
1670 collection_->names()->GetName(String::cast(shared->name())); | 1670 collection_->names()->GetName(String::cast(shared->name())); |
1671 return AddEntry(object, HeapEntry::kClosure, name); | 1671 return AddEntry(object, HeapEntry::kClosure, name); |
1672 } else if (object->IsJSRegExp()) { | 1672 } else if (object->IsJSRegExp()) { |
1673 JSRegExp* re = JSRegExp::cast(object); | 1673 JSRegExp* re = JSRegExp::cast(object); |
1674 return AddEntry(object, | 1674 return AddEntry(object, |
1675 HeapEntry::kRegExp, | 1675 HeapEntry::kRegExp, |
1676 collection_->names()->GetName(re->Pattern())); | 1676 collection_->names()->GetName(re->Pattern())); |
1677 } else if (object->IsJSObject()) { | 1677 } else if (object->IsJSObject()) { |
1678 return AddEntry(object, HeapEntry::kObject, ""); | 1678 const char* name = collection_->names()->GetName( |
1679 GetConstructorName(JSObject::cast(object))); | |
1680 if (object->IsJSGlobalObject()) { | |
1681 const char* tag = objects_tags_.GetTag(object); | |
yurys
2012/05/10 12:13:52
How can we be sure that the object has already bee
mnaganov (inactive)
2012/05/10 12:15:56
Global objects tagging is always done before snaps
yurys
2012/05/10 12:23:31
I think a comment would be helpful here. Also what
alexeif
2012/05/10 13:40:24
Yep, looks like non-global objects, i.e. arrays th
| |
1682 if (tag != NULL) { | |
1683 name = collection_->names()->GetFormatted("%s / %s", name, tag); | |
1684 } | |
1685 } | |
1686 return AddEntry(object, HeapEntry::kObject, name); | |
1679 } else if (object->IsString()) { | 1687 } else if (object->IsString()) { |
1680 return AddEntry(object, | 1688 return AddEntry(object, |
1681 HeapEntry::kString, | 1689 HeapEntry::kString, |
1682 collection_->names()->GetName(String::cast(object))); | 1690 collection_->names()->GetName(String::cast(object))); |
1683 } else if (object->IsCode()) { | 1691 } else if (object->IsCode()) { |
1684 return AddEntry(object, HeapEntry::kCode, ""); | 1692 return AddEntry(object, HeapEntry::kCode, ""); |
1685 } else if (object->IsSharedFunctionInfo()) { | 1693 } else if (object->IsSharedFunctionInfo()) { |
1686 String* name = String::cast(SharedFunctionInfo::cast(object)->name()); | 1694 String* name = String::cast(SharedFunctionInfo::cast(object)->name()); |
1687 return AddEntry(object, | 1695 return AddEntry(object, |
1688 HeapEntry::kCode, | 1696 HeapEntry::kCode, |
(...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2389 RootsReferencesExtractor extractor; | 2397 RootsReferencesExtractor extractor; |
2390 heap_->IterateRoots(&extractor, VISIT_ONLY_STRONG); | 2398 heap_->IterateRoots(&extractor, VISIT_ONLY_STRONG); |
2391 extractor.SetCollectingAllReferences(); | 2399 extractor.SetCollectingAllReferences(); |
2392 heap_->IterateRoots(&extractor, VISIT_ALL); | 2400 heap_->IterateRoots(&extractor, VISIT_ALL); |
2393 extractor.FillReferences(this); | 2401 extractor.FillReferences(this); |
2394 filler_ = NULL; | 2402 filler_ = NULL; |
2395 return progress_->ProgressReport(true); | 2403 return progress_->ProgressReport(true); |
2396 } | 2404 } |
2397 | 2405 |
2398 | 2406 |
2399 bool V8HeapExplorer::IterateAndSetObjectNames(SnapshotFillerInterface* filler) { | |
2400 HeapIterator iterator(HeapIterator::kFilterUnreachable); | |
2401 filler_ = filler; | |
2402 for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) { | |
2403 SetObjectName(obj); | |
2404 } | |
2405 return true; | |
2406 } | |
2407 | |
2408 | |
2409 void V8HeapExplorer::SetObjectName(HeapObject* object) { | |
2410 if (!object->IsJSObject() || object->IsJSRegExp() || object->IsJSFunction()) { | |
2411 return; | |
2412 } | |
2413 const char* name = collection_->names()->GetName( | |
2414 GetConstructorName(JSObject::cast(object))); | |
2415 if (object->IsJSGlobalObject()) { | |
2416 const char* tag = objects_tags_.GetTag(object); | |
2417 if (tag != NULL) { | |
2418 name = collection_->names()->GetFormatted("%s / %s", name, tag); | |
2419 } | |
2420 } | |
2421 GetEntry(object)->set_name(name); | |
2422 } | |
2423 | |
2424 | |
2425 bool V8HeapExplorer::IsEssentialObject(Object* object) { | 2407 bool V8HeapExplorer::IsEssentialObject(Object* object) { |
2426 // We have to use raw_unchecked_* versions because checked versions | 2408 // We have to use raw_unchecked_* versions because checked versions |
2427 // would fail during iteration over object properties. | 2409 // would fail during iteration over object properties. |
2428 return object->IsHeapObject() | 2410 return object->IsHeapObject() |
2429 && !object->IsOddball() | 2411 && !object->IsOddball() |
2430 && object != heap_->raw_unchecked_empty_byte_array() | 2412 && object != heap_->raw_unchecked_empty_byte_array() |
2431 && object != heap_->raw_unchecked_empty_fixed_array() | 2413 && object != heap_->raw_unchecked_empty_fixed_array() |
2432 && object != heap_->raw_unchecked_empty_descriptor_array() | 2414 && object != heap_->raw_unchecked_empty_descriptor_array() |
2433 && object != heap_->raw_unchecked_fixed_array_map() | 2415 && object != heap_->raw_unchecked_fixed_array_map() |
2434 && object != heap_->raw_unchecked_global_property_cell_map() | 2416 && object != heap_->raw_unchecked_global_property_cell_map() |
(...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3095 // stable. It should follow TagGlobalObjects as that can allocate. | 3077 // stable. It should follow TagGlobalObjects as that can allocate. |
3096 AssertNoAllocation no_alloc; | 3078 AssertNoAllocation no_alloc; |
3097 | 3079 |
3098 #ifdef DEBUG | 3080 #ifdef DEBUG |
3099 debug_heap->Verify(); | 3081 debug_heap->Verify(); |
3100 #endif | 3082 #endif |
3101 | 3083 |
3102 SetProgressTotal(1); // 1 pass. | 3084 SetProgressTotal(1); // 1 pass. |
3103 | 3085 |
3104 #ifdef DEBUG | 3086 #ifdef DEBUG |
3105 debug_heap->Verify(); | 3087 debug_heap->Verify(); |
yurys
2012/05/10 12:13:52
We can remove this second verification.
| |
3106 #endif | 3088 #endif |
3107 | 3089 |
3108 if (!FillReferences()) return false; | 3090 if (!FillReferences()) return false; |
3109 | 3091 |
3110 snapshot_->FillChildrenAndRetainers(); | 3092 snapshot_->FillChildrenAndRetainers(); |
3111 snapshot_->RememberLastJSObjectId(); | 3093 snapshot_->RememberLastJSObjectId(); |
3112 | 3094 |
3113 if (!SetEntriesDominators()) return false; | 3095 if (!SetEntriesDominators()) return false; |
3114 if (!CalculateRetainedSizes()) return false; | 3096 if (!CalculateRetainedSizes()) return false; |
3115 | 3097 |
(...skipping 26 matching lines...) Expand all Loading... | |
3142 progress_total_ = iterations_count * ( | 3124 progress_total_ = iterations_count * ( |
3143 v8_heap_explorer_.EstimateObjectsCount(&iterator) + | 3125 v8_heap_explorer_.EstimateObjectsCount(&iterator) + |
3144 dom_explorer_.EstimateObjectsCount()); | 3126 dom_explorer_.EstimateObjectsCount()); |
3145 progress_counter_ = 0; | 3127 progress_counter_ = 0; |
3146 } | 3128 } |
3147 | 3129 |
3148 | 3130 |
3149 bool HeapSnapshotGenerator::FillReferences() { | 3131 bool HeapSnapshotGenerator::FillReferences() { |
3150 SnapshotFiller filler(snapshot_, &entries_); | 3132 SnapshotFiller filler(snapshot_, &entries_); |
3151 v8_heap_explorer_.AddRootEntries(&filler); | 3133 v8_heap_explorer_.AddRootEntries(&filler); |
3152 // IterateAndExtractReferences cannot set object names because | |
3153 // it makes call to JSObject::LocalLookupRealNamedProperty which | |
3154 // in turn may relocate objects in property maps thus changing the heap | |
3155 // layout and affecting retainer counts. This is not acceptable because | |
3156 // number of retainers must not change between count and fill passes. | |
3157 // To avoid this there's a separate postpass that set object names. | |
3158 return v8_heap_explorer_.IterateAndExtractReferences(&filler) | 3134 return v8_heap_explorer_.IterateAndExtractReferences(&filler) |
3159 && dom_explorer_.IterateAndExtractReferences(&filler) | 3135 && dom_explorer_.IterateAndExtractReferences(&filler); |
3160 && v8_heap_explorer_.IterateAndSetObjectNames(&filler); | |
3161 } | 3136 } |
3162 | 3137 |
3163 | 3138 |
3164 bool HeapSnapshotGenerator::IsUserGlobalReference(const HeapGraphEdge* edge) { | 3139 bool HeapSnapshotGenerator::IsUserGlobalReference(const HeapGraphEdge* edge) { |
3165 ASSERT(edge->from() == snapshot_->root()); | 3140 ASSERT(edge->from() == snapshot_->root()); |
3166 return edge->type() == HeapGraphEdge::kShortcut; | 3141 return edge->type() == HeapGraphEdge::kShortcut; |
3167 } | 3142 } |
3168 | 3143 |
3169 | 3144 |
3170 void HeapSnapshotGenerator::MarkUserReachableObjects() { | 3145 void HeapSnapshotGenerator::MarkUserReachableObjects() { |
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3778 | 3753 |
3779 | 3754 |
3780 void HeapSnapshotJSONSerializer::SortHashMap( | 3755 void HeapSnapshotJSONSerializer::SortHashMap( |
3781 HashMap* map, List<HashMap::Entry*>* sorted_entries) { | 3756 HashMap* map, List<HashMap::Entry*>* sorted_entries) { |
3782 for (HashMap::Entry* p = map->Start(); p != NULL; p = map->Next(p)) | 3757 for (HashMap::Entry* p = map->Start(); p != NULL; p = map->Next(p)) |
3783 sorted_entries->Add(p); | 3758 sorted_entries->Add(p); |
3784 sorted_entries->Sort(SortUsingEntryValue); | 3759 sorted_entries->Sort(SortUsingEntryValue); |
3785 } | 3760 } |
3786 | 3761 |
3787 } } // namespace v8::internal | 3762 } } // namespace v8::internal |
OLD | NEW |