OLD | NEW |
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 "content/public/app/content_main_runner.h" | 5 #include "content/public/app/content_main_runner.h" |
6 | 6 |
7 #include <stdlib.h> | 7 #include <stdlib.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 &allocated_bytes) && | 422 &allocated_bytes) && |
423 ext->GetNumericProperty("tcmalloc.pageheap_unmapped_bytes", | 423 ext->GetNumericProperty("tcmalloc.pageheap_unmapped_bytes", |
424 &unmapped_bytes)) { | 424 &unmapped_bytes)) { |
425 *size = heap_size - allocated_bytes - unmapped_bytes; | 425 *size = heap_size - allocated_bytes - unmapped_bytes; |
426 return true; | 426 return true; |
427 } | 427 } |
428 DCHECK(false); | 428 DCHECK(false); |
429 return false; | 429 return false; |
430 } | 430 } |
431 | 431 |
432 static void GetStatsThunk(char* buffer, int buffer_length) { | |
433 MallocExtension::instance()->GetStats(buffer, buffer_length); | |
434 } | |
435 | |
436 static bool GetNumericPropertyThunk(const char* name, size_t* value) { | 432 static bool GetNumericPropertyThunk(const char* name, size_t* value) { |
437 return MallocExtension::instance()->GetNumericProperty(name, value); | 433 return MallocExtension::instance()->GetNumericProperty(name, value); |
438 } | 434 } |
439 | 435 |
440 static void ReleaseFreeMemoryThunk() { | 436 static void ReleaseFreeMemoryThunk() { |
441 MallocExtension::instance()->ReleaseFreeMemory(); | 437 MallocExtension::instance()->ReleaseFreeMemory(); |
442 } | 438 } |
443 #endif | 439 #endif |
444 | 440 |
445 int Initialize(const ContentMainParams& params) override { | 441 int Initialize(const ContentMainParams& params) override { |
(...skipping 20 matching lines...) Expand all Loading... |
466 // dependency on TCMalloc. Really, we ought to have our allocator shim code | 462 // dependency on TCMalloc. Really, we ought to have our allocator shim code |
467 // implement this EnableTerminationOnOutOfMemory() function. Whateverz. | 463 // implement this EnableTerminationOnOutOfMemory() function. Whateverz. |
468 // This works for now. | 464 // This works for now. |
469 #if !defined(OS_MACOSX) && defined(USE_TCMALLOC) | 465 #if !defined(OS_MACOSX) && defined(USE_TCMALLOC) |
470 // For tcmalloc, we need to tell it to behave like new. | 466 // For tcmalloc, we need to tell it to behave like new. |
471 tc_set_new_mode(1); | 467 tc_set_new_mode(1); |
472 | 468 |
473 // On windows, we've already set these thunks up in _heap_init() | 469 // On windows, we've already set these thunks up in _heap_init() |
474 base::allocator::SetGetAllocatorWasteSizeFunction( | 470 base::allocator::SetGetAllocatorWasteSizeFunction( |
475 GetAllocatorWasteSizeThunk); | 471 GetAllocatorWasteSizeThunk); |
476 base::allocator::SetGetStatsFunction(GetStatsThunk); | |
477 base::allocator::SetGetNumericPropertyFunction(GetNumericPropertyThunk); | 472 base::allocator::SetGetNumericPropertyFunction(GetNumericPropertyThunk); |
478 base::allocator::SetReleaseFreeMemoryFunction(ReleaseFreeMemoryThunk); | 473 base::allocator::SetReleaseFreeMemoryFunction(ReleaseFreeMemoryThunk); |
479 | 474 |
480 // Provide optional hook for monitoring allocation quantities on a | 475 // Provide optional hook for monitoring allocation quantities on a |
481 // per-thread basis. Only set the hook if the environment indicates this | 476 // per-thread basis. Only set the hook if the environment indicates this |
482 // needs to be enabled. | 477 // needs to be enabled. |
483 const char* profiling = getenv(tracked_objects::kAlternateProfilerTime); | 478 const char* profiling = getenv(tracked_objects::kAlternateProfilerTime); |
484 if (profiling && | 479 if (profiling && |
485 (atoi(profiling) == tracked_objects::TIME_SOURCE_TYPE_TCMALLOC)) { | 480 (atoi(profiling) == tracked_objects::TIME_SOURCE_TYPE_TCMALLOC)) { |
486 tracked_objects::SetAlternateTimeSource( | 481 tracked_objects::SetAlternateTimeSource( |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
867 | 862 |
868 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl); | 863 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl); |
869 }; | 864 }; |
870 | 865 |
871 // static | 866 // static |
872 ContentMainRunner* ContentMainRunner::Create() { | 867 ContentMainRunner* ContentMainRunner::Create() { |
873 return new ContentMainRunnerImpl(); | 868 return new ContentMainRunnerImpl(); |
874 } | 869 } |
875 | 870 |
876 } // namespace content | 871 } // namespace content |
OLD | NEW |