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 84 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") \ |
Florian Schneider
2013/01/03 14:39:51
Maybe also rename the other accessors for private
siva
2013/01/03 17:54:35
Good point.
I will rename these to be consistent
| |
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(FormatException, "FormatException") \ | |
169 V(StackOverflowError, "StackOverflowError") \ | |
170 V(OutOfMemoryError, "OutOfMemoryError") \ | |
171 V(InternalError, "InternalError") \ | |
172 V(NullThrownError, "NullThrownError") \ | |
173 V(IllegalJSRegExpException, "IllegalJSRegExpException") \ | |
174 V(IsolateSpawnException, "IsolateSpawnException") \ | |
175 V(IsolateUnhandledException, "IsolateUnhandledException") \ | |
176 V(BooleanExpression, "boolean expression") \ | |
177 V(Malformed, "malformed") \ | |
178 V(InstanceOf, "InstanceOf") \ | |
179 V(MegamorphicMiss, "megamorphic_miss") \ | |
180 V(CommaSpace, ", ") \ | |
181 V(ColonSpace, ": ") \ | |
182 V(RParenArrow, ") => ") \ | |
183 V(SpaceExtendsSpace, " extends ") \ | |
184 V(PatchSpace, "patch ") \ | |
185 V(AliasOwner, ":alias_owner") \ | |
186 V(SwitchExpr, ":switch_expr") \ | |
187 V(TwoNewlines, "\n\n") \ | |
188 V(TwoSpaces, " ") \ | |
152 | 189 |
153 // Contains a list of frequently used strings in a canonicalized form. This | 190 // 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 | 191 // list is kept in the vm_isolate in order to share the copy across isolates |
155 // without having to maintain copies in each isolate. | 192 // without having to maintain copies in each isolate. |
156 class Symbols : public AllStatic { | 193 class Symbols : public AllStatic { |
157 public: | 194 public: |
158 enum { kMaxOneCharCodeSymbol = 0xFF }; | 195 enum { kMaxOneCharCodeSymbol = 0xFF }; |
159 | 196 |
160 // List of strings that are pre created in the vm isolate. | 197 // List of strings that are pre created in the vm isolate. |
161 enum SymbolId { | 198 enum SymbolId { |
162 kIllegal = 0, | 199 kIllegal = 0, |
163 | 200 |
164 #define DEFINE_SYMBOL_INDEX(symbol, literal) \ | 201 #define DEFINE_SYMBOL_INDEX(symbol, literal) \ |
165 k##symbol, | 202 k##symbol##Id, |
166 PREDEFINED_SYMBOLS_LIST(DEFINE_SYMBOL_INDEX) | 203 PREDEFINED_SYMBOLS_LIST(DEFINE_SYMBOL_INDEX) |
167 #undef DEFINE_SYMBOL_INDEX | 204 #undef DEFINE_SYMBOL_INDEX |
168 kMaxPredefinedId, | 205 |
169 kNullCharId = kMaxPredefinedId, | 206 kNullCharId, // One char code symbol starts here and takes up 256 entries. |
170 kMaxId = kNullCharId + kMaxOneCharCodeSymbol + 1, | 207 kMaxPredefinedId = kNullCharId + kMaxOneCharCodeSymbol + 1, |
171 }; | 208 }; |
172 | 209 |
173 // Access methods for symbols stored in the vm isolate. | 210 // Number of one character symbols being predefined in the predefined_ array. |
174 #define DEFINE_SYMBOL_ACCESSOR(symbol, literal) \ | 211 static const int kNumberOfOneCharCodeSymbols = |
175 static RawString* symbol() { return predefined_[k##symbol]; } | 212 (kMaxPredefinedId - kNullCharId); |
176 PREDEFINED_SYMBOLS_LIST(DEFINE_SYMBOL_ACCESSOR) | 213 |
177 #undef DEFINE_SYMBOL_ACCESSOR | 214 // Offset of Null character which is the predefined character symbol. |
178 static RawString* Dot() { return predefined_[kNullCharId + '.']; } | 215 static const int kNullCharCodeSymbolOffset = 0; |
179 static RawString* Equals() { return predefined_[kNullCharId + '=']; } | 216 |
217 // Access methods for one byte character symbols stored in the vm isolate. | |
218 static const String& Dot() { | |
219 return *(symbol_handles_[kNullCharId + '.']); | |
220 } | |
221 static const String& Equals() { | |
222 return *(symbol_handles_[kNullCharId + '=']); | |
223 } | |
224 static const String& LAngleBracket() { | |
225 return *(symbol_handles_[kNullCharId + '<']); | |
226 } | |
227 static const String& RAngleBracket() { | |
228 return *(symbol_handles_[kNullCharId + '>']); | |
229 } | |
230 static const String& LParen() { | |
231 return *(symbol_handles_[kNullCharId + '(']); | |
232 } | |
233 static const String& RParen() { | |
234 return *(symbol_handles_[kNullCharId + ')']); | |
235 } | |
236 static const String& LBracket() { | |
237 return *(symbol_handles_[kNullCharId + '[']); | |
238 } | |
239 static const String& RBracket() { | |
240 return *(symbol_handles_[kNullCharId + ']']); | |
241 } | |
242 static const String& LBrace() { | |
243 return *(symbol_handles_[kNullCharId + '{']); | |
244 } | |
245 static const String& RBrace() { | |
246 return *(symbol_handles_[kNullCharId + '}']); | |
247 } | |
248 static const String& Blank() { | |
249 return *(symbol_handles_[kNullCharId + ' ']); | |
250 } | |
251 static const String& Dollar() { | |
252 return *(symbol_handles_[kNullCharId + '$']); | |
253 } | |
254 static const String& NewLine() { | |
255 return *(symbol_handles_[kNullCharId + '\n']); | |
256 } | |
257 static const String& DoubleQuotes() { | |
258 return *(symbol_handles_[kNullCharId + '"']); | |
259 } | |
260 static const String& LowercaseR() { | |
261 return *(symbol_handles_[kNullCharId + 'r']); | |
262 } | |
263 static const String& Dash() { | |
264 return *(symbol_handles_[kNullCharId + '-']); | |
265 } | |
180 | 266 |
181 // Access methods for symbol handles stored in the vm isolate. | 267 // Access methods for symbol handles stored in the vm isolate. |
182 #define DEFINE_SYMBOL_HANDLE_ACCESSOR(symbol) \ | 268 #define DEFINE_SYMBOL_HANDLE_ACCESSOR(symbol, literal) \ |
183 static const String& symbol##Handle() { return *symbol##_handle_; } | 269 static const String& symbol() { return *(symbol_handles_[k##symbol##Id]); } |
184 PREDEFINED_SYMBOL_HANDLES_LIST(DEFINE_SYMBOL_HANDLE_ACCESSOR) | 270 PREDEFINED_SYMBOLS_LIST(DEFINE_SYMBOL_HANDLE_ACCESSOR) |
185 #undef DEFINE_SYMBOL_HANDLE_ACCESSOR | 271 #undef DEFINE_SYMBOL_HANDLE_ACCESSOR |
186 | 272 |
187 // Initialize frequently used symbols in the vm isolate. | 273 // Initialize frequently used symbols in the vm isolate. |
188 static void InitOnce(Isolate* isolate); | 274 static void InitOnce(Isolate* isolate); |
189 | 275 |
190 // Initialize and setup a symbol table for the isolate. | 276 // Initialize and setup a symbol table for the isolate. |
191 static void SetupSymbolTable(Isolate* isolate); | 277 static void SetupSymbolTable(Isolate* isolate); |
192 | 278 |
193 // Get number of symbols in an isolate's symbol table. | 279 // Get number of symbols in an isolate's symbol table. |
194 static intptr_t Size(Isolate* isolate); | 280 static intptr_t Size(Isolate* isolate); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
258 intptr_t hash); | 344 intptr_t hash); |
259 static intptr_t FindIndex(const Array& symbol_table, | 345 static intptr_t FindIndex(const Array& symbol_table, |
260 const String& str, | 346 const String& str, |
261 intptr_t begin_index, | 347 intptr_t begin_index, |
262 intptr_t len, | 348 intptr_t len, |
263 intptr_t hash); | 349 intptr_t hash); |
264 static intptr_t LookupVMSymbol(RawObject* obj); | 350 static intptr_t LookupVMSymbol(RawObject* obj); |
265 static RawObject* GetVMSymbol(intptr_t object_id); | 351 static RawObject* GetVMSymbol(intptr_t object_id); |
266 static bool IsVMSymbolId(intptr_t object_id) { | 352 static bool IsVMSymbolId(intptr_t object_id) { |
267 return (object_id >= kMaxPredefinedObjectIds && | 353 return (object_id >= kMaxPredefinedObjectIds && |
268 object_id < (kMaxPredefinedObjectIds + kMaxId)); | 354 object_id < (kMaxPredefinedObjectIds + kMaxPredefinedId)); |
269 } | 355 } |
270 | 356 |
271 // List of symbols that are stored in the vm isolate for easy access. | 357 // List of Latin1 characters stored in the vm isolate as symbols |
272 static RawString* predefined_[kMaxId]; | 358 // in order to make Symbols::FromCharCode fast. This structure is |
359 // used in generated dart code for direct access to these objects. | |
360 static RawString* predefined_[kNumberOfOneCharCodeSymbols]; | |
361 | |
362 // List of handles for predefined symbols. | |
363 static String* symbol_handles_[kMaxPredefinedId]; | |
273 | 364 |
274 // Statistics used to measure the efficiency of the symbol table. | 365 // Statistics used to measure the efficiency of the symbol table. |
275 static const intptr_t kMaxCollisionBuckets = 10; | 366 static const intptr_t kMaxCollisionBuckets = 10; |
276 static intptr_t num_of_grows_; | 367 static intptr_t num_of_grows_; |
277 static intptr_t collision_count_[kMaxCollisionBuckets]; | 368 static intptr_t collision_count_[kMaxCollisionBuckets]; |
278 | 369 |
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; | 370 friend class String; |
285 friend class SnapshotReader; | 371 friend class SnapshotReader; |
286 friend class SnapshotWriter; | 372 friend class SnapshotWriter; |
287 friend class ApiMessageReader; | 373 friend class ApiMessageReader; |
288 | 374 |
289 DISALLOW_COPY_AND_ASSIGN(Symbols); | 375 DISALLOW_COPY_AND_ASSIGN(Symbols); |
290 }; | 376 }; |
291 | 377 |
292 } // namespace dart | 378 } // namespace dart |
293 | 379 |
294 #endif // VM_SYMBOLS_H_ | 380 #endif // VM_SYMBOLS_H_ |
OLD | NEW |