Replace experimental_infallible_new with compile-time flag

The runtime option aborted on every OOM, breaking new(std::nothrow)
semantics. Replace with configure-time --enable-cxx-infallible-new
(default off): when on, throwing new aborts (size logged) and
nothrow returns null; when off, standard new_handler + bad_alloc /
null behavior is preserved. Under LTO the on-path lets the compiler
prove operator new is no-throw.
This commit is contained in:
Slobodan Predolac
2026-06-04 10:58:43 -07:00
parent a6048680a8
commit 160ab9d7f6
19 changed files with 103 additions and 44 deletions

View File

@@ -0,0 +1,8 @@
#!/bin/sh
XMALLOC_STR=""
if [ "x${enable_xmalloc}" = "x1" ] ; then
XMALLOC_STR="xmalloc:false"
fi
export MALLOC_CONF="${XMALLOC_STR}"

View File

@@ -3,8 +3,9 @@
#include "test/jemalloc_test.h"
/*
* We can't test C++ in unit tests. In order to intercept abort, use the
* internal test hook in integration tests.
* Verifies that, when jemalloc is built with --enable-cxx-infallible-new,
* throwing operator new on OOM aborts via safety_check_fail. The test hook
* intercepts the abort and asserts the size-bearing message prefix.
*/
bool fake_abort_called;
void

View File

@@ -0,0 +1,8 @@
#!/bin/sh
XMALLOC_STR=""
if [ "x${enable_xmalloc}" = "x1" ] ; then
XMALLOC_STR="xmalloc:false"
fi
export MALLOC_CONF="${XMALLOC_STR}"

View File

@@ -1,8 +0,0 @@
#!/bin/sh
XMALLOC_STR=""
if [ "x${enable_xmalloc}" = "x1" ] ; then
XMALLOC_STR="xmalloc:false,"
fi
export MALLOC_CONF="${XMALLOC_STR}experimental_infallible_new:false"

View File

@@ -1,8 +0,0 @@
#!/bin/sh
XMALLOC_STR=""
if [ "x${enable_xmalloc}" = "x1" ] ; then
XMALLOC_STR="xmalloc:false,"
fi
export MALLOC_CONF="${XMALLOC_STR}experimental_infallible_new:true"

View File

@@ -266,6 +266,7 @@ TEST_BEGIN(test_mallctl_config) {
TEST_MALLCTL_CONFIG(cache_oblivious, bool);
TEST_MALLCTL_CONFIG(debug, bool);
TEST_MALLCTL_CONFIG(fill, bool);
TEST_MALLCTL_CONFIG(infallible_new, bool);
TEST_MALLCTL_CONFIG(lazy_lock, bool);
TEST_MALLCTL_CONFIG(malloc_conf, const char *);
TEST_MALLCTL_CONFIG(prof, bool);