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/object.h" | 5 #include "vm/object.h" |
6 | 6 |
7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
9 #include "vm/assembler.h" | 9 #include "vm/assembler.h" |
10 #include "vm/cpu.h" | 10 #include "vm/cpu.h" |
(...skipping 9469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9480 cache.Release(); | 9480 cache.Release(); |
9481 return present; | 9481 return present; |
9482 } | 9482 } |
9483 | 9483 |
9484 | 9484 |
9485 // Add a name to the resolved name cache. This name resolves to the | 9485 // Add a name to the resolved name cache. This name resolves to the |
9486 // given object in this library scope. obj may be null, which means | 9486 // given object in this library scope. obj may be null, which means |
9487 // the name does not resolve to anything in this library scope. | 9487 // the name does not resolve to anything in this library scope. |
9488 void Library::AddToResolvedNamesCache(const String& name, | 9488 void Library::AddToResolvedNamesCache(const String& name, |
9489 const Object& obj) const { | 9489 const Object& obj) const { |
| 9490 ASSERT(!Compiler::IsBackgroundCompilation()); |
9490 if (!FLAG_use_lib_cache) { | 9491 if (!FLAG_use_lib_cache) { |
9491 return; | 9492 return; |
9492 } | 9493 } |
9493 ResolvedNamesMap cache(resolved_names()); | 9494 ResolvedNamesMap cache(resolved_names()); |
9494 cache.UpdateOrInsert(name, obj); | 9495 cache.UpdateOrInsert(name, obj); |
9495 StorePointer(&raw_ptr()->resolved_names_, cache.Release().raw()); | 9496 StorePointer(&raw_ptr()->resolved_names_, cache.Release().raw()); |
9496 } | 9497 } |
9497 | 9498 |
9498 | 9499 |
9499 void Library::InvalidateResolvedName(const String& name) const { | 9500 void Library::InvalidateResolvedName(const String& name) const { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9538 } | 9539 } |
9539 // Copy used count. | 9540 // Copy used count. |
9540 new_entry = dict.At(dict_size); | 9541 new_entry = dict.At(dict_size); |
9541 new_dict.SetAt(new_dict_size, new_entry); | 9542 new_dict.SetAt(new_dict_size, new_entry); |
9542 // Remember the new dictionary now. | 9543 // Remember the new dictionary now. |
9543 StorePointer(&raw_ptr()->dictionary_, new_dict.raw()); | 9544 StorePointer(&raw_ptr()->dictionary_, new_dict.raw()); |
9544 } | 9545 } |
9545 | 9546 |
9546 | 9547 |
9547 void Library::AddObject(const Object& obj, const String& name) const { | 9548 void Library::AddObject(const Object& obj, const String& name) const { |
| 9549 ASSERT(!Compiler::IsBackgroundCompilation()); |
9548 ASSERT(obj.IsClass() || | 9550 ASSERT(obj.IsClass() || |
9549 obj.IsFunction() || | 9551 obj.IsFunction() || |
9550 obj.IsField() || | 9552 obj.IsField() || |
9551 obj.IsLibraryPrefix()); | 9553 obj.IsLibraryPrefix()); |
9552 ASSERT(name.Equals(String::Handle(obj.DictionaryName()))); | 9554 ASSERT(name.Equals(String::Handle(obj.DictionaryName()))); |
9553 ASSERT(LookupLocalObject(name) == Object::null()); | 9555 ASSERT(LookupLocalObject(name) == Object::null()); |
9554 const Array& dict = Array::Handle(dictionary()); | 9556 const Array& dict = Array::Handle(dictionary()); |
9555 intptr_t dict_size = dict.Length() - 1; | 9557 intptr_t dict_size = dict.Length() - 1; |
9556 intptr_t index = name.Hash() % dict_size; | 9558 intptr_t index = name.Hash() % dict_size; |
9557 | 9559 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9644 return entry.raw(); | 9646 return entry.raw(); |
9645 } | 9647 } |
9646 *index = (*index + 1) % dict_size; | 9648 *index = (*index + 1) % dict_size; |
9647 entry = dict.At(*index); | 9649 entry = dict.At(*index); |
9648 } | 9650 } |
9649 return Object::null(); | 9651 return Object::null(); |
9650 } | 9652 } |
9651 | 9653 |
9652 | 9654 |
9653 void Library::ReplaceObject(const Object& obj, const String& name) const { | 9655 void Library::ReplaceObject(const Object& obj, const String& name) const { |
| 9656 ASSERT(!Compiler::IsBackgroundCompilation()); |
9654 ASSERT(obj.IsClass() || obj.IsFunction() || obj.IsField()); | 9657 ASSERT(obj.IsClass() || obj.IsFunction() || obj.IsField()); |
9655 ASSERT(LookupLocalObject(name) != Object::null()); | 9658 ASSERT(LookupLocalObject(name) != Object::null()); |
9656 | 9659 |
9657 intptr_t index; | 9660 intptr_t index; |
9658 LookupEntry(name, &index); | 9661 LookupEntry(name, &index); |
9659 // The value is guaranteed to be found. | 9662 // The value is guaranteed to be found. |
9660 const Array& dict = Array::Handle(dictionary()); | 9663 const Array& dict = Array::Handle(dictionary()); |
9661 dict.SetAt(index, obj); | 9664 dict.SetAt(index, obj); |
9662 } | 9665 } |
9663 | 9666 |
9664 | 9667 |
9665 bool Library::RemoveObject(const Object& obj, const String& name) const { | 9668 bool Library::RemoveObject(const Object& obj, const String& name) const { |
| 9669 ASSERT(!Compiler::IsBackgroundCompilation()); |
9666 Object& entry = Object::Handle(); | 9670 Object& entry = Object::Handle(); |
9667 | 9671 |
9668 intptr_t index; | 9672 intptr_t index; |
9669 entry = LookupEntry(name, &index); | 9673 entry = LookupEntry(name, &index); |
9670 if (entry.raw() != obj.raw()) { | 9674 if (entry.raw() != obj.raw()) { |
9671 return false; | 9675 return false; |
9672 } | 9676 } |
9673 | 9677 |
9674 const Array& dict = Array::Handle(dictionary()); | 9678 const Array& dict = Array::Handle(dictionary()); |
9675 dict.SetAt(index, Object::null_object()); | 9679 dict.SetAt(index, Object::null_object()); |
(...skipping 25 matching lines...) Expand all Loading... |
9701 intptr_t used_elements = Smi::Value(Smi::RawCast(dict.At(dict_size))) - 1; | 9705 intptr_t used_elements = Smi::Value(Smi::RawCast(dict.At(dict_size))) - 1; |
9702 dict.SetAt(dict_size, Smi::Handle(Smi::New(used_elements))); | 9706 dict.SetAt(dict_size, Smi::Handle(Smi::New(used_elements))); |
9703 | 9707 |
9704 InvalidateResolvedNamesCache(); | 9708 InvalidateResolvedNamesCache(); |
9705 | 9709 |
9706 return true; | 9710 return true; |
9707 } | 9711 } |
9708 | 9712 |
9709 | 9713 |
9710 void Library::AddClass(const Class& cls) const { | 9714 void Library::AddClass(const Class& cls) const { |
| 9715 ASSERT(!Compiler::IsBackgroundCompilation()); |
9711 const String& class_name = String::Handle(cls.Name()); | 9716 const String& class_name = String::Handle(cls.Name()); |
9712 AddObject(cls, class_name); | 9717 AddObject(cls, class_name); |
9713 // Link class to this library. | 9718 // Link class to this library. |
9714 cls.set_library(*this); | 9719 cls.set_library(*this); |
9715 InvalidateResolvedName(class_name); | 9720 InvalidateResolvedName(class_name); |
9716 } | 9721 } |
9717 | 9722 |
| 9723 |
9718 static void AddScriptIfUnique(const GrowableObjectArray& scripts, | 9724 static void AddScriptIfUnique(const GrowableObjectArray& scripts, |
9719 const Script& candidate) { | 9725 const Script& candidate) { |
9720 if (candidate.IsNull()) { | 9726 if (candidate.IsNull()) { |
9721 return; | 9727 return; |
9722 } | 9728 } |
9723 Script& script_obj = Script::Handle(); | 9729 Script& script_obj = Script::Handle(); |
9724 | 9730 |
9725 for (int i = 0; i < scripts.Length(); i++) { | 9731 for (int i = 0; i < scripts.Length(); i++) { |
9726 script_obj ^= scripts.At(i); | 9732 script_obj ^= scripts.At(i); |
9727 if (script_obj.raw() == candidate.raw()) { | 9733 if (script_obj.raw() == candidate.raw()) { |
9728 // We already have a reference to this script. | 9734 // We already have a reference to this script. |
9729 return; | 9735 return; |
9730 } | 9736 } |
9731 } | 9737 } |
9732 // Add script to the list of scripts. | 9738 // Add script to the list of scripts. |
9733 scripts.Add(candidate); | 9739 scripts.Add(candidate); |
9734 } | 9740 } |
9735 | 9741 |
| 9742 |
9736 RawArray* Library::LoadedScripts() const { | 9743 RawArray* Library::LoadedScripts() const { |
9737 // We compute the list of loaded scripts lazily. The result is | 9744 // We compute the list of loaded scripts lazily. The result is |
9738 // cached in loaded_scripts_. | 9745 // cached in loaded_scripts_. |
9739 if (loaded_scripts() == Array::null()) { | 9746 if (loaded_scripts() == Array::null()) { |
9740 // Iterate over the library dictionary and collect all scripts. | 9747 // Iterate over the library dictionary and collect all scripts. |
9741 const GrowableObjectArray& scripts = | 9748 const GrowableObjectArray& scripts = |
9742 GrowableObjectArray::Handle(GrowableObjectArray::New(8)); | 9749 GrowableObjectArray::Handle(GrowableObjectArray::New(8)); |
9743 Object& entry = Object::Handle(); | 9750 Object& entry = Object::Handle(); |
9744 Class& cls = Class::Handle(); | 9751 Class& cls = Class::Handle(); |
9745 Script& owner_script = Script::Handle(); | 9752 Script& owner_script = Script::Handle(); |
(...skipping 12128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
21874 return UserTag::null(); | 21881 return UserTag::null(); |
21875 } | 21882 } |
21876 | 21883 |
21877 | 21884 |
21878 const char* UserTag::ToCString() const { | 21885 const char* UserTag::ToCString() const { |
21879 const String& tag_label = String::Handle(label()); | 21886 const String& tag_label = String::Handle(label()); |
21880 return tag_label.ToCString(); | 21887 return tag_label.ToCString(); |
21881 } | 21888 } |
21882 | 21889 |
21883 } // namespace dart | 21890 } // namespace dart |
OLD | NEW |