summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorjar@chromium.org <jar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-07 23:46:40 +0000
committerjar@chromium.org <jar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-07 23:46:40 +0000
commitcd75a5001fe541b418a0f46efd8c25201a4015e2 (patch)
treefaa72462076478ff4436167ce6a07a805ddacf17 /base
parent6452f1c0627a15a097472da9ea848408ebe080a8 (diff)
downloadchromium_src-cd75a5001fe541b418a0f46efd8c25201a4015e2.zip
chromium_src-cd75a5001fe541b418a0f46efd8c25201a4015e2.tar.gz
chromium_src-cd75a5001fe541b418a0f46efd8c25201a4015e2.tar.bz2
Revert 77207 - Support mixed allocation in browser vs subprocesses
Continue to support selection of a browser allocator selection via the environment variable CHROME_ALLOCATOR, and also add CHROME_ALLOCATOR_2 that can select the allocator to use in subprocesses, such as a renderer. Temporarilly set the browser default to the default windows heap allocator, and the subprocess allocator to TCMalloc to help detect memory corruption in a cannary for a few days. Add minor cleanup (removing reserved word "override" etc.). r=mbelshe bug=74901 Review URL: http://codereview.chromium.org/6623059 TBR=jar@chromium.org Review URL: http://codereview.chromium.org/6623069 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@77208 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/allocator/allocator.gyp1
-rw-r--r--base/allocator/allocator_shim.cc75
-rw-r--r--base/allocator/allocator_shim.h20
3 files changed, 18 insertions, 78 deletions
diff --git a/base/allocator/allocator.gyp b/base/allocator/allocator.gyp
index 065cbf4..9eb96de 100644
--- a/base/allocator/allocator.gyp
+++ b/base/allocator/allocator.gyp
@@ -176,7 +176,6 @@
'<(jemalloc_dir)/rb.h',
'allocator_shim.cc',
- 'allocator_shim.h',
'generic_allocators.cc',
'win_allocator.cc',
],
diff --git a/base/allocator/allocator_shim.cc b/base/allocator/allocator_shim.cc
index f11164c..3935737 100644
--- a/base/allocator/allocator_shim.cc
+++ b/base/allocator/allocator_shim.cc
@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "base/allocator/allocator_shim.h"
-
#include <config.h>
// When defined, different heap allocators can be used via an environment
@@ -31,24 +29,13 @@ static int new_mode = 0;
typedef enum {
TCMALLOC, // TCMalloc is the default allocator.
- JEMALLOC, // JEMalloc.
- WINHEAP, // Windows Heap (standard Windows allocator).
- WINLFH, // Windows LFH Heap.
+ JEMALLOC, // JEMalloc
+ WINDEFAULT, // Windows Heap
+ WINLFH, // Windows LFH Heap
} Allocator;
-// This is the default allocator. This value can be changed at startup by
-// specifying environment variables shown below it.
-// See SetupSubprocessAllocator() to specify a default secondary (subprocess)
-// allocator.
-// TODO(jar): Switch to using TCMALLOC for the renderer as well.
-static Allocator allocator = WINHEAP;
-
-// The names of the environment variables that can optionally control the
-// selection of the allocator. The primary may be used to control overall
-// allocator selection, and the secondary can be used to specify an allocator
-// to use in sub-processes.
-static const char* primary_name = "CHROME_ALLOCATOR";
-static const char* secondary_name = "CHROME_ALLOCATOR_2";
+// This is the default allocator.
+static Allocator allocator = TCMALLOC;
// We include tcmalloc and the win_allocator to get as much inlining as
// possible.
@@ -114,7 +101,7 @@ void* malloc(size_t size) __THROW {
case JEMALLOC:
ptr = je_malloc(size);
break;
- case WINHEAP:
+ case WINDEFAULT:
case WINLFH:
ptr = win_heap_malloc(size);
break;
@@ -142,7 +129,7 @@ void free(void* p) __THROW {
case JEMALLOC:
je_free(p);
return;
- case WINHEAP:
+ case WINDEFAULT:
case WINLFH:
win_heap_free(p);
return;
@@ -166,7 +153,7 @@ void* realloc(void* ptr, size_t size) __THROW {
case JEMALLOC:
new_ptr = je_realloc(ptr, size);
break;
- case WINHEAP:
+ case WINDEFAULT:
case WINLFH:
new_ptr = win_heap_realloc(ptr, size);
break;
@@ -198,7 +185,7 @@ void malloc_stats(void) __THROW {
case JEMALLOC:
// No stats.
return;
- case WINHEAP:
+ case WINDEFAULT:
case WINLFH:
// No stats.
return;
@@ -214,7 +201,7 @@ extern "C" size_t _msize(void* p) {
switch (allocator) {
case JEMALLOC:
return je_msize(p);
- case WINHEAP:
+ case WINDEFAULT:
case WINLFH:
return win_heap_msize(p);
}
@@ -230,22 +217,22 @@ extern "C" intptr_t _get_heap_handle() {
// The CRT heap initialization stub.
extern "C" int _heap_init() {
#ifdef ENABLE_DYNAMIC_ALLOCATOR_SWITCHING
- const char* environment_value = GetenvBeforeMain(primary_name);
- if (environment_value) {
- if (!stricmp(environment_value, "jemalloc"))
+ const char* override = GetenvBeforeMain("CHROME_ALLOCATOR");
+ if (override) {
+ if (!stricmp(override, "jemalloc"))
allocator = JEMALLOC;
- else if (!stricmp(environment_value, "winheap"))
- allocator = WINHEAP;
- else if (!stricmp(environment_value, "winlfh"))
+ else if (!stricmp(override, "winheap"))
+ allocator = WINDEFAULT;
+ else if (!stricmp(override, "winlfh"))
allocator = WINLFH;
- else if (!stricmp(environment_value, "tcmalloc"))
+ else if (!stricmp(override, "tcmalloc"))
allocator = TCMALLOC;
}
switch (allocator) {
case JEMALLOC:
return je_malloc_init_hard() ? 0 : 1;
- case WINHEAP:
+ case WINDEFAULT:
return win_heap_init(false) ? 1 : 0;
case WINLFH:
return win_heap_init(true) ? 1 : 0;
@@ -277,29 +264,3 @@ extern "C" void* _crtheap = reinterpret_cast<void*>(1);
#include "generic_allocators.cc"
} // extern C
-
-namespace base {
-namespace allocator {
-
-void SetupSubprocessAllocator() {
-#ifdef ENABLE_DYNAMIC_ALLOCATOR_SWITCHING
- size_t primary_length = 0;
- getenv_s(&primary_length, NULL, 0, primary_name);
-
- size_t secondary_length = 0;
- char buffer[20];
- getenv_s(&secondary_length, buffer, sizeof(buffer), secondary_name);
- DCHECK_GT(sizeof(buffer), secondary_length);
- buffer[sizeof(buffer) - 1] = '\0';
-
- if (secondary_length || !primary_length) {
- char* secondary_value = secondary_length ? buffer : "TCMALLOC";
- // Force renderer (or other subprocesses) to use secondary_value.
- int ret_val = _putenv_s(primary_name, secondary_value);
- CHECK_EQ(0, ret_val);
- }
-#endif // ENABLE_DYNAMIC_ALLOCATOR_SWITCHING
-}
-
-} // namespace base.
-} // namespace allocator.
diff --git a/base/allocator/allocator_shim.h b/base/allocator/allocator_shim.h
deleted file mode 100644
index 342710f..0000000
--- a/base/allocator/allocator_shim.h
+++ /dev/null
@@ -1,20 +0,0 @@
-// Copyright (c) 2011 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.
-
-#ifndef BASE_ALLOCATOR_ALLOCATOR_SHIM_H_
-#define BASE_ALLOCATOR_ALLOCATOR_SHIM_H_
-
-namespace base {
-namespace allocator {
-
-// Resets the environment variable CHROME_ALLOCATOR to specify the choice to
-// be used by subprocesses. Priority is given to the current value of
-// CHROME_ALLOCATOR_2 (if specified), then CHROME_ALLOCATOR (if specified), and
-// then a default value (typically set to TCMALLOC).
-void SetupSubprocessAllocator();
-
-} // namespace base.
-} // namespace allocator.
-
-#endif // BASE_ALLOCATOR_ALLOCATOR_SHIM_H_