| 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 #include "vm/snapshot_ids.h" |
| 9 | 10 |
| 10 namespace dart { | 11 namespace dart { |
| 11 | 12 |
| 12 // Forward declarations. | 13 // Forward declarations. |
| 13 class Isolate; | 14 class Isolate; |
| 14 class ObjectPointerVisitor; | 15 class ObjectPointerVisitor; |
| 15 | 16 |
| 16 #define PREDEFINED_SYMBOLS_LIST(V) \ | 17 #define PREDEFINED_SYMBOLS_LIST(V) \ |
| 17 V(Dot, ".") \ | 18 V(Dot, ".") \ |
| 18 V(Equals, "=") \ | 19 V(Equals, "=") \ |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 // Contains a list of frequently used strings in a canonicalized form. This | 57 // Contains a list of frequently used strings in a canonicalized form. This |
| 57 // list is kept in the vm_isolate in order to share the copy across isolates | 58 // list is kept in the vm_isolate in order to share the copy across isolates |
| 58 // without having to maintain copies in each isolate. | 59 // without having to maintain copies in each isolate. |
| 59 class Symbols : public AllStatic { | 60 class Symbols : public AllStatic { |
| 60 public: | 61 public: |
| 61 // List of strings that are pre created in the vm isolate. | 62 // List of strings that are pre created in the vm isolate. |
| 62 enum { | 63 enum { |
| 63 kIllegal = 0, | 64 kIllegal = 0, |
| 64 | 65 |
| 65 #define DEFINE_SYMBOL_INDEX(symbol, literal) \ | 66 #define DEFINE_SYMBOL_INDEX(symbol, literal) \ |
| 66 k##symbol, | 67 k##symbol, |
| 67 PREDEFINED_SYMBOLS_LIST(DEFINE_SYMBOL_INDEX) | 68 PREDEFINED_SYMBOLS_LIST(DEFINE_SYMBOL_INDEX) |
| 68 #undef DEFINE_SYMBOL_INDEX | 69 #undef DEFINE_SYMBOL_INDEX |
| 69 | 70 |
| 70 kMaxPredefined, | 71 kMaxId, |
| 71 }; | 72 }; |
| 72 | 73 |
| 73 // Access methods for symbols stored in the vm isolate. | 74 // Access methods for symbols stored in the vm isolate. |
| 74 #define DEFINE_SYMBOL_ACCESSOR(symbol, literal) \ | 75 #define DEFINE_SYMBOL_ACCESSOR(symbol, literal) \ |
| 75 static RawString* symbol() { return predefined_[k##symbol]; } | 76 static RawString* symbol() { return predefined_[k##symbol]; } |
| 76 PREDEFINED_SYMBOLS_LIST(DEFINE_SYMBOL_ACCESSOR) | 77 PREDEFINED_SYMBOLS_LIST(DEFINE_SYMBOL_ACCESSOR) |
| 77 #undef DEFINE_SYMBOL_ACCESSOR | 78 #undef DEFINE_SYMBOL_ACCESSOR |
| 78 | 79 |
| 79 // Initialize frequently used symbols in the vm isolate. | 80 // Initialize frequently used symbols in the vm isolate. |
| 80 static void InitOnce(Isolate* isolate); | 81 static void InitOnce(Isolate* isolate); |
| 81 | 82 |
| 82 // Initialize and setup a symbol table for the isolate. | 83 // Initialize and setup a symbol table for the isolate. |
| 83 static void SetupSymbolTable(Isolate* isolate); | 84 static void SetupSymbolTable(Isolate* isolate); |
| 84 | 85 |
| 85 // Get number of symbols in an isolate's symbol table. | 86 // Get number of symbols in an isolate's symbol table. |
| 86 static intptr_t Size(Isolate* isolate); | 87 static intptr_t Size(Isolate* isolate); |
| 87 | 88 |
| 88 // Helper functions to create a symbol given a string or set of characters. | 89 // Helper functions to create a symbol given a string or set of characters. |
| 89 static RawString* New(const char* str); | 90 static RawString* New(const char* str); |
| 90 template<typename T> | 91 template<typename T> |
| 91 static RawString* New(const T* characters, intptr_t len); | 92 static RawString* New(const T* characters, intptr_t len); |
| 92 static RawString* New(const String& str); | 93 static RawString* New(const String& str); |
| 93 static RawString* New(const String& str, | 94 static RawString* New(const String& str, |
| 94 intptr_t begin_index, | 95 intptr_t begin_index, |
| 95 intptr_t length); | 96 intptr_t length); |
| 96 | 97 |
| 97 | 98 |
| 98 private: | 99 private: |
| 99 enum { | 100 enum { |
| 100 kInitialVMIsolateSymtabSize = ((kMaxPredefined + 15) & -16), | 101 kInitialVMIsolateSymtabSize = ((Symbols::kMaxId + 15) & -16), |
| 101 kInitialSymtabSize = 256 | 102 kInitialSymtabSize = 256 |
| 102 }; | 103 }; |
| 103 | 104 |
| 104 // Add the string into the VM isolate symbol table. | 105 // Add the string into the VM isolate symbol table. |
| 105 static void Add(const Array& symbol_table, const String& str); | 106 static void Add(const Array& symbol_table, const String& str); |
| 106 | 107 |
| 107 // Insert symbol into symbol table, growing it if necessary. | 108 // Insert symbol into symbol table, growing it if necessary. |
| 108 static void InsertIntoSymbolTable(const Array& symbol_table, | 109 static void InsertIntoSymbolTable(const Array& symbol_table, |
| 109 const String& symbol, | 110 const String& symbol, |
| 110 intptr_t index); | 111 intptr_t index); |
| 111 | 112 |
| 112 // Grow the symbol table. | 113 // Grow the symbol table. |
| 113 static void GrowSymbolTable(const Array& symbol_table); | 114 static void GrowSymbolTable(const Array& symbol_table); |
| 114 | 115 |
| 115 // Return index in symbol table if the symbol already exists or | 116 // Return index in symbol table if the symbol already exists or |
| 116 // return the index into which the new symbol can be added. | 117 // return the index into which the new symbol can be added. |
| 117 template<typename T> | 118 template<typename T> |
| 118 static intptr_t FindIndex(const Array& symbol_table, | 119 static intptr_t FindIndex(const Array& symbol_table, |
| 119 const T* characters, | 120 const T* characters, |
| 120 intptr_t len, | 121 intptr_t len, |
| 121 intptr_t hash); | 122 intptr_t hash); |
| 122 static intptr_t FindIndex(const Array& symbol_table, | 123 static intptr_t FindIndex(const Array& symbol_table, |
| 123 const String& str, | 124 const String& str, |
| 124 intptr_t begin_index, | 125 intptr_t begin_index, |
| 125 intptr_t len, | 126 intptr_t len, |
| 126 intptr_t hash); | 127 intptr_t hash); |
| 127 static intptr_t LookupVMSymbol(RawObject* obj); | 128 static intptr_t LookupVMSymbol(RawObject* obj); |
| 128 static RawObject* GetVMSymbol(intptr_t object_id); | 129 static RawObject* GetVMSymbol(intptr_t object_id); |
| 129 static bool IsVMSymbolId(intptr_t object_id) { | 130 static bool IsVMSymbolId(intptr_t object_id) { |
| 130 return (object_id >= Object::kMaxId && | 131 return (object_id >= kMaxPredefinedObjectIds && |
| 131 object_id < (Object::kMaxId + kMaxPredefined)); | 132 object_id < (kMaxPredefinedObjectIds + Symbols::kMaxId)); |
| 132 } | 133 } |
| 133 | 134 |
| 134 // List of symbols that are stored in the vm isolate for easy access. | 135 // List of symbols that are stored in the vm isolate for easy access. |
| 135 static RawString* predefined_[kMaxPredefined]; | 136 static RawString* predefined_[Symbols::kMaxId]; |
| 136 | 137 |
| 137 friend class SnapshotReader; | 138 friend class SnapshotReader; |
| 138 friend class SnapshotWriter; | 139 friend class SnapshotWriter; |
| 139 friend class ApiMessageReader; | 140 friend class ApiMessageReader; |
| 140 | 141 |
| 141 DISALLOW_COPY_AND_ASSIGN(Symbols); | 142 DISALLOW_COPY_AND_ASSIGN(Symbols); |
| 142 }; | 143 }; |
| 143 | 144 |
| 144 } // namespace dart | 145 } // namespace dart |
| 145 | 146 |
| 146 #endif // VM_SYMBOLS_H_ | 147 #endif // VM_SYMBOLS_H_ |
| OLD | NEW |