Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wants to merge 10 commits into from

Conversation

fparain
Copy link
Collaborator

@fparain fparain commented Aug 26, 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();
@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


Progress

  • Change must not contain extraneous whitespace

Issue

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

Reviewers

Download

$ git fetch https://git.openjdk.java.net/valhalla pull/167/head:pull/167
$ git checkout pull/167

@bridgekeeper
Copy link

bridgekeeper bot commented Aug 26, 2020

👋 Welcome back fparain! A progress list of the required criteria for merging this PR into lworld will be added to the body of your pull request.

@openjdk
Copy link

openjdk bot commented Aug 26, 2020

@fparain This change now passes all automated pre-integration checks, type /integrate in a new comment to proceed. After integration, the commit message will be:

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

Reviewed-by: thartmann
  • If you would like to add a summary, use the /summary command.
  • To credit additional contributors, use the /contributor command.
  • To add additional solved issues, use the /issue command.

There are currently no new commits on the lworld branch since the last update of the source branch of this PR. If another commit should be pushed before you perform the /integrate command, your PR will be automatically rebased. If you would like to avoid potential automatic rebasing, specify the current head hash when integrating, like this: /integrate 54b541094689d6244b95307724f9a9698c10e46d.

➡️ To integrate this PR with the above commit message to the lworld branch, type /integrate in a new comment.

@mlbridge
Copy link

mlbridge bot commented Aug 26, 2020

Webrevs

Copy link
Member

@TobiHartmann TobiHartmann left a comment

Looks good to me!

@fparain
Copy link
Collaborator Author

fparain commented Aug 28, 2020

Thanks Tobias!

Fred

@fparain
Copy link
Collaborator Author

fparain commented Aug 28, 2020

/integrate

@openjdk openjdk bot closed this Aug 28, 2020
@openjdk openjdk bot added integrated and removed ready labels Aug 28, 2020
@openjdk
Copy link

openjdk bot commented Aug 28, 2020

@fparain
Pushed as commit 3540dd4.

@openjdk openjdk bot removed the rfr label Aug 28, 2020
@fparain fparain deleted the c1_getfield_opt branch Sep 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants