Why does the java.util.Objects.checkIndex method need @ForceInline?

174 Views Asked by At

Java version: openjdk-18.0.2.1

@ForceInline
public static int checkIndex(int index, int length) {
    return Preconditions.checkIndex(index, length, null);
}

I'm not sure why the class java.util.Objects needs an annotation applied to the checkIndex method. (added in java9 version)

After a brief investigation, I think it was used in the case of it may act as a temporary workaround until the profiling and lining perfected by the HotSpot VM is successfully improved. Is that correct?

Additionally, I wonder if the similar methods checkFromToIndex and checkFromIndexSize are not annotated.

Thank you in advance for your help.

0

There are 0 best solutions below