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/globals.h" | 9 #include "vm/globals.h" |
10 | 10 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 size_ = (region.size() + extra); | 59 size_ = (region.size() + extra); |
60 } | 60 } |
61 | 61 |
62 private: | 62 private: |
63 template<typename T> T* ComputeInternalPointer(uword offset) const { | 63 template<typename T> T* ComputeInternalPointer(uword offset) const { |
64 ASSERT(size() >= sizeof(T)); | 64 ASSERT(size() >= sizeof(T)); |
65 ASSERT(offset <= size() - sizeof(T)); | 65 ASSERT(offset <= size() - sizeof(T)); |
66 return reinterpret_cast<T*>(start() + offset); | 66 return reinterpret_cast<T*>(start() + offset); |
67 } | 67 } |
68 | 68 |
69 // Locate the bit with the given offset. Returns a pointer to the byte | |
70 // containing the bit, and sets bit_mask to the bit within that byte. | |
71 uint8_t* ComputeBitPointer(uword bit_offset, uint8_t* bit_mask) const { | |
72 uword bit_remainder = (bit_offset & (kBitsPerByte - 1)); | |
73 *bit_mask = (1U << bit_remainder); | |
74 uword byte_offset = (bit_offset >> kBitsPerByteLog2); | |
75 return ComputeInternalPointer<uint8_t>(byte_offset); | |
76 } | |
77 | |
78 void* pointer_; | 69 void* pointer_; |
79 uword size_; | 70 uword size_; |
80 | 71 |
81 DISALLOW_COPY_AND_ASSIGN(MemoryRegion); | 72 DISALLOW_COPY_AND_ASSIGN(MemoryRegion); |
82 }; | 73 }; |
83 | 74 |
84 } // namespace dart | 75 } // namespace dart |
85 | 76 |
86 #endif // VM_MEMORY_REGION_H_ | 77 #endif // VM_MEMORY_REGION_H_ |
OLD | NEW |