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

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

Issue 7865025: Move aligned allocation to the platform files. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/gc
Patch Set: Removed leftover debug code. 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.h ('k') | src/platform-macos.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 2011 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
(...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 #else // ndef __GLIBC__ 594 #else // ndef __GLIBC__
595 return 0; 595 return 0;
596 #endif // ndef __GLIBC__ 596 #endif // ndef __GLIBC__
597 } 597 }
598 598
599 599
600 // Constants used for mmap. 600 // Constants used for mmap.
601 static const int kMmapFd = -1; 601 static const int kMmapFd = -1;
602 static const int kMmapFdOffset = 0; 602 static const int kMmapFdOffset = 0;
603 603
604 VirtualMemory::VirtualMemory() : address_(NULL), size_(0) { }
604 605
605 VirtualMemory::VirtualMemory(size_t size) { 606 VirtualMemory::VirtualMemory(size_t size) {
606 address_ = ReserveRegion(size); 607 address_ = ReserveRegion(size);
607 size_ = size; 608 size_ = size;
608 } 609 }
609 610
610 611
612 VirtualMemory::VirtualMemory(size_t size, size_t alignment)
613 : address_(NULL), size_(0) {
614 ASSERT(IsAligned(alignment, static_cast<intptr_t>(OS::AllocateAlignment())));
615 size_t request_size = RoundUp(size + alignment,
616 static_cast<intptr_t>(OS::AllocateAlignment()));
617 void* reservation = mmap(GetRandomMmapAddr(),
618 request_size,
619 PROT_NONE,
620 MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE,
621 kMmapFd,
622 kMmapFdOffset);
623 if (reservation == MAP_FAILED) return;
624 Address base = static_cast<Address>(reservation);
625 Address aligned_base = RoundUp(base, alignment);
626 ASSERT(base <= aligned_base);
627
628 // Unmap extra memory reserved before and after the desired block.
629 size_t bytes_prior = static_cast<size_t>(aligned_base - base);
630 if (bytes_prior > 0) {
631 munmap(base, bytes_prior);
632 }
633 if (static_cast<size_t>(aligned_base - base) < request_size - size) {
634 munmap(aligned_base + size, request_size - size - bytes_prior);
635 }
636
637 address_ = static_cast<void*>(aligned_base);
638 size_ = size;
639 }
640
641
611 VirtualMemory::~VirtualMemory() { 642 VirtualMemory::~VirtualMemory() {
612 if (IsReserved()) { 643 if (IsReserved()) {
613 if (ReleaseRegion(address(), size())) address_ = NULL; 644 bool result = ReleaseRegion(address(), size());
645 ASSERT(result);
646 USE(result);
614 } 647 }
615 } 648 }
616 649
617 650
618 bool VirtualMemory::IsReserved() { 651 bool VirtualMemory::IsReserved() {
619 return address_ != NULL; 652 return address_ != NULL;
620 } 653 }
621 654
622 655
656 void VirtualMemory::Reset() {
657 address_ = NULL;
658 size_ = 0;
659 }
660
661
623 bool VirtualMemory::Commit(void* address, size_t size, bool is_executable) { 662 bool VirtualMemory::Commit(void* address, size_t size, bool is_executable) {
624 return CommitRegion(address, size, is_executable); 663 return CommitRegion(address, size, is_executable);
625 } 664 }
626 665
627 666
628 bool VirtualMemory::Uncommit(void* address, size_t size) { 667 bool VirtualMemory::Uncommit(void* address, size_t size) {
629 return UncommitRegion(address, size); 668 return UncommitRegion(address, size);
630 } 669 }
631 670
632 671
(...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after
1173 1212
1174 1213
1175 void Sampler::Stop() { 1214 void Sampler::Stop() {
1176 ASSERT(IsActive()); 1215 ASSERT(IsActive());
1177 SignalSender::RemoveActiveSampler(this); 1216 SignalSender::RemoveActiveSampler(this);
1178 SetActive(false); 1217 SetActive(false);
1179 } 1218 }
1180 1219
1181 1220
1182 } } // namespace v8::internal 1221 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/platform.h ('k') | src/platform-macos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698