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 #include "vm/snapshot_ids.h" |
10 | 10 |
(...skipping 21 matching lines...) Expand all Loading... |
32 V(ExprTemp, ":expr_temp") \ | 32 V(ExprTemp, ":expr_temp") \ |
33 V(AnonymousClosure, "<anonymous closure>") \ | 33 V(AnonymousClosure, "<anonymous closure>") \ |
34 V(ClosureParameter, ":closure") \ | 34 V(ClosureParameter, ":closure") \ |
35 V(PhaseParameter, ":phase") \ | 35 V(PhaseParameter, ":phase") \ |
36 V(TypeArgumentsParameter, ":type_arguments") \ | 36 V(TypeArgumentsParameter, ":type_arguments") \ |
37 V(AssertionError, "AssertionErrorImplementation") \ | 37 V(AssertionError, "AssertionErrorImplementation") \ |
38 V(TypeError, "TypeErrorImplementation") \ | 38 V(TypeError, "TypeErrorImplementation") \ |
39 V(FallThroughError, "FallThroughErrorImplementation") \ | 39 V(FallThroughError, "FallThroughErrorImplementation") \ |
40 V(AbstractClassInstantiationError, \ | 40 V(AbstractClassInstantiationError, \ |
41 "AbstractClassInstantiationErrorImplementation") \ | 41 "AbstractClassInstantiationErrorImplementation") \ |
42 V(NoSuchMethodError, "NoSuchMethodErrorImplementation") \ | 42 V(NoSuchMethodErrorImpl, "NoSuchMethodErrorImplementation") \ |
43 V(ThrowNew, "_throwNew") \ | 43 V(ThrowNew, "_throwNew") \ |
44 V(List, "List") \ | 44 V(List, "List") \ |
45 V(ListLiteralFactory, "List._fromLiteral") \ | 45 V(ListLiteralFactory, "List._fromLiteral") \ |
46 V(ListFactory, "List.") \ | 46 V(ListFactory, "List.") \ |
47 V(Map, "Map") \ | 47 V(Map, "Map") \ |
48 V(MapLiteralFactory, "Map._fromLiteral") \ | 48 V(MapLiteralFactory, "Map._fromLiteral") \ |
49 V(ImmutableMap, "ImmutableMap") \ | 49 V(ImmutableMap, "ImmutableMap") \ |
50 V(ImmutableMapConstructor, "ImmutableMap._create") \ | 50 V(ImmutableMapConstructor, "ImmutableMap._create") \ |
51 V(StringBase, "_StringBase") \ | 51 V(StringBase, "_StringBase") \ |
52 V(Interpolate, "_interpolate") \ | 52 V(Interpolate, "_interpolate") \ |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 V(ContextScope, "ContextScope") \ | 95 V(ContextScope, "ContextScope") \ |
96 V(ICData, "ICData") \ | 96 V(ICData, "ICData") \ |
97 V(MegamorphicCache, "MegamorphicCache") \ | 97 V(MegamorphicCache, "MegamorphicCache") \ |
98 V(SubtypeTestCache, "SubtypeTestCache") \ | 98 V(SubtypeTestCache, "SubtypeTestCache") \ |
99 V(ApiError, "ApiError") \ | 99 V(ApiError, "ApiError") \ |
100 V(LanguageError, "LanguageError") \ | 100 V(LanguageError, "LanguageError") \ |
101 V(UnhandledException, "UnhandledException") \ | 101 V(UnhandledException, "UnhandledException") \ |
102 V(UnwindError, "UnwindError") \ | 102 V(UnwindError, "UnwindError") \ |
103 V(IntegerImplementation, "_IntegerImplementation") \ | 103 V(IntegerImplementation, "_IntegerImplementation") \ |
104 V(Number, "num") \ | 104 V(Number, "num") \ |
105 V(Smi, "_Smi") \ | 105 V(_Smi, "_Smi") \ |
106 V(Mint, "_Mint") \ | 106 V(_Mint, "_Mint") \ |
107 V(Bigint, "_Bigint") \ | 107 V(_Bigint, "_Bigint") \ |
108 V(Double, "_Double") \ | 108 V(_Double, "_Double") \ |
109 V(Bool, "bool") \ | 109 V(Bool, "bool") \ |
110 V(ObjectArray, "_ObjectArray") \ | 110 V(ObjectArray, "_ObjectArray") \ |
111 V(GrowableObjectArray, "_GrowableObjectArray") \ | 111 V(GrowableObjectArray, "_GrowableObjectArray") \ |
112 V(ImmutableArray, "_ImmutableArray") \ | 112 V(ImmutableArray, "_ImmutableArray") \ |
113 V(OneByteString, "_OneByteString") \ | 113 V(OneByteString, "_OneByteString") \ |
114 V(TwoByteString, "_TwoByteString") \ | 114 V(TwoByteString, "_TwoByteString") \ |
115 V(ExternalOneByteString, "_ExternalOneByteString") \ | 115 V(ExternalOneByteString, "_ExternalOneByteString") \ |
116 V(ExternalTwoByteString, "_ExternalTwoByteString") \ | 116 V(ExternalTwoByteString, "_ExternalTwoByteString") \ |
117 V(Stacktrace, "Stacktrace") \ | 117 V(Stacktrace, "Stacktrace") \ |
118 V(JSSyntaxRegExp, "_JSSyntaxRegExp") \ | 118 V(JSSyntaxRegExp, "_JSSyntaxRegExp") \ |
119 V(Object, "Object") \ | 119 V(Object, "Object") \ |
| 120 V(Int, "int") \ |
| 121 V(Double, "double") \ |
| 122 V(Int8List, "Int8List") \ |
| 123 V(Uint8List, "Uint8List") \ |
| 124 V(Uint8ClampedList, "Uint8ClampedList") \ |
| 125 V(Int16List, "Int16List") \ |
| 126 V(Uint16List, "Uint16List") \ |
| 127 V(Int32List, "Int32List") \ |
| 128 V(Uint32List, "Uint32List") \ |
| 129 V(Int64List, "Int64List") \ |
| 130 V(Uint64List, "Uint64List") \ |
| 131 V(Float32List, "Float32List") \ |
| 132 V(Float64List, "Float64List") \ |
120 V(_Int8Array, "_Int8Array") \ | 133 V(_Int8Array, "_Int8Array") \ |
121 V(_Uint8Array, "_Uint8Array") \ | 134 V(_Uint8Array, "_Uint8Array") \ |
122 V(_Uint8ClampedArray, "_Uint8ClampedArray") \ | 135 V(_Uint8ClampedArray, "_Uint8ClampedArray") \ |
123 V(_Int16Array, "_Int16Array") \ | 136 V(_Int16Array, "_Int16Array") \ |
124 V(_Uint16Array, "_Uint16Array") \ | 137 V(_Uint16Array, "_Uint16Array") \ |
125 V(_Int32Array, "_Int32Array") \ | 138 V(_Int32Array, "_Int32Array") \ |
126 V(_Uint32Array, "_Uint32Array") \ | 139 V(_Uint32Array, "_Uint32Array") \ |
127 V(_Int64Array, "_Int64Array") \ | 140 V(_Int64Array, "_Int64Array") \ |
128 V(_Uint64Array, "_Uint64Array") \ | 141 V(_Uint64Array, "_Uint64Array") \ |
129 V(_Float32Array, "_Float32Array") \ | 142 V(_Float32Array, "_Float32Array") \ |
130 V(_Float64Array, "_Float64Array") \ | 143 V(_Float64Array, "_Float64Array") \ |
131 V(_ExternalInt8Array, "_ExternalInt8Array") \ | 144 V(_ExternalInt8Array, "_ExternalInt8Array") \ |
132 V(_ExternalUint8Array, "_ExternalUint8Array") \ | 145 V(_ExternalUint8Array, "_ExternalUint8Array") \ |
133 V(_ExternalUint8ClampedArray, "_ExternalUint8ClampedArray") \ | 146 V(_ExternalUint8ClampedArray, "_ExternalUint8ClampedArray") \ |
134 V(_ExternalInt16Array, "_ExternalInt16Array") \ | 147 V(_ExternalInt16Array, "_ExternalInt16Array") \ |
135 V(_ExternalUint16Array, "_ExternalUint16Array") \ | 148 V(_ExternalUint16Array, "_ExternalUint16Array") \ |
136 V(_ExternalInt32Array, "_ExternalInt32Array") \ | 149 V(_ExternalInt32Array, "_ExternalInt32Array") \ |
137 V(_ExternalUint32Array, "_ExternalUint32Array") \ | 150 V(_ExternalUint32Array, "_ExternalUint32Array") \ |
138 V(_ExternalInt64Array, "_ExternalInt64Array") \ | 151 V(_ExternalInt64Array, "_ExternalInt64Array") \ |
139 V(_ExternalUint64Array, "_ExternalUint64Array") \ | 152 V(_ExternalUint64Array, "_ExternalUint64Array") \ |
140 V(_ExternalFloat32Array, "_ExternalFloat32Array") \ | 153 V(_ExternalFloat32Array, "_ExternalFloat32Array") \ |
141 V(_ExternalFloat64Array, "_ExternalFloat64Array") \ | 154 V(_ExternalFloat64Array, "_ExternalFloat64Array") \ |
142 V(_WeakProperty, "_WeakProperty") \ | 155 V(_WeakProperty, "_WeakProperty") \ |
143 V(InvocationMirror, "_InvocationMirror") \ | 156 V(InvocationMirror, "_InvocationMirror") \ |
144 V(AllocateInvocationMirror, "_allocateInvocationMirror") \ | 157 V(AllocateInvocationMirror, "_allocateInvocationMirror") \ |
145 | 158 V(toString, "toString") \ |
146 #define PREDEFINED_SYMBOL_HANDLES_LIST(V) \ | 159 V(_ReceivePortImpl, "_ReceivePortImpl") \ |
147 V(Dot) \ | 160 V(_lookupReceivePort, "_lookupReceivePort") \ |
148 V(EqualOperator) \ | 161 V(_handleMessage, "_handleMessage") \ |
149 V(IndexToken) \ | 162 V(_SendPortImpl, "_SendPortImpl") \ |
150 V(AssignIndexToken) \ | 163 V(_create, "_create") \ |
151 V(This) \ | 164 V(_id, "_id") \ |
| 165 V(_get_or_create, "_get_or_create") \ |
| 166 V(RangeError, "RangeError") \ |
| 167 V(ArgumentError, "ArgumentError") \ |
| 168 V(NoSuchMethodError, "NoSuchMethodError") \ |
| 169 V(FormatException, "FormatException") \ |
| 170 V(StackOverflowError, "StackOverflowError") \ |
| 171 V(OutOfMemoryError, "OutOfMemoryError") \ |
| 172 V(InternalError, "InternalError") \ |
| 173 V(NullThrownError, "NullThrownError") \ |
| 174 V(IllegalJSRegExpException, "IllegalJSRegExpException") \ |
| 175 V(IsolateSpawnException, "IsolateSpawnException") \ |
| 176 V(IsolateUnhandledException, "IsolateUnhandledException") \ |
| 177 V(BooleanExpression, "boolean expression") \ |
| 178 V(Malformed, "malformed") \ |
| 179 V(InstanceOf, "InstanceOf") \ |
| 180 V(MegamorphicMiss, "megamorphic_miss") \ |
| 181 V(CommaSpace, ", ") \ |
| 182 V(ColonSpace, ": ") \ |
| 183 V(RParenArrow, ") => ") \ |
| 184 V(SpaceExtendsSpace, " extends ") \ |
| 185 V(PatchSpace, "patch ") \ |
| 186 V(AliasOwner, ":alias_owner") \ |
| 187 V(SwitchExpr, ":switch_expr") \ |
| 188 V(TwoNewlines, "\n\n") \ |
| 189 V(TwoSpaces, " ") \ |
152 | 190 |
153 // Contains a list of frequently used strings in a canonicalized form. This | 191 // Contains a list of frequently used strings in a canonicalized form. This |
154 // list is kept in the vm_isolate in order to share the copy across isolates | 192 // list is kept in the vm_isolate in order to share the copy across isolates |
155 // without having to maintain copies in each isolate. | 193 // without having to maintain copies in each isolate. |
156 class Symbols : public AllStatic { | 194 class Symbols : public AllStatic { |
157 public: | 195 public: |
158 enum { kMaxOneCharCodeSymbol = 0xFF }; | 196 enum { kMaxOneCharCodeSymbol = 0xFF }; |
159 | 197 |
160 // List of strings that are pre created in the vm isolate. | 198 // List of strings that are pre created in the vm isolate. |
161 enum SymbolId { | 199 enum SymbolId { |
162 kIllegal = 0, | 200 kIllegal = 0, |
163 | 201 |
164 #define DEFINE_SYMBOL_INDEX(symbol, literal) \ | 202 #define DEFINE_SYMBOL_INDEX(symbol, literal) \ |
165 k##symbol, | 203 k##symbol##Id, |
166 PREDEFINED_SYMBOLS_LIST(DEFINE_SYMBOL_INDEX) | 204 PREDEFINED_SYMBOLS_LIST(DEFINE_SYMBOL_INDEX) |
167 #undef DEFINE_SYMBOL_INDEX | 205 #undef DEFINE_SYMBOL_INDEX |
168 kMaxPredefinedId, | 206 |
169 kNullCharId = kMaxPredefinedId, | 207 kNullCharId, // One char code symbol starts here and takes up 256 entries. |
170 kMaxId = kNullCharId + kMaxOneCharCodeSymbol + 1, | 208 kMaxPredefinedId = kNullCharId + kMaxOneCharCodeSymbol + 1, |
171 }; | 209 }; |
172 | 210 |
173 // Access methods for symbols stored in the vm isolate. | 211 // Access methods for one byte character symbols stored in the vm isolate. |
174 #define DEFINE_SYMBOL_ACCESSOR(symbol, literal) \ | 212 static const String& Dot() { |
175 static RawString* symbol() { return predefined_[k##symbol]; } | 213 return *(symbol_handles_[kNullCharId + '.']); |
176 PREDEFINED_SYMBOLS_LIST(DEFINE_SYMBOL_ACCESSOR) | 214 } |
177 #undef DEFINE_SYMBOL_ACCESSOR | 215 static const String& Equals() { |
178 static RawString* Dot() { return predefined_[kNullCharId + '.']; } | 216 return *(symbol_handles_[kNullCharId + '=']); |
179 static RawString* Equals() { return predefined_[kNullCharId + '=']; } | 217 } |
| 218 static const String& LAngleBracket() { |
| 219 return *(symbol_handles_[kNullCharId + '<']); |
| 220 } |
| 221 static const String& RAngleBracket() { |
| 222 return *(symbol_handles_[kNullCharId + '>']); |
| 223 } |
| 224 static const String& LParen() { |
| 225 return *(symbol_handles_[kNullCharId + '(']); |
| 226 } |
| 227 static const String& RParen() { |
| 228 return *(symbol_handles_[kNullCharId + ')']); |
| 229 } |
| 230 static const String& LBracket() { |
| 231 return *(symbol_handles_[kNullCharId + '[']); |
| 232 } |
| 233 static const String& RBracket() { |
| 234 return *(symbol_handles_[kNullCharId + ']']); |
| 235 } |
| 236 static const String& LBrace() { |
| 237 return *(symbol_handles_[kNullCharId + '{']); |
| 238 } |
| 239 static const String& RBrace() { |
| 240 return *(symbol_handles_[kNullCharId + '}']); |
| 241 } |
| 242 static const String& Blank() { |
| 243 return *(symbol_handles_[kNullCharId + ' ']); |
| 244 } |
| 245 static const String& Dollar() { |
| 246 return *(symbol_handles_[kNullCharId + '$']); |
| 247 } |
| 248 static const String& NewLine() { |
| 249 return *(symbol_handles_[kNullCharId + '\n']); |
| 250 } |
| 251 static const String& DoubleQuotes() { |
| 252 return *(symbol_handles_[kNullCharId + '"']); |
| 253 } |
| 254 static const String& LowercaseR() { |
| 255 return *(symbol_handles_[kNullCharId + 'r']); |
| 256 } |
| 257 static const String& Dash() { |
| 258 return *(symbol_handles_[kNullCharId + '-']); |
| 259 } |
180 | 260 |
181 // Access methods for symbol handles stored in the vm isolate. | 261 // Access methods for symbol handles stored in the vm isolate. |
182 #define DEFINE_SYMBOL_HANDLE_ACCESSOR(symbol) \ | 262 #define DEFINE_SYMBOL_HANDLE_ACCESSOR(symbol, literal) \ |
183 static const String& symbol##Handle() { return *symbol##_handle_; } | 263 static const String& symbol() { return *(symbol_handles_[k##symbol##Id]); } |
184 PREDEFINED_SYMBOL_HANDLES_LIST(DEFINE_SYMBOL_HANDLE_ACCESSOR) | 264 PREDEFINED_SYMBOLS_LIST(DEFINE_SYMBOL_HANDLE_ACCESSOR) |
185 #undef DEFINE_SYMBOL_HANDLE_ACCESSOR | 265 #undef DEFINE_SYMBOL_HANDLE_ACCESSOR |
186 | 266 |
187 // Initialize frequently used symbols in the vm isolate. | 267 // Initialize frequently used symbols in the vm isolate. |
188 static void InitOnce(Isolate* isolate); | 268 static void InitOnce(Isolate* isolate); |
189 | 269 |
190 // Initialize and setup a symbol table for the isolate. | 270 // Initialize and setup a symbol table for the isolate. |
191 static void SetupSymbolTable(Isolate* isolate); | 271 static void SetupSymbolTable(Isolate* isolate); |
192 | 272 |
193 // Get number of symbols in an isolate's symbol table. | 273 // Get number of symbols in an isolate's symbol table. |
194 static intptr_t Size(Isolate* isolate); | 274 static intptr_t Size(Isolate* isolate); |
(...skipping 29 matching lines...) Expand all Loading... |
224 return reinterpret_cast<RawString**>(&predefined_); | 304 return reinterpret_cast<RawString**>(&predefined_); |
225 } | 305 } |
226 | 306 |
227 static void DumpStats(); | 307 static void DumpStats(); |
228 | 308 |
229 private: | 309 private: |
230 enum { | 310 enum { |
231 kInitialVMIsolateSymtabSize = 512, | 311 kInitialVMIsolateSymtabSize = 512, |
232 kInitialSymtabSize = 2048 | 312 kInitialSymtabSize = 2048 |
233 }; | 313 }; |
| 314 static const int kNumberOfOneCharCodeSymbols = |
| 315 (kMaxPredefinedId - kNullCharId); |
234 | 316 |
235 // Helper functions to create a symbol given a string or set of characters. | 317 // Helper functions to create a symbol given a string or set of characters. |
236 template<typename CharacterType, typename CallbackType> | 318 template<typename CharacterType, typename CallbackType> |
237 static RawString* NewSymbol(const CharacterType* characters, | 319 static RawString* NewSymbol(const CharacterType* characters, |
238 intptr_t len, | 320 intptr_t len, |
239 CallbackType new_string); | 321 CallbackType new_string); |
240 | 322 |
241 // Add the string into the VM isolate symbol table. | 323 // Add the string into the VM isolate symbol table. |
242 static void Add(const Array& symbol_table, const String& str); | 324 static void Add(const Array& symbol_table, const String& str); |
243 | 325 |
(...skipping 14 matching lines...) Expand all Loading... |
258 intptr_t hash); | 340 intptr_t hash); |
259 static intptr_t FindIndex(const Array& symbol_table, | 341 static intptr_t FindIndex(const Array& symbol_table, |
260 const String& str, | 342 const String& str, |
261 intptr_t begin_index, | 343 intptr_t begin_index, |
262 intptr_t len, | 344 intptr_t len, |
263 intptr_t hash); | 345 intptr_t hash); |
264 static intptr_t LookupVMSymbol(RawObject* obj); | 346 static intptr_t LookupVMSymbol(RawObject* obj); |
265 static RawObject* GetVMSymbol(intptr_t object_id); | 347 static RawObject* GetVMSymbol(intptr_t object_id); |
266 static bool IsVMSymbolId(intptr_t object_id) { | 348 static bool IsVMSymbolId(intptr_t object_id) { |
267 return (object_id >= kMaxPredefinedObjectIds && | 349 return (object_id >= kMaxPredefinedObjectIds && |
268 object_id < (kMaxPredefinedObjectIds + kMaxId)); | 350 object_id < (kMaxPredefinedObjectIds + kMaxPredefinedId)); |
269 } | 351 } |
270 | 352 |
271 // List of symbols that are stored in the vm isolate for easy access. | 353 // List of Latin1 characters stored in the vm isolate as symbols |
272 static RawString* predefined_[kMaxId]; | 354 // in order to make Symbols::FromCharCode fast. This structure is |
| 355 // used in generated dart code for direct access to these objects. |
| 356 static RawString* predefined_[kNumberOfOneCharCodeSymbols]; |
| 357 |
| 358 // List of handles for predefined symbols. |
| 359 static String* symbol_handles_[kMaxPredefinedId]; |
273 | 360 |
274 // Statistics used to measure the efficiency of the symbol table. | 361 // Statistics used to measure the efficiency of the symbol table. |
275 static const intptr_t kMaxCollisionBuckets = 10; | 362 static const intptr_t kMaxCollisionBuckets = 10; |
276 static intptr_t num_of_grows_; | 363 static intptr_t num_of_grows_; |
277 static intptr_t collision_count_[kMaxCollisionBuckets]; | 364 static intptr_t collision_count_[kMaxCollisionBuckets]; |
278 | 365 |
279 #define DECLARE_SYMBOL_HANDLE(symbol) \ | |
280 static String* symbol##_handle_; | |
281 PREDEFINED_SYMBOL_HANDLES_LIST(DECLARE_SYMBOL_HANDLE) | |
282 #undef DECLARE_SYMBOL_HANDLE | |
283 | |
284 friend class String; | 366 friend class String; |
285 friend class SnapshotReader; | 367 friend class SnapshotReader; |
286 friend class SnapshotWriter; | 368 friend class SnapshotWriter; |
287 friend class ApiMessageReader; | 369 friend class ApiMessageReader; |
288 | 370 |
289 DISALLOW_COPY_AND_ASSIGN(Symbols); | 371 DISALLOW_COPY_AND_ASSIGN(Symbols); |
290 }; | 372 }; |
291 | 373 |
292 } // namespace dart | 374 } // namespace dart |
293 | 375 |
294 #endif // VM_SYMBOLS_H_ | 376 #endif // VM_SYMBOLS_H_ |
OLD | NEW |