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

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: Working on win32 too 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') | src/platform-win32.cc » ('J')
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 00852baeebf66cd3be61a51ee10ade941bc98603..a16b70e788c1b4b7450834e4cab11f2cb3c0de71 100644
--- a/src/platform-linux.cc
+++ b/src/platform-linux.cc
@@ -607,6 +607,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);
@@ -614,9 +615,44 @@ 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;
+
+ address_ = reservation;
+ size_ = request_size;
+}
+
+
VirtualMemory::~VirtualMemory() {
if (IsReserved()) {
- if (ReleaseRegion(address(), size())) address_ = NULL;
+ bool result = ReleaseRegion(address(), size());
+ ASSERT(result);
+ USE(result);
}
}
@@ -626,6 +662,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') | src/platform-win32.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698