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

C1 doesn't respect the JMM with volatile field loads

XMLWordPrintable

    • 6
    • b14
    • generic
    • generic
    • Verified

        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

          There are no Sub-Tasks for this issue.

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

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: