[code-reflection] RFR: Concat Transform Optimizations [v6]

Paul Sandoz psandoz at openjdk.org
Fri Jun 28 20:17:32 UTC 2024


On Fri, 28 Jun 2024 19:49:41 GMT, Ian Graves <igraves at openjdk.org> wrote:

>> Updates to the transformation on Concats to StringBuilder that reduce redundant "new" StringBuilders while respecting correctness.
>
> Ian Graves has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Updates and revisions

src/java.base/share/classes/java/lang/reflect/code/analysis/StringConcatTransformer.java line 112:

> 110:         else {
> 111:             appendType = JavaType.J_L_OBJECT;
> 112:         }

I think you can simplify as its hard to follow the logic when the type is string. We can now collapse the append methods into one (the two methods were used in a prior version).
e.g.,

private static Op append(Block.Builder block, Value builder, Value arg) {
   TypeElement type = arg.type();
   if (type.equals(JavaType.BYTE) || type.equals(JavaType.SHORT)) {
       // Widen
       arg = block.op(CoreOp.conv(JavaType.INT, arg));
       type = JavaType.INT;
    } else if (!type.equals(JavaType.J_L_STRING)) {
        type = JavaType.J_L_OBJECT;
    }

    MethodRef appendMethod = MethodRef.method(J_L_STRING_BUILDER, "append", J_L_STRING_BUILDER, type);
    return CoreOp.invoke(appendMethod, builder, arg)
}

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

PR Review Comment: https://git.openjdk.org/babylon/pull/149#discussion_r1659273281


More information about the babylon-dev mailing list