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

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

Issue 5987005: Refactor MemoryAllocator to allow big normal pages (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/gc
Patch Set: Created 10 years 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.h ('k') | src/spaces.h » ('j') | src/spaces.h » ('J')
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 2006-2008 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 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 239
240 size_t OS::AllocateAlignment() { 240 size_t OS::AllocateAlignment() {
241 return sysconf(_SC_PAGESIZE); 241 return sysconf(_SC_PAGESIZE);
242 } 242 }
243 243
244 244
245 void* OS::Allocate(const size_t requested, 245 void* OS::Allocate(const size_t requested,
246 size_t* allocated, 246 size_t* allocated,
247 bool is_executable) { 247 bool is_executable) {
248 // TODO(805): Port randomization of allocated executable memory to Linux. 248 // TODO(805): Port randomization of allocated executable memory to Linux.
249 const size_t msize = RoundUp(requested, sysconf(_SC_PAGESIZE)); 249 const size_t msize = RoundUp(requested, AllocateAlignment());
250 int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0); 250 int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0);
251 void* mbase = mmap(NULL, msize, prot, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); 251 void* mbase = mmap(NULL, msize, prot, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
252 if (mbase == MAP_FAILED) { 252 if (mbase == MAP_FAILED) {
253 LOG(StringEvent("OS::Allocate", "mmap failed")); 253 LOG(StringEvent("OS::Allocate", "mmap failed"));
254 return NULL; 254 return NULL;
255 } 255 }
256 *allocated = msize; 256 *allocated = msize;
257 UpdateAllocatedSpaceLimits(mbase, msize); 257 UpdateAllocatedSpaceLimits(mbase, msize);
258 return mbase; 258 return mbase;
259 } 259 }
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 #endif // ndef __GLIBC__ 462 #endif // ndef __GLIBC__
463 } 463 }
464 464
465 465
466 // Constants used for mmap. 466 // Constants used for mmap.
467 static const int kMmapFd = -1; 467 static const int kMmapFd = -1;
468 static const int kMmapFdOffset = 0; 468 static const int kMmapFdOffset = 0;
469 469
470 470
471 VirtualMemory::VirtualMemory(size_t size) { 471 VirtualMemory::VirtualMemory(size_t size) {
472 address_ = mmap(NULL, size, PROT_NONE, 472 address_ = ReserveRegion(size);
473 MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE,
474 kMmapFd, kMmapFdOffset);
475 size_ = size; 473 size_ = size;
476 } 474 }
477 475
478 476
479 VirtualMemory::~VirtualMemory() { 477 VirtualMemory::~VirtualMemory() {
480 if (IsReserved()) { 478 if (IsReserved()) {
481 if (0 == munmap(address(), size())) address_ = MAP_FAILED; 479 if (0 == munmap(address(), size())) address_ = NULL;
482 } 480 }
483 } 481 }
484 482
485 483
486 bool VirtualMemory::IsReserved() { 484 bool VirtualMemory::IsReserved() {
487 return address_ != MAP_FAILED; 485 return address_ != NULL;
488 } 486 }
489 487
490 488
491 bool VirtualMemory::Commit(void* address, size_t size, bool is_executable) { 489 bool VirtualMemory::Commit(void* address, size_t size, bool is_executable) {
490 return CommitRegion(address, size, is_executable);
491 }
492
493
494 bool VirtualMemory::Uncommit(void* address, size_t size) {
495 return UncommitRegion(address, size);
496 }
497
498
499 void* VirtualMemory::ReserveRegion(size_t size) {
500 void* result = mmap(NULL,
501 size,
502 PROT_NONE,
503 MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE,
504 kMmapFd,
505 kMmapFdOffset);
506
507 if (result == MAP_FAILED) return NULL;
508
509 return result;
510 }
511
512
513 bool VirtualMemory::CommitRegion(void* base, size_t size, bool is_executable) {
492 int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0); 514 int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0);
493 if (MAP_FAILED == mmap(address, size, prot, 515 if (MAP_FAILED == mmap(base,
516 size,
517 prot,
494 MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, 518 MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED,
495 kMmapFd, kMmapFdOffset)) { 519 kMmapFd,
520 kMmapFdOffset)) {
496 return false; 521 return false;
497 } 522 }
498 523
499 UpdateAllocatedSpaceLimits(address, size); 524 UpdateAllocatedSpaceLimits(base, size);
500 return true; 525 return true;
501 } 526 }
502 527
503 528
504 bool VirtualMemory::Uncommit(void* address, size_t size) { 529 bool VirtualMemory::UncommitRegion(void* base, size_t size) {
505 return mmap(address, size, PROT_NONE, 530 return mmap(base,
531 size,
532 PROT_NONE,
506 MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE | MAP_FIXED, 533 MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE | MAP_FIXED,
507 kMmapFd, kMmapFdOffset) != MAP_FAILED; 534 kMmapFd,
535 kMmapFdOffset) != MAP_FAILED;
508 } 536 }
509 537
510 538
539 bool VirtualMemory::ReleaseRegion(void* base, size_t size) {
540 return munmap(base, size) == 0;
541 }
542
543
511 class ThreadHandle::PlatformData : public Malloced { 544 class ThreadHandle::PlatformData : public Malloced {
512 public: 545 public:
513 explicit PlatformData(ThreadHandle::Kind kind) { 546 explicit PlatformData(ThreadHandle::Kind kind) {
514 Initialize(kind); 547 Initialize(kind);
515 } 548 }
516 549
517 void Initialize(ThreadHandle::Kind kind) { 550 void Initialize(ThreadHandle::Kind kind) {
518 switch (kind) { 551 switch (kind) {
519 case ThreadHandle::SELF: thread_ = pthread_self(); break; 552 case ThreadHandle::SELF: thread_ = pthread_self(); break;
520 case ThreadHandle::INVALID: thread_ = kNoThread; break; 553 case ThreadHandle::INVALID: thread_ = kNoThread; break;
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
944 } 977 }
945 978
946 // This sampler is no longer the active sampler. 979 // This sampler is no longer the active sampler.
947 active_sampler_ = NULL; 980 active_sampler_ = NULL;
948 } 981 }
949 982
950 983
951 #endif // ENABLE_LOGGING_AND_PROFILING 984 #endif // ENABLE_LOGGING_AND_PROFILING
952 985
953 } } // namespace v8::internal 986 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/platform.h ('k') | src/spaces.h » ('j') | src/spaces.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698