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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/platform.h ('k') | src/platform-macos.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/platform-linux.cc
diff --git a/src/platform-linux.cc b/src/platform-linux.cc
index c64a94c7fcc1e46182c4ce85bfdce517b10703ce..2d6160e473f12c89f67693e44759622b9a538bc6 100644
--- a/src/platform-linux.cc
+++ b/src/platform-linux.cc
@@ -601,6 +601,7 @@ int OS::StackWalk(Vector<OS::StackFrame> frames) {
static const int kMmapFd = -1;
static const int kMmapFdOffset = 0;
+VirtualMemory::VirtualMemory() : address_(NULL), size_(0) { }
VirtualMemory::VirtualMemory(size_t size) {
address_ = ReserveRegion(size);
@@ -608,9 +609,41 @@ VirtualMemory::VirtualMemory(size_t size) {
}
+VirtualMemory::VirtualMemory(size_t size, size_t alignment)
+ : address_(NULL), size_(0) {
+ ASSERT(IsAligned(alignment, static_cast<intptr_t>(OS::AllocateAlignment())));
+ size_t request_size = RoundUp(size + alignment,
+ static_cast<intptr_t>(OS::AllocateAlignment()));
+ void* reservation = mmap(GetRandomMmapAddr(),
+ request_size,
+ PROT_NONE,
+ MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE,
+ kMmapFd,
+ kMmapFdOffset);
+ if (reservation == MAP_FAILED) return;
+ Address base = static_cast<Address>(reservation);
+ Address aligned_base = RoundUp(base, alignment);
+ ASSERT(base <= aligned_base);
+
+ // Unmap extra memory reserved before and after the desired block.
+ size_t bytes_prior = static_cast<size_t>(aligned_base - base);
+ if (bytes_prior > 0) {
+ munmap(base, bytes_prior);
+ }
+ if (static_cast<size_t>(aligned_base - base) < request_size - size) {
+ munmap(aligned_base + size, request_size - size - bytes_prior);
+ }
+
+ address_ = static_cast<void*>(aligned_base);
+ size_ = size;
+}
+
+
VirtualMemory::~VirtualMemory() {
if (IsReserved()) {
- if (ReleaseRegion(address(), size())) address_ = NULL;
+ bool result = ReleaseRegion(address(), size());
+ ASSERT(result);
+ USE(result);
}
}
@@ -620,6 +653,12 @@ bool VirtualMemory::IsReserved() {
}
+void VirtualMemory::Reset() {
+ address_ = NULL;
+ size_ = 0;
+}
+
+
bool VirtualMemory::Commit(void* address, size_t size, bool is_executable) {
return CommitRegion(address, size, is_executable);
}
« 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