OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 fclose(file); | 221 fclose(file); |
222 return NULL; | 222 return NULL; |
223 } | 223 } |
224 void* memory = | 224 void* memory = |
225 mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fileno(file), 0); | 225 mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fileno(file), 0); |
226 return new PosixMemoryMappedFile(file, memory, size); | 226 return new PosixMemoryMappedFile(file, memory, size); |
227 } | 227 } |
228 | 228 |
229 | 229 |
230 PosixMemoryMappedFile::~PosixMemoryMappedFile() { | 230 PosixMemoryMappedFile::~PosixMemoryMappedFile() { |
231 if (memory_) munmap(memory_, size_); | 231 if (memory_) OS::Free(memory_, size_); |
232 fclose(file_); | 232 fclose(file_); |
233 } | 233 } |
234 | 234 |
235 | 235 |
236 void OS::LogSharedLibraryAddresses() { | 236 void OS::LogSharedLibraryAddresses() { |
237 unsigned int images_count = _dyld_image_count(); | 237 unsigned int images_count = _dyld_image_count(); |
238 for (unsigned int i = 0; i < images_count; ++i) { | 238 for (unsigned int i = 0; i < images_count; ++i) { |
239 const mach_header* header = _dyld_get_image_header(i); | 239 const mach_header* header = _dyld_get_image_header(i); |
240 if (header == NULL) continue; | 240 if (header == NULL) continue; |
241 #if V8_HOST_ARCH_X64 | 241 #if V8_HOST_ARCH_X64 |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 ASSERT(IsAligned(alignment, static_cast<intptr_t>(OS::AllocateAlignment()))); | 346 ASSERT(IsAligned(alignment, static_cast<intptr_t>(OS::AllocateAlignment()))); |
347 size_t request_size = RoundUp(size + alignment, | 347 size_t request_size = RoundUp(size + alignment, |
348 static_cast<intptr_t>(OS::AllocateAlignment())); | 348 static_cast<intptr_t>(OS::AllocateAlignment())); |
349 void* reservation = mmap(NULL, | 349 void* reservation = mmap(NULL, |
350 request_size, | 350 request_size, |
351 PROT_NONE, | 351 PROT_NONE, |
352 MAP_PRIVATE | MAP_ANON | MAP_NORESERVE, | 352 MAP_PRIVATE | MAP_ANON | MAP_NORESERVE, |
353 kMmapFd, | 353 kMmapFd, |
354 kMmapFdOffset); | 354 kMmapFdOffset); |
355 if (reservation == MAP_FAILED) return; | 355 if (reservation == MAP_FAILED) return; |
| 356 |
356 Address base = static_cast<Address>(reservation); | 357 Address base = static_cast<Address>(reservation); |
357 Address aligned_base = RoundUp(base, alignment); | 358 Address aligned_base = RoundUp(base, alignment); |
358 ASSERT(base <= aligned_base); | 359 ASSERT_LE(base, aligned_base); |
359 | 360 |
360 // Unmap extra memory reserved before and after the desired block. | 361 // Unmap extra memory reserved before and after the desired block. |
361 size_t bytes_prior = static_cast<size_t>(aligned_base - base); | 362 if (aligned_base != base) { |
362 if (bytes_prior > 0) { | 363 size_t prefix_size = static_cast<size_t>(aligned_base - base); |
363 munmap(base, bytes_prior); | 364 OS::Free(base, prefix_size); |
364 } | 365 request_size -= prefix_size; |
365 if (static_cast<size_t>(aligned_base - base) < request_size - size) { | |
366 munmap(aligned_base + size, request_size - size - bytes_prior); | |
367 } | 366 } |
368 | 367 |
| 368 size_t aligned_size = RoundUp(size, OS::AllocateAlignment()); |
| 369 ASSERT_LE(aligned_size, request_size); |
| 370 |
| 371 if (aligned_size != request_size) { |
| 372 size_t suffix_size = request_size - aligned_size; |
| 373 OS::Free(aligned_base + aligned_size, suffix_size); |
| 374 request_size -= suffix_size; |
| 375 } |
| 376 |
| 377 ASSERT(aligned_size == request_size); |
| 378 |
369 address_ = static_cast<void*>(aligned_base); | 379 address_ = static_cast<void*>(aligned_base); |
370 size_ = size; | 380 size_ = aligned_size; |
371 } | 381 } |
372 | 382 |
373 | 383 |
374 VirtualMemory::~VirtualMemory() { | 384 VirtualMemory::~VirtualMemory() { |
375 if (IsReserved()) { | 385 if (IsReserved()) { |
376 bool result = ReleaseRegion(address(), size()); | 386 bool result = ReleaseRegion(address(), size()); |
377 ASSERT(result); | 387 ASSERT(result); |
378 USE(result); | 388 USE(result); |
379 } | 389 } |
380 } | 390 } |
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
869 | 879 |
870 | 880 |
871 void Sampler::Stop() { | 881 void Sampler::Stop() { |
872 ASSERT(IsActive()); | 882 ASSERT(IsActive()); |
873 SamplerThread::RemoveActiveSampler(this); | 883 SamplerThread::RemoveActiveSampler(this); |
874 SetActive(false); | 884 SetActive(false); |
875 } | 885 } |
876 | 886 |
877 | 887 |
878 } } // namespace v8::internal | 888 } } // namespace v8::internal |
OLD | NEW |