Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(267)

Side by Side Diff: runtime/vm/object.h

Issue 1151523002: VM-internalize the default Map implementation. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Ready for review. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #ifndef VM_OBJECT_H_ 5 #ifndef VM_OBJECT_H_
6 #define VM_OBJECT_H_ 6 #define VM_OBJECT_H_
7 7
8 #include "include/dart_api.h" 8 #include "include/dart_api.h"
9 #include "platform/assert.h" 9 #include "platform/assert.h"
10 #include "platform/utils.h" 10 #include "platform/utils.h"
(...skipping 2279 matching lines...) Expand 10 before | Expand all | Expand 10 after
2290 FOR_EACH_FUNCTION_KIND_BIT(DEFINE_ACCESSORS) 2290 FOR_EACH_FUNCTION_KIND_BIT(DEFINE_ACCESSORS)
2291 #undef DEFINE_ACCESSORS 2291 #undef DEFINE_ACCESSORS
2292 2292
2293 private: 2293 private:
2294 void set_ic_data_array(const Array& value) const; 2294 void set_ic_data_array(const Array& value) const;
2295 2295
2296 enum KindTagBits { 2296 enum KindTagBits {
2297 kKindTagPos = 0, 2297 kKindTagPos = 0,
2298 kKindTagSize = 4, 2298 kKindTagSize = 4,
2299 kRecognizedTagPos = kKindTagPos + kKindTagSize, 2299 kRecognizedTagPos = kKindTagPos + kKindTagSize,
2300 kRecognizedTagSize = 8, 2300 kRecognizedTagSize = 9,
2301 kModifierPos = kRecognizedTagPos + kRecognizedTagSize, 2301 kModifierPos = kRecognizedTagPos + kRecognizedTagSize,
2302 kModifierSize = 2, 2302 kModifierSize = 2,
2303 kLastModifierBitPos = kModifierPos + (kModifierSize - 1), 2303 kLastModifierBitPos = kModifierPos + (kModifierSize - 1),
2304 // Single bit sized fields start here. 2304 // Single bit sized fields start here.
2305 #define DECLARE_BIT(name, _) k##name##Bit, 2305 #define DECLARE_BIT(name, _) k##name##Bit,
2306 FOR_EACH_FUNCTION_KIND_BIT(DECLARE_BIT) 2306 FOR_EACH_FUNCTION_KIND_BIT(DECLARE_BIT)
2307 #undef DECLARE_BIT 2307 #undef DECLARE_BIT
2308 kNumTagBits 2308 kNumTagBits
2309 }; 2309 };
2310 2310
(...skipping 4362 matching lines...) Expand 10 before | Expand all | Expand 10 after
6673 } 6673 }
6674 6674
6675 static const int kDefaultInitialCapacity = 4; 6675 static const int kDefaultInitialCapacity = 4;
6676 6676
6677 FINAL_HEAP_OBJECT_IMPLEMENTATION(GrowableObjectArray, Instance); 6677 FINAL_HEAP_OBJECT_IMPLEMENTATION(GrowableObjectArray, Instance);
6678 friend class Array; 6678 friend class Array;
6679 friend class Class; 6679 friend class Class;
6680 }; 6680 };
6681 6681
6682 6682
6683 // Corresponds to
6684 // - "new Map()",
6685 // - non-const map literals, and
6686 // - the default constructor of LinkedHashMap in dart:collection.
6687 class LinkedHashMap : public Instance {
6688 public:
6689 intptr_t Length() const;
6690 RawObject* LookUp(const Object& key) const;
6691 void InsertOrUpdate(const Object& key, const Object& value) const;
6692 bool Contains(const Object& key) const;
6693 RawObject* Remove(const Object& key) const;
6694 void Clear() const;
6695 // List of key, value pairs in iteration (i.e., key insertion) order.
6696 RawArray* ToArray() const;
6697
6698 static intptr_t InstanceSize() {
6699 return RoundedAllocationSize(sizeof(RawLinkedHashMap));
6700 }
6701
6702 static RawLinkedHashMap* New(Heap::Space space = Heap::kNew);
6703
6704 virtual RawTypeArguments* GetTypeArguments() const {
6705 return raw_ptr()->type_arguments_;
6706 }
6707 virtual void SetTypeArguments(const TypeArguments& value) const {
6708 ASSERT(value.IsNull() || ((value.Length() >= 2) && value.IsInstantiated()));
6709 StorePointer(&raw_ptr()->type_arguments_, value.raw());
6710 }
6711 static intptr_t type_arguments_offset() {
6712 return OFFSET_OF(RawLinkedHashMap, type_arguments_);
6713 }
6714
6715 // Called whenever the set of keys changes.
6716 void SetModified() const;
6717 RawInstance* GetModificationMark(bool create) const;
6718
6719 private:
6720 RawArray* data() const { return raw_ptr()->data_; }
6721 void SetData(const Array& value) const {
6722 StorePointer(&raw_ptr()->data_, value.raw());
6723 }
6724
6725 FINAL_HEAP_OBJECT_IMPLEMENTATION(LinkedHashMap, Instance);
6726 friend class Class;
6727 };
6728
6729
6730 class Float32x4 : public Instance { 6683 class Float32x4 : public Instance {
6731 public: 6684 public:
6732 static RawFloat32x4* New(float value0, float value1, float value2, 6685 static RawFloat32x4* New(float value0, float value1, float value2,
6733 float value3, Heap::Space space = Heap::kNew); 6686 float value3, Heap::Space space = Heap::kNew);
6734 static RawFloat32x4* New(simd128_value_t value, 6687 static RawFloat32x4* New(simd128_value_t value,
6735 Heap::Space space = Heap::kNew); 6688 Heap::Space space = Heap::kNew);
6736 6689
6737 float x() const; 6690 float x() const;
6738 float y() const; 6691 float y() const;
6739 float z() const; 6692 float z() const;
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after
7190 return kWordSize * kDataOffset; 7143 return kWordSize * kDataOffset;
7191 } 7144 }
7192 7145
7193 private: 7146 private:
7194 enum { 7147 enum {
7195 kDataOffset = 1, 7148 kDataOffset = 1,
7196 }; 7149 };
7197 }; 7150 };
7198 7151
7199 7152
7153 // Corresponds to
7154 // - "new Map()",
7155 // - non-const map literals, and
7156 // - the default constructor of LinkedHashMap in dart:collection.
7157 class LinkedHashMap : public Instance {
7158 public:
7159 static intptr_t InstanceSize() {
7160 return RoundedAllocationSize(sizeof(RawLinkedHashMap));
7161 }
7162
7163 // Allocates a map with some default capacity, just like "new Map()".
7164 static RawLinkedHashMap* NewDefault(Heap::Space space = Heap::kNew);
7165 static RawLinkedHashMap* New(const Array& data,
7166 const TypedData& index,
7167 intptr_t hash_mask,
7168 intptr_t used_data,
7169 intptr_t deleted_keys,
7170 Heap::Space space = Heap::kNew);
7171
7172 virtual RawTypeArguments* GetTypeArguments() const {
7173 return raw_ptr()->type_arguments_;
7174 }
7175 virtual void SetTypeArguments(const TypeArguments& value) const {
7176 ASSERT(value.IsNull() || ((value.Length() >= 2) && value.IsInstantiated()));
7177 StorePointer(&raw_ptr()->type_arguments_, value.raw());
7178 }
7179 static intptr_t type_arguments_offset() {
7180 return OFFSET_OF(RawLinkedHashMap, type_arguments_);
7181 }
7182
7183 RawTypedData* index() const {
7184 return raw_ptr()->index_;
7185 }
7186 void SetIndex(const TypedData& value) const {
7187 StorePointer(&raw_ptr()->index_, value.raw());
7188 }
7189 static intptr_t index_offset() {
7190 return OFFSET_OF(RawLinkedHashMap, index_);
7191 }
7192
7193 RawArray* data() const {
7194 return raw_ptr()->data_;
7195 }
7196 void SetData(const Array& value) const {
7197 StorePointer(&raw_ptr()->data_, value.raw());
7198 }
7199 static intptr_t data_offset() {
7200 return OFFSET_OF(RawLinkedHashMap, data_);
7201 }
7202
7203 RawSmi* hash_mask() const {
7204 return raw_ptr()->hash_mask_;
7205 }
7206 void SetHashMask(intptr_t value) const {
7207 StoreSmi(&raw_ptr()->hash_mask_, Smi::New(value));
7208 }
7209 static intptr_t hash_mask_offset() {
7210 return OFFSET_OF(RawLinkedHashMap, hash_mask_);
7211 }
7212
7213 RawSmi* used_data() const {
7214 return raw_ptr()->used_data_;
7215 }
7216 void SetUsedData(intptr_t value) const {
7217 StoreSmi(&raw_ptr()->used_data_, Smi::New(value));
7218 }
7219 static intptr_t used_data_offset() {
7220 return OFFSET_OF(RawLinkedHashMap, used_data_);
7221 }
7222
7223 RawSmi* deleted_keys() const {
7224 return raw_ptr()->deleted_keys_;
7225 }
7226 void SetDeletedKeys(intptr_t value) const {
7227 StoreSmi(&raw_ptr()->deleted_keys_, Smi::New(value));
7228 }
7229 static intptr_t deleted_keys_offset() {
7230 return OFFSET_OF(RawLinkedHashMap, deleted_keys_);
7231 }
7232
7233 private:
7234 FINAL_HEAP_OBJECT_IMPLEMENTATION(LinkedHashMap, Instance);
7235
7236 // Allocate a map, but leave all fields set to null.
7237 // Used during deserialization (since map might contain itself as key/value).
7238 static RawLinkedHashMap* NewUninitialized(Heap::Space space = Heap::kNew);
7239
7240 friend class Class;
7241 };
7242
7243
7200 class Closure : public AllStatic { 7244 class Closure : public AllStatic {
7201 public: 7245 public:
7202 static RawFunction* function(const Instance& closure) { 7246 static RawFunction* function(const Instance& closure) {
7203 return *FunctionAddr(closure); 7247 return *FunctionAddr(closure);
7204 } 7248 }
7205 static intptr_t function_offset() { 7249 static intptr_t function_offset() {
7206 return static_cast<intptr_t>(kFunctionOffset * kWordSize); 7250 return static_cast<intptr_t>(kFunctionOffset * kWordSize);
7207 } 7251 }
7208 7252
7209 static RawContext* context(const Instance& closure) { 7253 static RawContext* context(const Instance& closure) {
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after
7745 7789
7746 7790
7747 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, 7791 RawObject* MegamorphicCache::GetTargetFunction(const Array& array,
7748 intptr_t index) { 7792 intptr_t index) {
7749 return array.At((index * kEntryLength) + kTargetFunctionIndex); 7793 return array.At((index * kEntryLength) + kTargetFunctionIndex);
7750 } 7794 }
7751 7795
7752 } // namespace dart 7796 } // namespace dart
7753 7797
7754 #endif // VM_OBJECT_H_ 7798 #endif // VM_OBJECT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698