RFR: 8331291: java.lang.classfile.Attributes class performs a lot of static initializations
Chen Liang
liach at openjdk.org
Tue Apr 30 11:56:20 UTC 2024
On Mon, 29 Apr 2024 18:48:53 GMT, Adam Sotona <asotona at openjdk.org> wrote:
> Hi,
> During performance optimization work on Class-File API as JDK lambda generator we found some static initialization killers.
> One of them is `java.lang.classfile.Attributes` with tens of static fields initialized with individual attribute mappers, and common set of all mappers, and static map from attribute names to the mappers.
>
> I propose to turn all the static fields into lazy-initialized static methods and remove `PREDEFINED_ATTRIBUTES` and `standardAttribute(Utf8Entry name)` static mapping method from the `Attributes` API class.
>
> Please let me know your comments or objections and please review the [PR](https://github.com/openjdk/jdk/pull/19006) and [CSR](https://bugs.openjdk.org/browse/JDK-8331414), so we can make it into 23.
>
> Thank you,
> Adam
Nice changes! Remarks
1. The `INSTANCE` fields should be declared `final`, still safe for lazy initialization.
2. Not from this patch, but the `AttributeStability stability()` overrides can be moved to `AbstractAttributeMapper`, stored in a field, to decrease source code size.
3. `AbstractAttributeMapper` might become sealed now that its implementations are no longer anonymous, might move it to be a private nested class of `Attributes` to omit the long list of permits.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/19006#issuecomment-2083832111
More information about the core-libs-dev
mailing list