[lworld] RFR: 8229897: [lworld] C1 should avoid allocation when reading a field from a flattened field
Frederic Parain
fparain at openjdk.java.net
Fri Aug 28 14:34:39 UTC 2020
On Fri, 28 Aug 2020 14:12:21 GMT, Tobias Hartmann <thartmann at openjdk.org> wrote:
>> Please review this patch which removes temporary heap allocations when reading a field from a flattened field.
>>
>> During the HIR graph construction, C1 detects sequences of consecutive getfield bytecodes involving flattened fields
>> and optimizes them with a single LoadField or NewInlineTypeInstance directly to the offset of the last nested field.
>> Performance improvement on a simple benchmark
>>
>> static inline class Point {
>> int i = 0, j = 0;
>> }
>> static inline class Rectangle {
>> Point p0 = new Point(), p1 = new Point();
>> }
>> static class NamedRectangle {
>> Rectangle rect = new Rectangle();
>> String name;
>> }
>> static NamedRectangle nr = new NamedRectangle();
>> @Benchmark
>> public void testGetfieldChain1(Blackhole blackhole) {
>> int i = nr.rect.p0.j; // reads two flattened fields before
>> reading an int blackhole.consume(i);
>> }
>>
>> @Benchmark
>> public void testGetfieldChain2(Blackhole blackhole) {
>> Point p = nr.rect.p1; // reads a flattened field inside a
>> flattened field blackhole.consume(p);
>> }
>>
>> Without the optimization:
>> Benchmark Mode Samples Score Score error Units
>> o.s.MyBenchmark.testGetfieldChain1 avgt 200 8.696 0.024 ns/op
>> o.s.MyBenchmark.testGetfieldChain2 avgt 200 8.969 0.027 ns/op
>>
>> With the optimization:
>> Benchmark Mode Samples Score Score error Units
>> o.s.MyBenchmark.testGetfieldChain1 avgt 200 2.134 0.019 ns/op
>> o.s.MyBenchmark.testGetfieldChain2 avgt 200 5.150 0.017 ns/op
>>
>>
>> Tested with Mach5, tiers 1 to 3.
>>
>> Thank you,
>>
>> Fred
>
> Looks good to me!
Thanks Tobias!
Fred
-------------
PR: https://git.openjdk.java.net/valhalla/pull/167
More information about the valhalla-dev
mailing list