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

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

Issue 7945009: Merge experimental/gc branch to the bleeding_edge. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 9 years, 3 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-win32.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 315 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
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 Address base = static_cast<Address>(reservation);
357 Address aligned_base = RoundUp(base, alignment);
358 ASSERT(base <= aligned_base);
359
360 // Unmap extra memory reserved before and after the desired block.
361 size_t bytes_prior = static_cast<size_t>(aligned_base - base);
362 if (bytes_prior > 0) {
363 munmap(base, bytes_prior);
364 }
365 if (static_cast<size_t>(aligned_base - base) < request_size - size) {
366 munmap(aligned_base + size, request_size - size - bytes_prior);
367 }
368
369 address_ = static_cast<void*>(aligned_base);
343 size_ = size; 370 size_ = size;
344 } 371 }
345 372
346 373
347 VirtualMemory::~VirtualMemory() { 374 VirtualMemory::~VirtualMemory() {
348 if (IsReserved()) { 375 if (IsReserved()) {
349 if (0 == munmap(address(), size())) address_ = MAP_FAILED; 376 bool result = ReleaseRegion(address(), size());
377 ASSERT(result);
378 USE(result);
350 } 379 }
351 } 380 }
352 381
353 382
383 void VirtualMemory::Reset() {
384 address_ = NULL;
385 size_ = 0;
386 }
387
388
389 void* VirtualMemory::ReserveRegion(size_t size) {
390 void* result = mmap(NULL,
391 size,
392 PROT_NONE,
393 MAP_PRIVATE | MAP_ANON | MAP_NORESERVE,
394 kMmapFd,
395 kMmapFdOffset);
396
397 if (result == MAP_FAILED) return NULL;
398
399 return result;
400 }
401
402
354 bool VirtualMemory::IsReserved() { 403 bool VirtualMemory::IsReserved() {
355 return address_ != MAP_FAILED; 404 return address_ != NULL;
356 } 405 }
357 406
358 407
359 bool VirtualMemory::Commit(void* address, size_t size, bool is_executable) { 408 bool VirtualMemory::Commit(void* address, size_t size, bool is_executable) {
409 return CommitRegion(address, size, is_executable);
410 }
411
412
413 bool VirtualMemory::CommitRegion(void* address,
414 size_t size,
415 bool is_executable) {
360 int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0); 416 int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0);
361 if (MAP_FAILED == mmap(address, size, prot, 417 if (MAP_FAILED == mmap(address,
418 size,
419 prot,
362 MAP_PRIVATE | MAP_ANON | MAP_FIXED, 420 MAP_PRIVATE | MAP_ANON | MAP_FIXED,
363 kMmapFd, kMmapFdOffset)) { 421 kMmapFd,
422 kMmapFdOffset)) {
364 return false; 423 return false;
365 } 424 }
366 425
367 UpdateAllocatedSpaceLimits(address, size); 426 UpdateAllocatedSpaceLimits(address, size);
368 return true; 427 return true;
369 } 428 }
370 429
371 430
372 bool VirtualMemory::Uncommit(void* address, size_t size) { 431 bool VirtualMemory::Uncommit(void* address, size_t size) {
373 return mmap(address, size, PROT_NONE, 432 return UncommitRegion(address, size);
433 }
434
435
436 bool VirtualMemory::UncommitRegion(void* address, size_t size) {
437 return mmap(address,
438 size,
439 PROT_NONE,
374 MAP_PRIVATE | MAP_ANON | MAP_NORESERVE | MAP_FIXED, 440 MAP_PRIVATE | MAP_ANON | MAP_NORESERVE | MAP_FIXED,
375 kMmapFd, kMmapFdOffset) != MAP_FAILED; 441 kMmapFd,
442 kMmapFdOffset) != MAP_FAILED;
443 }
444
445
446 bool VirtualMemory::ReleaseRegion(void* address, size_t size) {
447 return munmap(address, size) == 0;
376 } 448 }
377 449
378 450
379 class Thread::PlatformData : public Malloced { 451 class Thread::PlatformData : public Malloced {
380 public: 452 public:
381 PlatformData() : thread_(kNoThread) {} 453 PlatformData() : thread_(kNoThread) {}
382 pthread_t thread_; // Thread handle for pthread. 454 pthread_t thread_; // Thread handle for pthread.
383 }; 455 };
384 456
385 Thread::Thread(const Options& options) 457 Thread::Thread(const Options& options)
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 869
798 870
799 void Sampler::Stop() { 871 void Sampler::Stop() {
800 ASSERT(IsActive()); 872 ASSERT(IsActive());
801 SamplerThread::RemoveActiveSampler(this); 873 SamplerThread::RemoveActiveSampler(this);
802 SetActive(false); 874 SetActive(false);
803 } 875 }
804 876
805 877
806 } } // namespace v8::internal 878 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/platform-linux.cc ('k') | src/platform-win32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698