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

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

Issue 6665038: Dramatically speed up detailed heap snapshot generation. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix visited marks usage" Created 9 years, 9 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
« src/objects-inl.h ('K') | « 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 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 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 1808 matching lines...) Expand 10 before | Expand all | Expand 10 after
1819 obj = iterator.next(), ++objects_count) {} 1819 obj = iterator.next(), ++objects_count) {}
1820 return objects_count; 1820 return objects_count;
1821 } 1821 }
1822 1822
1823 1823
1824 class IndexedReferencesExtractor : public ObjectVisitor { 1824 class IndexedReferencesExtractor : public ObjectVisitor {
1825 public: 1825 public:
1826 IndexedReferencesExtractor(V8HeapExplorer* generator, 1826 IndexedReferencesExtractor(V8HeapExplorer* generator,
1827 HeapObject* parent_obj, 1827 HeapObject* parent_obj,
1828 HeapEntry* parent_entry, 1828 HeapEntry* parent_entry,
1829 HeapObjectsSet* known_references = NULL) 1829 bool process_field_marks = false)
1830 : generator_(generator), 1830 : generator_(generator),
1831 parent_obj_(parent_obj), 1831 parent_obj_(parent_obj),
1832 parent_(parent_entry), 1832 parent_(parent_entry),
1833 known_references_(known_references), 1833 process_field_marks_(process_field_marks),
1834 next_index_(1) { 1834 next_index_(1) {
1835 } 1835 }
1836 void VisitPointers(Object** start, Object** end) { 1836 void VisitPointers(Object** start, Object** end) {
1837 for (Object** p = start; p < end; p++) { 1837 for (Object** p = start; p < end; p++) {
1838 if (!known_references_ || !known_references_->Contains(*p)) { 1838 if (CheckVisitedAndUnmark(p)) continue;
1839 generator_->SetHiddenReference(parent_obj_, parent_, next_index_++, *p); 1839 generator_->SetHiddenReference(parent_obj_, parent_, next_index_++, *p);
1840 }
1841 } 1840 }
1842 } 1841 }
1842 static void MarkVisitedField(HeapObject* obj, int offset) {
1843 if (offset < 0) return;
1844 Address field = obj->address() + offset;
1845 ASSERT(!Memory::Object_at(field)->IsFailure());
1846 ASSERT(Memory::Object_at(field)->IsHeapObject());
1847 *field |= kFailureTag;
1848 }
1843 private: 1849 private:
1850 bool CheckVisitedAndUnmark(Object** field) {
1851 if (process_field_marks_ && (*field)->IsFailure()) {
1852 const int unmark_tag = ~kFailureTagMask | kHeapObjectTag;
1853 *field = reinterpret_cast<Object*>(
1854 reinterpret_cast<intptr_t>(*field) & unmark_tag);
Vitaly Repeshko 2011/03/18 12:16:36 Hmm, I think the correct way is: (reinterpret_cast
mnaganov (inactive) 2011/03/18 12:31:01 Done.
1855 ASSERT((*field)->IsHeapObject());
1856 return true;
1857 }
1858 return false;
1859 }
1844 V8HeapExplorer* generator_; 1860 V8HeapExplorer* generator_;
1845 HeapObject* parent_obj_; 1861 HeapObject* parent_obj_;
1846 HeapEntry* parent_; 1862 HeapEntry* parent_;
1847 HeapObjectsSet* known_references_; 1863 bool process_field_marks_;
1848 int next_index_; 1864 int next_index_;
1849 }; 1865 };
1850 1866
1851 1867
1852 void V8HeapExplorer::ExtractReferences(HeapObject* obj) { 1868 void V8HeapExplorer::ExtractReferences(HeapObject* obj) {
1853 HeapEntry* entry = GetEntry(obj); 1869 HeapEntry* entry = GetEntry(obj);
1854 if (entry == NULL) return; // No interest in this object. 1870 if (entry == NULL) return; // No interest in this object.
1855 1871
1856 known_references_.Clear();
1857 if (obj->IsJSGlobalProxy()) { 1872 if (obj->IsJSGlobalProxy()) {
1858 // We need to reference JS global objects from snapshot's root. 1873 // We need to reference JS global objects from snapshot's root.
1859 // We use JSGlobalProxy because this is what embedder (e.g. browser) 1874 // We use JSGlobalProxy because this is what embedder (e.g. browser)
1860 // uses for the global object. 1875 // uses for the global object.
1861 JSGlobalProxy* proxy = JSGlobalProxy::cast(obj); 1876 JSGlobalProxy* proxy = JSGlobalProxy::cast(obj);
1862 SetRootShortcutReference(proxy->map()->prototype()); 1877 SetRootShortcutReference(proxy->map()->prototype());
1863 IndexedReferencesExtractor refs_extractor(this, obj, entry); 1878 IndexedReferencesExtractor refs_extractor(this, obj, entry);
1864 obj->Iterate(&refs_extractor); 1879 obj->Iterate(&refs_extractor);
1865 } else if (obj->IsJSObject()) { 1880 } else if (obj->IsJSObject()) {
1866 JSObject* js_obj = JSObject::cast(obj); 1881 JSObject* js_obj = JSObject::cast(obj);
1867 ExtractClosureReferences(js_obj, entry); 1882 ExtractClosureReferences(js_obj, entry);
1868 ExtractPropertyReferences(js_obj, entry); 1883 ExtractPropertyReferences(js_obj, entry);
1869 ExtractElementReferences(js_obj, entry); 1884 ExtractElementReferences(js_obj, entry);
1870 ExtractInternalReferences(js_obj, entry); 1885 ExtractInternalReferences(js_obj, entry);
1871 SetPropertyReference( 1886 SetPropertyReference(obj, entry,
1872 obj, entry, Heap::Proto_symbol(), js_obj->GetPrototype()); 1887 Heap::Proto_symbol(), js_obj->GetPrototype());
1873 if (obj->IsJSFunction()) { 1888 if (obj->IsJSFunction()) {
1874 JSFunction* js_fun = JSFunction::cast(obj); 1889 JSFunction* js_fun = JSFunction::cast(js_obj);
1875 if (js_fun->has_prototype()) { 1890 SetInternalReference(
1876 SetPropertyReference( 1891 js_fun, entry,
1877 obj, entry, Heap::prototype_symbol(), js_fun->prototype()); 1892 "code", js_fun->shared(),
1893 JSFunction::kSharedFunctionInfoOffset);
1894 Object* proto_or_map = js_fun->prototype_or_initial_map();
1895 if (!proto_or_map->IsTheHole()) {
1896 if (!proto_or_map->IsMap()) {
1897 SetPropertyReference(
1898 obj, entry,
1899 Heap::prototype_symbol(), proto_or_map,
1900 JSFunction::kPrototypeOrInitialMapOffset);
1901 } else {
1902 SetPropertyReference(
1903 obj, entry,
1904 Heap::prototype_symbol(), js_fun->prototype());
1905 }
1878 } 1906 }
1879 } 1907 }
1880 IndexedReferencesExtractor refs_extractor( 1908 IndexedReferencesExtractor refs_extractor(this, obj, entry, true);
1881 this, obj, entry, &known_references_);
1882 obj->Iterate(&refs_extractor); 1909 obj->Iterate(&refs_extractor);
1883 } else if (obj->IsString()) { 1910 } else if (obj->IsString()) {
1884 if (obj->IsConsString()) { 1911 if (obj->IsConsString()) {
1885 ConsString* cs = ConsString::cast(obj); 1912 ConsString* cs = ConsString::cast(obj);
1886 SetInternalReference(obj, entry, 1, cs->first()); 1913 SetInternalReference(obj, entry, 1, cs->first());
1887 SetInternalReference(obj, entry, 2, cs->second()); 1914 SetInternalReference(obj, entry, 2, cs->second());
1888 } 1915 }
1889 } else { 1916 } else {
1890 IndexedReferencesExtractor refs_extractor(this, obj, entry); 1917 IndexedReferencesExtractor refs_extractor(this, obj, entry);
1891 obj->Iterate(&refs_extractor); 1918 obj->Iterate(&refs_extractor);
(...skipping 12 matching lines...) Expand all
1904 context->closure()->shared()->scope_info(); 1931 context->closure()->shared()->scope_info();
1905 ScopeInfo<ZoneListAllocationPolicy> zone_scope_info(serialized_scope_info); 1932 ScopeInfo<ZoneListAllocationPolicy> zone_scope_info(serialized_scope_info);
1906 int locals_number = zone_scope_info.NumberOfLocals(); 1933 int locals_number = zone_scope_info.NumberOfLocals();
1907 for (int i = 0; i < locals_number; ++i) { 1934 for (int i = 0; i < locals_number; ++i) {
1908 String* local_name = *zone_scope_info.LocalName(i); 1935 String* local_name = *zone_scope_info.LocalName(i);
1909 int idx = serialized_scope_info->ContextSlotIndex(local_name, NULL); 1936 int idx = serialized_scope_info->ContextSlotIndex(local_name, NULL);
1910 if (idx >= 0 && idx < context->length()) { 1937 if (idx >= 0 && idx < context->length()) {
1911 SetClosureReference(js_obj, entry, local_name, context->get(idx)); 1938 SetClosureReference(js_obj, entry, local_name, context->get(idx));
1912 } 1939 }
1913 } 1940 }
1914 SetInternalReference(js_obj, entry, "code", func->shared());
1915 } 1941 }
1916 } 1942 }
1917 1943
1918 1944
1919 void V8HeapExplorer::ExtractPropertyReferences(JSObject* js_obj, 1945 void V8HeapExplorer::ExtractPropertyReferences(JSObject* js_obj,
1920 HeapEntry* entry) { 1946 HeapEntry* entry) {
1921 if (js_obj->HasFastProperties()) { 1947 if (js_obj->HasFastProperties()) {
1922 DescriptorArray* descs = js_obj->map()->instance_descriptors(); 1948 DescriptorArray* descs = js_obj->map()->instance_descriptors();
1923 for (int i = 0; i < descs->number_of_descriptors(); i++) { 1949 for (int i = 0; i < descs->number_of_descriptors(); i++) {
1924 switch (descs->GetType(i)) { 1950 switch (descs->GetType(i)) {
1925 case FIELD: { 1951 case FIELD: {
1926 int index = descs->GetFieldIndex(i); 1952 int index = descs->GetFieldIndex(i);
1927 SetPropertyReference( 1953 SetPropertyReference(
1928 js_obj, entry, descs->GetKey(i), js_obj->FastPropertyAt(index)); 1954 js_obj, entry,
1955 descs->GetKey(i), js_obj->FastPropertyAt(index),
1956 js_obj->GetFastPropertyOffset(index));
1929 break; 1957 break;
1930 } 1958 }
1931 case CONSTANT_FUNCTION: 1959 case CONSTANT_FUNCTION:
1932 SetPropertyReference( 1960 SetPropertyReference(
1933 js_obj, entry, descs->GetKey(i), descs->GetConstantFunction(i)); 1961 js_obj, entry,
1962 descs->GetKey(i), descs->GetConstantFunction(i));
1934 break; 1963 break;
1935 default: ; 1964 default: ;
1936 } 1965 }
1937 } 1966 }
1938 } else { 1967 } else {
1939 StringDictionary* dictionary = js_obj->property_dictionary(); 1968 StringDictionary* dictionary = js_obj->property_dictionary();
1940 int length = dictionary->Capacity(); 1969 int length = dictionary->Capacity();
1941 for (int i = 0; i < length; ++i) { 1970 for (int i = 0; i < length; ++i) {
1942 Object* k = dictionary->KeyAt(i); 1971 Object* k = dictionary->KeyAt(i);
1943 if (dictionary->IsKey(k)) { 1972 if (dictionary->IsKey(k)) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1983 } 2012 }
1984 } 2013 }
1985 } 2014 }
1986 2015
1987 2016
1988 void V8HeapExplorer::ExtractInternalReferences(JSObject* js_obj, 2017 void V8HeapExplorer::ExtractInternalReferences(JSObject* js_obj,
1989 HeapEntry* entry) { 2018 HeapEntry* entry) {
1990 int length = js_obj->GetInternalFieldCount(); 2019 int length = js_obj->GetInternalFieldCount();
1991 for (int i = 0; i < length; ++i) { 2020 for (int i = 0; i < length; ++i) {
1992 Object* o = js_obj->GetInternalField(i); 2021 Object* o = js_obj->GetInternalField(i);
1993 SetInternalReference(js_obj, entry, i, o); 2022 SetInternalReference(
2023 js_obj, entry, i, o, js_obj->GetInternalFieldOffset(i));
1994 } 2024 }
1995 } 2025 }
1996 2026
1997 2027
1998 HeapEntry* V8HeapExplorer::GetEntry(Object* obj) { 2028 HeapEntry* V8HeapExplorer::GetEntry(Object* obj) {
1999 if (!obj->IsHeapObject()) return NULL; 2029 if (!obj->IsHeapObject()) return NULL;
2000 return filler_->FindOrAddEntry(obj, this); 2030 return filler_->FindOrAddEntry(obj, this);
2001 } 2031 }
2002 2032
2003 2033
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
2045 String* reference_name, 2075 String* reference_name,
2046 Object* child_obj) { 2076 Object* child_obj) {
2047 HeapEntry* child_entry = GetEntry(child_obj); 2077 HeapEntry* child_entry = GetEntry(child_obj);
2048 if (child_entry != NULL) { 2078 if (child_entry != NULL) {
2049 filler_->SetNamedReference(HeapGraphEdge::kContextVariable, 2079 filler_->SetNamedReference(HeapGraphEdge::kContextVariable,
2050 parent_obj, 2080 parent_obj,
2051 parent_entry, 2081 parent_entry,
2052 collection_->names()->GetName(reference_name), 2082 collection_->names()->GetName(reference_name),
2053 child_obj, 2083 child_obj,
2054 child_entry); 2084 child_entry);
2055 known_references_.Insert(child_obj);
2056 } 2085 }
2057 } 2086 }
2058 2087
2059 2088
2060 void V8HeapExplorer::SetElementReference(HeapObject* parent_obj, 2089 void V8HeapExplorer::SetElementReference(HeapObject* parent_obj,
2061 HeapEntry* parent_entry, 2090 HeapEntry* parent_entry,
2062 int index, 2091 int index,
2063 Object* child_obj) { 2092 Object* child_obj) {
2064 HeapEntry* child_entry = GetEntry(child_obj); 2093 HeapEntry* child_entry = GetEntry(child_obj);
2065 if (child_entry != NULL) { 2094 if (child_entry != NULL) {
2066 filler_->SetIndexedReference(HeapGraphEdge::kElement, 2095 filler_->SetIndexedReference(HeapGraphEdge::kElement,
2067 parent_obj, 2096 parent_obj,
2068 parent_entry, 2097 parent_entry,
2069 index, 2098 index,
2070 child_obj, 2099 child_obj,
2071 child_entry); 2100 child_entry);
2072 known_references_.Insert(child_obj);
2073 } 2101 }
2074 } 2102 }
2075 2103
2076 2104
2077 void V8HeapExplorer::SetInternalReference(HeapObject* parent_obj, 2105 void V8HeapExplorer::SetInternalReference(HeapObject* parent_obj,
2078 HeapEntry* parent_entry, 2106 HeapEntry* parent_entry,
2079 const char* reference_name, 2107 const char* reference_name,
2080 Object* child_obj) { 2108 Object* child_obj,
2109 int field_offset) {
2081 HeapEntry* child_entry = GetEntry(child_obj); 2110 HeapEntry* child_entry = GetEntry(child_obj);
2082 if (child_entry != NULL) { 2111 if (child_entry != NULL) {
2083 filler_->SetNamedReference(HeapGraphEdge::kInternal, 2112 filler_->SetNamedReference(HeapGraphEdge::kInternal,
2084 parent_obj, 2113 parent_obj,
2085 parent_entry, 2114 parent_entry,
2086 reference_name, 2115 reference_name,
2087 child_obj, 2116 child_obj,
2088 child_entry); 2117 child_entry);
2089 known_references_.Insert(child_obj); 2118 IndexedReferencesExtractor::MarkVisitedField(parent_obj, field_offset);
2090 } 2119 }
2091 } 2120 }
2092 2121
2093 2122
2094 void V8HeapExplorer::SetInternalReference(HeapObject* parent_obj, 2123 void V8HeapExplorer::SetInternalReference(HeapObject* parent_obj,
2095 HeapEntry* parent_entry, 2124 HeapEntry* parent_entry,
2096 int index, 2125 int index,
2097 Object* child_obj) { 2126 Object* child_obj,
2127 int field_offset) {
2098 HeapEntry* child_entry = GetEntry(child_obj); 2128 HeapEntry* child_entry = GetEntry(child_obj);
2099 if (child_entry != NULL) { 2129 if (child_entry != NULL) {
2100 filler_->SetNamedReference(HeapGraphEdge::kInternal, 2130 filler_->SetNamedReference(HeapGraphEdge::kInternal,
2101 parent_obj, 2131 parent_obj,
2102 parent_entry, 2132 parent_entry,
2103 collection_->names()->GetName(index), 2133 collection_->names()->GetName(index),
2104 child_obj, 2134 child_obj,
2105 child_entry); 2135 child_entry);
2106 known_references_.Insert(child_obj); 2136 IndexedReferencesExtractor::MarkVisitedField(parent_obj, field_offset);
2107 } 2137 }
2108 } 2138 }
2109 2139
2110 2140
2111 void V8HeapExplorer::SetHiddenReference(HeapObject* parent_obj, 2141 void V8HeapExplorer::SetHiddenReference(HeapObject* parent_obj,
2112 HeapEntry* parent_entry, 2142 HeapEntry* parent_entry,
2113 int index, 2143 int index,
2114 Object* child_obj) { 2144 Object* child_obj) {
2115 HeapEntry* child_entry = GetEntry(child_obj); 2145 HeapEntry* child_entry = GetEntry(child_obj);
2116 if (child_entry != NULL) { 2146 if (child_entry != NULL) {
2117 filler_->SetIndexedReference(HeapGraphEdge::kHidden, 2147 filler_->SetIndexedReference(HeapGraphEdge::kHidden,
2118 parent_obj, 2148 parent_obj,
2119 parent_entry, 2149 parent_entry,
2120 index, 2150 index,
2121 child_obj, 2151 child_obj,
2122 child_entry); 2152 child_entry);
2123 } 2153 }
2124 } 2154 }
2125 2155
2126 2156
2127 void V8HeapExplorer::SetPropertyReference(HeapObject* parent_obj, 2157 void V8HeapExplorer::SetPropertyReference(HeapObject* parent_obj,
2128 HeapEntry* parent_entry, 2158 HeapEntry* parent_entry,
2129 String* reference_name, 2159 String* reference_name,
2130 Object* child_obj) { 2160 Object* child_obj,
2161 int field_offset) {
2131 HeapEntry* child_entry = GetEntry(child_obj); 2162 HeapEntry* child_entry = GetEntry(child_obj);
2132 if (child_entry != NULL) { 2163 if (child_entry != NULL) {
2133 HeapGraphEdge::Type type = reference_name->length() > 0 ? 2164 HeapGraphEdge::Type type = reference_name->length() > 0 ?
2134 HeapGraphEdge::kProperty : HeapGraphEdge::kInternal; 2165 HeapGraphEdge::kProperty : HeapGraphEdge::kInternal;
2135 filler_->SetNamedReference(type, 2166 filler_->SetNamedReference(type,
2136 parent_obj, 2167 parent_obj,
2137 parent_entry, 2168 parent_entry,
2138 collection_->names()->GetName(reference_name), 2169 collection_->names()->GetName(reference_name),
2139 child_obj, 2170 child_obj,
2140 child_entry); 2171 child_entry);
2141 known_references_.Insert(child_obj); 2172 IndexedReferencesExtractor::MarkVisitedField(parent_obj, field_offset);
2142 } 2173 }
2143 } 2174 }
2144 2175
2145 2176
2146 void V8HeapExplorer::SetPropertyShortcutReference( 2177 void V8HeapExplorer::SetPropertyShortcutReference(HeapObject* parent_obj,
2147 HeapObject* parent_obj, 2178 HeapEntry* parent_entry,
2148 HeapEntry* parent_entry, 2179 String* reference_name,
2149 String* reference_name, 2180 Object* child_obj) {
2150 Object* child_obj) {
2151 HeapEntry* child_entry = GetEntry(child_obj); 2181 HeapEntry* child_entry = GetEntry(child_obj);
2152 if (child_entry != NULL) { 2182 if (child_entry != NULL) {
2153 filler_->SetNamedReference(HeapGraphEdge::kShortcut, 2183 filler_->SetNamedReference(HeapGraphEdge::kShortcut,
2154 parent_obj, 2184 parent_obj,
2155 parent_entry, 2185 parent_entry,
2156 collection_->names()->GetName(reference_name), 2186 collection_->names()->GetName(reference_name),
2157 child_obj, 2187 child_obj,
2158 child_entry); 2188 child_entry);
2159 } 2189 }
2160 } 2190 }
(...skipping 986 matching lines...) Expand 10 before | Expand all | Expand 10 after
3147 3177
3148 3178
3149 String* GetConstructorNameForHeapProfile(JSObject* object) { 3179 String* GetConstructorNameForHeapProfile(JSObject* object) {
3150 if (object->IsJSFunction()) return Heap::closure_symbol(); 3180 if (object->IsJSFunction()) return Heap::closure_symbol();
3151 return object->constructor_name(); 3181 return object->constructor_name();
3152 } 3182 }
3153 3183
3154 } } // namespace v8::internal 3184 } } // namespace v8::internal
3155 3185
3156 #endif // ENABLE_LOGGING_AND_PROFILING 3186 #endif // ENABLE_LOGGING_AND_PROFILING
OLDNEW
« src/objects-inl.h ('K') | « src/profile-generator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698