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 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 | 217 |
218 // Returns char* of predefined symbol. | 218 // Returns char* of predefined symbol. |
219 static const char* Name(SymbolId symbol); | 219 static const char* Name(SymbolId symbol); |
220 | 220 |
221 static RawString* FromCharCode(int32_t char_code); | 221 static RawString* FromCharCode(int32_t char_code); |
222 | 222 |
223 static RawString** PredefinedAddress() { | 223 static RawString** PredefinedAddress() { |
224 return reinterpret_cast<RawString**>(&predefined_); | 224 return reinterpret_cast<RawString**>(&predefined_); |
225 } | 225 } |
226 | 226 |
227 static bool IsPredefinedHandle(uword address); | |
228 | |
229 static void DumpStats(); | 227 static void DumpStats(); |
230 | 228 |
231 private: | 229 private: |
232 enum { | 230 enum { |
233 kInitialVMIsolateSymtabSize = 512, | 231 kInitialVMIsolateSymtabSize = 512, |
234 kInitialSymtabSize = 2048 | 232 kInitialSymtabSize = 2048 |
235 }; | 233 }; |
236 | 234 |
237 // Helper functions to create a symbol given a string or set of characters. | 235 // Helper functions to create a symbol given a string or set of characters. |
238 template<typename CharacterType, typename CallbackType> | 236 template<typename CharacterType, typename CallbackType> |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 } | 269 } |
272 | 270 |
273 // List of symbols that are stored in the vm isolate for easy access. | 271 // List of symbols that are stored in the vm isolate for easy access. |
274 static RawString* predefined_[kMaxId]; | 272 static RawString* predefined_[kMaxId]; |
275 | 273 |
276 // Statistics used to measure the efficiency of the symbol table. | 274 // Statistics used to measure the efficiency of the symbol table. |
277 static const intptr_t kMaxCollisionBuckets = 10; | 275 static const intptr_t kMaxCollisionBuckets = 10; |
278 static intptr_t num_of_grows_; | 276 static intptr_t num_of_grows_; |
279 static intptr_t collision_count_[kMaxCollisionBuckets]; | 277 static intptr_t collision_count_[kMaxCollisionBuckets]; |
280 | 278 |
281 // Structure for managing handles allocation for symbols that are | |
282 // stored in the vm isolate. We don't want these handles to be | |
283 // destroyed as part of the C++ static destructors and hence this | |
284 // object is dynamically allocated. | |
285 class ReadOnlyHandles { | |
286 public: | |
287 ReadOnlyHandles() { } | |
288 uword AllocateHandle() { | |
289 return handles_.AllocateScopedHandle(); | |
290 } | |
291 bool IsValidHandle(uword address) { | |
292 return handles_.IsValidScopedHandle(address); | |
293 } | |
294 | |
295 private: | |
296 VMHandles handles_; | |
297 | |
298 DISALLOW_COPY_AND_ASSIGN(ReadOnlyHandles); | |
299 }; | |
300 static ReadOnlyHandles* predefined_handles_; | |
301 | |
302 #define DECLARE_SYMBOL_HANDLE(symbol) \ | 279 #define DECLARE_SYMBOL_HANDLE(symbol) \ |
303 static String* symbol##_handle_; | 280 static String* symbol##_handle_; |
304 PREDEFINED_SYMBOL_HANDLES_LIST(DECLARE_SYMBOL_HANDLE) | 281 PREDEFINED_SYMBOL_HANDLES_LIST(DECLARE_SYMBOL_HANDLE) |
305 #undef DECLARE_SYMBOL_HANDLE | 282 #undef DECLARE_SYMBOL_HANDLE |
306 | 283 |
307 friend class String; | 284 friend class String; |
308 friend class SnapshotReader; | 285 friend class SnapshotReader; |
309 friend class SnapshotWriter; | 286 friend class SnapshotWriter; |
310 friend class ApiMessageReader; | 287 friend class ApiMessageReader; |
311 | 288 |
312 DISALLOW_COPY_AND_ASSIGN(Symbols); | 289 DISALLOW_COPY_AND_ASSIGN(Symbols); |
313 }; | 290 }; |
314 | 291 |
315 } // namespace dart | 292 } // namespace dart |
316 | 293 |
317 #endif // VM_SYMBOLS_H_ | 294 #endif // VM_SYMBOLS_H_ |
OLD | NEW |