| 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 #ifndef VM_SYMBOLS_H_ | 5 #ifndef VM_SYMBOLS_H_ |
| 6 #define VM_SYMBOLS_H_ | 6 #define VM_SYMBOLS_H_ |
| 7 | 7 |
| 8 #include "vm/object.h" | 8 #include "vm/object.h" |
| 9 | 9 |
| 10 namespace dart { | 10 namespace dart { |
| 11 | 11 |
| 12 // Forward declarations. | 12 // Forward declarations. |
| 13 class Isolate; | 13 class Isolate; |
| 14 class ObjectPointerVisitor; | 14 class ObjectPointerVisitor; |
| 15 | 15 |
| 16 #define PREDEFINED_SYMBOLS_LIST(V) \ |
| 17 V(Dot, ".") \ |
| 18 V(IndexToken, "[]") \ |
| 19 V(AssignIndexToken, "[]=") \ |
| 20 V(TopLevel, "::") \ |
| 21 V(Empty, "") \ |
| 22 V(This, "this") \ |
| 23 V(HasNext, "hasNext") \ |
| 24 V(Next, "next") \ |
| 25 V(Value, "value") \ |
| 26 V(ExprTemp, ":expr_temp") \ |
| 27 V(Function, "function") \ |
| 28 V(PhaseParameter, ":phase") \ |
| 29 V(AssertionError, "AssertionError") \ |
| 30 V(TypeError, "TypeError") \ |
| 31 V(FallThroughError, "FallThroughError") \ |
| 32 V(StaticResolutionException, "StaticResolutionException") \ |
| 33 V(ThrowNew, "_throwNew") \ |
| 34 V(ListLiteralFactoryClass, "_ListLiteralFactory") \ |
| 35 V(ListLiteralFactory, "List.fromLiteral") \ |
| 36 V(MapLiteralFactoryClass, "_MapLiteralFactory") \ |
| 37 V(MapLiteralFactory, "Map.fromLiteral") \ |
| 38 V(ImmutableMap, "ImmutableMap") \ |
| 39 V(ImmutableMapConstructor, "ImmutableMap._create") \ |
| 40 V(StringBase, "StringBase") \ |
| 41 V(Interpolate, "_interpolate") \ |
| 42 V(GetIterator, "iterator") \ |
| 43 V(NoSuchMethod, "noSuchMethod") \ |
| 44 V(SavedContextVar, ":saved_context_var") \ |
| 45 V(ExceptionVar, ":exception_var") \ |
| 46 V(StacktraceVar, ":stacktrace_var") \ |
| 47 V(ListLiteralElement, "list literal element") \ |
| 48 V(ForInIter, ":for-in-iter") \ |
| 49 V(Library, "library") \ |
| 50 V(Import, "import") \ |
| 51 V(Source, "source") \ |
| 52 V(Resource, "resource") \ |
| 53 |
| 16 // Contains a list of frequently used strings in a canonicalized form. This | 54 // Contains a list of frequently used strings in a canonicalized form. This |
| 17 // list is kept in the vm_isolate in order to share the copy across isolates | 55 // list is kept in the vm_isolate in order to share the copy across isolates |
| 18 // without having to maintain copies in each isolate. | 56 // without having to maintain copies in each isolate. |
| 19 class Symbols : public AllStatic { | 57 class Symbols : public AllStatic { |
| 20 public: | 58 public: |
| 21 // List of strings that are pre created in the vm isolate. | 59 // List of strings that are pre created in the vm isolate. |
| 22 static const char* kDot; | 60 enum { |
| 61 kIllegal = 0, |
| 62 |
| 63 #define DEFINE_SYMBOL_INDEX(symbol, literal) \ |
| 64 k##symbol, |
| 65 PREDEFINED_SYMBOLS_LIST(DEFINE_SYMBOL_INDEX) |
| 66 #undef DEFINE_SYMBOL_INDEX |
| 67 |
| 68 kMaxPredefined, |
| 69 }; |
| 23 | 70 |
| 24 // Access methods for symbols stored in the vm isolate. | 71 // Access methods for symbols stored in the vm isolate. |
| 25 static RawString* Dot() { return dot_; } | 72 #define DEFINE_SYMBOL_ACCESSOR(symbol, literal) \ |
| 73 static RawString* symbol() { return predefined_[k##symbol]; } |
| 74 PREDEFINED_SYMBOLS_LIST(DEFINE_SYMBOL_ACCESSOR) |
| 75 #undef DEFINE_SYMBOL_ACCESSOR |
| 26 | 76 |
| 27 // Initialize frequently used symbols in the vm isolate. | 77 // Initialize frequently used symbols in the vm isolate. |
| 28 static void InitOnce(Isolate* isolate); | 78 static void InitOnce(Isolate* isolate); |
| 29 | 79 |
| 30 // Initialize and setup a symbol table for the isolate. | 80 // Initialize and setup a symbol table for the isolate. |
| 31 static void SetupSymbolTable(Isolate* isolate); | 81 static void SetupSymbolTable(Isolate* isolate); |
| 32 | 82 |
| 33 // Helper functions to create a symbol given a string or set of characters. | 83 // Helper functions to create a symbol given a string or set of characters. |
| 34 static RawString* New(const char* str); | 84 static RawString* New(const char* str); |
| 35 template<typename T> | 85 template<typename T> |
| 36 static RawString* New(const T* characters, intptr_t len); | 86 static RawString* New(const T* characters, intptr_t len); |
| 37 static RawString* New(const String& str); | 87 static RawString* New(const String& str); |
| 38 static RawString* New(const String& str, | 88 static RawString* New(const String& str, |
| 39 intptr_t begin_index, | 89 intptr_t begin_index, |
| 40 intptr_t length); | 90 intptr_t length); |
| 41 | 91 |
| 42 | 92 |
| 43 private: | 93 private: |
| 44 static const int kInitialSymbolTableSize = 16; | 94 static const int kInitialVMIsolateSymtabSize = ((kMaxPredefined + 15) & -16); |
| 95 static const int kInitialSymtabSize = 256; |
| 45 | 96 |
| 46 // Add the string into the VM isolate symbol table. | 97 // Add the string into the VM isolate symbol table. |
| 47 static void Add(const Array& symbol_table, const String& str); | 98 static void Add(const Array& symbol_table, const String& str); |
| 48 | 99 |
| 49 // Insert symbol into symbol table, growing it if necessary. | 100 // Insert symbol into symbol table, growing it if necessary. |
| 50 static void InsertIntoSymbolTable(const Array& symbol_table, | 101 static void InsertIntoSymbolTable(const Array& symbol_table, |
| 51 const String& symbol, | 102 const String& symbol, |
| 52 intptr_t index); | 103 intptr_t index); |
| 53 | 104 |
| 54 // Grow the symbol table. | 105 // Grow the symbol table. |
| 55 static void GrowSymbolTable(const Array& symbol_table); | 106 static void GrowSymbolTable(const Array& symbol_table); |
| 56 | 107 |
| 57 // Return index in symbol table if the symbol already exists or | 108 // Return index in symbol table if the symbol already exists or |
| 58 // return the index into which the new symbol can be added. | 109 // return the index into which the new symbol can be added. |
| 59 template<typename T> | 110 template<typename T> |
| 60 static intptr_t FindIndex(const Array& symbol_table, | 111 static intptr_t FindIndex(const Array& symbol_table, |
| 61 const T* characters, | 112 const T* characters, |
| 62 intptr_t len, | 113 intptr_t len, |
| 63 intptr_t hash); | 114 intptr_t hash); |
| 64 static intptr_t FindIndex(const Array& symbol_table, | 115 static intptr_t FindIndex(const Array& symbol_table, |
| 65 const String& str, | 116 const String& str, |
| 66 intptr_t begin_index, | 117 intptr_t begin_index, |
| 67 intptr_t len, | 118 intptr_t len, |
| 68 intptr_t hash); | 119 intptr_t hash); |
| 69 | 120 |
| 70 // List of symbols that are stored in the vm isolate for easy access. | 121 // List of symbols that are stored in the vm isolate for easy access. |
| 71 static RawString* dot_; // "." string. | 122 static RawString* predefined_[kMaxPredefined]; |
| 72 | 123 |
| 73 friend class SnapshotReader; | 124 friend class SnapshotReader; |
| 74 | 125 |
| 75 DISALLOW_COPY_AND_ASSIGN(Symbols); | 126 DISALLOW_COPY_AND_ASSIGN(Symbols); |
| 76 }; | 127 }; |
| 77 | 128 |
| 78 } // namespace dart | 129 } // namespace dart |
| 79 | 130 |
| 80 #endif // VM_SYMBOLS_H_ | 131 #endif // VM_SYMBOLS_H_ |
| OLD | NEW |