#ifndef V8_OBJECTS_STRING_FORWARDING_TABLE_H_
#define V8_OBJECTS_STRING_FORWARDING_TABLE_H_
#include "src/objects/string.h"
#include "src/objects/object-macros.h"
namespace v8 {
namespace internal {
class StringForwardingTable {
public:
static constexpr int kInitialBlockSize = 16;
static_assert(base::bits::IsPowerOfTwo(kInitialBlockSize));
static constexpr int kInitialBlockSizeHighestBit =
kBitsPerInt - base::bits::CountLeadingZeros32(kInitialBlockSize) - 1;
static constexpr int kInitialBlockVectorCapacity = 4;
static constexpr Tagged<Smi> unused_element() { return Smi::FromInt(0); }
static constexpr Tagged<Smi> deleted_element() { return Smi::FromInt(1); }
explicit StringForwardingTable(Isolate* isolate);
~StringForwardingTable();
inline int size() const;
inline bool empty() const;
int AddForwardString(Tagged<String> string, Tagged<String> forward_to);
template <typename T>
EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE)
int AddExternalResourceAndHash(Tagged<String> string, T* resource,
uint32_t raw_hash);
void UpdateForwardString(int index, Tagged<String> forward_to);
template <typename T>
EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE)
bool TryUpdateExternalResource(int index, T* resource);
Tagged<String> GetForwardString(PtrComprCageBase cage_base, int index) const;
static Address GetForwardStringAddress(Isolate* isolate, int index);
V8_EXPORT_PRIVATE uint32_t GetRawHash(PtrComprCageBase cage_base,
int index) const;
static uint32_t GetRawHashStatic(Isolate* isolate, int index);
v8::String::ExternalStringResourceBase* GetExternalResource(
int index, bool* is_one_byte) const;
template <typename Func>
V8_INLINE void IterateElements(Func&& callback);
void TearDown();
void Reset();
void UpdateAfterYoungEvacuation();
void UpdateAfterFullEvacuation();
class Record;
private:
class Block;
class BlockVector;
static inline uint32_t BlockForIndex(int index, uint32_t* index_in_block_out);
static inline uint32_t IndexInBlock(int index, uint32_t block);
static inline uint32_t CapacityForBlock(uint32_t block);
void InitializeBlockVector();
BlockVector* EnsureCapacity(uint32_t block);
Isolate* isolate_;
std::atomic<BlockVector*> blocks_;
std::vector<std::unique_ptr<BlockVector>> block_vector_storage_;
std::atomic<int> next_free_index_;
base::Mutex grow_mutex_;
};
}
}
#include "src/objects/object-macros-undef.h"
#endif