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

Unified Diff: third_party/tcmalloc/chromium/src/windows/port.cc

Issue 9320005: [NOT TO COMMIT!] Replace third_party/tcmalloc/chromium with tcmalloc r136 (the latest). (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Created 8 years, 11 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
Index: third_party/tcmalloc/chromium/src/windows/port.cc
diff --git a/third_party/tcmalloc/chromium/src/windows/port.cc b/third_party/tcmalloc/chromium/src/windows/port.cc
index ec01fd60c9583a74249fe5faf459aca03995758e..e68de163d3ef91229ed305af8148d394710223d4 100644
--- a/third_party/tcmalloc/chromium/src/windows/port.cc
+++ b/third_party/tcmalloc/chromium/src/windows/port.cc
@@ -61,7 +61,7 @@ int getpagesize() {
return pagesize;
}
-extern "C" PERFTOOLS_DLL_DECL void* __sbrk(std::ptrdiff_t increment) {
+extern "C" PERFTOOLS_DLL_DECL void* __sbrk(ptrdiff_t increment) {
LOG(FATAL, "Windows doesn't implement sbrk!\n");
return NULL;
}
@@ -149,13 +149,12 @@ static void NTAPI on_tls_callback(HINSTANCE h, DWORD dwReason, PVOID pv) {
#ifdef _MSC_VER
-// extern "C" suppresses C++ name mangling so we know the symbol names for the
-// linker /INCLUDE:symbol pragmas above.
+// extern "C" suppresses C++ name mangling so we know the symbol names
+// for the linker /INCLUDE:symbol pragmas above.
extern "C" {
// This tells the linker to run these functions.
#pragma data_seg(push, old_seg)
- // Use CRT$XLY instead of CRT$XLB to ensure we're called LATER in sequence.
-#pragma data_seg(".CRT$XLY")
+#pragma data_seg(".CRT$XLB")
void (NTAPI *p_thread_callback_tcmalloc)(
HINSTANCE h, DWORD dwReason, PVOID pv) = on_tls_callback;
#pragma data_seg(".CRT$XTU")
@@ -219,10 +218,6 @@ extern "C" int perftools_pthread_once(pthread_once_t *once_control,
// -----------------------------------------------------------------------
// These functions replace system-alloc.cc
-// The current system allocator. Because we don't link with system-alloc.cc,
-// we need to define our own.
-SysAllocator* sys_alloc = NULL;
-
// This is mostly like MmapSysAllocator::Alloc, except it does these weird
// munmap's in the middle of the page, which is forbidden in windows.
extern void* TCMalloc_SystemAlloc(size_t size, size_t *actual_size,
@@ -232,102 +227,35 @@ extern void* TCMalloc_SystemAlloc(size_t size, size_t *actual_size,
if (alignment < pagesize) alignment = pagesize;
size = ((size + alignment - 1) / alignment) * alignment;
- // Report the total number of bytes the OS actually delivered. This might be
- // greater than |size| because of alignment concerns. The full size is
- // necessary so that adjacent spans can be coalesced.
- // TODO(antonm): proper processing of alignments
- // in actual_size and decommitting.
+ // Safest is to make actual_size same as input-size.
if (actual_size) {
*actual_size = size;
}
- // We currently do not support alignments larger than the pagesize or
- // alignments that are not multiples of the pagesize after being floored.
- // If this ability is needed it can be done by the caller (assuming it knows
- // the page size).
- assert(alignment <= pagesize);
+ // Ask for extra memory if alignment > pagesize
+ size_t extra = 0;
+ if (alignment > pagesize) {
+ extra = alignment - pagesize;
+ }
- void* result = VirtualAlloc(0, size,
+ void* result = VirtualAlloc(0, size + extra,
MEM_COMMIT|MEM_RESERVE, PAGE_READWRITE);
if (result == NULL)
return NULL;
- // If the result is not aligned memory fragmentation will result which can
- // lead to pathological memory use.
- assert((reinterpret_cast<uintptr_t>(result) & (alignment - 1)) == 0);
-
- return result;
-}
-
-size_t TCMalloc_SystemAddGuard(void* start, size_t size) {
- static size_t pagesize = 0;
- if (pagesize == 0) {
- SYSTEM_INFO system_info;
- GetSystemInfo(&system_info);
- pagesize = system_info.dwPageSize;
- }
-
- // We know that TCMalloc_SystemAlloc will give us a correct page alignment
- // regardless, so we can just assert to detect erroneous callers.
- assert(reinterpret_cast<size_t>(start) % pagesize == 0);
-
- // Add a guard page to catch metadata corruption. We're using the
- // PAGE_GUARD flag rather than NO_ACCESS because we want the unique
- // exception in crash reports.
- DWORD permissions = 0;
- if (size > pagesize &&
- VirtualProtect(start, pagesize, PAGE_READONLY | PAGE_GUARD,
- &permissions)) {
- return pagesize;
+ // Adjust the return memory so it is aligned
+ uintptr_t ptr = reinterpret_cast<uintptr_t>(result);
+ size_t adjust = 0;
+ if ((ptr & (alignment - 1)) != 0) {
+ adjust = alignment - (ptr & (alignment - 1));
}
- return 0;
+ ptr += adjust;
+ return reinterpret_cast<void*>(ptr);
}
void TCMalloc_SystemRelease(void* start, size_t length) {
- if (VirtualFree(start, length, MEM_DECOMMIT))
- return;
-
- // The decommit may fail if the memory region consists of allocations
- // from more than one call to VirtualAlloc. In this case, fall back to
- // using VirtualQuery to retrieve the allocation boundaries and decommit
- // them each individually.
-
- char* ptr = static_cast<char*>(start);
- char* end = ptr + length;
- MEMORY_BASIC_INFORMATION info;
- while (ptr < end) {
- size_t resultSize = VirtualQuery(ptr, &info, sizeof(info));
- assert(resultSize == sizeof(info));
- size_t decommitSize = std::min<size_t>(info.RegionSize, end - ptr);
- BOOL success = VirtualFree(ptr, decommitSize, MEM_DECOMMIT);
- assert(success == TRUE);
- ptr += decommitSize;
- }
-}
-
-void TCMalloc_SystemCommit(void* start, size_t length) {
- if (VirtualAlloc(start, length, MEM_COMMIT, PAGE_READWRITE) == start)
- return;
-
- // The commit may fail if the memory region consists of allocations
- // from more than one call to VirtualAlloc. In this case, fall back to
- // using VirtualQuery to retrieve the allocation boundaries and commit them
- // each individually.
-
- char* ptr = static_cast<char*>(start);
- char* end = ptr + length;
- MEMORY_BASIC_INFORMATION info;
- while (ptr < end) {
- size_t resultSize = VirtualQuery(ptr, &info, sizeof(info));
- assert(resultSize == sizeof(info));
-
- size_t commitSize = std::min<size_t>(info.RegionSize, end - ptr);
- void* newAddress = VirtualAlloc(ptr, commitSize, MEM_COMMIT,
- PAGE_READWRITE);
- assert(newAddress == ptr);
- ptr += commitSize;
- }
+ // TODO(csilvers): should I be calling VirtualFree here?
}
bool RegisterSystemAllocator(SysAllocator *allocator, int priority) {
@@ -338,6 +266,9 @@ void DumpSystemAllocatorStats(TCMalloc_Printer* printer) {
// We don't dump stats on windows, right now
}
+// The current system allocator
+SysAllocator* sys_alloc = NULL;
+
// -----------------------------------------------------------------------
// These functions rework existing functions of the same name in the
« no previous file with comments | « third_party/tcmalloc/chromium/src/windows/port.h ('k') | third_party/tcmalloc/chromium/src/windows/preamble_patcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698