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

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

Issue 7248058: Heap profiler: annotate fixed arrays by their purpose. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 5 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
« no previous file with comments | « src/profile-generator.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1617 matching lines...) Expand 10 before | Expand all | Expand 10 after
1628 reinterpret_cast<HeapObject*>( 1628 reinterpret_cast<HeapObject*>(
1629 static_cast<intptr_t>(HeapObjectsMap::kInternalRootObjectId)); 1629 static_cast<intptr_t>(HeapObjectsMap::kInternalRootObjectId));
1630 HeapObject *const V8HeapExplorer::kGcRootsObject = 1630 HeapObject *const V8HeapExplorer::kGcRootsObject =
1631 reinterpret_cast<HeapObject*>( 1631 reinterpret_cast<HeapObject*>(
1632 static_cast<intptr_t>(HeapObjectsMap::kGcRootsObjectId)); 1632 static_cast<intptr_t>(HeapObjectsMap::kGcRootsObjectId));
1633 1633
1634 1634
1635 V8HeapExplorer::V8HeapExplorer( 1635 V8HeapExplorer::V8HeapExplorer(
1636 HeapSnapshot* snapshot, 1636 HeapSnapshot* snapshot,
1637 SnapshottingProgressReportingInterface* progress) 1637 SnapshottingProgressReportingInterface* progress)
1638 : snapshot_(snapshot), 1638 : heap_(Isolate::Current()->heap()),
1639 snapshot_(snapshot),
1639 collection_(snapshot_->collection()), 1640 collection_(snapshot_->collection()),
1640 progress_(progress), 1641 progress_(progress),
1641 filler_(NULL) { 1642 filler_(NULL) {
1642 } 1643 }
1643 1644
1644 1645
1645 V8HeapExplorer::~V8HeapExplorer() { 1646 V8HeapExplorer::~V8HeapExplorer() {
1646 } 1647 }
1647 1648
1648 1649
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1718 } else if (object->IsScript()) { 1719 } else if (object->IsScript()) {
1719 Script* script = Script::cast(object); 1720 Script* script = Script::cast(object);
1720 return AddEntry(object, 1721 return AddEntry(object,
1721 HeapEntry::kCode, 1722 HeapEntry::kCode,
1722 script->name()->IsString() ? 1723 script->name()->IsString() ?
1723 collection_->names()->GetName( 1724 collection_->names()->GetName(
1724 String::cast(script->name())) 1725 String::cast(script->name()))
1725 : "", 1726 : "",
1726 children_count, 1727 children_count,
1727 retainers_count); 1728 retainers_count);
1728 } else if (object->IsFixedArray() || object->IsByteArray()) { 1729 } else if (object->IsFixedArray() ||
1730 object->IsFixedDoubleArray() ||
1731 object->IsByteArray() ||
1732 object->IsExternalArray()) {
1733 const char* tag = objects_tags_.GetTag(object);
1729 return AddEntry(object, 1734 return AddEntry(object,
1730 HeapEntry::kArray, 1735 HeapEntry::kArray,
1731 "", 1736 tag != NULL ? tag : "",
1732 children_count, 1737 children_count,
1733 retainers_count); 1738 retainers_count);
1734 } else if (object->IsHeapNumber()) { 1739 } else if (object->IsHeapNumber()) {
1735 return AddEntry(object, 1740 return AddEntry(object,
1736 HeapEntry::kHeapNumber, 1741 HeapEntry::kHeapNumber,
1737 "number", 1742 "number",
1738 children_count, 1743 children_count,
1739 retainers_count); 1744 retainers_count);
1740 } 1745 }
1741 return AddEntry(object, 1746 return AddEntry(object,
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1829 HeapObject* parent_obj_; 1834 HeapObject* parent_obj_;
1830 HeapEntry* parent_; 1835 HeapEntry* parent_;
1831 int next_index_; 1836 int next_index_;
1832 }; 1837 };
1833 1838
1834 1839
1835 void V8HeapExplorer::ExtractReferences(HeapObject* obj) { 1840 void V8HeapExplorer::ExtractReferences(HeapObject* obj) {
1836 HeapEntry* entry = GetEntry(obj); 1841 HeapEntry* entry = GetEntry(obj);
1837 if (entry == NULL) return; // No interest in this object. 1842 if (entry == NULL) return; // No interest in this object.
1838 1843
1844 bool extract_indexed_refs = true;
1839 if (obj->IsJSGlobalProxy()) { 1845 if (obj->IsJSGlobalProxy()) {
1840 // We need to reference JS global objects from snapshot's root. 1846 // We need to reference JS global objects from snapshot's root.
1841 // We use JSGlobalProxy because this is what embedder (e.g. browser) 1847 // We use JSGlobalProxy because this is what embedder (e.g. browser)
1842 // uses for the global object. 1848 // uses for the global object.
1843 JSGlobalProxy* proxy = JSGlobalProxy::cast(obj); 1849 JSGlobalProxy* proxy = JSGlobalProxy::cast(obj);
1844 SetRootShortcutReference(proxy->map()->prototype()); 1850 SetRootShortcutReference(proxy->map()->prototype());
1845 SetInternalReference(obj, entry, "map", obj->map(), HeapObject::kMapOffset);
1846 IndexedReferencesExtractor refs_extractor(this, obj, entry);
1847 obj->Iterate(&refs_extractor);
1848 } else if (obj->IsJSObject()) { 1851 } else if (obj->IsJSObject()) {
1849 JSObject* js_obj = JSObject::cast(obj); 1852 JSObject* js_obj = JSObject::cast(obj);
1850 ExtractClosureReferences(js_obj, entry); 1853 ExtractClosureReferences(js_obj, entry);
1851 ExtractPropertyReferences(js_obj, entry); 1854 ExtractPropertyReferences(js_obj, entry);
1852 ExtractElementReferences(js_obj, entry); 1855 ExtractElementReferences(js_obj, entry);
1853 ExtractInternalReferences(js_obj, entry); 1856 ExtractInternalReferences(js_obj, entry);
1854 SetPropertyReference( 1857 SetPropertyReference(
1855 obj, entry, HEAP->Proto_symbol(), js_obj->GetPrototype()); 1858 obj, entry, heap_->Proto_symbol(), js_obj->GetPrototype());
1856 if (obj->IsJSFunction()) { 1859 if (obj->IsJSFunction()) {
1857 JSFunction* js_fun = JSFunction::cast(js_obj); 1860 JSFunction* js_fun = JSFunction::cast(js_obj);
1858 Object* proto_or_map = js_fun->prototype_or_initial_map(); 1861 Object* proto_or_map = js_fun->prototype_or_initial_map();
1859 if (!proto_or_map->IsTheHole()) { 1862 if (!proto_or_map->IsTheHole()) {
1860 if (!proto_or_map->IsMap()) { 1863 if (!proto_or_map->IsMap()) {
1861 SetPropertyReference( 1864 SetPropertyReference(
1862 obj, entry, 1865 obj, entry,
1863 HEAP->prototype_symbol(), proto_or_map, 1866 heap_->prototype_symbol(), proto_or_map,
1864 JSFunction::kPrototypeOrInitialMapOffset); 1867 JSFunction::kPrototypeOrInitialMapOffset);
1865 } else { 1868 } else {
1866 SetPropertyReference( 1869 SetPropertyReference(
1867 obj, entry, 1870 obj, entry,
1868 HEAP->prototype_symbol(), js_fun->prototype()); 1871 heap_->prototype_symbol(), js_fun->prototype());
1869 } 1872 }
1870 } 1873 }
1871 SetInternalReference(js_fun, entry, 1874 SetInternalReference(js_fun, entry,
1872 "shared", js_fun->shared(), 1875 "shared", js_fun->shared(),
1873 JSFunction::kSharedFunctionInfoOffset); 1876 JSFunction::kSharedFunctionInfoOffset);
1877 if (js_fun->unchecked_context()->IsContext()) {
Vitaly Repeshko 2011/06/30 12:41:44 How about instead of having TagFoo functions just
mnaganov (inactive) 2011/06/30 13:37:05 Done.
1878 objects_tags_.SetTag(js_fun->unchecked_context(), "(context)");
1879 }
1874 SetInternalReference(js_fun, entry, 1880 SetInternalReference(js_fun, entry,
1875 "context", js_fun->unchecked_context(), 1881 "context", js_fun->unchecked_context(),
1876 JSFunction::kContextOffset); 1882 JSFunction::kContextOffset);
1883 TagFixedArray(js_fun->literals(), "(function literals)");
1877 SetInternalReference(js_fun, entry, 1884 SetInternalReference(js_fun, entry,
1878 "literals", js_fun->literals(), 1885 "literals", js_fun->literals(),
1879 JSFunction::kLiteralsOffset); 1886 JSFunction::kLiteralsOffset);
1880 } 1887 }
1888 TagFixedArray(js_obj->properties(), "(object properties)");
1881 SetInternalReference(obj, entry, 1889 SetInternalReference(obj, entry,
1882 "properties", js_obj->properties(), 1890 "properties", js_obj->properties(),
1883 JSObject::kPropertiesOffset); 1891 JSObject::kPropertiesOffset);
1892 TagFixedArray(js_obj->elements(), "(object elements)") ||
1893 TagFixedDoubleArray(js_obj->elements(), "(object elements)");
1884 SetInternalReference(obj, entry, 1894 SetInternalReference(obj, entry,
1885 "elements", js_obj->elements(), 1895 "elements", js_obj->elements(),
1886 JSObject::kElementsOffset); 1896 JSObject::kElementsOffset);
1887 SetInternalReference(obj, entry, "map", obj->map(), HeapObject::kMapOffset);
1888 IndexedReferencesExtractor refs_extractor(this, obj, entry);
1889 obj->Iterate(&refs_extractor);
1890 } else if (obj->IsString()) { 1897 } else if (obj->IsString()) {
1891 if (obj->IsConsString()) { 1898 if (obj->IsConsString()) {
1892 ConsString* cs = ConsString::cast(obj); 1899 ConsString* cs = ConsString::cast(obj);
1893 SetInternalReference(obj, entry, 1, cs->first()); 1900 SetInternalReference(obj, entry, 1, cs->first());
1894 SetInternalReference(obj, entry, 2, cs->second()); 1901 SetInternalReference(obj, entry, 2, cs->second());
1895 } 1902 }
1903 extract_indexed_refs = false;
1904 } else if (obj->IsGlobalContext()) {
1905 Context* context = Context::cast(obj);
1906 TagFixedArray(context->jsfunction_result_caches(), "(context func caches)");
1907 TagFixedArray(context->normalized_map_cache(), "(context norm. map cache)");
1908 TagFixedArray(context->runtime_context(), "(runtime context)");
1909 TagFixedArray(context->map_cache(), "(context map cache)");
Vitaly Repeshko 2011/06/30 12:41:44 This made me realize our map cache is just leaking
1910 TagFixedArray(context->data(), "(context data)");
1896 } else if (obj->IsMap()) { 1911 } else if (obj->IsMap()) {
1897 Map* map = Map::cast(obj); 1912 Map* map = Map::cast(obj);
1898 SetInternalReference(obj, entry, 1913 SetInternalReference(obj, entry,
1899 "prototype", map->prototype(), Map::kPrototypeOffset); 1914 "prototype", map->prototype(), Map::kPrototypeOffset);
1900 SetInternalReference(obj, entry, 1915 SetInternalReference(obj, entry,
1901 "constructor", map->constructor(), 1916 "constructor", map->constructor(),
1902 Map::kConstructorOffset); 1917 Map::kConstructorOffset);
1903 if (!map->instance_descriptors()->IsEmpty()) { 1918 if (!map->instance_descriptors()->IsEmpty()) {
1919 objects_tags_.SetTag(map->instance_descriptors(), "(map descriptors)");
1904 SetInternalReference(obj, entry, 1920 SetInternalReference(obj, entry,
1905 "descriptors", map->instance_descriptors(), 1921 "descriptors", map->instance_descriptors(),
1906 Map::kInstanceDescriptorsOrBitField3Offset); 1922 Map::kInstanceDescriptorsOrBitField3Offset);
1907 } 1923 }
1908 SetInternalReference(obj, entry, 1924 SetInternalReference(obj, entry,
1909 "code_cache", map->code_cache(), 1925 "code_cache", map->code_cache(),
1910 Map::kCodeCacheOffset); 1926 Map::kCodeCacheOffset);
1911 SetInternalReference(obj, entry, "map", obj->map(), HeapObject::kMapOffset);
1912 IndexedReferencesExtractor refs_extractor(this, obj, entry);
1913 obj->Iterate(&refs_extractor);
1914 } else if (obj->IsSharedFunctionInfo()) { 1927 } else if (obj->IsSharedFunctionInfo()) {
1915 SharedFunctionInfo* shared = SharedFunctionInfo::cast(obj); 1928 SharedFunctionInfo* shared = SharedFunctionInfo::cast(obj);
1916 SetInternalReference(obj, entry, 1929 SetInternalReference(obj, entry,
1917 "name", shared->name(), 1930 "name", shared->name(),
1918 SharedFunctionInfo::kNameOffset); 1931 SharedFunctionInfo::kNameOffset);
1919 SetInternalReference(obj, entry, 1932 SetInternalReference(obj, entry,
1920 "code", shared->unchecked_code(), 1933 "code", shared->unchecked_code(),
1921 SharedFunctionInfo::kCodeOffset); 1934 SharedFunctionInfo::kCodeOffset);
1935 TagFixedArray(shared->scope_info(), "(function scope info)");
1936 SetInternalReference(obj, entry,
1937 "scope_info", shared->scope_info(),
1938 SharedFunctionInfo::kScopeInfoOffset);
1922 SetInternalReference(obj, entry, 1939 SetInternalReference(obj, entry,
1923 "instance_class_name", shared->instance_class_name(), 1940 "instance_class_name", shared->instance_class_name(),
1924 SharedFunctionInfo::kInstanceClassNameOffset); 1941 SharedFunctionInfo::kInstanceClassNameOffset);
1925 SetInternalReference(obj, entry, 1942 SetInternalReference(obj, entry,
1926 "script", shared->script(), 1943 "script", shared->script(),
1927 SharedFunctionInfo::kScriptOffset); 1944 SharedFunctionInfo::kScriptOffset);
1945 } else if (obj->IsScript()) {
1946 Script* script = Script::cast(obj);
1947 SetInternalReference(obj, entry,
1948 "source", script->source(),
1949 Script::kSourceOffset);
1950 SetInternalReference(obj, entry,
1951 "name", script->name(),
1952 Script::kNameOffset);
1953 SetInternalReference(obj, entry,
1954 "data", script->data(),
1955 Script::kDataOffset);
1956 SetInternalReference(obj, entry,
1957 "context_data", script->context_data(),
1958 Script::kContextOffset);
1959 TagFixedArray(script->line_ends(), "(script line ends)");
1960 SetInternalReference(obj, entry,
1961 "line_ends", script->line_ends(),
1962 Script::kLineEndsOffset);
1963 } else if (obj->IsDescriptorArray()) {
1964 DescriptorArray* desc_array = DescriptorArray::cast(obj);
1965 if (desc_array->length() > DescriptorArray::kContentArrayIndex) {
1966 Object* content_array =
1967 desc_array->get(DescriptorArray::kContentArrayIndex);
1968 TagFixedArray(content_array, "(map descriptor content)");
1969 SetInternalReference(obj, entry,
1970 "content", content_array,
1971 FixedArray::OffsetOfElementAt(
1972 DescriptorArray::kContentArrayIndex));
1973 }
1974 } else if (obj->IsCodeCache()) {
1975 CodeCache* code_cache = CodeCache::cast(obj);
1976 TagFixedArray(code_cache->default_cache(), "(default code cache)");
1977 SetInternalReference(obj, entry,
1978 "default_cache", code_cache->default_cache(),
1979 CodeCache::kDefaultCacheOffset);
1980 if (code_cache->normal_type_cache()->IsCodeCacheHashTable()) {
1981 objects_tags_.SetTag(code_cache->normal_type_cache(), "(code type cache)") ;
1982 }
1983 SetInternalReference(obj, entry,
1984 "type_cache", code_cache->normal_type_cache(),
1985 CodeCache::kNormalTypeCacheOffset);
1986 } else if (obj->IsCode()) {
1987 Code* code = Code::cast(obj);
1988 TagByteArray(code->unchecked_relocation_info(), "(code relocation info)");
1989 TagFixedArray(code->unchecked_deoptimization_data(), "(code deopt data)");
1990 }
1991 if (extract_indexed_refs) {
1928 SetInternalReference(obj, entry, "map", obj->map(), HeapObject::kMapOffset); 1992 SetInternalReference(obj, entry, "map", obj->map(), HeapObject::kMapOffset);
1929 IndexedReferencesExtractor refs_extractor(this, obj, entry); 1993 IndexedReferencesExtractor refs_extractor(this, obj, entry);
1930 obj->Iterate(&refs_extractor); 1994 obj->Iterate(&refs_extractor);
1931 } else {
1932 SetInternalReference(obj, entry, "map", obj->map(), HeapObject::kMapOffset);
1933 IndexedReferencesExtractor refs_extractor(this, obj, entry);
1934 obj->Iterate(&refs_extractor);
1935 } 1995 }
1936 } 1996 }
1937 1997
1938 1998
1939 void V8HeapExplorer::ExtractClosureReferences(JSObject* js_obj, 1999 void V8HeapExplorer::ExtractClosureReferences(JSObject* js_obj,
1940 HeapEntry* entry) { 2000 HeapEntry* entry) {
1941 if (js_obj->IsJSFunction()) { 2001 if (js_obj->IsJSFunction()) {
1942 HandleScope hs; 2002 HandleScope hs;
1943 JSFunction* func = JSFunction::cast(js_obj); 2003 JSFunction* func = JSFunction::cast(js_obj);
1944 Context* context = func->context(); 2004 Context* context = func->context();
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
2079 ExtractReferences(obj); 2139 ExtractReferences(obj);
2080 if (!progress_->ProgressReport(false)) interrupted = true; 2140 if (!progress_->ProgressReport(false)) interrupted = true;
2081 } 2141 }
2082 } 2142 }
2083 if (interrupted) { 2143 if (interrupted) {
2084 filler_ = NULL; 2144 filler_ = NULL;
2085 return false; 2145 return false;
2086 } 2146 }
2087 SetRootGcRootsReference(); 2147 SetRootGcRootsReference();
2088 RootsReferencesExtractor extractor(this); 2148 RootsReferencesExtractor extractor(this);
2089 HEAP->IterateRoots(&extractor, VISIT_ALL); 2149 heap_->IterateRoots(&extractor, VISIT_ALL);
2090 filler_ = NULL; 2150 filler_ = NULL;
2091 return progress_->ProgressReport(false); 2151 return progress_->ProgressReport(false);
2092 } 2152 }
2093 2153
2094 2154
2095 void V8HeapExplorer::SetClosureReference(HeapObject* parent_obj, 2155 void V8HeapExplorer::SetClosureReference(HeapObject* parent_obj,
2096 HeapEntry* parent_entry, 2156 HeapEntry* parent_entry,
2097 String* reference_name, 2157 String* reference_name,
2098 Object* child_obj) { 2158 Object* child_obj) {
2099 HeapEntry* child_entry = GetEntry(child_obj); 2159 HeapEntry* child_entry = GetEntry(child_obj);
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
2234 HeapEntry* child_entry = GetEntry(child_obj); 2294 HeapEntry* child_entry = GetEntry(child_obj);
2235 if (child_entry != NULL) { 2295 if (child_entry != NULL) {
2236 filler_->SetIndexedAutoIndexReference( 2296 filler_->SetIndexedAutoIndexReference(
2237 HeapGraphEdge::kElement, 2297 HeapGraphEdge::kElement,
2238 kGcRootsObject, snapshot_->gc_roots(), 2298 kGcRootsObject, snapshot_->gc_roots(),
2239 child_obj, child_entry); 2299 child_obj, child_entry);
2240 } 2300 }
2241 } 2301 }
2242 2302
2243 2303
2304 bool V8HeapExplorer::TagByteArray(Object* maybe_array, const char* tag) {
2305 if (maybe_array->IsByteArray() &&
2306 maybe_array != heap_->empty_byte_array()) {
2307 objects_tags_.SetTag(maybe_array, tag);
2308 return true;
2309 }
2310 return false;
2311 }
2312
2313
2314 bool V8HeapExplorer::TagFixedArray(Object* maybe_array, const char* tag) {
2315 if (maybe_array->IsFixedArray() &&
2316 maybe_array != heap_->empty_fixed_array()) {
2317 objects_tags_.SetTag(maybe_array, tag);
2318 return true;
2319 }
2320 return false;
2321 }
2322
2323
2324 bool V8HeapExplorer::TagFixedDoubleArray(Object* maybe_array, const char* tag) {
2325 if (maybe_array->IsFixedDoubleArray() &&
2326 maybe_array != heap_->empty_fixed_double_array()) {
2327 objects_tags_.SetTag(maybe_array, tag);
2328 return true;
2329 }
2330 return false;
2331 }
2332
2333
2244 class GlobalObjectsEnumerator : public ObjectVisitor { 2334 class GlobalObjectsEnumerator : public ObjectVisitor {
2245 public: 2335 public:
2246 virtual void VisitPointers(Object** start, Object** end) { 2336 virtual void VisitPointers(Object** start, Object** end) {
2247 for (Object** p = start; p < end; p++) { 2337 for (Object** p = start; p < end; p++) {
2248 if ((*p)->IsGlobalContext()) { 2338 if ((*p)->IsGlobalContext()) {
2249 Context* context = Context::cast(*p); 2339 Context* context = Context::cast(*p);
2250 JSObject* proxy = context->global_proxy(); 2340 JSObject* proxy = context->global_proxy();
2251 if (proxy->IsJSGlobalProxy()) { 2341 if (proxy->IsJSGlobalProxy()) {
2252 Object* global = proxy->map()->prototype(); 2342 Object* global = proxy->map()->prototype();
2253 if (global->IsJSGlobalObject()) { 2343 if (global->IsJSGlobalObject()) {
(...skipping 932 matching lines...) Expand 10 before | Expand all | Expand 10 after
3186 3276
3187 3277
3188 String* GetConstructorNameForHeapProfile(JSObject* object) { 3278 String* GetConstructorNameForHeapProfile(JSObject* object) {
3189 if (object->IsJSFunction()) return HEAP->closure_symbol(); 3279 if (object->IsJSFunction()) return HEAP->closure_symbol();
3190 return object->constructor_name(); 3280 return object->constructor_name();
3191 } 3281 }
3192 3282
3193 } } // namespace v8::internal 3283 } } // namespace v8::internal
3194 3284
3195 #endif // ENABLE_LOGGING_AND_PROFILING 3285 #endif // ENABLE_LOGGING_AND_PROFILING
OLDNEW
« no previous file with comments | « src/profile-generator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698