blob: f98aa5e038bc2845caae7c63981372610d2f510a [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
Ben Murdoch61f157c2016-09-16 13:49:30 +01008#include <stdarg.h>
9
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000010#include "src/allocation.h"
Ben Murdochc5610432016-08-08 18:44:38 +010011#include "src/base/compiler-specific.h"
Ben Murdoch61f157c2016-09-16 13:49:30 +010012#include "src/base/hashmap.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000013
14namespace v8 {
15namespace internal {
16
17// Provides a storage of strings allocated in C++ heap, to hold them
18// forever, even if they disappear from JS heap or external storage.
19class StringsStorage {
20 public:
21 explicit StringsStorage(Heap* heap);
22 ~StringsStorage();
23
24 const char* GetCopy(const char* src);
Ben Murdochc5610432016-08-08 18:44:38 +010025 PRINTF_FORMAT(2, 3) const char* GetFormatted(const char* format, ...);
26 PRINTF_FORMAT(2, 0)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000027 const char* GetVFormatted(const char* format, va_list args);
28 const char* GetName(Name* name);
29 const char* GetName(int index);
30 const char* GetFunctionName(Name* name);
31 const char* GetFunctionName(const char* name);
32 size_t GetUsedMemorySize() const;
33
34 private:
35 static const int kMaxNameSize = 1024;
36
37 static bool StringsMatch(void* key1, void* key2);
38 const char* AddOrDisposeString(char* str, int len);
Ben Murdoch61f157c2016-09-16 13:49:30 +010039 base::HashMap::Entry* GetEntry(const char* str, int len);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000040
41 uint32_t hash_seed_;
Ben Murdoch61f157c2016-09-16 13:49:30 +010042 base::HashMap names_;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000043
44 DISALLOW_COPY_AND_ASSIGN(StringsStorage);
45};
46} // namespace internal
47} // namespace v8
48
49#endif // V8_PROFILER_STRINGS_STORAGE_H_