Should Class.name field be @Stable?
Jaikiran Pai
jai.forums2013 at gmail.com
Tue Dec 19 09:40:30 UTC 2023
Hello Chen,
Looking at the implementation of java.lang.Class.getName(), which then
triggers the hotspot code to initialize this "name" field, I suspect
there will be a (harmless) race in the hotspot implementation where more
than one thread could end up writing the "name" field (with the same
value of course)
https://github.com/openjdk/jdk/blob/master/src/hotspot/share/classfile/javaClasses.cpp#L1237.
I don't know how the JVM would then react if such a field is marked
@Stable (the javadoc of @Stable states that the behaviour is such cases
is undefined).
-Jaikiran
On 16/12/23 8:37 pm, - wrote:
> Hello,
> I just noticed the Class.name field is mutable but not @Stable,
> meaning `Class.getName()` calls are not eligible for constant folding.
>
> The last update to this field is in 2019 in JDK-8216302 when the field
> initialization was done directly by a write from hotspot code (for the
> class name is interned anyways, though interning limits scalability of
> hidden classes)
>
> Would it be a good idea to submit a patch to mark this field @Stable?
> Given class names may be frequently used to quickly identify a class,
> to create descriptors.
>
> Chen Liang
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/core-libs-dev/attachments/20231219/fd893068/attachment-0001.htm>
More information about the core-libs-dev
mailing list