RFR 8009736: Comparator API cleanup

Remi Forax forax at univ-mlv.fr
Fri Jun 14 16:12:20 PDT 2013

On 06/14/2013 11:44 PM, John Rose wrote:
> On Jun 14, 2013, at 3:07 AM, Paul Sandoz <paul.sandoz at oracle.com> wrote:
>>             this.real = (Comparator<T>) Objects.requireNonNull(real);
> Regarding this idiom, I added the following comment to JDK-6919064:
>> New JDK 8 code is making frequent use of static methods like Objects.requireNonNull and Objects.equal. If these were open-coded (that is, inlined by hand), the branches and virtual calls (to Object.equals) would be profiled per caller. As global functions, their profiles are polluted, which may cause performance problems.
>> A fix to this bug should demonstrate that Objects.requireNonNull and Objects.equal are as fast as their open-coded equivalents, even in the presence of profile pollution. To pollute the profile of these methods, simply pre-warm the benchmark by a small loop passing a variety of nulls and non-null references to various classes to the arguments of these methods.
> http://bugs.sun.com/view_bug.do?bug_id=6919064
> — John

Objects.requireNonNull is as fast as a hand written check if there is no 
code that catch the NullPointerException thrown by requireNonNull in the 
whole application. I think it's more efficient for the whole Java 
community to start a witch hunt to find developers that write codes that 
catch NPEs
thrown by a Objects.requireNonNull than to write benchmarks for every 
methods that starts with a Objects.requireNonNull.

The other solution is to fix http://bugs.sun.com/view_bug.do?bug_id=8015416


More information about the lambda-dev mailing list