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_VIRTUAL_MEMORY_H_ | 5 #ifndef VM_VIRTUAL_MEMORY_H_ |
6 #define VM_VIRTUAL_MEMORY_H_ | 6 #define VM_VIRTUAL_MEMORY_H_ |
7 | 7 |
8 #include "platform/utils.h" | 8 #include "platform/utils.h" |
9 #include "vm/globals.h" | 9 #include "vm/globals.h" |
10 #include "vm/memory_region.h" | 10 #include "vm/memory_region.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 } | 53 } |
54 | 54 |
55 static intptr_t PageSize() { | 55 static intptr_t PageSize() { |
56 ASSERT(page_size_ != 0); | 56 ASSERT(page_size_ != 0); |
57 ASSERT(Utils::IsPowerOfTwo(page_size_)); | 57 ASSERT(Utils::IsPowerOfTwo(page_size_)); |
58 return page_size_; | 58 return page_size_; |
59 } | 59 } |
60 | 60 |
61 static bool InSamePage(uword address0, uword address1); | 61 static bool InSamePage(uword address0, uword address1); |
62 | 62 |
63 // Truncate this virtual memory segment. | 63 // Truncate this virtual memory segment. If try_unmap is false, the |
| 64 // memory beyond the new end is still accessible, but will be returned |
| 65 // upon destruction. |
64 void Truncate(intptr_t new_size, bool try_unmap = true); | 66 void Truncate(intptr_t new_size, bool try_unmap = true); |
65 | 67 |
| 68 // Commit a reserved memory area, so that the memory can be accessed. |
| 69 bool Commit(uword addr, intptr_t size, bool is_executable); |
| 70 |
66 private: | 71 private: |
67 static VirtualMemory* ReserveInternal(intptr_t size); | 72 static VirtualMemory* ReserveInternal(intptr_t size); |
68 | 73 |
69 // Free a sub segment. On operating systems that support it this | 74 // Free a sub segment. On operating systems that support it this |
70 // can give back the virtual memory to the system. Returns true on success. | 75 // can give back the virtual memory to the system. Returns true on success. |
71 static bool FreeSubSegment(void* address, intptr_t size); | 76 static bool FreeSubSegment(void* address, intptr_t size); |
72 | 77 |
73 // This constructor is only used internally when reserving new virtual spaces. | 78 // This constructor is only used internally when reserving new virtual spaces. |
74 // It does not reserve any virtual address space on its own. | 79 // It does not reserve any virtual address space on its own. |
75 explicit VirtualMemory(const MemoryRegion& region) : | 80 explicit VirtualMemory(const MemoryRegion& region) : |
76 region_(region.pointer(), region.size()), | 81 region_(region.pointer(), region.size()), |
77 reserved_size_(region.size()) { } | 82 reserved_size_(region.size()) { } |
78 | 83 |
79 // Commit a reserved memory area, so that the memory can be accessed. | |
80 bool Commit(uword addr, intptr_t size, bool is_executable); | |
81 | |
82 MemoryRegion region_; | 84 MemoryRegion region_; |
83 | 85 |
84 // The size of the underlying reservation not yet given back to the OS. | 86 // The size of the underlying reservation not yet given back to the OS. |
85 // Its start coincides with region_, but its size might not, due to Truncate. | 87 // Its start coincides with region_, but its size might not, due to Truncate. |
86 intptr_t reserved_size_; | 88 intptr_t reserved_size_; |
87 | 89 |
88 static uword page_size_; | 90 static uword page_size_; |
89 | 91 |
90 DISALLOW_IMPLICIT_CONSTRUCTORS(VirtualMemory); | 92 DISALLOW_IMPLICIT_CONSTRUCTORS(VirtualMemory); |
91 }; | 93 }; |
92 | 94 |
93 } // namespace dart | 95 } // namespace dart |
94 | 96 |
95 #endif // VM_VIRTUAL_MEMORY_H_ | 97 #endif // VM_VIRTUAL_MEMORY_H_ |
OLD | NEW |