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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 static bool InSamePage(uword address0, uword address1); | 62 static bool InSamePage(uword address0, uword address1); |
63 | 63 |
64 // Truncate this virtual memory segment. If try_unmap is false, the | 64 // Truncate this virtual memory segment. If try_unmap is false, the |
65 // memory beyond the new end is still accessible, but will be returned | 65 // memory beyond the new end is still accessible, but will be returned |
66 // upon destruction. | 66 // upon destruction. |
67 void Truncate(intptr_t new_size, bool try_unmap = true); | 67 void Truncate(intptr_t new_size, bool try_unmap = true); |
68 | 68 |
69 // Commit a reserved memory area, so that the memory can be accessed. | 69 // Commit a reserved memory area, so that the memory can be accessed. |
70 bool Commit(uword addr, intptr_t size, bool is_executable); | 70 bool Commit(uword addr, intptr_t size, bool is_executable); |
71 | 71 |
| 72 bool embedder_allocated() const { return embedder_allocated_; } |
| 73 |
72 static VirtualMemory* ForInstructionsSnapshot(void* pointer, uword size); | 74 static VirtualMemory* ForInstructionsSnapshot(void* pointer, uword size); |
73 | 75 |
74 private: | 76 private: |
75 static VirtualMemory* ReserveInternal(intptr_t size); | 77 static VirtualMemory* ReserveInternal(intptr_t size); |
76 | 78 |
77 // Free a sub segment. On operating systems that support it this | 79 // Free a sub segment. On operating systems that support it this |
78 // can give back the virtual memory to the system. Returns true on success. | 80 // can give back the virtual memory to the system. Returns true on success. |
79 static bool FreeSubSegment(void* address, intptr_t size); | 81 static bool FreeSubSegment(void* address, intptr_t size); |
80 | 82 |
81 // This constructor is only used internally when reserving new virtual spaces. | 83 // This constructor is only used internally when reserving new virtual spaces. |
82 // It does not reserve any virtual address space on its own. | 84 // It does not reserve any virtual address space on its own. |
83 explicit VirtualMemory(const MemoryRegion& region) : | 85 explicit VirtualMemory(const MemoryRegion& region) : |
84 region_(region.pointer(), region.size()), | 86 region_(region.pointer(), region.size()), |
85 reserved_size_(region.size()) { } | 87 reserved_size_(region.size()) { } |
86 | 88 |
87 MemoryRegion region_; | 89 MemoryRegion region_; |
88 | 90 |
89 // The size of the underlying reservation not yet given back to the OS. | 91 // The size of the underlying reservation not yet given back to the OS. |
90 // Its start coincides with region_, but its size might not, due to Truncate. | 92 // Its start coincides with region_, but its size might not, due to Truncate. |
91 intptr_t reserved_size_; | 93 intptr_t reserved_size_; |
92 | 94 |
93 static uword page_size_; | 95 static uword page_size_; |
94 | 96 |
| 97 // True for a region provided by the embedder. |
| 98 bool embedder_allocated_; |
| 99 |
95 DISALLOW_IMPLICIT_CONSTRUCTORS(VirtualMemory); | 100 DISALLOW_IMPLICIT_CONSTRUCTORS(VirtualMemory); |
96 }; | 101 }; |
97 | 102 |
98 } // namespace dart | 103 } // namespace dart |
99 | 104 |
100 #endif // VM_VIRTUAL_MEMORY_H_ | 105 #endif // VM_VIRTUAL_MEMORY_H_ |
OLD | NEW |