Commit Graph

789 Commits

Author SHA1 Message Date
Aliaksey Kandratsenka
a46a391b14 gtestify low_level_alloc_unittest 2024-02-20 14:34:20 -05:00
Aliaksey Kandratsenka
6c24a59682 introduce vendor copy of googletest 2024-02-20 14:30:24 -05:00
Aliaksey Kandratsenka
ad6e29e7c9 move gtest-like asserts into legacy_assertions.h 2024-02-20 14:24:12 -05:00
oPiZiL
b02d36d2eb fix compile error with gcc 7.5
In file included from /home/louwei/arcs/gperftools/src/span.cc:41:0:
/home/louwei/arcs/gperftools/src/static_vars.h:125:37: error: ‘byte’ in namespace ‘std’ does not name a type
     alignas(alignof(PageHeap)) std::byte memory[sizeof(PageHeap)];
                                     ^~~~
/home/louwei/arcs/gperftools/src/static_vars.h: In static member function ‘static tcmalloc::PageHeap* tcmalloc::Static::pageheap()’:
/home/louwei/arcs/gperftools/src/static_vars.h:76:80: error: ‘struct tcmalloc::Static::<unnamed>’ has no member named ‘memory’
   static PageHeap* pageheap() { return reinterpret_cast<PageHeap *>(&pageheap_.memory); }
                                                                                ^~~~~~
2024-02-19 11:21:08 -05:00
Aliaksey Kandratsenka
3d155f6624 apply tcmalloc::FunctionRef in AddressMap 2024-02-17 20:10:21 -05:00
Aliaksey Kandratsenka
8c1a7ef17f implement tcmalloc::FunctionRef 2024-02-17 20:10:21 -05:00
Aliaksey Kandratsenka
5f92c0616a implement tcmalloc::Cleanup
This is similar, but slightly less featureful than
absl::{Make,}Cleanup.
2024-02-17 20:10:21 -05:00
Aliaksey Kandratsenka
dec85dcc03 avoid undefined behavior when parsing proc maps
Clang's undefined behavior sanitized correctly pointed out that
memmove requires non-nil args, so lets initialize sbuf to something.
2024-02-17 18:32:03 -05:00
Aliaksey Kandratsenka
9b5838f084 modernize overalignment testing bits 2024-02-17 18:32:03 -05:00
Aliaksey Kandratsenka
57d6ecc4ae drop obsolete src/windows/TODO 2024-02-08 09:41:38 -05:00
Aliaksey Kandratsenka
8a147b4833 untangle a number of unittests from libtcmalloc_minimal.so 2024-02-07 23:54:03 -05:00
Aliaksey Kandratsenka
e544d402f7 amputate unused log_message_write 2024-02-07 19:40:08 -05:00
Aliaksey Kandratsenka
b6798a5130 amputate unused kCrashWithStats 2024-02-07 19:40:08 -05:00
Aliaksey Kandratsenka
45a4ad8b70 mmap_hook_test: don't printf early
The test includes override of
MallocHook_InitAtFirstAllocation_HeapLeakChecker which runs early
enough to trigger FreeBSD bug of not having nearly anything working
early.
2024-02-07 19:37:04 -05:00
Aliaksey Kandratsenka
e7f576d9f1 generic_writer_test: crash with message if tmpfile fails 2024-02-07 19:36:41 -05:00
Aliaksey Kandratsenka
c52c321bdd replace raw printer with usage of generic writer facility 2024-02-07 15:46:54 -05:00
Aliaksey Kandratsenka
88adbbdb95 generalize FileGenericWriter
There is now WriteFnWriter which allows us to use lambdas for a
function that saves accumulated bytes.
2024-02-07 15:46:49 -05:00
Aliaksey Kandratsenka
59f0247033 liberate sampler_test from linking to libtcmalloc
This test is exercising purely sampling interval logic.
2024-02-07 15:45:25 -05:00
Aliaksey Kandratsenka
771a01ed28 rework and simplify emergency malloc integration
We now wrap StackTraceScope thingy in tcmalloc-specific parts, instead
of automagically inside every stacktrace.cc function. TCMalloc bits
all need to grab stacktraces via newly introduced
tcmalloc::GrabBacktrace (which handles emergency malloc wrapping).

New approach eliminates the need for doing fake stacktrace scope. CPU
profiler, being distinct .so library couldn't take advantage of
emergency malloc anyways.

This simplifies the build further and eliminates another potential
point of runtime divergence when stacktrace is linked to both
libprofiler and libtcmalloc.
2024-02-05 14:27:02 -05:00
Aliaksey Kandratsenka
1331c0e0d1 drop long deprecated google/ headers 2024-02-04 21:54:46 -05:00
Aliaksey Kandratsenka
a05bab586a align CentralFreeList on cache line size instead of just 64
We had hardcoded size alignment on 64 bytes, seemingly to avoid
cacheline contention when taking per-size-class central free list
locks. But it makes more sense to do platform specific alignment.

I did consider std::hardware_constructive_interference_size, but
practical values seem to differ from what we have configured at least
on some platforms.
2024-02-04 19:33:12 -05:00
Aliaksey Kandratsenka
353816fd9d drop LINKER_INITIALIZED in favor of constexpr constructors 2024-02-04 19:18:33 -05:00
Aliaksey Kandratsenka
247b7f3370 use std::thread when spawning threads in tests 2024-02-04 16:39:02 -05:00
Aliaksey Kandratsenka
2e5ecb4de6 amputate src/base/simple_mutex.h
Use standard mutex instead
2024-02-04 16:38:21 -05:00
Aliaksey Kandratsenka
885dd867bc liberate code base from legacy fixed size int types
I.e. all those int32 etc type (without _t at the end). We stick to
standard. Google/Abseil code base has long been liberated as well.
2024-02-04 15:47:21 -05:00
Aliaksey Kandratsenka
de22f024fb globally replace COMPILE_ASSERT with static_assert 2024-02-04 15:05:45 -05:00
Aliaksey Kandratsenka
c56764c3e6 tcmalloc_unittest: do 64-bit shift when computing alignment
Thanks goes to MSVC for warning about this.
2024-02-04 14:55:25 -05:00
Aliaksey Kandratsenka
329e9adfa6 fix MSVC warning on flexible data member extension 2024-02-04 14:55:10 -05:00
Aliaksey Kandratsenka
f910729012 turn inline ATTRIBUTE_ALWAYS_INLINE -> ALWAYS_INLINE
gcc needs both inline and __attribute__((always_inline)), while MSVC
only needs __forceinline. So relevant correct combination is now just
ALWAYS_INLINE macro.
2024-02-04 14:53:52 -05:00
Aliaksey Kandratsenka
57660e6a54 fix MSVC warning on thread annotations 2024-02-04 14:53:34 -05:00
Aliaksey Kandratsenka
5ec6f60bd7 suppress thread-safety warning for ThreadCachePtr
It is slightly less great that we have to disable thread-safety
analysis, but they explicitly say that optional locking is not
supported. And ours is very explicitly optional locking. I.e. we only
let ourselves resort to slow locking very early during process
startup, when TLS isn't 100% ready and safe to use yet.
2024-02-04 13:43:57 -05:00
Aliaksey Kandratsenka
78e7b959a7 fix clang warning for CreateBadTLSCache 2024-02-04 13:42:38 -05:00
Aliaksey Kandratsenka
2d35232cfa avoid unused variable warning for bucket_count 2024-02-04 13:23:16 -05:00
Aliaksey Kandratsenka
c59b431b28 use std::get_new_handler when handling OOM
Previously when dealing with OOM condition we couldn't use
std::get_new_handler (it didn't exist until c++ 11). Now we can and it
simplifies logic a bit.

We also detect -fno-exceptions case via standard __cpp_exceptions
define. Also I've rearranged the logic and even found and fixed one
bug in -fno-exceptions case.
2024-02-03 15:57:14 -05:00
Aliaksey Kandratsenka
04a8a4bae6 actually verify that we're deallocating thread caches 2024-02-03 15:57:14 -05:00
Aliaksey Kandratsenka
6691226953 split and rewrite TLS access for thread caches
Logic was removed from thread_cache.{h,cc} into
thread_cache_ptr.{h,cc}.

Separation will help possible future evolution, and we already changed
the logic quite a bit:

* early access (when TLS isn't initialized yet) now uses global
ThreadCache instance. We therefore have ThreadCachePtr instances
managing required locking. This eliminates unnecessary complication of
PTHREADS_CRASHES_IF_RUN_TOO_EARLY logic, and any other danger of
touching TLS too early. BTW previous implementation actually leaked
initial early-initialized ThreadCache instance(!)

* old configure-time HAVE_TLS logic is amputated. Config-time part of
it made little sense as C++ 17 guarantees availability of
thread_local, but we have manually curated deny-list of "bad" OSes,
that we tested (via compile checks!) at configure time. Now this
is all compile time. There is now compile-time kHaveGoodTLS variable
and we're using it mostly via if constexpr.

* kHaveGoodTLS case of creating thread cache is simplified and made
more straightforward (no need to have in_setspecific logic).

* !kHaveGoodTLS case if fixed and improved too. We avoid
std:🧵:get_id, as it deadlocks on mingw. We use errno address as
a portable and (usually) async-signal safe 'my thread' identifier. We
also eliminate linear searching of thread's cache and replace it with
straightforward hash table lookup.
2024-02-03 15:57:14 -05:00
Aliaksey Kandratsenka
104e2dd228 improve page_allocator debug diagnostics
Lets clear objects that we're freeing. Helps catch use-after free for
our internal memory allocations.
2024-02-03 14:20:07 -05:00
Aliaksey Kandratsenka
d0b0134c45 drop perftools_vsnprintf wrapper
Because everyone now has functional and standards compiliant vsnprintf.
2024-01-30 17:18:12 -05:00
Aliaksey Kandratsenka
51d3340b39 avoid -Wunused-results warnings from read/write
glibc with _FORTIFY_SOURCE sets those up to give warnings on unused
results. We used to disable this warning globally, but lets do better.
2024-01-30 17:08:29 -05:00
Aliaksey Kandratsenka
82a36a6fcd bump required c++ standard to c++-17 2024-01-30 15:54:24 -05:00
Aliaksey Kandratsenka
5db2adc4e7 drop stale workaround for ancient solaris issue 2024-01-29 21:02:17 -05:00
Aliaksey Kandratsenka
468ccf3d0d refactor and cleanup proc_maps_iterator.cc
We don't need messed up ProcMapsIterator class. Since our API has been
simplified we simply have one "for-each" function for each
implementation.
2024-01-29 21:02:17 -05:00
Aliaksey Kandratsenka
a3080fa8d6 extract proc-maps iteration into own file and cover it by tests
This allows us, later, to avoid building this stuff in configurations
that don't use it. I have also reduced API and ABI surface to enable
further refactorings.
2024-01-29 21:02:17 -05:00
Aliaksey Kandratsenka
fa5c61f52e stop trying to declare madvise on solaris
It isn't needed on modern opensolaris. And in fact it breaks the
build. And I am not entirely sure how to accomodate both old and new
behavior. So lets keep things simple and assume that old
behavior (where madvise needs to be declared) is ancient enough.
2024-01-29 21:02:17 -05:00
Aliaksey Kandratsenka
f22f5b2a63 workaround broken mmap allocator on solaris 2024-01-29 21:02:17 -05:00
Aliaksey Kandratsenka
7d37882df0 implement GetProgramInvocationName for solaris 2024-01-29 21:02:17 -05:00
Aliaksey Kandratsenka
689752dc38 generate vsprojects/gperftools/tcmalloc.h from our main tcmalloc.h
This will save me from risk of forgetting to update this file manually
when bumping package version.
2024-01-29 21:00:20 -05:00
Aliaksey Kandratsenka
1eeea50f89 don't use config.h PACKAGE_{VERSION,STRING} in tcmalloc_unittest
It makes a lot more sense to test our public API which is
TC_VERSION_STRING.
2024-01-29 20:57:12 -05:00
lennoxho
9a6848de8a A number of cleanups
* Remove build dependency on HAVE_PTHREAD
* Remove build dependency on HAVE_STD_ALIGNED_VAL_T and ENABLE_ALIGNED_NEW_DELETE
* Remove redundant tcmalloc.h files & ensure there are no cross-build-tool references
* Adopt automake commit 26927d1 in the CMake build
2024-01-29 17:15:53 -08:00
Aliaksey Kandratsenka
8b34e9425c unbreak freebsd build 2024-01-26 17:03:20 -05:00