RFR: 8324433: Introduce a way to determine if an expression is evaluated as a constant by the Jit compiler [v3]
Aleksey Shipilev
shade at openjdk.org
Tue Jan 23 16:03:29 UTC 2024
On Tue, 23 Jan 2024 15:52:29 GMT, Alan Bateman <alanb at openjdk.org> wrote:
> Would it be possible to list further examples where this might be used? Asking because I'm wondering about the usability and maintainability of if-then-else code.
A similar thing is already used in JDK: https://github.com/openjdk/jdk/blob/2a01c798d346656a0ee3553c0964feab75b5dfb6/src/java.base/share/classes/java/lang/invoke/Invokers.java#L622-L624
Extending this for more common use allows doing things like optimizing `Integer.toString(int)`:
@Stable
static final String[] CONST_STRINGS = {"-1", "0", "1"};
@IntrinsicCandidate
public static String toString(int i) {
if (isCompileConstant(i) && (i >= -1) && (i <= 1)) {
return CONST_STRINGS[i + 1];
}
...
-------------
PR Comment: https://git.openjdk.org/jdk/pull/17527#issuecomment-1906379544
More information about the core-libs-dev
mailing list