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

Side by Side Diff: src/platform-macos.cc

Issue 8139027: Version 3.6.5 (Closed) Base URL: http://v8.googlecode.com/svn/trunk/
Patch Set: '' Created 9 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 | « src/platform-linux.cc ('k') | src/platform-openbsd.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 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 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 // Make sure line termination is in place. 327 // Make sure line termination is in place.
328 frames[i].text[kStackWalkMaxTextLen - 1] = '\0'; 328 frames[i].text[kStackWalkMaxTextLen - 1] = '\0';
329 } 329 }
330 330
331 free(symbols); 331 free(symbols);
332 332
333 return frames_count; 333 return frames_count;
334 } 334 }
335 335
336 336
337 VirtualMemory::VirtualMemory() : address_(NULL), size_(0) { }
337 338
338 339
339 VirtualMemory::VirtualMemory(size_t size) { 340 VirtualMemory::VirtualMemory(size_t size)
340 address_ = mmap(NULL, size, PROT_NONE, 341 : address_(ReserveRegion(size)), size_(size) { }
341 MAP_PRIVATE | MAP_ANON | MAP_NORESERVE, 342
342 kMmapFd, kMmapFdOffset); 343
343 size_ = size; 344 VirtualMemory::VirtualMemory(size_t size, size_t alignment)
345 : address_(NULL), size_(0) {
346 ASSERT(IsAligned(alignment, static_cast<intptr_t>(OS::AllocateAlignment())));
347 size_t request_size = RoundUp(size + alignment,
348 static_cast<intptr_t>(OS::AllocateAlignment()));
349 void* reservation = mmap(NULL,
350 request_size,
351 PROT_NONE,
352 MAP_PRIVATE | MAP_ANON | MAP_NORESERVE,
353 kMmapFd,
354 kMmapFdOffset);
355 if (reservation == MAP_FAILED) return;
356
357 Address base = static_cast<Address>(reservation);
358 Address aligned_base = RoundUp(base, alignment);
359 ASSERT_LE(base, aligned_base);
360
361 // Unmap extra memory reserved before and after the desired block.
362 if (aligned_base != base) {
363 size_t prefix_size = static_cast<size_t>(aligned_base - base);
364 OS::Free(base, prefix_size);
365 request_size -= prefix_size;
366 }
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
379 address_ = static_cast<void*>(aligned_base);
380 size_ = aligned_size;
344 } 381 }
345 382
346 383
347 VirtualMemory::~VirtualMemory() { 384 VirtualMemory::~VirtualMemory() {
348 if (IsReserved()) { 385 if (IsReserved()) {
349 if (0 == munmap(address(), size())) address_ = MAP_FAILED; 386 bool result = ReleaseRegion(address(), size());
387 ASSERT(result);
388 USE(result);
350 } 389 }
351 } 390 }
352 391
353 392
393 void VirtualMemory::Reset() {
394 address_ = NULL;
395 size_ = 0;
396 }
397
398
399 void* VirtualMemory::ReserveRegion(size_t size) {
400 void* result = mmap(NULL,
401 size,
402 PROT_NONE,
403 MAP_PRIVATE | MAP_ANON | MAP_NORESERVE,
404 kMmapFd,
405 kMmapFdOffset);
406
407 if (result == MAP_FAILED) return NULL;
408
409 return result;
410 }
411
412
354 bool VirtualMemory::IsReserved() { 413 bool VirtualMemory::IsReserved() {
355 return address_ != MAP_FAILED; 414 return address_ != NULL;
356 } 415 }
357 416
358 417
359 bool VirtualMemory::Commit(void* address, size_t size, bool is_executable) { 418 bool VirtualMemory::Commit(void* address, size_t size, bool is_executable) {
419 return CommitRegion(address, size, is_executable);
420 }
421
422
423 bool VirtualMemory::CommitRegion(void* address,
424 size_t size,
425 bool is_executable) {
360 int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0); 426 int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0);
361 if (MAP_FAILED == mmap(address, size, prot, 427 if (MAP_FAILED == mmap(address,
428 size,
429 prot,
362 MAP_PRIVATE | MAP_ANON | MAP_FIXED, 430 MAP_PRIVATE | MAP_ANON | MAP_FIXED,
363 kMmapFd, kMmapFdOffset)) { 431 kMmapFd,
432 kMmapFdOffset)) {
364 return false; 433 return false;
365 } 434 }
366 435
367 UpdateAllocatedSpaceLimits(address, size); 436 UpdateAllocatedSpaceLimits(address, size);
368 return true; 437 return true;
369 } 438 }
370 439
371 440
372 bool VirtualMemory::Uncommit(void* address, size_t size) { 441 bool VirtualMemory::Uncommit(void* address, size_t size) {
373 return mmap(address, size, PROT_NONE, 442 return UncommitRegion(address, size);
443 }
444
445
446 bool VirtualMemory::UncommitRegion(void* address, size_t size) {
447 return mmap(address,
448 size,
449 PROT_NONE,
374 MAP_PRIVATE | MAP_ANON | MAP_NORESERVE | MAP_FIXED, 450 MAP_PRIVATE | MAP_ANON | MAP_NORESERVE | MAP_FIXED,
375 kMmapFd, kMmapFdOffset) != MAP_FAILED; 451 kMmapFd,
452 kMmapFdOffset) != MAP_FAILED;
453 }
454
455
456 bool VirtualMemory::ReleaseRegion(void* address, size_t size) {
457 return munmap(address, size) == 0;
376 } 458 }
377 459
378 460
379 class Thread::PlatformData : public Malloced { 461 class Thread::PlatformData : public Malloced {
380 public: 462 public:
381 PlatformData() : thread_(kNoThread) {} 463 PlatformData() : thread_(kNoThread) {}
382 pthread_t thread_; // Thread handle for pthread. 464 pthread_t thread_; // Thread handle for pthread.
383 }; 465 };
384 466
385 Thread::Thread(const Options& options) 467 Thread::Thread(const Options& options)
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 879
798 880
799 void Sampler::Stop() { 881 void Sampler::Stop() {
800 ASSERT(IsActive()); 882 ASSERT(IsActive());
801 SamplerThread::RemoveActiveSampler(this); 883 SamplerThread::RemoveActiveSampler(this);
802 SetActive(false); 884 SetActive(false);
803 } 885 }
804 886
805 887
806 } } // namespace v8::internal 888 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/platform-linux.cc ('k') | src/platform-openbsd.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698