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 1225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1236 pending_classes.Add(cls); | 1236 pending_classes.Add(cls); |
1237 | 1237 |
1238 cls = Class::NewStringClass(kExternalTwoByteStringCid); | 1238 cls = Class::NewStringClass(kExternalTwoByteStringCid); |
1239 object_store->set_external_two_byte_string_class(cls); | 1239 object_store->set_external_two_byte_string_class(cls); |
1240 RegisterPrivateClass(cls, Symbols::ExternalTwoByteString(), core_lib); | 1240 RegisterPrivateClass(cls, Symbols::ExternalTwoByteString(), core_lib); |
1241 pending_classes.Add(cls); | 1241 pending_classes.Add(cls); |
1242 | 1242 |
1243 // Pre-register the isolate library so the native class implementations | 1243 // Pre-register the isolate library so the native class implementations |
1244 // can be hooked up before compiling it. | 1244 // can be hooked up before compiling it. |
1245 Library& isolate_lib = | 1245 Library& isolate_lib = |
1246 Library::Handle(zone, Library::LookupLibrary(Symbols::DartIsolate())); | 1246 Library::Handle(zone, Library::LookupLibrary(thread, |
1247 Symbols::DartIsolate())); | |
1247 if (isolate_lib.IsNull()) { | 1248 if (isolate_lib.IsNull()) { |
1248 isolate_lib = Library::NewLibraryHelper(Symbols::DartIsolate(), true); | 1249 isolate_lib = Library::NewLibraryHelper(Symbols::DartIsolate(), true); |
1249 isolate_lib.SetLoadRequested(); | 1250 isolate_lib.SetLoadRequested(); |
1250 isolate_lib.Register(); | 1251 isolate_lib.Register(thread); |
1251 object_store->set_bootstrap_library(ObjectStore::kIsolate, isolate_lib); | 1252 object_store->set_bootstrap_library(ObjectStore::kIsolate, isolate_lib); |
1252 } | 1253 } |
1253 ASSERT(!isolate_lib.IsNull()); | 1254 ASSERT(!isolate_lib.IsNull()); |
1254 ASSERT(isolate_lib.raw() == Library::IsolateLibrary()); | 1255 ASSERT(isolate_lib.raw() == Library::IsolateLibrary()); |
1255 | 1256 |
1256 cls = Class::New<Capability>(); | 1257 cls = Class::New<Capability>(); |
1257 RegisterPrivateClass(cls, Symbols::_CapabilityImpl(), isolate_lib); | 1258 RegisterPrivateClass(cls, Symbols::_CapabilityImpl(), isolate_lib); |
1258 pending_classes.Add(cls); | 1259 pending_classes.Add(cls); |
1259 | 1260 |
1260 cls = Class::New<ReceivePort>(); | 1261 cls = Class::New<ReceivePort>(); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1358 pending_classes.Add(cls); | 1359 pending_classes.Add(cls); |
1359 object_store->set_closure_class(cls); | 1360 object_store->set_closure_class(cls); |
1360 | 1361 |
1361 cls = Class::New<WeakProperty>(); | 1362 cls = Class::New<WeakProperty>(); |
1362 object_store->set_weak_property_class(cls); | 1363 object_store->set_weak_property_class(cls); |
1363 RegisterPrivateClass(cls, Symbols::_WeakProperty(), core_lib); | 1364 RegisterPrivateClass(cls, Symbols::_WeakProperty(), core_lib); |
1364 | 1365 |
1365 // Pre-register the mirrors library so we can place the vm class | 1366 // Pre-register the mirrors library so we can place the vm class |
1366 // MirrorReference there rather than the core library. | 1367 // MirrorReference there rather than the core library. |
1367 NOT_IN_PRODUCT( | 1368 NOT_IN_PRODUCT( |
1368 lib = Library::LookupLibrary(Symbols::DartMirrors()); | 1369 lib = Library::LookupLibrary(thread, Symbols::DartMirrors()); |
1369 if (lib.IsNull()) { | 1370 if (lib.IsNull()) { |
1370 lib = Library::NewLibraryHelper(Symbols::DartMirrors(), true); | 1371 lib = Library::NewLibraryHelper(Symbols::DartMirrors(), true); |
1371 lib.SetLoadRequested(); | 1372 lib.SetLoadRequested(); |
1372 lib.Register(); | 1373 lib.Register(thread); |
1373 object_store->set_bootstrap_library(ObjectStore::kMirrors, lib); | 1374 object_store->set_bootstrap_library(ObjectStore::kMirrors, lib); |
1374 } | 1375 } |
1375 ASSERT(!lib.IsNull()); | 1376 ASSERT(!lib.IsNull()); |
1376 ASSERT(lib.raw() == Library::MirrorsLibrary()); | 1377 ASSERT(lib.raw() == Library::MirrorsLibrary()); |
1377 | 1378 |
1378 cls = Class::New<MirrorReference>(); | 1379 cls = Class::New<MirrorReference>(); |
1379 RegisterPrivateClass(cls, Symbols::_MirrorReference(), lib); | 1380 RegisterPrivateClass(cls, Symbols::_MirrorReference(), lib); |
1380 ) | 1381 ) |
1381 | 1382 |
1382 // Pre-register the collection library so we can place the vm class | 1383 // Pre-register the collection library so we can place the vm class |
1383 // LinkedHashMap there rather than the core library. | 1384 // LinkedHashMap there rather than the core library. |
1384 lib = Library::LookupLibrary(Symbols::DartCollection()); | 1385 lib = Library::LookupLibrary(thread, Symbols::DartCollection()); |
1385 if (lib.IsNull()) { | 1386 if (lib.IsNull()) { |
1386 lib = Library::NewLibraryHelper(Symbols::DartCollection(), true); | 1387 lib = Library::NewLibraryHelper(Symbols::DartCollection(), true); |
1387 lib.SetLoadRequested(); | 1388 lib.SetLoadRequested(); |
1388 lib.Register(); | 1389 lib.Register(thread); |
1389 object_store->set_bootstrap_library(ObjectStore::kCollection, lib); | 1390 object_store->set_bootstrap_library(ObjectStore::kCollection, lib); |
1390 } | 1391 } |
1391 ASSERT(!lib.IsNull()); | 1392 ASSERT(!lib.IsNull()); |
1392 ASSERT(lib.raw() == Library::CollectionLibrary()); | 1393 ASSERT(lib.raw() == Library::CollectionLibrary()); |
1393 cls = Class::New<LinkedHashMap>(); | 1394 cls = Class::New<LinkedHashMap>(); |
1394 object_store->set_linked_hash_map_class(cls); | 1395 object_store->set_linked_hash_map_class(cls); |
1395 cls.set_type_arguments_field_offset(LinkedHashMap::type_arguments_offset()); | 1396 cls.set_type_arguments_field_offset(LinkedHashMap::type_arguments_offset()); |
1396 cls.set_num_type_arguments(2); | 1397 cls.set_num_type_arguments(2); |
1397 cls.set_num_own_type_arguments(2); | 1398 cls.set_num_own_type_arguments(2); |
1398 RegisterPrivateClass(cls, Symbols::_LinkedHashMap(), lib); | 1399 RegisterPrivateClass(cls, Symbols::_LinkedHashMap(), lib); |
1399 pending_classes.Add(cls); | 1400 pending_classes.Add(cls); |
1400 | 1401 |
1401 // Pre-register the developer library so we can place the vm class | 1402 // Pre-register the developer library so we can place the vm class |
1402 // UserTag there rather than the core library. | 1403 // UserTag there rather than the core library. |
1403 lib = Library::LookupLibrary(Symbols::DartDeveloper()); | 1404 lib = Library::LookupLibrary(thread, Symbols::DartDeveloper()); |
1404 if (lib.IsNull()) { | 1405 if (lib.IsNull()) { |
1405 lib = Library::NewLibraryHelper(Symbols::DartDeveloper(), true); | 1406 lib = Library::NewLibraryHelper(Symbols::DartDeveloper(), true); |
1406 lib.SetLoadRequested(); | 1407 lib.SetLoadRequested(); |
1407 lib.Register(); | 1408 lib.Register(thread); |
1408 object_store->set_bootstrap_library(ObjectStore::kDeveloper, lib); | 1409 object_store->set_bootstrap_library(ObjectStore::kDeveloper, lib); |
1409 } | 1410 } |
1410 ASSERT(!lib.IsNull()); | 1411 ASSERT(!lib.IsNull()); |
1411 ASSERT(lib.raw() == Library::DeveloperLibrary()); | 1412 ASSERT(lib.raw() == Library::DeveloperLibrary()); |
1412 | 1413 |
1413 lib = Library::LookupLibrary(Symbols::DartDeveloper()); | 1414 lib = Library::LookupLibrary(thread, Symbols::DartDeveloper()); |
1414 ASSERT(!lib.IsNull()); | 1415 ASSERT(!lib.IsNull()); |
1415 cls = Class::New<UserTag>(); | 1416 cls = Class::New<UserTag>(); |
1416 RegisterPrivateClass(cls, Symbols::_UserTag(), lib); | 1417 RegisterPrivateClass(cls, Symbols::_UserTag(), lib); |
1417 pending_classes.Add(cls); | 1418 pending_classes.Add(cls); |
1418 | 1419 |
1419 // Setup some default native field classes which can be extended for | 1420 // Setup some default native field classes which can be extended for |
1420 // specifying native fields in dart classes. | 1421 // specifying native fields in dart classes. |
1421 Library::InitNativeWrappersLibrary(isolate); | 1422 Library::InitNativeWrappersLibrary(isolate); |
1422 ASSERT(object_store->native_wrappers_library() != Library::null()); | 1423 ASSERT(object_store->native_wrappers_library() != Library::null()); |
1423 | 1424 |
1424 // Pre-register the typed_data library so the native class implementations | 1425 // Pre-register the typed_data library so the native class implementations |
1425 // can be hooked up before compiling it. | 1426 // can be hooked up before compiling it. |
1426 lib = Library::LookupLibrary(Symbols::DartTypedData()); | 1427 lib = Library::LookupLibrary(thread, Symbols::DartTypedData()); |
1427 if (lib.IsNull()) { | 1428 if (lib.IsNull()) { |
1428 lib = Library::NewLibraryHelper(Symbols::DartTypedData(), true); | 1429 lib = Library::NewLibraryHelper(Symbols::DartTypedData(), true); |
1429 lib.SetLoadRequested(); | 1430 lib.SetLoadRequested(); |
1430 lib.Register(); | 1431 lib.Register(thread); |
1431 object_store->set_bootstrap_library(ObjectStore::kTypedData, lib); | 1432 object_store->set_bootstrap_library(ObjectStore::kTypedData, lib); |
1432 } | 1433 } |
1433 ASSERT(!lib.IsNull()); | 1434 ASSERT(!lib.IsNull()); |
1434 ASSERT(lib.raw() == Library::TypedDataLibrary()); | 1435 ASSERT(lib.raw() == Library::TypedDataLibrary()); |
1435 #define REGISTER_TYPED_DATA_CLASS(clazz) \ | 1436 #define REGISTER_TYPED_DATA_CLASS(clazz) \ |
1436 cls = Class::NewTypedDataClass(kTypedData##clazz##ArrayCid); \ | 1437 cls = Class::NewTypedDataClass(kTypedData##clazz##ArrayCid); \ |
1437 RegisterClass(cls, Symbols::clazz##List(), lib); \ | 1438 RegisterClass(cls, Symbols::clazz##List(), lib); \ |
1438 | 1439 |
1439 DART_CLASS_LIST_TYPED_DATA(REGISTER_TYPED_DATA_CLASS); | 1440 DART_CLASS_LIST_TYPED_DATA(REGISTER_TYPED_DATA_CLASS); |
1440 #undef REGISTER_TYPED_DATA_CLASS | 1441 #undef REGISTER_TYPED_DATA_CLASS |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1575 | 1576 |
1576 ClassFinalizer::VerifyBootstrapClasses(); | 1577 ClassFinalizer::VerifyBootstrapClasses(); |
1577 | 1578 |
1578 // Set up the intrinsic state of all functions (core, math and typed data). | 1579 // Set up the intrinsic state of all functions (core, math and typed data). |
1579 Intrinsifier::InitializeState(); | 1580 Intrinsifier::InitializeState(); |
1580 | 1581 |
1581 // Set up recognized state of all functions (core, math and typed data). | 1582 // Set up recognized state of all functions (core, math and typed data). |
1582 MethodRecognizer::InitializeState(); | 1583 MethodRecognizer::InitializeState(); |
1583 | 1584 |
1584 // Adds static const fields (class ids) to the class 'ClassID'); | 1585 // Adds static const fields (class ids) to the class 'ClassID'); |
1585 lib = Library::LookupLibrary(Symbols::DartInternal()); | 1586 lib = Library::LookupLibrary(thread, Symbols::DartInternal()); |
1586 ASSERT(!lib.IsNull()); | 1587 ASSERT(!lib.IsNull()); |
1587 cls = lib.LookupClassAllowPrivate(Symbols::ClassID()); | 1588 cls = lib.LookupClassAllowPrivate(Symbols::ClassID()); |
1588 ASSERT(!cls.IsNull()); | 1589 ASSERT(!cls.IsNull()); |
1589 Field& field = Field::Handle(zone); | 1590 Field& field = Field::Handle(zone); |
1590 Smi& value = Smi::Handle(zone); | 1591 Smi& value = Smi::Handle(zone); |
1591 String& field_name = String::Handle(zone); | 1592 String& field_name = String::Handle(zone); |
1592 | 1593 |
1593 #define CLASS_LIST_WITH_NULL(V) \ | 1594 #define CLASS_LIST_WITH_NULL(V) \ |
1594 V(Null) \ | 1595 V(Null) \ |
1595 CLASS_LIST_NO_OBJECT(V) | 1596 CLASS_LIST_NO_OBJECT(V) |
(...skipping 8942 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
10538 return result.raw(); | 10539 return result.raw(); |
10539 } | 10540 } |
10540 | 10541 |
10541 | 10542 |
10542 RawLibrary* Library::New(const String& url) { | 10543 RawLibrary* Library::New(const String& url) { |
10543 return NewLibraryHelper(url, false); | 10544 return NewLibraryHelper(url, false); |
10544 } | 10545 } |
10545 | 10546 |
10546 | 10547 |
10547 void Library::InitCoreLibrary(Isolate* isolate) { | 10548 void Library::InitCoreLibrary(Isolate* isolate) { |
10549 Thread* thread = Thread::Current(); | |
10550 Zone* zone = thread->zone(); | |
10548 const String& core_lib_url = Symbols::DartCore(); | 10551 const String& core_lib_url = Symbols::DartCore(); |
10549 const Library& core_lib = | 10552 const Library& core_lib = |
10550 Library::Handle(Library::NewLibraryHelper(core_lib_url, false)); | 10553 Library::Handle(zone, Library::NewLibraryHelper(core_lib_url, false)); |
10551 core_lib.SetLoadRequested(); | 10554 core_lib.SetLoadRequested(); |
10552 core_lib.Register(); | 10555 core_lib.Register(thread); |
10553 isolate->object_store()->set_bootstrap_library(ObjectStore::kCore, core_lib); | 10556 isolate->object_store()->set_bootstrap_library(ObjectStore::kCore, core_lib); |
10554 isolate->object_store()->set_root_library(Library::Handle()); | 10557 isolate->object_store()->set_root_library(Library::Handle()); |
10555 | 10558 |
10556 // Hook up predefined classes without setting their library pointers. These | 10559 // Hook up predefined classes without setting their library pointers. These |
10557 // classes are coming from the VM isolate, and are shared between multiple | 10560 // classes are coming from the VM isolate, and are shared between multiple |
10558 // isolates so setting their library pointers would be wrong. | 10561 // isolates so setting their library pointers would be wrong. |
10559 const Class& cls = Class::Handle(Object::dynamic_class()); | 10562 const Class& cls = Class::Handle(zone, Object::dynamic_class()); |
10560 core_lib.AddObject(cls, String::Handle(cls.Name())); | 10563 core_lib.AddObject(cls, String::Handle(zone, cls.Name())); |
10561 } | 10564 } |
10562 | 10565 |
10563 | 10566 |
10564 RawObject* Library::Evaluate(const String& expr, | 10567 RawObject* Library::Evaluate(const String& expr, |
10565 const Array& param_names, | 10568 const Array& param_names, |
10566 const Array& param_values) const { | 10569 const Array& param_values) const { |
10567 // Evaluate the expression as a static function of the toplevel class. | 10570 // Evaluate the expression as a static function of the toplevel class. |
10568 Class& top_level_class = Class::Handle(toplevel_class()); | 10571 Class& top_level_class = Class::Handle(toplevel_class()); |
10569 ASSERT(top_level_class.is_finalized()); | 10572 ASSERT(top_level_class.is_finalized()); |
10570 return top_level_class.Evaluate(expr, param_names, param_values); | 10573 return top_level_class.Evaluate(expr, param_names, param_values); |
10571 } | 10574 } |
10572 | 10575 |
10573 | 10576 |
10574 void Library::InitNativeWrappersLibrary(Isolate* isolate) { | 10577 void Library::InitNativeWrappersLibrary(Isolate* isolate) { |
10575 static const int kNumNativeWrappersClasses = 4; | 10578 static const int kNumNativeWrappersClasses = 4; |
10576 COMPILE_ASSERT((kNumNativeWrappersClasses > 0) && | 10579 COMPILE_ASSERT((kNumNativeWrappersClasses > 0) && |
10577 (kNumNativeWrappersClasses < 10)); | 10580 (kNumNativeWrappersClasses < 10)); |
10578 Thread* thread = Thread::Current(); | 10581 Thread* thread = Thread::Current(); |
10579 Zone* zone = thread->zone(); | 10582 Zone* zone = thread->zone(); |
10580 const String& native_flds_lib_url = Symbols::DartNativeWrappers(); | 10583 const String& native_flds_lib_url = Symbols::DartNativeWrappers(); |
10581 const Library& native_flds_lib = Library::Handle(zone, | 10584 const Library& native_flds_lib = Library::Handle(zone, |
10582 Library::NewLibraryHelper(native_flds_lib_url, false)); | 10585 Library::NewLibraryHelper(native_flds_lib_url, false)); |
10583 const String& native_flds_lib_name = Symbols::DartNativeWrappersLibName(); | 10586 const String& native_flds_lib_name = Symbols::DartNativeWrappersLibName(); |
10584 native_flds_lib.SetName(native_flds_lib_name); | 10587 native_flds_lib.SetName(native_flds_lib_name); |
10585 native_flds_lib.SetLoadRequested(); | 10588 native_flds_lib.SetLoadRequested(); |
10586 native_flds_lib.Register(); | 10589 native_flds_lib.Register(thread); |
10587 native_flds_lib.SetLoadInProgress(); | 10590 native_flds_lib.SetLoadInProgress(); |
10588 isolate->object_store()->set_native_wrappers_library(native_flds_lib); | 10591 isolate->object_store()->set_native_wrappers_library(native_flds_lib); |
10589 static const char* const kNativeWrappersClass = "NativeFieldWrapperClass"; | 10592 static const char* const kNativeWrappersClass = "NativeFieldWrapperClass"; |
10590 static const int kNameLength = 25; | 10593 static const int kNameLength = 25; |
10591 ASSERT(kNameLength == (strlen(kNativeWrappersClass) + 1 + 1)); | 10594 ASSERT(kNameLength == (strlen(kNativeWrappersClass) + 1 + 1)); |
10592 char name_buffer[kNameLength]; | 10595 char name_buffer[kNameLength]; |
10593 String& cls_name = String::Handle(zone); | 10596 String& cls_name = String::Handle(zone); |
10594 for (int fld_cnt = 1; fld_cnt <= kNumNativeWrappersClasses; fld_cnt++) { | 10597 for (int fld_cnt = 1; fld_cnt <= kNumNativeWrappersClasses; fld_cnt++) { |
10595 OS::SNPrint(name_buffer, | 10598 OS::SNPrint(name_buffer, |
10596 kNameLength, | 10599 kNameLength, |
10597 "%s%d", | 10600 "%s%d", |
10598 kNativeWrappersClass, | 10601 kNativeWrappersClass, |
10599 fld_cnt); | 10602 fld_cnt); |
10600 cls_name = Symbols::New(thread, name_buffer); | 10603 cls_name = Symbols::New(thread, name_buffer); |
10601 Class::NewNativeWrapper(native_flds_lib, cls_name, fld_cnt); | 10604 Class::NewNativeWrapper(native_flds_lib, cls_name, fld_cnt); |
10602 } | 10605 } |
10603 native_flds_lib.SetLoaded(); | 10606 native_flds_lib.SetLoaded(); |
10604 } | 10607 } |
10605 | 10608 |
10606 | 10609 |
10610 // LibraryLookupSet maps URIs to libraries. | |
10611 class LibraryLookupTraits { | |
10612 public: | |
10613 static const char* Name() { return "LibraryLookupTraits"; } | |
10614 static bool ReportStats() { return false; } | |
10615 | |
10616 static bool IsMatch(const Object& a, const Object& b) { | |
10617 const String& a_str = String::Cast(a); | |
10618 const String& b_str = String::Cast(b); | |
10619 | |
10620 ASSERT(a_str.HasHash() && b_str.HasHash()); | |
10621 return a_str.Equals(b_str); | |
10622 } | |
10623 | |
10624 static uword Hash(const Object& key) { | |
10625 return String::Cast(key).Hash(); | |
10626 } | |
10627 | |
10628 static RawObject* NewKey(const String& str) { | |
10629 return str.raw(); | |
10630 } | |
10631 }; | |
10632 typedef UnorderedHashMap<LibraryLookupTraits> LibraryLookupMap; | |
10633 | |
10634 | |
10607 // Returns library with given url in current isolate, or NULL. | 10635 // Returns library with given url in current isolate, or NULL. |
10608 RawLibrary* Library::LookupLibrary(const String &url) { | 10636 RawLibrary* Library::LookupLibrary(Thread* thread, const String &url) { |
10609 Thread* thread = Thread::Current(); | |
10610 Zone* zone = thread->zone(); | 10637 Zone* zone = thread->zone(); |
10611 Isolate* isolate = thread->isolate(); | 10638 Isolate* isolate = thread->isolate(); |
10612 Library& lib = Library::Handle(zone, Library::null()); | 10639 ObjectStore* object_store = isolate->object_store(); |
10613 String& lib_url = String::Handle(zone, String::null()); | |
10614 GrowableObjectArray& libs = GrowableObjectArray::Handle( | |
10615 zone, isolate->object_store()->libraries()); | |
10616 | 10640 |
10617 // Make sure the URL string has an associated hash code | 10641 // Make sure the URL string has an associated hash code |
10618 // to speed up the repeated equality checks. | 10642 // to speed up the repeated equality checks. |
10619 url.Hash(); | 10643 url.Hash(); |
10620 | 10644 |
10621 intptr_t len = libs.Length(); | 10645 // Use the libraries map to lookup the library by URL. |
10622 for (intptr_t i = 0; i < len; i++) { | 10646 Library& lib = Library::Handle(zone); |
10623 lib ^= libs.At(i); | 10647 if (object_store->libraries_map() == Array::null()) { |
10624 lib_url ^= lib.url(); | 10648 return Library::null(); |
10625 | 10649 } else { |
10626 ASSERT(url.HasHash() && lib_url.HasHash()); | 10650 LibraryLookupMap map(object_store->libraries_map()); |
10627 if (lib_url.Equals(url)) { | 10651 lib ^= map.GetOrNull(url); |
10628 return lib.raw(); | 10652 ASSERT(map.Release().raw() == object_store->libraries_map()); |
10629 } | |
10630 } | 10653 } |
10631 return Library::null(); | 10654 return lib.raw(); |
10632 } | 10655 } |
10633 | 10656 |
10634 | 10657 |
10635 RawError* Library::Patch(const Script& script) const { | 10658 RawError* Library::Patch(const Script& script) const { |
10636 ASSERT(script.kind() == RawScript::kPatchTag); | 10659 ASSERT(script.kind() == RawScript::kPatchTag); |
10637 return Compiler::Compile(*this, script); | 10660 return Compiler::Compile(*this, script); |
10638 } | 10661 } |
10639 | 10662 |
10640 | 10663 |
10641 bool Library::IsPrivate(const String& name) { | 10664 bool Library::IsPrivate(const String& name) { |
10642 if (ShouldBePrivate(name)) return true; | 10665 if (ShouldBePrivate(name)) return true; |
10643 // Factory names: List._fromLiteral. | 10666 // Factory names: List._fromLiteral. |
10644 for (intptr_t i = 1; i < name.Length() - 1; i++) { | 10667 for (intptr_t i = 1; i < name.Length() - 1; i++) { |
10645 if (name.CharAt(i) == '.') { | 10668 if (name.CharAt(i) == '.') { |
10646 if (name.CharAt(i + 1) == '_') { | 10669 if (name.CharAt(i + 1) == '_') { |
10647 return true; | 10670 return true; |
10648 } | 10671 } |
10649 } | 10672 } |
10650 } | 10673 } |
10651 return false; | 10674 return false; |
10652 } | 10675 } |
10653 | 10676 |
10654 | 10677 |
10655 bool Library::IsKeyUsed(intptr_t key) { | 10678 // Create a private key for this library. It is based on the hash of the |
10656 intptr_t lib_key; | 10679 // library URI and the sequence number of the library to guarantee unique |
10657 const GrowableObjectArray& libs = GrowableObjectArray::Handle( | 10680 // private keys without having to verify. |
10658 Isolate::Current()->object_store()->libraries()); | 10681 void Library::AllocatePrivateKey() const { |
10659 Library& lib = Library::Handle(); | 10682 Thread* thread = Thread::Current(); |
10660 String& lib_url = String::Handle(); | 10683 Zone* zone = thread->zone(); |
10661 for (int i = 0; i < libs.Length(); i++) { | 10684 Isolate* isolate = thread->isolate(); |
10662 lib ^= libs.At(i); | |
10663 lib_url ^= lib.url(); | |
10664 lib_key = lib_url.Hash(); | |
10665 if (lib_key == key) { | |
10666 return true; | |
10667 } | |
10668 } | |
10669 return false; | |
10670 } | |
10671 | 10685 |
10686 // Format of the private key is: "@<sequence number><6 digits of hash> | |
10687 const intptr_t hash_mask = 0x7FFFF; | |
10672 | 10688 |
10673 void Library::AllocatePrivateKey() const { | 10689 const String& url = String::Handle(zone, this->url()); |
10674 const String& url = String::Handle(this->url()); | 10690 intptr_t hash_value = url.Hash() & hash_mask; |
10675 intptr_t key_value = url.Hash() & kIntptrMax; | 10691 |
10676 while ((key_value == 0) || Library::IsKeyUsed(key_value)) { | 10692 const GrowableObjectArray& libs = GrowableObjectArray::Handle(zone, |
10677 key_value = (key_value + 1) & kIntptrMax; | 10693 isolate->object_store()->libraries()); |
10678 } | 10694 intptr_t sequence_value = libs.Length(); |
10679 ASSERT(key_value > 0); | 10695 |
10680 char private_key[32]; | 10696 char private_key[32]; |
10681 OS::SNPrint(private_key, sizeof(private_key), | 10697 OS::SNPrint(private_key, sizeof(private_key), |
10682 "%c%" Pd "", kPrivateKeySeparator, key_value); | 10698 "%c%" Pd "%06" Pd "", |
10699 kPrivateKeySeparator, sequence_value, hash_value); | |
10683 StorePointer(&raw_ptr()->private_key_, String::New(private_key, Heap::kOld)); | 10700 StorePointer(&raw_ptr()->private_key_, String::New(private_key, Heap::kOld)); |
10684 } | 10701 } |
10685 | 10702 |
10686 | 10703 |
10687 const String& Library::PrivateCoreLibName(const String& member) { | 10704 const String& Library::PrivateCoreLibName(const String& member) { |
10688 const Library& core_lib = Library::Handle(Library::CoreLibrary()); | 10705 const Library& core_lib = Library::Handle(Library::CoreLibrary()); |
10689 const String& private_name = String::ZoneHandle(core_lib.PrivateName(member)); | 10706 const String& private_name = String::ZoneHandle(core_lib.PrivateName(member)); |
10690 return private_name; | 10707 return private_name; |
10691 } | 10708 } |
10692 | 10709 |
(...skipping 21 matching lines...) Expand all Loading... | |
10714 // ASSERT(strchr(name, '@') == NULL); | 10731 // ASSERT(strchr(name, '@') == NULL); |
10715 String& str = String::Handle(zone); | 10732 String& str = String::Handle(zone); |
10716 str = name.raw(); | 10733 str = name.raw(); |
10717 str = Symbols::FromConcat(thread, | 10734 str = Symbols::FromConcat(thread, |
10718 str, String::Handle(zone, this->private_key())); | 10735 str, String::Handle(zone, this->private_key())); |
10719 return str.raw(); | 10736 return str.raw(); |
10720 } | 10737 } |
10721 | 10738 |
10722 | 10739 |
10723 RawLibrary* Library::GetLibrary(intptr_t index) { | 10740 RawLibrary* Library::GetLibrary(intptr_t index) { |
10724 Isolate* isolate = Isolate::Current(); | 10741 Thread* thread = Thread::Current(); |
10742 Zone* zone = thread->zone(); | |
10743 Isolate* isolate = thread->isolate(); | |
10725 const GrowableObjectArray& libs = | 10744 const GrowableObjectArray& libs = |
10726 GrowableObjectArray::Handle(isolate->object_store()->libraries()); | 10745 GrowableObjectArray::Handle(zone, isolate->object_store()->libraries()); |
10727 ASSERT(!libs.IsNull()); | 10746 ASSERT(!libs.IsNull()); |
10728 if ((0 <= index) && (index < libs.Length())) { | 10747 if ((0 <= index) && (index < libs.Length())) { |
10729 Library& lib = Library::Handle(); | 10748 Library& lib = Library::Handle(zone); |
10730 lib ^= libs.At(index); | 10749 lib ^= libs.At(index); |
10731 return lib.raw(); | 10750 return lib.raw(); |
10732 } | 10751 } |
10733 return Library::null(); | 10752 return Library::null(); |
10734 } | 10753 } |
10735 | 10754 |
10736 | 10755 |
10737 void Library::Register() const { | 10756 void Library::Register(Thread* thread) const { |
10738 ASSERT(Library::LookupLibrary(String::Handle(url())) == Library::null()); | 10757 Zone* zone = thread->zone(); |
10739 ASSERT(String::Handle(url()).HasHash()); | 10758 Isolate* isolate = thread->isolate(); |
10740 ObjectStore* object_store = Isolate::Current()->object_store(); | 10759 ObjectStore* object_store = isolate->object_store(); |
10741 GrowableObjectArray& libs = | 10760 |
10742 GrowableObjectArray::Handle(object_store->libraries()); | 10761 // A library is "registered" in two places: |
10762 // - A growable array mapping from index to library. | |
10763 const String& lib_url = String::Handle(zone, url()); | |
10764 ASSERT(Library::LookupLibrary(thread, lib_url) == Library::null()); | |
10765 ASSERT(lib_url.HasHash()); | |
10766 GrowableObjectArray& libs = GrowableObjectArray::Handle(zone, | |
10767 object_store->libraries()); | |
10743 ASSERT(!libs.IsNull()); | 10768 ASSERT(!libs.IsNull()); |
10744 set_index(libs.Length()); | 10769 set_index(libs.Length()); |
10745 libs.Add(*this); | 10770 libs.Add(*this); |
10771 | |
10772 // - A map from URL string to library. | |
10773 if (object_store->libraries_map() == Array::null()) { | |
10774 LibraryLookupMap map(HashTables::New<LibraryLookupMap>(16, Heap::kOld)); | |
10775 object_store->set_libraries_map(map.Release()); | |
10776 } | |
10777 | |
10778 LibraryLookupMap map(object_store->libraries_map()); | |
10779 DEBUG_ONLY(Object& existing = Object::Handle(zone);) | |
10780 DEBUG_ONLY(existing =) | |
10781 map.InsertNewOrGetValue(lib_url, *this); | |
rmacnak
2016/05/05 16:53:31
Consider
bool present = map.UpdateOrInsert(lib_ur
Ivan Posva
2016/05/05 17:31:43
Thanks!
| |
10782 DEBUG_ONLY(ASSERT(existing.raw() == this->raw())); | |
10783 object_store->set_libraries_map(map.Release()); | |
10746 } | 10784 } |
10747 | 10785 |
10748 | 10786 |
10787 void Library::RegisterLibraries(Thread* thread, | |
10788 const GrowableObjectArray& libs) { | |
10789 Zone* zone = thread->zone(); | |
10790 Isolate* isolate = thread->isolate(); | |
10791 Library& lib = Library::Handle(zone); | |
10792 String& lib_url = String::Handle(zone); | |
10793 | |
10794 LibraryLookupMap map(HashTables::New<LibraryLookupMap>(16, Heap::kOld)); | |
10795 | |
10796 intptr_t len = libs.Length(); | |
10797 for (intptr_t i = 0; i < len; i++) { | |
10798 lib ^= libs.At(i); | |
10799 lib_url = lib.url(); | |
10800 map.InsertNewOrGetValue(lib_url, lib); | |
10801 } | |
10802 // Now rememeber these in the isolate's object store. | |
10803 isolate->object_store()->set_libraries(libs); | |
10804 isolate->object_store()->set_libraries_map(map.Release()); | |
10805 } | |
10806 | |
10807 | |
10749 RawLibrary* Library::AsyncLibrary() { | 10808 RawLibrary* Library::AsyncLibrary() { |
10750 return Isolate::Current()->object_store()->async_library(); | 10809 return Isolate::Current()->object_store()->async_library(); |
10751 } | 10810 } |
10752 | 10811 |
10753 | 10812 |
10754 RawLibrary* Library::ConvertLibrary() { | 10813 RawLibrary* Library::ConvertLibrary() { |
10755 return Isolate::Current()->object_store()->convert_library(); | 10814 return Isolate::Current()->object_store()->convert_library(); |
10756 } | 10815 } |
10757 | 10816 |
10758 | 10817 |
(...skipping 11644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
22403 return UserTag::null(); | 22462 return UserTag::null(); |
22404 } | 22463 } |
22405 | 22464 |
22406 | 22465 |
22407 const char* UserTag::ToCString() const { | 22466 const char* UserTag::ToCString() const { |
22408 const String& tag_label = String::Handle(label()); | 22467 const String& tag_label = String::Handle(label()); |
22409 return tag_label.ToCString(); | 22468 return tag_label.ToCString(); |
22410 } | 22469 } |
22411 | 22470 |
22412 } // namespace dart | 22471 } // namespace dart |
OLD | NEW |