Revision: 4826
Author: [email protected]
Date: Wed Jun 9 00:00:33 2010
Log: Factor out StringsStorage from CpuProfilesCollection.
Review URL: http://codereview.chromium.org/2769001
http://code.google.com/p/v8/source/detail?r=4826
Modified:
/branches/bleeding_edge/src/profile-generator.cc
/branches/bleeding_edge/src/profile-generator.h
=======================================
--- /branches/bleeding_edge/src/profile-generator.cc Tue Jun 8 04:27:00
2010
+++ /branches/bleeding_edge/src/profile-generator.cc Wed Jun 9 00:00:33
2010
@@ -84,6 +84,37 @@
}
}
}
+
+
+StringsStorage::StringsStorage()
+ : names_(StringsMatch) {
+}
+
+
+StringsStorage::~StringsStorage() {
+ for (HashMap::Entry* p = names_.Start();
+ p != NULL;
+ p = names_.Next(p)) {
+ DeleteArray(reinterpret_cast<const char*>(p->value));
+ }
+}
+
+
+const char* StringsStorage::GetName(String* name) {
+ if (name->IsString()) {
+ char* c_name =
+ name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL).Detach();
+ HashMap::Entry* cache_entry = names_.Lookup(c_name, name->Hash(),
true);
+ if (cache_entry->value == NULL) {
+ // New entry added.
+ cache_entry->value = c_name;
+ } else {
+ DeleteArray(c_name);
+ }
+ return reinterpret_cast<const char*>(cache_entry->value);
+ }
+ return "";
+}
const char* CodeEntry::kEmptyNamePrefix = "";
@@ -438,8 +469,7 @@
CpuProfilesCollection::CpuProfilesCollection()
- : function_and_resource_names_(StringsMatch),
- profiles_uids_(UidsMatch),
+ : profiles_uids_(UidsMatch),
current_profiles_semaphore_(OS::CreateSemaphore(1)) {
// Create list of unabridged profiles.
profiles_by_token_.Add(new List<CpuProfile*>());
@@ -470,11 +500,6 @@
profiles_by_token_.Iterate(DeleteProfilesList);
code_entries_.Iterate(DeleteCodeEntry);
args_count_names_.Iterate(DeleteArgsCountName);
- for (HashMap::Entry* p = function_and_resource_names_.Start();
- p != NULL;
- p = function_and_resource_names_.Next(p)) {
- DeleteArray(reinterpret_cast<const char*>(p->value));
- }
}
@@ -664,27 +689,6 @@
code_entries_.Add(entry);
return entry;
}
-
-
-const char* CpuProfilesCollection::GetName(String* name) {
- if (name->IsString()) {
- char* c_name =
- name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL).Detach();
- HashMap::Entry* cache_entry =
- function_and_resource_names_.Lookup(c_name,
- name->Hash(),
- true);
- if (cache_entry->value == NULL) {
- // New entry added.
- cache_entry->value = c_name;
- } else {
- DeleteArray(c_name);
- }
- return reinterpret_cast<const char*>(cache_entry->value);
- } else {
- return "";
- }
-}
const char* CpuProfilesCollection::GetName(int args_count) {
=======================================
--- /branches/bleeding_edge/src/profile-generator.h Tue Jun 8 04:27:00 2010
+++ /branches/bleeding_edge/src/profile-generator.h Wed Jun 9 00:00:33 2010
@@ -56,6 +56,28 @@
};
+// Provides a storage of strings allocated in C++ heap, to hold them
+// forever, even if they disappear from JS heap or external storage.
+class StringsStorage {
+ public:
+ StringsStorage();
+ ~StringsStorage();
+
+ const char* GetName(String* name);
+
+ private:
+ INLINE(static bool StringsMatch(void* key1, void* key2)) {
+ return strcmp(reinterpret_cast<char*>(key1),
+ reinterpret_cast<char*>(key2)) == 0;
+ }
+
+ // String::Hash -> const char*
+ HashMap names_;
+
+ DISALLOW_COPY_AND_ASSIGN(StringsStorage);
+};
+
+
class CodeEntry {
public:
explicit INLINE(CodeEntry(int security_token_id));
@@ -258,10 +280,12 @@
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();
- const char* GetName(String* name);
CodeEntry* NewCodeEntry(Logger::LogEventsAndTags tag,
String* name, String* resource_name, int
line_number);
CodeEntry* NewCodeEntry(Logger::LogEventsAndTags tag, const char* name);
@@ -280,17 +304,11 @@
List<CpuProfile*>* GetProfilesList(int security_token_id);
int TokenToIndex(int security_token_id);
- INLINE(static bool StringsMatch(void* key1, void* key2)) {
- return strcmp(reinterpret_cast<char*>(key1),
- reinterpret_cast<char*>(key2)) == 0;
- }
-
INLINE(static bool UidsMatch(void* key1, void* key2)) {
return key1 == key2;
}
- // String::Hash -> const char*
- HashMap function_and_resource_names_;
+ StringsStorage function_and_resource_names_;
// args_count -> char*
List<char*> args_count_names_;
List<CodeEntry*> code_entries_;
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev