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

Graal gives different output when background compilations are disabled #4801

Closed
connglli opened this issue Aug 8, 2022 · 4 comments
Closed
Assignees

Comments

@connglli
Copy link

connglli commented Aug 8, 2022

Describe the issue

This is a JIT bug where Graal gives a different output from the interpreter or HotSpot's C1/C2 compiler only when the background compilations are disabled.

Steps to reproduce the issue

  1. javac T.java
  2. java -Xint T
  3. java T
  4. java -XX:-BackgroundCompilation T

The results of aaa and bbb are different, while expected to be the same.

Describe GraalVM and your environment:

  • GraalVM version: 22.3.0-dev
  • JDK major version: 11.0.16
  • OS: Ubuntu 20.04
  • Architecture: x86_64

More details

The following is the source of our tests:

class T {
  long a;

  void c() {}

  void z() {
    int i, j, q = 40574, v;
    double m = 2.51479;
    j = 1;
    while (++j < 139) {
      for (int w = 0; w < 5618; w += 1) c();
      v = 1;
      do m -= 0.853F;
      while (++v < 2);
      q = j;
      q &= v;
    }
    a += q;
  }

  void f() {
    z();
    System.out.println(a);
  }

  public static void main(String[] g) {
    T t = new T();
    t.f();
  }
}

Result of the interpreter:

$ java -Xint T
2

Result of Graal compiler w/ background compilations:

$ java T
2

Result of Graal compiler w/o background compilations:

$ java -XX:-BackgroundCompilation T
0
@connglli connglli added the bug label Aug 8, 2022
@dougxc dougxc assigned gergo- and unassigned dougxc Aug 9, 2022
@gergo-
Copy link
Member

gergo- commented Aug 9, 2022

Thanks for this report @connglli. This seems to be a duplicate of #4754 and fixed by 169807f. Please check if the newest development build from https://github.com/graalvm/graalvm-ce-dev-builds/releases behaves as expected.

@connglli
Copy link
Author

connglli commented Aug 9, 2022

Close this issue as fixed by 169807f

@connglli connglli closed this as completed Aug 9, 2022
@connglli
Copy link
Author

connglli commented Aug 9, 2022

@gergo- Could you explain to me why this happens only when background compilation is disabled? #4754 can be easily reproduced without disable background compilations. Thanks!

@dougxc
Copy link
Member

dougxc commented Aug 9, 2022

Could you explain to me why this happens only when background compilation is disabled

With background compilation disabled, an application thread that triggers a compilation will block and wait for the compilation to finish and then jump into the compiled code. That increases the likelihood of the problematic method being compiled and having the compiled code be executed. Without background compilation, the method in question maybe scheduled for compilation but complete execution in the interpreter (or as C1 compiled code) before the Graal compilation finishes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants