[cpu-profiler] Fix string length calculation for GetConsName

Currently, GetConsName incorrectly includes the null terminator as part
of the length used in the string's hash. Exclude this to be consistent
with GetCopy, GetName, etc. and permit coalescing.

Bug: v8:0
Change-Id: I1e8a4eb7055637f3ed178014725b44e84d7788b6
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2578192
Reviewed-by: Peter Marshall <petermarshall@chromium.org>
Commit-Queue: Andrew Comminos <acomminos@fb.com>
Cr-Commit-Position: refs/heads/master@{#71667}
This commit is contained in:
Andrew Comminos 2020-12-07 20:25:38 -08:00 committed by Commit Bot
parent 0b7769e393
commit 678afa3c04
2 changed files with 13 additions and 1 deletions

View File

@ -101,7 +101,7 @@ const char* StringsStorage::GetConsName(const char* prefix, Name name) {
char* cons_result = NewArray<char>(cons_length);
snprintf(cons_result, cons_length, "%s%s", prefix, data.get());
return AddOrDisposeString(cons_result, cons_length);
return AddOrDisposeString(cons_result, cons_length - 1);
} else if (name.IsSymbol()) {
return "<symbol>";
}

View File

@ -157,5 +157,17 @@ TEST_F(StringsStorageWithIsolate, InvalidRelease) {
#endif // DEBUG
}
TEST_F(StringsStorageWithIsolate, CopyAndConsShareStorage) {
StringsStorage storage;
Handle<String> str = isolate()->factory()->NewStringFromAsciiChecked("foo");
const char* copy_str = storage.GetCopy("get foo");
const char* cons_str = storage.GetConsName("get ", *str);
CHECK_EQ(storage.GetStringCountForTesting(), 1);
CHECK_EQ(copy_str, cons_str);
}
} // namespace internal
} // namespace v8