RFR: 8282143: Objects.requireNonNull should be ForceInline

John R Rose jrose at openjdk.java.net
Tue Mar 1 00:39:05 UTC 2022


On Sat, 19 Feb 2022 05:51:52 GMT, Quan Anh Mai <duke at 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


More information about the core-libs-dev mailing list