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_MEMORY_REGION_H_ | 5 #ifndef VM_MEMORY_REGION_H_ |
6 #define VM_MEMORY_REGION_H_ | 6 #define VM_MEMORY_REGION_H_ |
7 | 7 |
8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
| 9 #include "vm/allocation.h" |
9 #include "vm/globals.h" | 10 #include "vm/globals.h" |
10 | 11 |
11 namespace dart { | 12 namespace dart { |
12 | 13 |
13 // Memory regions are useful for accessing memory with bounds check in | 14 // Memory regions are useful for accessing memory with bounds check in |
14 // debug mode. They can be safely passed by value and do not assume ownership | 15 // debug mode. They can be safely passed by value and do not assume ownership |
15 // of the region. | 16 // of the region. |
16 class MemoryRegion { | 17 class MemoryRegion : public ValueObject { |
17 public: | 18 public: |
18 MemoryRegion() : pointer_(NULL), size_(0) { } | 19 MemoryRegion() : pointer_(NULL), size_(0) { } |
19 MemoryRegion(void* pointer, uword size) : pointer_(pointer), size_(size) { } | 20 MemoryRegion(void* pointer, uword size) : pointer_(pointer), size_(size) { } |
| 21 MemoryRegion(const MemoryRegion& other) : ValueObject() { *this = other; } |
| 22 MemoryRegion& operator=(const MemoryRegion& other) { |
| 23 pointer_ = other.pointer_; |
| 24 size_ = other.size_; |
| 25 return *this; |
| 26 } |
20 | 27 |
21 void* pointer() const { return pointer_; } | 28 void* pointer() const { return pointer_; } |
22 uword size() const { return size_; } | 29 uword size() const { return size_; } |
23 uword size_in_bits() const { return size_ * kBitsPerByte; } | 30 uword size_in_bits() const { return size_ * kBitsPerByte; } |
24 | 31 |
25 static uword pointer_offset() { return OFFSET_OF(MemoryRegion, pointer_); } | 32 static uword pointer_offset() { return OFFSET_OF(MemoryRegion, pointer_); } |
26 | 33 |
27 uword start() const { return reinterpret_cast<uword>(pointer_); } | 34 uword start() const { return reinterpret_cast<uword>(pointer_); } |
28 uword end() const { return start() + size_; } | 35 uword end() const { return start() + size_; } |
29 | 36 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 | 68 |
62 private: | 69 private: |
63 template<typename T> T* ComputeInternalPointer(uword offset) const { | 70 template<typename T> T* ComputeInternalPointer(uword offset) const { |
64 ASSERT(size() >= sizeof(T)); | 71 ASSERT(size() >= sizeof(T)); |
65 ASSERT(offset <= size() - sizeof(T)); | 72 ASSERT(offset <= size() - sizeof(T)); |
66 return reinterpret_cast<T*>(start() + offset); | 73 return reinterpret_cast<T*>(start() + offset); |
67 } | 74 } |
68 | 75 |
69 void* pointer_; | 76 void* pointer_; |
70 uword size_; | 77 uword size_; |
71 | |
72 DISALLOW_COPY_AND_ASSIGN(MemoryRegion); | |
73 }; | 78 }; |
74 | 79 |
75 } // namespace dart | 80 } // namespace dart |
76 | 81 |
77 #endif // VM_MEMORY_REGION_H_ | 82 #endif // VM_MEMORY_REGION_H_ |
OLD | NEW |