[profiler] Refactoring: decouple StringsStorage from Heap object.

Change-Id: I450efa4916bd774265991f987f4be618ba2eb1d2
Reviewed-on: https://chromium-review.googlesource.com/1045168
Commit-Queue: Alexei Filippov <alph@chromium.org>
Reviewed-by: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53005}
This commit is contained in:
Alexei Filippov 2018-05-04 14:42:03 -07:00 committed by Commit Bot
parent 8ec48b2117
commit a31320f59c
5 changed files with 11 additions and 16 deletions

View File

@ -16,14 +16,14 @@ namespace internal {
HeapProfiler::HeapProfiler(Heap* heap)
: ids_(new HeapObjectsMap(heap)),
names_(new StringsStorage(heap)),
names_(new StringsStorage(heap->HashSeed())),
is_tracking_object_moves_(false) {}
HeapProfiler::~HeapProfiler() = default;
void HeapProfiler::DeleteAllSnapshots() {
snapshots_.clear();
names_.reset(new StringsStorage(heap()));
names_.reset(new StringsStorage(heap()->HashSeed()));
}

View File

@ -515,7 +515,7 @@ void CodeMap::Print() {
}
CpuProfilesCollection::CpuProfilesCollection(Isolate* isolate)
: resource_names_(isolate->heap()),
: resource_names_(isolate->heap()->HashSeed()),
profiler_(nullptr),
current_profiles_semaphore_(1) {}

View File

@ -17,7 +17,8 @@ namespace internal {
ProfilerListener::ProfilerListener(Isolate* isolate,
CodeEventObserver* observer)
: observer_(observer), function_and_resource_names_(isolate->heap()) {}
: observer_(observer),
function_and_resource_names_(isolate->heap()->HashSeed()) {}
ProfilerListener::~ProfilerListener() = default;

View File

@ -6,21 +6,19 @@
#include <memory>
#include "src/allocation.h"
#include "src/objects-inl.h"
namespace v8 {
namespace internal {
bool StringsStorage::StringsMatch(void* key1, void* key2) {
return strcmp(reinterpret_cast<char*>(key1), reinterpret_cast<char*>(key2)) ==
0;
}
StringsStorage::StringsStorage(Heap* heap)
: hash_seed_(heap->HashSeed()), names_(StringsMatch) {}
StringsStorage::StringsStorage(uint32_t hash_seed)
: hash_seed_(hash_seed), names_(StringsMatch) {}
StringsStorage::~StringsStorage() {
for (base::HashMap::Entry* p = names_.Start(); p != nullptr;
@ -29,7 +27,6 @@ StringsStorage::~StringsStorage() {
}
}
const char* StringsStorage::GetCopy(const char* src) {
int len = static_cast<int>(strlen(src));
base::HashMap::Entry* entry = GetEntry(src, len);
@ -43,7 +40,6 @@ const char* StringsStorage::GetCopy(const char* src) {
return reinterpret_cast<const char*>(entry->value);
}
const char* StringsStorage::GetFormatted(const char* format, ...) {
va_list args;
va_start(args, format);
@ -52,7 +48,6 @@ const char* StringsStorage::GetFormatted(const char* format, ...) {
return result;
}
const char* StringsStorage::AddOrDisposeString(char* str, int len) {
base::HashMap::Entry* entry = GetEntry(str, len);
if (entry->value == nullptr) {
@ -65,7 +60,6 @@ const char* StringsStorage::AddOrDisposeString(char* str, int len) {
return reinterpret_cast<const char*>(entry->value);
}
const char* StringsStorage::GetVFormatted(const char* format, va_list args) {
Vector<char> str = Vector<char>::New(1024);
int len = VSNPrintF(str, format, args);
@ -76,7 +70,6 @@ const char* StringsStorage::GetVFormatted(const char* format, va_list args) {
return AddOrDisposeString(str.start(), len);
}
const char* StringsStorage::GetName(Name* name) {
if (name->IsString()) {
String* str = String::cast(name);

View File

@ -7,18 +7,19 @@
#include <stdarg.h>
#include "src/allocation.h"
#include "src/base/compiler-specific.h"
#include "src/base/hashmap.h"
namespace v8 {
namespace internal {
class Name;
// 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:
explicit StringsStorage(Heap* heap);
explicit StringsStorage(uint32_t hash_seed);
~StringsStorage();
const char* GetCopy(const char* src);