OLD | NEW |
---|---|
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 Loading... | |
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 intptr_t untagged = reinterpret_cast<intptr_t>(*field) & ~kFailureTagMask; | |
1853 *field = reinterpret_cast<Object*>(untagged | kHeapObjectTag); | |
1854 ASSERT((*field)->IsHeapObject()); | |
1855 return true; | |
1856 } | |
1857 return false; | |
1858 } | |
1844 V8HeapExplorer* generator_; | 1859 V8HeapExplorer* generator_; |
1845 HeapObject* parent_obj_; | 1860 HeapObject* parent_obj_; |
1846 HeapEntry* parent_; | 1861 HeapEntry* parent_; |
1847 HeapObjectsSet* known_references_; | 1862 bool process_field_marks_; |
1848 int next_index_; | 1863 int next_index_; |
1849 }; | 1864 }; |
1850 | 1865 |
1851 | 1866 |
1852 void V8HeapExplorer::ExtractReferences(HeapObject* obj) { | 1867 void V8HeapExplorer::ExtractReferences(HeapObject* obj) { |
1853 HeapEntry* entry = GetEntry(obj); | 1868 HeapEntry* entry = GetEntry(obj); |
1854 if (entry == NULL) return; // No interest in this object. | 1869 if (entry == NULL) return; // No interest in this object. |
1855 | 1870 |
1856 known_references_.Clear(); | |
1857 if (obj->IsJSGlobalProxy()) { | 1871 if (obj->IsJSGlobalProxy()) { |
1858 // We need to reference JS global objects from snapshot's root. | 1872 // We need to reference JS global objects from snapshot's root. |
1859 // We use JSGlobalProxy because this is what embedder (e.g. browser) | 1873 // We use JSGlobalProxy because this is what embedder (e.g. browser) |
1860 // uses for the global object. | 1874 // uses for the global object. |
1861 JSGlobalProxy* proxy = JSGlobalProxy::cast(obj); | 1875 JSGlobalProxy* proxy = JSGlobalProxy::cast(obj); |
1862 SetRootShortcutReference(proxy->map()->prototype()); | 1876 SetRootShortcutReference(proxy->map()->prototype()); |
1863 IndexedReferencesExtractor refs_extractor(this, obj, entry); | 1877 IndexedReferencesExtractor refs_extractor(this, obj, entry); |
1864 obj->Iterate(&refs_extractor); | 1878 obj->Iterate(&refs_extractor); |
1865 } else if (obj->IsJSObject()) { | 1879 } else if (obj->IsJSObject()) { |
1866 JSObject* js_obj = JSObject::cast(obj); | 1880 JSObject* js_obj = JSObject::cast(obj); |
1867 ExtractClosureReferences(js_obj, entry); | 1881 ExtractClosureReferences(js_obj, entry); |
1868 ExtractPropertyReferences(js_obj, entry); | 1882 ExtractPropertyReferences(js_obj, entry); |
1869 ExtractElementReferences(js_obj, entry); | 1883 ExtractElementReferences(js_obj, entry); |
1870 ExtractInternalReferences(js_obj, entry); | 1884 ExtractInternalReferences(js_obj, entry); |
1871 SetPropertyReference( | 1885 SetPropertyReference(obj, entry, |
1872 obj, entry, Heap::Proto_symbol(), js_obj->GetPrototype()); | 1886 Heap::Proto_symbol(), js_obj->GetPrototype()); |
1873 if (obj->IsJSFunction()) { | 1887 if (obj->IsJSFunction()) { |
1874 JSFunction* js_fun = JSFunction::cast(obj); | 1888 JSFunction* js_fun = JSFunction::cast(js_obj); |
1875 if (js_fun->has_prototype()) { | 1889 SetInternalReference( |
1876 SetPropertyReference( | 1890 js_fun, entry, |
1877 obj, entry, Heap::prototype_symbol(), js_fun->prototype()); | 1891 "code", js_fun->shared(), |
1892 JSFunction::kSharedFunctionInfoOffset); | |
1893 Object* proto_or_map = js_fun->prototype_or_initial_map(); | |
1894 if (!proto_or_map->IsTheHole()) { | |
1895 if (!proto_or_map->IsMap()) { | |
1896 SetPropertyReference( | |
1897 obj, entry, | |
1898 Heap::prototype_symbol(), proto_or_map, | |
1899 JSFunction::kPrototypeOrInitialMapOffset); | |
1900 } else { | |
1901 SetPropertyReference( | |
1902 obj, entry, | |
1903 Heap::prototype_symbol(), js_fun->prototype()); | |
1904 } | |
1878 } | 1905 } |
1879 } | 1906 } |
1880 IndexedReferencesExtractor refs_extractor( | 1907 IndexedReferencesExtractor refs_extractor(this, obj, entry, true); |
1881 this, obj, entry, &known_references_); | |
1882 obj->Iterate(&refs_extractor); | 1908 obj->Iterate(&refs_extractor); |
1883 } else if (obj->IsString()) { | 1909 } else if (obj->IsString()) { |
1884 if (obj->IsConsString()) { | 1910 if (obj->IsConsString()) { |
1885 ConsString* cs = ConsString::cast(obj); | 1911 ConsString* cs = ConsString::cast(obj); |
1886 SetInternalReference(obj, entry, 1, cs->first()); | 1912 SetInternalReference(obj, entry, 1, cs->first()); |
1887 SetInternalReference(obj, entry, 2, cs->second()); | 1913 SetInternalReference(obj, entry, 2, cs->second()); |
1888 } | 1914 } |
1889 } else { | 1915 } else { |
1890 IndexedReferencesExtractor refs_extractor(this, obj, entry); | 1916 IndexedReferencesExtractor refs_extractor(this, obj, entry); |
1891 obj->Iterate(&refs_extractor); | 1917 obj->Iterate(&refs_extractor); |
(...skipping 12 matching lines...) Expand all Loading... | |
1904 context->closure()->shared()->scope_info(); | 1930 context->closure()->shared()->scope_info(); |
1905 ScopeInfo<ZoneListAllocationPolicy> zone_scope_info(serialized_scope_info); | 1931 ScopeInfo<ZoneListAllocationPolicy> zone_scope_info(serialized_scope_info); |
1906 int locals_number = zone_scope_info.NumberOfLocals(); | 1932 int locals_number = zone_scope_info.NumberOfLocals(); |
1907 for (int i = 0; i < locals_number; ++i) { | 1933 for (int i = 0; i < locals_number; ++i) { |
1908 String* local_name = *zone_scope_info.LocalName(i); | 1934 String* local_name = *zone_scope_info.LocalName(i); |
1909 int idx = serialized_scope_info->ContextSlotIndex(local_name, NULL); | 1935 int idx = serialized_scope_info->ContextSlotIndex(local_name, NULL); |
1910 if (idx >= 0 && idx < context->length()) { | 1936 if (idx >= 0 && idx < context->length()) { |
1911 SetClosureReference(js_obj, entry, local_name, context->get(idx)); | 1937 SetClosureReference(js_obj, entry, local_name, context->get(idx)); |
1912 } | 1938 } |
1913 } | 1939 } |
1914 SetInternalReference(js_obj, entry, "code", func->shared()); | |
1915 } | 1940 } |
1916 } | 1941 } |
1917 | 1942 |
1918 | 1943 |
1919 void V8HeapExplorer::ExtractPropertyReferences(JSObject* js_obj, | 1944 void V8HeapExplorer::ExtractPropertyReferences(JSObject* js_obj, |
1920 HeapEntry* entry) { | 1945 HeapEntry* entry) { |
1921 if (js_obj->HasFastProperties()) { | 1946 if (js_obj->HasFastProperties()) { |
1922 DescriptorArray* descs = js_obj->map()->instance_descriptors(); | 1947 DescriptorArray* descs = js_obj->map()->instance_descriptors(); |
1923 for (int i = 0; i < descs->number_of_descriptors(); i++) { | 1948 for (int i = 0; i < descs->number_of_descriptors(); i++) { |
1924 switch (descs->GetType(i)) { | 1949 switch (descs->GetType(i)) { |
1925 case FIELD: { | 1950 case FIELD: { |
1926 int index = descs->GetFieldIndex(i); | 1951 int index = descs->GetFieldIndex(i); |
1927 SetPropertyReference( | 1952 if (index - js_obj->map()->inobject_properties() < 0) { |
Vitaly Repeshko
2011/03/18 12:36:03
nit: It's probably more natural to write "index <
mnaganov (inactive)
2011/03/18 12:46:34
Sure. I also have noted this afterwards.
| |
1928 js_obj, entry, descs->GetKey(i), js_obj->FastPropertyAt(index)); | 1953 SetPropertyReference( |
1954 js_obj, entry, | |
1955 descs->GetKey(i), js_obj->InObjectPropertyAt(index), | |
1956 js_obj->GetInObjectPropertyOffset(index)); | |
1957 } else { | |
1958 SetPropertyReference( | |
1959 js_obj, entry, | |
1960 descs->GetKey(i), js_obj->FastPropertyAt(index)); | |
1961 } | |
1929 break; | 1962 break; |
1930 } | 1963 } |
1931 case CONSTANT_FUNCTION: | 1964 case CONSTANT_FUNCTION: |
1932 SetPropertyReference( | 1965 SetPropertyReference( |
1933 js_obj, entry, descs->GetKey(i), descs->GetConstantFunction(i)); | 1966 js_obj, entry, |
1967 descs->GetKey(i), descs->GetConstantFunction(i)); | |
1934 break; | 1968 break; |
1935 default: ; | 1969 default: ; |
1936 } | 1970 } |
1937 } | 1971 } |
1938 } else { | 1972 } else { |
1939 StringDictionary* dictionary = js_obj->property_dictionary(); | 1973 StringDictionary* dictionary = js_obj->property_dictionary(); |
1940 int length = dictionary->Capacity(); | 1974 int length = dictionary->Capacity(); |
1941 for (int i = 0; i < length; ++i) { | 1975 for (int i = 0; i < length; ++i) { |
1942 Object* k = dictionary->KeyAt(i); | 1976 Object* k = dictionary->KeyAt(i); |
1943 if (dictionary->IsKey(k)) { | 1977 if (dictionary->IsKey(k)) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1983 } | 2017 } |
1984 } | 2018 } |
1985 } | 2019 } |
1986 | 2020 |
1987 | 2021 |
1988 void V8HeapExplorer::ExtractInternalReferences(JSObject* js_obj, | 2022 void V8HeapExplorer::ExtractInternalReferences(JSObject* js_obj, |
1989 HeapEntry* entry) { | 2023 HeapEntry* entry) { |
1990 int length = js_obj->GetInternalFieldCount(); | 2024 int length = js_obj->GetInternalFieldCount(); |
1991 for (int i = 0; i < length; ++i) { | 2025 for (int i = 0; i < length; ++i) { |
1992 Object* o = js_obj->GetInternalField(i); | 2026 Object* o = js_obj->GetInternalField(i); |
1993 SetInternalReference(js_obj, entry, i, o); | 2027 SetInternalReference( |
2028 js_obj, entry, i, o, js_obj->GetInternalFieldOffset(i)); | |
1994 } | 2029 } |
1995 } | 2030 } |
1996 | 2031 |
1997 | 2032 |
1998 HeapEntry* V8HeapExplorer::GetEntry(Object* obj) { | 2033 HeapEntry* V8HeapExplorer::GetEntry(Object* obj) { |
1999 if (!obj->IsHeapObject()) return NULL; | 2034 if (!obj->IsHeapObject()) return NULL; |
2000 return filler_->FindOrAddEntry(obj, this); | 2035 return filler_->FindOrAddEntry(obj, this); |
2001 } | 2036 } |
2002 | 2037 |
2003 | 2038 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2045 String* reference_name, | 2080 String* reference_name, |
2046 Object* child_obj) { | 2081 Object* child_obj) { |
2047 HeapEntry* child_entry = GetEntry(child_obj); | 2082 HeapEntry* child_entry = GetEntry(child_obj); |
2048 if (child_entry != NULL) { | 2083 if (child_entry != NULL) { |
2049 filler_->SetNamedReference(HeapGraphEdge::kContextVariable, | 2084 filler_->SetNamedReference(HeapGraphEdge::kContextVariable, |
2050 parent_obj, | 2085 parent_obj, |
2051 parent_entry, | 2086 parent_entry, |
2052 collection_->names()->GetName(reference_name), | 2087 collection_->names()->GetName(reference_name), |
2053 child_obj, | 2088 child_obj, |
2054 child_entry); | 2089 child_entry); |
2055 known_references_.Insert(child_obj); | |
2056 } | 2090 } |
2057 } | 2091 } |
2058 | 2092 |
2059 | 2093 |
2060 void V8HeapExplorer::SetElementReference(HeapObject* parent_obj, | 2094 void V8HeapExplorer::SetElementReference(HeapObject* parent_obj, |
2061 HeapEntry* parent_entry, | 2095 HeapEntry* parent_entry, |
2062 int index, | 2096 int index, |
2063 Object* child_obj) { | 2097 Object* child_obj) { |
2064 HeapEntry* child_entry = GetEntry(child_obj); | 2098 HeapEntry* child_entry = GetEntry(child_obj); |
2065 if (child_entry != NULL) { | 2099 if (child_entry != NULL) { |
2066 filler_->SetIndexedReference(HeapGraphEdge::kElement, | 2100 filler_->SetIndexedReference(HeapGraphEdge::kElement, |
2067 parent_obj, | 2101 parent_obj, |
2068 parent_entry, | 2102 parent_entry, |
2069 index, | 2103 index, |
2070 child_obj, | 2104 child_obj, |
2071 child_entry); | 2105 child_entry); |
2072 known_references_.Insert(child_obj); | |
2073 } | 2106 } |
2074 } | 2107 } |
2075 | 2108 |
2076 | 2109 |
2077 void V8HeapExplorer::SetInternalReference(HeapObject* parent_obj, | 2110 void V8HeapExplorer::SetInternalReference(HeapObject* parent_obj, |
2078 HeapEntry* parent_entry, | 2111 HeapEntry* parent_entry, |
2079 const char* reference_name, | 2112 const char* reference_name, |
2080 Object* child_obj) { | 2113 Object* child_obj, |
2114 int field_offset) { | |
2081 HeapEntry* child_entry = GetEntry(child_obj); | 2115 HeapEntry* child_entry = GetEntry(child_obj); |
2082 if (child_entry != NULL) { | 2116 if (child_entry != NULL) { |
2083 filler_->SetNamedReference(HeapGraphEdge::kInternal, | 2117 filler_->SetNamedReference(HeapGraphEdge::kInternal, |
2084 parent_obj, | 2118 parent_obj, |
2085 parent_entry, | 2119 parent_entry, |
2086 reference_name, | 2120 reference_name, |
2087 child_obj, | 2121 child_obj, |
2088 child_entry); | 2122 child_entry); |
2089 known_references_.Insert(child_obj); | 2123 IndexedReferencesExtractor::MarkVisitedField(parent_obj, field_offset); |
2090 } | 2124 } |
2091 } | 2125 } |
2092 | 2126 |
2093 | 2127 |
2094 void V8HeapExplorer::SetInternalReference(HeapObject* parent_obj, | 2128 void V8HeapExplorer::SetInternalReference(HeapObject* parent_obj, |
2095 HeapEntry* parent_entry, | 2129 HeapEntry* parent_entry, |
2096 int index, | 2130 int index, |
2097 Object* child_obj) { | 2131 Object* child_obj, |
2132 int field_offset) { | |
2098 HeapEntry* child_entry = GetEntry(child_obj); | 2133 HeapEntry* child_entry = GetEntry(child_obj); |
2099 if (child_entry != NULL) { | 2134 if (child_entry != NULL) { |
2100 filler_->SetNamedReference(HeapGraphEdge::kInternal, | 2135 filler_->SetNamedReference(HeapGraphEdge::kInternal, |
2101 parent_obj, | 2136 parent_obj, |
2102 parent_entry, | 2137 parent_entry, |
2103 collection_->names()->GetName(index), | 2138 collection_->names()->GetName(index), |
2104 child_obj, | 2139 child_obj, |
2105 child_entry); | 2140 child_entry); |
2106 known_references_.Insert(child_obj); | 2141 IndexedReferencesExtractor::MarkVisitedField(parent_obj, field_offset); |
2107 } | 2142 } |
2108 } | 2143 } |
2109 | 2144 |
2110 | 2145 |
2111 void V8HeapExplorer::SetHiddenReference(HeapObject* parent_obj, | 2146 void V8HeapExplorer::SetHiddenReference(HeapObject* parent_obj, |
2112 HeapEntry* parent_entry, | 2147 HeapEntry* parent_entry, |
2113 int index, | 2148 int index, |
2114 Object* child_obj) { | 2149 Object* child_obj) { |
2115 HeapEntry* child_entry = GetEntry(child_obj); | 2150 HeapEntry* child_entry = GetEntry(child_obj); |
2116 if (child_entry != NULL) { | 2151 if (child_entry != NULL) { |
2117 filler_->SetIndexedReference(HeapGraphEdge::kHidden, | 2152 filler_->SetIndexedReference(HeapGraphEdge::kHidden, |
2118 parent_obj, | 2153 parent_obj, |
2119 parent_entry, | 2154 parent_entry, |
2120 index, | 2155 index, |
2121 child_obj, | 2156 child_obj, |
2122 child_entry); | 2157 child_entry); |
2123 } | 2158 } |
2124 } | 2159 } |
2125 | 2160 |
2126 | 2161 |
2127 void V8HeapExplorer::SetPropertyReference(HeapObject* parent_obj, | 2162 void V8HeapExplorer::SetPropertyReference(HeapObject* parent_obj, |
2128 HeapEntry* parent_entry, | 2163 HeapEntry* parent_entry, |
2129 String* reference_name, | 2164 String* reference_name, |
2130 Object* child_obj) { | 2165 Object* child_obj, |
2166 int field_offset) { | |
2131 HeapEntry* child_entry = GetEntry(child_obj); | 2167 HeapEntry* child_entry = GetEntry(child_obj); |
2132 if (child_entry != NULL) { | 2168 if (child_entry != NULL) { |
2133 HeapGraphEdge::Type type = reference_name->length() > 0 ? | 2169 HeapGraphEdge::Type type = reference_name->length() > 0 ? |
2134 HeapGraphEdge::kProperty : HeapGraphEdge::kInternal; | 2170 HeapGraphEdge::kProperty : HeapGraphEdge::kInternal; |
2135 filler_->SetNamedReference(type, | 2171 filler_->SetNamedReference(type, |
2136 parent_obj, | 2172 parent_obj, |
2137 parent_entry, | 2173 parent_entry, |
2138 collection_->names()->GetName(reference_name), | 2174 collection_->names()->GetName(reference_name), |
2139 child_obj, | 2175 child_obj, |
2140 child_entry); | 2176 child_entry); |
2141 known_references_.Insert(child_obj); | 2177 IndexedReferencesExtractor::MarkVisitedField(parent_obj, field_offset); |
2142 } | 2178 } |
2143 } | 2179 } |
2144 | 2180 |
2145 | 2181 |
2146 void V8HeapExplorer::SetPropertyShortcutReference( | 2182 void V8HeapExplorer::SetPropertyShortcutReference(HeapObject* parent_obj, |
2147 HeapObject* parent_obj, | 2183 HeapEntry* parent_entry, |
2148 HeapEntry* parent_entry, | 2184 String* reference_name, |
2149 String* reference_name, | 2185 Object* child_obj) { |
2150 Object* child_obj) { | |
2151 HeapEntry* child_entry = GetEntry(child_obj); | 2186 HeapEntry* child_entry = GetEntry(child_obj); |
2152 if (child_entry != NULL) { | 2187 if (child_entry != NULL) { |
2153 filler_->SetNamedReference(HeapGraphEdge::kShortcut, | 2188 filler_->SetNamedReference(HeapGraphEdge::kShortcut, |
2154 parent_obj, | 2189 parent_obj, |
2155 parent_entry, | 2190 parent_entry, |
2156 collection_->names()->GetName(reference_name), | 2191 collection_->names()->GetName(reference_name), |
2157 child_obj, | 2192 child_obj, |
2158 child_entry); | 2193 child_entry); |
2159 } | 2194 } |
2160 } | 2195 } |
(...skipping 986 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3147 | 3182 |
3148 | 3183 |
3149 String* GetConstructorNameForHeapProfile(JSObject* object) { | 3184 String* GetConstructorNameForHeapProfile(JSObject* object) { |
3150 if (object->IsJSFunction()) return Heap::closure_symbol(); | 3185 if (object->IsJSFunction()) return Heap::closure_symbol(); |
3151 return object->constructor_name(); | 3186 return object->constructor_name(); |
3152 } | 3187 } |
3153 | 3188 |
3154 } } // namespace v8::internal | 3189 } } // namespace v8::internal |
3155 | 3190 |
3156 #endif // ENABLE_LOGGING_AND_PROFILING | 3191 #endif // ENABLE_LOGGING_AND_PROFILING |
OLD | NEW |