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

AArch64: Compressed pointer decoding optimization when base is zero. #1094

Merged
merged 1 commit into from
Apr 9, 2019

Conversation

XiaohongGong
Copy link
Contributor

@XiaohongGong XiaohongGong commented Mar 21, 2019

Currently decoding a compressed pointer with zero base will generate
the following code:
add x0, xzr, x0, lsl #3

This patch will optimize it to:
lsl x0, x0, #3

Here is a jmh benchmark to decode a compressed pointer:

public class UncompressPointer {
    private static final int field0 = 1000000;
    private int field1;

    static class A {
        B b;

        A(B b) {
            this.b = b;
        }
    }

    static class B {
        int field;

        B(int i) {
            this.field = i;
        }
    }

    static A[] arr;

    static {
        arr = new A[field0];
        for (int i = 0; i < field0; i++)
           arr[i] = new A(new B(i));
    }

    public static int func() {
        int result = 0;
        for (int i = 0; i < field0; i++) {
            result += arr[i].b.field;
        }
        return result;
    }

    @Benchmark
    public void jmhUncompressPointer() {
        field1 = func();
    }
}

And the performance results:

                         Score      Error    Units
Without this patch     21598.534 ? 2188.242  us/op
With this patch        19322.791 ? 1219.022  us/op

Change-Id: I5af6799eb82470d5598f5991e9210f99874f458a

@XiaohongGong
Copy link
Contributor Author

Hi there,
Can anyone please take a look at this patch? Thank you!

@sanzinger
Copy link
Contributor

Thank you for your contribution. I'll take a look as soon as possible. (And the other AArch64 related patches too)

@sanzinger sanzinger self-requested a review March 25, 2019 09:36
@sanzinger sanzinger self-assigned this Mar 25, 2019
Currently decoding a compressed pointer with zero base will generate
the following code:
add x0, xzr, x0, lsl oracle#3

This patch will optimize it to:
lsl x0, x0, oracle#3

Here is a jmh benchmark to decode a compressed pointer:
public class UncompressPointer {
    private static final int field0 = 1000000;
    private int field1;

    static class A {
        B b;

        A(B b) {
            this.b = b;
        }
    }

    static class B {
        int field;

        B(int i) {
            this.field = i;
        }
    }

    static A[] arr;

    static {
        arr = new A[field0];
        for (int i = 0; i < field0; i++)
           arr[i] = new A(new B(i));
    }

    public static int func() {
        int result = 0;
        for (int i = 0; i < field0; i++) {
            result += arr[i].b.field;
        }
        return result;
    }

    @benchmark
    public void jmhUncompressPointer() {
        field1 = func();
    }
}
And the performance results:
                         Score      Error    Units
Without this patch     21598.534 ? 2188.242  us/op
With this patch        19322.791 ? 1219.022  us/op

Change-Id: I5af6799eb82470d5598f5991e9210f99874f458a
@XiaohongGong
Copy link
Contributor Author

Thank you for your contribution. I'll take a look as soon as possible. (And the other AArch64 related patches too)

Thanks so much!


private void compareAssembly() {
byte[] expected = masm1.close(false);
byte[] actual = masm2.close(false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this kind of test. Nice work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@graalvmbot graalvmbot merged commit a44a5dc into oracle:master Apr 9, 2019
@XiaohongGong XiaohongGong deleted the uncompress branch April 10, 2019 01:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants