RFR: 8366925: Improper std::nothrow new expression in NativeHeapTrimmerThread ctor

Guanqiang Han ghan at openjdk.org
Mon Sep 15 14:12:59 UTC 2025


On Mon, 15 Sep 2025 10:21:24 GMT, Albert Mingkun Yang <ayang at openjdk.org> wrote:

>> Please review this Patch.
>> 
>> **Description:**
>> Add null check for _lock in NativeHeapTrimmerThread constructor. If allocation of the lock fails (_lock == nullptr), it indicates an out-of-memory condition. Since even this small allocation failed, it's unlikely that subsequent operations would succeed, so we terminate the JVM immediately.
>
> Why does the init of `_lock` use `std::nothrow`? `PaddedMonitor` is `CHeapObj` -- wouldn't the default `new` operator invoke the exit-on-oom?

Hi @albertnetymk, i’m actually not sure about the original author’s intent for using new (std::nothrow) here. In my change I kept the same allocation style. The reason I didn’t switch to the default CHeapObj operator new (which exits on OOM) is that it would terminate the VM with a generic OOM message.
By keeping std::nothrow and explicitly checking for nullptr, I can emit a clearer, more specific error message before exiting.

-------------

PR Comment: https://git.openjdk.org/jdk/pull/27275#issuecomment-3292372163


More information about the hotspot-runtime-dev mailing list