From: mikhail.naganov@gmail.com Date: Tue, 8 Jun 2010 11:27:00 +0000 (+0000) Subject: Move token-related constants from CodeEntry to TokenEnumerator. X-Git-Tag: upstream/4.7.83~21668 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a217c50ab2e60e42715dffa58a5d167b33ad5f09;p=platform%2Fupstream%2Fv8.git Move token-related constants from CodeEntry to TokenEnumerator. Review URL: http://codereview.chromium.org/2745002 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@4819 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- diff --git a/src/cpu-profiler.cc b/src/cpu-profiler.cc index 2968081..c8d29f8 100644 --- a/src/cpu-profiler.cc +++ b/src/cpu-profiler.cc @@ -294,7 +294,8 @@ CpuProfile* CpuProfiler::StopProfiling(Object* security_token, String* title) { int CpuProfiler::GetProfilesCount() { ASSERT(singleton_ != NULL); // The count of profiles doesn't depend on a security token. - return singleton_->profiles_->Profiles(CodeEntry::kNoSecurityToken)->length(); + return singleton_->profiles_->Profiles( + TokenEnumerator::kNoSecurityToken)->length(); } @@ -380,7 +381,7 @@ void CpuProfiler::CodeDeleteEvent(Address from) { void CpuProfiler::FunctionCreateEvent(JSFunction* function) { - int security_token_id = CodeEntry::kNoSecurityToken; + int security_token_id = TokenEnumerator::kNoSecurityToken; if (function->unchecked_context()->IsContext()) { security_token_id = singleton_->token_enumerator_->GetTokenId( function->context()->global_context()->security_token()); @@ -476,9 +477,10 @@ void CpuProfiler::StartProcessorIfNotStarted() { CpuProfile* CpuProfiler::StopCollectingProfile(const char* title) { const double actual_sampling_rate = generator_->actual_sampling_rate(); StopProcessorIfLastProfile(); - CpuProfile* result = profiles_->StopProfiling(CodeEntry::kNoSecurityToken, - title, - actual_sampling_rate); + CpuProfile* result = + profiles_->StopProfiling(TokenEnumerator::kNoSecurityToken, + title, + actual_sampling_rate); if (result != NULL) { result->Print(); } diff --git a/src/profile-generator.cc b/src/profile-generator.cc index 105c1a8..fb89a22 100644 --- a/src/profile-generator.cc +++ b/src/profile-generator.cc @@ -55,7 +55,7 @@ TokenEnumerator::~TokenEnumerator() { int TokenEnumerator::GetTokenId(Object* token) { - if (token == NULL) return CodeEntry::kNoSecurityToken; + if (token == NULL) return TokenEnumerator::kNoSecurityToken; for (int i = 0; i < token_locations_.length(); ++i) { if (*token_locations_[i] == token && !token_removed_[i]) return i; } @@ -171,7 +171,7 @@ ProfileTree::ProfileTree() "(root)", "", 0, - CodeEntry::kNoSecurityToken), + TokenEnumerator::kNoSecurityToken), root_(new ProfileNode(this, &root_entry_)) { } @@ -248,11 +248,11 @@ class FilteredCloneCallback { private: bool IsTokenAcceptable(int token, int parent_token) { - if (token == CodeEntry::kNoSecurityToken + if (token == TokenEnumerator::kNoSecurityToken || token == security_token_id_) return true; - if (token == CodeEntry::kInheritsSecurityToken) { - ASSERT(parent_token != CodeEntry::kInheritsSecurityToken); - return parent_token == CodeEntry::kNoSecurityToken + if (token == TokenEnumerator::kInheritsSecurityToken) { + ASSERT(parent_token != TokenEnumerator::kInheritsSecurityToken); + return parent_token == TokenEnumerator::kNoSecurityToken || parent_token == security_token_id_; } return false; @@ -373,7 +373,7 @@ void CpuProfile::SetActualSamplingRate(double actual_sampling_rate) { CpuProfile* CpuProfile::FilteredClone(int security_token_id) { - ASSERT(security_token_id != CodeEntry::kNoSecurityToken); + ASSERT(security_token_id != TokenEnumerator::kNoSecurityToken); CpuProfile* clone = new CpuProfile(title_, uid_); clone->top_down_.FilteredClone(&top_down_, security_token_id); clone->bottom_up_.FilteredClone(&bottom_up_, security_token_id); @@ -517,7 +517,7 @@ CpuProfile* CpuProfilesCollection::StopProfiling(int security_token_id, profile->CalculateTotalTicks(); profile->SetActualSamplingRate(actual_sampling_rate); List* unabridged_list = - profiles_by_token_[TokenToIndex(CodeEntry::kNoSecurityToken)]; + profiles_by_token_[TokenToIndex(TokenEnumerator::kNoSecurityToken)]; unabridged_list->Add(profile); HashMap::Entry* entry = profiles_uids_.Lookup(reinterpret_cast(profile->uid()), @@ -550,8 +550,8 @@ CpuProfile* CpuProfilesCollection::GetProfile(int security_token_id, return NULL; } List* unabridged_list = - profiles_by_token_[TokenToIndex(CodeEntry::kNoSecurityToken)]; - if (security_token_id == CodeEntry::kNoSecurityToken) { + profiles_by_token_[TokenToIndex(TokenEnumerator::kNoSecurityToken)]; + if (security_token_id == TokenEnumerator::kNoSecurityToken) { return unabridged_list->at(index); } List* list = GetProfilesList(security_token_id); @@ -564,7 +564,7 @@ CpuProfile* CpuProfilesCollection::GetProfile(int security_token_id, int CpuProfilesCollection::TokenToIndex(int security_token_id) { - ASSERT(CodeEntry::kNoSecurityToken == -1); + ASSERT(TokenEnumerator::kNoSecurityToken == -1); return security_token_id + 1; // kNoSecurityToken -> 0, 0 -> 1, ... } @@ -575,7 +575,7 @@ List* CpuProfilesCollection::GetProfilesList( const int lists_to_add = index - profiles_by_token_.length() + 1; if (lists_to_add > 0) profiles_by_token_.AddBlock(NULL, lists_to_add); List* unabridged_list = - profiles_by_token_[TokenToIndex(CodeEntry::kNoSecurityToken)]; + profiles_by_token_[TokenToIndex(TokenEnumerator::kNoSecurityToken)]; const int current_count = unabridged_list->length(); if (profiles_by_token_[index] == NULL) { profiles_by_token_[index] = new List(current_count); @@ -589,8 +589,8 @@ List* CpuProfilesCollection::GetProfilesList( List* CpuProfilesCollection::Profiles(int security_token_id) { List* unabridged_list = - profiles_by_token_[TokenToIndex(CodeEntry::kNoSecurityToken)]; - if (security_token_id == CodeEntry::kNoSecurityToken) { + profiles_by_token_[TokenToIndex(TokenEnumerator::kNoSecurityToken)]; + if (security_token_id == TokenEnumerator::kNoSecurityToken) { return unabridged_list; } List* list = GetProfilesList(security_token_id); @@ -613,7 +613,7 @@ CodeEntry* CpuProfilesCollection::NewCodeEntry(Logger::LogEventsAndTags tag, GetFunctionName(name), GetName(resource_name), line_number, - CodeEntry::kNoSecurityToken); + TokenEnumerator::kNoSecurityToken); code_entries_.Add(entry); return entry; } @@ -626,7 +626,7 @@ CodeEntry* CpuProfilesCollection::NewCodeEntry(Logger::LogEventsAndTags tag, GetFunctionName(name), "", v8::CpuProfileNode::kNoLineNumberInfo, - CodeEntry::kNoSecurityToken); + TokenEnumerator::kNoSecurityToken); code_entries_.Add(entry); return entry; } @@ -640,7 +640,7 @@ CodeEntry* CpuProfilesCollection::NewCodeEntry(Logger::LogEventsAndTags tag, GetName(name), "", v8::CpuProfileNode::kNoLineNumberInfo, - CodeEntry::kInheritsSecurityToken); + TokenEnumerator::kInheritsSecurityToken); code_entries_.Add(entry); return entry; } @@ -653,7 +653,7 @@ CodeEntry* CpuProfilesCollection::NewCodeEntry(Logger::LogEventsAndTags tag, GetName(args_count), "", v8::CpuProfileNode::kNoLineNumberInfo, - CodeEntry::kInheritsSecurityToken); + TokenEnumerator::kInheritsSecurityToken); code_entries_.Add(entry); return entry; } diff --git a/src/profile-generator.h b/src/profile-generator.h index 18265f1..d39974e 100644 --- a/src/profile-generator.h +++ b/src/profile-generator.h @@ -41,6 +41,9 @@ class TokenEnumerator { ~TokenEnumerator(); int GetTokenId(Object* token); + static const int kNoSecurityToken = -1; + static const int kInheritsSecurityToken = -2; + private: static void TokenRemovedCallback(v8::Persistent handle, void* parameter); @@ -78,8 +81,6 @@ class CodeEntry { void CopyData(const CodeEntry& source); static const char* kEmptyNamePrefix; - static const int kNoSecurityToken = -1; - static const int kInheritsSecurityToken = -2; private: unsigned call_uid_; diff --git a/test/cctest/test-cpu-profiler.cc b/test/cctest/test-cpu-profiler.cc index f587fc8..0e6f09d 100644 --- a/test/cctest/test-cpu-profiler.cc +++ b/test/cctest/test-cpu-profiler.cc @@ -16,6 +16,7 @@ using i::CpuProfilesCollection; using i::ProfileGenerator; using i::ProfileNode; using i::ProfilerEventsProcessor; +using i::TokenEnumerator; TEST(StartStop) { @@ -115,7 +116,7 @@ TEST(CodeEvents) { processor.CodeCreateEvent(i::Logger::STUB_TAG, 3, ToAddress(0x1600), 0x10); processor.CodeDeleteEvent(ToAddress(0x1600)); processor.FunctionCreateEvent(ToAddress(0x1700), ToAddress(0x1000), - CodeEntry::kNoSecurityToken); + TokenEnumerator::kNoSecurityToken); // Enqueue a tick event to enable code events processing. EnqueueTickSampleEvent(&processor, ToAddress(0x1000)); @@ -178,7 +179,7 @@ TEST(TickEvents) { processor.Stop(); processor.Join(); CpuProfile* profile = - profiles.StopProfiling(CodeEntry::kNoSecurityToken, "", 1); + profiles.StopProfiling(TokenEnumerator::kNoSecurityToken, "", 1); CHECK_NE(NULL, profile); // Check call trees. diff --git a/test/cctest/test-profile-generator.cc b/test/cctest/test-profile-generator.cc index 418fd36..308f764 100644 --- a/test/cctest/test-profile-generator.cc +++ b/test/cctest/test-profile-generator.cc @@ -39,7 +39,7 @@ class TokenEnumeratorTester { TEST(TokenEnumerator) { TokenEnumerator te; - CHECK_EQ(CodeEntry::kNoSecurityToken, te.GetTokenId(NULL)); + CHECK_EQ(TokenEnumerator::kNoSecurityToken, te.GetTokenId(NULL)); v8::HandleScope hs; v8::Local token1(v8::String::New("1")); CHECK_EQ(0, te.GetTokenId(*v8::Utils::OpenHandle(*token1))); @@ -65,20 +65,20 @@ TEST(TokenEnumerator) { TEST(ProfileNodeFindOrAddChild) { ProfileNode node(NULL, NULL); - CodeEntry entry1( - i::Logger::FUNCTION_TAG, "", "aaa", "", 0, CodeEntry::kNoSecurityToken); + CodeEntry entry1(i::Logger::FUNCTION_TAG, "", "aaa", "", 0, + TokenEnumerator::kNoSecurityToken); ProfileNode* childNode1 = node.FindOrAddChild(&entry1); CHECK_NE(NULL, childNode1); CHECK_EQ(childNode1, node.FindOrAddChild(&entry1)); - CodeEntry entry2( - i::Logger::FUNCTION_TAG, "", "bbb", "", 0, CodeEntry::kNoSecurityToken); + CodeEntry entry2(i::Logger::FUNCTION_TAG, "", "bbb", "", 0, + TokenEnumerator::kNoSecurityToken); ProfileNode* childNode2 = node.FindOrAddChild(&entry2); CHECK_NE(NULL, childNode2); CHECK_NE(childNode1, childNode2); CHECK_EQ(childNode1, node.FindOrAddChild(&entry1)); CHECK_EQ(childNode2, node.FindOrAddChild(&entry2)); - CodeEntry entry3( - i::Logger::FUNCTION_TAG, "", "ccc", "", 0, CodeEntry::kNoSecurityToken); + CodeEntry entry3(i::Logger::FUNCTION_TAG, "", "ccc", "", 0, + TokenEnumerator::kNoSecurityToken); ProfileNode* childNode3 = node.FindOrAddChild(&entry3); CHECK_NE(NULL, childNode3); CHECK_NE(childNode1, childNode3); @@ -119,12 +119,12 @@ class ProfileTreeTestHelper { } // namespace TEST(ProfileTreeAddPathFromStart) { - CodeEntry entry1( - i::Logger::FUNCTION_TAG, "", "aaa", "", 0, CodeEntry::kNoSecurityToken); - CodeEntry entry2( - i::Logger::FUNCTION_TAG, "", "bbb", "", 0, CodeEntry::kNoSecurityToken); - CodeEntry entry3( - i::Logger::FUNCTION_TAG, "", "ccc", "", 0, CodeEntry::kNoSecurityToken); + CodeEntry entry1(i::Logger::FUNCTION_TAG, "", "aaa", "", 0, + TokenEnumerator::kNoSecurityToken); + CodeEntry entry2(i::Logger::FUNCTION_TAG, "", "bbb", "", 0, + TokenEnumerator::kNoSecurityToken); + CodeEntry entry3(i::Logger::FUNCTION_TAG, "", "ccc", "", 0, + TokenEnumerator::kNoSecurityToken); ProfileTree tree; ProfileTreeTestHelper helper(&tree); CHECK_EQ(NULL, helper.Walk(&entry1)); @@ -189,12 +189,12 @@ TEST(ProfileTreeAddPathFromStart) { TEST(ProfileTreeAddPathFromEnd) { - CodeEntry entry1( - i::Logger::FUNCTION_TAG, "", "aaa", "", 0, CodeEntry::kNoSecurityToken); - CodeEntry entry2( - i::Logger::FUNCTION_TAG, "", "bbb", "", 0, CodeEntry::kNoSecurityToken); - CodeEntry entry3( - i::Logger::FUNCTION_TAG, "", "ccc", "", 0, CodeEntry::kNoSecurityToken); + CodeEntry entry1(i::Logger::FUNCTION_TAG, "", "aaa", "", 0, + TokenEnumerator::kNoSecurityToken); + CodeEntry entry2(i::Logger::FUNCTION_TAG, "", "bbb", "", 0, + TokenEnumerator::kNoSecurityToken); + CodeEntry entry3(i::Logger::FUNCTION_TAG, "", "ccc", "", 0, + TokenEnumerator::kNoSecurityToken); ProfileTree tree; ProfileTreeTestHelper helper(&tree); CHECK_EQ(NULL, helper.Walk(&entry1)); @@ -272,8 +272,8 @@ TEST(ProfileTreeCalculateTotalTicks) { CHECK_EQ(1, empty_tree.root()->total_ticks()); CHECK_EQ(1, empty_tree.root()->self_ticks()); - CodeEntry entry1( - i::Logger::FUNCTION_TAG, "", "aaa", "", 0, CodeEntry::kNoSecurityToken); + CodeEntry entry1(i::Logger::FUNCTION_TAG, "", "aaa", "", 0, + TokenEnumerator::kNoSecurityToken); CodeEntry* e1_path[] = {&entry1}; Vector e1_path_vec( e1_path, sizeof(e1_path) / sizeof(e1_path[0])); @@ -294,8 +294,8 @@ TEST(ProfileTreeCalculateTotalTicks) { CHECK_EQ(1, node1->total_ticks()); CHECK_EQ(1, node1->self_ticks()); - CodeEntry entry2( - i::Logger::FUNCTION_TAG, "", "bbb", "", 0, CodeEntry::kNoSecurityToken); + CodeEntry entry2(i::Logger::FUNCTION_TAG, "", "bbb", "", 0, + TokenEnumerator::kNoSecurityToken); CodeEntry* e1_e2_path[] = {&entry1, &entry2}; Vector e1_e2_path_vec( e1_e2_path, sizeof(e1_e2_path) / sizeof(e1_e2_path[0])); @@ -330,8 +330,8 @@ TEST(ProfileTreeCalculateTotalTicks) { CodeEntry* e2_path[] = {&entry2}; Vector e2_path_vec( e2_path, sizeof(e2_path) / sizeof(e2_path[0])); - CodeEntry entry3( - i::Logger::FUNCTION_TAG, "", "ccc", "", 0, CodeEntry::kNoSecurityToken); + CodeEntry entry3(i::Logger::FUNCTION_TAG, "", "ccc", "", 0, + TokenEnumerator::kNoSecurityToken); CodeEntry* e3_path[] = {&entry3}; Vector e3_path_vec( e3_path, sizeof(e3_path) / sizeof(e3_path[0])); @@ -394,7 +394,7 @@ TEST(ProfileTreeFilteredClone) { CodeEntry entry3(i::Logger::FUNCTION_TAG, "", "ccc", "", 0, token0); CodeEntry entry4( i::Logger::FUNCTION_TAG, "", "ddd", "", 0, - CodeEntry::kInheritsSecurityToken); + TokenEnumerator::kInheritsSecurityToken); { CodeEntry* e1_e2_path[] = {&entry1, &entry2}; @@ -491,14 +491,14 @@ static inline i::Address ToAddress(int n) { TEST(CodeMapAddCode) { CodeMap code_map; - CodeEntry entry1( - i::Logger::FUNCTION_TAG, "", "aaa", "", 0, CodeEntry::kNoSecurityToken); - CodeEntry entry2( - i::Logger::FUNCTION_TAG, "", "bbb", "", 0, CodeEntry::kNoSecurityToken); - CodeEntry entry3( - i::Logger::FUNCTION_TAG, "", "ccc", "", 0, CodeEntry::kNoSecurityToken); - CodeEntry entry4( - i::Logger::FUNCTION_TAG, "", "ddd", "", 0, CodeEntry::kNoSecurityToken); + CodeEntry entry1(i::Logger::FUNCTION_TAG, "", "aaa", "", 0, + TokenEnumerator::kNoSecurityToken); + CodeEntry entry2(i::Logger::FUNCTION_TAG, "", "bbb", "", 0, + TokenEnumerator::kNoSecurityToken); + CodeEntry entry3(i::Logger::FUNCTION_TAG, "", "ccc", "", 0, + TokenEnumerator::kNoSecurityToken); + CodeEntry entry4(i::Logger::FUNCTION_TAG, "", "ddd", "", 0, + TokenEnumerator::kNoSecurityToken); code_map.AddCode(ToAddress(0x1500), &entry1, 0x200); code_map.AddCode(ToAddress(0x1700), &entry2, 0x100); code_map.AddCode(ToAddress(0x1900), &entry3, 0x50); @@ -525,10 +525,10 @@ TEST(CodeMapAddCode) { TEST(CodeMapMoveAndDeleteCode) { CodeMap code_map; - CodeEntry entry1( - i::Logger::FUNCTION_TAG, "", "aaa", "", 0, CodeEntry::kNoSecurityToken); - CodeEntry entry2( - i::Logger::FUNCTION_TAG, "", "bbb", "", 0, CodeEntry::kNoSecurityToken); + CodeEntry entry1(i::Logger::FUNCTION_TAG, "", "aaa", "", 0, + TokenEnumerator::kNoSecurityToken); + CodeEntry entry2(i::Logger::FUNCTION_TAG, "", "bbb", "", 0, + TokenEnumerator::kNoSecurityToken); code_map.AddCode(ToAddress(0x1500), &entry1, 0x200); code_map.AddCode(ToAddress(0x1700), &entry2, 0x100); CHECK_EQ(&entry1, code_map.FindEntry(ToAddress(0x1500))); @@ -601,7 +601,7 @@ TEST(RecordTickSample) { generator.RecordTickSample(sample3); CpuProfile* profile = - profiles.StopProfiling(CodeEntry::kNoSecurityToken, "", 1); + profiles.StopProfiling(TokenEnumerator::kNoSecurityToken, "", 1); CHECK_NE(NULL, profile); ProfileTreeTestHelper top_down_test_helper(profile->top_down()); CHECK_EQ(NULL, top_down_test_helper.Walk(entry2));