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

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

Issue 6711034: [Isolates] Merge (7253,7263] from bleeding_edge. (Closed)
Patch Set: 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
« 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 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 1812 matching lines...) Expand 10 before | Expand all | Expand 10 after
1823 obj = iterator.next(), ++objects_count) {} 1823 obj = iterator.next(), ++objects_count) {}
1824 return objects_count; 1824 return objects_count;
1825 } 1825 }
1826 1826
1827 1827
1828 class IndexedReferencesExtractor : public ObjectVisitor { 1828 class IndexedReferencesExtractor : public ObjectVisitor {
1829 public: 1829 public:
1830 IndexedReferencesExtractor(V8HeapExplorer* generator, 1830 IndexedReferencesExtractor(V8HeapExplorer* generator,
1831 HeapObject* parent_obj, 1831 HeapObject* parent_obj,
1832 HeapEntry* parent_entry, 1832 HeapEntry* parent_entry,
1833 HeapObjectsSet* known_references = NULL) 1833 bool process_field_marks = false)
1834 : generator_(generator), 1834 : generator_(generator),
1835 parent_obj_(parent_obj), 1835 parent_obj_(parent_obj),
1836 parent_(parent_entry), 1836 parent_(parent_entry),
1837 known_references_(known_references), 1837 process_field_marks_(process_field_marks),
1838 next_index_(1) { 1838 next_index_(1) {
1839 } 1839 }
1840 void VisitPointers(Object** start, Object** end) { 1840 void VisitPointers(Object** start, Object** end) {
1841 for (Object** p = start; p < end; p++) { 1841 for (Object** p = start; p < end; p++) {
1842 if (!known_references_ || !known_references_->Contains(*p)) { 1842 if (CheckVisitedAndUnmark(p)) continue;
1843 generator_->SetHiddenReference(parent_obj_, parent_, next_index_++, *p); 1843 generator_->SetHiddenReference(parent_obj_, parent_, next_index_++, *p);
1844 }
1845 } 1844 }
1846 } 1845 }
1846 static void MarkVisitedField(HeapObject* obj, int offset) {
1847 if (offset < 0) return;
1848 Address field = obj->address() + offset;
1849 ASSERT(!Memory::Object_at(field)->IsFailure());
1850 ASSERT(Memory::Object_at(field)->IsHeapObject());
1851 *field |= kFailureTag;
1852 }
1847 private: 1853 private:
1854 bool CheckVisitedAndUnmark(Object** field) {
1855 if (process_field_marks_ && (*field)->IsFailure()) {
1856 intptr_t untagged = reinterpret_cast<intptr_t>(*field) & ~kFailureTagMask;
1857 *field = reinterpret_cast<Object*>(untagged | kHeapObjectTag);
1858 ASSERT((*field)->IsHeapObject());
1859 return true;
1860 }
1861 return false;
1862 }
1848 V8HeapExplorer* generator_; 1863 V8HeapExplorer* generator_;
1849 HeapObject* parent_obj_; 1864 HeapObject* parent_obj_;
1850 HeapEntry* parent_; 1865 HeapEntry* parent_;
1851 HeapObjectsSet* known_references_; 1866 bool process_field_marks_;
1852 int next_index_; 1867 int next_index_;
1853 }; 1868 };
1854 1869
1855 1870
1856 void V8HeapExplorer::ExtractReferences(HeapObject* obj) { 1871 void V8HeapExplorer::ExtractReferences(HeapObject* obj) {
1857 HeapEntry* entry = GetEntry(obj); 1872 HeapEntry* entry = GetEntry(obj);
1858 if (entry == NULL) return; // No interest in this object. 1873 if (entry == NULL) return; // No interest in this object.
1859 1874
1860 known_references_.Clear();
1861 if (obj->IsJSGlobalProxy()) { 1875 if (obj->IsJSGlobalProxy()) {
1862 // We need to reference JS global objects from snapshot's root. 1876 // We need to reference JS global objects from snapshot's root.
1863 // We use JSGlobalProxy because this is what embedder (e.g. browser) 1877 // We use JSGlobalProxy because this is what embedder (e.g. browser)
1864 // uses for the global object. 1878 // uses for the global object.
1865 JSGlobalProxy* proxy = JSGlobalProxy::cast(obj); 1879 JSGlobalProxy* proxy = JSGlobalProxy::cast(obj);
1866 SetRootShortcutReference(proxy->map()->prototype()); 1880 SetRootShortcutReference(proxy->map()->prototype());
1867 IndexedReferencesExtractor refs_extractor(this, obj, entry); 1881 IndexedReferencesExtractor refs_extractor(this, obj, entry);
1868 obj->Iterate(&refs_extractor); 1882 obj->Iterate(&refs_extractor);
1869 } else if (obj->IsJSObject()) { 1883 } else if (obj->IsJSObject()) {
1870 JSObject* js_obj = JSObject::cast(obj); 1884 JSObject* js_obj = JSObject::cast(obj);
1871 ExtractClosureReferences(js_obj, entry); 1885 ExtractClosureReferences(js_obj, entry);
1872 ExtractPropertyReferences(js_obj, entry); 1886 ExtractPropertyReferences(js_obj, entry);
1873 ExtractElementReferences(js_obj, entry); 1887 ExtractElementReferences(js_obj, entry);
1874 ExtractInternalReferences(js_obj, entry); 1888 ExtractInternalReferences(js_obj, entry);
1875 SetPropertyReference( 1889 SetPropertyReference(
1876 obj, entry, HEAP->Proto_symbol(), js_obj->GetPrototype()); 1890 obj, entry, HEAP->Proto_symbol(), js_obj->GetPrototype());
1877 if (obj->IsJSFunction()) { 1891 if (obj->IsJSFunction()) {
1878 JSFunction* js_fun = JSFunction::cast(obj); 1892 JSFunction* js_fun = JSFunction::cast(js_obj);
1879 if (js_fun->has_prototype()) { 1893 SetInternalReference(
1880 SetPropertyReference( 1894 js_fun, entry,
1881 obj, entry, HEAP->prototype_symbol(), js_fun->prototype()); 1895 "code", js_fun->shared(),
1896 JSFunction::kSharedFunctionInfoOffset);
1897 Object* proto_or_map = js_fun->prototype_or_initial_map();
1898 if (!proto_or_map->IsTheHole()) {
1899 if (!proto_or_map->IsMap()) {
1900 SetPropertyReference(
1901 obj, entry,
1902 HEAP->prototype_symbol(), proto_or_map,
1903 JSFunction::kPrototypeOrInitialMapOffset);
1904 } else {
1905 SetPropertyReference(
1906 obj, entry,
1907 HEAP->prototype_symbol(), js_fun->prototype());
1908 }
1882 } 1909 }
1883 } 1910 }
1884 IndexedReferencesExtractor refs_extractor( 1911 IndexedReferencesExtractor refs_extractor(this, obj, entry, true);
1885 this, obj, entry, &known_references_);
1886 obj->Iterate(&refs_extractor); 1912 obj->Iterate(&refs_extractor);
1887 } else if (obj->IsString()) { 1913 } else if (obj->IsString()) {
1888 if (obj->IsConsString()) { 1914 if (obj->IsConsString()) {
1889 ConsString* cs = ConsString::cast(obj); 1915 ConsString* cs = ConsString::cast(obj);
1890 SetInternalReference(obj, entry, 1, cs->first()); 1916 SetInternalReference(obj, entry, 1, cs->first());
1891 SetInternalReference(obj, entry, 2, cs->second()); 1917 SetInternalReference(obj, entry, 2, cs->second());
1892 } 1918 }
1893 } else { 1919 } else {
1894 IndexedReferencesExtractor refs_extractor(this, obj, entry); 1920 IndexedReferencesExtractor refs_extractor(this, obj, entry);
1895 obj->Iterate(&refs_extractor); 1921 obj->Iterate(&refs_extractor);
(...skipping 12 matching lines...) Expand all
1908 context->closure()->shared()->scope_info(); 1934 context->closure()->shared()->scope_info();
1909 ScopeInfo<ZoneListAllocationPolicy> zone_scope_info(serialized_scope_info); 1935 ScopeInfo<ZoneListAllocationPolicy> zone_scope_info(serialized_scope_info);
1910 int locals_number = zone_scope_info.NumberOfLocals(); 1936 int locals_number = zone_scope_info.NumberOfLocals();
1911 for (int i = 0; i < locals_number; ++i) { 1937 for (int i = 0; i < locals_number; ++i) {
1912 String* local_name = *zone_scope_info.LocalName(i); 1938 String* local_name = *zone_scope_info.LocalName(i);
1913 int idx = serialized_scope_info->ContextSlotIndex(local_name, NULL); 1939 int idx = serialized_scope_info->ContextSlotIndex(local_name, NULL);
1914 if (idx >= 0 && idx < context->length()) { 1940 if (idx >= 0 && idx < context->length()) {
1915 SetClosureReference(js_obj, entry, local_name, context->get(idx)); 1941 SetClosureReference(js_obj, entry, local_name, context->get(idx));
1916 } 1942 }
1917 } 1943 }
1918 SetInternalReference(js_obj, entry, "code", func->shared());
1919 } 1944 }
1920 } 1945 }
1921 1946
1922 1947
1923 void V8HeapExplorer::ExtractPropertyReferences(JSObject* js_obj, 1948 void V8HeapExplorer::ExtractPropertyReferences(JSObject* js_obj,
1924 HeapEntry* entry) { 1949 HeapEntry* entry) {
1925 if (js_obj->HasFastProperties()) { 1950 if (js_obj->HasFastProperties()) {
1926 DescriptorArray* descs = js_obj->map()->instance_descriptors(); 1951 DescriptorArray* descs = js_obj->map()->instance_descriptors();
1927 for (int i = 0; i < descs->number_of_descriptors(); i++) { 1952 for (int i = 0; i < descs->number_of_descriptors(); i++) {
1928 switch (descs->GetType(i)) { 1953 switch (descs->GetType(i)) {
1929 case FIELD: { 1954 case FIELD: {
1930 int index = descs->GetFieldIndex(i); 1955 int index = descs->GetFieldIndex(i);
1931 SetPropertyReference( 1956 if (index < js_obj->map()->inobject_properties()) {
1932 js_obj, entry, descs->GetKey(i), js_obj->FastPropertyAt(index)); 1957 SetPropertyReference(
1958 js_obj, entry,
1959 descs->GetKey(i), js_obj->InObjectPropertyAt(index),
1960 js_obj->GetInObjectPropertyOffset(index));
1961 } else {
1962 SetPropertyReference(
1963 js_obj, entry,
1964 descs->GetKey(i), js_obj->FastPropertyAt(index));
1965 }
1933 break; 1966 break;
1934 } 1967 }
1935 case CONSTANT_FUNCTION: 1968 case CONSTANT_FUNCTION:
1936 SetPropertyReference( 1969 SetPropertyReference(
1937 js_obj, entry, descs->GetKey(i), descs->GetConstantFunction(i)); 1970 js_obj, entry,
1971 descs->GetKey(i), descs->GetConstantFunction(i));
1938 break; 1972 break;
1939 default: ; 1973 default: ;
1940 } 1974 }
1941 } 1975 }
1942 } else { 1976 } else {
1943 StringDictionary* dictionary = js_obj->property_dictionary(); 1977 StringDictionary* dictionary = js_obj->property_dictionary();
1944 int length = dictionary->Capacity(); 1978 int length = dictionary->Capacity();
1945 for (int i = 0; i < length; ++i) { 1979 for (int i = 0; i < length; ++i) {
1946 Object* k = dictionary->KeyAt(i); 1980 Object* k = dictionary->KeyAt(i);
1947 if (dictionary->IsKey(k)) { 1981 if (dictionary->IsKey(k)) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1987 } 2021 }
1988 } 2022 }
1989 } 2023 }
1990 2024
1991 2025
1992 void V8HeapExplorer::ExtractInternalReferences(JSObject* js_obj, 2026 void V8HeapExplorer::ExtractInternalReferences(JSObject* js_obj,
1993 HeapEntry* entry) { 2027 HeapEntry* entry) {
1994 int length = js_obj->GetInternalFieldCount(); 2028 int length = js_obj->GetInternalFieldCount();
1995 for (int i = 0; i < length; ++i) { 2029 for (int i = 0; i < length; ++i) {
1996 Object* o = js_obj->GetInternalField(i); 2030 Object* o = js_obj->GetInternalField(i);
1997 SetInternalReference(js_obj, entry, i, o); 2031 SetInternalReference(
2032 js_obj, entry, i, o, js_obj->GetInternalFieldOffset(i));
1998 } 2033 }
1999 } 2034 }
2000 2035
2001 2036
2002 HeapEntry* V8HeapExplorer::GetEntry(Object* obj) { 2037 HeapEntry* V8HeapExplorer::GetEntry(Object* obj) {
2003 if (!obj->IsHeapObject()) return NULL; 2038 if (!obj->IsHeapObject()) return NULL;
2004 return filler_->FindOrAddEntry(obj, this); 2039 return filler_->FindOrAddEntry(obj, this);
2005 } 2040 }
2006 2041
2007 2042
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
2049 String* reference_name, 2084 String* reference_name,
2050 Object* child_obj) { 2085 Object* child_obj) {
2051 HeapEntry* child_entry = GetEntry(child_obj); 2086 HeapEntry* child_entry = GetEntry(child_obj);
2052 if (child_entry != NULL) { 2087 if (child_entry != NULL) {
2053 filler_->SetNamedReference(HeapGraphEdge::kContextVariable, 2088 filler_->SetNamedReference(HeapGraphEdge::kContextVariable,
2054 parent_obj, 2089 parent_obj,
2055 parent_entry, 2090 parent_entry,
2056 collection_->names()->GetName(reference_name), 2091 collection_->names()->GetName(reference_name),
2057 child_obj, 2092 child_obj,
2058 child_entry); 2093 child_entry);
2059 known_references_.Insert(child_obj);
2060 } 2094 }
2061 } 2095 }
2062 2096
2063 2097
2064 void V8HeapExplorer::SetElementReference(HeapObject* parent_obj, 2098 void V8HeapExplorer::SetElementReference(HeapObject* parent_obj,
2065 HeapEntry* parent_entry, 2099 HeapEntry* parent_entry,
2066 int index, 2100 int index,
2067 Object* child_obj) { 2101 Object* child_obj) {
2068 HeapEntry* child_entry = GetEntry(child_obj); 2102 HeapEntry* child_entry = GetEntry(child_obj);
2069 if (child_entry != NULL) { 2103 if (child_entry != NULL) {
2070 filler_->SetIndexedReference(HeapGraphEdge::kElement, 2104 filler_->SetIndexedReference(HeapGraphEdge::kElement,
2071 parent_obj, 2105 parent_obj,
2072 parent_entry, 2106 parent_entry,
2073 index, 2107 index,
2074 child_obj, 2108 child_obj,
2075 child_entry); 2109 child_entry);
2076 known_references_.Insert(child_obj);
2077 } 2110 }
2078 } 2111 }
2079 2112
2080 2113
2081 void V8HeapExplorer::SetInternalReference(HeapObject* parent_obj, 2114 void V8HeapExplorer::SetInternalReference(HeapObject* parent_obj,
2082 HeapEntry* parent_entry, 2115 HeapEntry* parent_entry,
2083 const char* reference_name, 2116 const char* reference_name,
2084 Object* child_obj) { 2117 Object* child_obj,
2118 int field_offset) {
2085 HeapEntry* child_entry = GetEntry(child_obj); 2119 HeapEntry* child_entry = GetEntry(child_obj);
2086 if (child_entry != NULL) { 2120 if (child_entry != NULL) {
2087 filler_->SetNamedReference(HeapGraphEdge::kInternal, 2121 filler_->SetNamedReference(HeapGraphEdge::kInternal,
2088 parent_obj, 2122 parent_obj,
2089 parent_entry, 2123 parent_entry,
2090 reference_name, 2124 reference_name,
2091 child_obj, 2125 child_obj,
2092 child_entry); 2126 child_entry);
2093 known_references_.Insert(child_obj); 2127 IndexedReferencesExtractor::MarkVisitedField(parent_obj, field_offset);
2094 } 2128 }
2095 } 2129 }
2096 2130
2097 2131
2098 void V8HeapExplorer::SetInternalReference(HeapObject* parent_obj, 2132 void V8HeapExplorer::SetInternalReference(HeapObject* parent_obj,
2099 HeapEntry* parent_entry, 2133 HeapEntry* parent_entry,
2100 int index, 2134 int index,
2101 Object* child_obj) { 2135 Object* child_obj,
2136 int field_offset) {
2102 HeapEntry* child_entry = GetEntry(child_obj); 2137 HeapEntry* child_entry = GetEntry(child_obj);
2103 if (child_entry != NULL) { 2138 if (child_entry != NULL) {
2104 filler_->SetNamedReference(HeapGraphEdge::kInternal, 2139 filler_->SetNamedReference(HeapGraphEdge::kInternal,
2105 parent_obj, 2140 parent_obj,
2106 parent_entry, 2141 parent_entry,
2107 collection_->names()->GetName(index), 2142 collection_->names()->GetName(index),
2108 child_obj, 2143 child_obj,
2109 child_entry); 2144 child_entry);
2110 known_references_.Insert(child_obj); 2145 IndexedReferencesExtractor::MarkVisitedField(parent_obj, field_offset);
2111 } 2146 }
2112 } 2147 }
2113 2148
2114 2149
2115 void V8HeapExplorer::SetHiddenReference(HeapObject* parent_obj, 2150 void V8HeapExplorer::SetHiddenReference(HeapObject* parent_obj,
2116 HeapEntry* parent_entry, 2151 HeapEntry* parent_entry,
2117 int index, 2152 int index,
2118 Object* child_obj) { 2153 Object* child_obj) {
2119 HeapEntry* child_entry = GetEntry(child_obj); 2154 HeapEntry* child_entry = GetEntry(child_obj);
2120 if (child_entry != NULL) { 2155 if (child_entry != NULL) {
2121 filler_->SetIndexedReference(HeapGraphEdge::kHidden, 2156 filler_->SetIndexedReference(HeapGraphEdge::kHidden,
2122 parent_obj, 2157 parent_obj,
2123 parent_entry, 2158 parent_entry,
2124 index, 2159 index,
2125 child_obj, 2160 child_obj,
2126 child_entry); 2161 child_entry);
2127 } 2162 }
2128 } 2163 }
2129 2164
2130 2165
2131 void V8HeapExplorer::SetPropertyReference(HeapObject* parent_obj, 2166 void V8HeapExplorer::SetPropertyReference(HeapObject* parent_obj,
2132 HeapEntry* parent_entry, 2167 HeapEntry* parent_entry,
2133 String* reference_name, 2168 String* reference_name,
2134 Object* child_obj) { 2169 Object* child_obj,
2170 int field_offset) {
2135 HeapEntry* child_entry = GetEntry(child_obj); 2171 HeapEntry* child_entry = GetEntry(child_obj);
2136 if (child_entry != NULL) { 2172 if (child_entry != NULL) {
2137 HeapGraphEdge::Type type = reference_name->length() > 0 ? 2173 HeapGraphEdge::Type type = reference_name->length() > 0 ?
2138 HeapGraphEdge::kProperty : HeapGraphEdge::kInternal; 2174 HeapGraphEdge::kProperty : HeapGraphEdge::kInternal;
2139 filler_->SetNamedReference(type, 2175 filler_->SetNamedReference(type,
2140 parent_obj, 2176 parent_obj,
2141 parent_entry, 2177 parent_entry,
2142 collection_->names()->GetName(reference_name), 2178 collection_->names()->GetName(reference_name),
2143 child_obj, 2179 child_obj,
2144 child_entry); 2180 child_entry);
2145 known_references_.Insert(child_obj); 2181 IndexedReferencesExtractor::MarkVisitedField(parent_obj, field_offset);
2146 } 2182 }
2147 } 2183 }
2148 2184
2149 2185
2150 void V8HeapExplorer::SetPropertyShortcutReference( 2186 void V8HeapExplorer::SetPropertyShortcutReference(HeapObject* parent_obj,
2151 HeapObject* parent_obj, 2187 HeapEntry* parent_entry,
2152 HeapEntry* parent_entry, 2188 String* reference_name,
2153 String* reference_name, 2189 Object* child_obj) {
2154 Object* child_obj) {
2155 HeapEntry* child_entry = GetEntry(child_obj); 2190 HeapEntry* child_entry = GetEntry(child_obj);
2156 if (child_entry != NULL) { 2191 if (child_entry != NULL) {
2157 filler_->SetNamedReference(HeapGraphEdge::kShortcut, 2192 filler_->SetNamedReference(HeapGraphEdge::kShortcut,
2158 parent_obj, 2193 parent_obj,
2159 parent_entry, 2194 parent_entry,
2160 collection_->names()->GetName(reference_name), 2195 collection_->names()->GetName(reference_name),
2161 child_obj, 2196 child_obj,
2162 child_entry); 2197 child_entry);
2163 } 2198 }
2164 } 2199 }
(...skipping 988 matching lines...) Expand 10 before | Expand all | Expand 10 after
3153 3188
3154 3189
3155 String* GetConstructorNameForHeapProfile(JSObject* object) { 3190 String* GetConstructorNameForHeapProfile(JSObject* object) {
3156 if (object->IsJSFunction()) return HEAP->closure_symbol(); 3191 if (object->IsJSFunction()) return HEAP->closure_symbol();
3157 return object->constructor_name(); 3192 return object->constructor_name();
3158 } 3193 }
3159 3194
3160 } } // namespace v8::internal 3195 } } // namespace v8::internal
3161 3196
3162 #endif // ENABLE_LOGGING_AND_PROFILING 3197 #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