Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(548)

Side by Side Diff: src/profile-generator.cc

Issue 7709026: Heap profiler: for objects of class "Object", try to lookup name (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
2094 HeapEntry* entry) { 2093 HeapEntry* entry) {
2095 int length = js_obj->GetInternalFieldCount(); 2094 int length = js_obj->GetInternalFieldCount();
2096 for (int i = 0; i < length; ++i) { 2095 for (int i = 0; i < length; ++i) {
2097 Object* o = js_obj->GetInternalField(i); 2096 Object* o = js_obj->GetInternalField(i);
2098 SetInternalReference( 2097 SetInternalReference(
2099 js_obj, entry, i, o, js_obj->GetInternalFieldOffset(i)); 2098 js_obj, entry, i, o, js_obj->GetInternalFieldOffset(i));
2100 } 2099 }
2101 } 2100 }
2102 2101
2103 2102
2103 String* V8HeapExplorer::GetConstructorName(JSObject* object) {
2104 if (object->IsJSFunction()) return HEAP->closure_symbol();
2105 String* constructor_name = object->constructor_name();
2106 if (constructor_name == HEAP->Object_symbol()) {
2107 // Look up an immediate "constructor" property, if it is a function,
2108 // return its name. This is for instances of binding objects, which
2109 // have prototype constructor type "Object".
2110 Object* constructor_prop = NULL;
2111 LookupResult result;
2112 object->LocalLookupRealNamedProperty(HEAP->constructor_symbol(), &result);
2113 if (result.IsProperty()) {
2114 constructor_prop = result.GetLazyValue();
2115 }
2116 if (constructor_prop->IsJSFunction()) {
2117 Object* maybe_name = JSFunction::cast(constructor_prop)->shared()->name();
2118 if (maybe_name->IsString()) {
2119 String* name = String::cast(maybe_name);
2120 if (name->length() > 0) return name;
2121 }
2122 }
2123 }
2124 return object->constructor_name();
2125 }
2126
2127
2104 HeapEntry* V8HeapExplorer::GetEntry(Object* obj) { 2128 HeapEntry* V8HeapExplorer::GetEntry(Object* obj) {
2105 if (!obj->IsHeapObject()) return NULL; 2129 if (!obj->IsHeapObject()) return NULL;
2106 return filler_->FindOrAddEntry(obj, this); 2130 return filler_->FindOrAddEntry(obj, this);
2107 } 2131 }
2108 2132
2109 2133
2110 class RootsReferencesExtractor : public ObjectVisitor { 2134 class RootsReferencesExtractor : public ObjectVisitor {
2111 public: 2135 public:
2112 explicit RootsReferencesExtractor(V8HeapExplorer* explorer) 2136 explicit RootsReferencesExtractor(V8HeapExplorer* explorer)
2113 : explorer_(explorer) { 2137 : explorer_(explorer) {
(...skipping 1129 matching lines...) Expand 10 before | Expand all | Expand 10 after
3243 } 3267 }
3244 3268
3245 3269
3246 void HeapSnapshotJSONSerializer::SortHashMap( 3270 void HeapSnapshotJSONSerializer::SortHashMap(
3247 HashMap* map, List<HashMap::Entry*>* sorted_entries) { 3271 HashMap* map, List<HashMap::Entry*>* sorted_entries) {
3248 for (HashMap::Entry* p = map->Start(); p != NULL; p = map->Next(p)) 3272 for (HashMap::Entry* p = map->Start(); p != NULL; p = map->Next(p))
3249 sorted_entries->Add(p); 3273 sorted_entries->Add(p);
3250 sorted_entries->Sort(SortUsingEntryValue); 3274 sorted_entries->Sort(SortUsingEntryValue);
3251 } 3275 }
3252 3276
3253
3254 String* GetConstructorNameForHeapProfile(JSObject* object) {
3255 if (object->IsJSFunction()) return HEAP->closure_symbol();
3256 return object->constructor_name();
3257 }
3258
3259 } } // namespace v8::internal 3277 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698