| 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 1074 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1874 JSGlobalProxy* proxy = JSGlobalProxy::cast(obj); | 1878 JSGlobalProxy* proxy = JSGlobalProxy::cast(obj); |
| 1875 SetRootShortcutReference(proxy->map()->prototype()); | 1879 SetRootShortcutReference(proxy->map()->prototype()); |
| 1876 IndexedReferencesExtractor refs_extractor(this, obj, entry); | 1880 IndexedReferencesExtractor refs_extractor(this, obj, entry); |
| 1877 obj->Iterate(&refs_extractor); | 1881 obj->Iterate(&refs_extractor); |
| 1878 } else if (obj->IsJSObject()) { | 1882 } else if (obj->IsJSObject()) { |
| 1879 JSObject* js_obj = JSObject::cast(obj); | 1883 JSObject* js_obj = JSObject::cast(obj); |
| 1880 ExtractClosureReferences(js_obj, entry); | 1884 ExtractClosureReferences(js_obj, entry); |
| 1881 ExtractPropertyReferences(js_obj, entry); | 1885 ExtractPropertyReferences(js_obj, entry); |
| 1882 ExtractElementReferences(js_obj, entry); | 1886 ExtractElementReferences(js_obj, entry); |
| 1883 ExtractInternalReferences(js_obj, entry); | 1887 ExtractInternalReferences(js_obj, entry); |
| 1884 SetPropertyReference(obj, entry, | 1888 SetPropertyReference( |
| 1885 Heap::Proto_symbol(), js_obj->GetPrototype()); | 1889 obj, entry, HEAP->Proto_symbol(), js_obj->GetPrototype()); |
| 1886 if (obj->IsJSFunction()) { | 1890 if (obj->IsJSFunction()) { |
| 1887 JSFunction* js_fun = JSFunction::cast(js_obj); | 1891 JSFunction* js_fun = JSFunction::cast(js_obj); |
| 1888 SetInternalReference( | 1892 SetInternalReference( |
| 1889 js_fun, entry, | 1893 js_fun, entry, |
| 1890 "code", js_fun->shared(), | 1894 "code", js_fun->shared(), |
| 1891 JSFunction::kSharedFunctionInfoOffset); | 1895 JSFunction::kSharedFunctionInfoOffset); |
| 1892 Object* proto_or_map = js_fun->prototype_or_initial_map(); | 1896 Object* proto_or_map = js_fun->prototype_or_initial_map(); |
| 1893 if (!proto_or_map->IsTheHole()) { | 1897 if (!proto_or_map->IsTheHole()) { |
| 1894 if (!proto_or_map->IsMap()) { | 1898 if (!proto_or_map->IsMap()) { |
| 1895 SetPropertyReference( | 1899 SetPropertyReference( |
| 1896 obj, entry, | 1900 obj, entry, |
| 1897 Heap::prototype_symbol(), proto_or_map, | 1901 HEAP->prototype_symbol(), proto_or_map, |
| 1898 JSFunction::kPrototypeOrInitialMapOffset); | 1902 JSFunction::kPrototypeOrInitialMapOffset); |
| 1899 } else { | 1903 } else { |
| 1900 SetPropertyReference( | 1904 SetPropertyReference( |
| 1901 obj, entry, | 1905 obj, entry, |
| 1902 Heap::prototype_symbol(), js_fun->prototype()); | 1906 HEAP->prototype_symbol(), js_fun->prototype()); |
| 1903 } | 1907 } |
| 1904 } | 1908 } |
| 1905 } | 1909 } |
| 1906 IndexedReferencesExtractor refs_extractor(this, obj, entry, true); | 1910 IndexedReferencesExtractor refs_extractor(this, obj, entry, true); |
| 1907 obj->Iterate(&refs_extractor); | 1911 obj->Iterate(&refs_extractor); |
| 1908 } else if (obj->IsString()) { | 1912 } else if (obj->IsString()) { |
| 1909 if (obj->IsConsString()) { | 1913 if (obj->IsConsString()) { |
| 1910 ConsString* cs = ConsString::cast(obj); | 1914 ConsString* cs = ConsString::cast(obj); |
| 1911 SetInternalReference(obj, entry, 1, cs->first()); | 1915 SetInternalReference(obj, entry, 1, cs->first()); |
| 1912 SetInternalReference(obj, entry, 2, cs->second()); | 1916 SetInternalReference(obj, entry, 2, cs->second()); |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2061 ExtractReferences(obj); | 2065 ExtractReferences(obj); |
| 2062 if (!progress_->ProgressReport(false)) interrupted = true; | 2066 if (!progress_->ProgressReport(false)) interrupted = true; |
| 2063 } | 2067 } |
| 2064 } | 2068 } |
| 2065 if (interrupted) { | 2069 if (interrupted) { |
| 2066 filler_ = NULL; | 2070 filler_ = NULL; |
| 2067 return false; | 2071 return false; |
| 2068 } | 2072 } |
| 2069 SetRootGcRootsReference(); | 2073 SetRootGcRootsReference(); |
| 2070 RootsReferencesExtractor extractor(this); | 2074 RootsReferencesExtractor extractor(this); |
| 2071 Heap::IterateRoots(&extractor, VISIT_ALL); | 2075 HEAP->IterateRoots(&extractor, VISIT_ALL); |
| 2072 filler_ = NULL; | 2076 filler_ = NULL; |
| 2073 return progress_->ProgressReport(false); | 2077 return progress_->ProgressReport(false); |
| 2074 } | 2078 } |
| 2075 | 2079 |
| 2076 | 2080 |
| 2077 void V8HeapExplorer::SetClosureReference(HeapObject* parent_obj, | 2081 void V8HeapExplorer::SetClosureReference(HeapObject* parent_obj, |
| 2078 HeapEntry* parent_entry, | 2082 HeapEntry* parent_entry, |
| 2079 String* reference_name, | 2083 String* reference_name, |
| 2080 Object* child_obj) { | 2084 Object* child_obj) { |
| 2081 HeapEntry* child_entry = GetEntry(child_obj); | 2085 HeapEntry* child_entry = GetEntry(child_obj); |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2300 | 2304 |
| 2301 | 2305 |
| 2302 int NativeObjectsExplorer::EstimateObjectsCount() { | 2306 int NativeObjectsExplorer::EstimateObjectsCount() { |
| 2303 FillRetainedObjects(); | 2307 FillRetainedObjects(); |
| 2304 return objects_by_info_.occupancy(); | 2308 return objects_by_info_.occupancy(); |
| 2305 } | 2309 } |
| 2306 | 2310 |
| 2307 | 2311 |
| 2308 void NativeObjectsExplorer::FillRetainedObjects() { | 2312 void NativeObjectsExplorer::FillRetainedObjects() { |
| 2309 if (embedder_queried_) return; | 2313 if (embedder_queried_) return; |
| 2314 Isolate* isolate = Isolate::Current(); |
| 2310 // Record objects that are joined into ObjectGroups. | 2315 // Record objects that are joined into ObjectGroups. |
| 2311 Heap::CallGlobalGCPrologueCallback(); | 2316 isolate->heap()->CallGlobalGCPrologueCallback(); |
| 2312 List<ObjectGroup*>* groups = GlobalHandles::ObjectGroups(); | 2317 List<ObjectGroup*>* groups = isolate->global_handles()->object_groups(); |
| 2313 for (int i = 0; i < groups->length(); ++i) { | 2318 for (int i = 0; i < groups->length(); ++i) { |
| 2314 ObjectGroup* group = groups->at(i); | 2319 ObjectGroup* group = groups->at(i); |
| 2315 if (group->info_ == NULL) continue; | 2320 if (group->info_ == NULL) continue; |
| 2316 List<HeapObject*>* list = GetListMaybeDisposeInfo(group->info_); | 2321 List<HeapObject*>* list = GetListMaybeDisposeInfo(group->info_); |
| 2317 for (int j = 0; j < group->objects_.length(); ++j) { | 2322 for (int j = 0; j < group->objects_.length(); ++j) { |
| 2318 HeapObject* obj = HeapObject::cast(*group->objects_[j]); | 2323 HeapObject* obj = HeapObject::cast(*group->objects_[j]); |
| 2319 list->Add(obj); | 2324 list->Add(obj); |
| 2320 in_groups_.Insert(obj); | 2325 in_groups_.Insert(obj); |
| 2321 } | 2326 } |
| 2322 group->info_ = NULL; // Acquire info object ownership. | 2327 group->info_ = NULL; // Acquire info object ownership. |
| 2323 } | 2328 } |
| 2324 GlobalHandles::RemoveObjectGroups(); | 2329 isolate->global_handles()->RemoveObjectGroups(); |
| 2325 Heap::CallGlobalGCEpilogueCallback(); | 2330 isolate->heap()->CallGlobalGCEpilogueCallback(); |
| 2326 // Record objects that are not in ObjectGroups, but have class ID. | 2331 // Record objects that are not in ObjectGroups, but have class ID. |
| 2327 GlobalHandlesExtractor extractor(this); | 2332 GlobalHandlesExtractor extractor(this); |
| 2328 GlobalHandles::IterateAllRootsWithClassIds(&extractor); | 2333 isolate->global_handles()->IterateAllRootsWithClassIds(&extractor); |
| 2329 embedder_queried_ = true; | 2334 embedder_queried_ = true; |
| 2330 } | 2335 } |
| 2331 | 2336 |
| 2332 | 2337 |
| 2333 List<HeapObject*>* NativeObjectsExplorer::GetListMaybeDisposeInfo( | 2338 List<HeapObject*>* NativeObjectsExplorer::GetListMaybeDisposeInfo( |
| 2334 v8::RetainedObjectInfo* info) { | 2339 v8::RetainedObjectInfo* info) { |
| 2335 HashMap::Entry* entry = | 2340 HashMap::Entry* entry = |
| 2336 objects_by_info_.Lookup(info, InfoHash(info), true); | 2341 objects_by_info_.Lookup(info, InfoHash(info), true); |
| 2337 if (entry->value != NULL) { | 2342 if (entry->value != NULL) { |
| 2338 info->Dispose(); | 2343 info->Dispose(); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2396 void NativeObjectsExplorer::SetRootNativesRootReference() { | 2401 void NativeObjectsExplorer::SetRootNativesRootReference() { |
| 2397 filler_->SetIndexedAutoIndexReference( | 2402 filler_->SetIndexedAutoIndexReference( |
| 2398 HeapGraphEdge::kElement, | 2403 HeapGraphEdge::kElement, |
| 2399 V8HeapExplorer::kInternalRootObject, snapshot_->root(), | 2404 V8HeapExplorer::kInternalRootObject, snapshot_->root(), |
| 2400 kNativesRootObject, snapshot_->natives_root()); | 2405 kNativesRootObject, snapshot_->natives_root()); |
| 2401 } | 2406 } |
| 2402 | 2407 |
| 2403 | 2408 |
| 2404 void NativeObjectsExplorer::VisitSubtreeWrapper(Object** p, uint16_t class_id) { | 2409 void NativeObjectsExplorer::VisitSubtreeWrapper(Object** p, uint16_t class_id) { |
| 2405 if (in_groups_.Contains(*p)) return; | 2410 if (in_groups_.Contains(*p)) return; |
| 2411 Isolate* isolate = Isolate::Current(); |
| 2406 v8::RetainedObjectInfo* info = | 2412 v8::RetainedObjectInfo* info = |
| 2407 HeapProfiler::ExecuteWrapperClassCallback(class_id, p); | 2413 isolate->heap_profiler()->ExecuteWrapperClassCallback(class_id, p); |
| 2408 if (info == NULL) return; | 2414 if (info == NULL) return; |
| 2409 GetListMaybeDisposeInfo(info)->Add(HeapObject::cast(*p)); | 2415 GetListMaybeDisposeInfo(info)->Add(HeapObject::cast(*p)); |
| 2410 } | 2416 } |
| 2411 | 2417 |
| 2412 | 2418 |
| 2413 HeapSnapshotGenerator::HeapSnapshotGenerator(HeapSnapshot* snapshot, | 2419 HeapSnapshotGenerator::HeapSnapshotGenerator(HeapSnapshot* snapshot, |
| 2414 v8::ActivityControl* control) | 2420 v8::ActivityControl* control) |
| 2415 : snapshot_(snapshot), | 2421 : snapshot_(snapshot), |
| 2416 control_(control), | 2422 control_(control), |
| 2417 v8_heap_explorer_(snapshot_, this), | 2423 v8_heap_explorer_(snapshot_, this), |
| (...skipping 761 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3179 | 3185 |
| 3180 void HeapSnapshotJSONSerializer::SortHashMap( | 3186 void HeapSnapshotJSONSerializer::SortHashMap( |
| 3181 HashMap* map, List<HashMap::Entry*>* sorted_entries) { | 3187 HashMap* map, List<HashMap::Entry*>* sorted_entries) { |
| 3182 for (HashMap::Entry* p = map->Start(); p != NULL; p = map->Next(p)) | 3188 for (HashMap::Entry* p = map->Start(); p != NULL; p = map->Next(p)) |
| 3183 sorted_entries->Add(p); | 3189 sorted_entries->Add(p); |
| 3184 sorted_entries->Sort(SortUsingEntryValue); | 3190 sorted_entries->Sort(SortUsingEntryValue); |
| 3185 } | 3191 } |
| 3186 | 3192 |
| 3187 | 3193 |
| 3188 String* GetConstructorNameForHeapProfile(JSObject* object) { | 3194 String* GetConstructorNameForHeapProfile(JSObject* object) { |
| 3189 if (object->IsJSFunction()) return Heap::closure_symbol(); | 3195 if (object->IsJSFunction()) return HEAP->closure_symbol(); |
| 3190 return object->constructor_name(); | 3196 return object->constructor_name(); |
| 3191 } | 3197 } |
| 3192 | 3198 |
| 3193 } } // namespace v8::internal | 3199 } } // namespace v8::internal |
| 3194 | 3200 |
| 3195 #endif // ENABLE_LOGGING_AND_PROFILING | 3201 #endif // ENABLE_LOGGING_AND_PROFILING |
| OLD | NEW |