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 "platform/assert.h" | 7 #include "platform/assert.h" |
8 #include "vm/assembler.h" | 8 #include "vm/assembler.h" |
9 #include "vm/bigint_operations.h" | 9 #include "vm/bigint_operations.h" |
10 #include "vm/bootstrap.h" | 10 #include "vm/bootstrap.h" |
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 object_store->set_symbol_table(array); | 490 object_store->set_symbol_table(array); |
491 | 491 |
492 // canonical_type_arguments_ are NULL terminated. | 492 // canonical_type_arguments_ are NULL terminated. |
493 array = Array::New(4); | 493 array = Array::New(4); |
494 object_store->set_canonical_type_arguments(array); | 494 object_store->set_canonical_type_arguments(array); |
495 | 495 |
496 // Pre-allocate the OneByteString class needed by the symbol table. | 496 // Pre-allocate the OneByteString class needed by the symbol table. |
497 cls = Class::New<OneByteString>(); | 497 cls = Class::New<OneByteString>(); |
498 object_store->set_one_byte_string_class(cls); | 498 object_store->set_one_byte_string_class(cls); |
499 | 499 |
| 500 // Set up the libraries array before initializing the core library. |
| 501 const GrowableObjectArray& libraries = |
| 502 GrowableObjectArray::Handle(GrowableObjectArray::New(Heap::kOld)); |
| 503 object_store->set_libraries(libraries); |
| 504 |
500 // Basic infrastructure has been setup, initialize the class dictionary. | 505 // Basic infrastructure has been setup, initialize the class dictionary. |
501 Library::InitCoreLibrary(isolate); | 506 Library::InitCoreLibrary(isolate); |
502 Library& core_lib = Library::Handle(Library::CoreLibrary()); | 507 Library& core_lib = Library::Handle(Library::CoreLibrary()); |
503 ASSERT(!core_lib.IsNull()); | 508 ASSERT(!core_lib.IsNull()); |
504 Library& core_impl_lib = Library::Handle(Library::CoreImplLibrary()); | 509 Library& core_impl_lib = Library::Handle(Library::CoreImplLibrary()); |
505 ASSERT(!core_impl_lib.IsNull()); | 510 ASSERT(!core_impl_lib.IsNull()); |
506 | 511 |
507 const GrowableObjectArray& pending_classes = | 512 const GrowableObjectArray& pending_classes = |
508 GrowableObjectArray::Handle(GrowableObjectArray::New(Heap::kOld)); | 513 GrowableObjectArray::Handle(GrowableObjectArray::New(Heap::kOld)); |
509 object_store->set_pending_classes(pending_classes); | 514 object_store->set_pending_classes(pending_classes); |
(...skipping 4789 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5299 RawLibrary* Library::NewLibraryHelper(const String& url, | 5304 RawLibrary* Library::NewLibraryHelper(const String& url, |
5300 bool import_core_lib) { | 5305 bool import_core_lib) { |
5301 const Library& result = Library::Handle(Library::New()); | 5306 const Library& result = Library::Handle(Library::New()); |
5302 result.raw_ptr()->name_ = url.raw(); | 5307 result.raw_ptr()->name_ = url.raw(); |
5303 result.raw_ptr()->url_ = url.raw(); | 5308 result.raw_ptr()->url_ = url.raw(); |
5304 result.raw_ptr()->private_key_ = Scanner::AllocatePrivateKey(result); | 5309 result.raw_ptr()->private_key_ = Scanner::AllocatePrivateKey(result); |
5305 result.raw_ptr()->dictionary_ = Array::Empty(); | 5310 result.raw_ptr()->dictionary_ = Array::Empty(); |
5306 result.raw_ptr()->anonymous_classes_ = Array::Empty(); | 5311 result.raw_ptr()->anonymous_classes_ = Array::Empty(); |
5307 result.raw_ptr()->num_anonymous_ = 0; | 5312 result.raw_ptr()->num_anonymous_ = 0; |
5308 result.raw_ptr()->imports_ = Array::Empty(); | 5313 result.raw_ptr()->imports_ = Array::Empty(); |
5309 result.raw_ptr()->next_registered_ = Library::null(); | |
5310 result.raw_ptr()->loaded_scripts_ = Array::null(); | 5314 result.raw_ptr()->loaded_scripts_ = Array::null(); |
5311 result.set_native_entry_resolver(NULL); | 5315 result.set_native_entry_resolver(NULL); |
5312 result.raw_ptr()->corelib_imported_ = true; | 5316 result.raw_ptr()->corelib_imported_ = true; |
5313 result.raw_ptr()->load_state_ = RawLibrary::kAllocated; | 5317 result.raw_ptr()->load_state_ = RawLibrary::kAllocated; |
5314 result.InitClassDictionary(); | 5318 result.InitClassDictionary(); |
5315 result.InitImportList(); | 5319 result.InitImportList(); |
5316 result.InitImportedIntoList(); | 5320 result.InitImportedIntoList(); |
5317 if (import_core_lib) { | 5321 if (import_core_lib) { |
5318 Library& core_lib = Library::Handle(Library::CoreLibrary()); | 5322 Library& core_lib = Library::Handle(Library::CoreLibrary()); |
5319 ASSERT(!core_lib.IsNull()); | 5323 ASSERT(!core_lib.IsNull()); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5397 cls_name = String::NewSymbol(name_buffer); | 5401 cls_name = String::NewSymbol(name_buffer); |
5398 Class::NewNativeWrapper(&native_flds_lib, cls_name, fld_cnt); | 5402 Class::NewNativeWrapper(&native_flds_lib, cls_name, fld_cnt); |
5399 } | 5403 } |
5400 } | 5404 } |
5401 | 5405 |
5402 | 5406 |
5403 RawLibrary* Library::LookupLibrary(const String &url) { | 5407 RawLibrary* Library::LookupLibrary(const String &url) { |
5404 Isolate* isolate = Isolate::Current(); | 5408 Isolate* isolate = Isolate::Current(); |
5405 Library& lib = Library::Handle(isolate, Library::null()); | 5409 Library& lib = Library::Handle(isolate, Library::null()); |
5406 String& lib_url = String::Handle(isolate, String::null()); | 5410 String& lib_url = String::Handle(isolate, String::null()); |
5407 lib = isolate->object_store()->registered_libraries(); | 5411 GrowableObjectArray& libs = GrowableObjectArray::Handle( |
5408 while (!lib.IsNull()) { | 5412 isolate, isolate->object_store()->libraries()); |
| 5413 for (int i = 0; i < libs.Length(); i++) { |
| 5414 lib ^= libs.At(i); |
5409 lib_url = lib.url(); | 5415 lib_url = lib.url(); |
5410 if (lib_url.Equals(url)) { | 5416 if (lib_url.Equals(url)) { |
5411 return lib.raw(); | 5417 return lib.raw(); |
5412 } | 5418 } |
5413 lib = lib.next_registered(); | |
5414 } | 5419 } |
5415 return Library::null(); | 5420 return Library::null(); |
5416 } | 5421 } |
5417 | 5422 |
5418 | 5423 |
5419 RawString* Library::CheckForDuplicateDefinition() { | 5424 RawString* Library::CheckForDuplicateDefinition() { |
5420 Library& lib = Library::Handle(); | |
5421 Isolate* isolate = Isolate::Current(); | 5425 Isolate* isolate = Isolate::Current(); |
5422 ASSERT(isolate != NULL); | 5426 ASSERT(isolate != NULL); |
5423 ObjectStore* object_store = isolate->object_store(); | 5427 ObjectStore* object_store = isolate->object_store(); |
5424 ASSERT(object_store != NULL); | 5428 ASSERT(object_store != NULL); |
5425 lib ^= object_store->registered_libraries(); | 5429 const GrowableObjectArray& libs = |
| 5430 GrowableObjectArray::Handle(object_store->libraries()); |
| 5431 Library& lib = Library::Handle(); |
5426 String& error_message = String::Handle(); | 5432 String& error_message = String::Handle(); |
5427 while (!lib.IsNull()) { | 5433 for (int i = 0; i < libs.Length(); i++) { |
| 5434 lib ^= libs.At(i); |
5428 error_message = lib.FindDuplicateDefinition(); | 5435 error_message = lib.FindDuplicateDefinition(); |
5429 if (!error_message.IsNull()) { | 5436 if (!error_message.IsNull()) { |
5430 return error_message.raw(); | 5437 return error_message.raw(); |
5431 } | 5438 } |
5432 lib ^= lib.next_registered(); | |
5433 } | 5439 } |
5434 return String::null(); | 5440 return String::null(); |
5435 } | 5441 } |
5436 | 5442 |
5437 | 5443 |
5438 bool Library::IsKeyUsed(intptr_t key) { | 5444 bool Library::IsKeyUsed(intptr_t key) { |
5439 intptr_t lib_key; | 5445 intptr_t lib_key; |
| 5446 const GrowableObjectArray& libs = GrowableObjectArray::Handle( |
| 5447 Isolate::Current()->object_store()->libraries()); |
5440 Library& lib = Library::Handle(); | 5448 Library& lib = Library::Handle(); |
5441 lib = Isolate::Current()->object_store()->registered_libraries(); | |
5442 String& lib_url = String::Handle(); | 5449 String& lib_url = String::Handle(); |
5443 while (!lib.IsNull()) { | 5450 for (int i = 0; i < libs.Length(); i++) { |
| 5451 lib ^= libs.At(i); |
5444 lib_url ^= lib.url(); | 5452 lib_url ^= lib.url(); |
5445 lib_key = lib_url.Hash(); | 5453 lib_key = lib_url.Hash(); |
5446 if (lib_key == key) { | 5454 if (lib_key == key) { |
5447 return true; | 5455 return true; |
5448 } | 5456 } |
5449 lib = lib.next_registered(); | |
5450 } | 5457 } |
5451 return false; | 5458 return false; |
5452 } | 5459 } |
5453 | 5460 |
5454 | 5461 |
5455 RawString* Library::PrivateName(const String& name) const { | 5462 RawString* Library::PrivateName(const String& name) const { |
5456 ASSERT(ShouldBePrivate(name)); | 5463 ASSERT(ShouldBePrivate(name)); |
5457 // ASSERT(strchr(name, '@') == NULL); | 5464 // ASSERT(strchr(name, '@') == NULL); |
5458 String& str = String::Handle(); | 5465 String& str = String::Handle(); |
5459 str ^= name.raw(); | 5466 str ^= name.raw(); |
5460 str = String::Concat(str, String::Handle(this->private_key())); | 5467 str = String::Concat(str, String::Handle(this->private_key())); |
5461 str = String::NewSymbol(str); | 5468 str = String::NewSymbol(str); |
5462 return str.raw(); | 5469 return str.raw(); |
5463 } | 5470 } |
5464 | 5471 |
5465 | 5472 |
| 5473 RawLibrary* Library::GetLibrary(intptr_t index) { |
| 5474 Isolate* isolate = Isolate::Current(); |
| 5475 const GrowableObjectArray& libs = |
| 5476 GrowableObjectArray::Handle(isolate->object_store()->libraries()); |
| 5477 ASSERT(!libs.IsNull()); |
| 5478 if ((0 <= index) && (index < libs.Length())) { |
| 5479 Library& lib = Library::Handle(); |
| 5480 lib ^= libs.At(index); |
| 5481 return lib.raw(); |
| 5482 } |
| 5483 return Library::null(); |
| 5484 } |
| 5485 |
| 5486 |
5466 void Library::Register() const { | 5487 void Library::Register() const { |
5467 ASSERT(Library::LookupLibrary(String::Handle(url())) == Library::null()); | 5488 ASSERT(Library::LookupLibrary(String::Handle(url())) == Library::null()); |
5468 raw_ptr()->next_registered_ = | 5489 ObjectStore* object_store = Isolate::Current()->object_store(); |
5469 Isolate::Current()->object_store()->registered_libraries(); | 5490 GrowableObjectArray& libs = |
5470 Isolate::Current()->object_store()->set_registered_libraries(*this); | 5491 GrowableObjectArray::Handle(object_store->libraries()); |
| 5492 ASSERT(!libs.IsNull()); |
| 5493 libs.Add(*this); |
5471 } | 5494 } |
5472 | 5495 |
5473 | 5496 |
5474 RawLibrary* Library::CoreLibrary() { | 5497 RawLibrary* Library::CoreLibrary() { |
5475 return Isolate::Current()->object_store()->core_library(); | 5498 return Isolate::Current()->object_store()->core_library(); |
5476 } | 5499 } |
5477 | 5500 |
5478 | 5501 |
5479 RawLibrary* Library::CoreImplLibrary() { | 5502 RawLibrary* Library::CoreImplLibrary() { |
5480 return Isolate::Current()->object_store()->core_impl_library(); | 5503 return Isolate::Current()->object_store()->core_impl_library(); |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5660 } | 5683 } |
5661 | 5684 |
5662 | 5685 |
5663 void LibraryPrefix::set_num_libs(intptr_t value) const { | 5686 void LibraryPrefix::set_num_libs(intptr_t value) const { |
5664 raw_ptr()->num_libs_ = value; | 5687 raw_ptr()->num_libs_ = value; |
5665 } | 5688 } |
5666 | 5689 |
5667 | 5690 |
5668 RawError* Library::CompileAll() { | 5691 RawError* Library::CompileAll() { |
5669 Error& error = Error::Handle(); | 5692 Error& error = Error::Handle(); |
5670 Library& lib = Library::Handle( | 5693 const GrowableObjectArray& libs = GrowableObjectArray::Handle( |
5671 Isolate::Current()->object_store()->registered_libraries()); | 5694 Isolate::Current()->object_store()->libraries()); |
| 5695 Library& lib = Library::Handle(); |
5672 Class& cls = Class::Handle(); | 5696 Class& cls = Class::Handle(); |
5673 while (!lib.IsNull()) { | 5697 for (int i = 0; i < libs.Length(); i++) { |
| 5698 lib ^= libs.At(i); |
5674 ClassDictionaryIterator it(lib); | 5699 ClassDictionaryIterator it(lib); |
5675 while (it.HasNext()) { | 5700 while (it.HasNext()) { |
5676 cls ^= it.GetNextClass(); | 5701 cls ^= it.GetNextClass(); |
5677 if (!cls.is_interface()) { | 5702 if (!cls.is_interface()) { |
5678 error = Compiler::CompileAllFunctions(cls); | 5703 error = Compiler::CompileAllFunctions(cls); |
5679 if (!error.IsNull()) { | 5704 if (!error.IsNull()) { |
5680 return error.raw(); | 5705 return error.raw(); |
5681 } | 5706 } |
5682 } | 5707 } |
5683 } | 5708 } |
5684 Array& anon_classes = Array::Handle(lib.raw_ptr()->anonymous_classes_); | 5709 Array& anon_classes = Array::Handle(lib.raw_ptr()->anonymous_classes_); |
5685 for (int i = 0; i < lib.raw_ptr()->num_anonymous_; i++) { | 5710 for (int i = 0; i < lib.raw_ptr()->num_anonymous_; i++) { |
5686 cls ^= anon_classes.At(i); | 5711 cls ^= anon_classes.At(i); |
5687 ASSERT(!cls.is_interface()); | 5712 ASSERT(!cls.is_interface()); |
5688 error = Compiler::CompileAllFunctions(cls); | 5713 error = Compiler::CompileAllFunctions(cls); |
5689 if (!error.IsNull()) { | 5714 if (!error.IsNull()) { |
5690 return error.raw(); | 5715 return error.raw(); |
5691 } | 5716 } |
5692 } | 5717 } |
5693 lib = lib.next_registered(); | |
5694 } | 5718 } |
5695 return error.raw(); | 5719 return error.raw(); |
5696 } | 5720 } |
5697 | 5721 |
5698 | 5722 |
5699 RawInstructions* Instructions::New(intptr_t size) { | 5723 RawInstructions* Instructions::New(intptr_t size) { |
5700 const Class& instructions_class = Class::Handle(Object::instructions_class()); | 5724 const Class& instructions_class = Class::Handle(Object::instructions_class()); |
5701 Instructions& result = Instructions::Handle(); | 5725 Instructions& result = Instructions::Handle(); |
5702 { | 5726 { |
5703 uword aligned_size = Instructions::InstanceSize(size); | 5727 uword aligned_size = Instructions::InstanceSize(size); |
(...skipping 4315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10019 const String& str = String::Handle(pattern()); | 10043 const String& str = String::Handle(pattern()); |
10020 const char* format = "JSRegExp: pattern=%s flags=%s"; | 10044 const char* format = "JSRegExp: pattern=%s flags=%s"; |
10021 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); | 10045 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); |
10022 char* chars = reinterpret_cast<char*>( | 10046 char* chars = reinterpret_cast<char*>( |
10023 Isolate::Current()->current_zone()->Allocate(len + 1)); | 10047 Isolate::Current()->current_zone()->Allocate(len + 1)); |
10024 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); | 10048 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); |
10025 return chars; | 10049 return chars; |
10026 } | 10050 } |
10027 | 10051 |
10028 } // namespace dart | 10052 } // namespace dart |
OLD | NEW |