Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1 | // 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 Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 8 | #include <stdarg.h> |
| 9 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10 | #include "src/allocation.h" |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 11 | #include "src/base/compiler-specific.h" |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 12 | #include "src/base/hashmap.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 13 | |
| 14 | namespace v8 { |
| 15 | namespace 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. |
| 19 | class StringsStorage { |
| 20 | public: |
| 21 | explicit StringsStorage(Heap* heap); |
| 22 | ~StringsStorage(); |
| 23 | |
| 24 | const char* GetCopy(const char* src); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 25 | PRINTF_FORMAT(2, 3) const char* GetFormatted(const char* format, ...); |
| 26 | PRINTF_FORMAT(2, 0) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 27 | 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 Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 39 | base::HashMap::Entry* GetEntry(const char* str, int len); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 40 | |
| 41 | uint32_t hash_seed_; |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 42 | base::HashMap names_; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 43 | |
| 44 | DISALLOW_COPY_AND_ASSIGN(StringsStorage); |
| 45 | }; |
| 46 | } // namespace internal |
| 47 | } // namespace v8 |
| 48 | |
| 49 | #endif // V8_PROFILER_STRINGS_STORAGE_H_ |