Hi Frank, a VarHandle is a glorified integer value that correspond to the number of bytes from a pointer to a field address, so you give it a reference and you have access to the field at the address: reference + shift, given that the shift value is the same for all the instances of the same class, it should be declared static (and final so it's a constant for the VM).
Rémi ----- Mail original ----- > De: "Frank Yuan" <[email protected]> > À: "Aleksey Shipilev" <[email protected]> > Cc: "core-libs-dev" <[email protected]> > Envoyé: Mercredi 24 Avril 2019 12:11:11 > Objet: RE: VarHandle instance methods performance >> On 4/24/19 11:51 AM, Frank Yuan wrote: >> > My test code is as below: >> > ... >> > final VarHandle vhf; >> > final VarHandle vhvf; >> > ... >> >> Make these two "static final", initialize them in class initializer, then try >> again. >> >> VarHandle (like Atomic*FieldUpdaters, MethodHandle, etc), have internal >> checks >> that can only be >> folded away when the VH/MH/A*FU instance is constant. >> > > Thank you, it works! > > YC > > > -Aleksey
