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

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

Issue 14162004: Unified the structure of VirtualMemory implementations across platforms a bit. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 8 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-nullos.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 401
402 VirtualMemory::~VirtualMemory() { 402 VirtualMemory::~VirtualMemory() {
403 if (IsReserved()) { 403 if (IsReserved()) {
404 bool result = ReleaseRegion(address(), size()); 404 bool result = ReleaseRegion(address(), size());
405 ASSERT(result); 405 ASSERT(result);
406 USE(result); 406 USE(result);
407 } 407 }
408 } 408 }
409 409
410 410
411 bool VirtualMemory::IsReserved() {
412 return address_ != NULL;
413 }
414
415
411 void VirtualMemory::Reset() { 416 void VirtualMemory::Reset() {
412 address_ = NULL; 417 address_ = NULL;
413 size_ = 0; 418 size_ = 0;
414 } 419 }
415 420
416 421
422 bool VirtualMemory::Commit(void* address, size_t size, bool is_executable) {
423 return CommitRegion(address, size, is_executable);
424 }
425
426
427 bool VirtualMemory::Uncommit(void* address, size_t size) {
428 return UncommitRegion(address, size);
429 }
430
431
432 bool VirtualMemory::Guard(void* address) {
433 OS::Guard(address, OS::CommitPageSize());
434 return true;
435 }
436
437
417 void* VirtualMemory::ReserveRegion(size_t size) { 438 void* VirtualMemory::ReserveRegion(size_t size) {
418 void* result = mmap(OS::GetRandomMmapAddr(), 439 void* result = mmap(OS::GetRandomMmapAddr(),
419 size, 440 size,
420 PROT_NONE, 441 PROT_NONE,
421 MAP_PRIVATE | MAP_ANON | MAP_NORESERVE, 442 MAP_PRIVATE | MAP_ANON | MAP_NORESERVE,
422 kMmapFd, 443 kMmapFd,
423 kMmapFdOffset); 444 kMmapFdOffset);
424 445
425 if (result == MAP_FAILED) return NULL; 446 if (result == MAP_FAILED) return NULL;
426 447
427 return result; 448 return result;
428 } 449 }
429 450
430 451
431 bool VirtualMemory::IsReserved() {
432 return address_ != NULL;
433 }
434
435
436 bool VirtualMemory::Commit(void* address, size_t size, bool is_executable) {
437 return CommitRegion(address, size, is_executable);
438 }
439
440
441 bool VirtualMemory::Guard(void* address) {
442 OS::Guard(address, OS::CommitPageSize());
443 return true;
444 }
445
446
447 bool VirtualMemory::CommitRegion(void* address, 452 bool VirtualMemory::CommitRegion(void* address,
448 size_t size, 453 size_t size,
449 bool is_executable) { 454 bool is_executable) {
450 int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0); 455 int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0);
451 if (MAP_FAILED == mmap(address, 456 if (MAP_FAILED == mmap(address,
452 size, 457 size,
453 prot, 458 prot,
454 MAP_PRIVATE | MAP_ANON | MAP_FIXED, 459 MAP_PRIVATE | MAP_ANON | MAP_FIXED,
455 kMmapFd, 460 kMmapFd,
456 kMmapFdOffset)) { 461 kMmapFdOffset)) {
457 return false; 462 return false;
458 } 463 }
459 464
460 UpdateAllocatedSpaceLimits(address, size); 465 UpdateAllocatedSpaceLimits(address, size);
461 return true; 466 return true;
462 } 467 }
463 468
464 469
465 bool VirtualMemory::Uncommit(void* address, size_t size) {
466 return UncommitRegion(address, size);
467 }
468
469
470 bool VirtualMemory::UncommitRegion(void* address, size_t size) { 470 bool VirtualMemory::UncommitRegion(void* address, size_t size) {
471 return mmap(address, 471 return mmap(address,
472 size, 472 size,
473 PROT_NONE, 473 PROT_NONE,
474 MAP_PRIVATE | MAP_ANON | MAP_NORESERVE | MAP_FIXED, 474 MAP_PRIVATE | MAP_ANON | MAP_NORESERVE | MAP_FIXED,
475 kMmapFd, 475 kMmapFd,
476 kMmapFdOffset) != MAP_FAILED; 476 kMmapFdOffset) != MAP_FAILED;
477 } 477 }
478 478
479 479
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
944 944
945 945
946 void Sampler::Stop() { 946 void Sampler::Stop() {
947 ASSERT(IsActive()); 947 ASSERT(IsActive());
948 SamplerThread::RemoveActiveSampler(this); 948 SamplerThread::RemoveActiveSampler(this);
949 SetActive(false); 949 SetActive(false);
950 } 950 }
951 951
952 952
953 } } // namespace v8::internal 953 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/platform-linux.cc ('k') | src/platform-nullos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698