Re: RFR: 8255150: Add utility methods to check long indexes and ranges [v2]

2020-11-06 Thread Roland Westrelin
On Thu, 5 Nov 2020 23:59:43 GMT, Dean Long  wrote:

> C2 changes look good, except for new code block in 
> inline_preconditions_checkIndex could use a comment.

Thanks for the review. I added a comment for this block and some other comments 
for the rest of this method.

-

PR: https://git.openjdk.java.net/jdk/pull/1003


Re: RFR: 8255150: Add utility methods to check long indexes and ranges [v2]

2020-11-06 Thread Roland Westrelin
On Fri, 6 Nov 2020 04:25:40 GMT, Dean Long  wrote:

>> src/hotspot/share/opto/library_call.cpp line 1015:
>> 
>>> 1013:   Deoptimization::Action_make_not_entrant);
>>> 1014:   }
>>> 1015: 
>> 
>> A comment here explaining what the code below is doing would be helpful.
>
> This code wasn't here before, so I'm guessing it's needed for T_LONG.  For 
> T_INT is it just wasted work?

Code in IdealLoopTree::is_range_check_if() uses this check:
  if (range->Opcode() != Op_LoadRange && !iff->is_RangeCheck()) {
const TypeInt* tint = phase->_igvn.type(range)->isa_int();
if (tint == NULL || tint->empty() || tint->_lo < 0) {
  // Allow predication on positive values that aren't LoadRanges.
  // This allows optimization of loops where the length of the
  // array is a known value and doesn't need to be loaded back
  // from the array.
  return false;
that is it assumes that everything that's on the right hand size of the a 
RangeCheck test is positive. I think it's cleaner and less dangerous to 
explicitly cast the length to >= 0 when the intrinsic is built. In a subsequent 
patch I intend to drop the && !iff->is_RangeCheck() check above.

-

PR: https://git.openjdk.java.net/jdk/pull/1003


Re: RFR: 8255150: Add utility methods to check long indexes and ranges [v2]

2020-11-05 Thread Dean Long
On Thu, 5 Nov 2020 23:58:21 GMT, Dean Long  wrote:

>> Roland Westrelin has updated the pull request with a new target base due to 
>> a merge or a rebase. The pull request now contains ten commits:
>> 
>>  - Jorn's comments
>>  - Update headers and add intrinsic to Graal test ignore list
>>  - move compiler test and add bug to test
>>  - non x86_64 arch support
>>  - c2 test case
>>  - intrinsic
>>  - Use overloads of method names.
>>
>>Simplify internally to avoid overload resolution
>>issues, leverging List for the exception
>>mapper.
>>  - Vladimir's comments
>>  - checkLongIndex
>
> src/hotspot/share/opto/library_call.cpp line 1015:
> 
>> 1013:   Deoptimization::Action_make_not_entrant);
>> 1014:   }
>> 1015: 
> 
> A comment here explaining what the code below is doing would be helpful.

This code wasn't here before, so I'm guessing it's needed for T_LONG.  For 
T_INT is it just wasted work?

-

PR: https://git.openjdk.java.net/jdk/pull/1003


Re: RFR: 8255150: Add utility methods to check long indexes and ranges [v2]

2020-11-05 Thread Dean Long
On Thu, 5 Nov 2020 15:47:31 GMT, Roland Westrelin  wrote:

>> This change add 3 new methods in Objects:
>> 
>> public static long checkIndex(long index, long length)
>> public static long checkFromToIndex(long fromIndex, long toIndex, long 
>> length)
>> public static long checkFromIndexSize(long fromIndex, long size, long length)
>> 
>> This mirrors the int utility methods that were added by JDK-8135248
>> with the same motivations.
>> 
>> As is the case with the int checkIndex(), the long checkIndex() method
>> is JIT compiled as an intrinsic. It allows the JIT to compile
>> checkIndex to an unsigned comparison and properly recognize it as
>> a range check that then becomes a candidate for the existing range check
>> optimizations. This has proven to be important for panama's
>> MemorySegment API and a prototype of this change (with some extra c2
>> improvements) showed that panama micro benchmark results improve
>> significantly.
>> 
>> This change includes:
>> 
>> - the API change
>> - the C2 intrinsic
>> - tests for the API and the C2 intrinsic
>> 
>> This is a joint work with Paul who reviewed and reworked the API change
>> and filled the CSR.
>
> Roland Westrelin has updated the pull request with a new target base due to a 
> merge or a rebase. The pull request now contains ten commits:
> 
>  - Jorn's comments
>  - Update headers and add intrinsic to Graal test ignore list
>  - move compiler test and add bug to test
>  - non x86_64 arch support
>  - c2 test case
>  - intrinsic
>  - Use overloads of method names.
>
>Simplify internally to avoid overload resolution
>issues, leverging List for the exception
>mapper.
>  - Vladimir's comments
>  - checkLongIndex

C2 changes look good, except for new code block in 
inline_preconditions_checkIndex could use a comment.

src/hotspot/share/opto/library_call.cpp line 1015:

> 1013:   Deoptimization::Action_make_not_entrant);
> 1014:   }
> 1015: 

A comment here explaining what the code below is doing would be helpful.

-

Changes requested by dlong (Reviewer).

PR: https://git.openjdk.java.net/jdk/pull/1003


Re: RFR: 8255150: Add utility methods to check long indexes and ranges [v2]

2020-11-05 Thread Jorn Vernee
On Thu, 5 Nov 2020 15:42:54 GMT, Roland Westrelin  wrote:

>> src/java.base/share/classes/java/lang/IndexOutOfBoundsException.java line 83:
>> 
>>> 81:  */
>>> 82: public IndexOutOfBoundsException(long index) {
>>> 83: super("Index out of range: " + index);
>> 
>> For consistency with the class name:
>> Suggestion:
>> 
>> super("Index out of bounds: " + index);
>
> Not sure about that one as it's a copy of the message from 
> IndexOutOfBoundsException(int index). Both would need to be changed for 
> consistency.

Ok, I didn't notice that it was taken from elsewhere. Never mind then.

-

PR: https://git.openjdk.java.net/jdk/pull/1003


Re: RFR: 8255150: Add utility methods to check long indexes and ranges [v2]

2020-11-05 Thread Roland Westrelin
> This change add 3 new methods in Objects:
> 
> public static long checkIndex(long index, long length)
> public static long checkFromToIndex(long fromIndex, long toIndex, long length)
> public static long checkFromIndexSize(long fromIndex, long size, long length)
> 
> This mirrors the int utility methods that were added by JDK-8135248
> with the same motivations.
> 
> As is the case with the int checkIndex(), the long checkIndex() method
> is JIT compiled as an intrinsic. It allows the JIT to compile
> checkIndex to an unsigned comparison and properly recognize it as
> a range check that then becomes a candidate for the existing range check
> optimizations. This has proven to be important for panama's
> MemorySegment API and a prototype of this change (with some extra c2
> improvements) showed that panama micro benchmark results improve
> significantly.
> 
> This change includes:
> 
> - the API change
> - the C2 intrinsic
> - tests for the API and the C2 intrinsic
> 
> This is a joint work with Paul who reviewed and reworked the API change
> and filled the CSR.

Roland Westrelin has updated the pull request with a new target base due to a 
merge or a rebase. The incremental webrev excludes the unrelated changes 
brought in by the merge/rebase. The pull request contains ten additional 
commits since the last revision:

 - Jorn's comments
 - Update headers and add intrinsic to Graal test ignore list
 - move compiler test and add bug to test
 - non x86_64 arch support
 - c2 test case
 - intrinsic
 - Use overloads of method names.
   
   Simplify internally to avoid overload resolution
   issues, leverging List for the exception
   mapper.
 - Vladimir's comments
 - checkLongIndex

-

Changes:
  - all: https://git.openjdk.java.net/jdk/pull/1003/files
  - new: https://git.openjdk.java.net/jdk/pull/1003/files/74df12d3..b47184ac

Webrevs:
 - full: https://webrevs.openjdk.java.net/?repo=jdk=1003=01
 - incr: https://webrevs.openjdk.java.net/?repo=jdk=1003=00-01

  Stats: 11784 lines in 698 files changed: 6370 ins; 3584 del; 1830 mod
  Patch: https://git.openjdk.java.net/jdk/pull/1003.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/1003/head:pull/1003

PR: https://git.openjdk.java.net/jdk/pull/1003


Re: RFR: 8255150: Add utility methods to check long indexes and ranges [v2]

2020-11-05 Thread Roland Westrelin
On Thu, 5 Nov 2020 11:58:43 GMT, Jorn Vernee  wrote:

> Although I'm not a 'Reviewer', I've done a pass over the code and left some 
> inline comments that I hope you find useful.

Thanks for the review! All suggestions (except the exception message one that I 
commented on) look good to me. I applied them.

> src/java.base/share/classes/java/lang/IndexOutOfBoundsException.java line 83:
> 
>> 81:  */
>> 82: public IndexOutOfBoundsException(long index) {
>> 83: super("Index out of range: " + index);
> 
> For consistency with the class name:
> Suggestion:
> 
> super("Index out of bounds: " + index);

Not sure about that one as it's a copy of the message from 
IndexOutOfBoundsException(int index). Both would need to be changed for 
consistency.

-

PR: https://git.openjdk.java.net/jdk/pull/1003