| 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" |
| 8 #include "vm/handles_impl.h" |
| 7 #include "vm/isolate.h" | 9 #include "vm/isolate.h" |
| 8 #include "vm/object.h" | 10 #include "vm/object.h" |
| 9 #include "vm/object_store.h" | 11 #include "vm/object_store.h" |
| 10 #include "vm/raw_object.h" | 12 #include "vm/raw_object.h" |
| 11 #include "vm/snapshot_ids.h" | 13 #include "vm/snapshot_ids.h" |
| 12 #include "vm/unicode.h" | 14 #include "vm/unicode.h" |
| 13 #include "vm/visitor.h" | 15 #include "vm/visitor.h" |
| 14 | 16 |
| 15 namespace dart { | 17 namespace dart { |
| 16 | 18 |
| 17 RawString* Symbols::predefined_[Symbols::kMaxId]; | 19 RawString* Symbols::predefined_[Symbols::kMaxId]; |
| 20 VMHandles Symbols::predefined_handles_; |
| 21 |
| 22 #define DEFINE_SYMBOL_HANDLE(symbol) \ |
| 23 String* Symbols::symbol##_handle_ = NULL; |
| 24 PREDEFINED_SYMBOL_HANDLES_LIST(DEFINE_SYMBOL_HANDLE) |
| 25 #undef DEFINE_SYMBOL_HANDLE |
| 18 | 26 |
| 19 static const char* names[] = { | 27 static const char* names[] = { |
| 20 NULL, | 28 NULL, |
| 21 | 29 |
| 22 #define DEFINE_SYMBOL_LITERAL(symbol, literal) \ | 30 #define DEFINE_SYMBOL_LITERAL(symbol, literal) \ |
| 23 literal, | 31 literal, |
| 24 PREDEFINED_SYMBOLS_LIST(DEFINE_SYMBOL_LITERAL) | 32 PREDEFINED_SYMBOLS_LIST(DEFINE_SYMBOL_LITERAL) |
| 25 #undef DEFINE_SYMBOL_LITERAL | 33 #undef DEFINE_SYMBOL_LITERAL |
| 26 }; | 34 }; |
| 27 | 35 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 52 str = OneByteString::New(names[i], Heap::kOld); | 60 str = OneByteString::New(names[i], Heap::kOld); |
| 53 Add(symbol_table, str); | 61 Add(symbol_table, str); |
| 54 predefined_[i] = str.raw(); | 62 predefined_[i] = str.raw(); |
| 55 } | 63 } |
| 56 Object::RegisterSingletonClassNames(); | 64 Object::RegisterSingletonClassNames(); |
| 57 | 65 |
| 58 for (int32_t c = 0; c <= kMaxOneCharCodeSymbol; c++) { | 66 for (int32_t c = 0; c <= kMaxOneCharCodeSymbol; c++) { |
| 59 ASSERT(kMaxPredefinedId + c < kMaxId); | 67 ASSERT(kMaxPredefinedId + c < kMaxId); |
| 60 predefined_[kMaxPredefinedId + c] = FromUTF32(&c, 1); | 68 predefined_[kMaxPredefinedId + c] = FromUTF32(&c, 1); |
| 61 } | 69 } |
| 70 |
| 71 #define INITIALIZE_SYMBOL_HANDLE(symbol) \ |
| 72 symbol##_handle_ = reinterpret_cast<String*>( \ |
| 73 predefined_handles_.AllocateScopedHandle()); \ |
| 74 *symbol##_handle_ = symbol(); |
| 75 PREDEFINED_SYMBOL_HANDLES_LIST(INITIALIZE_SYMBOL_HANDLE) |
| 76 #undef INITIALIZE_SYMBOL_HANDLE |
| 62 } | 77 } |
| 63 | 78 |
| 64 | 79 |
| 65 void Symbols::SetupSymbolTable(Isolate* isolate) { | 80 void Symbols::SetupSymbolTable(Isolate* isolate) { |
| 66 ASSERT(isolate != NULL); | 81 ASSERT(isolate != NULL); |
| 67 | 82 |
| 68 // Setup the symbol table used within the String class. | 83 // Setup the symbol table used within the String class. |
| 69 const int initial_size = (isolate == Dart::vm_isolate()) ? | 84 const int initial_size = (isolate == Dart::vm_isolate()) ? |
| 70 kInitialVMIsolateSymtabSize : kInitialSymtabSize; | 85 kInitialVMIsolateSymtabSize : kInitialSymtabSize; |
| 71 const Array& array = Array::Handle(Array::New(initial_size + 1)); | 86 const Array& array = Array::Handle(Array::New(initial_size + 1)); |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 } | 374 } |
| 360 | 375 |
| 361 | 376 |
| 362 RawObject* Symbols::GetVMSymbol(intptr_t object_id) { | 377 RawObject* Symbols::GetVMSymbol(intptr_t object_id) { |
| 363 ASSERT(IsVMSymbolId(object_id)); | 378 ASSERT(IsVMSymbolId(object_id)); |
| 364 intptr_t i = (object_id - kMaxPredefinedObjectIds); | 379 intptr_t i = (object_id - kMaxPredefinedObjectIds); |
| 365 return (i > 0 && i < Symbols::kMaxId) ? predefined_[i] : Object::null(); | 380 return (i > 0 && i < Symbols::kMaxId) ? predefined_[i] : Object::null(); |
| 366 } | 381 } |
| 367 | 382 |
| 368 } // namespace dart | 383 } // namespace dart |
| OLD | NEW |