Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(46)

Side by Side Diff: vm/symbols.cc

Issue 10827209: Unify class ids and snapshot object ids list so that we don't have disparate and sometimes confusin… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « vm/symbols.h ('k') | vm/vm_sources.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "vm/symbols.h" 5 #include "vm/symbols.h"
6 6
7 #include "vm/isolate.h" 7 #include "vm/isolate.h"
8 #include "vm/object.h" 8 #include "vm/object.h"
9 #include "vm/object_store.h" 9 #include "vm/object_store.h"
10 #include "vm/raw_object.h" 10 #include "vm/raw_object.h"
11 #include "vm/snapshot_ids.h"
11 #include "vm/unicode.h" 12 #include "vm/unicode.h"
12 #include "vm/visitor.h" 13 #include "vm/visitor.h"
13 14
14 namespace dart { 15 namespace dart {
15 16
16 RawString* Symbols::predefined_[Symbols::kMaxPredefined]; 17 RawString* Symbols::predefined_[Symbols::kMaxId];
17 18
18 // Turn off population of symbols in the VM symbol table, so that we 19 // Turn off population of symbols in the VM symbol table, so that we
19 // don't find these symbols while doing a Symbols::New(...). 20 // don't find these symbols while doing a Symbols::New(...).
20 static const char* names[] = { 21 static const char* names[] = {
21 NULL, 22 NULL,
22 23
23 #define DEFINE_SYMBOL_LITERAL(symbol, literal) \ 24 #define DEFINE_SYMBOL_LITERAL(symbol, literal) \
24 literal, 25 literal,
25 PREDEFINED_SYMBOLS_LIST(DEFINE_SYMBOL_LITERAL) 26 PREDEFINED_SYMBOLS_LIST(DEFINE_SYMBOL_LITERAL)
26 #undef DEFINE_SYMBOL_LITERAL 27 #undef DEFINE_SYMBOL_LITERAL
27 }; 28 };
28 29
29 30
30 void Symbols::InitOnce(Isolate* isolate) { 31 void Symbols::InitOnce(Isolate* isolate) {
31 // Should only be run by the vm isolate. 32 // Should only be run by the vm isolate.
32 ASSERT(isolate == Dart::vm_isolate()); 33 ASSERT(isolate == Dart::vm_isolate());
33 34
34 // Create and setup a symbol table in the vm isolate. 35 // Create and setup a symbol table in the vm isolate.
35 SetupSymbolTable(isolate); 36 SetupSymbolTable(isolate);
36 37
37 // Turn off population of symbols in the VM symbol table, so that we 38 // Turn off population of symbols in the VM symbol table, so that we
38 // don't find these symbols while doing a Symbols::New(...). 39 // don't find these symbols while doing a Symbols::New(...).
39 // Create all predefined symbols. 40 // Create all predefined symbols.
40 ASSERT((sizeof(names) / sizeof(const char*)) == kMaxPredefined); 41 ASSERT((sizeof(names) / sizeof(const char*)) == Symbols::kMaxId);
41 const Array& symbol_table = 42 const Array& symbol_table =
42 Array::Handle(isolate->object_store()->symbol_table()); 43 Array::Handle(isolate->object_store()->symbol_table());
43 OneByteString& str = OneByteString::Handle(); 44 OneByteString& str = OneByteString::Handle();
44 45
45 for (intptr_t i = 1; i < kMaxPredefined; i++) { 46 for (intptr_t i = 1; i < Symbols::kMaxId; i++) {
46 str = OneByteString::New(names[i], Heap::kOld); 47 str = OneByteString::New(names[i], Heap::kOld);
47 Add(symbol_table, str); 48 Add(symbol_table, str);
48 predefined_[i] = str.raw(); 49 predefined_[i] = str.raw();
49 } 50 }
50 } 51 }
51 52
52 53
53 void Symbols::SetupSymbolTable(Isolate* isolate) { 54 void Symbols::SetupSymbolTable(Isolate* isolate) {
54 ASSERT(isolate != NULL); 55 ASSERT(isolate != NULL);
55 56
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 symbol ^= symbol_table.At(index); 289 symbol ^= symbol_table.At(index);
289 while (!symbol.IsNull() && !symbol.Equals(str, begin_index, len)) { 290 while (!symbol.IsNull() && !symbol.Equals(str, begin_index, len)) {
290 index = (index + 1) % table_size; // Move to next element. 291 index = (index + 1) % table_size; // Move to next element.
291 symbol ^= symbol_table.At(index); 292 symbol ^= symbol_table.At(index);
292 } 293 }
293 return index; // Index of symbol if found or slot into which to add symbol. 294 return index; // Index of symbol if found or slot into which to add symbol.
294 } 295 }
295 296
296 297
297 intptr_t Symbols::LookupVMSymbol(RawObject* obj) { 298 intptr_t Symbols::LookupVMSymbol(RawObject* obj) {
298 for (intptr_t i = 1; i < kMaxPredefined; i++) { 299 for (intptr_t i = 1; i < Symbols::kMaxId; i++) {
299 if (predefined_[i] == obj) { 300 if (predefined_[i] == obj) {
300 return (i + Object::kMaxId); 301 return (i + kMaxPredefinedObjectIds);
301 } 302 }
302 } 303 }
303 return Object::kInvalidIndex; 304 return kInvalidIndex;
304 } 305 }
305 306
306 307
307 RawObject* Symbols::GetVMSymbol(intptr_t object_id) { 308 RawObject* Symbols::GetVMSymbol(intptr_t object_id) {
308 ASSERT(IsVMSymbolId(object_id)); 309 ASSERT(IsVMSymbolId(object_id));
309 intptr_t i = (object_id - Object::kMaxId); 310 intptr_t i = (object_id - kMaxPredefinedObjectIds);
310 return (i > 0 && i < kMaxPredefined) ? predefined_[i] : Object::null(); 311 return (i > 0 && i < Symbols::kMaxId) ? predefined_[i] : Object::null();
311 } 312 }
312 313
313 } // namespace dart 314 } // namespace dart
OLDNEW
« no previous file with comments | « vm/symbols.h ('k') | vm/vm_sources.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698