| 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/isolate.h" | 7 #include "vm/isolate.h" |
| 8 #include "vm/object.h" | 8 #include "vm/object.h" |
| 9 #include "vm/object_store.h" | 9 #include "vm/object_store.h" |
| 10 #include "vm/raw_object.h" | 10 #include "vm/raw_object.h" |
| 11 #include "vm/snapshot_ids.h" | 11 #include "vm/snapshot_ids.h" |
| 12 #include "vm/unicode.h" | 12 #include "vm/unicode.h" |
| 13 #include "vm/visitor.h" | 13 #include "vm/visitor.h" |
| 14 | 14 |
| 15 namespace dart { | 15 namespace dart { |
| 16 | 16 |
| 17 RawString* Symbols::predefined_[Symbols::kMaxId]; | 17 RawString* Symbols::predefined_[Symbols::kMaxId]; |
| 18 | 18 |
| 19 // Turn off population of symbols in the VM symbol table, so that we | |
| 20 // don't find these symbols while doing a Symbols::New(...). | |
| 21 static const char* names[] = { | 19 static const char* names[] = { |
| 22 NULL, | 20 NULL, |
| 23 | 21 |
| 24 #define DEFINE_SYMBOL_LITERAL(symbol, literal) \ | 22 #define DEFINE_SYMBOL_LITERAL(symbol, literal) \ |
| 25 literal, | 23 literal, |
| 26 PREDEFINED_SYMBOLS_LIST(DEFINE_SYMBOL_LITERAL) | 24 PREDEFINED_SYMBOLS_LIST(DEFINE_SYMBOL_LITERAL) |
| 27 #undef DEFINE_SYMBOL_LITERAL | 25 #undef DEFINE_SYMBOL_LITERAL |
| 28 }; | 26 }; |
| 29 | 27 |
| 30 | 28 |
| 31 const char* Symbols::Name(intptr_t symbol) { | 29 const char* Symbols::Name(intptr_t symbol) { |
| 32 ASSERT((symbol > kIllegal) && (symbol < kMaxId)); | 30 ASSERT((symbol > kIllegal) && (symbol < kMaxId)); |
| 33 return names[symbol]; | 31 return names[symbol]; |
| 34 } | 32 } |
| 35 | 33 |
| 36 | 34 |
| 37 void Symbols::InitOnce(Isolate* isolate) { | 35 void Symbols::InitOnce(Isolate* isolate) { |
| 38 // Should only be run by the vm isolate. | 36 // Should only be run by the vm isolate. |
| 39 ASSERT(isolate == Dart::vm_isolate()); | 37 ASSERT(isolate == Dart::vm_isolate()); |
| 40 | 38 |
| 41 // Create and setup a symbol table in the vm isolate. | 39 // Create and setup a symbol table in the vm isolate. |
| 42 SetupSymbolTable(isolate); | 40 SetupSymbolTable(isolate); |
| 43 | 41 |
| 44 // Turn off population of symbols in the VM symbol table, so that we | |
| 45 // don't find these symbols while doing a Symbols::New(...). | |
| 46 // Create all predefined symbols. | 42 // Create all predefined symbols. |
| 47 ASSERT((sizeof(names) / sizeof(const char*)) == Symbols::kMaxId); | 43 ASSERT((sizeof(names) / sizeof(const char*)) == Symbols::kMaxId); |
| 48 const Array& symbol_table = | 44 ObjectStore* object_store = isolate->object_store(); |
| 49 Array::Handle(isolate->object_store()->symbol_table()); | 45 Array& symbol_table = Array::Handle(); |
| 50 dart::String& str = String::Handle(); | 46 dart::String& str = String::Handle(); |
| 51 | 47 |
| 52 for (intptr_t i = 1; i < Symbols::kMaxId; i++) { | 48 for (intptr_t i = 1; i < Symbols::kMaxId; i++) { |
| 49 // The symbol_table needs to be reloaded as it might have grown in the |
| 50 // previous iteration. |
| 51 symbol_table = object_store->symbol_table(); |
| 53 str = OneByteString::New(names[i], Heap::kOld); | 52 str = OneByteString::New(names[i], Heap::kOld); |
| 54 Add(symbol_table, str); | 53 Add(symbol_table, str); |
| 55 predefined_[i] = str.raw(); | 54 predefined_[i] = str.raw(); |
| 56 } | 55 } |
| 57 Object::RegisterSingletonClassNames(); | 56 Object::RegisterSingletonClassNames(); |
| 58 } | 57 } |
| 59 | 58 |
| 60 | 59 |
| 61 void Symbols::SetupSymbolTable(Isolate* isolate) { | 60 void Symbols::SetupSymbolTable(Isolate* isolate) { |
| 62 ASSERT(isolate != NULL); | 61 ASSERT(isolate != NULL); |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 } | 311 } |
| 313 | 312 |
| 314 | 313 |
| 315 RawObject* Symbols::GetVMSymbol(intptr_t object_id) { | 314 RawObject* Symbols::GetVMSymbol(intptr_t object_id) { |
| 316 ASSERT(IsVMSymbolId(object_id)); | 315 ASSERT(IsVMSymbolId(object_id)); |
| 317 intptr_t i = (object_id - kMaxPredefinedObjectIds); | 316 intptr_t i = (object_id - kMaxPredefinedObjectIds); |
| 318 return (i > 0 && i < Symbols::kMaxId) ? predefined_[i] : Object::null(); | 317 return (i > 0 && i < Symbols::kMaxId) ? predefined_[i] : Object::null(); |
| 319 } | 318 } |
| 320 | 319 |
| 321 } // namespace dart | 320 } // namespace dart |
| OLD | NEW |