-
Enhancement
-
Resolution: Not an Issue
-
P4
-
None
-
None
-
None
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().
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().
- relates to
-
JDK-8219774 Reexamine the initialization of LangReflectAccess shared secret at AccessibleObject::<clinit>
-
- Resolved
-