Revision: 5230
Author: [email protected]
Date: Tue Aug 10 05:06:42 2010
Log: Fix CPU profiler crash in start / stop sequence when non-existent name
is passed
BUG=51594
TEST=test-cpu-profiler/CrashIfStoppingLastNonExistentProfile
Review URL: http://codereview.chromium.org/3108004
http://code.google.com/p/v8/source/detail?r=5230
Modified:
/branches/bleeding_edge/src/cpu-profiler.cc
/branches/bleeding_edge/src/cpu-profiler.h
/branches/bleeding_edge/src/profile-generator-inl.h
/branches/bleeding_edge/src/profile-generator.cc
/branches/bleeding_edge/src/profile-generator.h
/branches/bleeding_edge/test/cctest/test-cpu-profiler.cc
=======================================
--- /branches/bleeding_edge/src/cpu-profiler.cc Tue Jun 8 04:27:00 2010
+++ /branches/bleeding_edge/src/cpu-profiler.cc Tue Aug 10 05:06:42 2010
@@ -476,7 +476,7 @@
CpuProfile* CpuProfiler::StopCollectingProfile(const char* title) {
const double actual_sampling_rate = generator_->actual_sampling_rate();
- StopProcessorIfLastProfile();
+ StopProcessorIfLastProfile(title);
CpuProfile* result =
profiles_->StopProfiling(TokenEnumerator::kNoSecurityToken,
title,
@@ -491,14 +491,15 @@
CpuProfile* CpuProfiler::StopCollectingProfile(Object* security_token,
String* title) {
const double actual_sampling_rate = generator_->actual_sampling_rate();
- StopProcessorIfLastProfile();
+ const char* profile_title = profiles_->GetName(title);
+ StopProcessorIfLastProfile(profile_title);
int token = token_enumerator_->GetTokenId(security_token);
- return profiles_->StopProfiling(token, title, actual_sampling_rate);
+ return profiles_->StopProfiling(token, profile_title,
actual_sampling_rate);
}
-void CpuProfiler::StopProcessorIfLastProfile() {
- if (profiles_->is_last_profile()) {
+void CpuProfiler::StopProcessorIfLastProfile(const char* title) {
+ if (profiles_->IsLastProfile(title)) {
reinterpret_cast<Sampler*>(Logger::ticker_)->Stop();
processor_->Stop();
processor_->Join();
=======================================
--- /branches/bleeding_edge/src/cpu-profiler.h Tue Jun 1 06:52:49 2010
+++ /branches/bleeding_edge/src/cpu-profiler.h Tue Aug 10 05:06:42 2010
@@ -260,7 +260,7 @@
void StartProcessorIfNotStarted();
CpuProfile* StopCollectingProfile(const char* title);
CpuProfile* StopCollectingProfile(Object* security_token, String* title);
- void StopProcessorIfLastProfile();
+ void StopProcessorIfLastProfile(const char* title);
CpuProfilesCollection* profiles_;
unsigned next_profile_uid_;
=======================================
--- /branches/bleeding_edge/src/profile-generator-inl.h Mon Aug 9 04:37:24
2010
+++ /branches/bleeding_edge/src/profile-generator-inl.h Tue Aug 10 05:06:42
2010
@@ -95,13 +95,6 @@
void CodeMap::DeleteCode(Address addr) {
tree_.Remove(addr);
}
-
-
-bool CpuProfilesCollection::is_last_profile() {
- // Called from VM thread, and only it can mutate the list,
- // so no locking is needed here.
- return current_profiles_.length() == 1;
-}
const char* CpuProfilesCollection::GetFunctionName(String* name) {
=======================================
--- /branches/bleeding_edge/src/profile-generator.cc Tue Aug 10 00:37:59
2010
+++ /branches/bleeding_edge/src/profile-generator.cc Tue Aug 10 05:06:42
2010
@@ -540,13 +540,6 @@
}
return NULL;
}
-
-
-CpuProfile* CpuProfilesCollection::StopProfiling(int security_token_id,
- String* title,
- double
actual_sampling_rate) {
- return StopProfiling(security_token_id, GetName(title),
actual_sampling_rate);
-}
CpuProfile* CpuProfilesCollection::GetProfile(int security_token_id,
@@ -572,6 +565,15 @@
}
return list->at(index);
}
+
+
+bool CpuProfilesCollection::IsLastProfile(const char* title) {
+ // Called from VM thread, and only it can mutate the list,
+ // so no locking is needed here.
+ if (current_profiles_.length() != 1) return false;
+ return StrLength(title) == 0
+ || strcmp(current_profiles_[0]->title(), title) == 0;
+}
int CpuProfilesCollection::TokenToIndex(int security_token_id) {
=======================================
--- /branches/bleeding_edge/src/profile-generator.h Mon Aug 9 07:57:13 2010
+++ /branches/bleeding_edge/src/profile-generator.h Tue Aug 10 05:06:42 2010
@@ -278,16 +278,13 @@
bool StartProfiling(String* title, unsigned uid);
CpuProfile* StopProfiling(int security_token_id,
const char* title,
- double actual_sampling_rate);
- CpuProfile* StopProfiling(int security_token_id,
- String* title,
double actual_sampling_rate);
List<CpuProfile*>* Profiles(int security_token_id);
const char* GetName(String* name) {
return function_and_resource_names_.GetName(name);
}
CpuProfile* GetProfile(int security_token_id, unsigned uid);
- inline bool is_last_profile();
+ bool IsLastProfile(const char* title);
CodeEntry* NewCodeEntry(Logger::LogEventsAndTags tag,
String* name, String* resource_name, int
line_number);
=======================================
--- /branches/bleeding_edge/test/cctest/test-cpu-profiler.cc Tue Jun 8
04:27:00 2010
+++ /branches/bleeding_edge/test/cctest/test-cpu-profiler.cc Tue Aug 10
05:06:42 2010
@@ -12,6 +12,7 @@
using i::CodeEntry;
using i::CpuProfile;
+using i::CpuProfiler;
using i::CpuProfilesCollection;
using i::ProfileGenerator;
using i::ProfileNode;
@@ -224,5 +225,19 @@
CHECK_EQ(1, bottom_up_ddd_stub_children->length());
CHECK_EQ("bbb", bottom_up_ddd_stub_children->last()->entry()->name());
}
+
+
+// http://crbug/51594
+// This test must not crash.
+TEST(CrashIfStoppingLastNonExistentProfile) {
+ InitializeVM();
+ TestSetup test_setup;
+ CpuProfiler::Setup();
+ CpuProfiler::StartProfiling("1");
+ CpuProfiler::StopProfiling("2");
+ CpuProfiler::StartProfiling("1");
+ CpuProfiler::StopProfiling("");
+ CpuProfiler::TearDown();
+}
#endif // ENABLE_LOGGING_AND_PROFILING
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev