Commit 453035e2 authored by pcc's avatar pcc Committed by Commit bot

tcmalloc_unittest: Use malloc and free directly, instead of tc_malloc and tc_free.

tcmalloc defines malloc and free as wrappers (or aliases) for tc_malloc
and tc_free, so we can test tcmalloc by using malloc and free directly
instead of tc_malloc and tc_free. This fixes the test in component
builds, where tc_malloc and tc_free are defined in a separate DSO with
hidden visibility (due to https://codereview.chromium.org/2019183002/),
and so will not be visible to tests.

Some compilers (e.g. clang) will specifically recognize and optimize
away calls to malloc and free, which would break these tests, as
they are testing specific behavior of the allocator. Address this by
marking the wrappers for malloc and free as NOINLINE.

BUG=
TBR=primiano@chromium.org

Review-Url: https://codereview.chromium.org/2028183002
Cr-Commit-Position: refs/heads/master@{#397204}
parent 9a4f5513
...@@ -5,28 +5,27 @@ ...@@ -5,28 +5,27 @@
#include <stddef.h> #include <stddef.h>
#include <stdio.h> #include <stdio.h>
#include "base/compiler_specific.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/process/process_metrics.h" #include "base/process/process_metrics.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#if defined(USE_TCMALLOC) #if defined(USE_TCMALLOC)
extern "C" {
void* tc_malloc(size_t size);
void tc_free(void*);
}
namespace { namespace {
using std::min; using std::min;
#ifdef NDEBUG #ifdef NDEBUG
void* TCMallocDoMallocForTest(size_t size) { // We wrap malloc and free in noinline functions to ensure that we test the real
return tc_malloc(size); // implementation of the allocator. Otherwise, the compiler may specifically
// recognize the calls to malloc and free in our tests and optimize them away.
NOINLINE void* TCMallocDoMallocForTest(size_t size) {
return malloc(size);
} }
void TCMallocDoFreeForTest(void* ptr) { NOINLINE void TCMallocDoFreeForTest(void* ptr) {
tc_free(ptr); free(ptr);
} }
#endif #endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment