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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
50 "Huge method cutoff in unoptimized code size (in bytes)."); | 50 "Huge method cutoff in unoptimized code size (in bytes)."); |
51 DEFINE_FLAG(int, huge_method_cutoff_in_tokens, 20000, | 51 DEFINE_FLAG(int, huge_method_cutoff_in_tokens, 20000, |
52 "Huge method cutoff in tokens: Disables optimizations for huge methods."); | 52 "Huge method cutoff in tokens: Disables optimizations for huge methods."); |
53 DEFINE_FLAG(bool, overlap_type_arguments, true, | 53 DEFINE_FLAG(bool, overlap_type_arguments, true, |
54 "When possible, partially or fully overlap the type arguments of a type " | 54 "When possible, partially or fully overlap the type arguments of a type " |
55 "with the type arguments of its super type."); | 55 "with the type arguments of its super type."); |
56 DEFINE_FLAG(bool, show_internal_names, false, | 56 DEFINE_FLAG(bool, show_internal_names, false, |
57 "Show names of internal classes (e.g. \"OneByteString\") in error messages " | 57 "Show names of internal classes (e.g. \"OneByteString\") in error messages " |
58 "instead of showing the corresponding interface names (e.g. \"String\")"); | 58 "instead of showing the corresponding interface names (e.g. \"String\")"); |
59 DEFINE_FLAG(bool, use_lib_cache, true, "Use library name cache"); | 59 DEFINE_FLAG(bool, use_lib_cache, true, "Use library name cache"); |
60 DEFINE_FLAG(bool, use_exp_cache, true, "Use library exported name cache"); | |
srdjan
2016/04/18 22:40:49
use_exported_name_cache sounds more readable than
Ivan Posva
2016/04/18 23:07:21
In the future please add new flags to the flag_lis
hausner
2016/04/18 23:51:58
Yes, I consider the flag temporary.
hausner
2016/04/18 23:51:58
More readable maybe, but I'm not sure it is more u
srdjan
2016/04/26 21:09:42
The flag is temporary, your choice.
| |
60 DEFINE_FLAG(bool, ignore_patch_signature_mismatch, false, | 61 DEFINE_FLAG(bool, ignore_patch_signature_mismatch, false, |
61 "Ignore patch file member signature mismatch."); | 62 "Ignore patch file member signature mismatch."); |
62 | 63 |
63 DECLARE_FLAG(bool, show_invisible_frames); | 64 DECLARE_FLAG(bool, show_invisible_frames); |
64 DECLARE_FLAG(bool, trace_deoptimization); | 65 DECLARE_FLAG(bool, trace_deoptimization); |
65 DECLARE_FLAG(bool, trace_deoptimization_verbose); | 66 DECLARE_FLAG(bool, trace_deoptimization_verbose); |
66 DECLARE_FLAG(bool, write_protect_code); | 67 DECLARE_FLAG(bool, write_protect_code); |
67 DECLARE_FLAG(bool, support_externalizable_strings); | 68 DECLARE_FLAG(bool, support_externalizable_strings); |
68 | 69 |
69 | 70 |
(...skipping 9546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
9616 #endif | 9617 #endif |
9617 return present; | 9618 return present; |
9618 } | 9619 } |
9619 | 9620 |
9620 | 9621 |
9621 // Add a name to the resolved name cache. This name resolves to the | 9622 // Add a name to the resolved name cache. This name resolves to the |
9622 // given object in this library scope. obj may be null, which means | 9623 // given object in this library scope. obj may be null, which means |
9623 // the name does not resolve to anything in this library scope. | 9624 // the name does not resolve to anything in this library scope. |
9624 void Library::AddToResolvedNamesCache(const String& name, | 9625 void Library::AddToResolvedNamesCache(const String& name, |
9625 const Object& obj) const { | 9626 const Object& obj) const { |
9626 ASSERT(!Compiler::IsBackgroundCompilation()); | 9627 if (!FLAG_use_lib_cache || Compiler::IsBackgroundCompilation()) { |
srdjan
2016/04/18 22:40:48
Why are we starting to call AddToResolvedNamesCach
hausner
2016/04/18 23:51:58
No change here, but I think it is possible that th
| |
9627 if (!FLAG_use_lib_cache) { | |
9628 return; | 9628 return; |
9629 } | 9629 } |
9630 ResolvedNamesMap cache(resolved_names()); | 9630 ResolvedNamesMap cache(resolved_names()); |
9631 cache.UpdateOrInsert(name, obj); | 9631 cache.UpdateOrInsert(name, obj); |
9632 StorePointer(&raw_ptr()->resolved_names_, cache.Release().raw()); | 9632 StorePointer(&raw_ptr()->resolved_names_, cache.Release().raw()); |
9633 } | 9633 } |
9634 | 9634 |
9635 | 9635 |
9636 bool Library::LookupExportedNamesCache(const String& name, | |
9637 Object* obj) const { | |
9638 ASSERT(FLAG_use_exp_cache); | |
9639 if (exported_names() == Array::null()) { | |
9640 return false; | |
9641 } | |
9642 ResolvedNamesMap cache(exported_names()); | |
9643 bool present = false; | |
9644 *obj = cache.GetOrNull(name, &present); | |
9645 // Mutator compiler thread may add entries and therefore | |
9646 // change 'resolved_names()' while running a background compilation; | |
srdjan
2016/04/18 22:40:49
s/resolved_names/exported_names/
hausner
2016/04/18 23:51:58
Done.
| |
9647 // do not ASSERT that 'exported_names()' has not changed. | |
9648 cache.Release(); | |
srdjan
2016/04/18 22:40:49
You may want to the same as in LookupResolvedNames
hausner
2016/04/18 23:51:58
Done.
| |
9649 return present; | |
9650 } | |
9651 | |
9652 void Library::AddToExportedNamesCache(const String& name, | |
9653 const Object& obj) const { | |
9654 ASSERT(!Compiler::IsBackgroundCompilation()); | |
9655 if (!FLAG_use_exp_cache || Compiler::IsBackgroundCompilation()) { | |
srdjan
2016/04/18 22:40:48
Why tests for background compilation when assertin
hausner
2016/04/18 23:51:58
Ok, assertion removed.
| |
9656 return; | |
9657 } | |
9658 if (exported_names() == Array::null()) { | |
9659 AllocateExportedNamesCache(); | |
9660 } | |
9661 ResolvedNamesMap cache(exported_names()); | |
9662 cache.UpdateOrInsert(name, obj); | |
9663 StorePointer(&raw_ptr()->exported_names_, cache.Release().raw()); | |
9664 } | |
9665 | |
9666 | |
9636 void Library::InvalidateResolvedName(const String& name) const { | 9667 void Library::InvalidateResolvedName(const String& name) const { |
srdjan
2016/04/18 22:40:49
You may want to:
Thread* thread = Thread::Current
srdjan
2016/04/18 22:40:49
ASSERT(FLAG_use_exp_cache)
hausner
2016/04/18 23:51:58
the flags for resolved name cache and exported nam
hausner
2016/04/18 23:51:58
Done.
| |
9637 Object& entry = Object::Handle(); | 9668 Object& entry = Object::Handle(); |
9638 if (LookupResolvedNamesCache(name, &entry)) { | 9669 if (LookupResolvedNamesCache(name, &entry)) { |
9639 // TODO(koda): Support deleted sentinel in snapshots and remove only 'name'. | 9670 // TODO(koda): Support deleted sentinel in snapshots and remove only 'name'. |
9640 InvalidateResolvedNamesCache(); | 9671 InvalidateResolvedNamesCache(); |
9641 } | 9672 } |
9673 GrowableObjectArray& libs = GrowableObjectArray::Handle( | |
Ivan Posva
2016/04/18 23:07:21
Please add a comment how we can get into a state w
hausner
2016/04/18 23:51:58
Done.
| |
9674 Isolate::Current()->object_store()->libraries()); | |
9675 Library& lib = Library::Handle(); | |
9676 intptr_t num_libs = libs.Length(); | |
9677 for (intptr_t i = 0; i < num_libs; i++) { | |
9678 lib ^= libs.At(i); | |
9679 if (LookupExportedNamesCache(name, &entry)) { | |
9680 InitExportedNamesCache(); | |
9681 } | |
9682 } | |
9642 } | 9683 } |
9643 | 9684 |
9644 | 9685 |
9645 void Library::InvalidateResolvedNamesCache() const { | 9686 void Library::InvalidateResolvedNamesCache() const { |
9646 const intptr_t kInvalidatedCacheSize = 16; | 9687 const intptr_t kInvalidatedCacheSize = 16; |
9647 InitResolvedNamesCache(kInvalidatedCacheSize); | 9688 InitResolvedNamesCache(kInvalidatedCacheSize); |
9648 } | 9689 } |
9649 | 9690 |
9650 | 9691 |
9692 // Invalidate all exported names caches in the isolate. | |
9693 void Library::InvalidateExportedNamesCaches() { | |
9694 GrowableObjectArray& libs = GrowableObjectArray::Handle( | |
9695 Isolate::Current()->object_store()->libraries()); | |
9696 Library& lib = Library::Handle(); | |
9697 intptr_t num_libs = libs.Length(); | |
9698 for (intptr_t i = 0; i < num_libs; i++) { | |
9699 lib ^= libs.At(i); | |
9700 lib.InitExportedNamesCache(); | |
9701 } | |
9702 } | |
9703 | |
9704 | |
9651 void Library::GrowDictionary(const Array& dict, intptr_t dict_size) const { | 9705 void Library::GrowDictionary(const Array& dict, intptr_t dict_size) const { |
9652 // TODO(iposva): Avoid exponential growth. | 9706 // TODO(iposva): Avoid exponential growth. |
9653 intptr_t new_dict_size = dict_size * 2; | 9707 intptr_t new_dict_size = dict_size * 2; |
9654 const Array& new_dict = | 9708 const Array& new_dict = |
9655 Array::Handle(Array::New(new_dict_size + 1, Heap::kOld)); | 9709 Array::Handle(Array::New(new_dict_size + 1, Heap::kOld)); |
9656 // Rehash all elements from the original dictionary | 9710 // Rehash all elements from the original dictionary |
9657 // to the newly allocated array. | 9711 // to the newly allocated array. |
9658 Object& entry = Class::Handle(); | 9712 Object& entry = Class::Handle(); |
9659 String& entry_name = String::Handle(); | 9713 String& entry_name = String::Handle(); |
9660 Object& new_entry = Object::Handle(); | 9714 Object& new_entry = Object::Handle(); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
9716 // Invalidate the cache of loaded scripts. | 9770 // Invalidate the cache of loaded scripts. |
9717 if (loaded_scripts() != Array::null()) { | 9771 if (loaded_scripts() != Array::null()) { |
9718 StorePointer(&raw_ptr()->loaded_scripts_, Array::null()); | 9772 StorePointer(&raw_ptr()->loaded_scripts_, Array::null()); |
9719 } | 9773 } |
9720 } | 9774 } |
9721 | 9775 |
9722 | 9776 |
9723 // Lookup a name in the library's re-export namespace. | 9777 // Lookup a name in the library's re-export namespace. |
9724 // This lookup can occur from two different threads: background compiler and | 9778 // This lookup can occur from two different threads: background compiler and |
9725 // mutator thread. | 9779 // mutator thread. |
9726 RawObject* Library::LookupReExport(const String& name) const { | 9780 RawObject* Library::LookupReExport(const String& name, |
9727 if (HasExports()) { | 9781 ZoneGrowableArray<intptr_t>* trail) const { |
9728 const bool is_background_compiler = Compiler::IsBackgroundCompilation(); | 9782 if (!HasExports()) { |
9729 Array& exports = Array::Handle(); | 9783 return Object::null(); |
9730 if (is_background_compiler) { | 9784 } |
9731 exports = this->exports2(); | 9785 |
9732 // Break potential export cycle while looking up name. | 9786 if (trail == NULL) { |
9733 StorePointer(&raw_ptr()->exports2_, Object::empty_array().raw()); | 9787 trail = new ZoneGrowableArray<intptr_t>(); |
9734 } else { | 9788 } |
9735 exports = this->exports(); | 9789 Object& obj = Object::Handle(); |
9736 // Break potential export cycle while looking up name. | 9790 if (FLAG_use_exp_cache && LookupExportedNamesCache(name, &obj)) { |
9737 StorePointer(&raw_ptr()->exports_, Object::empty_array().raw()); | 9791 return obj.raw(); |
9738 } | 9792 } |
9739 Namespace& ns = Namespace::Handle(); | 9793 |
9740 Object& obj = Object::Handle(); | 9794 const intptr_t lib_id = this->index(); |
9741 for (int i = 0; i < exports.Length(); i++) { | 9795 ASSERT(lib_id >= 0); // We use -1 to indicate that a cycle was found. |
9742 ns ^= exports.At(i); | 9796 trail->Add(lib_id); |
9743 obj = ns.Lookup(name); | 9797 const Array& exports = Array::Handle(this->exports()); |
9744 if (!obj.IsNull()) { | 9798 Namespace& ns = Namespace::Handle(); |
9745 // The Lookup call above may return a setter x= when we are looking | 9799 for (int i = 0; i < exports.Length(); i++) { |
9746 // for the name x. Make sure we only return when a matching name | 9800 ns ^= exports.At(i); |
9747 // is found. | 9801 obj = ns.Lookup(name, trail); |
9748 String& obj_name = String::Handle(obj.DictionaryName()); | 9802 if (!obj.IsNull()) { |
9749 if (Field::IsSetterName(obj_name) == Field::IsSetterName(name)) { | 9803 // The Lookup call above may return a setter x= when we are looking |
9750 break; | 9804 // for the name x. Make sure we only return when a matching name |
9751 } | 9805 // is found. |
9806 String& obj_name = String::Handle(obj.DictionaryName()); | |
9807 if (Field::IsSetterName(obj_name) == Field::IsSetterName(name)) { | |
9808 break; | |
9752 } | 9809 } |
9753 } | 9810 } |
9754 if (is_background_compiler) { | |
9755 StorePointer(&raw_ptr()->exports2_, exports.raw()); | |
9756 } else { | |
9757 StorePointer(&raw_ptr()->exports_, exports.raw()); | |
9758 } | |
9759 return obj.raw(); | |
9760 } | 9811 } |
9761 return Object::null(); | 9812 bool in_cycle = (trail->RemoveLast() < 0); |
9813 if (FLAG_use_exp_cache && | |
9814 !in_cycle && | |
9815 !Compiler::IsBackgroundCompilation()) { | |
9816 AddToExportedNamesCache(name, obj); | |
9817 } | |
9818 return obj.raw(); | |
9762 } | 9819 } |
9763 | 9820 |
9764 | 9821 |
9765 RawObject* Library::LookupEntry(const String& name, intptr_t *index) const { | 9822 RawObject* Library::LookupEntry(const String& name, intptr_t *index) const { |
9766 Thread* thread = Thread::Current(); | 9823 Thread* thread = Thread::Current(); |
9767 REUSABLE_ARRAY_HANDLESCOPE(thread); | 9824 REUSABLE_ARRAY_HANDLESCOPE(thread); |
9768 REUSABLE_OBJECT_HANDLESCOPE(thread); | 9825 REUSABLE_OBJECT_HANDLESCOPE(thread); |
9769 REUSABLE_STRING_HANDLESCOPE(thread); | 9826 REUSABLE_STRING_HANDLESCOPE(thread); |
9770 Array& dict = thread->ArrayHandle(); | 9827 Array& dict = thread->ArrayHandle(); |
9771 dict ^= dictionary(); | 9828 dict ^= dictionary(); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
9837 dict.SetAt(new_index, entry); | 9894 dict.SetAt(new_index, entry); |
9838 dict.SetAt(index, Object::null_object()); | 9895 dict.SetAt(index, Object::null_object()); |
9839 } | 9896 } |
9840 } | 9897 } |
9841 | 9898 |
9842 // Update used count. | 9899 // Update used count. |
9843 intptr_t used_elements = Smi::Value(Smi::RawCast(dict.At(dict_size))) - 1; | 9900 intptr_t used_elements = Smi::Value(Smi::RawCast(dict.At(dict_size))) - 1; |
9844 dict.SetAt(dict_size, Smi::Handle(zone, Smi::New(used_elements))); | 9901 dict.SetAt(dict_size, Smi::Handle(zone, Smi::New(used_elements))); |
9845 | 9902 |
9846 InvalidateResolvedNamesCache(); | 9903 InvalidateResolvedNamesCache(); |
9904 InvalidateExportedNamesCaches(); | |
9847 | 9905 |
9848 return true; | 9906 return true; |
9849 } | 9907 } |
9850 | 9908 |
9851 | 9909 |
9852 void Library::AddClass(const Class& cls) const { | 9910 void Library::AddClass(const Class& cls) const { |
9853 ASSERT(!Compiler::IsBackgroundCompilation()); | 9911 ASSERT(!Compiler::IsBackgroundCompilation()); |
9854 const String& class_name = String::Handle(cls.Name()); | 9912 const String& class_name = String::Handle(cls.Name()); |
9855 AddObject(cls, class_name); | 9913 AddObject(cls, class_name); |
9856 // Link class to this library. | 9914 // Link class to this library. |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
10203 } | 10261 } |
10204 } | 10262 } |
10205 } | 10263 } |
10206 return false; | 10264 return false; |
10207 } | 10265 } |
10208 | 10266 |
10209 | 10267 |
10210 void Library::DropDependencies() const { | 10268 void Library::DropDependencies() const { |
10211 StorePointer(&raw_ptr()->imports_, Array::null()); | 10269 StorePointer(&raw_ptr()->imports_, Array::null()); |
10212 StorePointer(&raw_ptr()->exports_, Array::null()); | 10270 StorePointer(&raw_ptr()->exports_, Array::null()); |
10213 StorePointer(&raw_ptr()->exports2_, Array::null()); | |
10214 } | 10271 } |
10215 | 10272 |
10216 | 10273 |
10217 void Library::AddImport(const Namespace& ns) const { | 10274 void Library::AddImport(const Namespace& ns) const { |
10218 Array& imports = Array::Handle(this->imports()); | 10275 Array& imports = Array::Handle(this->imports()); |
10219 intptr_t capacity = imports.Length(); | 10276 intptr_t capacity = imports.Length(); |
10220 if (num_imports() == capacity) { | 10277 if (num_imports() == capacity) { |
10221 capacity = capacity + kImportsCapacityIncrement; | 10278 capacity = capacity + kImportsCapacityIncrement; |
10222 imports = Array::Grow(imports, capacity); | 10279 imports = Array::Grow(imports, capacity); |
10223 StorePointer(&raw_ptr()->imports_, imports.raw()); | 10280 StorePointer(&raw_ptr()->imports_, imports.raw()); |
(...skipping 12 matching lines...) Expand all Loading... | |
10236 | 10293 |
10237 | 10294 |
10238 // We add one namespace at a time to the exports array and don't | 10295 // We add one namespace at a time to the exports array and don't |
10239 // pre-allocate any unused capacity. The assumption is that | 10296 // pre-allocate any unused capacity. The assumption is that |
10240 // re-exports are quite rare. | 10297 // re-exports are quite rare. |
10241 void Library::AddExport(const Namespace& ns) const { | 10298 void Library::AddExport(const Namespace& ns) const { |
10242 Array &exports = Array::Handle(this->exports()); | 10299 Array &exports = Array::Handle(this->exports()); |
10243 intptr_t num_exports = exports.Length(); | 10300 intptr_t num_exports = exports.Length(); |
10244 exports = Array::Grow(exports, num_exports + 1); | 10301 exports = Array::Grow(exports, num_exports + 1); |
10245 StorePointer(&raw_ptr()->exports_, exports.raw()); | 10302 StorePointer(&raw_ptr()->exports_, exports.raw()); |
10246 StorePointer(&raw_ptr()->exports2_, exports.raw()); | |
10247 exports.SetAt(num_exports, ns); | 10303 exports.SetAt(num_exports, ns); |
10248 } | 10304 } |
10249 | 10305 |
10250 | 10306 |
10251 static RawArray* NewDictionary(intptr_t initial_size) { | 10307 static RawArray* NewDictionary(intptr_t initial_size) { |
10252 const Array& dict = Array::Handle(Array::New(initial_size + 1, Heap::kOld)); | 10308 const Array& dict = Array::Handle(Array::New(initial_size + 1, Heap::kOld)); |
10253 // The last element of the dictionary specifies the number of in use slots. | 10309 // The last element of the dictionary specifies the number of in use slots. |
10254 dict.SetAt(initial_size, Smi::Handle(Smi::New(0))); | 10310 dict.SetAt(initial_size, Smi::Handle(Smi::New(0))); |
10255 return dict.raw(); | 10311 return dict.raw(); |
10256 } | 10312 } |
10257 | 10313 |
10258 | 10314 |
10259 void Library::InitResolvedNamesCache(intptr_t size, | 10315 void Library::InitResolvedNamesCache(intptr_t size, |
10260 SnapshotReader* reader) const { | 10316 SnapshotReader* reader) const { |
10261 ASSERT(Thread::Current()->IsMutatorThread()); | 10317 ASSERT(Thread::Current()->IsMutatorThread()); |
10262 if (reader == NULL) { | 10318 if (reader == NULL) { |
10263 StorePointer(&raw_ptr()->resolved_names_, | 10319 StorePointer(&raw_ptr()->resolved_names_, |
10264 HashTables::New<ResolvedNamesMap>(size)); | 10320 HashTables::New<ResolvedNamesMap>(size)); |
10265 } else { | 10321 } else { |
10266 intptr_t len = ResolvedNamesMap::ArrayLengthForNumOccupied(size); | 10322 intptr_t len = ResolvedNamesMap::ArrayLengthForNumOccupied(size); |
10267 *reader->ArrayHandle() ^= reader->NewArray(len); | 10323 *reader->ArrayHandle() ^= reader->NewArray(len); |
10268 StorePointer(&raw_ptr()->resolved_names_, | 10324 StorePointer(&raw_ptr()->resolved_names_, |
10269 HashTables::New<ResolvedNamesMap>(*reader->ArrayHandle())); | 10325 HashTables::New<ResolvedNamesMap>(*reader->ArrayHandle())); |
10270 } | 10326 } |
10271 } | 10327 } |
10272 | 10328 |
10273 | 10329 |
10330 void Library::AllocateExportedNamesCache() const { | |
10331 StorePointer(&raw_ptr()->exported_names_, | |
10332 HashTables::New<ResolvedNamesMap>(16)); | |
10333 } | |
10334 | |
10335 | |
10336 void Library::InitExportedNamesCache() const { | |
10337 if (exported_names() != Array::null()) { | |
10338 StorePointer(&raw_ptr()->exported_names_, | |
10339 HashTables::New<ResolvedNamesMap>(16)); | |
10340 } | |
10341 } | |
10342 | |
10343 | |
10274 void Library::InitClassDictionary() const { | 10344 void Library::InitClassDictionary() const { |
10275 // TODO(iposva): Find reasonable initial size. | 10345 // TODO(iposva): Find reasonable initial size. |
10276 const int kInitialElementCount = 16; | 10346 const int kInitialElementCount = 16; |
10277 StorePointer(&raw_ptr()->dictionary_, NewDictionary(kInitialElementCount)); | 10347 StorePointer(&raw_ptr()->dictionary_, NewDictionary(kInitialElementCount)); |
10278 } | 10348 } |
10279 | 10349 |
10280 | 10350 |
10281 void Library::InitImportList() const { | 10351 void Library::InitImportList() const { |
10282 const Array& imports = | 10352 const Array& imports = |
10283 Array::Handle(Array::New(kInitialImportsCapacity, Heap::kOld)); | 10353 Array::Handle(Array::New(kInitialImportsCapacity, Heap::kOld)); |
(...skipping 14 matching lines...) Expand all Loading... | |
10298 RawLibrary* Library::NewLibraryHelper(const String& url, | 10368 RawLibrary* Library::NewLibraryHelper(const String& url, |
10299 bool import_core_lib) { | 10369 bool import_core_lib) { |
10300 Thread* thread = Thread::Current(); | 10370 Thread* thread = Thread::Current(); |
10301 Zone* zone = thread->zone(); | 10371 Zone* zone = thread->zone(); |
10302 ASSERT(thread->IsMutatorThread()); | 10372 ASSERT(thread->IsMutatorThread()); |
10303 const Library& result = Library::Handle(zone, Library::New()); | 10373 const Library& result = Library::Handle(zone, Library::New()); |
10304 result.StorePointer(&result.raw_ptr()->name_, Symbols::Empty().raw()); | 10374 result.StorePointer(&result.raw_ptr()->name_, Symbols::Empty().raw()); |
10305 result.StorePointer(&result.raw_ptr()->url_, url.raw()); | 10375 result.StorePointer(&result.raw_ptr()->url_, url.raw()); |
10306 result.StorePointer(&result.raw_ptr()->resolved_names_, | 10376 result.StorePointer(&result.raw_ptr()->resolved_names_, |
10307 Object::empty_array().raw()); | 10377 Object::empty_array().raw()); |
10378 result.StorePointer(&result.raw_ptr()->exported_names_, | |
10379 Array::null()); | |
10308 result.StorePointer(&result.raw_ptr()->dictionary_, | 10380 result.StorePointer(&result.raw_ptr()->dictionary_, |
10309 Object::empty_array().raw()); | 10381 Object::empty_array().raw()); |
10310 result.StorePointer(&result.raw_ptr()->metadata_, | 10382 result.StorePointer(&result.raw_ptr()->metadata_, |
10311 GrowableObjectArray::New(4, Heap::kOld)); | 10383 GrowableObjectArray::New(4, Heap::kOld)); |
10312 result.StorePointer(&result.raw_ptr()->toplevel_class_, Class::null()); | 10384 result.StorePointer(&result.raw_ptr()->toplevel_class_, Class::null()); |
10313 result.StorePointer(&result.raw_ptr()->patch_classes_, | 10385 result.StorePointer(&result.raw_ptr()->patch_classes_, |
10314 GrowableObjectArray::New(Object::empty_array(), | 10386 GrowableObjectArray::New(Object::empty_array(), |
10315 Heap::kOld)); | 10387 Heap::kOld)); |
10316 result.StorePointer(&result.raw_ptr()->imports_, Object::empty_array().raw()); | 10388 result.StorePointer(&result.raw_ptr()->imports_, Object::empty_array().raw()); |
10317 result.StorePointer(&result.raw_ptr()->exports_, Object::empty_array().raw()); | 10389 result.StorePointer(&result.raw_ptr()->exports_, Object::empty_array().raw()); |
10318 result.StorePointer(&result.raw_ptr()->exports2_, | |
10319 Object::empty_array().raw()); | |
10320 result.StorePointer(&result.raw_ptr()->loaded_scripts_, Array::null()); | 10390 result.StorePointer(&result.raw_ptr()->loaded_scripts_, Array::null()); |
10321 result.StorePointer(&result.raw_ptr()->load_error_, Instance::null()); | 10391 result.StorePointer(&result.raw_ptr()->load_error_, Instance::null()); |
10322 result.set_native_entry_resolver(NULL); | 10392 result.set_native_entry_resolver(NULL); |
10323 result.set_native_entry_symbol_resolver(NULL); | 10393 result.set_native_entry_symbol_resolver(NULL); |
10324 result.set_is_in_fullsnapshot(false); | 10394 result.set_is_in_fullsnapshot(false); |
10325 result.StoreNonPointer(&result.raw_ptr()->corelib_imported_, true); | 10395 result.StoreNonPointer(&result.raw_ptr()->corelib_imported_, true); |
10326 result.set_debuggable(false); | 10396 result.set_debuggable(false); |
10327 result.set_is_dart_scheme(url.StartsWith(Symbols::DartScheme())); | 10397 result.set_is_dart_scheme(url.StartsWith(Symbols::DartScheme())); |
10328 result.StoreNonPointer(&result.raw_ptr()->load_state_, | 10398 result.StoreNonPointer(&result.raw_ptr()->load_state_, |
10329 RawLibrary::kAllocated); | 10399 RawLibrary::kAllocated); |
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
11031 // contained in the list, so it is hidden. | 11101 // contained in the list, so it is hidden. |
11032 return true; | 11102 return true; |
11033 } | 11103 } |
11034 // The name is not filtered out. | 11104 // The name is not filtered out. |
11035 return false; | 11105 return false; |
11036 } | 11106 } |
11037 | 11107 |
11038 | 11108 |
11039 // Look up object with given name in library and filter out hidden | 11109 // Look up object with given name in library and filter out hidden |
11040 // names. Also look up getters and setters. | 11110 // names. Also look up getters and setters. |
11041 RawObject* Namespace::Lookup(const String& name) const { | 11111 RawObject* Namespace::Lookup(const String& name, |
11112 ZoneGrowableArray<intptr_t>* trail) const { | |
11042 Zone* zone = Thread::Current()->zone(); | 11113 Zone* zone = Thread::Current()->zone(); |
11043 const Library& lib = Library::Handle(zone, library()); | 11114 const Library& lib = Library::Handle(zone, library()); |
11115 | |
11116 if (trail != NULL) { | |
11117 // Look for cycle in reexport graph. | |
11118 for (int i = 0; i < trail->length(); i++) { | |
11119 if (trail->At(i) == lib.index()) { | |
11120 for (int j = i+1; j < trail->length(); j++) { | |
11121 (*trail)[j] = -1; | |
11122 } | |
11123 return Object::null(); | |
11124 } | |
11125 } | |
11126 } | |
11127 | |
11044 intptr_t ignore = 0; | 11128 intptr_t ignore = 0; |
11045 | |
11046 // Lookup the name in the library's symbols. | 11129 // Lookup the name in the library's symbols. |
11047 Object& obj = Object::Handle(zone, lib.LookupEntry(name, &ignore)); | 11130 Object& obj = Object::Handle(zone, lib.LookupEntry(name, &ignore)); |
11048 if (!Field::IsGetterName(name) && | 11131 if (!Field::IsGetterName(name) && |
11049 !Field::IsSetterName(name) && | 11132 !Field::IsSetterName(name) && |
11050 (obj.IsNull() || obj.IsLibraryPrefix())) { | 11133 (obj.IsNull() || obj.IsLibraryPrefix())) { |
11051 String& accessor_name = String::Handle(zone); | 11134 String& accessor_name = String::Handle(zone); |
11052 accessor_name ^= Field::LookupGetterSymbol(name); | 11135 accessor_name ^= Field::LookupGetterSymbol(name); |
11053 if (!accessor_name.IsNull()) { | 11136 if (!accessor_name.IsNull()) { |
11054 obj = lib.LookupEntry(accessor_name, &ignore); | 11137 obj = lib.LookupEntry(accessor_name, &ignore); |
11055 } | 11138 } |
11056 if (obj.IsNull()) { | 11139 if (obj.IsNull()) { |
11057 accessor_name ^= Field::LookupSetterSymbol(name); | 11140 accessor_name ^= Field::LookupSetterSymbol(name); |
11058 if (!accessor_name.IsNull()) { | 11141 if (!accessor_name.IsNull()) { |
11059 obj = lib.LookupEntry(accessor_name, &ignore); | 11142 obj = lib.LookupEntry(accessor_name, &ignore); |
11060 } | 11143 } |
11061 } | 11144 } |
11062 } | 11145 } |
11063 | 11146 |
11064 // Library prefixes are not exported. | 11147 // Library prefixes are not exported. |
11065 if (obj.IsNull() || obj.IsLibraryPrefix()) { | 11148 if (obj.IsNull() || obj.IsLibraryPrefix()) { |
11066 // Lookup in the re-exported symbols. | 11149 // Lookup in the re-exported symbols. |
11067 obj = lib.LookupReExport(name); | 11150 obj = lib.LookupReExport(name, trail); |
11068 if (obj.IsNull() && !Field::IsSetterName(name)) { | 11151 if (obj.IsNull() && !Field::IsSetterName(name)) { |
11069 // LookupReExport() only returns objects that match the given name. | 11152 // LookupReExport() only returns objects that match the given name. |
11070 // If there is no field/func/getter, try finding a setter. | 11153 // If there is no field/func/getter, try finding a setter. |
11071 const String& setter_name = | 11154 const String& setter_name = |
11072 String::Handle(zone, Field::LookupSetterSymbol(name)); | 11155 String::Handle(zone, Field::LookupSetterSymbol(name)); |
11073 if (!setter_name.IsNull()) { | 11156 if (!setter_name.IsNull()) { |
11074 obj = lib.LookupReExport(setter_name); | 11157 obj = lib.LookupReExport(setter_name, trail); |
11075 } | 11158 } |
11076 } | 11159 } |
11077 } | 11160 } |
11078 if (obj.IsNull() || HidesName(name) || obj.IsLibraryPrefix()) { | 11161 if (obj.IsNull() || HidesName(name) || obj.IsLibraryPrefix()) { |
11079 return Object::null(); | 11162 return Object::null(); |
11080 } | 11163 } |
11081 return obj.raw(); | 11164 return obj.raw(); |
11082 } | 11165 } |
11083 | 11166 |
11084 | 11167 |
(...skipping 10968 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
22053 return UserTag::null(); | 22136 return UserTag::null(); |
22054 } | 22137 } |
22055 | 22138 |
22056 | 22139 |
22057 const char* UserTag::ToCString() const { | 22140 const char* UserTag::ToCString() const { |
22058 const String& tag_label = String::Handle(label()); | 22141 const String& tag_label = String::Handle(label()); |
22059 return tag_label.ToCString(); | 22142 return tag_label.ToCString(); |
22060 } | 22143 } |
22061 | 22144 |
22062 } // namespace dart | 22145 } // namespace dart |
OLD | NEW |