Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8352169

Perf regression accessing fields

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P2 P2
    • None
    • None
    • hotspot
    • None
    • 21

        JDK 21 and later versions introduce a performance regression when accessing fields in a class with many fields, in interpreted mode. I believe this is caused by introduction of FieldStream in JDK-8292818; another performance regression caused by this change was already found upon heap dump JDK-8317692.

        Field access causes iteration through all fields in InstanceKlass::find_local_field(...). After JDK-8292818 this results in decoding many variable-length integers (through FieldInfoReader.read_field_info invoked by the next() method) rather than simple indexed access, which turns out to be costly.
        Moreover, when we call fd->reinitialize(...) the field lookup by index results in another iteration through the fields rather than O(1) access.

        I am attaching a reproducer; this creates a class with 21,000 fields, compiles it and executes this (all that the class does is to initialize
        all its fields). On JDK 17 running this reports 581 ms; on JDK 21 the test takes 8017 ms on my laptop.

        I was able to avoid the second iteration by passing FieldInfo to reinitialize() and the execution went down to 5712 ms, but I don't see a simple solution that would make the first iteration more efficient.

        hotspot-dev reference: https://mail.openjdk.org/pipermail/hotspot-dev/2025-March/102679.html

              Unassigned Unassigned
              xuelei Xuelei Fan
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved: