Commit Graph

621 Commits

Author SHA1 Message Date
Gabriel Marin
3af509d4f9 benchmark: use angle brackets to include ucontext.h
Using quotes for a system header file fails a presubmit check in Chromium.
2018-08-05 16:15:12 -07:00
Gabriel Marin
0cdda6d7cc use utf-8 for special symbols
A few files in the windows port that haven't been touched in a long time,
use non-utf8 codes for special symbols, breaking a presubmit checker in
Chromium.
2018-08-05 16:15:12 -07:00
etienneb
c7a0cfda88 Fix potential missing nul character on resolved symbol names
The symbol name returned by SymFromName may not contains a NUL character
when the symbol name is exactly the size of the buffer. It believe this
may also happen when the symbol name is too long and truncated.

The original code is based on:
  https://msdn.microsoft.com/en-us/library/windows/desktop/ms680580(v=vs.85).aspx

A right implementation can be found here:
  https://cs.chromium.org/chromium/src/base/debug/stack_trace_win.cc?l=145&rcl=f4ecb9e37e9e2d59e32b8b96f23ac4a1e33b9552

As described here:
  https://msdn.microsoft.com/en-us/library/windows/desktop/ms680686(v=vs.85).aspx

  NameLen
    The length of the name, in characters, not including the null-terminating character.
  MaxNameLen
    The size of the Name buffer, in characters. If this member is 0, the Name member is not used.

This issue was causing the catapult symbolisation script to encode incorrect (random) characters into the symbol names.
See the example in the bug.

Original BUG=713741

Review-Url: https://codereview.chromium.org/2832643004
Cr-Commit-Position: refs/heads/master@{#466098}

BUG=724399,b:70905156

Change-Id: Ia6de4ddbd5c66a966b74ecec3fda5e853f36073b
2018-08-05 16:11:14 -07:00
Gabriel Marin
e42bfc8c06 tcmalloc: use relative addresses with the windows addr2line wrapper
Modifies the Windows addr2line wrapper to expect addresses relative to
DllBase to better simulate how addr2line works with modules in Linux.

Windows DLLs have a concept of "default load address" which hints to the OS
where to load the binary image after relocation. The dbghelp.dll
symbolization library will load the module at this location in the virtual
address space meaning the caller of these functions would need to be aware
of the base address. This makes things unnecessarily complex in the face of
ASLR and also diverges from the behavior of addr2line when used with linux-
style DSOs. This CL simply adds the module base address to the incoming
addresses, thereby making the input relative addresses for the module which
both is easier to use and lines up better with linux's addr2line behavior.

These changes were made originally as part of CL
https://codereview.chromium.org/2730473002.

BUG=724399,b:70905156

Change-Id: I0abe9e0c380e7e60ae29a11021bb805b31718d08
2018-08-05 16:11:14 -07:00
Gabriel Marin
d8f8d1cced tcmalloc: add long form flag '--exe' to specify the binary
This change was originally made as part of CL
https://codereview.chromium.org/2730473002

BUG=724399,b:70905156

Change-Id: I33ee28eac4dab6077cf162358cf4c10b41c0f6a2
2018-08-05 16:11:14 -07:00
Gabriel Marin
25c53aca12 tcmalloc: fixes for the windows addr2line wrapper
Fixes a few small format string bugs and makes the windows library
configuration #defines more friendly for chromium builds.

Based on original CL: https://codereview.chromium.org/2730473002

BUG=724399,b:70905156

Change-Id: If54c6cfc5c508744d2ee18f251677b2456acda72
2018-08-05 16:11:14 -07:00
Gabriel Marin
f02e28f348 Replace builtin_expect configure test with a direct GCC compiler check 2018-08-05 16:07:51 -07:00
obones
62c4eca6e7 Under x64, the PE loader looks for callbacks in constant sections
[alkondratenko@gmail.com: deleted some trailing whitespace]
2018-08-05 16:04:31 -07:00
Brian Silverman
0b588e7490 Fix uninitialized memory use in sampler_test
Sampler's documentation states the following:
  C++03 requires that types stored in TLS be POD.  As a result, you must
  initialize these members to {0, 0, false} before using this class!

However, the test code wasn't doing that. MemorySanitizer and
UndefinedBehaviorSanitizer both failed because of it.
2018-08-05 15:54:00 -07:00
Aliaksei Kandratsenka
51a5613f21 Upgrade MSVC projects to MSVC2015 2018-08-05 15:54:00 -07:00
Aliaksey Kandratsenka
44da4ce539 build with c++11 or later 2018-08-05 15:15:10 -07:00
HolyWu
f47a52ce85 Make _recalloc adhere to MS's definition 2018-05-21 16:08:27 +08:00
Junhao Li
fe87ffb7ea Disable large allocation report by default
Fixes issue #360.

[alkondratenko@gmail.com: adjusted commit message a bit]
[alkondratenko@gmail.com: adjusted configure help message]
Signed-off-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
2018-05-20 21:13:05 -07:00
Aliaksey Kandratsenka
9608fa3bcf bumped version to 2.7 2018-04-29 23:00:34 -07:00
HolyWu
db890ccfad Clean up src/windows/config.h 2018-04-29 22:59:43 -07:00
HolyWu
497ea33165 Fix WIN32_OVERRIDE_ALLOCATORS for VS2017
At first I try to add some functions as what Chrome does at their
https://chromium.googlesource.com/chromium/src/+/master/base/allocator/allocator_shim_override_ucrt_symbols_win.h,
but it still fails. So I decide to remove all heap-related objects
from libucrt.lib to see what happens. At the end I find that a lot of
functions in the CRT directly invoke _malloc_base instead of
malloc (and the others alike), hence we need to override them as well.

This should close issue #716.

[alkondratenko@gmail.com: added reference to ticket]
Signed-off-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
2018-04-29 22:59:01 -07:00
HolyWu
ebc85cca90 Enable aligned new/delete declarations on Windows when applicable 2018-04-29 21:51:42 -07:00
Aliaksey Kandratsenka
a3badd6d21 Really fix CheckAddressBits compilation warning
It looks like previous fix introduced another warning on gcc for
i386. Somehow it barked on kAddressBits shift even that shift was dead
code.

Anyways, we now avoid possibility of undefined shift even
stronger. And it actually removes compile warning on all compilers I
tested.
2018-04-29 16:40:22 -07:00
HolyWu
7c718fe176 Add tests for sized deallocation 2018-04-29 14:42:44 -07:00
Fabrice Fontaine
30e5e614a8 Fix build without static libraries
Only add -static to malloc_bench_LDFLAGS and binary_trees_LDFLAGS if
ENABLE_STATC is set otherwise build with some compilers will fail if
user has decided to build only the shared version of gperftools
libraries

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
2018-04-29 14:29:16 -07:00
Ben Dang
836c4f29a5
Update documentation for heap_checker.html
Make it clear that the static methods used require the "namespace", `HeapLeakChecker::`.
2018-04-13 10:54:05 -07:00
Tulio Magno Quites Machado Filho
e47d0d1c51 powerpc: Re-enable VDSO support
Powerpc requires VDSO support in order to produce a stack trace.
Without this, it isn't possible to complete a build.
Tested on powerpc, powerpc64 and powerpc64le.
2018-04-11 20:19:55 -07:00
Christoph Müllner
0a66dd3a6a linux: add aarch64_ilp32 support.
This patch adds aarch64 (arm64) ILP32 support by using
the proper syscalls for sys_fcntl(), sys_fstat(), sys_lseek()
and sys_mmap().

Signed-off-by: Christoph Müllner <christophm30@gmail.com>
2018-04-09 21:34:37 -07:00
Christoph Müllner
05dff09663 Fix signature of sbrk.
The manpage of sbrk says that its argument is of type intptr_t.
This patch fixes a compiler warning on gcc 7.3.0.

Signed-off-by: Christoph Müllner <christophm30@gmail.com>
2018-04-09 21:08:20 -07:00
Aliaksey Kandratsenka
33ae0ed2ae unbreak compilation on GNU/Linux i386
Recent commit to fix int overflow for implausibly huge allocation
added call to std::min. Notably, first arg was old size divided by
unsigned long 4. And on GNU/Linux i386 size_t is not long. So such
division was promoting first arg to unsigned long while second arg was
still size_t, so just unsigned. And that caused compilation to fail.

Fix is droping 'ul'.
2018-04-09 20:58:31 -07:00
Christoph Müllner
977e0d4500 Remove not needed header in vdso_support.cc.
Signed-off-by: Christoph Müllner <christophm30@gmail.com>
2018-04-07 08:35:42 +02:00
Mao
36bfa9a404 Enable tcmalloc VDSO support only on x86 to reduce static initializers
Background context
------------------
crrev.com/1466173002 switched the GN tcmalloc target from source_set
-> static_library. There are good reasons for keeping tcmalloc a
source_set (see "Note on static libraries" in [1]).  However, in the
current state source_set was exposing extra static initializers in the
GN build which, are not present in the gyp build due to the linker gc
sections.

Resolution of this CL
---------------------
The fact that vdso_support.cc is GC-ed by the linker is the symptom
that such code is unreachable. A search in the codebase shows that the
only client is stacktrace_x86-inl.h, which depends on VDSO only when
defined(__linux__) && defined(__i386__) This CL is therefore matching
this condition in vdso_support.h and conditioning the #define
HAVE_VDSO_SUPPORT with the same conditions.

[1] https://chromium.googlesource.com/chromium/src/+/master/tools/gn/docs/cookbook.md

References:
https://bugs.chromium.org/p/chromium/issues/detail?id=559766
https://bugs.chromium.org/p/chromium/issues/detail?id=564618
2018-03-27 23:30:17 -07:00
Mao
1cb5de6db9 Explicitly prevent int overflow 2018-03-26 17:28:28 +08:00
Aliaksey Kandratsenka
8f63f2bb98 Correctly detect presence of various functions in tcmalloc.h
This fixes test miscompilations on some clang 6.0
installations. Particularly issue #946.

Defines tested by tcmalloc.h where totally wrong defines. configure
actually puts defines of HAVE_DECL_FOOBAR kind in config.h. Which is
what we're using now.
2018-03-24 21:15:01 -07:00
Aliaksey Kandratsenka
736648887b Don't test OOM handling of debugallocator
This may fix issue #969.

When testing OOM handling we set up sys allocator that fails memory
allocation. But debugallocator itself allocates some internal metadata
memory via malloc and crashes if those allocations fail. So
occasionally this test failed when debugallocator's internal malloc
ended up causing sys allocator.

So instead of failing tests from time to time, we drop it for debug
allocator. It's OOM handling is already crashy anyways.
2018-03-24 20:12:44 -07:00
Aliaksey Kandratsenka
c4a8e00da4 Fix warning about one of CheckAddressBits functions unused 2018-03-24 20:12:44 -07:00
Aliaksey Kandratsenka
47c99cf492 unbreak printing large span stats
One of recent commits started passing kMaxPages to printf but not used
it. Thankfully compilers gave us warning. Apparently intention was to
print real value of kMaxPages, so this is what we're doing now.
2018-03-24 20:12:44 -07:00
Aliaksey Kandratsenka
34f78a2dcd bumped version to 2.7rc 2018-03-18 16:40:44 -07:00
Todd Lipcon
db98aac55a Add a central free list for kMaxPages-sized spans
Previously, the central free list with index '0' was always unused,
since freelist index 'i' tracked spans of length 'i' and there are no
spans of length 0. This meant that there was no freelist for spans of
length 'kMaxPages'. In the default configuration, this corresponds to
1MB, which is a relatively common allocation size in a lot of
applications.

This changes the free list indexing so that index 'i' tracks spans of
length 'i + 1', meaning that free list index 0 is now used and
freelist[kMaxPages - 1] tracks allocations of kMaxPages size (1MB by
default).

This also fixes the stats output to indicate '>128' for the large spans
stats rather than the incorrect '>255' which must have referred to a
historical value of kMaxPages.

No new tests are added since this code is covered by existing tests.
2018-03-17 09:46:28 -07:00
Aliaksey Kandratsenka
d7be938560 implement more robust detection of sized delete support
As reported in issue #954, osx clang compiler is able to optimize our
previous detection away while not really having runtime support for
sized delete. So this time we use AC_LINK_IFELSE and more robust code
to prevent compiler from optimizing away sized delete call. This
should reliably catch "bad" compilers.

Special thanks to Alexey Serbin for reporting the issue, suggesting a
fix and verifying it.

Fixes issue #954.
2018-03-04 23:41:26 -08:00
Aliaksey Kandratsenka
f1d3fe4a21 refactored handling of reverse span set iterator for correctness
I.e. no more questionable memcpy and we run iterator's destructor when
we remove span from SpanSet.
2018-02-25 15:25:16 -08:00
Todd Lipcon
59c77be0fa Update docs for central page heap to reflect tree 2018-02-25 15:25:16 -08:00
Aliaksey Kandratsenka
06c9414ec4 Implemented O(log n) searching among large spans
This is implemented via std::set with custom STL allocator that
delegates to PageHeapAllocator. Free large spans are not linked
together via linked list, but inserted into std::set. Spans also store
iterators to std::set positions pointing to them. So that removing
span from set is fast too.

Patch implemented by Aliaksey Kandratsenka and Todd Lipcon based on
earlier research and experimentation by James Golick.

Addresses issue #535

[alkondratenko@gmail.com: added Todd's fix for building on OSX]
[alkondratenko@gmail.com: removed unnecessary Span constructor]
[alkondratenko@gmail.com: added const for SpanSet comparator]
[alkondratenko@gmail.com: added operator != for STLPageHeapAllocator]
2018-02-25 15:24:17 -08:00
Ishan Arora
a42e44738a typo in docs/tcmalloc.html 2018-01-09 01:35:43 +05:30
Aliaksey Kandratsenka
71bf09aabe bumped version to 2.6.3 2017-12-09 09:59:37 -08:00
Aliaksey Kandratsenka
0bccb5e658 fix malloc fast path for patched windows functions
malloc_fast_path now receives oom function instead of full allocation
function and windows/patch_function.cc wasn't updated until now. It
caused assertion failures as reported in issue #944.
2017-12-09 09:06:52 -08:00
Stephan Zuercher
8b1d13c631 configure.ac: use link check for std::align_val_t 2017-12-09 09:06:52 -08:00
Stephan Zuercher
36ab068baa configure.ac: better test for -faligned-new
XCode 9 provides only partial support for aligned new/delete when -faligned-new
is specified. Require successful linking to enable aligned new/delete.
2017-12-09 09:06:52 -08:00
Aliaksey Kandratsenka
6a4b079997 bumped version to 2.6.2 2017-11-30 18:19:17 +00:00
Aliaksey Kandratsenka
2291714518 implement fast-path for memalign/aligned_alloc/tc_new_aligned
We're taking advantage of "natural" alignedness of our size classes
and instead of previous loop over size classes looking for suitably
aligned size, we now directly compute right size. See align_size_up
function. And that gives us ability to use our existing malloc
fast-path to make memalign neat and fast in most common
cases. I.e. memalign/aligned_alloc now only tail calls and thus avoids
expensive prologue/epilogue and is almost as fast as regular malloc.
2017-11-30 18:14:14 +00:00
Aliaksey Kandratsenka
8b9728b023 add memalign benchmark to malloc_bench 2017-11-30 18:14:11 +00:00
Aliaksey Kandratsenka
79c91a9810 always define empty PERFTOOLS_NOTHROW
Because somehow clang still builds "this function will not throw" code
even with noexcept. Which breaks performance of
tc_malloc/tc_new_nothrow. The difference with throw() seems to be just
which function is called when unexpected exception happens.

So we work around this sillyness by simply dropping any exception
specification when compiling tcmalloc.
2017-11-29 21:44:52 +00:00
Aliaksey Kandratsenka
03da6afff5 unbreak throw declarations on operators new/delete
We now clearly separate PERFTOOLS_NOTHROW (used for tc_XXX functions)
and throw()/noexcept (used for operators we define).

The former is basically "nothrow() for our callers, nothing for
us". It is roughly equivalent of what glibc declares for malloc and
friends. If some exception-full C++ code calls such function it
doesn't have to bother setting up exception handling around such
call. Notably, it is still important for those functions to _not have
throw() declarations when we're building tcmalloc. Because C++ throw()
requires setting up handling of unexpected exceptions thrown from
under such functions which we don't want.

The later is necessary to have operators new/delete definitions have
"correct" exception specifications to calm down compiler
warnings. Particularly older clang versions warn if new/delete aren't
defined with correct exception specifications. Also this commit fixes
annoying gcc 7+ warning (and gnu++14 mode) that complains about
throw() being deprecated.
2017-11-29 21:44:49 +00:00
Aliaksey Kandratsenka
89fe59c831 Fix OOM handling in fast-path
Previous fast-path malloc implementation failed to arrange proper oom
handling for operator new. I.e. operator new is supposed to call new
handler and throw exception, which was not arranged in fast-path case.

Fixed code now passes pointer for oom function to
ThreadCache::FetchFromCentralCache which will call it in oom
condition. Test is added to verify correct behavior.

I've also updated some fast-path-related comments for more accuracy.
2017-11-29 21:44:49 +00:00
Aliaksey Kandratsenka
a29a0cf348 delete-trailing-whitespace on thread_cache.* 2017-11-29 20:50:55 +00:00