[lworld] Integrated: 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:41 UTC 2020


On Wed, 26 Aug 2020 19:56:27 GMT, Frederic Parain <fparain 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

This pull request has now been integrated.

Changeset: 3540dd4d
Author:    Frederic Parain <fparain at openjdk.org>
URL:       https://git.openjdk.java.net/valhalla/commit/3540dd4d
Stats:     1296 lines in 7 files changed: 0 ins; 1264 del; 32 mod

8229897: [lworld] C1 should avoid allocation when reading a field from a flattened field

Reviewed-by: thartmann

-------------

PR: https://git.openjdk.java.net/valhalla/pull/167


More information about the valhalla-dev mailing list