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 13 matching lines...) Expand all Loading... |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 #ifdef ENABLE_LOGGING_AND_PROFILING | 28 #ifdef ENABLE_LOGGING_AND_PROFILING |
29 | 29 |
30 #include "v8.h" | 30 #include "v8.h" |
31 #include "global-handles.h" | 31 #include "global-handles.h" |
32 #include "heap-profiler.h" | 32 #include "heap-profiler.h" |
33 #include "scopeinfo.h" | 33 #include "scopeinfo.h" |
34 #include "top.h" | |
35 #include "unicode.h" | 34 #include "unicode.h" |
36 #include "zone-inl.h" | 35 #include "zone-inl.h" |
37 | 36 |
38 #include "profile-generator-inl.h" | 37 #include "profile-generator-inl.h" |
39 | 38 |
40 namespace v8 { | 39 namespace v8 { |
41 namespace internal { | 40 namespace internal { |
42 | 41 |
43 | 42 |
44 TokenEnumerator::TokenEnumerator() | 43 TokenEnumerator::TokenEnumerator() |
45 : token_locations_(4), | 44 : token_locations_(4), |
46 token_removed_(4) { | 45 token_removed_(4) { |
47 } | 46 } |
48 | 47 |
49 | 48 |
50 TokenEnumerator::~TokenEnumerator() { | 49 TokenEnumerator::~TokenEnumerator() { |
| 50 Isolate* isolate = Isolate::Current(); |
51 for (int i = 0; i < token_locations_.length(); ++i) { | 51 for (int i = 0; i < token_locations_.length(); ++i) { |
52 if (!token_removed_[i]) { | 52 if (!token_removed_[i]) { |
53 GlobalHandles::ClearWeakness(token_locations_[i]); | 53 isolate->global_handles()->ClearWeakness(token_locations_[i]); |
54 GlobalHandles::Destroy(token_locations_[i]); | 54 isolate->global_handles()->Destroy(token_locations_[i]); |
55 } | 55 } |
56 } | 56 } |
57 } | 57 } |
58 | 58 |
59 | 59 |
60 int TokenEnumerator::GetTokenId(Object* token) { | 60 int TokenEnumerator::GetTokenId(Object* token) { |
| 61 Isolate* isolate = Isolate::Current(); |
61 if (token == NULL) return TokenEnumerator::kNoSecurityToken; | 62 if (token == NULL) return TokenEnumerator::kNoSecurityToken; |
62 for (int i = 0; i < token_locations_.length(); ++i) { | 63 for (int i = 0; i < token_locations_.length(); ++i) { |
63 if (*token_locations_[i] == token && !token_removed_[i]) return i; | 64 if (*token_locations_[i] == token && !token_removed_[i]) return i; |
64 } | 65 } |
65 Handle<Object> handle = GlobalHandles::Create(token); | 66 Handle<Object> handle = isolate->global_handles()->Create(token); |
66 // handle.location() points to a memory cell holding a pointer | 67 // handle.location() points to a memory cell holding a pointer |
67 // to a token object in the V8's heap. | 68 // to a token object in the V8's heap. |
68 GlobalHandles::MakeWeak(handle.location(), this, TokenRemovedCallback); | 69 isolate->global_handles()->MakeWeak(handle.location(), this, |
| 70 TokenRemovedCallback); |
69 token_locations_.Add(handle.location()); | 71 token_locations_.Add(handle.location()); |
70 token_removed_.Add(false); | 72 token_removed_.Add(false); |
71 return token_locations_.length() - 1; | 73 return token_locations_.length() - 1; |
72 } | 74 } |
73 | 75 |
74 | 76 |
75 void TokenEnumerator::TokenRemovedCallback(v8::Persistent<v8::Value> handle, | 77 void TokenEnumerator::TokenRemovedCallback(v8::Persistent<v8::Value> handle, |
76 void* parameter) { | 78 void* parameter) { |
77 reinterpret_cast<TokenEnumerator*>(parameter)->TokenRemoved( | 79 reinterpret_cast<TokenEnumerator*>(parameter)->TokenRemoved( |
78 Utils::OpenHandle(*handle).location()); | 80 Utils::OpenHandle(*handle).location()); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 } | 157 } |
156 return ""; | 158 return ""; |
157 } | 159 } |
158 | 160 |
159 | 161 |
160 const char* StringsStorage::GetName(int index) { | 162 const char* StringsStorage::GetName(int index) { |
161 return GetFormatted("%d", index); | 163 return GetFormatted("%d", index); |
162 } | 164 } |
163 | 165 |
164 | 166 |
165 const char* CodeEntry::kEmptyNamePrefix = ""; | 167 const char* const CodeEntry::kEmptyNamePrefix = ""; |
166 | 168 |
167 | 169 |
168 void CodeEntry::CopyData(const CodeEntry& source) { | 170 void CodeEntry::CopyData(const CodeEntry& source) { |
169 tag_ = source.tag_; | 171 tag_ = source.tag_; |
170 name_prefix_ = source.name_prefix_; | 172 name_prefix_ = source.name_prefix_; |
171 name_ = source.name_; | 173 name_ = source.name_; |
172 resource_name_ = source.resource_name_; | 174 resource_name_ = source.resource_name_; |
173 line_number_ = source.line_number_; | 175 line_number_ = source.line_number_; |
174 } | 176 } |
175 | 177 |
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
776 (measured_ticks_per_ms - ticks_per_ms_) / measurements_count_; | 778 (measured_ticks_per_ms - ticks_per_ms_) / measurements_count_; |
777 // Update the externally accessible result. | 779 // Update the externally accessible result. |
778 result_ = static_cast<AtomicWord>(ticks_per_ms_ * kResultScale); | 780 result_ = static_cast<AtomicWord>(ticks_per_ms_ * kResultScale); |
779 } | 781 } |
780 last_wall_time_ = current_time; | 782 last_wall_time_ = current_time; |
781 wall_time_query_countdown_ = | 783 wall_time_query_countdown_ = |
782 static_cast<unsigned>(kWallTimeQueryIntervalMs * ticks_per_ms_); | 784 static_cast<unsigned>(kWallTimeQueryIntervalMs * ticks_per_ms_); |
783 } | 785 } |
784 | 786 |
785 | 787 |
786 const char* ProfileGenerator::kAnonymousFunctionName = "(anonymous function)"; | 788 const char* const ProfileGenerator::kAnonymousFunctionName = |
787 const char* ProfileGenerator::kProgramEntryName = "(program)"; | 789 "(anonymous function)"; |
788 const char* ProfileGenerator::kGarbageCollectorEntryName = | 790 const char* const ProfileGenerator::kProgramEntryName = |
789 "(garbage collector)"; | 791 "(program)"; |
| 792 const char* const ProfileGenerator::kGarbageCollectorEntryName = |
| 793 "(garbage collector)"; |
790 | 794 |
791 | 795 |
792 ProfileGenerator::ProfileGenerator(CpuProfilesCollection* profiles) | 796 ProfileGenerator::ProfileGenerator(CpuProfilesCollection* profiles) |
793 : profiles_(profiles), | 797 : profiles_(profiles), |
794 program_entry_( | 798 program_entry_( |
795 profiles->NewCodeEntry(Logger::FUNCTION_TAG, kProgramEntryName)), | 799 profiles->NewCodeEntry(Logger::FUNCTION_TAG, kProgramEntryName)), |
796 gc_entry_( | 800 gc_entry_( |
797 profiles->NewCodeEntry(Logger::BUILTIN_TAG, | 801 profiles->NewCodeEntry(Logger::BUILTIN_TAG, |
798 kGarbageCollectorEntryName)) { | 802 kGarbageCollectorEntryName)) { |
799 } | 803 } |
(...skipping 1075 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1875 JSGlobalProxy* proxy = JSGlobalProxy::cast(obj); | 1879 JSGlobalProxy* proxy = JSGlobalProxy::cast(obj); |
1876 SetRootShortcutReference(proxy->map()->prototype()); | 1880 SetRootShortcutReference(proxy->map()->prototype()); |
1877 IndexedReferencesExtractor refs_extractor(this, obj, entry); | 1881 IndexedReferencesExtractor refs_extractor(this, obj, entry); |
1878 obj->Iterate(&refs_extractor); | 1882 obj->Iterate(&refs_extractor); |
1879 } else if (obj->IsJSObject()) { | 1883 } else if (obj->IsJSObject()) { |
1880 JSObject* js_obj = JSObject::cast(obj); | 1884 JSObject* js_obj = JSObject::cast(obj); |
1881 ExtractClosureReferences(js_obj, entry); | 1885 ExtractClosureReferences(js_obj, entry); |
1882 ExtractPropertyReferences(js_obj, entry); | 1886 ExtractPropertyReferences(js_obj, entry); |
1883 ExtractElementReferences(js_obj, entry); | 1887 ExtractElementReferences(js_obj, entry); |
1884 ExtractInternalReferences(js_obj, entry); | 1888 ExtractInternalReferences(js_obj, entry); |
1885 SetPropertyReference(obj, entry, | 1889 SetPropertyReference( |
1886 Heap::Proto_symbol(), js_obj->GetPrototype()); | 1890 obj, entry, HEAP->Proto_symbol(), js_obj->GetPrototype()); |
1887 if (obj->IsJSFunction()) { | 1891 if (obj->IsJSFunction()) { |
1888 JSFunction* js_fun = JSFunction::cast(js_obj); | 1892 JSFunction* js_fun = JSFunction::cast(js_obj); |
1889 SetInternalReference( | 1893 SetInternalReference( |
1890 js_fun, entry, | 1894 js_fun, entry, |
1891 "code", js_fun->shared(), | 1895 "code", js_fun->shared(), |
1892 JSFunction::kSharedFunctionInfoOffset); | 1896 JSFunction::kSharedFunctionInfoOffset); |
1893 Object* proto_or_map = js_fun->prototype_or_initial_map(); | 1897 Object* proto_or_map = js_fun->prototype_or_initial_map(); |
1894 if (!proto_or_map->IsTheHole()) { | 1898 if (!proto_or_map->IsTheHole()) { |
1895 if (!proto_or_map->IsMap()) { | 1899 if (!proto_or_map->IsMap()) { |
1896 SetPropertyReference( | 1900 SetPropertyReference( |
1897 obj, entry, | 1901 obj, entry, |
1898 Heap::prototype_symbol(), proto_or_map, | 1902 HEAP->prototype_symbol(), proto_or_map, |
1899 JSFunction::kPrototypeOrInitialMapOffset); | 1903 JSFunction::kPrototypeOrInitialMapOffset); |
1900 } else { | 1904 } else { |
1901 SetPropertyReference( | 1905 SetPropertyReference( |
1902 obj, entry, | 1906 obj, entry, |
1903 Heap::prototype_symbol(), js_fun->prototype()); | 1907 HEAP->prototype_symbol(), js_fun->prototype()); |
1904 } | 1908 } |
1905 } | 1909 } |
1906 } | 1910 } |
1907 IndexedReferencesExtractor refs_extractor(this, obj, entry, true); | 1911 IndexedReferencesExtractor refs_extractor(this, obj, entry, true); |
1908 obj->Iterate(&refs_extractor); | 1912 obj->Iterate(&refs_extractor); |
1909 } else if (obj->IsString()) { | 1913 } else if (obj->IsString()) { |
1910 if (obj->IsConsString()) { | 1914 if (obj->IsConsString()) { |
1911 ConsString* cs = ConsString::cast(obj); | 1915 ConsString* cs = ConsString::cast(obj); |
1912 SetInternalReference(obj, entry, 1, cs->first()); | 1916 SetInternalReference(obj, entry, 1, cs->first()); |
1913 SetInternalReference(obj, entry, 2, cs->second()); | 1917 SetInternalReference(obj, entry, 2, cs->second()); |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2062 ExtractReferences(obj); | 2066 ExtractReferences(obj); |
2063 if (!progress_->ProgressReport(false)) interrupted = true; | 2067 if (!progress_->ProgressReport(false)) interrupted = true; |
2064 } | 2068 } |
2065 } | 2069 } |
2066 if (interrupted) { | 2070 if (interrupted) { |
2067 filler_ = NULL; | 2071 filler_ = NULL; |
2068 return false; | 2072 return false; |
2069 } | 2073 } |
2070 SetRootGcRootsReference(); | 2074 SetRootGcRootsReference(); |
2071 RootsReferencesExtractor extractor(this); | 2075 RootsReferencesExtractor extractor(this); |
2072 Heap::IterateRoots(&extractor, VISIT_ALL); | 2076 HEAP->IterateRoots(&extractor, VISIT_ALL); |
2073 filler_ = NULL; | 2077 filler_ = NULL; |
2074 return progress_->ProgressReport(false); | 2078 return progress_->ProgressReport(false); |
2075 } | 2079 } |
2076 | 2080 |
2077 | 2081 |
2078 void V8HeapExplorer::SetClosureReference(HeapObject* parent_obj, | 2082 void V8HeapExplorer::SetClosureReference(HeapObject* parent_obj, |
2079 HeapEntry* parent_entry, | 2083 HeapEntry* parent_entry, |
2080 String* reference_name, | 2084 String* reference_name, |
2081 Object* child_obj) { | 2085 Object* child_obj) { |
2082 HeapEntry* child_entry = GetEntry(child_obj); | 2086 HeapEntry* child_entry = GetEntry(child_obj); |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2301 | 2305 |
2302 | 2306 |
2303 int NativeObjectsExplorer::EstimateObjectsCount() { | 2307 int NativeObjectsExplorer::EstimateObjectsCount() { |
2304 FillRetainedObjects(); | 2308 FillRetainedObjects(); |
2305 return objects_by_info_.occupancy(); | 2309 return objects_by_info_.occupancy(); |
2306 } | 2310 } |
2307 | 2311 |
2308 | 2312 |
2309 void NativeObjectsExplorer::FillRetainedObjects() { | 2313 void NativeObjectsExplorer::FillRetainedObjects() { |
2310 if (embedder_queried_) return; | 2314 if (embedder_queried_) return; |
| 2315 Isolate* isolate = Isolate::Current(); |
2311 // Record objects that are joined into ObjectGroups. | 2316 // Record objects that are joined into ObjectGroups. |
2312 Heap::CallGlobalGCPrologueCallback(); | 2317 isolate->heap()->CallGlobalGCPrologueCallback(); |
2313 List<ObjectGroup*>* groups = GlobalHandles::ObjectGroups(); | 2318 List<ObjectGroup*>* groups = isolate->global_handles()->object_groups(); |
2314 for (int i = 0; i < groups->length(); ++i) { | 2319 for (int i = 0; i < groups->length(); ++i) { |
2315 ObjectGroup* group = groups->at(i); | 2320 ObjectGroup* group = groups->at(i); |
2316 if (group->info_ == NULL) continue; | 2321 if (group->info_ == NULL) continue; |
2317 List<HeapObject*>* list = GetListMaybeDisposeInfo(group->info_); | 2322 List<HeapObject*>* list = GetListMaybeDisposeInfo(group->info_); |
2318 for (int j = 0; j < group->objects_.length(); ++j) { | 2323 for (int j = 0; j < group->objects_.length(); ++j) { |
2319 HeapObject* obj = HeapObject::cast(*group->objects_[j]); | 2324 HeapObject* obj = HeapObject::cast(*group->objects_[j]); |
2320 list->Add(obj); | 2325 list->Add(obj); |
2321 in_groups_.Insert(obj); | 2326 in_groups_.Insert(obj); |
2322 } | 2327 } |
2323 group->info_ = NULL; // Acquire info object ownership. | 2328 group->info_ = NULL; // Acquire info object ownership. |
2324 } | 2329 } |
2325 GlobalHandles::RemoveObjectGroups(); | 2330 isolate->global_handles()->RemoveObjectGroups(); |
2326 Heap::CallGlobalGCEpilogueCallback(); | 2331 isolate->heap()->CallGlobalGCEpilogueCallback(); |
2327 // Record objects that are not in ObjectGroups, but have class ID. | 2332 // Record objects that are not in ObjectGroups, but have class ID. |
2328 GlobalHandlesExtractor extractor(this); | 2333 GlobalHandlesExtractor extractor(this); |
2329 GlobalHandles::IterateAllRootsWithClassIds(&extractor); | 2334 isolate->global_handles()->IterateAllRootsWithClassIds(&extractor); |
2330 embedder_queried_ = true; | 2335 embedder_queried_ = true; |
2331 } | 2336 } |
2332 | 2337 |
2333 | 2338 |
2334 List<HeapObject*>* NativeObjectsExplorer::GetListMaybeDisposeInfo( | 2339 List<HeapObject*>* NativeObjectsExplorer::GetListMaybeDisposeInfo( |
2335 v8::RetainedObjectInfo* info) { | 2340 v8::RetainedObjectInfo* info) { |
2336 HashMap::Entry* entry = | 2341 HashMap::Entry* entry = |
2337 objects_by_info_.Lookup(info, InfoHash(info), true); | 2342 objects_by_info_.Lookup(info, InfoHash(info), true); |
2338 if (entry->value != NULL) { | 2343 if (entry->value != NULL) { |
2339 info->Dispose(); | 2344 info->Dispose(); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2397 void NativeObjectsExplorer::SetRootNativesRootReference() { | 2402 void NativeObjectsExplorer::SetRootNativesRootReference() { |
2398 filler_->SetIndexedAutoIndexReference( | 2403 filler_->SetIndexedAutoIndexReference( |
2399 HeapGraphEdge::kElement, | 2404 HeapGraphEdge::kElement, |
2400 V8HeapExplorer::kInternalRootObject, snapshot_->root(), | 2405 V8HeapExplorer::kInternalRootObject, snapshot_->root(), |
2401 kNativesRootObject, snapshot_->natives_root()); | 2406 kNativesRootObject, snapshot_->natives_root()); |
2402 } | 2407 } |
2403 | 2408 |
2404 | 2409 |
2405 void NativeObjectsExplorer::VisitSubtreeWrapper(Object** p, uint16_t class_id) { | 2410 void NativeObjectsExplorer::VisitSubtreeWrapper(Object** p, uint16_t class_id) { |
2406 if (in_groups_.Contains(*p)) return; | 2411 if (in_groups_.Contains(*p)) return; |
| 2412 Isolate* isolate = Isolate::Current(); |
2407 v8::RetainedObjectInfo* info = | 2413 v8::RetainedObjectInfo* info = |
2408 HeapProfiler::ExecuteWrapperClassCallback(class_id, p); | 2414 isolate->heap_profiler()->ExecuteWrapperClassCallback(class_id, p); |
2409 if (info == NULL) return; | 2415 if (info == NULL) return; |
2410 GetListMaybeDisposeInfo(info)->Add(HeapObject::cast(*p)); | 2416 GetListMaybeDisposeInfo(info)->Add(HeapObject::cast(*p)); |
2411 } | 2417 } |
2412 | 2418 |
2413 | 2419 |
2414 HeapSnapshotGenerator::HeapSnapshotGenerator(HeapSnapshot* snapshot, | 2420 HeapSnapshotGenerator::HeapSnapshotGenerator(HeapSnapshot* snapshot, |
2415 v8::ActivityControl* control) | 2421 v8::ActivityControl* control) |
2416 : snapshot_(snapshot), | 2422 : snapshot_(snapshot), |
2417 control_(control), | 2423 control_(control), |
2418 v8_heap_explorer_(snapshot_, this), | 2424 v8_heap_explorer_(snapshot_, this), |
(...skipping 756 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3175 | 3181 |
3176 void HeapSnapshotJSONSerializer::SortHashMap( | 3182 void HeapSnapshotJSONSerializer::SortHashMap( |
3177 HashMap* map, List<HashMap::Entry*>* sorted_entries) { | 3183 HashMap* map, List<HashMap::Entry*>* sorted_entries) { |
3178 for (HashMap::Entry* p = map->Start(); p != NULL; p = map->Next(p)) | 3184 for (HashMap::Entry* p = map->Start(); p != NULL; p = map->Next(p)) |
3179 sorted_entries->Add(p); | 3185 sorted_entries->Add(p); |
3180 sorted_entries->Sort(SortUsingEntryValue); | 3186 sorted_entries->Sort(SortUsingEntryValue); |
3181 } | 3187 } |
3182 | 3188 |
3183 | 3189 |
3184 String* GetConstructorNameForHeapProfile(JSObject* object) { | 3190 String* GetConstructorNameForHeapProfile(JSObject* object) { |
3185 if (object->IsJSFunction()) return Heap::closure_symbol(); | 3191 if (object->IsJSFunction()) return HEAP->closure_symbol(); |
3186 return object->constructor_name(); | 3192 return object->constructor_name(); |
3187 } | 3193 } |
3188 | 3194 |
3189 } } // namespace v8::internal | 3195 } } // namespace v8::internal |
3190 | 3196 |
3191 #endif // ENABLE_LOGGING_AND_PROFILING | 3197 #endif // ENABLE_LOGGING_AND_PROFILING |
OLD | NEW |