| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Platform-specific code for MacOS goes here. For the POSIX-compatible | 5 // Platform-specific code for MacOS goes here. For the POSIX-compatible |
| 6 // parts, the implementation is in platform-posix.cc. | 6 // parts, the implementation is in platform-posix.cc. |
| 7 | 7 |
| 8 #include <dlfcn.h> | 8 #include <dlfcn.h> |
| 9 #include <mach/mach_init.h> | 9 #include <mach/mach_init.h> |
| 10 #include <mach-o/dyld.h> | 10 #include <mach-o/dyld.h> |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 | 177 |
| 178 VirtualMemory::VirtualMemory() : address_(NULL), size_(0) { } | 178 VirtualMemory::VirtualMemory() : address_(NULL), size_(0) { } |
| 179 | 179 |
| 180 | 180 |
| 181 VirtualMemory::VirtualMemory(size_t size) | 181 VirtualMemory::VirtualMemory(size_t size) |
| 182 : address_(ReserveRegion(size)), size_(size) { } | 182 : address_(ReserveRegion(size)), size_(size) { } |
| 183 | 183 |
| 184 | 184 |
| 185 VirtualMemory::VirtualMemory(size_t size, size_t alignment) | 185 VirtualMemory::VirtualMemory(size_t size, size_t alignment) |
| 186 : address_(NULL), size_(0) { | 186 : address_(NULL), size_(0) { |
| 187 ASSERT(IsAligned(alignment, static_cast<intptr_t>(OS::AllocateAlignment()))); | 187 DCHECK(IsAligned(alignment, static_cast<intptr_t>(OS::AllocateAlignment()))); |
| 188 size_t request_size = RoundUp(size + alignment, | 188 size_t request_size = RoundUp(size + alignment, |
| 189 static_cast<intptr_t>(OS::AllocateAlignment())); | 189 static_cast<intptr_t>(OS::AllocateAlignment())); |
| 190 void* reservation = mmap(OS::GetRandomMmapAddr(), | 190 void* reservation = mmap(OS::GetRandomMmapAddr(), |
| 191 request_size, | 191 request_size, |
| 192 PROT_NONE, | 192 PROT_NONE, |
| 193 MAP_PRIVATE | MAP_ANON | MAP_NORESERVE, | 193 MAP_PRIVATE | MAP_ANON | MAP_NORESERVE, |
| 194 kMmapFd, | 194 kMmapFd, |
| 195 kMmapFdOffset); | 195 kMmapFdOffset); |
| 196 if (reservation == MAP_FAILED) return; | 196 if (reservation == MAP_FAILED) return; |
| 197 | 197 |
| 198 uint8_t* base = static_cast<uint8_t*>(reservation); | 198 uint8_t* base = static_cast<uint8_t*>(reservation); |
| 199 uint8_t* aligned_base = RoundUp(base, alignment); | 199 uint8_t* aligned_base = RoundUp(base, alignment); |
| 200 ASSERT_LE(base, aligned_base); | 200 DCHECK_LE(base, aligned_base); |
| 201 | 201 |
| 202 // Unmap extra memory reserved before and after the desired block. | 202 // Unmap extra memory reserved before and after the desired block. |
| 203 if (aligned_base != base) { | 203 if (aligned_base != base) { |
| 204 size_t prefix_size = static_cast<size_t>(aligned_base - base); | 204 size_t prefix_size = static_cast<size_t>(aligned_base - base); |
| 205 OS::Free(base, prefix_size); | 205 OS::Free(base, prefix_size); |
| 206 request_size -= prefix_size; | 206 request_size -= prefix_size; |
| 207 } | 207 } |
| 208 | 208 |
| 209 size_t aligned_size = RoundUp(size, OS::AllocateAlignment()); | 209 size_t aligned_size = RoundUp(size, OS::AllocateAlignment()); |
| 210 ASSERT_LE(aligned_size, request_size); | 210 DCHECK_LE(aligned_size, request_size); |
| 211 | 211 |
| 212 if (aligned_size != request_size) { | 212 if (aligned_size != request_size) { |
| 213 size_t suffix_size = request_size - aligned_size; | 213 size_t suffix_size = request_size - aligned_size; |
| 214 OS::Free(aligned_base + aligned_size, suffix_size); | 214 OS::Free(aligned_base + aligned_size, suffix_size); |
| 215 request_size -= suffix_size; | 215 request_size -= suffix_size; |
| 216 } | 216 } |
| 217 | 217 |
| 218 ASSERT(aligned_size == request_size); | 218 DCHECK(aligned_size == request_size); |
| 219 | 219 |
| 220 address_ = static_cast<void*>(aligned_base); | 220 address_ = static_cast<void*>(aligned_base); |
| 221 size_ = aligned_size; | 221 size_ = aligned_size; |
| 222 } | 222 } |
| 223 | 223 |
| 224 | 224 |
| 225 VirtualMemory::~VirtualMemory() { | 225 VirtualMemory::~VirtualMemory() { |
| 226 if (IsReserved()) { | 226 if (IsReserved()) { |
| 227 bool result = ReleaseRegion(address(), size()); | 227 bool result = ReleaseRegion(address(), size()); |
| 228 ASSERT(result); | 228 DCHECK(result); |
| 229 USE(result); | 229 USE(result); |
| 230 } | 230 } |
| 231 } | 231 } |
| 232 | 232 |
| 233 | 233 |
| 234 bool VirtualMemory::IsReserved() { | 234 bool VirtualMemory::IsReserved() { |
| 235 return address_ != NULL; | 235 return address_ != NULL; |
| 236 } | 236 } |
| 237 | 237 |
| 238 | 238 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 bool VirtualMemory::ReleaseRegion(void* address, size_t size) { | 301 bool VirtualMemory::ReleaseRegion(void* address, size_t size) { |
| 302 return munmap(address, size) == 0; | 302 return munmap(address, size) == 0; |
| 303 } | 303 } |
| 304 | 304 |
| 305 | 305 |
| 306 bool VirtualMemory::HasLazyCommits() { | 306 bool VirtualMemory::HasLazyCommits() { |
| 307 return false; | 307 return false; |
| 308 } | 308 } |
| 309 | 309 |
| 310 } } // namespace v8::base | 310 } } // namespace v8::base |
| OLD | NEW |