JDK-7170145 : C1 doesn't respect the JMM with volatile field loads
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: hs23,6
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2012-05-18
  • Updated: 2017-02-27
  • Resolved: 2012-06-16
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6 JDK 7 JDK 8 Other
6u60Fixed 7u40Fixed 8Fixed hs23.2Fixed
Related Reports
Duplicate :  
Relates :  
Sub Tasks
JDK-8002330 :  
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

Comments
Sorry, wrong bug, should have assigned the backport to me..
18-10-2012

EVALUATION http://hg.openjdk.java.net/lambda/lambda/hotspot/rev/4d8787136e08
29-06-2012

EVALUATION http://hg.openjdk.java.net/hsx/hsx23.2/hotspot/rev/202880d633e6
07-06-2012

EVALUATION http://hg.openjdk.java.net/hsx/hotspot-comp/hotspot/rev/4d8787136e08
25-05-2012

EVALUATION ValueNumberingVisitor::do_LoadField does not include logic for volatile fields which allows CSE of normal field loads across volatile field loads. That's explicitly prohibited by the JMM.
18-05-2012