Apparently some recent FreeBSDs occasionally lack brk. So our code
which previously hard-coded that this OS has brk (which we use to
implement hooked sbrk) fails to compile.
Our configure scripts already detects sbrk, so we simply need to pay
attention. Fixes github issue #1499
Our implementation of emergency malloc slow-path actually depends on
good TLS implementation. So on systems without good TLS (i.e. OSX), we
lied to ourselves that emergency malloc is available, but then failed
tests.
We don't expose DefaultArena anymore. Simply passing nullptr implies
default arena.
We also streamline default arena initialization (we
previously relied on combination of lazy initialazation in ArenaInit
and constexpr construction).
There is also no need to have elaborate ArenaLock thingy. We use plain
SpinLockHolder instead.
This is off by default for now. And autotools-only. But after
significant preparatory work, we're now able to do it cleanly. Stuff
that was previously exported just for tests (like page heap stuff or
flags) is now unexported.
Just like on windows all symbols explicitly exported by
PERFTOOLS_DLL_DECL are visible and exported and rest are hidden. Those
include all the malloc/new APIs of course, and all the other symbols
we advertise in our headers (e.g. MallocExtension, MallocHook).
Updates issue #600
While it still needs more work to be up to highest standards of
cleanness and clarity, we made it better.
One big part of this change is we're now liberated from
tcmalloc_unittest.sh. We now arrange testing of various environment
variable tweaks in C++ by self-execing with updated environment at the
end of tests.
Biggest part of it is removal of SetTestResourceLimit. The reasoning
behind it is, we don't do it on windows. Tests pass just fine. So,
there is no reason to bother.
I just dealt with somewhat curious failure in page heap test and the
change was due to breakage of HaveSystemRelease on OSX. And since OSX
can truly release memory and Windows too, lets assert this.
This improves fragmentation in some use-cases when mmap sys allocator
is used. In specific terms, it unbreaks
tcmalloc_large_heap_fragmentation_unittest on OSX. They have sbrk that
seemingly always fails (fair game). And this test aggressive
fragmentation use-case pretty much requires tcmalloc to allocate
memory "linearly". Which sbrk does.
Previously, our mmap sys allocator didn't pass any start address hint,
so it caused the test to fail. Now we remember end of previous mmap
allocation into hint_ member variable and try to pass it as address
hint to next mmap.
Note, it doesn't help TCMALLOC_SKIP_SBRK=t to pass this test on Linux,
as Linux tends to pick initial mmap chunk "backwards" and too close to
library allocations. So it leaves not enough address space to extend
into. We may address this use-case some other time.
On OSX and Windows we could end up with "default" and no-op
MallocExtension to be used if MallocExtension::instance() is used
before tcmalloc is fully initialized. It was nearly intended after my
recent change. But thinking about this more, even in use-cases where
we don't replace systems malloc APIs, we want MallocExtension to
reflect tcmalloc's state. So we now truly force tcmalloc
initialization on first MallocExtension::instance() use and
MallocExtension is now abstract class.
Otherwise when _TIME_BITS are set, glibc complains that it seems
_TIME_BITS=64 without seeing _FILE_OFFSET_BITS=64. Thankfully, none of
the code in mmap_hook.cc depends on time_t.
Debian is doing massive rebuild of everything with 64-bit off_t (and
time_t), but on those systems where it matters, glibc still has mmap
with 32-bit off_t argument and mmap64 with 64-bit off_t. Since we're
aiming to match glibc's ABI, we need to see system's native off_t
width.
Some our tests are intended to test behavior of external APIs (like
operator new etc), but they do need occasional ability to peek into
the guts of tcmalloc. We want to make our .so libraries to be built
with -fvisibility=hidden, so we'll loose this ability.
In order to have this limited ability for tests to get into the guts
of tcmalloc, we introduce TestingPortal exactly for that. It uses
carefuly designed and thouroughly undocumented GetNumericProperty
extension to grab pointer to TestingPortal. Then through calling
member functions of this instance, we're able to do the right thing.