RFR: 8339217: Optimize ClassFile API loadConstant

Chen Liang liach at openjdk.org
Thu Aug 29 06:04:46 UTC 2024


On Thu, 29 Aug 2024 05:01:52 GMT, Shaojin Wen <swen at openjdk.org> wrote:

> This is a large method. By splitting it into multiple methods with the same name, the caller can automatically select based on the different types of parameters, avoiding this large call that cannot be inlined, which can also improve startup performance.
> 
> * current
> 
> CodeBuilder {
>     default CodeBuilder loadConstant(ConstantDesc value) { ... }
> }
> 
> java.lang.classfile.CodeBuilder::loadConstant (465 bytes)   failed to inline: callee is too large

The primitive overloads of `loadConstant` avoid extraneous boxing. 👍

src/java.base/share/classes/java/lang/classfile/CodeBuilder.java line 646:

> 644:         if (value instanceof Float     ) return loadConstant((float)  value);
> 645:         if (value instanceof Double    ) return loadConstant((double) value);
> 646:         else                             return ldc(value);

I think we need to rearrange this to follow the code style, like:

if (value instanceof Number) {
    if (value instanceof Integer i)
        return loadConstant(i);
    if (value instanceof Long l)
        return loadConstant(l);
    if (value instanceof Float f)
        return loadConstant(f);
    if (value instanceof Double d)
        return loadConstant(d);
}
if (value == null || value == ConstantDescs.NULL)
    return aconst_null();
return ldc(value);

src/java.base/share/classes/java/lang/classfile/CodeBuilder.java line 653:

> 651:      * @param value the constant value
> 652:      * @return this builder
> 653:      * @since 23

These are technically since 24.

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

PR Review: https://git.openjdk.org/jdk/pull/20761#pullrequestreview-2267692194
PR Review Comment: https://git.openjdk.org/jdk/pull/20761#discussion_r1735577199
PR Review Comment: https://git.openjdk.org/jdk/pull/20761#discussion_r1735575357


More information about the core-libs-dev mailing list