C1 and @Stable array elements
Vladimir Ivanov
vladimir.x.ivanov at oracle.com
Thu Nov 19 17:30:11 UTC 2015
Paul,
It is definitely doable, but my estimate is that it could require
extensive changes.
The first question I'd like to ask you is what use cases do you have in
mind?
What I'm trying to understand is what level of optimization you are
looking for.
(1) With field loads it is simple
getfield T.f // class T { @Stable int f; }
all information is local, so it can be constant folded during bytecode
parsing.
(2) For arrays it becomes slightly harder:
getfield T.arr:[I // class T { @Stable int[] arr; }
iconst_0
iaload
The value produced by getfield should be annotated as "stable", so when
aaload is parsed there is a way to find out the array on stack is "stable".
(3) And for arrays of arrays it becomes complex:
getfield T.arr:[[[I // class T { @Stable int[][][] arr; }
iconst_0
aaload // => int[][]
iconst_0
aaload // => int[]
iconst_0
iaload // => int
The compiler has to track not only "stable" bit, but also array
dimension to be able to constant fold the very last load.
And then we have to add control flow into consideration. Ends up pretty
complex, isn't it? :-)
Best regards,
Vladimir Ivanov
PS: I deliberately tried to be pessimistic in my estimates since I don't
have extensive experience in C1 code base.
On 11/19/15 7:22 PM, Paul Sandoz wrote:
> Hi,
>
> Currently C1 does not support constant folding of array elements of an array held by a @Stable field.
>
> How easy or hard would it be for C1 to support such constant folding?
>
> Naively and intuitively, since C1 appears to constant fold an array length (i.e. it knows the array itself is stable or static final), it would in theory seem possible to extend that logic for array elements, such that if the referenced element value is not the default value, produce a constant holding the element value.
>
> Paul.
>
More information about the hotspot-compiler-dev
mailing list