Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(361)

Side by Side Diff: runtime/vm/symbols.cc

Issue 2481873005: clang-format runtime/vm (Closed)
Patch Set: Merge Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/symbols.h ('k') | runtime/vm/tags.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/symbols.h" 5 #include "vm/symbols.h"
6 6
7 #include "vm/handles.h" 7 #include "vm/handles.h"
8 #include "vm/hash_table.h" 8 #include "vm/hash_table.h"
9 #include "vm/isolate.h" 9 #include "vm/isolate.h"
10 #include "vm/object.h" 10 #include "vm/object.h"
11 #include "vm/object_store.h" 11 #include "vm/object_store.h"
12 #include "vm/raw_object.h" 12 #include "vm/raw_object.h"
13 #include "vm/reusable_handles.h" 13 #include "vm/reusable_handles.h"
14 #include "vm/snapshot_ids.h" 14 #include "vm/snapshot_ids.h"
15 #include "vm/unicode.h" 15 #include "vm/unicode.h"
16 #include "vm/visitor.h" 16 #include "vm/visitor.h"
17 17
18 namespace dart { 18 namespace dart {
19 19
20 RawString* Symbols::predefined_[Symbols::kNumberOfOneCharCodeSymbols]; 20 RawString* Symbols::predefined_[Symbols::kNumberOfOneCharCodeSymbols];
21 String* Symbols::symbol_handles_[Symbols::kMaxPredefinedId]; 21 String* Symbols::symbol_handles_[Symbols::kMaxPredefinedId];
22 22
23 static const char* names[] = { 23 static const char* names[] = {
24 // clang-format off
24 NULL, 25 NULL,
25 26 #define DEFINE_SYMBOL_LITERAL(symbol, literal) literal,
26 #define DEFINE_SYMBOL_LITERAL(symbol, literal) \ 27 PREDEFINED_SYMBOLS_LIST(DEFINE_SYMBOL_LITERAL)
27 literal,
28 PREDEFINED_SYMBOLS_LIST(DEFINE_SYMBOL_LITERAL)
29 #undef DEFINE_SYMBOL_LITERAL 28 #undef DEFINE_SYMBOL_LITERAL
30
31 "", // matches kTokenTableStart. 29 "", // matches kTokenTableStart.
32 30 #define DEFINE_TOKEN_SYMBOL_INDEX(t, s, p, a) s,
33 #define DEFINE_TOKEN_SYMBOL_INDEX(t, s, p, a) \
34 s,
35 DART_TOKEN_LIST(DEFINE_TOKEN_SYMBOL_INDEX) 31 DART_TOKEN_LIST(DEFINE_TOKEN_SYMBOL_INDEX)
36 DART_KEYWORD_LIST(DEFINE_TOKEN_SYMBOL_INDEX) 32 DART_KEYWORD_LIST(DEFINE_TOKEN_SYMBOL_INDEX)
37 #undef DEFINE_TOKEN_SYMBOL_INDEX 33 #undef DEFINE_TOKEN_SYMBOL_INDEX
34 // clang-format on
38 }; 35 };
39 36
40 RawString* StringFrom(const uint8_t* data, intptr_t len, Heap::Space space) { 37 RawString* StringFrom(const uint8_t* data, intptr_t len, Heap::Space space) {
41 return String::FromLatin1(data, len, space); 38 return String::FromLatin1(data, len, space);
42 } 39 }
40
41
43 RawString* StringFrom(const uint16_t* data, intptr_t len, Heap::Space space) { 42 RawString* StringFrom(const uint16_t* data, intptr_t len, Heap::Space space) {
44 return String::FromUTF16(data, len, space); 43 return String::FromUTF16(data, len, space);
45 } 44 }
45
46
46 RawString* StringFrom(const int32_t* data, intptr_t len, Heap::Space space) { 47 RawString* StringFrom(const int32_t* data, intptr_t len, Heap::Space space) {
47 return String::FromUTF32(data, len, space); 48 return String::FromUTF32(data, len, space);
48 } 49 }
49 50
50 51
51 template<typename CharType> 52 template <typename CharType>
52 class CharArray { 53 class CharArray {
53 public: 54 public:
54 CharArray(const CharType* data, intptr_t len) 55 CharArray(const CharType* data, intptr_t len) : data_(data), len_(len) {
55 : data_(data), len_(len) {
56 hash_ = String::Hash(data, len); 56 hash_ = String::Hash(data, len);
57 } 57 }
58 RawString* ToSymbol() const { 58 RawString* ToSymbol() const {
59 String& result = String::Handle(StringFrom(data_, len_, Heap::kOld)); 59 String& result = String::Handle(StringFrom(data_, len_, Heap::kOld));
60 result.SetCanonical(); 60 result.SetCanonical();
61 result.SetHash(hash_); 61 result.SetHash(hash_);
62 return result.raw(); 62 return result.raw();
63 } 63 }
64 bool Equals(const String& other) const { 64 bool Equals(const String& other) const {
65 ASSERT(other.HasHash()); 65 ASSERT(other.HasHash());
66 if (other.Hash() != hash_) { 66 if (other.Hash() != hash_) {
67 return false; 67 return false;
68 } 68 }
69 return other.Equals(data_, len_); 69 return other.Equals(data_, len_);
70 } 70 }
71 intptr_t Hash() const { return hash_; } 71 intptr_t Hash() const { return hash_; }
72
72 private: 73 private:
73 const CharType* data_; 74 const CharType* data_;
74 intptr_t len_; 75 intptr_t len_;
75 intptr_t hash_; 76 intptr_t hash_;
76 }; 77 };
77 typedef CharArray<uint8_t> Latin1Array; 78 typedef CharArray<uint8_t> Latin1Array;
78 typedef CharArray<uint16_t> UTF16Array; 79 typedef CharArray<uint16_t> UTF16Array;
79 typedef CharArray<int32_t> UTF32Array; 80 typedef CharArray<int32_t> UTF32Array;
80 81
81 82
82 class StringSlice { 83 class StringSlice {
83 public: 84 public:
84 StringSlice(const String& str, intptr_t begin_index, intptr_t length) 85 StringSlice(const String& str, intptr_t begin_index, intptr_t length)
85 : str_(str), begin_index_(begin_index), len_(length) { 86 : str_(str), begin_index_(begin_index), len_(length) {
86 hash_ = is_all() ? str.Hash() : String::Hash(str, begin_index, length); 87 hash_ = is_all() ? str.Hash() : String::Hash(str, begin_index, length);
87 } 88 }
88 RawString* ToSymbol() const; 89 RawString* ToSymbol() const;
89 bool Equals(const String& other) const { 90 bool Equals(const String& other) const {
90 ASSERT(other.HasHash()); 91 ASSERT(other.HasHash());
91 if (other.Hash() != hash_) { 92 if (other.Hash() != hash_) {
92 return false; 93 return false;
93 } 94 }
94 return other.Equals(str_, begin_index_, len_); 95 return other.Equals(str_, begin_index_, len_);
95 } 96 }
96 intptr_t Hash() const { return hash_; } 97 intptr_t Hash() const { return hash_; }
98
97 private: 99 private:
98 bool is_all() const { return begin_index_ == 0 && len_ == str_.Length(); } 100 bool is_all() const { return begin_index_ == 0 && len_ == str_.Length(); }
99 const String& str_; 101 const String& str_;
100 intptr_t begin_index_; 102 intptr_t begin_index_;
101 intptr_t len_; 103 intptr_t len_;
102 intptr_t hash_; 104 intptr_t hash_;
103 }; 105 };
104 106
105 107
106 RawString* StringSlice::ToSymbol() const { 108 RawString* StringSlice::ToSymbol() const {
107 if (is_all() && str_.IsOld()) { 109 if (is_all() && str_.IsOld()) {
108 str_.SetCanonical(); 110 str_.SetCanonical();
109 return str_.raw(); 111 return str_.raw();
110 } else { 112 } else {
111 String& result = String::Handle( 113 String& result =
112 String::SubString(str_, begin_index_, len_, Heap::kOld)); 114 String::Handle(String::SubString(str_, begin_index_, len_, Heap::kOld));
113 result.SetCanonical(); 115 result.SetCanonical();
114 result.SetHash(hash_); 116 result.SetHash(hash_);
115 return result.raw(); 117 return result.raw();
116 } 118 }
117 } 119 }
118 120
119 121
120 class ConcatString { 122 class ConcatString {
121 public: 123 public:
122 ConcatString(const String& str1, const String& str2) 124 ConcatString(const String& str1, const String& str2)
123 : str1_(str1), str2_(str2), hash_(String::HashConcat(str1, str2)) {} 125 : str1_(str1), str2_(str2), hash_(String::HashConcat(str1, str2)) {}
124 RawString* ToSymbol() const; 126 RawString* ToSymbol() const;
125 bool Equals(const String& other) const { 127 bool Equals(const String& other) const {
126 ASSERT(other.HasHash()); 128 ASSERT(other.HasHash());
127 if (other.Hash() != hash_) { 129 if (other.Hash() != hash_) {
128 return false; 130 return false;
129 } 131 }
130 return other.EqualsConcat(str1_, str2_); 132 return other.EqualsConcat(str1_, str2_);
131 } 133 }
132 intptr_t Hash() const { return hash_; } 134 intptr_t Hash() const { return hash_; }
135
133 private: 136 private:
134 const String& str1_; 137 const String& str1_;
135 const String& str2_; 138 const String& str2_;
136 intptr_t hash_; 139 intptr_t hash_;
137 }; 140 };
138 141
139 142
140 RawString* ConcatString::ToSymbol() const { 143 RawString* ConcatString::ToSymbol() const {
141 String& result = String::Handle(String::Concat(str1_, str2_, Heap::kOld)); 144 String& result = String::Handle(String::Concat(str1_, str2_, Heap::kOld));
142 result.SetCanonical(); 145 result.SetCanonical();
(...skipping 15 matching lines...) Expand all
158 if (a_str.Hash() != b_str.Hash()) { 161 if (a_str.Hash() != b_str.Hash()) {
159 return false; 162 return false;
160 } 163 }
161 intptr_t a_len = a_str.Length(); 164 intptr_t a_len = a_str.Length();
162 if (a_len != b_str.Length()) { 165 if (a_len != b_str.Length()) {
163 return false; 166 return false;
164 } 167 }
165 // Use a comparison which does not consider the state of the canonical bit. 168 // Use a comparison which does not consider the state of the canonical bit.
166 return a_str.Equals(b_str, 0, a_len); 169 return a_str.Equals(b_str, 0, a_len);
167 } 170 }
168 template<typename CharType> 171 template <typename CharType>
169 static bool IsMatch(const CharArray<CharType>& array, const Object& obj) { 172 static bool IsMatch(const CharArray<CharType>& array, const Object& obj) {
170 return array.Equals(String::Cast(obj)); 173 return array.Equals(String::Cast(obj));
171 } 174 }
172 static bool IsMatch(const StringSlice& slice, const Object& obj) { 175 static bool IsMatch(const StringSlice& slice, const Object& obj) {
173 return slice.Equals(String::Cast(obj)); 176 return slice.Equals(String::Cast(obj));
174 } 177 }
175 static bool IsMatch(const ConcatString& concat, const Object& obj) { 178 static bool IsMatch(const ConcatString& concat, const Object& obj) {
176 return concat.Equals(String::Cast(obj)); 179 return concat.Equals(String::Cast(obj));
177 } 180 }
178 static uword Hash(const Object& key) { 181 static uword Hash(const Object& key) { return String::Cast(key).Hash(); }
179 return String::Cast(key).Hash(); 182 template <typename CharType>
180 }
181 template<typename CharType>
182 static uword Hash(const CharArray<CharType>& array) { 183 static uword Hash(const CharArray<CharType>& array) {
183 return array.Hash(); 184 return array.Hash();
184 } 185 }
185 static uword Hash(const StringSlice& slice) { 186 static uword Hash(const StringSlice& slice) { return slice.Hash(); }
186 return slice.Hash(); 187 static uword Hash(const ConcatString& concat) { return concat.Hash(); }
187 } 188 template <typename CharType>
188 static uword Hash(const ConcatString& concat) {
189 return concat.Hash();
190 }
191 template<typename CharType>
192 static RawObject* NewKey(const CharArray<CharType>& array) { 189 static RawObject* NewKey(const CharArray<CharType>& array) {
193 return array.ToSymbol(); 190 return array.ToSymbol();
194 } 191 }
195 static RawObject* NewKey(const StringSlice& slice) { 192 static RawObject* NewKey(const StringSlice& slice) {
196 return slice.ToSymbol(); 193 return slice.ToSymbol();
197 } 194 }
198 static RawObject* NewKey(const ConcatString& concat) { 195 static RawObject* NewKey(const ConcatString& concat) {
199 return concat.ToSymbol(); 196 return concat.ToSymbol();
200 } 197 }
201 }; 198 };
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 } 300 }
304 301
305 vm_isolate->object_store()->set_symbol_table(table.Release()); 302 vm_isolate->object_store()->set_symbol_table(table.Release());
306 } 303 }
307 304
308 305
309 void Symbols::SetupSymbolTable(Isolate* isolate) { 306 void Symbols::SetupSymbolTable(Isolate* isolate) {
310 ASSERT(isolate != NULL); 307 ASSERT(isolate != NULL);
311 308
312 // Setup the symbol table used within the String class. 309 // Setup the symbol table used within the String class.
313 const intptr_t initial_size = (isolate == Dart::vm_isolate()) ? 310 const intptr_t initial_size = (isolate == Dart::vm_isolate())
314 kInitialVMIsolateSymtabSize : kInitialSymtabSize; 311 ? kInitialVMIsolateSymtabSize
312 : kInitialSymtabSize;
315 Array& array = 313 Array& array =
316 Array::Handle(HashTables::New<SymbolTable>(initial_size, Heap::kOld)); 314 Array::Handle(HashTables::New<SymbolTable>(initial_size, Heap::kOld));
317 isolate->object_store()->set_symbol_table(array); 315 isolate->object_store()->set_symbol_table(array);
318 } 316 }
319 317
320 318
321 RawArray* Symbols::UnifiedSymbolTable() { 319 RawArray* Symbols::UnifiedSymbolTable() {
322 Thread* thread = Thread::Current(); 320 Thread* thread = Thread::Current();
323 Isolate* isolate = thread->isolate(); 321 Isolate* isolate = thread->isolate();
324 Zone* zone = thread->zone(); 322 Zone* zone = thread->zone();
325 323
326 ASSERT(thread->IsMutatorThread()); 324 ASSERT(thread->IsMutatorThread());
327 ASSERT(isolate->background_compiler() == NULL); 325 ASSERT(isolate->background_compiler() == NULL);
328 326
329 SymbolTable vm_table(zone, 327 SymbolTable vm_table(zone,
330 Dart::vm_isolate()->object_store()->symbol_table()); 328 Dart::vm_isolate()->object_store()->symbol_table());
331 SymbolTable table(zone, isolate->object_store()->symbol_table()); 329 SymbolTable table(zone, isolate->object_store()->symbol_table());
332 intptr_t unified_size = vm_table.NumOccupied() + table.NumOccupied(); 330 intptr_t unified_size = vm_table.NumOccupied() + table.NumOccupied();
333 SymbolTable unified_table(zone, HashTables::New<SymbolTable>(unified_size, 331 SymbolTable unified_table(
334 Heap::kOld)); 332 zone, HashTables::New<SymbolTable>(unified_size, Heap::kOld));
335 String& symbol = String::Handle(zone); 333 String& symbol = String::Handle(zone);
336 334
337 SymbolTable::Iterator vm_iter(&vm_table); 335 SymbolTable::Iterator vm_iter(&vm_table);
338 while (vm_iter.MoveNext()) { 336 while (vm_iter.MoveNext()) {
339 symbol ^= vm_table.GetKey(vm_iter.Current()); 337 symbol ^= vm_table.GetKey(vm_iter.Current());
340 ASSERT(!symbol.IsNull()); 338 ASSERT(!symbol.IsNull());
341 bool present = unified_table.Insert(symbol); 339 bool present = unified_table.Insert(symbol);
342 ASSERT(!present); 340 ASSERT(!present);
343 } 341 }
344 vm_table.Release(); 342 vm_table.Release();
(...skipping 17 matching lines...) Expand all
362 Zone* zone = Thread::Current()->zone(); 360 Zone* zone = Thread::Current()->zone();
363 361
364 // 1. Drop the symbol table and do a full garbage collection. 362 // 1. Drop the symbol table and do a full garbage collection.
365 isolate->object_store()->set_symbol_table(Object::empty_array()); 363 isolate->object_store()->set_symbol_table(Object::empty_array());
366 isolate->heap()->CollectAllGarbage(); 364 isolate->heap()->CollectAllGarbage();
367 365
368 // 2. Walk the heap to find surviving symbols. 366 // 2. Walk the heap to find surviving symbols.
369 GrowableArray<String*> symbols; 367 GrowableArray<String*> symbols;
370 class SymbolCollector : public ObjectVisitor { 368 class SymbolCollector : public ObjectVisitor {
371 public: 369 public:
372 SymbolCollector(Thread* thread, 370 SymbolCollector(Thread* thread, GrowableArray<String*>* symbols)
373 GrowableArray<String*>* symbols) 371 : symbols_(symbols), zone_(thread->zone()) {}
374 : symbols_(symbols),
375 zone_(thread->zone()) {}
376 372
377 void VisitObject(RawObject* obj) { 373 void VisitObject(RawObject* obj) {
378 if (obj->IsCanonical() && obj->IsStringInstance()) { 374 if (obj->IsCanonical() && obj->IsStringInstance()) {
379 symbols_->Add(&String::ZoneHandle(zone_, String::RawCast(obj))); 375 symbols_->Add(&String::ZoneHandle(zone_, String::RawCast(obj)));
380 } 376 }
381 } 377 }
382 378
383 private: 379 private:
384 GrowableArray<String*>* symbols_; 380 GrowableArray<String*>* symbols_;
385 Zone* zone_; 381 Zone* zone_;
386 }; 382 };
387 383
388 SymbolCollector visitor(Thread::Current(), &symbols); 384 SymbolCollector visitor(Thread::Current(), &symbols);
389 isolate->heap()->IterateObjects(&visitor); 385 isolate->heap()->IterateObjects(&visitor);
390 386
391 // 3. Build a new table from the surviving symbols. 387 // 3. Build a new table from the surviving symbols.
392 Array& array = 388 Array& array = Array::Handle(
393 Array::Handle(zone, HashTables::New<SymbolTable>(symbols.length() * 4 / 3, 389 zone, HashTables::New<SymbolTable>(symbols.length() * 4 / 3, Heap::kOld));
394 Heap::kOld));
395 SymbolTable table(zone, array.raw()); 390 SymbolTable table(zone, array.raw());
396 for (intptr_t i = 0; i < symbols.length(); i++) { 391 for (intptr_t i = 0; i < symbols.length(); i++) {
397 String& symbol = *symbols[i]; 392 String& symbol = *symbols[i];
398 ASSERT(symbol.IsString()); 393 ASSERT(symbol.IsString());
399 ASSERT(symbol.IsCanonical()); 394 ASSERT(symbol.IsCanonical());
400 bool present = table.Insert(symbol); 395 bool present = table.Insert(symbol);
401 ASSERT(!present); 396 ASSERT(!present);
402 } 397 }
403 isolate->object_store()->set_symbol_table(table.Release()); 398 isolate->object_store()->set_symbol_table(table.Release());
404 } 399 }
405 #endif // DART_PRECOMPILER 400 #endif // DART_PRECOMPILER
406 401
407 402
408 void Symbols::GetStats(Isolate* isolate, intptr_t* size, intptr_t* capacity) { 403 void Symbols::GetStats(Isolate* isolate, intptr_t* size, intptr_t* capacity) {
409 ASSERT(isolate != NULL); 404 ASSERT(isolate != NULL);
410 SymbolTable table(isolate->object_store()->symbol_table()); 405 SymbolTable table(isolate->object_store()->symbol_table());
411 *size = table.NumOccupied(); 406 *size = table.NumOccupied();
412 *capacity = table.NumEntries(); 407 *capacity = table.NumEntries();
413 table.Release(); 408 table.Release();
414 } 409 }
415 410
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 483
489 484
490 RawString* Symbols::FromDot(Thread* thread, const String& str) { 485 RawString* Symbols::FromDot(Thread* thread, const String& str) {
491 return FromConcat(thread, str, Dot()); 486 return FromConcat(thread, str, Dot());
492 } 487 }
493 488
494 489
495 // TODO(srdjan): If this becomes performance critical code, consider looking 490 // TODO(srdjan): If this becomes performance critical code, consider looking
496 // up symbol from hash of pieces instead of concatenating them first into 491 // up symbol from hash of pieces instead of concatenating them first into
497 // a string. 492 // a string.
498 RawString* Symbols::FromConcatAll(Thread* thread, 493 RawString* Symbols::FromConcatAll(
494 Thread* thread,
499 const GrowableHandlePtrArray<const String>& strs) { 495 const GrowableHandlePtrArray<const String>& strs) {
500 const intptr_t strs_length = strs.length(); 496 const intptr_t strs_length = strs.length();
501 GrowableArray<intptr_t> lengths(strs_length); 497 GrowableArray<intptr_t> lengths(strs_length);
502 498
503 intptr_t len_sum = 0; 499 intptr_t len_sum = 0;
504 const intptr_t kOneByteChar = 1; 500 const intptr_t kOneByteChar = 1;
505 intptr_t char_size = kOneByteChar; 501 intptr_t char_size = kOneByteChar;
506 502
507 for (intptr_t i = 0; i < strs_length; i++) { 503 for (intptr_t i = 0; i < strs_length; i++) {
508 const String& str = strs[i]; 504 const String& str = strs[i];
(...skipping 11 matching lines...) Expand all
520 Zone* zone = thread->zone(); 516 Zone* zone = thread->zone();
521 if (is_one_byte_string) { 517 if (is_one_byte_string) {
522 uint8_t* buffer = zone->Alloc<uint8_t>(len_sum); 518 uint8_t* buffer = zone->Alloc<uint8_t>(len_sum);
523 const uint8_t* const orig_buffer = buffer; 519 const uint8_t* const orig_buffer = buffer;
524 for (intptr_t i = 0; i < strs_length; i++) { 520 for (intptr_t i = 0; i < strs_length; i++) {
525 NoSafepointScope no_safepoint; 521 NoSafepointScope no_safepoint;
526 intptr_t str_len = lengths[i]; 522 intptr_t str_len = lengths[i];
527 if (str_len > 0) { 523 if (str_len > 0) {
528 const String& str = strs[i]; 524 const String& str = strs[i];
529 ASSERT(str.IsOneByteString() || str.IsExternalOneByteString()); 525 ASSERT(str.IsOneByteString() || str.IsExternalOneByteString());
530 const uint8_t* src_p = str.IsOneByteString() ? 526 const uint8_t* src_p = str.IsOneByteString()
531 OneByteString::CharAddr(str, 0) : 527 ? OneByteString::CharAddr(str, 0)
532 ExternalOneByteString::CharAddr(str, 0); 528 : ExternalOneByteString::CharAddr(str, 0);
533 memmove(buffer, src_p, str_len); 529 memmove(buffer, src_p, str_len);
534 buffer += str_len; 530 buffer += str_len;
535 } 531 }
536 } 532 }
537 ASSERT(len_sum == buffer - orig_buffer); 533 ASSERT(len_sum == buffer - orig_buffer);
538 return Symbols::FromLatin1(thread, orig_buffer, len_sum); 534 return Symbols::FromLatin1(thread, orig_buffer, len_sum);
539 } else { 535 } else {
540 uint16_t* buffer = zone->Alloc<uint16_t>(len_sum); 536 uint16_t* buffer = zone->Alloc<uint16_t>(len_sum);
541 const uint16_t* const orig_buffer = buffer; 537 const uint16_t* const orig_buffer = buffer;
542 for (intptr_t i = 0; i < strs_length; i++) { 538 for (intptr_t i = 0; i < strs_length; i++) {
543 NoSafepointScope no_safepoint; 539 NoSafepointScope no_safepoint;
544 intptr_t str_len = lengths[i]; 540 intptr_t str_len = lengths[i];
545 if (str_len > 0) { 541 if (str_len > 0) {
546 const String& str = strs[i]; 542 const String& str = strs[i];
547 if (str.IsTwoByteString()) { 543 if (str.IsTwoByteString()) {
548 memmove(buffer, TwoByteString::CharAddr(str, 0), str_len * 2); 544 memmove(buffer, TwoByteString::CharAddr(str, 0), str_len * 2);
549 } else if (str.IsExternalTwoByteString()) { 545 } else if (str.IsExternalTwoByteString()) {
550 memmove(buffer, ExternalTwoByteString::CharAddr(str, 0), str_len * 2); 546 memmove(buffer, ExternalTwoByteString::CharAddr(str, 0), str_len * 2);
551 } else { 547 } else {
552 // One-byte to two-byte string copy. 548 // One-byte to two-byte string copy.
553 ASSERT(str.IsOneByteString() || str.IsExternalOneByteString()); 549 ASSERT(str.IsOneByteString() || str.IsExternalOneByteString());
554 const uint8_t* src_p = str.IsOneByteString() ? 550 const uint8_t* src_p = str.IsOneByteString()
555 OneByteString::CharAddr(str, 0) : 551 ? OneByteString::CharAddr(str, 0)
556 ExternalOneByteString::CharAddr(str, 0); 552 : ExternalOneByteString::CharAddr(str, 0);
557 for (int n = 0; n < str_len; n++) { 553 for (int n = 0; n < str_len; n++) {
558 buffer[n] = src_p[n]; 554 buffer[n] = src_p[n];
559 } 555 }
560 } 556 }
561 buffer += str_len; 557 buffer += str_len;
562 } 558 }
563 } 559 }
564 ASSERT(len_sum == buffer - orig_buffer); 560 ASSERT(len_sum == buffer - orig_buffer);
565 return Symbols::FromUTF16(thread, orig_buffer, len_sum); 561 return Symbols::FromUTF16(thread, orig_buffer, len_sum);
566 } 562 }
567 } 563 }
568 564
569 565
570 // StringType can be StringSlice, ConcatString, or {Latin1,UTF16,UTF32}Array. 566 // StringType can be StringSlice, ConcatString, or {Latin1,UTF16,UTF32}Array.
571 template<typename StringType> 567 template <typename StringType>
572 RawString* Symbols::NewSymbol(Thread* thread, const StringType& str) { 568 RawString* Symbols::NewSymbol(Thread* thread, const StringType& str) {
573 REUSABLE_OBJECT_HANDLESCOPE(thread); 569 REUSABLE_OBJECT_HANDLESCOPE(thread);
574 REUSABLE_SMI_HANDLESCOPE(thread); 570 REUSABLE_SMI_HANDLESCOPE(thread);
575 REUSABLE_ARRAY_HANDLESCOPE(thread); 571 REUSABLE_ARRAY_HANDLESCOPE(thread);
576 String& symbol = String::Handle(thread->zone()); 572 String& symbol = String::Handle(thread->zone());
577 dart::Object& key = thread->ObjectHandle(); 573 dart::Object& key = thread->ObjectHandle();
578 Smi& value = thread->SmiHandle(); 574 Smi& value = thread->SmiHandle();
579 Array& data = thread->ArrayHandle(); 575 Array& data = thread->ArrayHandle();
580 { 576 {
581 Isolate* vm_isolate = Dart::vm_isolate(); 577 Isolate* vm_isolate = Dart::vm_isolate();
582 data ^= vm_isolate->object_store()->symbol_table(); 578 data ^= vm_isolate->object_store()->symbol_table();
583 SymbolTable table(&key, &value, &data); 579 SymbolTable table(&key, &value, &data);
584 symbol ^= table.GetOrNull(str); 580 symbol ^= table.GetOrNull(str);
585 table.Release(); 581 table.Release();
586 } 582 }
587 if (symbol.IsNull()) { 583 if (symbol.IsNull()) {
588 Isolate* isolate = thread->isolate(); 584 Isolate* isolate = thread->isolate();
589 SafepointMutexLocker ml(isolate->symbols_mutex()); 585 SafepointMutexLocker ml(isolate->symbols_mutex());
590 data ^= isolate->object_store()->symbol_table(); 586 data ^= isolate->object_store()->symbol_table();
591 SymbolTable table(&key, &value, &data); 587 SymbolTable table(&key, &value, &data);
592 symbol ^= table.InsertNewOrGet(str); 588 symbol ^= table.InsertNewOrGet(str);
593 isolate->object_store()->set_symbol_table(table.Release()); 589 isolate->object_store()->set_symbol_table(table.Release());
594 } 590 }
595 ASSERT(symbol.IsSymbol()); 591 ASSERT(symbol.IsSymbol());
596 ASSERT(symbol.HasHash()); 592 ASSERT(symbol.HasHash());
597 return symbol.raw(); 593 return symbol.raw();
598 } 594 }
599 595
600 596
601 template<typename StringType> 597 template <typename StringType>
602 RawString* Symbols::Lookup(Thread* thread, const StringType& str) { 598 RawString* Symbols::Lookup(Thread* thread, const StringType& str) {
603 REUSABLE_OBJECT_HANDLESCOPE(thread); 599 REUSABLE_OBJECT_HANDLESCOPE(thread);
604 REUSABLE_SMI_HANDLESCOPE(thread); 600 REUSABLE_SMI_HANDLESCOPE(thread);
605 REUSABLE_ARRAY_HANDLESCOPE(thread); 601 REUSABLE_ARRAY_HANDLESCOPE(thread);
606 String& symbol = String::Handle(thread->zone()); 602 String& symbol = String::Handle(thread->zone());
607 dart::Object& key = thread->ObjectHandle(); 603 dart::Object& key = thread->ObjectHandle();
608 Smi& value = thread->SmiHandle(); 604 Smi& value = thread->SmiHandle();
609 Array& data = thread->ArrayHandle(); 605 Array& data = thread->ArrayHandle();
610 { 606 {
611 Isolate* vm_isolate = Dart::vm_isolate(); 607 Isolate* vm_isolate = Dart::vm_isolate();
612 data ^= vm_isolate->object_store()->symbol_table(); 608 data ^= vm_isolate->object_store()->symbol_table();
613 SymbolTable table(&key, &value, &data); 609 SymbolTable table(&key, &value, &data);
614 symbol ^= table.GetOrNull(str); 610 symbol ^= table.GetOrNull(str);
615 table.Release(); 611 table.Release();
616 } 612 }
617 if (symbol.IsNull()) { 613 if (symbol.IsNull()) {
618 Isolate* isolate = thread->isolate(); 614 Isolate* isolate = thread->isolate();
619 SafepointMutexLocker ml(isolate->symbols_mutex()); 615 SafepointMutexLocker ml(isolate->symbols_mutex());
620 data ^= isolate->object_store()->symbol_table(); 616 data ^= isolate->object_store()->symbol_table();
621 SymbolTable table(&key, &value, &data); 617 SymbolTable table(&key, &value, &data);
622 symbol ^= table.GetOrNull(str); 618 symbol ^= table.GetOrNull(str);
623 table.Release(); 619 table.Release();
624 } 620 }
625 ASSERT(symbol.IsNull() || symbol.IsSymbol()); 621 ASSERT(symbol.IsNull() || symbol.IsSymbol());
626 ASSERT(symbol.IsNull() || symbol.HasHash()); 622 ASSERT(symbol.IsNull() || symbol.HasHash());
627 return symbol.raw(); 623 return symbol.raw();
628 } 624 }
629 625
630 626
631 RawString* Symbols::LookupFromConcat( 627 RawString* Symbols::LookupFromConcat(Thread* thread,
632 Thread* thread, const String& str1, const String& str2) { 628 const String& str1,
629 const String& str2) {
633 if (str1.Length() == 0) { 630 if (str1.Length() == 0) {
634 return Lookup(thread, str2); 631 return Lookup(thread, str2);
635 } else if (str2.Length() == 0) { 632 } else if (str2.Length() == 0) {
636 return Lookup(thread, str1); 633 return Lookup(thread, str1);
637 } else { 634 } else {
638 return Lookup(thread, ConcatString(str1, str2)); 635 return Lookup(thread, ConcatString(str1, str2));
639 } 636 }
640 } 637 }
641 638
642 639
(...skipping 21 matching lines...) Expand all
664 661
665 662
666 RawString* Symbols::New(Thread* thread, 663 RawString* Symbols::New(Thread* thread,
667 const String& str, 664 const String& str,
668 intptr_t begin_index, 665 intptr_t begin_index,
669 intptr_t len) { 666 intptr_t len) {
670 return NewSymbol(thread, StringSlice(str, begin_index, len)); 667 return NewSymbol(thread, StringSlice(str, begin_index, len));
671 } 668 }
672 669
673 670
674
675 RawString* Symbols::NewFormatted(Thread* thread, const char* format, ...) { 671 RawString* Symbols::NewFormatted(Thread* thread, const char* format, ...) {
676 va_list args; 672 va_list args;
677 va_start(args, format); 673 va_start(args, format);
678 RawString* result = NewFormattedV(thread, format, args); 674 RawString* result = NewFormattedV(thread, format, args);
679 NoSafepointScope no_safepoint; 675 NoSafepointScope no_safepoint;
680 va_end(args); 676 va_end(args);
681 return result; 677 return result;
682 } 678 }
683 679
684 680
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
737 RawObject* Symbols::GetPredefinedSymbol(intptr_t object_id) { 733 RawObject* Symbols::GetPredefinedSymbol(intptr_t object_id) {
738 ASSERT(IsPredefinedSymbolId(object_id)); 734 ASSERT(IsPredefinedSymbolId(object_id));
739 intptr_t i = (object_id - kMaxPredefinedObjectIds); 735 intptr_t i = (object_id - kMaxPredefinedObjectIds);
740 if ((i > kIllegal) && (i < Symbols::kMaxPredefinedId)) { 736 if ((i > kIllegal) && (i < Symbols::kMaxPredefinedId)) {
741 return symbol_handles_[i]->raw(); 737 return symbol_handles_[i]->raw();
742 } 738 }
743 return Object::null(); 739 return Object::null();
744 } 740 }
745 741
746 } // namespace dart 742 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/symbols.h ('k') | runtime/vm/tags.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698