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

Side by Side Diff: vm/symbols.cc

Issue 10808111: Move more symbols to the vm isolate. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 5 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
« vm/symbols.h ('K') | « vm/symbols.h ('k') | no next file » | 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/unicode.h" 11 #include "vm/unicode.h"
12 #include "vm/visitor.h" 12 #include "vm/visitor.h"
13 13
14 namespace dart { 14 namespace dart {
15 15
16 const char* Symbols::kDot = "."; 16 RawString* Symbols::predefined_[Symbols::kMaxPredefined];
17 RawString* Symbols::dot_ = String::null(); 17
18 static const char* names[] = {
19 NULL,
20
21 #define DEFINE_SYMBOL_LITERAL(symbol, literal) \
22 literal,
23 PREDEFINED_SYMBOLS_LIST(DEFINE_SYMBOL_LITERAL)
24 #undef DEFINE_SYMBOL_LITERAL
25 };
18 26
19 27
20 void Symbols::InitOnce(Isolate* isolate) { 28 void Symbols::InitOnce(Isolate* isolate) {
21 // Should only be run by the vm isolate. 29 // Should only be run by the vm isolate.
22 ASSERT(isolate == Dart::vm_isolate()); 30 ASSERT(isolate == Dart::vm_isolate());
23 31
24 // Create and setup a symbol table in the vm isolate. 32 // Create and setup a symbol table in the vm isolate.
25 SetupSymbolTable(isolate); 33 SetupSymbolTable(isolate);
26 34
27 // Create all predefined symbols. 35 // Create all predefined symbols.
36 ASSERT((sizeof(names) / sizeof(const char*)) == kMaxPredefined);
28 const Array& symbol_table = 37 const Array& symbol_table =
29 Array::Handle(isolate->object_store()->symbol_table()); 38 Array::Handle(isolate->object_store()->symbol_table());
30 OneByteString& str = OneByteString::Handle(); 39 OneByteString& str = OneByteString::Handle();
31 40
32 str = OneByteString::New(kDot, Heap::kOld); 41 for (intptr_t i = 1; i < kMaxPredefined; i++) {
33 Add(symbol_table, str); // "." 42 str = OneByteString::New(names[i], Heap::kOld);
34 dot_ = str.raw(); 43 Add(symbol_table, str);
44 predefined_[i] = str.raw();
45 }
35 } 46 }
36 47
37 48
38 void Symbols::SetupSymbolTable(Isolate* isolate) { 49 void Symbols::SetupSymbolTable(Isolate* isolate) {
39 ASSERT(isolate != NULL); 50 ASSERT(isolate != NULL);
40 51
41 // Setup the symbol table used within the String class. 52 // Setup the symbol table used within the String class.
42 const Array& array = Array::Handle(Array::New(kInitialSymbolTableSize + 1)); 53 const int initial_size = (isolate == Dart::vm_isolate()) ?
54 kInitialVMIsolateSymtabSize : kInitialSymtabSize;
55 const Array& array = Array::Handle(Array::New(initial_size + 1));
43 56
44 // Last element contains the count of used slots. 57 // Last element contains the count of used slots.
45 array.SetAt(kInitialSymbolTableSize, Smi::Handle(Smi::New(0))); 58 array.SetAt(initial_size, Smi::Handle(Smi::New(0)));
46 isolate->object_store()->set_symbol_table(array); 59 isolate->object_store()->set_symbol_table(array);
47 } 60 }
48 61
49 62
50 void Symbols::Add(const Array& symbol_table, const String& str) { 63 void Symbols::Add(const Array& symbol_table, const String& str) {
51 // Should only be run by the vm isolate. 64 // Should only be run by the vm isolate.
52 ASSERT(Isolate::Current() == Dart::vm_isolate()); 65 ASSERT(Isolate::Current() == Dart::vm_isolate());
53 intptr_t hash = str.Hash(); 66 intptr_t hash = str.Hash();
54 intptr_t index = FindIndex(symbol_table, str, 0, str.Length(), hash); 67 intptr_t index = FindIndex(symbol_table, str, 0, str.Length(), hash);
55 ASSERT(symbol_table.At(index) == String::null()); 68 ASSERT(symbol_table.At(index) == String::null());
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 String& symbol = String::Handle(); 273 String& symbol = String::Handle();
261 symbol ^= symbol_table.At(index); 274 symbol ^= symbol_table.At(index);
262 while (!symbol.IsNull() && !symbol.Equals(str, begin_index, len)) { 275 while (!symbol.IsNull() && !symbol.Equals(str, begin_index, len)) {
263 index = (index + 1) % table_size; // Move to next element. 276 index = (index + 1) % table_size; // Move to next element.
264 symbol ^= symbol_table.At(index); 277 symbol ^= symbol_table.At(index);
265 } 278 }
266 return index; // Index of symbol if found or slot into which to add symbol. 279 return index; // Index of symbol if found or slot into which to add symbol.
267 } 280 }
268 281
269 } // namespace dart 282 } // namespace dart
OLDNEW
« vm/symbols.h ('K') | « vm/symbols.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698