oracle/graal

Graal gives different output when background compilations are disabled

connglli opened this issue · 4 comments

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

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.

Close this issue as fixed by 169807f

@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!

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.