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 #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 3056 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3067 | 3067 |
| 3068 // Check if the type of this instance is a subtype of the given type. | 3068 // Check if the type of this instance is a subtype of the given type. |
| 3069 bool IsInstanceOf(const AbstractType& type, | 3069 bool IsInstanceOf(const AbstractType& type, |
| 3070 const AbstractTypeArguments& type_instantiator, | 3070 const AbstractTypeArguments& type_instantiator, |
| 3071 Error* malformed_error) const; | 3071 Error* malformed_error) const; |
| 3072 | 3072 |
| 3073 bool IsValidNativeIndex(int index) const { | 3073 bool IsValidNativeIndex(int index) const { |
| 3074 return ((index >= 0) && (index < clazz()->ptr()->num_native_fields_)); | 3074 return ((index >= 0) && (index < clazz()->ptr()->num_native_fields_)); |
| 3075 } | 3075 } |
| 3076 | 3076 |
| 3077 intptr_t GetNativeField(int index) const { | 3077 inline intptr_t GetNativeField(Isolate* isolate, int index) const; |
| 3078 return *NativeFieldAddr(index); | 3078 void SetNativeField(int index, intptr_t value) const; |
|
cshapiro
2012/11/12 18:48:45
Interesting, GetNativeField needs the isolate but
Tom Ball
2012/11/12 21:05:15
SetNativeField calls Object::Handle(RawObject*), w
Ivan Posva
2012/11/12 22:01:03
The reason I pass the isolate in GetNativeField is
| |
| 3079 } | |
| 3080 | |
| 3081 void SetNativeField(int index, intptr_t value) const { | |
| 3082 *NativeFieldAddr(index) = value; | |
| 3083 } | |
| 3084 | 3079 |
| 3085 // Returns true if the instance is a closure object. | 3080 // Returns true if the instance is a closure object. |
| 3086 bool IsClosure() const; | 3081 bool IsClosure() const; |
| 3087 | 3082 |
| 3088 static intptr_t InstanceSize() { | 3083 static intptr_t InstanceSize() { |
| 3089 return RoundedAllocationSize(sizeof(RawInstance)); | 3084 return RoundedAllocationSize(sizeof(RawInstance)); |
| 3090 } | 3085 } |
| 3091 | 3086 |
| 3092 static RawInstance* New(const Class& cls, Heap::Space space = Heap::kNew); | 3087 static RawInstance* New(const Class& cls, Heap::Space space = Heap::kNew); |
| 3093 | 3088 |
| 3094 private: | 3089 private: |
| 3095 RawObject** FieldAddrAtOffset(intptr_t offset) const { | 3090 RawObject** FieldAddrAtOffset(intptr_t offset) const { |
| 3096 ASSERT(IsValidFieldOffset(offset)); | 3091 ASSERT(IsValidFieldOffset(offset)); |
| 3097 return reinterpret_cast<RawObject**>(raw_value() - kHeapObjectTag + offset); | 3092 return reinterpret_cast<RawObject**>(raw_value() - kHeapObjectTag + offset); |
| 3098 } | 3093 } |
| 3099 RawObject** FieldAddr(const Field& field) const { | 3094 RawObject** FieldAddr(const Field& field) const { |
| 3100 return FieldAddrAtOffset(field.Offset()); | 3095 return FieldAddrAtOffset(field.Offset()); |
| 3101 } | 3096 } |
| 3102 intptr_t* NativeFieldAddr(int index) const { | 3097 RawObject** NativeFieldsAddr() const { |
| 3103 ASSERT(IsValidNativeIndex(index)); | 3098 return FieldAddrAtOffset(sizeof(RawObject)); |
| 3104 return reinterpret_cast<intptr_t*>((raw_value() - kHeapObjectTag) | |
| 3105 + (index * kWordSize) | |
| 3106 + sizeof(RawObject)); | |
| 3107 } | 3099 } |
| 3108 void SetFieldAtOffset(intptr_t offset, const Object& value) const { | 3100 void SetFieldAtOffset(intptr_t offset, const Object& value) const { |
| 3109 StorePointer(FieldAddrAtOffset(offset), value.raw()); | 3101 StorePointer(FieldAddrAtOffset(offset), value.raw()); |
| 3110 } | 3102 } |
| 3111 bool IsValidFieldOffset(int offset) const; | 3103 bool IsValidFieldOffset(int offset) const; |
| 3112 | 3104 |
| 3113 // TODO(iposva): Determine if this gets in the way of Smi. | 3105 // TODO(iposva): Determine if this gets in the way of Smi. |
| 3114 HEAP_OBJECT_IMPLEMENTATION(Instance, Object); | 3106 HEAP_OBJECT_IMPLEMENTATION(Instance, Object); |
| 3115 friend class Class; | 3107 friend class Class; |
| 3116 friend class Closure; | 3108 friend class Closure; |
| (...skipping 2725 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5842 ASSERT(!is_static()); // SetOffset is valid only for instance fields. | 5834 ASSERT(!is_static()); // SetOffset is valid only for instance fields. |
| 5843 raw_ptr()->value_ = Smi::New(value); | 5835 raw_ptr()->value_ = Smi::New(value); |
| 5844 } | 5836 } |
| 5845 | 5837 |
| 5846 | 5838 |
| 5847 void Context::SetAt(intptr_t index, const Instance& value) const { | 5839 void Context::SetAt(intptr_t index, const Instance& value) const { |
| 5848 StorePointer(InstanceAddr(index), value.raw()); | 5840 StorePointer(InstanceAddr(index), value.raw()); |
| 5849 } | 5841 } |
| 5850 | 5842 |
| 5851 | 5843 |
| 5844 intptr_t Instance::GetNativeField(Isolate* isolate, int index) const { | |
| 5845 ASSERT(IsValidNativeIndex(index)); | |
| 5846 const Object& native_fields = Object::Handle(isolate, *NativeFieldsAddr()); | |
| 5847 if (native_fields.IsNull()) { | |
| 5848 return 0; | |
| 5849 } | |
| 5850 return IntPtrArray::Cast(native_fields).At(index); | |
| 5851 } | |
| 5852 | |
| 5853 | |
| 5852 bool String::Equals(const String& str) const { | 5854 bool String::Equals(const String& str) const { |
| 5853 if (raw() == str.raw()) { | 5855 if (raw() == str.raw()) { |
| 5854 return true; // Both handles point to the same raw instance. | 5856 return true; // Both handles point to the same raw instance. |
| 5855 } | 5857 } |
| 5856 if (str.IsNull()) { | 5858 if (str.IsNull()) { |
| 5857 return false; | 5859 return false; |
| 5858 } | 5860 } |
| 5859 return Equals(str, 0, str.Length()); | 5861 return Equals(str, 0, str.Length()); |
| 5860 } | 5862 } |
| 5861 | 5863 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 5874 if (this->CharAt(i) != str.CharAt(begin_index + i)) { | 5876 if (this->CharAt(i) != str.CharAt(begin_index + i)) { |
| 5875 return false; | 5877 return false; |
| 5876 } | 5878 } |
| 5877 } | 5879 } |
| 5878 return true; | 5880 return true; |
| 5879 } | 5881 } |
| 5880 | 5882 |
| 5881 } // namespace dart | 5883 } // namespace dart |
| 5882 | 5884 |
| 5883 #endif // VM_OBJECT_H_ | 5885 #endif // VM_OBJECT_H_ |
| OLD | NEW |