RFR: 8221980: Simplify Optional implementation

Claes Redestad claes.redestad at oracle.com
Thu Apr 4 10:29:29 UTC 2019


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



More information about the core-libs-dev mailing list