OLD | NEW |
1 // Copyright 2006-2008 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 |
11 // with the distribution. | 11 // with the distribution. |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 MAP_PRIVATE | MAP_ANON | MAP_NORESERVE, | 347 MAP_PRIVATE | MAP_ANON | MAP_NORESERVE, |
348 kMmapFd, | 348 kMmapFd, |
349 kMmapFdOffset); | 349 kMmapFdOffset); |
350 | 350 |
351 if (result == MAP_FAILED) return NULL; | 351 if (result == MAP_FAILED) return NULL; |
352 | 352 |
353 return result; | 353 return result; |
354 } | 354 } |
355 | 355 |
356 | 356 |
| 357 void* VirtualMemory::ReserveAlignedRegion(size_t size, size_t alignment) { |
| 358 ASSERT(IsAligned(alignment, static_cast<intptr_t>(OS::AllocateAlignment()))); |
| 359 size_t request_size = RoundUp(size + alignment, |
| 360 static_cast<intptr_t>(OS::AllocateAlignment())); |
| 361 void* reservation = mmap(GetRandomMmapAddr(), |
| 362 request_size, |
| 363 PROT_NONE, |
| 364 MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, |
| 365 kMmapFd, |
| 366 kMmapFdOffset); |
| 367 if (reservation == MAP_FAILED) return NULL; |
| 368 Address base = static_cast<Address>(reservation); |
| 369 Address aligned_base = RoundUp(base, alignment); |
| 370 ASSERT(base <= aligned_base); |
| 371 |
| 372 // Unmap extra memory reserved before and after the desired block. |
| 373 size_t bytes_prior = static_cast<size_t>(aligned_base - base); |
| 374 if (bytes_prior > 0) { |
| 375 munmap(base, bytes_prior); |
| 376 } |
| 377 if (static_cast<size_t>(aligned_base - base) < request_size - size) { |
| 378 munmap(aligned_base + size, request_size - size - bytes_prior); |
| 379 } |
| 380 |
| 381 return static_cast<void*>(aligned_base); |
| 382 } |
| 383 |
| 384 |
357 VirtualMemory::~VirtualMemory() { | 385 VirtualMemory::~VirtualMemory() { |
358 if (IsReserved()) { | 386 if (IsReserved()) { |
359 if (ReleaseRegion(address_, size_)) address_ = MAP_FAILED; | 387 if (ReleaseRegion(address_, size_)) address_ = MAP_FAILED; |
360 } | 388 } |
361 } | 389 } |
362 | 390 |
363 | 391 |
364 bool VirtualMemory::IsReserved() { | 392 bool VirtualMemory::IsReserved() { |
365 return address_ != MAP_FAILED; | 393 return address_ != MAP_FAILED; |
366 } | 394 } |
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
831 | 859 |
832 | 860 |
833 void Sampler::Stop() { | 861 void Sampler::Stop() { |
834 ASSERT(IsActive()); | 862 ASSERT(IsActive()); |
835 SamplerThread::RemoveActiveSampler(this); | 863 SamplerThread::RemoveActiveSampler(this); |
836 SetActive(false); | 864 SetActive(false); |
837 } | 865 } |
838 | 866 |
839 | 867 |
840 } } // namespace v8::internal | 868 } } // namespace v8::internal |
OLD | NEW |