Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-7170145

C1 doesn't respect the JMM with volatile field loads

    Details

    • Subcomponent:
    • Introduced In Version:
      6
    • Resolved In Build:
      b14
    • CPU:
      generic
    • OS:
      generic
    • Verification:
      Verified

      Backports

        Description

        A post on hotspot-compiler-dev shows a problem with volatile field loads in C1:

        http://mail.openjdk.java.net/pipermail/hotspot-compiler-dev/2012-May/007698.html

        The failing test case is:

        public class Test {
            volatile static private int a;
            static private int b;

            public static void main(String [] args) throws Exception {
                for (int i = 0; i < 100; i++) {
                    new Thread() {

                        @Override
                        public void run() {
                            int tt = b; // makes the jvm cache the value of b

                            while (a==0) {

                            }

                            if (b == 0) {
                                System.out.println("error");
                            }
                        }

                    }.start();
                }

                b = 1;
                a = 1;
            }
        }

        To hit the bug run:

        $ java -client Test

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  twisti Christian Thalinger
                  Reporter:
                  twisti Christian Thalinger
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  2 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Imported:
                    Indexed: