RFR 8135248: Add utility methods to check indexes and ranges
Paul Sandoz
paul.sandoz at oracle.com
Mon Sep 21 17:18:49 UTC 2015
Hi Peter,
You can find some discussion in the comments of https://bugs.openjdk.java.net/browse/JDK-8042997 which may help.
I originally thought we could intrinsify unsigned comparison or have a boolean returning method.
Over a series of discussions i was convinced by the current shape that makes it easier to use in an expression, the result of which may be easier for the JIT to track, no flow control is arguably easier, it encapsulates the throwing logic in a single failure block that is squirrelled away, and potentially reduces the code of callers. Like the inequality checks themselves those things may be easy but one can often make trivial mistakes too.
Paul.
On 21 Sep 2015, at 17:53, Peter Levart <peter.levart at gmail.com> wrote:
>
>
> On 09/21/2015 05:22 PM, Peter Levart wrote:
>> Hi Paul,
>>
>> It seems that all that is needed for performance is to intrinsify static methods Integer.compareUnsigned(int, int) and Long.compareUnsigned(long, long). Or would that not be enough? Then perhaps explicit compare operations would suffice:
>>
>> public class Integer {
>> ...
>> public static boolean unsignedLess(int a, int b);
>> public static boolean unsignedLessOrEqual(int a, int b);
>>
>> You could still have Arrays.checkIndex methods, but they could be pure bytecode methods with standard exception types / messages. And if one needs special exception types / messages, (s)he can use the intrinsified comparison methods directly and imperative code to throw the exception.
>>
>> What do you think?
>>
>> Regards, Peter
>
> Or,
>
> ...have intrinsified method(s) in the form of:
>
> public class Arrays {
> ...
> public static boolean isIndexValid(int i, int length);
> public static boolean isFromToIndexValid(int from, int to, int length);
> ...
>
> ... and pure bytecode checkXXXIndex methods implemented in terms of above but just for standard exceptions. Code throwing customized exceptions would use isXXXIndexValid methods and imperative code to construct and throw exception.
>
> The question is whether boolean return from intrinsic method coupled with if statement in bytecode optimizes equally well as if the branch was in the intrinsified method itself.
>
>
> Regards, Peter
>
More information about the core-libs-dev
mailing list