| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 1645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1656 int children_count, | 1656 int children_count, |
| 1657 int retainers_count) { | 1657 int retainers_count) { |
| 1658 if (object == kInternalRootObject) { | 1658 if (object == kInternalRootObject) { |
| 1659 ASSERT(retainers_count == 0); | 1659 ASSERT(retainers_count == 0); |
| 1660 return snapshot_->AddRootEntry(children_count); | 1660 return snapshot_->AddRootEntry(children_count); |
| 1661 } else if (object == kGcRootsObject) { | 1661 } else if (object == kGcRootsObject) { |
| 1662 return snapshot_->AddGcRootsEntry(children_count, retainers_count); | 1662 return snapshot_->AddGcRootsEntry(children_count, retainers_count); |
| 1663 } else if (object->IsJSGlobalObject()) { | 1663 } else if (object->IsJSGlobalObject()) { |
| 1664 const char* tag = objects_tags_.GetTag(object); | 1664 const char* tag = objects_tags_.GetTag(object); |
| 1665 const char* name = collection_->names()->GetName( | 1665 const char* name = collection_->names()->GetName( |
| 1666 GetConstructorNameForHeapProfile(JSObject::cast(object))); | 1666 GetConstructorName(JSObject::cast(object))); |
| 1667 if (tag != NULL) { | 1667 if (tag != NULL) { |
| 1668 name = collection_->names()->GetFormatted("%s / %s", name, tag); | 1668 name = collection_->names()->GetFormatted("%s / %s", name, tag); |
| 1669 } | 1669 } |
| 1670 return AddEntry(object, | 1670 return AddEntry(object, |
| 1671 HeapEntry::kObject, | 1671 HeapEntry::kObject, |
| 1672 name, | 1672 name, |
| 1673 children_count, | 1673 children_count, |
| 1674 retainers_count); | 1674 retainers_count); |
| 1675 } else if (object->IsJSFunction()) { | 1675 } else if (object->IsJSFunction()) { |
| 1676 JSFunction* func = JSFunction::cast(object); | 1676 JSFunction* func = JSFunction::cast(object); |
| 1677 SharedFunctionInfo* shared = func->shared(); | 1677 SharedFunctionInfo* shared = func->shared(); |
| 1678 return AddEntry(object, | 1678 return AddEntry(object, |
| 1679 HeapEntry::kClosure, | 1679 HeapEntry::kClosure, |
| 1680 collection_->names()->GetName(String::cast(shared->name())), | 1680 collection_->names()->GetName(String::cast(shared->name())), |
| 1681 children_count, | 1681 children_count, |
| 1682 retainers_count); | 1682 retainers_count); |
| 1683 } else if (object->IsJSRegExp()) { | 1683 } else if (object->IsJSRegExp()) { |
| 1684 JSRegExp* re = JSRegExp::cast(object); | 1684 JSRegExp* re = JSRegExp::cast(object); |
| 1685 return AddEntry(object, | 1685 return AddEntry(object, |
| 1686 HeapEntry::kRegExp, | 1686 HeapEntry::kRegExp, |
| 1687 collection_->names()->GetName(re->Pattern()), | 1687 collection_->names()->GetName(re->Pattern()), |
| 1688 children_count, | 1688 children_count, |
| 1689 retainers_count); | 1689 retainers_count); |
| 1690 } else if (object->IsJSObject()) { | 1690 } else if (object->IsJSObject()) { |
| 1691 return AddEntry(object, | 1691 return AddEntry(object, |
| 1692 HeapEntry::kObject, | 1692 HeapEntry::kObject, |
| 1693 collection_->names()->GetName( | 1693 collection_->names()->GetName( |
| 1694 GetConstructorNameForHeapProfile( | 1694 GetConstructorName(JSObject::cast(object))), |
| 1695 JSObject::cast(object))), | |
| 1696 children_count, | 1695 children_count, |
| 1697 retainers_count); | 1696 retainers_count); |
| 1698 } else if (object->IsString()) { | 1697 } else if (object->IsString()) { |
| 1699 return AddEntry(object, | 1698 return AddEntry(object, |
| 1700 HeapEntry::kString, | 1699 HeapEntry::kString, |
| 1701 collection_->names()->GetName(String::cast(object)), | 1700 collection_->names()->GetName(String::cast(object)), |
| 1702 children_count, | 1701 children_count, |
| 1703 retainers_count); | 1702 retainers_count); |
| 1704 } else if (object->IsCode()) { | 1703 } else if (object->IsCode()) { |
| 1705 return AddEntry(object, | 1704 return AddEntry(object, |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2103 HeapEntry* entry) { | 2102 HeapEntry* entry) { |
| 2104 int length = js_obj->GetInternalFieldCount(); | 2103 int length = js_obj->GetInternalFieldCount(); |
| 2105 for (int i = 0; i < length; ++i) { | 2104 for (int i = 0; i < length; ++i) { |
| 2106 Object* o = js_obj->GetInternalField(i); | 2105 Object* o = js_obj->GetInternalField(i); |
| 2107 SetInternalReference( | 2106 SetInternalReference( |
| 2108 js_obj, entry, i, o, js_obj->GetInternalFieldOffset(i)); | 2107 js_obj, entry, i, o, js_obj->GetInternalFieldOffset(i)); |
| 2109 } | 2108 } |
| 2110 } | 2109 } |
| 2111 | 2110 |
| 2112 | 2111 |
| 2112 String* V8HeapExplorer::GetConstructorName(JSObject* object) { |
| 2113 if (object->IsJSFunction()) return HEAP->closure_symbol(); |
| 2114 String* constructor_name = object->constructor_name(); |
| 2115 if (constructor_name == HEAP->Object_symbol()) { |
| 2116 // Look up an immediate "constructor" property, if it is a function, |
| 2117 // return its name. This is for instances of binding objects, which |
| 2118 // have prototype constructor type "Object". |
| 2119 Object* constructor_prop = NULL; |
| 2120 LookupResult result; |
| 2121 object->LocalLookupRealNamedProperty(HEAP->constructor_symbol(), &result); |
| 2122 if (result.IsProperty()) { |
| 2123 constructor_prop = result.GetLazyValue(); |
| 2124 } |
| 2125 if (constructor_prop->IsJSFunction()) { |
| 2126 Object* maybe_name = JSFunction::cast(constructor_prop)->shared()->name(); |
| 2127 if (maybe_name->IsString()) { |
| 2128 String* name = String::cast(maybe_name); |
| 2129 if (name->length() > 0) return name; |
| 2130 } |
| 2131 } |
| 2132 } |
| 2133 return object->constructor_name(); |
| 2134 } |
| 2135 |
| 2136 |
| 2113 HeapEntry* V8HeapExplorer::GetEntry(Object* obj) { | 2137 HeapEntry* V8HeapExplorer::GetEntry(Object* obj) { |
| 2114 if (!obj->IsHeapObject()) return NULL; | 2138 if (!obj->IsHeapObject()) return NULL; |
| 2115 return filler_->FindOrAddEntry(obj, this); | 2139 return filler_->FindOrAddEntry(obj, this); |
| 2116 } | 2140 } |
| 2117 | 2141 |
| 2118 | 2142 |
| 2119 class RootsReferencesExtractor : public ObjectVisitor { | 2143 class RootsReferencesExtractor : public ObjectVisitor { |
| 2120 public: | 2144 public: |
| 2121 explicit RootsReferencesExtractor(V8HeapExplorer* explorer) | 2145 explicit RootsReferencesExtractor(V8HeapExplorer* explorer) |
| 2122 : explorer_(explorer) { | 2146 : explorer_(explorer) { |
| (...skipping 1162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3285 } | 3309 } |
| 3286 | 3310 |
| 3287 | 3311 |
| 3288 void HeapSnapshotJSONSerializer::SortHashMap( | 3312 void HeapSnapshotJSONSerializer::SortHashMap( |
| 3289 HashMap* map, List<HashMap::Entry*>* sorted_entries) { | 3313 HashMap* map, List<HashMap::Entry*>* sorted_entries) { |
| 3290 for (HashMap::Entry* p = map->Start(); p != NULL; p = map->Next(p)) | 3314 for (HashMap::Entry* p = map->Start(); p != NULL; p = map->Next(p)) |
| 3291 sorted_entries->Add(p); | 3315 sorted_entries->Add(p); |
| 3292 sorted_entries->Sort(SortUsingEntryValue); | 3316 sorted_entries->Sort(SortUsingEntryValue); |
| 3293 } | 3317 } |
| 3294 | 3318 |
| 3295 | |
| 3296 String* GetConstructorNameForHeapProfile(JSObject* object) { | |
| 3297 if (object->IsJSFunction()) return HEAP->closure_symbol(); | |
| 3298 return object->constructor_name(); | |
| 3299 } | |
| 3300 | |
| 3301 } } // namespace v8::internal | 3319 } } // namespace v8::internal |
| OLD | NEW |