| OLD | NEW |
| 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/handles_impl.h" | 8 #include "vm/handles_impl.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/snapshot_ids.h" | 13 #include "vm/snapshot_ids.h" |
| 14 #include "vm/unicode.h" | 14 #include "vm/unicode.h" |
| 15 #include "vm/visitor.h" | 15 #include "vm/visitor.h" |
| 16 | 16 |
| 17 namespace dart { | 17 namespace dart { |
| 18 | 18 |
| 19 RawString* Symbols::predefined_[Symbols::kMaxId]; | 19 RawString* Symbols::predefined_[Symbols::kMaxId]; |
| 20 VMHandles Symbols::predefined_handles_; | 20 |
| 21 Symbols::ReadOnlyHandles* Symbols::predefined_handles_ = NULL; |
| 21 | 22 |
| 22 #define DEFINE_SYMBOL_HANDLE(symbol) \ | 23 #define DEFINE_SYMBOL_HANDLE(symbol) \ |
| 23 String* Symbols::symbol##_handle_ = NULL; | 24 String* Symbols::symbol##_handle_ = NULL; |
| 24 PREDEFINED_SYMBOL_HANDLES_LIST(DEFINE_SYMBOL_HANDLE) | 25 PREDEFINED_SYMBOL_HANDLES_LIST(DEFINE_SYMBOL_HANDLE) |
| 25 #undef DEFINE_SYMBOL_HANDLE | 26 #undef DEFINE_SYMBOL_HANDLE |
| 26 | 27 |
| 27 static const char* names[] = { | 28 static const char* names[] = { |
| 28 NULL, | 29 NULL, |
| 29 | 30 |
| 30 #define DEFINE_SYMBOL_LITERAL(symbol, literal) \ | 31 #define DEFINE_SYMBOL_LITERAL(symbol, literal) \ |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 Add(symbol_table, str); | 74 Add(symbol_table, str); |
| 74 predefined_[i] = str.raw(); | 75 predefined_[i] = str.raw(); |
| 75 } | 76 } |
| 76 Object::RegisterSingletonClassNames(); | 77 Object::RegisterSingletonClassNames(); |
| 77 | 78 |
| 78 for (int32_t c = 0; c <= kMaxOneCharCodeSymbol; c++) { | 79 for (int32_t c = 0; c <= kMaxOneCharCodeSymbol; c++) { |
| 79 ASSERT(kMaxPredefinedId + c < kMaxId); | 80 ASSERT(kMaxPredefinedId + c < kMaxId); |
| 80 predefined_[kMaxPredefinedId + c] = FromUTF32(&c, 1); | 81 predefined_[kMaxPredefinedId + c] = FromUTF32(&c, 1); |
| 81 } | 82 } |
| 82 | 83 |
| 84 predefined_handles_ = new ReadOnlyHandles(); |
| 83 #define INITIALIZE_SYMBOL_HANDLE(symbol) \ | 85 #define INITIALIZE_SYMBOL_HANDLE(symbol) \ |
| 84 symbol##_handle_ = reinterpret_cast<String*>( \ | 86 symbol##_handle_ = reinterpret_cast<String*>( \ |
| 85 predefined_handles_.AllocateScopedHandle()); \ | 87 predefined_handles_->AllocateHandle()); \ |
| 86 *symbol##_handle_ = symbol(); | 88 *symbol##_handle_ = symbol(); |
| 87 PREDEFINED_SYMBOL_HANDLES_LIST(INITIALIZE_SYMBOL_HANDLE) | 89 PREDEFINED_SYMBOL_HANDLES_LIST(INITIALIZE_SYMBOL_HANDLE) |
| 88 #undef INITIALIZE_SYMBOL_HANDLE | 90 #undef INITIALIZE_SYMBOL_HANDLE |
| 89 } | 91 } |
| 90 | 92 |
| 91 | 93 |
| 92 void Symbols::SetupSymbolTable(Isolate* isolate) { | 94 void Symbols::SetupSymbolTable(Isolate* isolate) { |
| 93 ASSERT(isolate != NULL); | 95 ASSERT(isolate != NULL); |
| 94 | 96 |
| 95 // Setup the symbol table used within the String class. | 97 // Setup the symbol table used within the String class. |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 | 271 |
| 270 RawString* Symbols::FromCharCode(int32_t char_code) { | 272 RawString* Symbols::FromCharCode(int32_t char_code) { |
| 271 if (char_code > kMaxOneCharCodeSymbol) { | 273 if (char_code > kMaxOneCharCodeSymbol) { |
| 272 return FromUTF32(&char_code, 1); | 274 return FromUTF32(&char_code, 1); |
| 273 } | 275 } |
| 274 return predefined_[kNullCharId + char_code]; | 276 return predefined_[kNullCharId + char_code]; |
| 275 } | 277 } |
| 276 | 278 |
| 277 | 279 |
| 278 bool Symbols::IsPredefinedHandle(uword address) { | 280 bool Symbols::IsPredefinedHandle(uword address) { |
| 279 return predefined_handles_.IsValidScopedHandle(address); | 281 return predefined_handles_->IsValidHandle(address); |
| 280 } | 282 } |
| 281 | 283 |
| 282 | 284 |
| 283 void Symbols::DumpStats() { | 285 void Symbols::DumpStats() { |
| 284 if (FLAG_dump_symbol_stats) { | 286 if (FLAG_dump_symbol_stats) { |
| 285 intptr_t table_size = 0; | 287 intptr_t table_size = 0; |
| 286 dart::Smi& used = Smi::Handle(); | 288 dart::Smi& used = Smi::Handle(); |
| 287 Array& symbol_table = Array::Handle(Array::null()); | 289 Array& symbol_table = Array::Handle(Array::null()); |
| 288 | 290 |
| 289 // First dump VM symbol table stats. | 291 // First dump VM symbol table stats. |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 } | 450 } |
| 449 | 451 |
| 450 | 452 |
| 451 RawObject* Symbols::GetVMSymbol(intptr_t object_id) { | 453 RawObject* Symbols::GetVMSymbol(intptr_t object_id) { |
| 452 ASSERT(IsVMSymbolId(object_id)); | 454 ASSERT(IsVMSymbolId(object_id)); |
| 453 intptr_t i = (object_id - kMaxPredefinedObjectIds); | 455 intptr_t i = (object_id - kMaxPredefinedObjectIds); |
| 454 return (i > 0 && i < Symbols::kMaxId) ? predefined_[i] : Object::null(); | 456 return (i > 0 && i < Symbols::kMaxId) ? predefined_[i] : Object::null(); |
| 455 } | 457 } |
| 456 | 458 |
| 457 } // namespace dart | 459 } // namespace dart |
| OLD | NEW |