blob: 0849d6330021ca0f3c831144cf0b732fefd6373b [file] [log] [blame]
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001// Copyright 2015 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef V8_PROFILER_STRINGS_STORAGE_H_
6#define V8_PROFILER_STRINGS_STORAGE_H_
7
8#include "src/allocation.h"
Ben Murdochc5610432016-08-08 18:44:38 +01009#include "src/base/compiler-specific.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000010#include "src/hashmap.h"
11
12namespace v8 {
13namespace internal {
14
15// Provides a storage of strings allocated in C++ heap, to hold them
16// forever, even if they disappear from JS heap or external storage.
17class StringsStorage {
18 public:
19 explicit StringsStorage(Heap* heap);
20 ~StringsStorage();
21
22 const char* GetCopy(const char* src);
Ben Murdochc5610432016-08-08 18:44:38 +010023 PRINTF_FORMAT(2, 3) const char* GetFormatted(const char* format, ...);
24 PRINTF_FORMAT(2, 0)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000025 const char* GetVFormatted(const char* format, va_list args);
26 const char* GetName(Name* name);
27 const char* GetName(int index);
28 const char* GetFunctionName(Name* name);
29 const char* GetFunctionName(const char* name);
30 size_t GetUsedMemorySize() const;
31
32 private:
33 static const int kMaxNameSize = 1024;
34
35 static bool StringsMatch(void* key1, void* key2);
36 const char* AddOrDisposeString(char* str, int len);
37 HashMap::Entry* GetEntry(const char* str, int len);
38
39 uint32_t hash_seed_;
40 HashMap names_;
41
42 DISALLOW_COPY_AND_ASSIGN(StringsStorage);
43};
44} // namespace internal
45} // namespace v8
46
47#endif // V8_PROFILER_STRINGS_STORAGE_H_