v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
strings-storage.h
Go to the documentation of this file.
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
11#include "src/base/hashmap.h"
13#include "src/common/globals.h"
14
15namespace v8 {
16namespace internal {
17
18class Name;
19class Symbol;
20
21// Provides a storage of strings allocated in C++ heap, to hold them
22// forever, even if they disappear from JS heap or external storage.
24 public:
29
30 // Copies the given c-string and stores it, returning the stored copy, or just
31 // returns the existing string in storage if it already exists.
32 const char* GetCopy(const char* src);
33 // Returns a formatted string, de-duplicated via the storage.
34 PRINTF_FORMAT(2, 3) const char* GetFormatted(const char* format, ...);
35 // Returns a stored string resulting from name, or "<symbol>" for a symbol.
36 const char* GetName(Tagged<Name> name);
37 // Returns the string representation of the int from the store.
38 const char* GetName(int index);
39 // Appends string resulting from name to prefix, then returns the stored
40 // result.
41 const char* GetConsName(const char* prefix, Tagged<Name> name);
42 // Reduces the refcount of the given string, freeing it if no other
43 // references are made to it. Returns true if the string was successfully
44 // unref'd, or false if the string was not present in the table.
45 bool Release(const char* str);
46
47 // Returns the number of strings in the store.
48 size_t GetStringCountForTesting() const;
49
50 // Returns the size of strings in the store
51 size_t GetStringSize();
52
53 // Returns true if the strings table is empty.
54 bool empty() const { return names_.occupancy() == 0; }
55
56 private:
57 static bool StringsMatch(void* key1, void* key2);
58 // Adds the string to storage and returns it, or if a matching string exists
59 // in the storage, deletes str and returns the matching string instead.
60 const char* AddOrDisposeString(char* str, size_t len);
61 base::CustomMatcherHashMap::Entry* GetEntry(const char* str, size_t len);
62 PRINTF_FORMAT(2, 0)
63 const char* GetVFormatted(const char* format, va_list args);
64 const char* GetSymbol(Tagged<Symbol> sym);
65
66 base::CustomMatcherHashMap names_;
67 base::Mutex mutex_;
68 size_t string_size_ = 0;
69};
70
71} // namespace internal
72} // namespace v8
73
74#endif // V8_PROFILER_STRINGS_STORAGE_H_
StringsStorage & operator=(const StringsStorage &)=delete
StringsStorage(const StringsStorage &)=delete
PRINTF_FORMAT(2, 3) const char *GetFormatted(const char *format
base::Mutex & mutex_
base::Vector< const DirectHandle< Object > > args
Definition execution.cc:74
StringsStorage * names_
#define PRINTF_FORMAT(format_param, dots_param)
#define V8_EXPORT_PRIVATE
Definition macros.h:460