Hi Ogata, this seems to make sense. So, +1 from my end.
Can you please add a space after "if" in line "734 if(langReflectAccess == null) {"? Thanks Christoph > -----Original Message----- > From: core-libs-dev <core-libs-dev-boun...@openjdk.java.net> On Behalf > Of Kazunori Ogata > Sent: Mittwoch, 17. Juli 2019 08:49 > To: core-libs-dev@openjdk.java.net > Subject: RFR: JDK-8227831: Avoid using volatile for write-once, read-many > class field > > Hi, > > May I have a review for "JDK-8227831: Avoid using volatile for write-once, > read-many class field"? > > In jdk.internal.reflect.ReflectionFactory, there is a private class field > named "langReflectAccess", which is referenced every time when the library > handles various reflective operations. This field is initialized on the > first access to the ReflectionFactory class. This field is declared as > volatile to avoid (or reduce) race condition between initialization and > references to the field. > > On the platforms with weak memory model (i.e, POWER and ARM), reading a > volatile variable requires memory fence and incurs overhead. So it is > preferable to avoid use of volatile for such a write-once, read-many > variable. > > langReflectAccess can be modified only in setLangReflectAccess() method. > So we can avoid using volatile by modifying setLangReflectAccess() to use > a synchronized block to avoid race condition. This change reduced elapsed > time of a micro benchmark by 9%, which repeatedly invoke > Class.getMethods(). > > > Bug: https://bugs.openjdk.java.net/browse/JDK-8227831 > > Webrev: http://cr.openjdk.java.net/~ogatak/8227831/webrev/ > > > Regards, > Ogata