RFR: 8331291: java.lang.classfile.Attributes class performs a lot of static initializations

Chen Liang liach at openjdk.org
Tue Apr 30 12:12:06 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

Also the `final` modifier addition should be included in the CSR, as it changes the access modifiers even if it has no real impact.

src/java.base/share/classes/jdk/internal/classfile/impl/BoundAttribute.java line 996:

> 994:     public static AttributeMapper<?> standardAttribute(Utf8Entry name) {
> 995:         // critical bootstrap path, so no lambdas nor method handles here
> 996:         return switch (name.hashCode()) {

I think we can safely switch over strings, as they are compiled to hashCode switch like what you explicitly have right now. Isn't that the case?

test/jdk/jdk/classfile/AttributesTest.java line 26:

> 24: /*
> 25:  * @test
> 26:  * @summary Testing Attributes API.

Can add a line `@bug 8331291`

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

PR Comment: https://git.openjdk.org/jdk/pull/19006#issuecomment-2085160221
PR Review Comment: https://git.openjdk.org/jdk/pull/19006#discussion_r1584686905
PR Review Comment: https://git.openjdk.org/jdk/pull/19006#discussion_r1584687500


More information about the hotspot-compiler-dev mailing list