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

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: Missing renames added to patch. 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
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 address_ = reservation;
641 size_ = request_size;
642 }
643
644
611 VirtualMemory::~VirtualMemory() { 645 VirtualMemory::~VirtualMemory() {
612 if (IsReserved()) { 646 if (IsReserved()) {
613 if (ReleaseRegion(address(), size())) address_ = NULL; 647 bool result = ReleaseRegion(address(), size());
648 ASSERT(result);
649 USE(result);
614 } 650 }
615 } 651 }
616 652
617 653
618 bool VirtualMemory::IsReserved() { 654 bool VirtualMemory::IsReserved() {
619 return address_ != NULL; 655 return address_ != NULL;
620 } 656 }
621 657
622 658
659 void VirtualMemory::Reset() {
660 address_ = NULL;
661 size_ = 0;
662 }
663
664
623 bool VirtualMemory::Commit(void* address, size_t size, bool is_executable) { 665 bool VirtualMemory::Commit(void* address, size_t size, bool is_executable) {
624 return CommitRegion(address, size, is_executable); 666 return CommitRegion(address, size, is_executable);
625 } 667 }
626 668
627 669
628 bool VirtualMemory::Uncommit(void* address, size_t size) { 670 bool VirtualMemory::Uncommit(void* address, size_t size) {
629 return UncommitRegion(address, size); 671 return UncommitRegion(address, size);
630 } 672 }
631 673
632 674
(...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after
1173 1215
1174 1216
1175 void Sampler::Stop() { 1217 void Sampler::Stop() {
1176 ASSERT(IsActive()); 1218 ASSERT(IsActive());
1177 SignalSender::RemoveActiveSampler(this); 1219 SignalSender::RemoveActiveSampler(this);
1178 SetActive(false); 1220 SetActive(false);
1179 } 1221 }
1180 1222
1181 1223
1182 } } // namespace v8::internal 1224 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/platform.h ('k') | src/platform-macos.cc » ('j') | src/spaces.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698