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 #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 4914 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4925 } | 4925 } |
4926 | 4926 |
4927 RawObject* At(intptr_t index) const { | 4927 RawObject* At(intptr_t index) const { |
4928 return *ObjectAddr(index); | 4928 return *ObjectAddr(index); |
4929 } | 4929 } |
4930 void SetAt(intptr_t index, const Object& value) const { | 4930 void SetAt(intptr_t index, const Object& value) const { |
4931 // TODO(iposva): Add storing NoGCScope. | 4931 // TODO(iposva): Add storing NoGCScope. |
4932 StorePointer(ObjectAddr(index), value.raw()); | 4932 StorePointer(ObjectAddr(index), value.raw()); |
4933 } | 4933 } |
4934 | 4934 |
| 4935 bool IsImmutable() const { |
| 4936 return raw()->GetClassId() == kImmutableArrayCid; |
| 4937 } |
| 4938 |
4935 virtual RawAbstractTypeArguments* GetTypeArguments() const { | 4939 virtual RawAbstractTypeArguments* GetTypeArguments() const { |
4936 return raw_ptr()->type_arguments_; | 4940 return raw_ptr()->type_arguments_; |
4937 } | 4941 } |
4938 virtual void SetTypeArguments(const AbstractTypeArguments& value) const { | 4942 virtual void SetTypeArguments(const AbstractTypeArguments& value) const { |
4939 // An Array is raw or takes one type argument. However, its type argument | 4943 // An Array is raw or takes one type argument. However, its type argument |
4940 // vector may be longer than 1 due to a type optimization reusing the type | 4944 // vector may be longer than 1 due to a type optimization reusing the type |
4941 // argument vector of the instantiator. | 4945 // argument vector of the instantiator. |
4942 ASSERT(value.IsNull() || ((value.Length() >= 1) && value.IsInstantiated())); | 4946 ASSERT(value.IsNull() || ((value.Length() >= 1) && value.IsInstantiated())); |
4943 StorePointer(&raw_ptr()->type_arguments_, value.raw()); | 4947 StorePointer(&raw_ptr()->type_arguments_, value.raw()); |
4944 } | 4948 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4998 ASSERT((index >= 0) && (index < Length())); | 5002 ASSERT((index >= 0) && (index < Length())); |
4999 return &raw_ptr()->data()[index]; | 5003 return &raw_ptr()->data()[index]; |
5000 } | 5004 } |
5001 | 5005 |
5002 void SetLength(intptr_t value) const { | 5006 void SetLength(intptr_t value) const { |
5003 // This is only safe because we create a new Smi, which does not cause | 5007 // This is only safe because we create a new Smi, which does not cause |
5004 // heap allocation. | 5008 // heap allocation. |
5005 raw_ptr()->length_ = Smi::New(value); | 5009 raw_ptr()->length_ = Smi::New(value); |
5006 } | 5010 } |
5007 | 5011 |
5008 HEAP_OBJECT_IMPLEMENTATION(Array, Instance); | 5012 FINAL_HEAP_OBJECT_IMPLEMENTATION(Array, Instance); |
5009 friend class Class; | 5013 friend class Class; |
| 5014 friend class ImmutableArray; |
5010 friend class Object; | 5015 friend class Object; |
5011 friend class String; | 5016 friend class String; |
5012 }; | 5017 }; |
5013 | 5018 |
5014 | 5019 |
5015 class ImmutableArray : public Array { | 5020 class ImmutableArray : public AllStatic { |
5016 public: | 5021 public: |
5017 static RawImmutableArray* New(intptr_t len, Heap::Space space = Heap::kNew); | 5022 static RawImmutableArray* New(intptr_t len, Heap::Space space = Heap::kNew); |
5018 | 5023 |
| 5024 static RawImmutableArray* ReadFrom(SnapshotReader* reader, |
| 5025 intptr_t object_id, |
| 5026 intptr_t tags, |
| 5027 Snapshot::Kind kind); |
| 5028 |
| 5029 static const ClassId kClassId = kImmutableArrayCid; |
| 5030 |
| 5031 static intptr_t InstanceSize() { |
| 5032 return Array::InstanceSize(); |
| 5033 } |
| 5034 |
| 5035 static intptr_t InstanceSize(intptr_t len) { |
| 5036 return Array::InstanceSize(len); |
| 5037 } |
| 5038 |
5019 private: | 5039 private: |
5020 FINAL_HEAP_OBJECT_IMPLEMENTATION(ImmutableArray, Array); | 5040 static RawImmutableArray* raw(const Array& array) { |
| 5041 return reinterpret_cast<RawImmutableArray*>(array.raw()); |
| 5042 } |
| 5043 |
5021 friend class Class; | 5044 friend class Class; |
5022 }; | 5045 }; |
5023 | 5046 |
5024 | 5047 |
5025 class GrowableObjectArray : public Instance { | 5048 class GrowableObjectArray : public Instance { |
5026 public: | 5049 public: |
5027 intptr_t Capacity() const { | 5050 intptr_t Capacity() const { |
5028 NoGCScope no_gc; | 5051 NoGCScope no_gc; |
5029 ASSERT(!IsNull()); | 5052 ASSERT(!IsNull()); |
5030 return Smi::Value(DataArray()->length_); | 5053 return Smi::Value(DataArray()->length_); |
(...skipping 836 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5867 | 5890 |
5868 | 5891 |
5869 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, | 5892 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, |
5870 intptr_t index) { | 5893 intptr_t index) { |
5871 return array.At((index * kEntryLength) + kTargetFunctionIndex); | 5894 return array.At((index * kEntryLength) + kTargetFunctionIndex); |
5872 } | 5895 } |
5873 | 5896 |
5874 } // namespace dart | 5897 } // namespace dart |
5875 | 5898 |
5876 #endif // VM_OBJECT_H_ | 5899 #endif // VM_OBJECT_H_ |
OLD | NEW |