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/unicode.h" | 11 #include "vm/unicode.h" |
12 #include "vm/visitor.h" | 12 #include "vm/visitor.h" |
13 | 13 |
14 namespace dart { | 14 namespace dart { |
15 | 15 |
16 RawString* Symbols::predefined_[Symbols::kMaxPredefined]; | 16 RawString* Symbols::predefined_[Symbols::kMaxPredefined]; |
17 | 17 |
18 // Turn off population of symbols in the VM symbol table, so that we | 18 // Turn off population of symbols in the VM symbol table, so that we |
19 // don't find these symbols while doing a Symbols::New(...). | 19 // don't find these symbols while doing a Symbols::New(...). |
20 #if 0 | |
21 static const char* names[] = { | 20 static const char* names[] = { |
22 NULL, | 21 NULL, |
23 | 22 |
24 #define DEFINE_SYMBOL_LITERAL(symbol, literal) \ | 23 #define DEFINE_SYMBOL_LITERAL(symbol, literal) \ |
25 literal, | 24 literal, |
26 PREDEFINED_SYMBOLS_LIST(DEFINE_SYMBOL_LITERAL) | 25 PREDEFINED_SYMBOLS_LIST(DEFINE_SYMBOL_LITERAL) |
27 #undef DEFINE_SYMBOL_LITERAL | 26 #undef DEFINE_SYMBOL_LITERAL |
28 }; | 27 }; |
29 #endif | |
30 | 28 |
31 | 29 |
32 void Symbols::InitOnce(Isolate* isolate) { | 30 void Symbols::InitOnce(Isolate* isolate) { |
33 // Should only be run by the vm isolate. | 31 // Should only be run by the vm isolate. |
34 ASSERT(isolate == Dart::vm_isolate()); | 32 ASSERT(isolate == Dart::vm_isolate()); |
35 | 33 |
36 // Create and setup a symbol table in the vm isolate. | 34 // Create and setup a symbol table in the vm isolate. |
37 SetupSymbolTable(isolate); | 35 SetupSymbolTable(isolate); |
38 | 36 |
39 // Turn off population of symbols in the VM symbol table, so that we | 37 // Turn off population of symbols in the VM symbol table, so that we |
40 // don't find these symbols while doing a Symbols::New(...). | 38 // don't find these symbols while doing a Symbols::New(...). |
41 #if 0 | |
42 // Create all predefined symbols. | 39 // Create all predefined symbols. |
43 ASSERT((sizeof(names) / sizeof(const char*)) == kMaxPredefined); | 40 ASSERT((sizeof(names) / sizeof(const char*)) == kMaxPredefined); |
44 const Array& symbol_table = | 41 const Array& symbol_table = |
45 Array::Handle(isolate->object_store()->symbol_table()); | 42 Array::Handle(isolate->object_store()->symbol_table()); |
46 OneByteString& str = OneByteString::Handle(); | 43 OneByteString& str = OneByteString::Handle(); |
47 | 44 |
48 for (intptr_t i = 1; i < kMaxPredefined; i++) { | 45 for (intptr_t i = 1; i < kMaxPredefined; i++) { |
49 str = OneByteString::New(names[i], Heap::kOld); | 46 str = OneByteString::New(names[i], Heap::kOld); |
50 Add(symbol_table, str); | 47 Add(symbol_table, str); |
51 predefined_[i] = str.raw(); | 48 predefined_[i] = str.raw(); |
52 } | 49 } |
53 #endif | |
54 } | 50 } |
55 | 51 |
56 | 52 |
57 void Symbols::SetupSymbolTable(Isolate* isolate) { | 53 void Symbols::SetupSymbolTable(Isolate* isolate) { |
58 ASSERT(isolate != NULL); | 54 ASSERT(isolate != NULL); |
59 | 55 |
60 // Setup the symbol table used within the String class. | 56 // Setup the symbol table used within the String class. |
61 const int initial_size = (isolate == Dart::vm_isolate()) ? | 57 const int initial_size = (isolate == Dart::vm_isolate()) ? |
62 kInitialVMIsolateSymtabSize : kInitialSymtabSize; | 58 kInitialVMIsolateSymtabSize : kInitialSymtabSize; |
63 const Array& array = Array::Handle(Array::New(initial_size + 1)); | 59 const Array& array = Array::Handle(Array::New(initial_size + 1)); |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 | 286 |
291 String& symbol = String::Handle(); | 287 String& symbol = String::Handle(); |
292 symbol ^= symbol_table.At(index); | 288 symbol ^= symbol_table.At(index); |
293 while (!symbol.IsNull() && !symbol.Equals(str, begin_index, len)) { | 289 while (!symbol.IsNull() && !symbol.Equals(str, begin_index, len)) { |
294 index = (index + 1) % table_size; // Move to next element. | 290 index = (index + 1) % table_size; // Move to next element. |
295 symbol ^= symbol_table.At(index); | 291 symbol ^= symbol_table.At(index); |
296 } | 292 } |
297 return index; // Index of symbol if found or slot into which to add symbol. | 293 return index; // Index of symbol if found or slot into which to add symbol. |
298 } | 294 } |
299 | 295 |
| 296 |
| 297 intptr_t Symbols::LookupVMSymbol(RawObject* obj) { |
| 298 for (intptr_t i = 1; i < kMaxPredefined; i++) { |
| 299 if (predefined_[i] == obj) { |
| 300 return (i + Object::kMaxId); |
| 301 } |
| 302 } |
| 303 return Object::kInvalidIndex; |
| 304 } |
| 305 |
| 306 |
| 307 RawObject* Symbols::GetVMSymbol(intptr_t object_id) { |
| 308 ASSERT(IsVMSymbolId(object_id)); |
| 309 intptr_t i = (object_id - Object::kMaxId); |
| 310 return (i > 0 && i < kMaxPredefined) ? predefined_[i] : Object::null(); |
| 311 } |
| 312 |
300 } // namespace dart | 313 } // namespace dart |
OLD | NEW |