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

Unified Diff: content/app/content_main_runner.cc

Issue 1469843002: Remove dependency on allocator from 'content' targets (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@unify_allocator1_2
Patch Set: Fix build Created 5 years, 1 month 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: content/app/content_main_runner.cc
diff --git a/content/app/content_main_runner.cc b/content/app/content_main_runner.cc
index 6df81377d6061dad505e9b56f326d89540a0b2cc..7522ebb103db92bf6e65b66c670ed4ee7220a100 100644
--- a/content/app/content_main_runner.cc
+++ b/content/app/content_main_runner.cc
@@ -58,10 +58,6 @@
#include "gin/v8_initializer.h"
#endif
-#if defined(USE_TCMALLOC)
-#include "third_party/tcmalloc/chromium/src/gperftools/malloc_extension.h"
-#endif
-
#if !defined(OS_IOS)
#include "content/app/mojo/mojo_init.h"
#include "content/browser/gpu/gpu_process_host.h"
@@ -111,11 +107,18 @@
#include "crypto/nss_util.h"
#endif
-#if !defined(OS_MACOSX) && defined(USE_TCMALLOC)
-extern "C" {
-int tc_set_new_mode(int mode);
+#if defined(USE_TCMALLOC)
+namespace {
+
+// This method translates the tcmalloc bytes allocated function to now function
+// for alternate time source.
+unsigned int TimeSourceNowFunction() {
+ return static_cast<unsigned int>(
+ base::allocator::GetBytesAllocatedOnCurrentThread());
}
-#endif
+
+} // namespace
+#endif // defined(USE_TCMALLOC)
namespace content {
extern int GpuMain(const content::MainFunctionParams&);
@@ -413,35 +416,6 @@ class ContentMainRunnerImpl : public ContentMainRunner {
Shutdown();
}
-#if defined(USE_TCMALLOC)
- static bool GetAllocatorWasteSizeThunk(size_t* size) {
- size_t heap_size, allocated_bytes, unmapped_bytes;
- MallocExtension* ext = MallocExtension::instance();
- if (ext->GetNumericProperty("generic.heap_size", &heap_size) &&
- ext->GetNumericProperty("generic.current_allocated_bytes",
- &allocated_bytes) &&
- ext->GetNumericProperty("tcmalloc.pageheap_unmapped_bytes",
- &unmapped_bytes)) {
- *size = heap_size - allocated_bytes - unmapped_bytes;
- return true;
- }
- DCHECK(false);
- return false;
- }
-
- static void GetStatsThunk(char* buffer, int buffer_length) {
- MallocExtension::instance()->GetStats(buffer, buffer_length);
- }
-
- static bool GetNumericPropertyThunk(const char* name, size_t* value) {
- return MallocExtension::instance()->GetNumericProperty(name, value);
- }
-
- static void ReleaseFreeMemoryThunk() {
- MallocExtension::instance()->ReleaseFreeMemory();
- }
-#endif
-
int Initialize(const ContentMainParams& params) override {
ui_task_ = params.ui_task;
@@ -460,22 +434,14 @@ class ContentMainRunnerImpl : public ContentMainRunner {
TRACE_EVENT0("startup,benchmark", "ContentMainRunnerImpl::Initialize");
#endif // OS_ANDROID
- // NOTE(willchan): One might ask why these TCMalloc-related calls are done
- // here rather than in process_util_linux.cc with the definition of
- // EnableTerminationOnOutOfMemory(). That's because base shouldn't have a
- // dependency on TCMalloc. Really, we ought to have our allocator shim code
- // implement this EnableTerminationOnOutOfMemory() function. Whateverz.
- // This works for now.
#if !defined(OS_MACOSX) && defined(USE_TCMALLOC)
- // For tcmalloc, we need to tell it to behave like new.
- tc_set_new_mode(1);
-
- // On windows, we've already set these thunks up in _heap_init()
- base::allocator::SetGetAllocatorWasteSizeFunction(
- GetAllocatorWasteSizeThunk);
- base::allocator::SetGetStatsFunction(GetStatsThunk);
- base::allocator::SetGetNumericPropertyFunction(GetNumericPropertyThunk);
- base::allocator::SetReleaseFreeMemoryFunction(ReleaseFreeMemoryThunk);
+ // Allocator initialization is needed for tcmalloc to set up the allocator
+ // extension callbacks. This needs to happen before any threads are created
+ // and any of the extension methods is used. To be able to call this method
+ // implies that the executable target should link in the allocator shim
+ // implementation. Note that the content target does not decide the
+ // allocator.
+ base::allocator::InitializeAllocator();
// Provide optional hook for monitoring allocation quantities on a
// per-thread basis. Only set the hook if the environment indicates this
@@ -484,8 +450,7 @@ class ContentMainRunnerImpl : public ContentMainRunner {
if (profiling &&
(atoi(profiling) == tracked_objects::TIME_SOURCE_TYPE_TCMALLOC)) {
tracked_objects::SetAlternateTimeSource(
- MallocExtension::GetBytesAllocatedOnCurrentThread,
- tracked_objects::TIME_SOURCE_TYPE_TCMALLOC);
+ TimeSourceNowFunction, tracked_objects::TIME_SOURCE_TYPE_TCMALLOC);
}
#endif // !OS_MACOSX && USE_TCMALLOC

Powered by Google App Engine
This is Rietveld 408576698