| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 "vm/assert.h" | 8 #include "vm/assert.h" |
| 9 #include "vm/dart.h" | 9 #include "vm/dart.h" |
| 10 #include "vm/globals.h" | 10 #include "vm/globals.h" |
| (...skipping 2765 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2776 static RawImmutableArray* New(intptr_t len, Heap::Space space = Heap::kNew) { | 2776 static RawImmutableArray* New(intptr_t len, Heap::Space space = Heap::kNew) { |
| 2777 return reinterpret_cast<RawImmutableArray*>(Array::New(len, true, space)); | 2777 return reinterpret_cast<RawImmutableArray*>(Array::New(len, true, space)); |
| 2778 } | 2778 } |
| 2779 | 2779 |
| 2780 private: | 2780 private: |
| 2781 HEAP_OBJECT_IMPLEMENTATION(ImmutableArray, Array); | 2781 HEAP_OBJECT_IMPLEMENTATION(ImmutableArray, Array); |
| 2782 friend class Class; | 2782 friend class Class; |
| 2783 }; | 2783 }; |
| 2784 | 2784 |
| 2785 | 2785 |
| 2786 class ByteBuffer : public Instance { |
| 2787 public: |
| 2788 intptr_t Length() const { |
| 2789 ASSERT(!IsNull()); |
| 2790 return Smi::Value(raw_ptr()->length_); |
| 2791 } |
| 2792 |
| 2793 template<typename T> |
| 2794 T At(intptr_t byte_offset) const { |
| 2795 ASSERT(Utils::IsAligned(byte_offset, sizeof(T))); |
| 2796 return *Addr<T>(byte_offset); |
| 2797 } |
| 2798 template<typename T> |
| 2799 void SetAt(intptr_t byte_offset, T value) const { |
| 2800 ASSERT(Utils::IsAligned(byte_offset, sizeof(T))); |
| 2801 *Addr<T>(byte_offset) = value; |
| 2802 } |
| 2803 |
| 2804 template<typename T> |
| 2805 T UnalignedAt(intptr_t byte_offset) const { |
| 2806 T result; |
| 2807 memmove(&result, Addr<T>(byte_offset), sizeof(T)); |
| 2808 return result; |
| 2809 } |
| 2810 template<typename T> |
| 2811 void SetUnalignedAt(intptr_t byte_offset, T value) const { |
| 2812 memmove(Addr<T>(byte_offset), &value, sizeof(T)); |
| 2813 } |
| 2814 |
| 2815 virtual bool Equals(const Instance& other) const; |
| 2816 |
| 2817 static intptr_t InstanceSize() { |
| 2818 return RoundedAllocationSize(sizeof(RawByteBuffer)); |
| 2819 } |
| 2820 |
| 2821 static RawByteBuffer* New(uint8_t* data, |
| 2822 intptr_t len, |
| 2823 Heap::Space space = Heap::kNew); |
| 2824 |
| 2825 private: |
| 2826 template<typename T> |
| 2827 T* Addr(intptr_t byte_offset) const { |
| 2828 intptr_t limit = byte_offset + sizeof(T); |
| 2829 // TODO(iposva): Determine if we should throw an exception here. |
| 2830 ASSERT((byte_offset >= 0) && (limit <= Length())); |
| 2831 uint8_t* addr = &raw_ptr()->data_[byte_offset]; |
| 2832 return reinterpret_cast<T*>(addr); |
| 2833 } |
| 2834 |
| 2835 void SetLength(intptr_t value) { |
| 2836 raw_ptr()->length_ = Smi::New(value); |
| 2837 } |
| 2838 |
| 2839 void SetData(uint8_t* data) const { |
| 2840 raw_ptr()->data_ = data; |
| 2841 } |
| 2842 |
| 2843 HEAP_OBJECT_IMPLEMENTATION(ByteBuffer, Instance); |
| 2844 friend class Class; |
| 2845 }; |
| 2846 |
| 2847 |
| 2786 class Closure : public Instance { | 2848 class Closure : public Instance { |
| 2787 public: | 2849 public: |
| 2788 RawFunction* function() const { return raw_ptr()->function_; } | 2850 RawFunction* function() const { return raw_ptr()->function_; } |
| 2789 static intptr_t function_offset() { | 2851 static intptr_t function_offset() { |
| 2790 return OFFSET_OF(RawClosure, function_); | 2852 return OFFSET_OF(RawClosure, function_); |
| 2791 } | 2853 } |
| 2792 | 2854 |
| 2793 RawContext* context() const { return raw_ptr()->context_; } | 2855 RawContext* context() const { return raw_ptr()->context_; } |
| 2794 static intptr_t context_offset() { return OFFSET_OF(RawClosure, context_); } | 2856 static intptr_t context_offset() { return OFFSET_OF(RawClosure, context_); } |
| 2795 | 2857 |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2989 } | 3051 } |
| 2990 | 3052 |
| 2991 | 3053 |
| 2992 void Context::SetAt(intptr_t index, const Instance& value) const { | 3054 void Context::SetAt(intptr_t index, const Instance& value) const { |
| 2993 StorePointer(InstanceAddr(index), value.raw()); | 3055 StorePointer(InstanceAddr(index), value.raw()); |
| 2994 } | 3056 } |
| 2995 | 3057 |
| 2996 } // namespace dart | 3058 } // namespace dart |
| 2997 | 3059 |
| 2998 #endif // VM_OBJECT_H_ | 3060 #endif // VM_OBJECT_H_ |
| OLD | NEW |