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

Perf regression accessing fields

XMLWordPrintable

    • 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

        1. CCC.java
          321 kB
        2. ManyFieldsRegression.java
          2 kB
        3. profile-forward.html
          17 kB
        4. profile-reverse.html
          15 kB

            Unassigned Unassigned
            rvansa Radim Vansa
            Votes:
            0 Vote for this issue
            Watchers:
            11 Start watching this issue

              Created:
              Updated: