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

Frederic Parain fparain at openjdk.java.net
Wed Aug 26 20:16:40 UTC 2020

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();
    public void testGetfieldChain1(Blackhole blackhole) {
        int i = nr.rect.p0.j;                                                              // reads two flattened fields before
        reading an int blackhole.consume(i);

    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,



Commit messages:
 - Fix whitespaces
 - Fix whitespaces
 - Fix and upgrade tests
 - Adding back refactored unit test
 - Removing problematic unit test
 - Fix test configuration for C2
 - Add new test for NoSuchFieldError
 - Fixes, cleanup and unit test
 - Fix reading of flattened field, remove debug messages
 - Initial getfield optimization, no exception support

Changes: https://git.openjdk.java.net/valhalla/pull/167/files
 Webrev: https://webrevs.openjdk.java.net/valhalla/167/webrev.00
  Issue: https://bugs.openjdk.java.net/browse/JDK-8229897
  Stats: 1296 lines in 7 files changed: 1264 ins; 0 del; 32 mod
  Patch: https://git.openjdk.java.net/valhalla/pull/167.diff
  Fetch: git fetch https://git.openjdk.java.net/valhalla pull/167/head:pull/167

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

More information about the valhalla-dev mailing list