Commit Graph

999 Commits

Author SHA1 Message Date
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
7756b4cc61 don't force TMPDIR on all unittests
Turns out at least on FreeBSD tmpfile will fail if TMPDIR points to
non-existant directory. This also has nice property of leaving it down
to users to set up TMPDIR the way they want.
2024-02-07 19:35:37 -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
a02ac30bbf rework and optimize structure of Makefile.am
There were far too many intermediate libraries, references to obsolete
libtool bugs and whatnot.

We now have libcommon.la as a convenience archive that contains
spinlock, logging and misc stuff. A number of unit tests that need
those facilities are being linked to this.

Then we have libstacktrace.la convenience archive, since it is used by
libtcmalloc.la and libprofiler.la.

And after that we're simply directly creating our main library
products: libtcmalloc_minimal{,_debug}.la, libtcmalloc_{,debug}.la,
libprofiler.la etc.
2024-02-07 15:45:22 -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
4be76ab707 drop symbols weakening step
It has questionable value and most importantly, it was broken lots of
years without anyone complaining. So lets get things simpler.
2024-02-05 00:00:00 -05:00
Aliaksey Kandratsenka
ca50448a1e drop export-symbols-regex stuff for libstacktrace.la
It has no effect, because libstacktrace.la is convenience archive, not
a library we install.
2024-02-04 23:56:08 -05:00
Aliaksey Kandratsenka
ba3d790855 drop running pprof -test as part of make check
Not needed anymore.
2024-02-04 23:46:39 -05:00
Aliaksey Kandratsenka
144c118f92 drop outdated comment in Makefile.am 2024-02-04 23:42:58 -05:00
Aliaksey Kandratsenka
e262ebc741 ship everything under vsprojects/ in make dist
We also drop all those WINDOWS_PROJECTS amends and simplify makefile.
2024-02-04 23:38:18 -05:00
Aliaksey Kandratsenka
b49920ea64 don't bother listing every header in Makefile.am
For compiling things automake never needs to be given a full set of
headers. Usually headers are specified so that make dist includes them
into archive, but we can achieve this goal easier.

This reduces size and complexity of our Makefile.am stuff.
2024-02-04 23:20:35 -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
21e66f807c enable -Wthread-safety for clang 2024-02-04 13:37:53 -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
1eb2d1a604 bump msvc projects to VS2019 and c++ 17 2024-01-30 15:54:24 -05:00
Aliaksey Kandratsenka
82a36a6fcd bump required c++ standard to c++-17 2024-01-30 15:54:24 -05:00
Aliaksey Kandratsenka
faf96cd81e reflect renaming src/tcmalloc{,_internal}.h in MSVC projects 2024-01-30 15:54:24 -05:00
Aliaksey Kandratsenka
71b3a0c6c4 unreak gperftools/tcmalloc.h inclusion in MSVC projects 2024-01-30 15:53:10 -05:00
Aliaksey Kandratsenka
5db2adc4e7 drop stale workaround for ancient solaris issue 2024-01-29 21:02:17 -05:00
Aliaksey Kandratsenka
5ce342e1c8 fix generic_writer_test and proc_maps_iterator_test on cmake+msvc 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
d6728a0b4c drop unused PACKAGE_XYZ defines from {cmake/vsproject}/config.h
Automake or autoconf adds them automagically, but we don't really need
them. Main effect of this change is that MSVC version of config.h
doesn't duplicate package version.
2024-01-29 20:58:02 -05:00