On Thu, 29 Apr 2021 10:13:16 GMT, Yi Yang <yy...@openjdk.org> wrote:

>> The JDK codebase re-created many variants of checkIndex(`grep -I -r 
>> 'cehckIndex' jdk/`). A notable variant is java.nio.Buffer.checkIndex, which 
>> annotated with @IntrinsicCandidate and it only has a corresponding C1 
>> intrinsic version.
>> 
>> In fact, there is an utility method 
>> `jdk.internal.util.Preconditions.checkIndex`(wrapped by 
>> java.lang.Objects.checkIndex) that behaves the same as these variants of 
>> checkIndex, we can replace these re-created variants of checkIndex by 
>> Objects.checkIndex, it would significantly reduce duplicated code and enjoys 
>> performance improvement because Preconditions.checkIndex is 
>> @IntrinsicCandidate and it has a corresponding intrinsic method in HotSpot.
>> 
>> But, the problem is currently HotSpot only implements the C2 version of 
>> Preconditions.checkIndex. To reuse it global-widely in JDK code, I think we 
>> can firstly implement its C1 counterpart. There are also a few kinds of 
>> stuff we can do later:
>> 
>> 1. Replace all variants of checkIndex by Objects.checkIndex in the whole JDK 
>> codebase.
>> 2. Remove Buffer.checkIndex and obsolete/deprecate InlineNIOCheckIndex flag
>> 
>> Testing: cds, compiler and jdk
>
> Yi Yang has updated the pull request incrementally with one additional commit 
> since the last revision:
> 
>   AssertionError when expected exception was not thrown

test/hotspot/jtreg/compiler/c1/TestCheckIndexC1Intrinsic.java line 86:

> 84:             // read fields
> 85:             Preconditions.checkIndex(limit + 1, limit, (s, integers) -> 
> new MyException("Reason:" + s + "::" + integers));
> 86:             throw new AssertionError("Expected IndexOutOfBoundsException 
> not thrown");

nit: well maybe here it should be:

throw new AssertionError("Expected MyException not thrown");

test/hotspot/jtreg/compiler/c1/TestCheckIndexC1Intrinsic.java line 94:

> 92:     static void check1(int i) {
> 93:         try {
> 94:             Preconditions.checkIndex(i, 9999, (s, integers) -> new 
> RuntimeException("ex"));

I believe 

throw new AssertionError("Expected IndexOutOfBoundsException not thrown");


should be added in `check1`...`check4` as well...

-------------

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

Reply via email to