24static const char*
const names[] = {
27#define DEFINE_SYMBOL_LITERAL(symbol, literal) literal,
29#undef DEFINE_SYMBOL_LITERAL
31#define DEFINE_TOKEN_SYMBOL_INDEX(t, s, p, a) s,
34#undef DEFINE_TOKEN_SYMBOL_INDEX
47 if (is_all() && str_.
IsOld()) {
72 const int tok_index = token;
73 ASSERT((0 <= tok_index) && (tok_index < Token::kNumTokens));
76 ASSERT(symbol_handles_[token_id] !=
nullptr);
77 return *symbol_handles_[token_id];
90 ASSERT((
sizeof(
names) /
sizeof(
const char*)) == Symbols::kNullCharId);
99 for (intptr_t i = 1; i < Symbols::kNullCharId; i++) {
103 *str ^=
table.InsertOrGet(*str);
105 symbol_handles_[i] = str;
110 intptr_t idx = (kNullCharId + c);
113 uint8_t ch =
static_cast<uint8_t
>(c);
117 *str ^=
table.InsertOrGet(*str);
118 ASSERT(predefined_[c] ==
nullptr);
120 predefined_[c] = str->
ptr();
121 symbol_handles_[idx] = str;
138 for (intptr_t i = 1; i < Symbols::kNullCharId; i++) {
140 const unsigned char*
name =
141 reinterpret_cast<const unsigned char*
>(
names[i]);
146 symbol_handles_[i] = str;
152 intptr_t idx = (kNullCharId + c);
155 uint8_t ch =
static_cast<uint8_t
>(c);
161 predefined_[c] = str->
ptr();
162 symbol_handles_[idx] = str;
169 ASSERT(isolate_group !=
nullptr);
173 ? kInitialVMIsolateSymtabSize
174 : kInitialSymtabSize;
176 HashTables::New<CanonicalStringSet>(initial_size,
Heap::kOld));
182 intptr_t* capacity) {
183 ASSERT(isolate_group !=
nullptr);
185 *size =
table.NumOccupied();
186 *capacity =
table.NumEntries();
191 ASSERT((cstr !=
nullptr) && (len >= 0));
192 const uint8_t* utf8_array =
reinterpret_cast<const uint8_t*
>(cstr);
197 const uint8_t* utf8_array,
198 intptr_t array_len) {
199 if (array_len == 0 || utf8_array ==
nullptr) {
200 return FromLatin1(thread,
static_cast<uint8_t*
>(
nullptr), 0);
207 uint8_t* characters = zone->
Alloc<uint8_t>(len);
215 uint16_t* characters = zone->
Alloc<uint16_t>(len);
220 return FromUTF16(thread, characters, len);
224 const uint8_t* latin1_array,
226 return NewSymbol(thread,
Latin1Array(latin1_array, len));
230 const uint16_t* utf16_array,
232 return NewSymbol(thread,
UTF16Array(utf16_array, len));
239 return New(thread, str2);
240 }
else if (str2.
Length() == 0) {
241 return New(thread, str1);
248 return FromConcat(thread, GetterPrefix(), str);
252 return FromConcat(thread, SetterPrefix(), str);
265 const intptr_t strs_length = strs.
length();
268 intptr_t len_sum = 0;
269 const intptr_t kOneByteChar = 1;
270 intptr_t char_size = kOneByteChar;
272 for (intptr_t i = 0; i < strs_length; i++) {
273 const String& str = strs[i];
274 const intptr_t str_len = str.
Length();
280 lengths.
Add(str_len);
283 const bool is_one_byte_string = char_size == kOneByteChar;
286 if (is_one_byte_string) {
288 const uint8_t*
const orig_buffer =
buffer;
289 for (intptr_t i = 0; i < strs_length; i++) {
291 intptr_t str_len = lengths[i];
293 const String& str = strs[i];
295 const uint8_t*
src_p = OneByteString::DataStart(str);
304 const uint16_t*
const orig_buffer =
buffer;
305 for (intptr_t i = 0; i < strs_length; i++) {
307 intptr_t str_len = lengths[i];
309 const String& str = strs[i];
311 memmove(
buffer, TwoByteString::DataStart(str), str_len * 2);
315 const uint8_t*
src_p = OneByteString::DataStart(str);
316 for (
int n = 0; n < str_len; n++) {
329template <
typename StringType>
330StringPtr Symbols::NewSymbol(
Thread* thread,
const StringType& str) {
340 data = vm_isolate_group->object_store()->symbol_table();
342 symbol ^=
table.GetOrNull(str);
347 ObjectStore* object_store = group->object_store();
355 data = object_store->symbol_table();
357 symbol ^=
table.GetOrNull(str);
362 SafepointMutexLocker ml(
group->symbols_mutex());
363 data = object_store->symbol_table();
365 symbol ^=
table.InsertNewOrGet(str);
366 object_store->set_symbol_table(
table.Release());
374template <
typename StringType>
385 data = vm_isolate_group->object_store()->symbol_table();
387 symbol ^=
table.GetOrNull(str);
396 data = object_store->symbol_table();
398 symbol ^=
table.GetOrNull(str);
401 data = object_store->symbol_table();
403 symbol ^=
table.GetOrNull(str);
416 return Lookup(thread, str2);
417 }
else if (str2.
Length() == 0) {
418 return Lookup(thread, str1);
440 return New(thread, str, 0, str.
Length());
445 intptr_t begin_index,
447 return NewSymbol(thread,
StringSlice(str, begin_index, len));
463 va_copy(args_copy,
args);
478 return predefined_[char_code];
483 intptr_t capacity = -1;
487 OS::PrintErr(
"VM Isolate: Symbol table capacity : %" Pd "\n", capacity);
489 GetStats(isolate_group, &size, &capacity);
491 OS::PrintErr(
"Isolate: Symbol table capacity : %" Pd "\n", capacity);
static uint8_t src_p(uint8_t src, uint8_t dst)
#define RELEASE_ASSERT(cond)
StringPtr ToSymbol() const
static IsolateGroup * vm_isolate_group()
static DART_NORETURN void ThrowOOM()
ObjectStore * object_store() const
static IsolateGroup * Current()
static void static void PrintErr(const char *format,...) PRINTF_ATTRIBUTE(1
static Object * ReadOnlyHandle()
void SetCanonical() const
static OneByteStringPtr New(intptr_t len, Heap::Space space)
StringPtr ToSymbol() const
static StringPtr FromLatin1(const uint8_t *latin1_array, intptr_t array_len, Heap::Space space=Heap::kNew)
static constexpr intptr_t kMaxElements
bool IsOneByteString() const
intptr_t CharSize() const
bool IsTwoByteString() const
static StringPtr SubString(const String &str, intptr_t begin_index, Heap::Space space=Heap::kNew)
static StringPtr Concat(const String &str1, const String &str2, Heap::Space space=Heap::kNew)
static StringPtr FromUTF16(const uint16_t *utf16_array, intptr_t array_len, Heap::Space space=Heap::kNew)
static void GetStats(IsolateGroup *isolate_group, intptr_t *size, intptr_t *capacity)
static void InitFromSnapshot(IsolateGroup *isolate_group)
static StringPtr Lookup(Thread *thread, const StringType &str)
static const char * Name(SymbolId symbol)
static StringPtr LookupFromDot(Thread *thread, const String &str)
static StringPtr static StringPtr NewFormattedV(Thread *thread, const char *format, va_list args)
static StringPtr LookupFromGet(Thread *thread, const String &str)
static void Init(IsolateGroup *isolate_group)
static StringPtr FromConcat(Thread *thread, const String &str1, const String &str2)
static StringPtr LookupFromSet(Thread *thread, const String &str)
static StringPtr FromUTF16(Thread *thread, const uint16_t *utf16_array, intptr_t len)
static constexpr int kNumberOfOneCharCodeSymbols
static StringPtr FromGet(Thread *thread, const String &str)
static StringPtr FromSet(Thread *thread, const String &str)
static StringPtr FromDot(Thread *thread, const String &str)
static StringPtr FromCharCode(Thread *thread, uint16_t char_code)
static void SetupSymbolTable(IsolateGroup *isolate_group)
static StringPtr FromConcatAll(Thread *thread, const GrowableHandlePtrArray< const String > &strs)
static StringPtr FromUTF8(Thread *thread, const uint8_t *utf8_array, intptr_t len)
static StringPtr New(Thread *thread, const char *cstr)
static void DumpStats(IsolateGroup *isolate_group)
static const String & Dot()
static StringPtr LookupFromConcat(Thread *thread, const String &str1, const String &str2)
static StringPtr NewFormatted(Thread *thread, const char *format,...) PRINTF_ATTRIBUTE(2
static void DumpTable(IsolateGroup *isolate_group)
static StringPtr FromLatin1(Thread *thread, const uint8_t *latin1_array, intptr_t len)
static const String & Token(Token::Kind token)
bool CanAcquireSafepointLocks() const
bool OwnsSafepoint() const
static Thread * Current()
IsolateGroup * isolate_group() const
static intptr_t CodeUnitCount(const uint8_t *utf8_array, intptr_t array_len, Type *type)
static intptr_t ReportInvalidByte(const uint8_t *utf8_array, intptr_t array_len, intptr_t len)
static bool DecodeToUTF16(const uint8_t *utf8_array, intptr_t array_len, uint16_t *dst, intptr_t len)
static bool DecodeToLatin1(const uint8_t *utf8_array, intptr_t array_len, uint8_t *dst, intptr_t len)
static bool IsLatin1(int32_t code_point)
static constexpr T Maximum(T x, T y)
static int static int VSNPrint(char *str, size_t size, const char *format, va_list args)
ElementType * Alloc(intptr_t length)
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
static const uint8_t buffer[]
uint32_t uint32_t * format
static const char *const names[]
CharArray< uint8_t > Latin1Array
CharArray< uint16_t > UTF16Array
StringPtr StringFrom(const uint8_t *data, intptr_t len, Heap::Space space)
static int8_t data[kExtLength]
UnorderedHashSet< SymbolTraits, WeakAcqRelStorageTraits > CanonicalStringSet
#define REUSABLE_ARRAY_HANDLESCOPE(thread)
#define REUSABLE_SMI_HANDLESCOPE(thread)
#define REUSABLE_WEAK_ARRAY_HANDLESCOPE(thread)
#define REUSABLE_OBJECT_HANDLESCOPE(thread)
#define DEFINE_SYMBOL_LITERAL(symbol, literal)
#define DEFINE_TOKEN_SYMBOL_INDEX(t, s, p, a)
#define PREDEFINED_SYMBOLS_LIST(V)
#define DART_KEYWORD_LIST(KW)
#define DART_TOKEN_LIST(TOK)