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;
    }
}
2
  • Are you running on a box with more than one CPU? Commented May 14, 2019 at 22:13
  • @NotaJD Yes, the output of nproc command in my machine is 12. Commented May 14, 2019 at 22:20

1 Answer 1

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
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.