Commit 610c1163 authored by Pádraig Brady's avatar Pádraig Brady Committed by Facebook Github Bot

fix usingJEMalloc() with LTO

Summary:
LTO has better optimization which results in the malloc() being optimized away in this function.

Note we don't use folly::dontOptimizeAway() because
that introduces a circular dependency between the
malloc and benchmark targets.

Reviewed By: marksantaniello, meyering, interwq

Differential Revision: D5840883

fbshipit-source-id: 5dd9b152f70b7a49f125b6d79b4dfa40f4cdac59
parent 2c62efc8
......@@ -183,15 +183,15 @@ FOLLY_MALLOC_NOINLINE inline bool usingJEMalloc() noexcept {
uint64_t origAllocated = *counter;
// Static because otherwise clever compilers will find out that
// the ptr is not used and does not escape the scope, so they will
// just optimize away the malloc.
static const void* ptr = malloc(1);
const void* ptr = malloc(1);
if (!ptr) {
// wtf, failing to allocate 1 byte
return false;
}
/* Avoid optimizing away the malloc. */
asm volatile("" ::"m"(ptr) : "memory");
return (origAllocated != *counter);
}();
......
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