| 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 947 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 958 Class& cls = Class::Handle(isolate); | 958 Class& cls = Class::Handle(isolate); |
| 959 Type& type = Type::Handle(isolate); | 959 Type& type = Type::Handle(isolate); |
| 960 Array& array = Array::Handle(isolate); | 960 Array& array = Array::Handle(isolate); |
| 961 Library& lib = Library::Handle(isolate); | 961 Library& lib = Library::Handle(isolate); |
| 962 | 962 |
| 963 // All RawArray fields will be initialized to an empty array, therefore | 963 // All RawArray fields will be initialized to an empty array, therefore |
| 964 // initialize array class first. | 964 // initialize array class first. |
| 965 cls = Class::New<Array>(); | 965 cls = Class::New<Array>(); |
| 966 object_store->set_array_class(cls); | 966 object_store->set_array_class(cls); |
| 967 | 967 |
| 968 // Array and ImmutableArray are the only VM classes that are parameterized. | 968 // VM classes that are parameterized (Array, ImmutableArray, |
| 969 // Since they are pre-finalized, CalculateFieldOffsets() is not called, so we | 969 // GrowableObjectArray, and LinkedHashMap) are also pre-finalized, |
| 970 // need to set the offset of their type_arguments_ field, which is explicitly | 970 // so CalculateFieldOffsets() is not called, so we need to set the |
| 971 // declared in RawArray. | 971 // offset of their type_arguments_ field, which is explicitly |
| 972 // declared in their respective Raw* classes. |
| 972 cls.set_type_arguments_field_offset(Array::type_arguments_offset()); | 973 cls.set_type_arguments_field_offset(Array::type_arguments_offset()); |
| 973 cls.set_num_type_arguments(1); | 974 cls.set_num_type_arguments(1); |
| 974 | 975 |
| 975 // Set up the growable object array class (Has to be done after the array | 976 // Set up the growable object array class (Has to be done after the array |
| 976 // class is setup as one of its field is an array object). | 977 // class is setup as one of its field is an array object). |
| 977 cls = Class::New<GrowableObjectArray>(); | 978 cls = Class::New<GrowableObjectArray>(); |
| 978 object_store->set_growable_object_array_class(cls); | 979 object_store->set_growable_object_array_class(cls); |
| 979 cls.set_type_arguments_field_offset( | 980 cls.set_type_arguments_field_offset( |
| 980 GrowableObjectArray::type_arguments_offset()); | 981 GrowableObjectArray::type_arguments_offset()); |
| 981 cls.set_num_type_arguments(1); | 982 cls.set_num_type_arguments(1); |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1218 // LinkedHashMap there rather than the core library. | 1219 // LinkedHashMap there rather than the core library. |
| 1219 lib = Library::LookupLibrary(Symbols::DartCollection()); | 1220 lib = Library::LookupLibrary(Symbols::DartCollection()); |
| 1220 if (lib.IsNull()) { | 1221 if (lib.IsNull()) { |
| 1221 lib = Library::NewLibraryHelper(Symbols::DartCollection(), true); | 1222 lib = Library::NewLibraryHelper(Symbols::DartCollection(), true); |
| 1222 lib.SetLoadRequested(); | 1223 lib.SetLoadRequested(); |
| 1223 lib.Register(); | 1224 lib.Register(); |
| 1224 object_store->set_bootstrap_library(ObjectStore::kCollection, lib); | 1225 object_store->set_bootstrap_library(ObjectStore::kCollection, lib); |
| 1225 } | 1226 } |
| 1226 ASSERT(!lib.IsNull()); | 1227 ASSERT(!lib.IsNull()); |
| 1227 ASSERT(lib.raw() == Library::CollectionLibrary()); | 1228 ASSERT(lib.raw() == Library::CollectionLibrary()); |
| 1228 | |
| 1229 cls = Class::New<LinkedHashMap>(); | 1229 cls = Class::New<LinkedHashMap>(); |
| 1230 object_store->set_linked_hash_map_class(cls); | 1230 object_store->set_linked_hash_map_class(cls); |
| 1231 cls.set_type_arguments_field_offset(LinkedHashMap::type_arguments_offset()); | 1231 cls.set_type_arguments_field_offset(LinkedHashMap::type_arguments_offset()); |
| 1232 cls.set_num_type_arguments(2); | 1232 cls.set_num_type_arguments(2); |
| 1233 cls.set_num_own_type_arguments(2); | 1233 cls.set_num_own_type_arguments(2); |
| 1234 RegisterPrivateClass(cls, Symbols::_LinkedHashMap(), lib); | 1234 RegisterPrivateClass(cls, Symbols::_LinkedHashMap(), lib); |
| 1235 pending_classes.Add(cls); | 1235 pending_classes.Add(cls); |
| 1236 | 1236 |
| 1237 // Pre-register the developer library so we can place the vm class | 1237 // Pre-register the developer library so we can place the vm class |
| 1238 // UserTag there rather than the core library. | 1238 // UserTag there rather than the core library. |
| (...skipping 9236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10475 } else { \ | 10475 } else { \ |
| 10476 CHECK_FINGERPRINT3(func, class_name, function_name, dest, fp); \ | 10476 CHECK_FINGERPRINT3(func, class_name, function_name, dest, fp); \ |
| 10477 } \ | 10477 } \ |
| 10478 | 10478 |
| 10479 all_libs.Add(&Library::ZoneHandle(Library::CoreLibrary())); | 10479 all_libs.Add(&Library::ZoneHandle(Library::CoreLibrary())); |
| 10480 CORE_LIB_INTRINSIC_LIST(CHECK_FINGERPRINTS); | 10480 CORE_LIB_INTRINSIC_LIST(CHECK_FINGERPRINTS); |
| 10481 CORE_INTEGER_LIB_INTRINSIC_LIST(CHECK_FINGERPRINTS); | 10481 CORE_INTEGER_LIB_INTRINSIC_LIST(CHECK_FINGERPRINTS); |
| 10482 | 10482 |
| 10483 all_libs.Add(&Library::ZoneHandle(Library::MathLibrary())); | 10483 all_libs.Add(&Library::ZoneHandle(Library::MathLibrary())); |
| 10484 all_libs.Add(&Library::ZoneHandle(Library::TypedDataLibrary())); | 10484 all_libs.Add(&Library::ZoneHandle(Library::TypedDataLibrary())); |
| 10485 all_libs.Add(&Library::ZoneHandle(Library::CollectionLibrary())); |
| 10485 OTHER_RECOGNIZED_LIST(CHECK_FINGERPRINTS); | 10486 OTHER_RECOGNIZED_LIST(CHECK_FINGERPRINTS); |
| 10486 INLINE_WHITE_LIST(CHECK_FINGERPRINTS); | 10487 INLINE_WHITE_LIST(CHECK_FINGERPRINTS); |
| 10487 INLINE_BLACK_LIST(CHECK_FINGERPRINTS); | 10488 INLINE_BLACK_LIST(CHECK_FINGERPRINTS); |
| 10488 POLYMORPHIC_TARGET_LIST(CHECK_FINGERPRINTS); | 10489 POLYMORPHIC_TARGET_LIST(CHECK_FINGERPRINTS); |
| 10489 | 10490 |
| 10490 all_libs.Clear(); | 10491 all_libs.Clear(); |
| 10491 all_libs.Add(&Library::ZoneHandle(Library::DeveloperLibrary())); | 10492 all_libs.Add(&Library::ZoneHandle(Library::DeveloperLibrary())); |
| 10492 DEVELOPER_LIB_INTRINSIC_LIST(CHECK_FINGERPRINTS); | 10493 DEVELOPER_LIB_INTRINSIC_LIST(CHECK_FINGERPRINTS); |
| 10493 | 10494 |
| 10494 all_libs.Clear(); | 10495 all_libs.Clear(); |
| (...skipping 9091 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 19586 return static_cast<uword>( | 19587 return static_cast<uword>( |
| 19587 Integer::Cast(hash_code).AsTruncatedUint32Value()); | 19588 Integer::Cast(hash_code).AsTruncatedUint32Value()); |
| 19588 } else { | 19589 } else { |
| 19589 return 0; | 19590 return 0; |
| 19590 } | 19591 } |
| 19591 } | 19592 } |
| 19592 }; | 19593 }; |
| 19593 typedef EnumIndexHashMap<DefaultHashTraits> EnumIndexDefaultMap; | 19594 typedef EnumIndexHashMap<DefaultHashTraits> EnumIndexDefaultMap; |
| 19594 | 19595 |
| 19595 | 19596 |
| 19596 intptr_t LinkedHashMap::Length() const { | 19597 RawLinkedHashMap* LinkedHashMap::NewDefault(Heap::Space space) { |
| 19597 EnumIndexDefaultMap map(data()); | 19598 // Keep this in sync with Dart implementation (lib/compact_hash.dart). |
| 19598 intptr_t result = map.NumOccupied(); | 19599 static const intptr_t kInitialIndexBits = 3; |
| 19599 ASSERT(map.Release().raw() == data()); | 19600 static const intptr_t kInitialIndexSize = 1 << (kInitialIndexBits + 1); |
| 19600 return result; | 19601 const Array& data = Array::Handle(Array::New(kInitialIndexSize, space)); |
| 19602 const TypedData& index = TypedData::Handle(TypedData::New( |
| 19603 kTypedDataUint32ArrayCid, kInitialIndexSize, space)); |
| 19604 static const intptr_t kInitialHashMask = |
| 19605 #if defined(ARCH_IS_64_BIT) |
| 19606 (1 << (32 - kInitialIndexBits)) - 1; |
| 19607 #else |
| 19608 (1 << (30 - kInitialIndexBits)) - 1; |
| 19609 #endif |
| 19610 return LinkedHashMap::New(data, index, kInitialHashMask, 0, 0, space); |
| 19601 } | 19611 } |
| 19602 | 19612 |
| 19603 | 19613 |
| 19604 void LinkedHashMap::InsertOrUpdate(const Object& key, | 19614 RawLinkedHashMap* LinkedHashMap::New(const Array& data, |
| 19605 const Object& value) const { | 19615 const TypedData& index, |
| 19606 ASSERT(!IsNull()); | 19616 intptr_t hash_mask, |
| 19607 EnumIndexDefaultMap map(data()); | 19617 intptr_t used_data, |
| 19608 if (!map.UpdateOrInsert(key, value)) { | 19618 intptr_t deleted_keys, |
| 19609 SetModified(); | 19619 Heap::Space space) { |
| 19610 } | 19620 ASSERT(Isolate::Current()->object_store()->linked_hash_map_class() |
| 19611 StorePointer(&raw_ptr()->data_, map.Release().raw()); | 19621 != Class::null()); |
| 19612 } | 19622 LinkedHashMap& result = LinkedHashMap::Handle( |
| 19613 | 19623 LinkedHashMap::NewUninitialized(space)); |
| 19614 | 19624 result.SetData(data); |
| 19615 RawObject* LinkedHashMap::LookUp(const Object& key) const { | 19625 result.SetIndex(index); |
| 19616 ASSERT(!IsNull()); | 19626 result.SetHashMask(hash_mask); |
| 19617 EnumIndexDefaultMap map(data()); | 19627 result.SetUsedData(used_data); |
| 19618 { | 19628 result.SetDeletedKeys(deleted_keys); |
| 19619 NoSafepointScope no_safepoint; | |
| 19620 RawObject* result = map.GetOrNull(key); | |
| 19621 ASSERT(map.Release().raw() == data()); | |
| 19622 return result; | |
| 19623 } | |
| 19624 } | |
| 19625 | |
| 19626 | |
| 19627 bool LinkedHashMap::Contains(const Object& key) const { | |
| 19628 ASSERT(!IsNull()); | |
| 19629 EnumIndexDefaultMap map(data()); | |
| 19630 bool result = map.ContainsKey(key); | |
| 19631 ASSERT(map.Release().raw() == data()); | |
| 19632 return result; | |
| 19633 } | |
| 19634 | |
| 19635 | |
| 19636 RawObject* LinkedHashMap::Remove(const Object& key) const { | |
| 19637 ASSERT(!IsNull()); | |
| 19638 EnumIndexDefaultMap map(data()); | |
| 19639 // TODO(koda): Make 'Remove' also return the old value. | |
| 19640 const PassiveObject& result = PassiveObject::Handle(map.GetOrNull(key)); | |
| 19641 if (map.Remove(key)) { | |
| 19642 SetModified(); | |
| 19643 } | |
| 19644 StorePointer(&raw_ptr()->data_, map.Release().raw()); | |
| 19645 return result.raw(); | 19629 return result.raw(); |
| 19646 } | 19630 } |
| 19647 | 19631 |
| 19648 | 19632 |
| 19649 void LinkedHashMap::Clear() const { | 19633 RawLinkedHashMap* LinkedHashMap::NewUninitialized(Heap::Space space) { |
| 19650 ASSERT(!IsNull()); | |
| 19651 if (Length() != 0) { | |
| 19652 EnumIndexDefaultMap map(data()); | |
| 19653 map.Initialize(); | |
| 19654 SetModified(); | |
| 19655 StorePointer(&raw_ptr()->data_, map.Release().raw()); | |
| 19656 } | |
| 19657 } | |
| 19658 | |
| 19659 | |
| 19660 RawArray* LinkedHashMap::ToArray() const { | |
| 19661 EnumIndexDefaultMap map(data()); | |
| 19662 const Array& result = Array::Handle(HashTables::ToArray(map, true)); | |
| 19663 ASSERT(map.Release().raw() == data()); | |
| 19664 return result.raw(); | |
| 19665 } | |
| 19666 | |
| 19667 | |
| 19668 void LinkedHashMap::SetModified() const { | |
| 19669 StorePointer(&raw_ptr()->cme_mark_, Instance::null()); | |
| 19670 } | |
| 19671 | |
| 19672 | |
| 19673 RawInstance* LinkedHashMap::GetModificationMark(bool create) const { | |
| 19674 if (create && raw_ptr()->cme_mark_ == Instance::null()) { | |
| 19675 Isolate* isolate = Isolate::Current(); | |
| 19676 const Class& object_class = | |
| 19677 Class::Handle(isolate, isolate->object_store()->object_class()); | |
| 19678 const Instance& current = | |
| 19679 Instance::Handle(isolate, Instance::New(object_class)); | |
| 19680 StorePointer(&raw_ptr()->cme_mark_, current.raw()); | |
| 19681 } | |
| 19682 return raw_ptr()->cme_mark_; | |
| 19683 } | |
| 19684 | |
| 19685 | |
| 19686 RawLinkedHashMap* LinkedHashMap::New(Heap::Space space) { | |
| 19687 ASSERT(Isolate::Current()->object_store()->linked_hash_map_class() | 19634 ASSERT(Isolate::Current()->object_store()->linked_hash_map_class() |
| 19688 != Class::null()); | 19635 != Class::null()); |
| 19689 static const intptr_t kInitialCapacity = 4; | |
| 19690 const Array& data = | |
| 19691 Array::Handle(HashTables::New<EnumIndexDefaultMap>(kInitialCapacity, | |
| 19692 space)); | |
| 19693 LinkedHashMap& result = LinkedHashMap::Handle(); | 19636 LinkedHashMap& result = LinkedHashMap::Handle(); |
| 19694 { | 19637 { |
| 19695 RawObject* raw = Object::Allocate(LinkedHashMap::kClassId, | 19638 RawObject* raw = Object::Allocate(LinkedHashMap::kClassId, |
| 19696 LinkedHashMap::InstanceSize(), | 19639 LinkedHashMap::InstanceSize(), |
| 19697 space); | 19640 space); |
| 19698 NoSafepointScope no_safepoint; | 19641 NoSafepointScope no_safepoint; |
| 19699 result ^= raw; | 19642 result ^= raw; |
| 19700 result.SetData(data); | |
| 19701 result.SetModified(); | |
| 19702 } | 19643 } |
| 19703 return result.raw(); | 19644 return result.raw(); |
| 19704 } | 19645 } |
| 19705 | 19646 |
| 19706 | 19647 |
| 19707 const char* LinkedHashMap::ToCString() const { | 19648 const char* LinkedHashMap::ToCString() const { |
| 19708 // TODO(koda): Print key/value pairs. | 19649 // TODO(koda): Print key/value pairs. |
| 19709 return "_LinkedHashMap"; | 19650 return "_LinkedHashMap"; |
| 19710 } | 19651 } |
| 19711 | 19652 |
| (...skipping 1086 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 20798 return tag_label.ToCString(); | 20739 return tag_label.ToCString(); |
| 20799 } | 20740 } |
| 20800 | 20741 |
| 20801 | 20742 |
| 20802 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { | 20743 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { |
| 20803 Instance::PrintJSONImpl(stream, ref); | 20744 Instance::PrintJSONImpl(stream, ref); |
| 20804 } | 20745 } |
| 20805 | 20746 |
| 20806 | 20747 |
| 20807 } // namespace dart | 20748 } // namespace dart |
| OLD | NEW |