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

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

Issue 644453003: Simplify VirtualMemory by removing unused ReserveAligned method. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 2 months 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 | Annotate | Revision Log
« no previous file with comments | « runtime/vm/pages.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 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 30 matching lines...) Expand all
41 } 41 }
42 42
43 // Changes the protection of the virtual memory area. 43 // Changes the protection of the virtual memory area.
44 static bool Protect(void* address, intptr_t size, Protection mode); 44 static bool Protect(void* address, intptr_t size, Protection mode);
45 bool Protect(Protection mode) { 45 bool Protect(Protection mode) {
46 return Protect(address(), size(), mode); 46 return Protect(address(), size(), mode);
47 } 47 }
48 48
49 // Reserves a virtual memory segment with size. If a segment of the requested 49 // Reserves a virtual memory segment with size. If a segment of the requested
50 // size cannot be allocated NULL is returned. 50 // size cannot be allocated NULL is returned.
51 static VirtualMemory* Reserve(intptr_t size); 51 static VirtualMemory* Reserve(intptr_t size) {
52 52 return ReserveInternal(size);
Ivan Posva 2014/10/09 07:01:14 Why this extra indirection?
koda 2014/10/09 15:58:52 To allow for inserting a bit of OS-independent log
53 // Reserves a virtual memory segment with the start address being aligned to 53 }
54 // the requested power of two.
55 static VirtualMemory* ReserveAligned(intptr_t size, intptr_t alignment);
56 54
57 static intptr_t PageSize() { 55 static intptr_t PageSize() {
58 ASSERT(page_size_ != 0); 56 ASSERT(page_size_ != 0);
59 ASSERT(Utils::IsPowerOfTwo(page_size_)); 57 ASSERT(Utils::IsPowerOfTwo(page_size_));
60 return page_size_; 58 return page_size_;
61 } 59 }
62 60
63 static bool InSamePage(uword address0, uword address1); 61 static bool InSamePage(uword address0, uword address1);
64 62
65 // Truncate this virtual memory segment. 63 // Truncate this virtual memory segment.
66 void Truncate(uword new_start, intptr_t size); 64 void Truncate(intptr_t new_size, bool try_unmap = true);
Ivan Posva 2014/10/09 07:01:13 When would it be beneficial to truncate without un
koda 2014/10/09 15:58:52 I will use it to implement the writer barrier veri
67 65
68 private: 66 private:
67 static VirtualMemory* ReserveInternal(intptr_t size);
68
69 // Free a sub segment. On operating systems that support it this 69 // Free a sub segment. On operating systems that support it this
70 // can give back the virtual memory to the system. 70 // can give back the virtual memory to the system. Returns true on success.
71 void FreeSubSegment(void* address, intptr_t size); 71 static bool FreeSubSegment(void* address, intptr_t size);
72 72
73 // This constructor is only used internally when reserving new virtual spaces. 73 // This constructor is only used internally when reserving new virtual spaces.
74 // It does not reserve any virtual address space on its own. 74 // It does not reserve any virtual address space on its own.
75 VirtualMemory(const MemoryRegion& region, void* reserved_pointer) : 75 explicit VirtualMemory(const MemoryRegion& region) :
76 region_(region.pointer(), region.size()), 76 region_(region.pointer(), region.size()),
77 reserved_pointer_(reserved_pointer) { } 77 reserved_size_(region.size()) { }
78 78
79 // Commit a reserved memory area, so that the memory can be accessed. 79 // Commit a reserved memory area, so that the memory can be accessed.
80 bool Commit(uword addr, intptr_t size, bool is_executable); 80 bool Commit(uword addr, intptr_t size, bool is_executable);
81 81
82 MemoryRegion region_; 82 MemoryRegion region_;
83 83
84 // The original pointer returned by the OS for this virtual memory 84 // The size of the underlying reservation not yet given back to the OS.
85 // allocation or NULL. reserved_pointer_ is non-NULL only for 85 // Its start coincides with region_, but its size might not, due to Truncate.
86 // platforms where virtual memory subregions cannot be given back to 86 intptr_t reserved_size_;
87 // the OS. When non-null it might not coincide with
88 // region_.pointer() if the virtual memory region has been
89 // truncated.
90 void* reserved_pointer_;
91 87
92 static uword page_size_; 88 static uword page_size_;
93 89
94 DISALLOW_IMPLICIT_CONSTRUCTORS(VirtualMemory); 90 DISALLOW_IMPLICIT_CONSTRUCTORS(VirtualMemory);
95 }; 91 };
96 92
97 } // namespace dart 93 } // namespace dart
98 94
99 #endif // VM_VIRTUAL_MEMORY_H_ 95 #endif // VM_VIRTUAL_MEMORY_H_
OLDNEW
« no previous file with comments | « runtime/vm/pages.cc ('k') | runtime/vm/virtual_memory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698