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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 for (int i = 0; i < token_locations_.length(); ++i) { | 48 for (int i = 0; i < token_locations_.length(); ++i) { |
49 if (!token_removed_[i]) { | 49 if (!token_removed_[i]) { |
50 GlobalHandles::ClearWeakness(token_locations_[i]); | 50 GlobalHandles::ClearWeakness(token_locations_[i]); |
51 GlobalHandles::Destroy(token_locations_[i]); | 51 GlobalHandles::Destroy(token_locations_[i]); |
52 } | 52 } |
53 } | 53 } |
54 } | 54 } |
55 | 55 |
56 | 56 |
57 int TokenEnumerator::GetTokenId(Object* token) { | 57 int TokenEnumerator::GetTokenId(Object* token) { |
58 if (token == NULL) return CodeEntry::kNoSecurityToken; | 58 if (token == NULL) return TokenEnumerator::kNoSecurityToken; |
59 for (int i = 0; i < token_locations_.length(); ++i) { | 59 for (int i = 0; i < token_locations_.length(); ++i) { |
60 if (*token_locations_[i] == token && !token_removed_[i]) return i; | 60 if (*token_locations_[i] == token && !token_removed_[i]) return i; |
61 } | 61 } |
62 Handle<Object> handle = GlobalHandles::Create(token); | 62 Handle<Object> handle = GlobalHandles::Create(token); |
63 // handle.location() points to a memory cell holding a pointer | 63 // handle.location() points to a memory cell holding a pointer |
64 // to a token object in the V8's heap. | 64 // to a token object in the V8's heap. |
65 GlobalHandles::MakeWeak(handle.location(), this, TokenRemovedCallback); | 65 GlobalHandles::MakeWeak(handle.location(), this, TokenRemovedCallback); |
66 token_locations_.Add(handle.location()); | 66 token_locations_.Add(handle.location()); |
67 token_removed_.Add(false); | 67 token_removed_.Add(false); |
68 return token_locations_.length() - 1; | 68 return token_locations_.length() - 1; |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 | 164 |
165 } // namespace | 165 } // namespace |
166 | 166 |
167 | 167 |
168 ProfileTree::ProfileTree() | 168 ProfileTree::ProfileTree() |
169 : root_entry_(Logger::FUNCTION_TAG, | 169 : root_entry_(Logger::FUNCTION_TAG, |
170 "", | 170 "", |
171 "(root)", | 171 "(root)", |
172 "", | 172 "", |
173 0, | 173 0, |
174 CodeEntry::kNoSecurityToken), | 174 TokenEnumerator::kNoSecurityToken), |
175 root_(new ProfileNode(this, &root_entry_)) { | 175 root_(new ProfileNode(this, &root_entry_)) { |
176 } | 176 } |
177 | 177 |
178 | 178 |
179 ProfileTree::~ProfileTree() { | 179 ProfileTree::~ProfileTree() { |
180 DeleteNodesCallback cb; | 180 DeleteNodesCallback cb; |
181 TraverseDepthFirst(&cb); | 181 TraverseDepthFirst(&cb); |
182 } | 182 } |
183 | 183 |
184 | 184 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 void AfterAllChildrenTraversed(ProfileNode* parent) { } | 241 void AfterAllChildrenTraversed(ProfileNode* parent) { } |
242 | 242 |
243 void AfterChildTraversed(ProfileNode*, ProfileNode* child) { | 243 void AfterChildTraversed(ProfileNode*, ProfileNode* child) { |
244 if (stack_.last().src == child) { | 244 if (stack_.last().src == child) { |
245 stack_.RemoveLast(); | 245 stack_.RemoveLast(); |
246 } | 246 } |
247 } | 247 } |
248 | 248 |
249 private: | 249 private: |
250 bool IsTokenAcceptable(int token, int parent_token) { | 250 bool IsTokenAcceptable(int token, int parent_token) { |
251 if (token == CodeEntry::kNoSecurityToken | 251 if (token == TokenEnumerator::kNoSecurityToken |
252 || token == security_token_id_) return true; | 252 || token == security_token_id_) return true; |
253 if (token == CodeEntry::kInheritsSecurityToken) { | 253 if (token == TokenEnumerator::kInheritsSecurityToken) { |
254 ASSERT(parent_token != CodeEntry::kInheritsSecurityToken); | 254 ASSERT(parent_token != TokenEnumerator::kInheritsSecurityToken); |
255 return parent_token == CodeEntry::kNoSecurityToken | 255 return parent_token == TokenEnumerator::kNoSecurityToken |
256 || parent_token == security_token_id_; | 256 || parent_token == security_token_id_; |
257 } | 257 } |
258 return false; | 258 return false; |
259 } | 259 } |
260 | 260 |
261 List<NodesPair> stack_; | 261 List<NodesPair> stack_; |
262 int security_token_id_; | 262 int security_token_id_; |
263 }; | 263 }; |
264 | 264 |
265 } // namespace | 265 } // namespace |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 } | 366 } |
367 | 367 |
368 | 368 |
369 void CpuProfile::SetActualSamplingRate(double actual_sampling_rate) { | 369 void CpuProfile::SetActualSamplingRate(double actual_sampling_rate) { |
370 top_down_.SetTickRatePerMs(actual_sampling_rate); | 370 top_down_.SetTickRatePerMs(actual_sampling_rate); |
371 bottom_up_.SetTickRatePerMs(actual_sampling_rate); | 371 bottom_up_.SetTickRatePerMs(actual_sampling_rate); |
372 } | 372 } |
373 | 373 |
374 | 374 |
375 CpuProfile* CpuProfile::FilteredClone(int security_token_id) { | 375 CpuProfile* CpuProfile::FilteredClone(int security_token_id) { |
376 ASSERT(security_token_id != CodeEntry::kNoSecurityToken); | 376 ASSERT(security_token_id != TokenEnumerator::kNoSecurityToken); |
377 CpuProfile* clone = new CpuProfile(title_, uid_); | 377 CpuProfile* clone = new CpuProfile(title_, uid_); |
378 clone->top_down_.FilteredClone(&top_down_, security_token_id); | 378 clone->top_down_.FilteredClone(&top_down_, security_token_id); |
379 clone->bottom_up_.FilteredClone(&bottom_up_, security_token_id); | 379 clone->bottom_up_.FilteredClone(&bottom_up_, security_token_id); |
380 return clone; | 380 return clone; |
381 } | 381 } |
382 | 382 |
383 | 383 |
384 void CpuProfile::ShortPrint() { | 384 void CpuProfile::ShortPrint() { |
385 OS::Print("top down "); | 385 OS::Print("top down "); |
386 top_down_.ShortPrint(); | 386 top_down_.ShortPrint(); |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 profile = current_profiles_.Remove(i); | 510 profile = current_profiles_.Remove(i); |
511 break; | 511 break; |
512 } | 512 } |
513 } | 513 } |
514 current_profiles_semaphore_->Signal(); | 514 current_profiles_semaphore_->Signal(); |
515 | 515 |
516 if (profile != NULL) { | 516 if (profile != NULL) { |
517 profile->CalculateTotalTicks(); | 517 profile->CalculateTotalTicks(); |
518 profile->SetActualSamplingRate(actual_sampling_rate); | 518 profile->SetActualSamplingRate(actual_sampling_rate); |
519 List<CpuProfile*>* unabridged_list = | 519 List<CpuProfile*>* unabridged_list = |
520 profiles_by_token_[TokenToIndex(CodeEntry::kNoSecurityToken)]; | 520 profiles_by_token_[TokenToIndex(TokenEnumerator::kNoSecurityToken)]; |
521 unabridged_list->Add(profile); | 521 unabridged_list->Add(profile); |
522 HashMap::Entry* entry = | 522 HashMap::Entry* entry = |
523 profiles_uids_.Lookup(reinterpret_cast<void*>(profile->uid()), | 523 profiles_uids_.Lookup(reinterpret_cast<void*>(profile->uid()), |
524 static_cast<uint32_t>(profile->uid()), | 524 static_cast<uint32_t>(profile->uid()), |
525 true); | 525 true); |
526 ASSERT(entry->value == NULL); | 526 ASSERT(entry->value == NULL); |
527 entry->value = reinterpret_cast<void*>(unabridged_list->length() - 1); | 527 entry->value = reinterpret_cast<void*>(unabridged_list->length() - 1); |
528 return GetProfile(security_token_id, profile->uid()); | 528 return GetProfile(security_token_id, profile->uid()); |
529 } | 529 } |
530 return NULL; | 530 return NULL; |
(...skipping 12 matching lines...) Expand all Loading... |
543 HashMap::Entry* entry = profiles_uids_.Lookup(reinterpret_cast<void*>(uid), | 543 HashMap::Entry* entry = profiles_uids_.Lookup(reinterpret_cast<void*>(uid), |
544 static_cast<uint32_t>(uid), | 544 static_cast<uint32_t>(uid), |
545 false); | 545 false); |
546 int index; | 546 int index; |
547 if (entry != NULL) { | 547 if (entry != NULL) { |
548 index = static_cast<int>(reinterpret_cast<intptr_t>(entry->value)); | 548 index = static_cast<int>(reinterpret_cast<intptr_t>(entry->value)); |
549 } else { | 549 } else { |
550 return NULL; | 550 return NULL; |
551 } | 551 } |
552 List<CpuProfile*>* unabridged_list = | 552 List<CpuProfile*>* unabridged_list = |
553 profiles_by_token_[TokenToIndex(CodeEntry::kNoSecurityToken)]; | 553 profiles_by_token_[TokenToIndex(TokenEnumerator::kNoSecurityToken)]; |
554 if (security_token_id == CodeEntry::kNoSecurityToken) { | 554 if (security_token_id == TokenEnumerator::kNoSecurityToken) { |
555 return unabridged_list->at(index); | 555 return unabridged_list->at(index); |
556 } | 556 } |
557 List<CpuProfile*>* list = GetProfilesList(security_token_id); | 557 List<CpuProfile*>* list = GetProfilesList(security_token_id); |
558 if (list->at(index) == NULL) { | 558 if (list->at(index) == NULL) { |
559 list->at(index) = | 559 list->at(index) = |
560 unabridged_list->at(index)->FilteredClone(security_token_id); | 560 unabridged_list->at(index)->FilteredClone(security_token_id); |
561 } | 561 } |
562 return list->at(index); | 562 return list->at(index); |
563 } | 563 } |
564 | 564 |
565 | 565 |
566 int CpuProfilesCollection::TokenToIndex(int security_token_id) { | 566 int CpuProfilesCollection::TokenToIndex(int security_token_id) { |
567 ASSERT(CodeEntry::kNoSecurityToken == -1); | 567 ASSERT(TokenEnumerator::kNoSecurityToken == -1); |
568 return security_token_id + 1; // kNoSecurityToken -> 0, 0 -> 1, ... | 568 return security_token_id + 1; // kNoSecurityToken -> 0, 0 -> 1, ... |
569 } | 569 } |
570 | 570 |
571 | 571 |
572 List<CpuProfile*>* CpuProfilesCollection::GetProfilesList( | 572 List<CpuProfile*>* CpuProfilesCollection::GetProfilesList( |
573 int security_token_id) { | 573 int security_token_id) { |
574 const int index = TokenToIndex(security_token_id); | 574 const int index = TokenToIndex(security_token_id); |
575 const int lists_to_add = index - profiles_by_token_.length() + 1; | 575 const int lists_to_add = index - profiles_by_token_.length() + 1; |
576 if (lists_to_add > 0) profiles_by_token_.AddBlock(NULL, lists_to_add); | 576 if (lists_to_add > 0) profiles_by_token_.AddBlock(NULL, lists_to_add); |
577 List<CpuProfile*>* unabridged_list = | 577 List<CpuProfile*>* unabridged_list = |
578 profiles_by_token_[TokenToIndex(CodeEntry::kNoSecurityToken)]; | 578 profiles_by_token_[TokenToIndex(TokenEnumerator::kNoSecurityToken)]; |
579 const int current_count = unabridged_list->length(); | 579 const int current_count = unabridged_list->length(); |
580 if (profiles_by_token_[index] == NULL) { | 580 if (profiles_by_token_[index] == NULL) { |
581 profiles_by_token_[index] = new List<CpuProfile*>(current_count); | 581 profiles_by_token_[index] = new List<CpuProfile*>(current_count); |
582 } | 582 } |
583 List<CpuProfile*>* list = profiles_by_token_[index]; | 583 List<CpuProfile*>* list = profiles_by_token_[index]; |
584 const int profiles_to_add = current_count - list->length(); | 584 const int profiles_to_add = current_count - list->length(); |
585 if (profiles_to_add > 0) list->AddBlock(NULL, profiles_to_add); | 585 if (profiles_to_add > 0) list->AddBlock(NULL, profiles_to_add); |
586 return list; | 586 return list; |
587 } | 587 } |
588 | 588 |
589 | 589 |
590 List<CpuProfile*>* CpuProfilesCollection::Profiles(int security_token_id) { | 590 List<CpuProfile*>* CpuProfilesCollection::Profiles(int security_token_id) { |
591 List<CpuProfile*>* unabridged_list = | 591 List<CpuProfile*>* unabridged_list = |
592 profiles_by_token_[TokenToIndex(CodeEntry::kNoSecurityToken)]; | 592 profiles_by_token_[TokenToIndex(TokenEnumerator::kNoSecurityToken)]; |
593 if (security_token_id == CodeEntry::kNoSecurityToken) { | 593 if (security_token_id == TokenEnumerator::kNoSecurityToken) { |
594 return unabridged_list; | 594 return unabridged_list; |
595 } | 595 } |
596 List<CpuProfile*>* list = GetProfilesList(security_token_id); | 596 List<CpuProfile*>* list = GetProfilesList(security_token_id); |
597 const int current_count = unabridged_list->length(); | 597 const int current_count = unabridged_list->length(); |
598 for (int i = 0; i < current_count; ++i) { | 598 for (int i = 0; i < current_count; ++i) { |
599 if (list->at(i) == NULL) { | 599 if (list->at(i) == NULL) { |
600 list->at(i) = unabridged_list->at(i)->FilteredClone(security_token_id); | 600 list->at(i) = unabridged_list->at(i)->FilteredClone(security_token_id); |
601 } | 601 } |
602 } | 602 } |
603 return list; | 603 return list; |
604 } | 604 } |
605 | 605 |
606 | 606 |
607 CodeEntry* CpuProfilesCollection::NewCodeEntry(Logger::LogEventsAndTags tag, | 607 CodeEntry* CpuProfilesCollection::NewCodeEntry(Logger::LogEventsAndTags tag, |
608 String* name, | 608 String* name, |
609 String* resource_name, | 609 String* resource_name, |
610 int line_number) { | 610 int line_number) { |
611 CodeEntry* entry = new CodeEntry(tag, | 611 CodeEntry* entry = new CodeEntry(tag, |
612 CodeEntry::kEmptyNamePrefix, | 612 CodeEntry::kEmptyNamePrefix, |
613 GetFunctionName(name), | 613 GetFunctionName(name), |
614 GetName(resource_name), | 614 GetName(resource_name), |
615 line_number, | 615 line_number, |
616 CodeEntry::kNoSecurityToken); | 616 TokenEnumerator::kNoSecurityToken); |
617 code_entries_.Add(entry); | 617 code_entries_.Add(entry); |
618 return entry; | 618 return entry; |
619 } | 619 } |
620 | 620 |
621 | 621 |
622 CodeEntry* CpuProfilesCollection::NewCodeEntry(Logger::LogEventsAndTags tag, | 622 CodeEntry* CpuProfilesCollection::NewCodeEntry(Logger::LogEventsAndTags tag, |
623 const char* name) { | 623 const char* name) { |
624 CodeEntry* entry = new CodeEntry(tag, | 624 CodeEntry* entry = new CodeEntry(tag, |
625 CodeEntry::kEmptyNamePrefix, | 625 CodeEntry::kEmptyNamePrefix, |
626 GetFunctionName(name), | 626 GetFunctionName(name), |
627 "", | 627 "", |
628 v8::CpuProfileNode::kNoLineNumberInfo, | 628 v8::CpuProfileNode::kNoLineNumberInfo, |
629 CodeEntry::kNoSecurityToken); | 629 TokenEnumerator::kNoSecurityToken); |
630 code_entries_.Add(entry); | 630 code_entries_.Add(entry); |
631 return entry; | 631 return entry; |
632 } | 632 } |
633 | 633 |
634 | 634 |
635 CodeEntry* CpuProfilesCollection::NewCodeEntry(Logger::LogEventsAndTags tag, | 635 CodeEntry* CpuProfilesCollection::NewCodeEntry(Logger::LogEventsAndTags tag, |
636 const char* name_prefix, | 636 const char* name_prefix, |
637 String* name) { | 637 String* name) { |
638 CodeEntry* entry = new CodeEntry(tag, | 638 CodeEntry* entry = new CodeEntry(tag, |
639 name_prefix, | 639 name_prefix, |
640 GetName(name), | 640 GetName(name), |
641 "", | 641 "", |
642 v8::CpuProfileNode::kNoLineNumberInfo, | 642 v8::CpuProfileNode::kNoLineNumberInfo, |
643 CodeEntry::kInheritsSecurityToken); | 643 TokenEnumerator::kInheritsSecurityToken); |
644 code_entries_.Add(entry); | 644 code_entries_.Add(entry); |
645 return entry; | 645 return entry; |
646 } | 646 } |
647 | 647 |
648 | 648 |
649 CodeEntry* CpuProfilesCollection::NewCodeEntry(Logger::LogEventsAndTags tag, | 649 CodeEntry* CpuProfilesCollection::NewCodeEntry(Logger::LogEventsAndTags tag, |
650 int args_count) { | 650 int args_count) { |
651 CodeEntry* entry = new CodeEntry(tag, | 651 CodeEntry* entry = new CodeEntry(tag, |
652 "args_count: ", | 652 "args_count: ", |
653 GetName(args_count), | 653 GetName(args_count), |
654 "", | 654 "", |
655 v8::CpuProfileNode::kNoLineNumberInfo, | 655 v8::CpuProfileNode::kNoLineNumberInfo, |
656 CodeEntry::kInheritsSecurityToken); | 656 TokenEnumerator::kInheritsSecurityToken); |
657 code_entries_.Add(entry); | 657 code_entries_.Add(entry); |
658 return entry; | 658 return entry; |
659 } | 659 } |
660 | 660 |
661 | 661 |
662 CodeEntry* CpuProfilesCollection::NewCodeEntry(int security_token_id) { | 662 CodeEntry* CpuProfilesCollection::NewCodeEntry(int security_token_id) { |
663 CodeEntry* entry = new CodeEntry(security_token_id); | 663 CodeEntry* entry = new CodeEntry(security_token_id); |
664 code_entries_.Add(entry); | 664 code_entries_.Add(entry); |
665 return entry; | 665 return entry; |
666 } | 666 } |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
803 *entry++ = EntryForVMState(sample.state); | 803 *entry++ = EntryForVMState(sample.state); |
804 } | 804 } |
805 } | 805 } |
806 | 806 |
807 profiles_->AddPathToCurrentProfiles(entries); | 807 profiles_->AddPathToCurrentProfiles(entries); |
808 } | 808 } |
809 | 809 |
810 } } // namespace v8::internal | 810 } } // namespace v8::internal |
811 | 811 |
812 #endif // ENABLE_LOGGING_AND_PROFILING | 812 #endif // ENABLE_LOGGING_AND_PROFILING |
OLD | NEW |