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 8727 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8738 | 8738 |
8739 | 8739 |
8740 void Library::SetLoadError(const Instance& error) const { | 8740 void Library::SetLoadError(const Instance& error) const { |
8741 // Should not be already successfully loaded or just allocated. | 8741 // Should not be already successfully loaded or just allocated. |
8742 ASSERT(LoadInProgress() || LoadRequested() || LoadFailed()); | 8742 ASSERT(LoadInProgress() || LoadRequested() || LoadFailed()); |
8743 raw_ptr()->load_state_ = RawLibrary::kLoadError; | 8743 raw_ptr()->load_state_ = RawLibrary::kLoadError; |
8744 StorePointer(&raw_ptr()->load_error_, error.raw()); | 8744 StorePointer(&raw_ptr()->load_error_, error.raw()); |
8745 } | 8745 } |
8746 | 8746 |
8747 | 8747 |
8748 // Traits for looking up Libraries by url in a hash set. | |
8749 class LibraryUrl { | |
8750 public: | |
8751 LibraryUrl(const String& url, String* tmp_string) | |
8752 : url_(url), tmp_string_(tmp_string) {} | |
8753 bool Matches(const Library& library) const { | |
8754 if (url_.IsSymbol()) { | |
8755 return url_.raw() == library.url(); | |
8756 } else { | |
8757 *tmp_string_ = library.url(); | |
8758 return url_.Equals(*tmp_string_); | |
8759 } | |
8760 } | |
8761 intptr_t Hash() const { return url_.Hash(); } | |
8762 private: | |
8763 const String& url_; | |
8764 String* tmp_string_; | |
8765 }; | |
8766 | |
8767 | |
8768 class LibraryUrlTraits { | |
8769 public: | |
8770 // Called when growing the table. | |
8771 static bool IsMatch(const Object& a, const Object& b) { | |
8772 ASSERT(a.IsLibrary() && b.IsLibrary()); | |
8773 // Library objects are always canonical. | |
8774 return a.raw() == b.raw(); | |
8775 } | |
8776 static bool IsMatch(const LibraryUrl& url, const Object& obj) { | |
8777 return url.Matches(Library::Cast(obj)); | |
8778 } | |
8779 static uword Hash(const Object& key) { | |
8780 return Library::Cast(key).UrlHash(); | |
8781 } | |
8782 static uword Hash(const LibraryUrl& url) { | |
8783 return url.Hash(); | |
8784 } | |
8785 }; | |
8786 | |
8787 | |
8788 typedef UnorderedHashSet<LibraryUrlTraits> LibraryLoadErrorSet; | |
8789 | |
8790 | |
8748 RawInstance* Library::TransitiveLoadError() const { | 8791 RawInstance* Library::TransitiveLoadError() const { |
8749 if (LoadError() != Instance::null()) { | 8792 if (LoadError() != Instance::null()) { |
8750 return LoadError(); | 8793 return LoadError(); |
8751 } | 8794 } |
8795 Isolate* isolate = Isolate::Current(); | |
8796 ObjectStore* object_store = isolate->object_store(); | |
8797 LibraryLoadErrorSet set(object_store->library_load_error_table()); | |
8798 bool present = false; | |
8799 if (set.GetOrNull(*this, &present) != Object::null()) { | |
8800 object_store->set_library_load_error_table(set.Release()); | |
8801 return Instance::null(); | |
8802 } | |
8752 intptr_t num_imp = num_imports(); | 8803 intptr_t num_imp = num_imports(); |
8753 Library& lib = Library::Handle(); | 8804 Library& lib = Library::Handle(isolate); |
8754 Instance& error = Instance::Handle(); | 8805 Instance& error = Instance::Handle(isolate); |
8755 for (intptr_t i = 0; i < num_imp; i++) { | 8806 for (intptr_t i = 0; i < num_imp; i++) { |
8807 HANDLESCOPE(isolate); | |
8756 lib = ImportLibraryAt(i); | 8808 lib = ImportLibraryAt(i); |
8757 // Break potential import cycles while recursing through imports. | 8809 // Ensure we don't repeatedly visit the same library again. |
8758 set_num_imports(0); | 8810 set.Insert(lib); |
8759 error = lib.TransitiveLoadError(); | 8811 error = lib.TransitiveLoadError(); |
8760 set_num_imports(num_imp); | |
8761 if (!error.IsNull()) { | 8812 if (!error.IsNull()) { |
8762 break; | 8813 break; |
8763 } | 8814 } |
8764 } | 8815 } |
8816 object_store->set_library_load_error_table(set.Release()); | |
8765 return error.raw(); | 8817 return error.raw(); |
8766 } | 8818 } |
8767 | 8819 |
8768 | 8820 |
8769 static RawString* MakeClassMetaName(const Class& cls) { | 8821 static RawString* MakeClassMetaName(const Class& cls) { |
8770 String& cname = String::Handle(cls.Name()); | 8822 String& cname = String::Handle(cls.Name()); |
8771 return String::Concat(Symbols::At(), cname); | 8823 return String::Concat(Symbols::At(), cname); |
8772 } | 8824 } |
8773 | 8825 |
8774 | 8826 |
(...skipping 1159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
9934 const Array& imports = Array::Handle(this->imports()); | 9986 const Array& imports = Array::Handle(this->imports()); |
9935 Namespace& import = Namespace::Handle(); | 9987 Namespace& import = Namespace::Handle(); |
9936 import ^= imports.At(index); | 9988 import ^= imports.At(index); |
9937 return import.library(); | 9989 return import.library(); |
9938 } | 9990 } |
9939 return Library::null(); | 9991 return Library::null(); |
9940 } | 9992 } |
9941 | 9993 |
9942 | 9994 |
9943 RawInstance* LibraryPrefix::LoadError() const { | 9995 RawInstance* LibraryPrefix::LoadError() const { |
9944 Library& lib = Library::Handle(); | 9996 const intptr_t kNumLibs = 25; |
9945 Instance& error = Instance::Handle(); | 9997 Isolate* isolate = Isolate::Current(); |
9998 ObjectStore* object_store = isolate->object_store(); | |
9999 LibraryLoadErrorSet set(HashTables::New<LibraryLoadErrorSet>(kNumLibs)); | |
Ivan Posva
2014/09/18 00:58:04
How about just calling set.Clear() once we are don
siva
2014/09/18 01:07:37
Ignoring this for now.
| |
10000 object_store->set_library_load_error_table(set.Release()); | |
10001 Library& lib = Library::Handle(isolate); | |
10002 Instance& error = Instance::Handle(isolate); | |
9946 for (int32_t i = 0; i < num_imports(); i++) { | 10003 for (int32_t i = 0; i < num_imports(); i++) { |
9947 lib = GetLibrary(i); | 10004 lib = GetLibrary(i); |
Ivan Posva
2014/09/18 00:58:04
HANDLESCOPE(isolate);
siva
2014/09/18 01:07:37
Done.
| |
9948 ASSERT(!lib.IsNull()); | 10005 ASSERT(!lib.IsNull()); |
9949 error = lib.TransitiveLoadError(); | 10006 error = lib.TransitiveLoadError(); |
9950 if (!error.IsNull()) { | 10007 if (!error.IsNull()) { |
9951 return error.raw(); | 10008 break; |
9952 } | 10009 } |
9953 } | 10010 } |
9954 return Instance::null(); | 10011 object_store->set_library_load_error_table(Object::empty_array()); |
10012 return error.raw(); | |
9955 } | 10013 } |
9956 | 10014 |
9957 | 10015 |
9958 bool LibraryPrefix::ContainsLibrary(const Library& library) const { | 10016 bool LibraryPrefix::ContainsLibrary(const Library& library) const { |
9959 int32_t num_current_imports = num_imports(); | 10017 int32_t num_current_imports = num_imports(); |
9960 if (num_current_imports > 0) { | 10018 if (num_current_imports > 0) { |
9961 Library& lib = Library::Handle(); | 10019 Library& lib = Library::Handle(); |
9962 const String& url = String::Handle(library.url()); | 10020 const String& url = String::Handle(library.url()); |
9963 String& lib_url = String::Handle(); | 10021 String& lib_url = String::Handle(); |
9964 for (int32_t i = 0; i < num_current_imports; i++) { | 10022 for (int32_t i = 0; i < num_current_imports; i++) { |
(...skipping 10401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
20366 return tag_label.ToCString(); | 20424 return tag_label.ToCString(); |
20367 } | 20425 } |
20368 | 20426 |
20369 | 20427 |
20370 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { | 20428 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { |
20371 Instance::PrintJSONImpl(stream, ref); | 20429 Instance::PrintJSONImpl(stream, ref); |
20372 } | 20430 } |
20373 | 20431 |
20374 | 20432 |
20375 } // namespace dart | 20433 } // namespace dart |
OLD | NEW |