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(...). AfterJDK-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
Field access causes iteration through all fields in InstanceKlass::find_local_field(...). After
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
- caused by
-
JDK-8292818 replace 96-bit representation for field metadata with variable-sized streams
-
- Resolved
-
- duplicates
-
JDK-8352169 Perf regression accessing fields
-
- Closed
-
- relates to
-
JDK-8353175 Eliminate double iteration of stream in FieldDescriptor reinitialization
-
- Open
-