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

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

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

Powered by Google App Engine
This is Rietveld 408576698