1

When I am suspicious certain instruction reordering is allowed by the java language specification, I want to reproduce it in a jcstress test. How can I do that? For example, in the following code, the Load and Store instructions (I believe) are allowed to be reordered in execution in some runtime environment. However, when I run the jcstress in Intel x84_64 Ubuntu, the result does not show any reordering happened.

import org.openjdk.jcstress.annotations.*;
import org.openjdk.jcstress.infra.results.I_Result;

@JCStressTest
@Outcome(id = "0", expect = Expect.ACCEPTABLE,
         desc = "Default outcome.")
@Outcome(id = "2", expect = Expect.ACCEPTABLE_INTERESTING,
         desc = "Load-Store reordering happens.")
@State
public class ReorderingTest {

    int d;
    int e;
    int f;

    @Actor
    public void actor1() {
        int ee = e;     // Load
        d = 1;          // Store

        if (ee == 2) {
            f = 2;
        }
    }

    @Actor
    public void actor2() {
        if (d == 1) {
            e = 2;
        }
    }

    @Arbiter
    public void arbiter(I_Result r) {
        r.r1 = f;
    }
}
user675693
  • 307
  • 1
  • 8

1 Answers1

1

I finally managed to observe the reordering in the original jcstress test with explicit JVM options and running it with more hours of time.

java -jar target/jcstress.jar -f 20 -XX:-TieredCompilation, -XX:+UnlockDiagnosticVMOptions, -XX:+StressLCM, -XX:+StressGCM

However, in one of the following tests, reordering is never observed no matter how long I run the testing, although it looks equivalent to other tests.

// reordering can be observed!
@Actor
    public void actor1() {
        int ee = e;     // Load
        d = 1;          // Store

        if (ee == 2) {
            f = 2;
        }
    }
// reordering can be observed!
@Actor
    public void actor1() {
        f = e;          // Load & Store
        d = 1;          // Store
    }
// reordering NEVER observed!
@Actor
    public void actor1() {
        if (e == 2) f = 2;     // Load & conditionally Store
        d = 1;          // Store
    }
user675693
  • 307
  • 1
  • 8