VarHandle instance methods performance
Remi Forax
forax at univ-mlv.fr
Wed Apr 24 10:26:24 UTC 2019
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" <frank.yuan at oracle.com>
> À: "Aleksey Shipilev" <shade at redhat.com>
> Cc: "core-libs-dev" <core-libs-dev at openjdk.java.net>
> 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
More information about the core-libs-dev
mailing list