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

Side by Side Diff: base/allocator/allocator_shim.cc

Issue 55333002: Make possible to check memory allocations inside chromium (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix component and windows build Created 6 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/allocator/allocator_shim.h" 5 #include "base/allocator/allocator_shim.h"
6 6
7 #include <config.h> 7 #include <config.h>
8 #include "base/allocator/allocator_extension_thunks.h" 8 #include "base/allocator/allocator_extension_thunks.h"
9 #include "base/process/memory.h"
9 #include "base/profiler/alternate_timer.h" 10 #include "base/profiler/alternate_timer.h"
10 #include "base/sysinfo.h" 11 #include "base/sysinfo.h"
11 #include "jemalloc.h" 12 #include "jemalloc.h"
12 13
13 // This shim make it possible to use different allocators via an environment 14 // This shim make it possible to use different allocators via an environment
14 // variable set before running the program. This may reduce the 15 // variable set before running the program. This may reduce the
15 // amount of inlining that we get with malloc/free/etc. 16 // amount of inlining that we get with malloc/free/etc.
16 17
17 // TODO(mbelshe): Ensure that all calls to tcmalloc have the proper call depth 18 // TODO(mbelshe): Ensure that all calls to tcmalloc have the proper call depth
18 // from the "user code" so that debugging tools (HeapChecker) can work. 19 // from the "user code" so that debugging tools (HeapChecker) can work.
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 } 374 }
374 } 375 }
375 376
376 #endif // WIN32 377 #endif // WIN32
377 378
378 #include "generic_allocators.cc" 379 #include "generic_allocators.cc"
379 380
380 } // extern C 381 } // extern C
381 382
382 namespace base { 383 namespace base {
384
385 bool UncheckedMalloc(size_t size, void** result) {
386 switch (::allocator) {
387 case JEMALLOC:
388 *result = je_malloc(size);
389 break;
390 case WINHEAP:
391 case WINLFH:
392 *result = win_heap_malloc(size);
393 break;
394 case TCMALLOC:
395 *result = do_malloc(size);
396 break;
397 }
398
399 return *result;
400 }
401
383 namespace allocator { 402 namespace allocator {
384 403
385 void SetupSubprocessAllocator() { 404 void SetupSubprocessAllocator() {
386 size_t primary_length = 0; 405 size_t primary_length = 0;
387 getenv_s(&primary_length, NULL, 0, primary_name); 406 getenv_s(&primary_length, NULL, 0, primary_name);
388 407
389 size_t secondary_length = 0; 408 size_t secondary_length = 0;
390 char buffer[20]; 409 char buffer[20];
391 getenv_s(&secondary_length, buffer, sizeof(buffer), secondary_name); 410 getenv_s(&secondary_length, buffer, sizeof(buffer), secondary_name);
392 DCHECK_GT(sizeof(buffer), secondary_length); 411 DCHECK_GT(sizeof(buffer), secondary_length);
(...skipping 20 matching lines...) Expand all
413 void TCMallocDoFreeForTest(void* ptr) { 432 void TCMallocDoFreeForTest(void* ptr) {
414 do_free(ptr); 433 do_free(ptr);
415 } 434 }
416 435
417 size_t ExcludeSpaceForMarkForTest(size_t size) { 436 size_t ExcludeSpaceForMarkForTest(size_t size) {
418 return ExcludeSpaceForMark(size); 437 return ExcludeSpaceForMark(size);
419 } 438 }
420 439
421 } // namespace allocator. 440 } // namespace allocator.
422 } // namespace base. 441 } // namespace base.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698