Chromium Code Reviews| 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 4812 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5322 bool import_core_lib) { | 5327 bool import_core_lib) { |
| 5323 const Library& result = Library::Handle(Library::New()); | 5328 const Library& result = Library::Handle(Library::New()); |
| 5324 result.raw_ptr()->name_ = url.raw(); | 5329 result.raw_ptr()->name_ = url.raw(); |
| 5325 result.raw_ptr()->url_ = url.raw(); | 5330 result.raw_ptr()->url_ = url.raw(); |
| 5326 result.raw_ptr()->private_key_ = Scanner::AllocatePrivateKey(result); | 5331 result.raw_ptr()->private_key_ = Scanner::AllocatePrivateKey(result); |
| 5327 result.raw_ptr()->dictionary_ = Array::Empty(); | 5332 result.raw_ptr()->dictionary_ = Array::Empty(); |
| 5328 result.raw_ptr()->anonymous_classes_ = Array::Empty(); | 5333 result.raw_ptr()->anonymous_classes_ = Array::Empty(); |
| 5329 result.raw_ptr()->num_anonymous_ = 0; | 5334 result.raw_ptr()->num_anonymous_ = 0; |
| 5330 result.raw_ptr()->import_map_ = Array::Empty(); | 5335 result.raw_ptr()->import_map_ = Array::Empty(); |
| 5331 result.raw_ptr()->imports_ = Array::Empty(); | 5336 result.raw_ptr()->imports_ = Array::Empty(); |
| 5332 result.raw_ptr()->next_registered_ = Library::null(); | |
| 5333 result.raw_ptr()->loaded_scripts_ = Array::null(); | 5337 result.raw_ptr()->loaded_scripts_ = Array::null(); |
| 5334 result.set_native_entry_resolver(NULL); | 5338 result.set_native_entry_resolver(NULL); |
| 5335 result.raw_ptr()->corelib_imported_ = true; | 5339 result.raw_ptr()->corelib_imported_ = true; |
| 5336 result.raw_ptr()->load_state_ = RawLibrary::kAllocated; | 5340 result.raw_ptr()->load_state_ = RawLibrary::kAllocated; |
| 5337 result.InitClassDictionary(); | 5341 result.InitClassDictionary(); |
| 5338 result.InitImportList(); | 5342 result.InitImportList(); |
| 5339 result.InitImportedIntoList(); | 5343 result.InitImportedIntoList(); |
| 5340 if (import_core_lib) { | 5344 if (import_core_lib) { |
| 5341 Library& core_lib = Library::Handle(Library::CoreLibrary()); | 5345 Library& core_lib = Library::Handle(Library::CoreLibrary()); |
| 5342 ASSERT(!core_lib.IsNull()); | 5346 ASSERT(!core_lib.IsNull()); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5420 cls_name = String::NewSymbol(name_buffer); | 5424 cls_name = String::NewSymbol(name_buffer); |
| 5421 Class::NewNativeWrapper(&native_flds_lib, cls_name, fld_cnt); | 5425 Class::NewNativeWrapper(&native_flds_lib, cls_name, fld_cnt); |
| 5422 } | 5426 } |
| 5423 } | 5427 } |
| 5424 | 5428 |
| 5425 | 5429 |
| 5426 RawLibrary* Library::LookupLibrary(const String &url) { | 5430 RawLibrary* Library::LookupLibrary(const String &url) { |
| 5427 Isolate* isolate = Isolate::Current(); | 5431 Isolate* isolate = Isolate::Current(); |
| 5428 Library& lib = Library::Handle(isolate, Library::null()); | 5432 Library& lib = Library::Handle(isolate, Library::null()); |
| 5429 String& lib_url = String::Handle(isolate, String::null()); | 5433 String& lib_url = String::Handle(isolate, String::null()); |
| 5430 lib = isolate->object_store()->registered_libraries(); | 5434 GrowableObjectArray& libs = GrowableObjectArray::Handle( |
| 5431 while (!lib.IsNull()) { | 5435 isolate, isolate->object_store()->libraries()); |
| 5436 for (int i = 0; i < libs.Length(); i++) { | |
| 5437 lib ^= libs.At(i); | |
| 5432 lib_url = lib.url(); | 5438 lib_url = lib.url(); |
| 5433 if (lib_url.Equals(url)) { | 5439 if (lib_url.Equals(url)) { |
| 5434 return lib.raw(); | 5440 return lib.raw(); |
| 5435 } | 5441 } |
| 5436 lib = lib.next_registered(); | |
| 5437 } | 5442 } |
| 5438 return Library::null(); | 5443 return Library::null(); |
| 5439 } | 5444 } |
| 5440 | 5445 |
| 5441 | 5446 |
| 5442 RawString* Library::CheckForDuplicateDefinition() { | 5447 RawString* Library::CheckForDuplicateDefinition() { |
| 5443 Library& lib = Library::Handle(); | |
| 5444 Isolate* isolate = Isolate::Current(); | 5448 Isolate* isolate = Isolate::Current(); |
| 5445 ASSERT(isolate != NULL); | 5449 ASSERT(isolate != NULL); |
| 5446 ObjectStore* object_store = isolate->object_store(); | 5450 ObjectStore* object_store = isolate->object_store(); |
| 5447 ASSERT(object_store != NULL); | 5451 ASSERT(object_store != NULL); |
| 5448 lib ^= object_store->registered_libraries(); | 5452 const GrowableObjectArray& libs = |
| 5453 GrowableObjectArray::Handle(object_store->libraries()); | |
| 5454 Library& lib = Library::Handle(); | |
| 5449 String& error_message = String::Handle(); | 5455 String& error_message = String::Handle(); |
| 5450 while (!lib.IsNull()) { | 5456 for (int i = 0; i < libs.Length(); i++) { |
| 5457 lib ^= libs.At(i); | |
| 5451 error_message = lib.FindDuplicateDefinition(); | 5458 error_message = lib.FindDuplicateDefinition(); |
| 5452 if (!error_message.IsNull()) { | 5459 if (!error_message.IsNull()) { |
| 5453 return error_message.raw(); | 5460 return error_message.raw(); |
| 5454 } | 5461 } |
| 5455 lib ^= lib.next_registered(); | |
| 5456 } | 5462 } |
| 5457 return String::null(); | 5463 return String::null(); |
| 5458 } | 5464 } |
| 5459 | 5465 |
| 5460 | 5466 |
| 5461 bool Library::IsKeyUsed(intptr_t key) { | 5467 bool Library::IsKeyUsed(intptr_t key) { |
| 5462 intptr_t lib_key; | 5468 intptr_t lib_key; |
| 5469 const GrowableObjectArray& libs = GrowableObjectArray::Handle( | |
| 5470 Isolate::Current()->object_store()->libraries()); | |
| 5463 Library& lib = Library::Handle(); | 5471 Library& lib = Library::Handle(); |
| 5464 lib = Isolate::Current()->object_store()->registered_libraries(); | |
| 5465 String& lib_url = String::Handle(); | 5472 String& lib_url = String::Handle(); |
| 5466 while (!lib.IsNull()) { | 5473 for (int i = 0; i < libs.Length(); i++) { |
| 5474 lib ^= libs.At(i); | |
| 5467 lib_url ^= lib.url(); | 5475 lib_url ^= lib.url(); |
| 5468 lib_key = lib_url.Hash(); | 5476 lib_key = lib_url.Hash(); |
| 5469 if (lib_key == key) { | 5477 if (lib_key == key) { |
| 5470 return true; | 5478 return true; |
| 5471 } | 5479 } |
| 5472 lib = lib.next_registered(); | |
| 5473 } | 5480 } |
| 5474 return false; | 5481 return false; |
| 5475 } | 5482 } |
| 5476 | 5483 |
| 5477 | 5484 |
| 5478 RawString* Library::PrivateName(const String& name) const { | 5485 RawString* Library::PrivateName(const String& name) const { |
| 5479 ASSERT(ShouldBePrivate(name)); | 5486 ASSERT(ShouldBePrivate(name)); |
| 5480 // ASSERT(strchr(name, '@') == NULL); | 5487 // ASSERT(strchr(name, '@') == NULL); |
| 5481 String& str = String::Handle(); | 5488 String& str = String::Handle(); |
| 5482 str ^= name.raw(); | 5489 str ^= name.raw(); |
| 5483 str = String::Concat(str, String::Handle(this->private_key())); | 5490 str = String::Concat(str, String::Handle(this->private_key())); |
| 5484 str = String::NewSymbol(str); | 5491 str = String::NewSymbol(str); |
| 5485 return str.raw(); | 5492 return str.raw(); |
| 5486 } | 5493 } |
| 5487 | 5494 |
| 5488 | 5495 |
| 5496 RawLibrary* Library::GetLibrary(intptr_t index) { | |
| 5497 Isolate* isolate = Isolate::Current(); | |
| 5498 const GrowableObjectArray& libs = | |
| 5499 GrowableObjectArray::Handle(isolate->object_store()->libraries()); | |
| 5500 ASSERT(!libs.IsNull()); | |
| 5501 if ((0 <= index) && (index < libs.Length())) { | |
| 5502 const Library& lib = Library::CheckedHandle(libs.At(index)); | |
|
srdjan
2012/05/23 17:35:18
Should be ^=
hausner
2012/05/23 20:27:14
Done.
| |
| 5503 return lib.raw(); | |
| 5504 } | |
| 5505 return Library::null(); | |
| 5506 } | |
| 5507 | |
| 5508 | |
| 5489 void Library::Register() const { | 5509 void Library::Register() const { |
| 5490 ASSERT(Library::LookupLibrary(String::Handle(url())) == Library::null()); | 5510 ASSERT(Library::LookupLibrary(String::Handle(url())) == Library::null()); |
| 5491 raw_ptr()->next_registered_ = | 5511 ObjectStore* object_store = Isolate::Current()->object_store(); |
| 5492 Isolate::Current()->object_store()->registered_libraries(); | 5512 GrowableObjectArray& libs = |
| 5493 Isolate::Current()->object_store()->set_registered_libraries(*this); | 5513 GrowableObjectArray::Handle(object_store->libraries()); |
| 5514 ASSERT(!libs.IsNull()); | |
| 5515 libs.Add(*this); | |
| 5494 } | 5516 } |
| 5495 | 5517 |
| 5496 | 5518 |
| 5497 RawLibrary* Library::CoreLibrary() { | 5519 RawLibrary* Library::CoreLibrary() { |
| 5498 return Isolate::Current()->object_store()->core_library(); | 5520 return Isolate::Current()->object_store()->core_library(); |
| 5499 } | 5521 } |
| 5500 | 5522 |
| 5501 | 5523 |
| 5502 RawLibrary* Library::CoreImplLibrary() { | 5524 RawLibrary* Library::CoreImplLibrary() { |
| 5503 return Isolate::Current()->object_store()->core_impl_library(); | 5525 return Isolate::Current()->object_store()->core_impl_library(); |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5683 } | 5705 } |
| 5684 | 5706 |
| 5685 | 5707 |
| 5686 void LibraryPrefix::set_num_libs(intptr_t value) const { | 5708 void LibraryPrefix::set_num_libs(intptr_t value) const { |
| 5687 raw_ptr()->num_libs_ = value; | 5709 raw_ptr()->num_libs_ = value; |
| 5688 } | 5710 } |
| 5689 | 5711 |
| 5690 | 5712 |
| 5691 RawError* Library::CompileAll() { | 5713 RawError* Library::CompileAll() { |
| 5692 Error& error = Error::Handle(); | 5714 Error& error = Error::Handle(); |
| 5693 Library& lib = Library::Handle( | 5715 const GrowableObjectArray& libs = GrowableObjectArray::Handle( |
| 5694 Isolate::Current()->object_store()->registered_libraries()); | 5716 Isolate::Current()->object_store()->libraries()); |
| 5717 Library& lib = Library::Handle(); | |
| 5695 Class& cls = Class::Handle(); | 5718 Class& cls = Class::Handle(); |
| 5696 while (!lib.IsNull()) { | 5719 for (int i = 0; i < libs.Length(); i++) { |
| 5720 lib ^= libs.At(i); | |
| 5697 ClassDictionaryIterator it(lib); | 5721 ClassDictionaryIterator it(lib); |
| 5698 while (it.HasNext()) { | 5722 while (it.HasNext()) { |
| 5699 cls ^= it.GetNextClass(); | 5723 cls ^= it.GetNextClass(); |
| 5700 if (!cls.is_interface()) { | 5724 if (!cls.is_interface()) { |
| 5701 error = Compiler::CompileAllFunctions(cls); | 5725 error = Compiler::CompileAllFunctions(cls); |
| 5702 if (!error.IsNull()) { | 5726 if (!error.IsNull()) { |
| 5703 return error.raw(); | 5727 return error.raw(); |
| 5704 } | 5728 } |
| 5705 } | 5729 } |
| 5706 } | 5730 } |
| 5707 Array& anon_classes = Array::Handle(lib.raw_ptr()->anonymous_classes_); | 5731 Array& anon_classes = Array::Handle(lib.raw_ptr()->anonymous_classes_); |
| 5708 for (int i = 0; i < lib.raw_ptr()->num_anonymous_; i++) { | 5732 for (int i = 0; i < lib.raw_ptr()->num_anonymous_; i++) { |
| 5709 cls ^= anon_classes.At(i); | 5733 cls ^= anon_classes.At(i); |
| 5710 ASSERT(!cls.is_interface()); | 5734 ASSERT(!cls.is_interface()); |
| 5711 error = Compiler::CompileAllFunctions(cls); | 5735 error = Compiler::CompileAllFunctions(cls); |
| 5712 if (!error.IsNull()) { | 5736 if (!error.IsNull()) { |
| 5713 return error.raw(); | 5737 return error.raw(); |
| 5714 } | 5738 } |
| 5715 } | 5739 } |
| 5716 lib = lib.next_registered(); | |
| 5717 } | 5740 } |
| 5718 return error.raw(); | 5741 return error.raw(); |
| 5719 } | 5742 } |
| 5720 | 5743 |
| 5721 | 5744 |
| 5722 RawInstructions* Instructions::New(intptr_t size) { | 5745 RawInstructions* Instructions::New(intptr_t size) { |
| 5723 const Class& instructions_class = Class::Handle(Object::instructions_class()); | 5746 const Class& instructions_class = Class::Handle(Object::instructions_class()); |
| 5724 Instructions& result = Instructions::Handle(); | 5747 Instructions& result = Instructions::Handle(); |
| 5725 { | 5748 { |
| 5726 uword aligned_size = Instructions::InstanceSize(size); | 5749 uword aligned_size = Instructions::InstanceSize(size); |
| (...skipping 4315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 10042 const String& str = String::Handle(pattern()); | 10065 const String& str = String::Handle(pattern()); |
| 10043 const char* format = "JSRegExp: pattern=%s flags=%s"; | 10066 const char* format = "JSRegExp: pattern=%s flags=%s"; |
| 10044 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); | 10067 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); |
| 10045 char* chars = reinterpret_cast<char*>( | 10068 char* chars = reinterpret_cast<char*>( |
| 10046 Isolate::Current()->current_zone()->Allocate(len + 1)); | 10069 Isolate::Current()->current_zone()->Allocate(len + 1)); |
| 10047 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); | 10070 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); |
| 10048 return chars; | 10071 return chars; |
| 10049 } | 10072 } |
| 10050 | 10073 |
| 10051 } // namespace dart | 10074 } // namespace dart |
| OLD | NEW |