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 "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 936 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 947 Class& cls = Class::Handle(isolate); | 947 Class& cls = Class::Handle(isolate); |
| 948 Type& type = Type::Handle(isolate); | 948 Type& type = Type::Handle(isolate); |
| 949 Array& array = Array::Handle(isolate); | 949 Array& array = Array::Handle(isolate); |
| 950 Library& lib = Library::Handle(isolate); | 950 Library& lib = Library::Handle(isolate); |
| 951 | 951 |
| 952 // All RawArray fields will be initialized to an empty array, therefore | 952 // All RawArray fields will be initialized to an empty array, therefore |
| 953 // initialize array class first. | 953 // initialize array class first. |
| 954 cls = Class::New<Array>(); | 954 cls = Class::New<Array>(); |
| 955 object_store->set_array_class(cls); | 955 object_store->set_array_class(cls); |
| 956 | 956 |
| 957 // Array and ImmutableArray are the only VM classes that are parameterized. | 957 // VM classes that are parameterized (Array, ImmutableArray, |
| 958 // Since they are pre-finalized, CalculateFieldOffsets() is not called, so we | 958 // GrowableObjectArray, and LinkedHashMap) are also pre-finalized, |
| 959 // need to set the offset of their type_arguments_ field, which is explicitly | 959 // so CalculateFieldOffsets() is not called, so we need to set the |
| 960 // declared in RawArray. | 960 // offset of their type_arguments_ field, which is explicitly |
| 961 // declared in their respective Raw* classes. | |
| 961 cls.set_type_arguments_field_offset(Array::type_arguments_offset()); | 962 cls.set_type_arguments_field_offset(Array::type_arguments_offset()); |
| 962 cls.set_num_type_arguments(1); | 963 cls.set_num_type_arguments(1); |
| 963 | 964 |
| 964 // Set up the growable object array class (Has to be done after the array | 965 // Set up the growable object array class (Has to be done after the array |
| 965 // class is setup as one of its field is an array object). | 966 // class is setup as one of its field is an array object). |
| 966 cls = Class::New<GrowableObjectArray>(); | 967 cls = Class::New<GrowableObjectArray>(); |
| 967 object_store->set_growable_object_array_class(cls); | 968 object_store->set_growable_object_array_class(cls); |
| 968 cls.set_type_arguments_field_offset( | 969 cls.set_type_arguments_field_offset( |
| 969 GrowableObjectArray::type_arguments_offset()); | 970 GrowableObjectArray::type_arguments_offset()); |
| 970 cls.set_num_type_arguments(1); | 971 cls.set_num_type_arguments(1); |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1207 // LinkedHashMap there rather than the core library. | 1208 // LinkedHashMap there rather than the core library. |
| 1208 lib = Library::LookupLibrary(Symbols::DartCollection()); | 1209 lib = Library::LookupLibrary(Symbols::DartCollection()); |
| 1209 if (lib.IsNull()) { | 1210 if (lib.IsNull()) { |
| 1210 lib = Library::NewLibraryHelper(Symbols::DartCollection(), true); | 1211 lib = Library::NewLibraryHelper(Symbols::DartCollection(), true); |
| 1211 lib.SetLoadRequested(); | 1212 lib.SetLoadRequested(); |
| 1212 lib.Register(); | 1213 lib.Register(); |
| 1213 object_store->set_bootstrap_library(ObjectStore::kCollection, lib); | 1214 object_store->set_bootstrap_library(ObjectStore::kCollection, lib); |
| 1214 } | 1215 } |
| 1215 ASSERT(!lib.IsNull()); | 1216 ASSERT(!lib.IsNull()); |
| 1216 ASSERT(lib.raw() == Library::CollectionLibrary()); | 1217 ASSERT(lib.raw() == Library::CollectionLibrary()); |
| 1217 | |
| 1218 cls = Class::New<LinkedHashMap>(); | 1218 cls = Class::New<LinkedHashMap>(); |
| 1219 object_store->set_linked_hash_map_class(cls); | 1219 object_store->set_linked_hash_map_class(cls); |
| 1220 cls.set_type_arguments_field_offset(LinkedHashMap::type_arguments_offset()); | 1220 cls.set_type_arguments_field_offset(LinkedHashMap::type_arguments_offset()); |
| 1221 cls.set_num_type_arguments(2); | 1221 cls.set_num_type_arguments(2); |
| 1222 cls.set_num_own_type_arguments(2); | 1222 cls.set_num_own_type_arguments(2); |
| 1223 RegisterPrivateClass(cls, Symbols::_LinkedHashMap(), lib); | 1223 RegisterPrivateClass(cls, Symbols::_LinkedHashMap(), lib); |
| 1224 pending_classes.Add(cls); | 1224 pending_classes.Add(cls); |
| 1225 | 1225 |
| 1226 // Pre-register the developer library so we can place the vm class | 1226 // Pre-register the developer library so we can place the vm class |
| 1227 // UserTag there rather than the core library. | 1227 // UserTag there rather than the core library. |
| (...skipping 9234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 10462 } else { \ | 10462 } else { \ |
| 10463 CHECK_FINGERPRINT3(func, class_name, function_name, dest, fp); \ | 10463 CHECK_FINGERPRINT3(func, class_name, function_name, dest, fp); \ |
| 10464 } \ | 10464 } \ |
| 10465 | 10465 |
| 10466 all_libs.Add(&Library::ZoneHandle(Library::CoreLibrary())); | 10466 all_libs.Add(&Library::ZoneHandle(Library::CoreLibrary())); |
| 10467 CORE_LIB_INTRINSIC_LIST(CHECK_FINGERPRINTS); | 10467 CORE_LIB_INTRINSIC_LIST(CHECK_FINGERPRINTS); |
| 10468 CORE_INTEGER_LIB_INTRINSIC_LIST(CHECK_FINGERPRINTS); | 10468 CORE_INTEGER_LIB_INTRINSIC_LIST(CHECK_FINGERPRINTS); |
| 10469 | 10469 |
| 10470 all_libs.Add(&Library::ZoneHandle(Library::MathLibrary())); | 10470 all_libs.Add(&Library::ZoneHandle(Library::MathLibrary())); |
| 10471 all_libs.Add(&Library::ZoneHandle(Library::TypedDataLibrary())); | 10471 all_libs.Add(&Library::ZoneHandle(Library::TypedDataLibrary())); |
| 10472 all_libs.Add(&Library::ZoneHandle(Library::CollectionLibrary())); | |
| 10472 OTHER_RECOGNIZED_LIST(CHECK_FINGERPRINTS); | 10473 OTHER_RECOGNIZED_LIST(CHECK_FINGERPRINTS); |
| 10473 INLINE_WHITE_LIST(CHECK_FINGERPRINTS); | 10474 INLINE_WHITE_LIST(CHECK_FINGERPRINTS); |
| 10474 INLINE_BLACK_LIST(CHECK_FINGERPRINTS); | 10475 INLINE_BLACK_LIST(CHECK_FINGERPRINTS); |
| 10475 POLYMORPHIC_TARGET_LIST(CHECK_FINGERPRINTS); | 10476 POLYMORPHIC_TARGET_LIST(CHECK_FINGERPRINTS); |
| 10476 | 10477 |
| 10477 all_libs.Clear(); | 10478 all_libs.Clear(); |
| 10478 all_libs.Add(&Library::ZoneHandle(Library::DeveloperLibrary())); | 10479 all_libs.Add(&Library::ZoneHandle(Library::DeveloperLibrary())); |
| 10479 DEVELOPER_LIB_INTRINSIC_LIST(CHECK_FINGERPRINTS); | 10480 DEVELOPER_LIB_INTRINSIC_LIST(CHECK_FINGERPRINTS); |
| 10480 | 10481 |
| 10481 all_libs.Clear(); | 10482 all_libs.Clear(); |
| (...skipping 9036 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 19518 return static_cast<uword>( | 19519 return static_cast<uword>( |
| 19519 Integer::Cast(hash_code).AsTruncatedUint32Value()); | 19520 Integer::Cast(hash_code).AsTruncatedUint32Value()); |
| 19520 } else { | 19521 } else { |
| 19521 return 0; | 19522 return 0; |
| 19522 } | 19523 } |
| 19523 } | 19524 } |
| 19524 }; | 19525 }; |
| 19525 typedef EnumIndexHashMap<DefaultHashTraits> EnumIndexDefaultMap; | 19526 typedef EnumIndexHashMap<DefaultHashTraits> EnumIndexDefaultMap; |
| 19526 | 19527 |
| 19527 | 19528 |
| 19528 intptr_t LinkedHashMap::Length() const { | 19529 RawLinkedHashMap* LinkedHashMap::NewDefault(Heap::Space space) { |
| 19529 EnumIndexDefaultMap map(data()); | 19530 // Keep this in sync with Dart implementation (lib/compact_hash.dart). |
|
siva
2015/05/22 16:27:11
I think you need to add a verification step for th
koda
2015/05/26 12:22:04
Done, as a unit test (which can be extended as mor
| |
| 19530 intptr_t result = map.NumOccupied(); | 19531 static const intptr_t kInitialIndexBits = 3; |
| 19531 ASSERT(map.Release().raw() == data()); | 19532 static const intptr_t kInitialIndexSize = 1 << (kInitialIndexBits + 1); |
| 19532 return result; | 19533 const Array& data = Array::Handle(Array::New(kInitialIndexSize, space)); |
| 19534 const TypedData& index = TypedData::Handle(TypedData::New( | |
| 19535 kTypedDataUint32ArrayCid, kInitialIndexSize, space)); | |
| 19536 static const intptr_t kInitialHashMask = | |
| 19537 #if defined(ARCH_IS_64_BIT) | |
| 19538 (1 << (32 - kInitialIndexBits)) - 1; | |
| 19539 #else | |
| 19540 (1 << (30 - kInitialIndexBits)) - 1; | |
| 19541 #endif | |
| 19542 return LinkedHashMap::New(data, index, kInitialHashMask, 0, 0, space); | |
| 19533 } | 19543 } |
| 19534 | 19544 |
| 19535 | 19545 |
| 19536 void LinkedHashMap::InsertOrUpdate(const Object& key, | 19546 RawLinkedHashMap* LinkedHashMap::New(const Array& data, |
| 19537 const Object& value) const { | 19547 const TypedData& index, |
| 19538 ASSERT(!IsNull()); | 19548 intptr_t hash_mask, |
| 19539 EnumIndexDefaultMap map(data()); | 19549 intptr_t used_data, |
| 19540 if (!map.UpdateOrInsert(key, value)) { | 19550 intptr_t deleted_keys, |
| 19541 SetModified(); | 19551 Heap::Space space) { |
| 19542 } | 19552 ASSERT(Isolate::Current()->object_store()->linked_hash_map_class() |
| 19543 StorePointer(&raw_ptr()->data_, map.Release().raw()); | 19553 != Class::null()); |
| 19544 } | 19554 LinkedHashMap& result = LinkedHashMap::Handle( |
| 19545 | 19555 LinkedHashMap::NewUninitialized(space)); |
| 19546 | 19556 result.SetData(data); |
| 19547 RawObject* LinkedHashMap::LookUp(const Object& key) const { | 19557 result.SetIndex(index); |
| 19548 ASSERT(!IsNull()); | 19558 result.SetHashMask(hash_mask); |
| 19549 EnumIndexDefaultMap map(data()); | 19559 result.SetUsedData(used_data); |
| 19550 { | 19560 result.SetDeletedKeys(deleted_keys); |
| 19551 NoSafepointScope no_safepoint; | |
| 19552 RawObject* result = map.GetOrNull(key); | |
| 19553 ASSERT(map.Release().raw() == data()); | |
| 19554 return result; | |
| 19555 } | |
| 19556 } | |
| 19557 | |
| 19558 | |
| 19559 bool LinkedHashMap::Contains(const Object& key) const { | |
| 19560 ASSERT(!IsNull()); | |
| 19561 EnumIndexDefaultMap map(data()); | |
| 19562 bool result = map.ContainsKey(key); | |
| 19563 ASSERT(map.Release().raw() == data()); | |
| 19564 return result; | |
| 19565 } | |
| 19566 | |
| 19567 | |
| 19568 RawObject* LinkedHashMap::Remove(const Object& key) const { | |
| 19569 ASSERT(!IsNull()); | |
| 19570 EnumIndexDefaultMap map(data()); | |
| 19571 // TODO(koda): Make 'Remove' also return the old value. | |
| 19572 const PassiveObject& result = PassiveObject::Handle(map.GetOrNull(key)); | |
| 19573 if (map.Remove(key)) { | |
| 19574 SetModified(); | |
| 19575 } | |
| 19576 StorePointer(&raw_ptr()->data_, map.Release().raw()); | |
| 19577 return result.raw(); | 19561 return result.raw(); |
| 19578 } | 19562 } |
| 19579 | 19563 |
| 19580 | 19564 |
| 19581 void LinkedHashMap::Clear() const { | 19565 RawLinkedHashMap* LinkedHashMap::NewUninitialized(Heap::Space space) { |
| 19582 ASSERT(!IsNull()); | |
| 19583 if (Length() != 0) { | |
| 19584 EnumIndexDefaultMap map(data()); | |
| 19585 map.Initialize(); | |
| 19586 SetModified(); | |
| 19587 StorePointer(&raw_ptr()->data_, map.Release().raw()); | |
| 19588 } | |
| 19589 } | |
| 19590 | |
| 19591 | |
| 19592 RawArray* LinkedHashMap::ToArray() const { | |
| 19593 EnumIndexDefaultMap map(data()); | |
| 19594 const Array& result = Array::Handle(HashTables::ToArray(map, true)); | |
| 19595 ASSERT(map.Release().raw() == data()); | |
| 19596 return result.raw(); | |
| 19597 } | |
| 19598 | |
| 19599 | |
| 19600 void LinkedHashMap::SetModified() const { | |
| 19601 StorePointer(&raw_ptr()->cme_mark_, Instance::null()); | |
| 19602 } | |
| 19603 | |
| 19604 | |
| 19605 RawInstance* LinkedHashMap::GetModificationMark(bool create) const { | |
| 19606 if (create && raw_ptr()->cme_mark_ == Instance::null()) { | |
| 19607 Isolate* isolate = Isolate::Current(); | |
| 19608 const Class& object_class = | |
| 19609 Class::Handle(isolate, isolate->object_store()->object_class()); | |
| 19610 const Instance& current = | |
| 19611 Instance::Handle(isolate, Instance::New(object_class)); | |
| 19612 StorePointer(&raw_ptr()->cme_mark_, current.raw()); | |
| 19613 } | |
| 19614 return raw_ptr()->cme_mark_; | |
| 19615 } | |
| 19616 | |
| 19617 | |
| 19618 RawLinkedHashMap* LinkedHashMap::New(Heap::Space space) { | |
| 19619 ASSERT(Isolate::Current()->object_store()->linked_hash_map_class() | 19566 ASSERT(Isolate::Current()->object_store()->linked_hash_map_class() |
| 19620 != Class::null()); | 19567 != Class::null()); |
| 19621 static const intptr_t kInitialCapacity = 4; | |
| 19622 const Array& data = | |
| 19623 Array::Handle(HashTables::New<EnumIndexDefaultMap>(kInitialCapacity, | |
| 19624 space)); | |
| 19625 LinkedHashMap& result = LinkedHashMap::Handle(); | 19568 LinkedHashMap& result = LinkedHashMap::Handle(); |
| 19626 { | 19569 { |
| 19627 RawObject* raw = Object::Allocate(LinkedHashMap::kClassId, | 19570 RawObject* raw = Object::Allocate(LinkedHashMap::kClassId, |
| 19628 LinkedHashMap::InstanceSize(), | 19571 LinkedHashMap::InstanceSize(), |
| 19629 space); | 19572 space); |
| 19630 NoSafepointScope no_safepoint; | 19573 NoSafepointScope no_safepoint; |
| 19631 result ^= raw; | 19574 result ^= raw; |
| 19632 result.SetData(data); | |
| 19633 result.SetModified(); | |
| 19634 } | 19575 } |
| 19635 return result.raw(); | 19576 return result.raw(); |
| 19636 } | 19577 } |
| 19637 | 19578 |
| 19638 | 19579 |
| 19639 const char* LinkedHashMap::ToCString() const { | 19580 const char* LinkedHashMap::ToCString() const { |
| 19640 // TODO(koda): Print key/value pairs. | 19581 // TODO(koda): Print key/value pairs. |
| 19641 return "_LinkedHashMap"; | 19582 return "_LinkedHashMap"; |
| 19642 } | 19583 } |
| 19643 | 19584 |
| (...skipping 1086 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 20730 return tag_label.ToCString(); | 20671 return tag_label.ToCString(); |
| 20731 } | 20672 } |
| 20732 | 20673 |
| 20733 | 20674 |
| 20734 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { | 20675 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { |
| 20735 Instance::PrintJSONImpl(stream, ref); | 20676 Instance::PrintJSONImpl(stream, ref); |
| 20736 } | 20677 } |
| 20737 | 20678 |
| 20738 | 20679 |
| 20739 } // namespace dart | 20680 } // namespace dart |
| OLD | NEW |