On Sat, 19 Feb 2022 05:51:52 GMT, Quan Anh Mai <d...@openjdk.java.net> wrote:

> Hi,
> 
> `Objects.requireNonNull` may fail to be inlined. The call is expensive and 
> may lead to objects escaping to the heap while the null check is cheap and is 
> often elided. I have observed this when using the vector API when a call to 
> `Objects.requireNonNull` leads to vectors being materialised in a hot loop.
> 
> Should the other `requireNonNull` be `ForceInline` as well?
> 
> Thank you very much.

Very simple methods like this are almost always inlined, but I suppose there 
are depth cutoffs that may cause inlining to fail.

Yes, it should always be inlined.  The optimizer works hard to track null-ness 
conditions, and making this call go out of line "breaks the thread of thought" 
in the optimizer's reasoning about null.

Yes, both versions of `O::cNN` should be marked this way; the only difference 
is in how the exception is constructed.

(A similar point goes for index-checking functions, which are also 
force-inlined so that simple index checks of the form `i*K+L <u R` can be 
strength-reduced by loop iteration range splitting.)

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

PR: https://git.openjdk.java.net/jdk/pull/7543

Reply via email to