| 54 | #endif |
| 55 | |
| 56 | JEMALLOC_NOINLINE |
| 57 | static void * |
| 58 | handleOOM(std::size_t size, bool nothrow) { |
| 59 | if (opt_experimental_infallible_new) { |
| 60 | safety_check_fail("<jemalloc>: Allocation failed and " |
| 61 | "opt.experimental_infallible_new is true. Aborting.\n"); |
| 62 | return nullptr; |
| 63 | } |
| 64 | |
| 65 | void *ptr = nullptr; |
| 66 | |
| 67 | while (ptr == nullptr) { |
| 68 | std::new_handler handler; |
| 69 | // GCC-4.8 and clang 4.0 do not have std::get_new_handler. |
| 70 | { |
| 71 | static std::mutex mtx; |
| 72 | std::lock_guard<std::mutex> lock(mtx); |
| 73 | |
| 74 | handler = std::set_new_handler(nullptr); |
| 75 | std::set_new_handler(handler); |
| 76 | } |
| 77 | if (handler == nullptr) |
| 78 | break; |
| 79 | |
| 80 | try { |
| 81 | handler(); |
| 82 | } catch (const std::bad_alloc &) { |
| 83 | break; |
| 84 | } |
| 85 | |
| 86 | ptr = je_malloc(size); |
| 87 | } |
| 88 | |
| 89 | if (ptr == nullptr && !nothrow) |
| 90 | std::__throw_bad_alloc(); |
| 91 | return ptr; |
| 92 | } |
| 93 | |
| 94 | template <bool IsNoExcept> |
| 95 | JEMALLOC_NOINLINE |
no test coverage detected