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 #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/hash_table.h" | 9 #include "vm/hash_table.h" |
10 #include "vm/isolate.h" | 10 #include "vm/isolate.h" |
11 #include "vm/object.h" | 11 #include "vm/object.h" |
12 #include "vm/object_store.h" | 12 #include "vm/object_store.h" |
13 #include "vm/raw_object.h" | 13 #include "vm/raw_object.h" |
| 14 #include "vm/reusable_handles.h" |
14 #include "vm/snapshot_ids.h" | 15 #include "vm/snapshot_ids.h" |
15 #include "vm/unicode.h" | 16 #include "vm/unicode.h" |
16 #include "vm/visitor.h" | 17 #include "vm/visitor.h" |
17 | 18 |
18 namespace dart { | 19 namespace dart { |
19 | 20 |
20 RawString* Symbols::predefined_[Symbols::kNumberOfOneCharCodeSymbols]; | 21 RawString* Symbols::predefined_[Symbols::kNumberOfOneCharCodeSymbols]; |
21 String* Symbols::symbol_handles_[Symbols::kMaxPredefinedId]; | 22 String* Symbols::symbol_handles_[Symbols::kMaxPredefinedId]; |
22 | 23 |
23 static const char* names[] = { | 24 static const char* names[] = { |
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
595 } | 596 } |
596 ASSERT(len_sum == buffer - orig_buffer); | 597 ASSERT(len_sum == buffer - orig_buffer); |
597 return Symbols::FromUTF16(thread, orig_buffer, len_sum); | 598 return Symbols::FromUTF16(thread, orig_buffer, len_sum); |
598 } | 599 } |
599 } | 600 } |
600 | 601 |
601 | 602 |
602 // StringType can be StringSlice, ConcatString, or {Latin1,UTF16,UTF32}Array. | 603 // StringType can be StringSlice, ConcatString, or {Latin1,UTF16,UTF32}Array. |
603 template<typename StringType> | 604 template<typename StringType> |
604 RawString* Symbols::NewSymbol(Thread* thread, const StringType& str) { | 605 RawString* Symbols::NewSymbol(Thread* thread, const StringType& str) { |
605 Zone* zone = thread->zone(); | 606 REUSABLE_OBJECT_HANDLESCOPE(thread); |
606 String& symbol = String::Handle(zone); | 607 REUSABLE_SMI_HANDLESCOPE(thread); |
| 608 REUSABLE_ARRAY_HANDLESCOPE(thread); |
| 609 String& symbol = String::Handle(thread->zone()); |
| 610 dart::Object& key = thread->ObjectHandle(); |
| 611 Smi& value = thread->SmiHandle(); |
| 612 Array& data = thread->ArrayHandle(); |
607 { | 613 { |
608 Isolate* vm_isolate = Dart::vm_isolate(); | 614 Isolate* vm_isolate = Dart::vm_isolate(); |
609 SymbolTable table(zone, vm_isolate->object_store()->symbol_table()); | 615 data ^= vm_isolate->object_store()->symbol_table(); |
| 616 SymbolTable table(&key, &value, &data); |
610 symbol ^= table.GetOrNull(str); | 617 symbol ^= table.GetOrNull(str); |
611 table.Release(); | 618 table.Release(); |
612 } | 619 } |
613 if (symbol.IsNull()) { | 620 if (symbol.IsNull()) { |
614 Isolate* isolate = thread->isolate(); | 621 Isolate* isolate = thread->isolate(); |
615 SafepointMutexLocker ml(isolate->symbols_mutex()); | 622 SafepointMutexLocker ml(isolate->symbols_mutex()); |
616 SymbolTable table(zone, isolate->object_store()->symbol_table()); | 623 data ^= isolate->object_store()->symbol_table(); |
| 624 SymbolTable table(&key, &value, &data); |
617 symbol ^= table.InsertNewOrGet(str); | 625 symbol ^= table.InsertNewOrGet(str); |
618 isolate->object_store()->set_symbol_table(table.Release()); | 626 isolate->object_store()->set_symbol_table(table.Release()); |
619 } | 627 } |
620 ASSERT(symbol.IsSymbol()); | 628 ASSERT(symbol.IsSymbol()); |
621 ASSERT(symbol.HasHash()); | 629 ASSERT(symbol.HasHash()); |
622 return symbol.raw(); | 630 return symbol.raw(); |
623 } | 631 } |
624 | 632 |
625 | 633 |
626 template<typename StringType> | 634 template<typename StringType> |
627 RawString* Symbols::Lookup(Thread* thread, const StringType& str) { | 635 RawString* Symbols::Lookup(Thread* thread, const StringType& str) { |
628 Isolate* isolate = thread->isolate(); | 636 REUSABLE_OBJECT_HANDLESCOPE(thread); |
629 Zone* zone = thread->zone(); | 637 REUSABLE_SMI_HANDLESCOPE(thread); |
630 String& symbol = String::Handle(zone); | 638 REUSABLE_ARRAY_HANDLESCOPE(thread); |
| 639 String& symbol = String::Handle(thread->zone()); |
| 640 dart::Object& key = thread->ObjectHandle(); |
| 641 Smi& value = thread->SmiHandle(); |
| 642 Array& data = thread->ArrayHandle(); |
631 { | 643 { |
632 Isolate* vm_isolate = Dart::vm_isolate(); | 644 Isolate* vm_isolate = Dart::vm_isolate(); |
633 SymbolTable table(zone, vm_isolate->object_store()->symbol_table()); | 645 data ^= vm_isolate->object_store()->symbol_table(); |
| 646 SymbolTable table(&key, &value, &data); |
634 symbol ^= table.GetOrNull(str); | 647 symbol ^= table.GetOrNull(str); |
635 table.Release(); | 648 table.Release(); |
636 } | 649 } |
637 if (symbol.IsNull()) { | 650 if (symbol.IsNull()) { |
| 651 Isolate* isolate = thread->isolate(); |
638 SafepointMutexLocker ml(isolate->symbols_mutex()); | 652 SafepointMutexLocker ml(isolate->symbols_mutex()); |
639 SymbolTable table(zone, isolate->object_store()->symbol_table()); | 653 data ^= isolate->object_store()->symbol_table(); |
| 654 SymbolTable table(&key, &value, &data); |
640 symbol ^= table.GetOrNull(str); | 655 symbol ^= table.GetOrNull(str); |
641 table.Release(); | 656 table.Release(); |
642 } | 657 } |
643 | 658 |
644 ASSERT(symbol.IsNull() || symbol.IsSymbol()); | 659 ASSERT(symbol.IsNull() || symbol.IsSymbol()); |
645 ASSERT(symbol.IsNull() || symbol.HasHash()); | 660 ASSERT(symbol.IsNull() || symbol.HasHash()); |
646 return symbol.raw(); | 661 return symbol.raw(); |
647 } | 662 } |
648 | 663 |
649 | 664 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
756 RawObject* Symbols::GetVMSymbol(intptr_t object_id) { | 771 RawObject* Symbols::GetVMSymbol(intptr_t object_id) { |
757 ASSERT(IsVMSymbolId(object_id)); | 772 ASSERT(IsVMSymbolId(object_id)); |
758 intptr_t i = (object_id - kMaxPredefinedObjectIds); | 773 intptr_t i = (object_id - kMaxPredefinedObjectIds); |
759 if ((i > kIllegal) && (i < Symbols::kMaxPredefinedId)) { | 774 if ((i > kIllegal) && (i < Symbols::kMaxPredefinedId)) { |
760 return symbol_handles_[i]->raw(); | 775 return symbol_handles_[i]->raw(); |
761 } | 776 } |
762 return Object::null(); | 777 return Object::null(); |
763 } | 778 } |
764 | 779 |
765 } // namespace dart | 780 } // namespace dart |
OLD | NEW |