From 170418b2124c44bc16cb485a909f0d2a040e1009 Mon Sep 17 00:00:00 2001 From: Peter Marshall Date: Thu, 24 May 2018 12:53:19 +0200 Subject: [PATCH] [cleanup] Remove GetFunctionName from StringsStorage This distinction doesn't matter, they aren't treated any differently to other strings. Change-Id: I524a0a1c4089284af97aa507afc5bd5985fe6631 Reviewed-on: https://chromium-review.googlesource.com/1071628 Reviewed-by: Camillo Bruni Commit-Queue: Peter Marshall Cr-Commit-Position: refs/heads/master@{#53329} --- src/profiler/allocation-tracker.cc | 2 +- src/profiler/profiler-listener.cc | 24 +++++++++++----------- src/profiler/profiler-listener.h | 9 +++----- src/profiler/sampling-heap-profiler.cc | 2 +- src/profiler/strings-storage.cc | 8 -------- src/profiler/strings-storage.h | 4 ---- test/unittests/strings-storage-unittest.cc | 22 -------------------- 7 files changed, 17 insertions(+), 54 deletions(-) diff --git a/src/profiler/allocation-tracker.cc b/src/profiler/allocation-tracker.cc index cf672f920c..21843325f9 100644 --- a/src/profiler/allocation-tracker.cc +++ b/src/profiler/allocation-tracker.cc @@ -249,7 +249,7 @@ unsigned AllocationTracker::AddFunctionInfo(SharedFunctionInfo* shared, reinterpret_cast(id), SnapshotObjectIdHash(id)); if (entry->value == nullptr) { FunctionInfo* info = new FunctionInfo(); - info->name = names_->GetFunctionName(shared->DebugName()); + info->name = names_->GetName(shared->DebugName()); info->function_id = id; if (shared->script()->IsScript()) { Script* script = Script::cast(shared->script()); diff --git a/src/profiler/profiler-listener.cc b/src/profiler/profiler-listener.cc index 62c2d55443..3671068f1d 100644 --- a/src/profiler/profiler-listener.cc +++ b/src/profiler/profiler-listener.cc @@ -37,10 +37,10 @@ void ProfilerListener::CodeCreateEvent(CodeEventListener::LogEventsAndTags tag, CodeEventsContainer evt_rec(CodeEventRecord::CODE_CREATION); CodeCreateEventRecord* rec = &evt_rec.CodeCreateEventRecord_; rec->start = code->address(); - rec->entry = NewCodeEntry( - tag, GetFunctionName(name), CodeEntry::kEmptyResourceName, - CpuProfileNode::kNoLineNumberInfo, CpuProfileNode::kNoColumnNumberInfo, - nullptr, code->InstructionStart()); + rec->entry = NewCodeEntry(tag, GetName(name), CodeEntry::kEmptyResourceName, + CpuProfileNode::kNoLineNumberInfo, + CpuProfileNode::kNoColumnNumberInfo, nullptr, + code->InstructionStart()); RecordInliningInfo(rec->entry, code); rec->size = code->ExecutableSize(); DispatchCodeEvent(evt_rec); @@ -51,10 +51,10 @@ void ProfilerListener::CodeCreateEvent(CodeEventListener::LogEventsAndTags tag, CodeEventsContainer evt_rec(CodeEventRecord::CODE_CREATION); CodeCreateEventRecord* rec = &evt_rec.CodeCreateEventRecord_; rec->start = code->address(); - rec->entry = NewCodeEntry( - tag, GetFunctionName(name), CodeEntry::kEmptyResourceName, - CpuProfileNode::kNoLineNumberInfo, CpuProfileNode::kNoColumnNumberInfo, - nullptr, code->InstructionStart()); + rec->entry = NewCodeEntry(tag, GetName(name), CodeEntry::kEmptyResourceName, + CpuProfileNode::kNoLineNumberInfo, + CpuProfileNode::kNoColumnNumberInfo, nullptr, + code->InstructionStart()); RecordInliningInfo(rec->entry, code); rec->size = code->ExecutableSize(); DispatchCodeEvent(evt_rec); @@ -67,7 +67,7 @@ void ProfilerListener::CodeCreateEvent(CodeEventListener::LogEventsAndTags tag, CodeEventsContainer evt_rec(CodeEventRecord::CODE_CREATION); CodeCreateEventRecord* rec = &evt_rec.CodeCreateEventRecord_; rec->start = code->address(); - rec->entry = NewCodeEntry(tag, GetFunctionName(shared->DebugName()), + rec->entry = NewCodeEntry(tag, GetName(shared->DebugName()), GetName(InferScriptName(script_name, shared)), CpuProfileNode::kNoLineNumberInfo, CpuProfileNode::kNoColumnNumberInfo, nullptr, @@ -102,7 +102,7 @@ void ProfilerListener::CodeCreateEvent(CodeEventListener::LogEventsAndTags tag, } } rec->entry = - NewCodeEntry(tag, GetFunctionName(shared->DebugName()), + NewCodeEntry(tag, GetName(shared->DebugName()), GetName(InferScriptName(script_name, shared)), line, column, std::move(line_table), abstract_code->InstructionStart()); RecordInliningInfo(rec->entry, abstract_code); @@ -119,7 +119,7 @@ void ProfilerListener::CodeCreateEvent(CodeEventListener::LogEventsAndTags tag, CodeCreateEventRecord* rec = &evt_rec.CodeCreateEventRecord_; rec->start = code->instruction_start(); rec->entry = NewCodeEntry( - tag, GetFunctionName(name.start()), CodeEntry::kWasmResourceNamePrefix, + tag, GetName(name.start()), CodeEntry::kWasmResourceNamePrefix, CpuProfileNode::kNoLineNumberInfo, CpuProfileNode::kNoColumnNumberInfo, nullptr, code->instruction_start()); rec->size = code->instructions().length(); @@ -237,7 +237,7 @@ void ProfilerListener::RecordInliningInfo(CodeEntry* entry, : CodeEntry::kEmptyResourceName; CodeEntry* inline_entry = - new CodeEntry(entry->tag(), GetFunctionName(shared_info->DebugName()), + new CodeEntry(entry->tag(), GetName(shared_info->DebugName()), resource_name, CpuProfileNode::kNoLineNumberInfo, CpuProfileNode::kNoColumnNumberInfo, nullptr, code->InstructionStart()); diff --git a/src/profiler/profiler-listener.h b/src/profiler/profiler-listener.h index eafefcd753..c0cd300092 100644 --- a/src/profiler/profiler-listener.h +++ b/src/profiler/profiler-listener.h @@ -67,15 +67,12 @@ class ProfilerListener : public CodeEventListener { const char* GetName(int args_count) { return function_and_resource_names_.GetName(args_count); } + const char* GetName(const char* name) { + return function_and_resource_names_.GetCopy(name); + } const char* GetConsName(const char* prefix, Name* name) { return function_and_resource_names_.GetConsName(prefix, name); } - const char* GetFunctionName(Name* name) { - return function_and_resource_names_.GetFunctionName(name); - } - const char* GetFunctionName(const char* name) { - return function_and_resource_names_.GetFunctionName(name); - } private: void RecordInliningInfo(CodeEntry* entry, AbstractCode* abstract_code); diff --git a/src/profiler/sampling-heap-profiler.cc b/src/profiler/sampling-heap-profiler.cc index 6912f3eba1..8af1dd5c1f 100644 --- a/src/profiler/sampling-heap-profiler.cc +++ b/src/profiler/sampling-heap-profiler.cc @@ -203,7 +203,7 @@ SamplingHeapProfiler::AllocationNode* SamplingHeapProfiler::AddStack() { // the first element in the list. for (auto it = stack.rbegin(); it != stack.rend(); ++it) { SharedFunctionInfo* shared = *it; - const char* name = this->names()->GetFunctionName(shared->DebugName()); + const char* name = this->names()->GetName(shared->DebugName()); int script_id = v8::UnboundScript::kNoScriptId; if (shared->script()->IsScript()) { Script* script = Script::cast(shared->script()); diff --git a/src/profiler/strings-storage.cc b/src/profiler/strings-storage.cc index e48d054df6..4416479279 100644 --- a/src/profiler/strings-storage.cc +++ b/src/profiler/strings-storage.cc @@ -107,14 +107,6 @@ const char* StringsStorage::GetConsName(const char* prefix, Name* name) { return ""; } -const char* StringsStorage::GetFunctionName(Name* name) { - return GetName(name); -} - -const char* StringsStorage::GetFunctionName(const char* name) { - return GetCopy(name); -} - base::HashMap::Entry* StringsStorage::GetEntry(const char* str, int len) { uint32_t hash = StringHasher::HashSequentialString(str, len, hash_seed_); return names_.LookupOrInsert(const_cast(str), hash); diff --git a/src/profiler/strings-storage.h b/src/profiler/strings-storage.h index cdc22e48f2..ccd58f746e 100644 --- a/src/profiler/strings-storage.h +++ b/src/profiler/strings-storage.h @@ -35,10 +35,6 @@ class V8_EXPORT_PRIVATE StringsStorage { // Appends string resulting from name to prefix, then returns the stored // result. const char* GetConsName(const char* prefix, Name* name); - // Does exactly the same thing as GetName(Name* name). - const char* GetFunctionName(Name* name); - // Does exactly the same thing as GetCopy(const char* name). - const char* GetFunctionName(const char* name); private: static bool StringsMatch(void* key1, void* key2); diff --git a/test/unittests/strings-storage-unittest.cc b/test/unittests/strings-storage-unittest.cc index de410e8e26..dad8356ad4 100644 --- a/test/unittests/strings-storage-unittest.cc +++ b/test/unittests/strings-storage-unittest.cc @@ -80,28 +80,6 @@ TEST_F(StringsStorageWithIsolate, GetNameFromInt) { CHECK(StringEq(str_negative_int, stored_str)); } -TEST_F(StringsStorageWithIsolate, GetFunctionNameFromString) { - StringsStorage storage(isolate()->heap()->HashSeed()); - - Handle str = isolate()->factory()->NewStringFromAsciiChecked("xy"); - const char* stored_str = storage.GetFunctionName(*str); - CHECK(StringEq("xy", stored_str)); - - // Check that GetName and GetFunctionName use the same storage. - const char* stored_str_twice = storage.GetName(*str); - CHECK_EQ(stored_str, stored_str_twice); -} - -TEST_F(StringsStorageWithIsolate, GetFunctionNameFromCString) { - StringsStorage storage(isolate()->heap()->HashSeed()); - - const char* xy = "xy"; - const char* stored_str = storage.GetFunctionName("xy"); - CHECK(StringEq("xy", stored_str)); - // Check that the string is copied. - CHECK_NE(xy, stored_str); -} - TEST_F(StringsStorageWithIsolate, Format) { StringsStorage storage(isolate()->heap()->HashSeed());