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

Unified Diff: base/allocator/tcmalloc_extension.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: base/allocator/tcmalloc_extension.cc
diff --git a/base/allocator/tcmalloc_extension.cc b/base/allocator/tcmalloc_extension.cc
new file mode 100644
index 0000000000000000000000000000000000000000..80e37c3e96f3aba957e241c64c46ef6b1996595f
--- /dev/null
+++ b/base/allocator/tcmalloc_extension.cc
@@ -0,0 +1,72 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/allocator/allocator_extension_thunks.h"
+
+#include "third_party/tcmalloc/chromium/src/gperftools/heap-profiler.h"
+#include "third_party/tcmalloc/chromium/src/gperftools/malloc_extension.h"
+
+extern "C" {
+int tc_set_new_mode(int mode);
+}
+
+namespace {
+
+bool GetAllocatorWasteSizeHelper(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;
+ }
+ return false;
+}
+
+void GetStatsHelper(char* buffer, int buffer_length) {
+ MallocExtension::instance()->GetStats(buffer, buffer_length);
+}
+
+bool GetNumericPropertyHelper(const char* name, size_t* value) {
+ return MallocExtension::instance()->GetNumericProperty(name, value);
+}
+
+void ReleaseFreeMemoryHelper() {
+ MallocExtension::instance()->ReleaseFreeMemory();
+}
+
+unsigned int GetBytesAllocatedOnCurrentThreadHelper() {
+ return MallocExtension::instance()->GetBytesAllocatedOnCurrentThread();
+}
+
+bool IsHeapProfilerRunningHelper() {
+ return IsHeapProfilerRunning();
+}
+
+} // namespace
+
+namespace base {
+namespace allocator {
+
+__attribute__((visibility("default"))) thunks::AllocatorExtensionFunctions
+InitializeAllocatorWeak();
+
+thunks::AllocatorExtensionFunctions InitializeAllocatorWeak() {
+ // For tcmalloc, we need to tell it to behave like new.
+ tc_set_new_mode(1);
+
+ thunks::AllocatorExtensionFunctions allocator_funtions = {
+ GetAllocatorWasteSizeHelper, GetStatsHelper,
+ ReleaseFreeMemoryHelper, GetBytesAllocatedOnCurrentThreadHelper,
+ GetNumericPropertyHelper, ::HeapProfilerWithPseudoStackStart,
+ ::HeapProfilerStop, ::GetHeapProfile,
+ ::HeapProfilerDump, IsHeapProfilerRunningHelper};
+ return allocator_funtions;
+}
+
+} // namespace allocator
+} // namespace base

Powered by Google App Engine
This is Rietveld 408576698