| 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 2788 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2799 static RawImmutableArray* New(intptr_t len, Heap::Space space = Heap::kNew) { | 2799 static RawImmutableArray* New(intptr_t len, Heap::Space space = Heap::kNew) { |
| 2800 return reinterpret_cast<RawImmutableArray*>(Array::New(len, true, space)); | 2800 return reinterpret_cast<RawImmutableArray*>(Array::New(len, true, space)); |
| 2801 } | 2801 } |
| 2802 | 2802 |
| 2803 private: | 2803 private: |
| 2804 HEAP_OBJECT_IMPLEMENTATION(ImmutableArray, Array); | 2804 HEAP_OBJECT_IMPLEMENTATION(ImmutableArray, Array); |
| 2805 friend class Class; | 2805 friend class Class; |
| 2806 }; | 2806 }; |
| 2807 | 2807 |
| 2808 | 2808 |
| 2809 class ByteBuffer : public Instance { |
| 2810 public: |
| 2811 intptr_t Length() const { |
| 2812 ASSERT(!IsNull()); |
| 2813 return Smi::Value(raw_ptr()->length_); |
| 2814 } |
| 2815 |
| 2816 template<typename T> |
| 2817 T At(intptr_t byte_offset) const { |
| 2818 T* addr = Addr<T>(byte_offset); |
| 2819 ASSERT(Utils::IsAligned(reinterpret_cast<intptr_t>(addr), sizeof(T))); |
| 2820 return *addr; |
| 2821 } |
| 2822 template<typename T> |
| 2823 void SetAt(intptr_t byte_offset, T value) const { |
| 2824 T* addr = Addr<T>(byte_offset); |
| 2825 ASSERT(Utils::IsAligned(reinterpret_cast<intptr_t>(addr), sizeof(T))); |
| 2826 *addr = value; |
| 2827 } |
| 2828 |
| 2829 template<typename T> |
| 2830 T UnalignedAt(intptr_t byte_offset) const { |
| 2831 T result; |
| 2832 memmove(&result, Addr<T>(byte_offset), sizeof(T)); |
| 2833 return result; |
| 2834 } |
| 2835 template<typename T> |
| 2836 void SetUnalignedAt(intptr_t byte_offset, T value) const { |
| 2837 memmove(Addr<T>(byte_offset), &value, sizeof(T)); |
| 2838 } |
| 2839 |
| 2840 virtual bool Equals(const Instance& other) const; |
| 2841 |
| 2842 static intptr_t InstanceSize() { |
| 2843 return RoundedAllocationSize(sizeof(RawByteBuffer)); |
| 2844 } |
| 2845 |
| 2846 static RawByteBuffer* New(uint8_t* data, |
| 2847 intptr_t len, |
| 2848 Heap::Space space = Heap::kNew); |
| 2849 |
| 2850 private: |
| 2851 template<typename T> |
| 2852 T* Addr(intptr_t byte_offset) const { |
| 2853 intptr_t limit = byte_offset + sizeof(T); |
| 2854 // TODO(iposva): Determine if we should throw an exception here. |
| 2855 ASSERT((byte_offset >= 0) && (limit <= Length())); |
| 2856 uint8_t* addr = &raw_ptr()->data_[byte_offset]; |
| 2857 return reinterpret_cast<T*>(addr); |
| 2858 } |
| 2859 |
| 2860 void SetLength(intptr_t value) { |
| 2861 raw_ptr()->length_ = Smi::New(value); |
| 2862 } |
| 2863 |
| 2864 void SetData(uint8_t* data) const { |
| 2865 raw_ptr()->data_ = data; |
| 2866 } |
| 2867 |
| 2868 HEAP_OBJECT_IMPLEMENTATION(ByteBuffer, Instance); |
| 2869 friend class Class; |
| 2870 }; |
| 2871 |
| 2872 |
| 2809 class Closure : public Instance { | 2873 class Closure : public Instance { |
| 2810 public: | 2874 public: |
| 2811 RawFunction* function() const { return raw_ptr()->function_; } | 2875 RawFunction* function() const { return raw_ptr()->function_; } |
| 2812 static intptr_t function_offset() { | 2876 static intptr_t function_offset() { |
| 2813 return OFFSET_OF(RawClosure, function_); | 2877 return OFFSET_OF(RawClosure, function_); |
| 2814 } | 2878 } |
| 2815 | 2879 |
| 2816 RawContext* context() const { return raw_ptr()->context_; } | 2880 RawContext* context() const { return raw_ptr()->context_; } |
| 2817 static intptr_t context_offset() { return OFFSET_OF(RawClosure, context_); } | 2881 static intptr_t context_offset() { return OFFSET_OF(RawClosure, context_); } |
| 2818 | 2882 |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3012 } | 3076 } |
| 3013 | 3077 |
| 3014 | 3078 |
| 3015 void Context::SetAt(intptr_t index, const Instance& value) const { | 3079 void Context::SetAt(intptr_t index, const Instance& value) const { |
| 3016 StorePointer(InstanceAddr(index), value.raw()); | 3080 StorePointer(InstanceAddr(index), value.raw()); |
| 3017 } | 3081 } |
| 3018 | 3082 |
| 3019 } // namespace dart | 3083 } // namespace dart |
| 3020 | 3084 |
| 3021 #endif // VM_OBJECT_H_ | 3085 #endif // VM_OBJECT_H_ |
| OLD | NEW |