Strict long type casting

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Tue Apr 7 20:54:15 UTC 2020


On 07/04/2020 20:38, Ty Young wrote:
> Question: can the JIT compiler still perform these optimizations if 
> the VarHandle(s) are stored in a Map so long as the references are 
> final? Currently(as shown in the code), I'm doing just that to cut 
> down on the amount of wasted memory on the exact same VarHandle(s) as 
> I'd otherwise have 60+ instances. 

I would expect a Map to obfuscate things too much for the JIT. Rather 
than having a Map, if you care about performances, I'd suggest to just 
declare all the common (final static) constants you need somewhere - and 
fetch them from that single place. That's at least how code typically 
operate with MethodHandle and VarHandle.

Even storing them into arrays is not great in the absence of the @Stable 
annotation (which is only available to JDK code).

Maurizio



More information about the panama-dev mailing list