United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: 7170145 C1 doesn't respect the JMM with volatile field loads
7170145 : C1 doesn't respect the JMM with volatile field loads

Details
Type:
Bug
Submit Date:
2012-05-18
Status:
Resolved
Updated Date:
2013-04-30
Project Name:
JDK
Resolved Date:
2012-06-16
Component:
hotspot
OS:
generic
Sub-Component:
compiler
CPU:
generic
Priority:
P2
Resolution:
Fixed
Affected Versions:
hs23,6
Fixed Versions:
hs24

Related Reports
Backport:
Backport:
Backport:
Backport:
Backport:
Backport:
Duplicate:

Sub Tasks

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..
                                     
2012-10-18
EVALUATION

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

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

http://hg.openjdk.java.net/hsx/hotspot-comp/hotspot/rev/4d8787136e08
                                     
2012-05-25
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.
                                     
2012-05-18



Hardware and Software, Engineered to Work Together