From 687fab1763eacf53518428621296c1b885e8b393 Mon Sep 17 00:00:00 2001
From: Christian Thalinger <twisti@openjdk.org>
Date: Fri, 25 May 2012 11:39:13 -0700
Subject: [PATCH] 7170145: C1 doesn't respect the JMM with volatile field loads

Reviewed-by: kvn, roland
---
 hotspot/src/share/vm/c1/c1_ValueMap.hpp | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/hotspot/src/share/vm/c1/c1_ValueMap.hpp b/hotspot/src/share/vm/c1/c1_ValueMap.hpp
index 4278b11d39a..5b38819da82 100644
--- a/hotspot/src/share/vm/c1/c1_ValueMap.hpp
+++ b/hotspot/src/share/vm/c1/c1_ValueMap.hpp
@@ -141,8 +141,11 @@ class ValueNumberingVisitor: public InstructionVisitor {
 
   // visitor functions
   void do_StoreField     (StoreField*      x) {
-    if (x->is_init_point()) {
-      // putstatic is an initialization point so treat it as a wide kill
+    if (x->is_init_point() ||  // putstatic is an initialization point so treat it as a wide kill
+        // This is actually too strict and the JMM doesn't require
+        // this in all cases (e.g. load a; volatile store b; load a)
+        // but possible future optimizations might require this.
+        x->field()->is_volatile()) {
       kill_memory();
     } else {
       kill_field(x->field());
@@ -160,8 +163,8 @@ class ValueNumberingVisitor: public InstructionVisitor {
   void do_Local          (Local*           x) { /* nothing to do */ }
   void do_Constant       (Constant*        x) { /* nothing to do */ }
   void do_LoadField      (LoadField*       x) {
-    if (x->is_init_point()) {
-      // getstatic is an initialization point so treat it as a wide kill
+    if (x->is_init_point() ||         // getstatic is an initialization point so treat it as a wide kill
+        x->field()->is_volatile()) {  // the JMM requires this
       kill_memory();
     }
   }