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

Side by Side Diff: third_party/tcmalloc/port.cc

Issue 235003: Actually on Windows VirtualAlloc'ated address might have bigger alignment tha... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 11 years, 2 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* Copyright (c) 2007, Google Inc. 1 /* Copyright (c) 2007, Google Inc.
2 * All rights reserved. 2 * All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 va_end(ap); 64 va_end(ap);
65 return r; 65 return r;
66 } 66 }
67 #endif 67 #endif
68 68
69 int getpagesize() { 69 int getpagesize() {
70 static int pagesize = 0; 70 static int pagesize = 0;
71 if (pagesize == 0) { 71 if (pagesize == 0) {
72 SYSTEM_INFO system_info; 72 SYSTEM_INFO system_info;
73 GetSystemInfo(&system_info); 73 GetSystemInfo(&system_info);
74 pagesize = system_info.dwPageSize; 74 pagesize = std::max(system_info.dwPageSize,
75 system_info.dwAllocationGranularity);
75 } 76 }
76 return pagesize; 77 return pagesize;
77 } 78 }
78 79
79 extern "C" PERFTOOLS_DLL_DECL void* __sbrk(ptrdiff_t increment) { 80 extern "C" PERFTOOLS_DLL_DECL void* __sbrk(ptrdiff_t increment) {
80 LOG(FATAL, "Windows doesn't implement sbrk!\n"); 81 LOG(FATAL, "Windows doesn't implement sbrk!\n");
81 return NULL; 82 return NULL;
82 } 83 }
83 84
84 // ----------------------------------------------------------------------- 85 // -----------------------------------------------------------------------
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 182
182 // ----------------------------------------------------------------------- 183 // -----------------------------------------------------------------------
183 // These functions replace system-alloc.cc 184 // These functions replace system-alloc.cc
184 185
185 static SpinLock alloc_lock(SpinLock::LINKER_INITIALIZED); 186 static SpinLock alloc_lock(SpinLock::LINKER_INITIALIZED);
186 187
187 // This is mostly like MmapSysAllocator::Alloc, except it does these weird 188 // This is mostly like MmapSysAllocator::Alloc, except it does these weird
188 // munmap's in the middle of the page, which is forbidden in windows. 189 // munmap's in the middle of the page, which is forbidden in windows.
189 extern void* TCMalloc_SystemAlloc(size_t size, size_t *actual_size, 190 extern void* TCMalloc_SystemAlloc(size_t size, size_t *actual_size,
190 size_t alignment) { 191 size_t alignment) {
191 // Safest is to make actual_size same as input-size.
192 if (actual_size) {
193 *actual_size = size;
194 }
195
196 SpinLockHolder sh(&alloc_lock); 192 SpinLockHolder sh(&alloc_lock);
197 // Align on the pagesize boundary 193 // Align on the pagesize boundary
198 const int pagesize = getpagesize(); 194 const int pagesize = getpagesize();
199 if (alignment < pagesize) alignment = pagesize; 195 if (alignment < pagesize) alignment = pagesize;
200 size = ((size + alignment - 1) / alignment) * alignment; 196 size = ((size + alignment - 1) / alignment) * alignment;
201 197
198 // Safest is to make actual_size same as input-size.
199 // TODO(antonm): proper processing of alignments
200 // in actual_size and decommitting.
201 if (actual_size) {
202 *actual_size = size;
203 }
204
202 // Ask for extra memory if alignment > pagesize 205 // Ask for extra memory if alignment > pagesize
203 size_t extra = 0; 206 size_t extra = 0;
204 if (alignment > pagesize) { 207 if (alignment > pagesize) {
205 extra = alignment - pagesize; 208 extra = alignment - pagesize;
206 } 209 }
207 210
208 void* result = VirtualAlloc(0, size + extra, 211 void* result = VirtualAlloc(0, size + extra,
209 MEM_COMMIT|MEM_RESERVE, PAGE_READWRITE); 212 MEM_COMMIT|MEM_RESERVE, PAGE_READWRITE);
210 if (result == NULL) 213 if (result == NULL)
211 return NULL; 214 return NULL;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 if ((strlen(fname) >= prefix_length) && 295 if ((strlen(fname) >= prefix_length) &&
293 (memcmp(fname, prefix, prefix_length) == 0)) { 296 (memcmp(fname, prefix, prefix_length) == 0)) {
294 RAW_VLOG(0, "Removing old heap profile %s\n", fname); 297 RAW_VLOG(0, "Removing old heap profile %s\n", fname);
295 // TODO(csilvers): we really need to unlink dirname + fname 298 // TODO(csilvers): we really need to unlink dirname + fname
296 _unlink(fname); 299 _unlink(fname);
297 } 300 }
298 } while (FindNextFileA(hFind, &found) != FALSE); // A is for Ansi 301 } while (FindNextFileA(hFind, &found) != FALSE); // A is for Ansi
299 FindClose(hFind); 302 FindClose(hFind);
300 } 303 }
301 } 304 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698