RFR: 8221980: Simplify Optional implementation

Langer, Christoph christoph.langer at sap.com
Thu Apr 4 12:51:36 UTC 2019


Hi Claes,

this looks good to me.

Best regards
Christoph

> -----Original Message-----
> From: core-libs-dev <core-libs-dev-bounces at openjdk.java.net> On Behalf
> Of Claes Redestad
> Sent: Donnerstag, 4. April 2019 12:29
> To: core-libs-dev <core-libs-dev at openjdk.java.net>
> Subject: RFR: 8221980: Simplify Optional implementation
> 
> Hi,
> 
> the current code for Optional.ofNullable() null-checks the value, then
> calls of(), which calls new Optional(), which null-checks again via
> Objects.requireNonNull(). This can be simplified by refactoring so that
> we only null-check once and chain through fewer methods.
> 
> Bug:    https://bugs.openjdk.java.net/browse/JDK-8221980
> Webrev: http://cr.openjdk.java.net/~redestad/8221980/open.00/
> 
> While JITs are likely to inline all this and generate the optimal
> code, it can fail to do so due inlining heuristics. This simplification
> reduces the risk of hitting such limits, while also speeding up code
> executed during startup and warmup phases.
> 
> Testing: tier1-2, verified a small improvement in startup profiles
> 
> Thanks!
> 
> /Claes


More information about the core-libs-dev mailing list