Perf regression accessing fields in JDK21
Radim Vansa
rvansa at azul.com
Fri Mar 14 10:21:04 UTC 2025
Hello,
I've stumbled upon a performance regression when accessing fields in a
class with many fields, in interpreted mode. I believe this is caused by
introduction of FieldStream [1]; another performance regression caused
by this change was already found upon heap dump [2].
Field access causes iteration through all fields in
InstanceKlass::find_local_field(...) [3]. After [1] 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 indexed access [4] results in another
iteration through the fields [5] 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. I
was thinking that the name and signature indices might not be
variable-size encoded (this would require 4 rather than 2 bytes in
classes with a short constant pool) but then in reinitialize() we would
need to load the other flags anyway (hence iterating through the stream
with variable lengths). The stream could be also reordered (?) into
several sequences of fixed length records, but this is rather
complicated and does not really guarantee to fix the regression.
Thank you for your thoughts on this matter.
Radim Vansa
[1] https://bugs.openjdk.org/browse/JDK-8292818
[2] https://bugs.openjdk.org/browse/JDK-8317692
[3]
https://github.com/openjdk/jdk/blob/master/src/hotspot/share/oops/instanceKlass.cpp#L1783
[4]
https://github.com/openjdk/jdk/blob/master/src/hotspot/share/runtime/fieldDescriptor.cpp#L97
[5]
https://github.com/openjdk/jdk/blob/master/src/hotspot/share/oops/instanceKlass.cpp#L1774
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ManyFieldsRegression.java
Type: text/x-java
Size: 2198 bytes
Desc: not available
URL: <https://mail.openjdk.org/pipermail/hotspot-dev/attachments/20250314/685b7f94/ManyFieldsRegression-0001.java>
More information about the hotspot-dev
mailing list