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 8 #include <stdarg.h> 9 10 #include "src/allocation.h" 11 #include "src/base/compiler-specific.h" 12 #include "src/base/hashmap.h" 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); 25 PRINTF_FORMAT(2, 3) const char* GetFormatted(const char* format, ...); 26 PRINTF_FORMAT(2, 0) 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); 39 base::CustomMatcherHashMap::Entry* GetEntry(const char* str, int len); 40 41 uint32_t hash_seed_; 42 base::CustomMatcherHashMap names_; 43 44 DISALLOW_COPY_AND_ASSIGN(StringsStorage); 45 }; 46 } // namespace internal 47 } // namespace v8 48 49 #endif // V8_PROFILER_STRINGS_STORAGE_H_ 50