Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(310)

Side by Side Diff: runtime/vm/virtual_memory.h

Issue 2481873005: clang-format runtime/vm (Closed)
Patch Set: Merge Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/verifier.cc ('k') | runtime/vm/virtual_memory.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 RUNTIME_VM_VIRTUAL_MEMORY_H_ 5 #ifndef RUNTIME_VM_VIRTUAL_MEMORY_H_
6 #define RUNTIME_VM_VIRTUAL_MEMORY_H_ 6 #define RUNTIME_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 14 matching lines...) Expand all
25 ~VirtualMemory(); 25 ~VirtualMemory();
26 26
27 int32_t handle() const { return handle_; } 27 int32_t handle() const { return handle_; }
28 uword start() const { return region_.start(); } 28 uword start() const { return region_.start(); }
29 uword end() const { return region_.end(); } 29 uword end() const { return region_.end(); }
30 void* address() const { return region_.pointer(); } 30 void* address() const { return region_.pointer(); }
31 intptr_t size() const { return region_.size(); } 31 intptr_t size() const { return region_.size(); }
32 32
33 static void InitOnce(); 33 static void InitOnce();
34 34
35 bool Contains(uword addr) const { 35 bool Contains(uword addr) const { return region_.Contains(addr); }
36 return region_.Contains(addr);
37 }
38 36
39 // Commits the virtual memory area, which is guaranteed to be zeroed. Returns 37 // Commits the virtual memory area, which is guaranteed to be zeroed. Returns
40 // true on success and false on failure (e.g., out-of-memory). 38 // true on success and false on failure (e.g., out-of-memory).
41 bool Commit(bool is_executable) { 39 bool Commit(bool is_executable) {
42 return Commit(start(), size(), is_executable); 40 return Commit(start(), size(), is_executable);
43 } 41 }
44 42
45 // Changes the protection of the virtual memory area. 43 // Changes the protection of the virtual memory area.
46 static bool Protect(void* address, intptr_t size, Protection mode); 44 static bool Protect(void* address, intptr_t size, Protection mode);
47 bool Protect(Protection mode) { 45 bool Protect(Protection mode) { return Protect(address(), size(), mode); }
48 return Protect(address(), size(), mode);
49 }
50 46
51 // Reserves a virtual memory segment with size. If a segment of the requested 47 // Reserves a virtual memory segment with size. If a segment of the requested
52 // size cannot be allocated NULL is returned. 48 // size cannot be allocated NULL is returned.
53 static VirtualMemory* Reserve(intptr_t size) { 49 static VirtualMemory* Reserve(intptr_t size) { return ReserveInternal(size); }
54 return ReserveInternal(size);
55 }
56 50
57 static intptr_t PageSize() { 51 static intptr_t PageSize() {
58 ASSERT(page_size_ != 0); 52 ASSERT(page_size_ != 0);
59 ASSERT(Utils::IsPowerOfTwo(page_size_)); 53 ASSERT(Utils::IsPowerOfTwo(page_size_));
60 return page_size_; 54 return page_size_;
61 } 55 }
62 56
63 static bool InSamePage(uword address0, uword address1); 57 static bool InSamePage(uword address0, uword address1);
64 58
65 // Truncate this virtual memory segment. If try_unmap is false, the 59 // Truncate this virtual memory segment. If try_unmap is false, the
(...skipping 10 matching lines...) Expand all
76 70
77 private: 71 private:
78 static VirtualMemory* ReserveInternal(intptr_t size); 72 static VirtualMemory* ReserveInternal(intptr_t size);
79 73
80 // Free a sub segment. On operating systems that support it this 74 // Free a sub segment. On operating systems that support it this
81 // 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.
82 static bool FreeSubSegment(void* address, intptr_t size); 76 static bool FreeSubSegment(void* address, intptr_t size);
83 77
84 // This constructor is only used internally when reserving new virtual spaces. 78 // This constructor is only used internally when reserving new virtual spaces.
85 // It does not reserve any virtual address space on its own. 79 // It does not reserve any virtual address space on its own.
86 explicit VirtualMemory(const MemoryRegion& region, int32_t handle = 0) : 80 explicit VirtualMemory(const MemoryRegion& region, int32_t handle = 0)
87 region_(region.pointer(), region.size()), 81 : region_(region.pointer(), region.size()),
88 reserved_size_(region.size()), 82 reserved_size_(region.size()),
89 handle_(handle), 83 handle_(handle),
90 embedder_allocated_(false) { } 84 embedder_allocated_(false) {}
91 85
92 MemoryRegion region_; 86 MemoryRegion region_;
93 87
94 // The size of the underlying reservation not yet given back to the OS. 88 // The size of the underlying reservation not yet given back to the OS.
95 // Its start coincides with region_, but its size might not, due to Truncate. 89 // Its start coincides with region_, but its size might not, due to Truncate.
96 intptr_t reserved_size_; 90 intptr_t reserved_size_;
97 91
98 int32_t handle_; 92 int32_t handle_;
99 93
100 static uword page_size_; 94 static uword page_size_;
101 95
102 // True for a region provided by the embedder. 96 // True for a region provided by the embedder.
103 bool embedder_allocated_; 97 bool embedder_allocated_;
104 98
105 DISALLOW_IMPLICIT_CONSTRUCTORS(VirtualMemory); 99 DISALLOW_IMPLICIT_CONSTRUCTORS(VirtualMemory);
106 }; 100 };
107 101
108 } // namespace dart 102 } // namespace dart
109 103
110 #endif // RUNTIME_VM_VIRTUAL_MEMORY_H_ 104 #endif // RUNTIME_VM_VIRTUAL_MEMORY_H_
OLDNEW
« no previous file with comments | « runtime/vm/verifier.cc ('k') | runtime/vm/virtual_memory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698