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

Side by Side Diff: vm/symbols.cc

Issue 11648006: Create read only handles for empty_array and sentinel objects (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years 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/unit_test.h » ('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/handles.h" 7 #include "vm/handles.h"
8 #include "vm/handles_impl.h" 8 #include "vm/handles_impl.h"
9 #include "vm/isolate.h" 9 #include "vm/isolate.h"
10 #include "vm/object.h" 10 #include "vm/object.h"
11 #include "vm/object_store.h" 11 #include "vm/object_store.h"
12 #include "vm/raw_object.h" 12 #include "vm/raw_object.h"
13 #include "vm/snapshot_ids.h" 13 #include "vm/snapshot_ids.h"
14 #include "vm/unicode.h" 14 #include "vm/unicode.h"
15 #include "vm/visitor.h" 15 #include "vm/visitor.h"
16 16
17 namespace dart { 17 namespace dart {
18 18
19 RawString* Symbols::predefined_[Symbols::kMaxId]; 19 RawString* Symbols::predefined_[Symbols::kMaxId];
20 20
21 Symbols::ReadOnlyHandles* Symbols::predefined_handles_ = NULL;
22
23 #define DEFINE_SYMBOL_HANDLE(symbol) \ 21 #define DEFINE_SYMBOL_HANDLE(symbol) \
24 String* Symbols::symbol##_handle_ = NULL; 22 String* Symbols::symbol##_handle_ = NULL;
25 PREDEFINED_SYMBOL_HANDLES_LIST(DEFINE_SYMBOL_HANDLE) 23 PREDEFINED_SYMBOL_HANDLES_LIST(DEFINE_SYMBOL_HANDLE)
26 #undef DEFINE_SYMBOL_HANDLE 24 #undef DEFINE_SYMBOL_HANDLE
27 25
28 static const char* names[] = { 26 static const char* names[] = {
29 NULL, 27 NULL,
30 28
31 #define DEFINE_SYMBOL_LITERAL(symbol, literal) \ 29 #define DEFINE_SYMBOL_LITERAL(symbol, literal) \
32 literal, 30 literal,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 Add(symbol_table, str); 72 Add(symbol_table, str);
75 predefined_[i] = str.raw(); 73 predefined_[i] = str.raw();
76 } 74 }
77 Object::RegisterSingletonClassNames(); 75 Object::RegisterSingletonClassNames();
78 76
79 for (int32_t c = 0; c <= kMaxOneCharCodeSymbol; c++) { 77 for (int32_t c = 0; c <= kMaxOneCharCodeSymbol; c++) {
80 ASSERT(kMaxPredefinedId + c < kMaxId); 78 ASSERT(kMaxPredefinedId + c < kMaxId);
81 predefined_[kMaxPredefinedId + c] = FromUTF32(&c, 1); 79 predefined_[kMaxPredefinedId + c] = FromUTF32(&c, 1);
82 } 80 }
83 81
84 predefined_handles_ = new ReadOnlyHandles();
85 #define INITIALIZE_SYMBOL_HANDLE(symbol) \ 82 #define INITIALIZE_SYMBOL_HANDLE(symbol) \
86 symbol##_handle_ = reinterpret_cast<String*>( \ 83 symbol##_handle_ = reinterpret_cast<String*>( \
87 predefined_handles_->AllocateHandle()); \ 84 Dart::AllocateReadOnlyHandle()); \
88 *symbol##_handle_ = symbol(); 85 *symbol##_handle_ = symbol();
89 PREDEFINED_SYMBOL_HANDLES_LIST(INITIALIZE_SYMBOL_HANDLE) 86 PREDEFINED_SYMBOL_HANDLES_LIST(INITIALIZE_SYMBOL_HANDLE)
90 #undef INITIALIZE_SYMBOL_HANDLE 87 #undef INITIALIZE_SYMBOL_HANDLE
91 } 88 }
92 89
93 90
94 void Symbols::SetupSymbolTable(Isolate* isolate) { 91 void Symbols::SetupSymbolTable(Isolate* isolate) {
95 ASSERT(isolate != NULL); 92 ASSERT(isolate != NULL);
96 93
97 // Setup the symbol table used within the String class. 94 // Setup the symbol table used within the String class.
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 267
271 268
272 RawString* Symbols::FromCharCode(int32_t char_code) { 269 RawString* Symbols::FromCharCode(int32_t char_code) {
273 if (char_code > kMaxOneCharCodeSymbol) { 270 if (char_code > kMaxOneCharCodeSymbol) {
274 return FromUTF32(&char_code, 1); 271 return FromUTF32(&char_code, 1);
275 } 272 }
276 return predefined_[kNullCharId + char_code]; 273 return predefined_[kNullCharId + char_code];
277 } 274 }
278 275
279 276
280 bool Symbols::IsPredefinedHandle(uword address) {
281 return predefined_handles_->IsValidHandle(address);
282 }
283
284
285 void Symbols::DumpStats() { 277 void Symbols::DumpStats() {
286 if (FLAG_dump_symbol_stats) { 278 if (FLAG_dump_symbol_stats) {
287 intptr_t table_size = 0; 279 intptr_t table_size = 0;
288 dart::Smi& used = Smi::Handle(); 280 dart::Smi& used = Smi::Handle();
289 Array& symbol_table = Array::Handle(Array::null()); 281 Array& symbol_table = Array::Handle(Array::null());
290 282
291 // First dump VM symbol table stats. 283 // First dump VM symbol table stats.
292 symbol_table = Dart::vm_isolate()->object_store()->symbol_table(); 284 symbol_table = Dart::vm_isolate()->object_store()->symbol_table();
293 table_size = symbol_table.Length() - 1; 285 table_size = symbol_table.Length() - 1;
294 used ^= symbol_table.At(table_size); 286 used ^= symbol_table.At(table_size);
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 } 442 }
451 443
452 444
453 RawObject* Symbols::GetVMSymbol(intptr_t object_id) { 445 RawObject* Symbols::GetVMSymbol(intptr_t object_id) {
454 ASSERT(IsVMSymbolId(object_id)); 446 ASSERT(IsVMSymbolId(object_id));
455 intptr_t i = (object_id - kMaxPredefinedObjectIds); 447 intptr_t i = (object_id - kMaxPredefinedObjectIds);
456 return (i > 0 && i < Symbols::kMaxId) ? predefined_[i] : Object::null(); 448 return (i > 0 && i < Symbols::kMaxId) ? predefined_[i] : Object::null();
457 } 449 }
458 450
459 } // namespace dart 451 } // namespace dart
OLDNEW
« no previous file with comments | « vm/symbols.h ('k') | vm/unit_test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698