| 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 9481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9492 } | 9492 } |
| 9493 | 9493 |
| 9494 // Invalidate the cache of loaded scripts. | 9494 // Invalidate the cache of loaded scripts. |
| 9495 if (loaded_scripts() != Array::null()) { | 9495 if (loaded_scripts() != Array::null()) { |
| 9496 StorePointer(&raw_ptr()->loaded_scripts_, Array::null()); | 9496 StorePointer(&raw_ptr()->loaded_scripts_, Array::null()); |
| 9497 } | 9497 } |
| 9498 } | 9498 } |
| 9499 | 9499 |
| 9500 | 9500 |
| 9501 // Lookup a name in the library's re-export namespace. | 9501 // Lookup a name in the library's re-export namespace. |
| 9502 // This lookup can occur from two different threads: background compiler and |
| 9503 // mutator thread. |
| 9502 RawObject* Library::LookupReExport(const String& name) const { | 9504 RawObject* Library::LookupReExport(const String& name) const { |
| 9503 if (HasExports()) { | 9505 if (HasExports()) { |
| 9504 const Array& exports = Array::Handle(this->exports()); | 9506 const bool is_background_compiler = Compiler::IsBackgroundCompilation(); |
| 9505 // Break potential export cycle while looking up name. | 9507 Array& exports = Array::Handle(); |
| 9506 StorePointer(&raw_ptr()->exports_, Object::empty_array().raw()); | 9508 if (is_background_compiler) { |
| 9509 exports = this->exports2(); |
| 9510 // Break potential export cycle while looking up name. |
| 9511 StorePointer(&raw_ptr()->exports2_, Object::empty_array().raw()); |
| 9512 } else { |
| 9513 exports = this->exports(); |
| 9514 // Break potential export cycle while looking up name. |
| 9515 StorePointer(&raw_ptr()->exports_, Object::empty_array().raw()); |
| 9516 } |
| 9507 Namespace& ns = Namespace::Handle(); | 9517 Namespace& ns = Namespace::Handle(); |
| 9508 Object& obj = Object::Handle(); | 9518 Object& obj = Object::Handle(); |
| 9509 for (int i = 0; i < exports.Length(); i++) { | 9519 for (int i = 0; i < exports.Length(); i++) { |
| 9510 ns ^= exports.At(i); | 9520 ns ^= exports.At(i); |
| 9511 obj = ns.Lookup(name); | 9521 obj = ns.Lookup(name); |
| 9512 if (!obj.IsNull()) { | 9522 if (!obj.IsNull()) { |
| 9513 // The Lookup call above may return a setter x= when we are looking | 9523 // The Lookup call above may return a setter x= when we are looking |
| 9514 // for the name x. Make sure we only return when a matching name | 9524 // for the name x. Make sure we only return when a matching name |
| 9515 // is found. | 9525 // is found. |
| 9516 String& obj_name = String::Handle(obj.DictionaryName()); | 9526 String& obj_name = String::Handle(obj.DictionaryName()); |
| 9517 if (Field::IsSetterName(obj_name) == Field::IsSetterName(name)) { | 9527 if (Field::IsSetterName(obj_name) == Field::IsSetterName(name)) { |
| 9518 break; | 9528 break; |
| 9519 } | 9529 } |
| 9520 } | 9530 } |
| 9521 } | 9531 } |
| 9522 StorePointer(&raw_ptr()->exports_, exports.raw()); | 9532 if (is_background_compiler) { |
| 9533 StorePointer(&raw_ptr()->exports2_, exports.raw()); |
| 9534 } else { |
| 9535 StorePointer(&raw_ptr()->exports_, exports.raw()); |
| 9536 } |
| 9523 return obj.raw(); | 9537 return obj.raw(); |
| 9524 } | 9538 } |
| 9525 return Object::null(); | 9539 return Object::null(); |
| 9526 } | 9540 } |
| 9527 | 9541 |
| 9528 | 9542 |
| 9529 RawObject* Library::LookupEntry(const String& name, intptr_t *index) const { | 9543 RawObject* Library::LookupEntry(const String& name, intptr_t *index) const { |
| 9530 Thread* thread = Thread::Current(); | 9544 Thread* thread = Thread::Current(); |
| 9531 REUSABLE_ARRAY_HANDLESCOPE(thread); | 9545 REUSABLE_ARRAY_HANDLESCOPE(thread); |
| 9532 REUSABLE_OBJECT_HANDLESCOPE(thread); | 9546 REUSABLE_OBJECT_HANDLESCOPE(thread); |
| (...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9959 } | 9973 } |
| 9960 } | 9974 } |
| 9961 } | 9975 } |
| 9962 return false; | 9976 return false; |
| 9963 } | 9977 } |
| 9964 | 9978 |
| 9965 | 9979 |
| 9966 void Library::DropDependencies() const { | 9980 void Library::DropDependencies() const { |
| 9967 StorePointer(&raw_ptr()->imports_, Array::null()); | 9981 StorePointer(&raw_ptr()->imports_, Array::null()); |
| 9968 StorePointer(&raw_ptr()->exports_, Array::null()); | 9982 StorePointer(&raw_ptr()->exports_, Array::null()); |
| 9983 StorePointer(&raw_ptr()->exports2_, Array::null()); |
| 9969 } | 9984 } |
| 9970 | 9985 |
| 9971 | 9986 |
| 9972 void Library::AddImport(const Namespace& ns) const { | 9987 void Library::AddImport(const Namespace& ns) const { |
| 9973 Array& imports = Array::Handle(this->imports()); | 9988 Array& imports = Array::Handle(this->imports()); |
| 9974 intptr_t capacity = imports.Length(); | 9989 intptr_t capacity = imports.Length(); |
| 9975 if (num_imports() == capacity) { | 9990 if (num_imports() == capacity) { |
| 9976 capacity = capacity + kImportsCapacityIncrement; | 9991 capacity = capacity + kImportsCapacityIncrement; |
| 9977 imports = Array::Grow(imports, capacity); | 9992 imports = Array::Grow(imports, capacity); |
| 9978 StorePointer(&raw_ptr()->imports_, imports.raw()); | 9993 StorePointer(&raw_ptr()->imports_, imports.raw()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 9991 | 10006 |
| 9992 | 10007 |
| 9993 // We add one namespace at a time to the exports array and don't | 10008 // We add one namespace at a time to the exports array and don't |
| 9994 // pre-allocate any unused capacity. The assumption is that | 10009 // pre-allocate any unused capacity. The assumption is that |
| 9995 // re-exports are quite rare. | 10010 // re-exports are quite rare. |
| 9996 void Library::AddExport(const Namespace& ns) const { | 10011 void Library::AddExport(const Namespace& ns) const { |
| 9997 Array &exports = Array::Handle(this->exports()); | 10012 Array &exports = Array::Handle(this->exports()); |
| 9998 intptr_t num_exports = exports.Length(); | 10013 intptr_t num_exports = exports.Length(); |
| 9999 exports = Array::Grow(exports, num_exports + 1); | 10014 exports = Array::Grow(exports, num_exports + 1); |
| 10000 StorePointer(&raw_ptr()->exports_, exports.raw()); | 10015 StorePointer(&raw_ptr()->exports_, exports.raw()); |
| 10016 StorePointer(&raw_ptr()->exports2_, exports.raw()); |
| 10001 exports.SetAt(num_exports, ns); | 10017 exports.SetAt(num_exports, ns); |
| 10002 } | 10018 } |
| 10003 | 10019 |
| 10004 | 10020 |
| 10005 static RawArray* NewDictionary(intptr_t initial_size) { | 10021 static RawArray* NewDictionary(intptr_t initial_size) { |
| 10006 const Array& dict = Array::Handle(Array::New(initial_size + 1, Heap::kOld)); | 10022 const Array& dict = Array::Handle(Array::New(initial_size + 1, Heap::kOld)); |
| 10007 // The last element of the dictionary specifies the number of in use slots. | 10023 // The last element of the dictionary specifies the number of in use slots. |
| 10008 dict.SetAt(initial_size, Smi::Handle(Smi::New(0))); | 10024 dict.SetAt(initial_size, Smi::Handle(Smi::New(0))); |
| 10009 return dict.raw(); | 10025 return dict.raw(); |
| 10010 } | 10026 } |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10058 result.StorePointer(&result.raw_ptr()->dictionary_, | 10074 result.StorePointer(&result.raw_ptr()->dictionary_, |
| 10059 Object::empty_array().raw()); | 10075 Object::empty_array().raw()); |
| 10060 result.StorePointer(&result.raw_ptr()->metadata_, | 10076 result.StorePointer(&result.raw_ptr()->metadata_, |
| 10061 GrowableObjectArray::New(4, Heap::kOld)); | 10077 GrowableObjectArray::New(4, Heap::kOld)); |
| 10062 result.StorePointer(&result.raw_ptr()->toplevel_class_, Class::null()); | 10078 result.StorePointer(&result.raw_ptr()->toplevel_class_, Class::null()); |
| 10063 result.StorePointer(&result.raw_ptr()->patch_classes_, | 10079 result.StorePointer(&result.raw_ptr()->patch_classes_, |
| 10064 GrowableObjectArray::New(Object::empty_array(), | 10080 GrowableObjectArray::New(Object::empty_array(), |
| 10065 Heap::kOld)); | 10081 Heap::kOld)); |
| 10066 result.StorePointer(&result.raw_ptr()->imports_, Object::empty_array().raw()); | 10082 result.StorePointer(&result.raw_ptr()->imports_, Object::empty_array().raw()); |
| 10067 result.StorePointer(&result.raw_ptr()->exports_, Object::empty_array().raw()); | 10083 result.StorePointer(&result.raw_ptr()->exports_, Object::empty_array().raw()); |
| 10084 result.StorePointer(&result.raw_ptr()->exports2_, |
| 10085 Object::empty_array().raw()); |
| 10068 result.StorePointer(&result.raw_ptr()->loaded_scripts_, Array::null()); | 10086 result.StorePointer(&result.raw_ptr()->loaded_scripts_, Array::null()); |
| 10069 result.StorePointer(&result.raw_ptr()->load_error_, Instance::null()); | 10087 result.StorePointer(&result.raw_ptr()->load_error_, Instance::null()); |
| 10070 result.set_native_entry_resolver(NULL); | 10088 result.set_native_entry_resolver(NULL); |
| 10071 result.set_native_entry_symbol_resolver(NULL); | 10089 result.set_native_entry_symbol_resolver(NULL); |
| 10072 result.set_is_in_fullsnapshot(false); | 10090 result.set_is_in_fullsnapshot(false); |
| 10073 result.StoreNonPointer(&result.raw_ptr()->corelib_imported_, true); | 10091 result.StoreNonPointer(&result.raw_ptr()->corelib_imported_, true); |
| 10074 result.set_debuggable(false); | 10092 result.set_debuggable(false); |
| 10075 result.set_is_dart_scheme(url.StartsWith(Symbols::DartScheme())); | 10093 result.set_is_dart_scheme(url.StartsWith(Symbols::DartScheme())); |
| 10076 result.StoreNonPointer(&result.raw_ptr()->load_state_, | 10094 result.StoreNonPointer(&result.raw_ptr()->load_state_, |
| 10077 RawLibrary::kAllocated); | 10095 RawLibrary::kAllocated); |
| (...skipping 11658 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 21736 return UserTag::null(); | 21754 return UserTag::null(); |
| 21737 } | 21755 } |
| 21738 | 21756 |
| 21739 | 21757 |
| 21740 const char* UserTag::ToCString() const { | 21758 const char* UserTag::ToCString() const { |
| 21741 const String& tag_label = String::Handle(label()); | 21759 const String& tag_label = String::Handle(label()); |
| 21742 return tag_label.ToCString(); | 21760 return tag_label.ToCString(); |
| 21743 } | 21761 } |
| 21744 | 21762 |
| 21745 } // namespace dart | 21763 } // namespace dart |
| OLD | NEW |