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

Unified Diff: src/platform-win32.cc

Issue 7865025: Move aligned allocation to the platform files. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/gc
Patch Set: Match the VirtualFree return type and arguments. 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-macos.cc ('k') | src/spaces.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/platform-win32.cc
diff --git a/src/platform-win32.cc b/src/platform-win32.cc
index c441b96ce48fedfab29d49a4f0c8d0d157e4bf57..0a26f5e93a8a3c02ae31a55f78bd8912e82b5e59 100644
--- a/src/platform-win32.cc
+++ b/src/platform-win32.cc
@@ -1,4 +1,4 @@
-// Copyright 2006-2008 the V8 project authors. All rights reserved.
+// Copyright 2011 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
@@ -1503,6 +1503,35 @@ void* VirtualMemory::ReserveRegion(size_t size) {
}
+void* VirtualMemory::ReserveAlignedRegion(size_t size, size_t alignment) {
+ ASSERT(IsAligned(alignment, static_cast<intptr_t>(OS::AllocateAlignment())));
+ size_t request_size = RoundUp(size + alignment,
+ static_cast<intptr_t>(OS::AllocateAlignment()));
+ Address result;
+ do {
+ void* reservation =
+ VirtualAlloc(NULL, request_size, MEM_RESERVE, PAGE_NOACCESS);
+ // If we can't allocate at all, give up.
+ if (reservation == NULL) return NULL;
+ Address base = static_cast<Address>(reservation);
+ Address aligned_base = RoundUp(base, alignment);
+ ASSERT(base <= aligned_base);
+ // Try to reallocate part of the original allocation by first freeing it,
+ // and then allocating with a specific target address in the middle of
+ // the freed area.
+ // This can fail in the rare case that someone else in the same process
+ // allocates the same memory between the VirtualFree and VirtualAlloc
+ // calls. In that case, just try again.
+ VirtualFree(reservation, 0, MEM_RELEASE);
+ reservation = VirtualAlloc(aligned_base, size, MEM_RESERVE, PAGE_NOACCESS);
+ result = static_cast<Address>(reservation);
+ ASSERT(result == NULL || result == aligned_base);
+ } while (result == NULL);
Vyacheslav Egorov (Chromium) 2011/09/12 13:42:48 this looks too fragile and might go into infinite
Lasse Reichstein 2011/09/12 19:18:02 This was an attempt to avoid finding a place to st
+
+ return static_cast<void*>(result);
+}
+
+
bool VirtualMemory::CommitRegion(void* base, size_t size, bool is_executable) {
int prot = is_executable ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE;
if (NULL == VirtualAlloc(base, size, MEM_COMMIT, prot)) {
@@ -1515,12 +1544,12 @@ bool VirtualMemory::CommitRegion(void* base, size_t size, bool is_executable) {
bool VirtualMemory::UncommitRegion(void* base, size_t size) {
- return VirtualFree(base, size, MEM_DECOMMIT) != false;
+ return VirtualFree(base, size, MEM_DECOMMIT) != 0;
}
bool VirtualMemory::ReleaseRegion(void* base, size_t size) {
- return VirtualFree(base, size, MEM_DECOMMIT) != false;
+ return VirtualFree(base, 0, MEM_DECOMMIT) != 0;
Vyacheslav Egorov (Chromium) 2011/09/12 13:42:48 Should not it become MEM_RELEASE?
Lasse Reichstein 2011/09/12 19:18:02 Absolutely! It should have been that all along! Th
}
« no previous file with comments | « src/platform-macos.cc ('k') | src/spaces.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698