8054927: Missing MemNode::acquire ordering in some volatile Load nodes
authorkvn
Wed, 13 Aug 2014 13:05:04 -0700
changeset 26171 ddd28cb3f2b9
parent 26170 4645d30c2e27
child 26172 7ab032af2835
8054927: Missing MemNode::acquire ordering in some volatile Load nodes Summary: Fixed memory ordering parameter and added missing barriers for volatile loads. Reviewed-by: roland, iveresov
hotspot/src/share/vm/opto/library_call.cpp
--- a/hotspot/src/share/vm/opto/library_call.cpp	Wed Aug 13 09:53:18 2014 +0000
+++ b/hotspot/src/share/vm/opto/library_call.cpp	Wed Aug 13 13:05:04 2014 -0700
@@ -2595,7 +2595,8 @@
   if (need_mem_bar) insert_mem_bar(Op_MemBarCPUOrder);
 
   if (!is_store) {
-    Node* p = make_load(control(), adr, value_type, type, adr_type, MemNode::unordered, is_volatile);
+    MemNode::MemOrd mo = is_volatile ? MemNode::acquire : MemNode::unordered;
+    Node* p = make_load(control(), adr, value_type, type, adr_type, mo, is_volatile);
     // load value
     switch (type) {
     case T_BOOLEAN:
@@ -5096,8 +5097,19 @@
     type = Type::get_const_basic_type(bt);
   }
 
+  if (support_IRIW_for_not_multiple_copy_atomic_cpu && is_vol) {
+    insert_mem_bar(Op_MemBarVolatile);   // StoreLoad barrier
+  }
   // Build the load.
-  Node* loadedField = make_load(NULL, adr, type, bt, adr_type, MemNode::unordered, is_vol);
+  MemNode::MemOrd mo = is_vol ? MemNode::acquire : MemNode::unordered;
+  Node* loadedField = make_load(NULL, adr, type, bt, adr_type, mo, is_vol);
+  // If reference is volatile, prevent following memory ops from
+  // floating up past the volatile read.  Also prevents commoning
+  // another volatile read.
+  if (is_vol) {
+    // Memory barrier includes bogus read of value to force load BEFORE membar
+    insert_mem_bar(Op_MemBarAcquire, loadedField);
+  }
   return loadedField;
 }